WC_Template_Fixer/sntg-woocommerce-language-fix.php
2020-09-09 12:33:30 +02:00

82 lines
2.7 KiB
PHP

<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link https://sonith.de
*
* @wordpress-plugin
* Plugin Name: Language Fix for Woocommerce Template Files
* Plugin URI: https://sonith.de
* Description: Some themes use their own textdomain in their woocommerce template files, resulting in partially missing translations. This plugin fixes the textdomains to woocommerce on every update.
* Version: 1.0.0
* Author: Sonith
* Author URI: https://sonith.de
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: sntg-wc-template-fix
* Domain Path: /languages
*/
defined( 'ABSPATH' ) || exit;
include ('src/helpers.php');
include ('constants.php');
include ('src/Template_Fixer.php');
include ('src/Template_Finder.php');
add_action ('init', 'sntg_wclf_init');
add_action( 'upgrader_process_complete', 'sntg_wc_template_fixer_update_trigger',10, 2);
function sntg_wc_template_fixer_update_trigger( $upgrader_object, $options ) {
//this is a bit of an overhead as on every theme update all themes templates get updated
if ($options['action'] == 'update' && $options['type'] == 'theme' ){
fix_woocommerce_template_textdomains();
}
}
function sntg_wclf_init(){
//register shortcode for testing
add_shortcode('sntg_wclf_tester', 'fix_woocommerce_template_textdomains');
}
register_activation_hook( __FILE__, 'sntg_woocommerce_language_fix_activation' );
register_deactivation_hook( __FILE__, 'sntg_woocommerce_language_fix_deactivation' );
add_action('admin_init', 'sntg_woocommerce_language_fix_activate');
function sntg_woocommerce_language_fix_activation(){
add_option( 'sntg_activated_plugin', 'sntg-woocommerce-language-fix' );
}
function sntg_woocommerce_language_fix_activate(){
if (is_admin() && get_option ('sntg_activated_plugin') == 'sntg-woocommerce-language-fix'){
fix_woocommerce_template_textdomains();
delete_option( 'sntg_activated_plugin' );
}
}
function sntg_automatic_user_deletion_deactivation(){
//i don't think there is actions necessarry...
}
function fix_woocommerce_template_textdomains(){
//find all templates
$tfinder = new Template_Finder(ABSPATH . THEME_FOLDER_PATH);
$templates=$tfinder->get_templates();
foreach ($templates as $template_path => $template_textdomain){
$tfixer = new Template_Fixer($template_path, $template_textdomain);
$tfixer->fix_template();
}
}