diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/README.txt b/README.txt index 5dda641..c3a35dd 100755 --- a/README.txt +++ b/README.txt @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i Tags: polylang, contact form 7, multisite, contact form 7 extension, contact form 7 module, multilingual contact form 7, multilingual form, cf7 smart grid extension Requires at least: 4.7 Requires PHP: 5.6 -Tested up to: 5.5.1 +Tested up to: 5.8.3 Stable tag: trunk License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -137,7 +137,7 @@ function add_translation_resource($plugin_translation){ }` this filter should be used by plugin developers to ensure their plugin translation resources are loaded. - + == Screenshots == 1. If you don't see the polylang links in your contact table list, head to the Polylang settings and save the existing post content to the default language. (Step 6 in the installation instructions) 2. Contact form table list with Polylang language columns, a dropdown of available languages next to the 'Add New' button allows you to create new forms in any language, note also the portable cf7 shortcodes. @@ -145,6 +145,8 @@ this filter should be used by plugin developers to ensure their plugin translati 4. Ensure you enable translations for Contact Forms in your Polyland settings. == Changelog == += 2.4.1 = +* fix language update. = 2.4.0 = * enable other plugins to add their translation files. * added 'cf7pll_load_plugin_translation_resource' filter. diff --git a/admin/class-cf7-polylang-admin.php b/admin/class-cf7-polylang-admin.php index f9c8402..391ad37 100755 --- a/admin/class-cf7-polylang-admin.php +++ b/admin/class-cf7-polylang-admin.php @@ -507,6 +507,7 @@ protected function load_l10n_domains($locale){ if ( is_admin() && get_user_locale() == $locale) return true; $plugin_translations = apply_filters('cf7pll_load_plugin_translation_resource', array()); + foreach($plugin_translations as $plugin=>$version){ //make sure we have at least 1 default locale should Polylang change its API. $available_locales = array('en_US'); @@ -521,7 +522,6 @@ protected function load_l10n_domains($locale){ $locale = $locales[0]; } } - if ( is_textdomain_loaded( $plugin ) ) { unload_textdomain( $plugin ); } @@ -536,4 +536,37 @@ protected function load_l10n_domains($locale){ } } } + /** + * Save locale and messages. + * + *@since 2.4.1 + *@param string $post_id post id + */ + public function save_locale($post_id){ + $current = sanitize_text_field($_POST['wpcf7-locale']); + // $current = get_post_meta($post_id, '_locale', true); + $update = $current; + if(function_exists('pll_get_post_language')){ + $update = pll_get_post_language($post_id, 'locale'); + } + if($current != $update){ + update_post_meta($post_id, '_locale', $update); + if(method_exists('WPCF7_ContactFormTemplate','messages')){ + $this->load_l10n_domains($update); + $msg = WPCF7_ContactFormTemplate::messages(); + update_post_meta($post_id, '_messages',$msg); + } + } + } + /** + * Filter plugins domains to load translation resources. + * + *@since 2.4.1 + *@param Array $plugin_translations plugin-domain=>version-number pairs. + *@return Array + */ + public function include_cf7_plugin($plugin_translations){ + $plugin_translations['contact-form-7']=WPCF7_VERSION; + return $plugin_translations; + } } diff --git a/assets/persist-admin-notices/dismiss-notice.js b/assets/persist-admin-notices/dismiss-notice.js old mode 100644 new mode 100755 diff --git a/assets/persist-admin-notices/persist-admin-notices-dismissal.php b/assets/persist-admin-notices/persist-admin-notices-dismissal.php old mode 100644 new mode 100755 diff --git a/changelog.txt b/changelog.txt old mode 100644 new mode 100755 diff --git a/includes/class-cf7-polylang.php b/includes/class-cf7-polylang.php index 6560776..1774d40 100755 --- a/includes/class-cf7-polylang.php +++ b/includes/class-cf7-polylang.php @@ -188,6 +188,9 @@ private function define_admin_hooks() { $this->loader->add_filter( 'wpcf7_special_mail_tags', $plugin_admin, 'cf7_tag_home_url', 10, 3 ); /** @since 2.3.4 - fix translations in smart-grid */ $this->loader->add_filter('cf7sg_new_cf7_form_template_arguments', $plugin_admin, 'new_form_template'); + /** @since 2.4.1 - fix change language*/ + $this->loader->add_action('save_post_wpcf7_contact_form', $plugin_admin, 'save_locale',100,1); + $this->loader->add_filter('cf7pll_load_plugin_translation_resource', $plugin_admin, 'include_cf7_plugin',10,1); } diff --git a/includes/wordpress-gurus-debug-api.php b/includes/wordpress-gurus-debug-api.php old mode 100644 new mode 100755 index 4ffd178..7da2ded --- a/includes/wordpress-gurus-debug-api.php +++ b/includes/wordpress-gurus-debug-api.php @@ -11,32 +11,41 @@ $debug_msg_last_line=''; $debug_msg_last_file=''; } + /** + * Function to log debug messages. + * Requires WP_GURUS_DEBUG = true, define it in your wp-config.php file. + * Set WP_DEBUG to true, and WP_DEBUG_DISPLAY to false (so no errors are printed to screen), and WP_DEBUG_LOG to true so messages are logged to wp-content/debug.log file. + */ function debug_msg($message, $prefix='', $trace=0) { - if (true === WP_GURUS_DEBUG) { - global $debug_msg_last_line,$debug_msg_last_file; - $backtrace = debug_backtrace(); - $file = $backtrace[0]['file']; - $files = explode('/',$file); - $dirs = explode('/',plugin_dir_path( __FILE__ )); - $files = array_diff($files,$dirs); - $file = implode('/',$files); - $line = $backtrace[0]['line']; - $msg='DEBUG_MSG: '.PHP_EOL; - if($file != $debug_msg_last_file && $line != $debug_msg_last_line){ - for($idx=$trace; $idx>0; $idx--){ - $msg.=" [".$backtrace[$idx]['line']."]->/".$backtrace[$idx]['file'].PHP_EOL; - } - $msg.= " [".$line."]./".$file.PHP_EOL; - $debug_msg_last_file=$file; - $debug_msg_last_line=$line; - } - - if (is_array($message) || is_object($message)) { - $msg.=" + ".$prefix.print_r($message, true); - } else { - $msg.=" + ".$prefix.$message; - } - error_log($msg); + if (true === WP_GURUS_DEBUG) { + global $debug_msg_last_line,$debug_msg_last_file; + $backtrace = debug_backtrace(); + $file = $backtrace[0]['file']; + $line = $backtrace[0]['line']; + $files = explode('/',$file); + $dirs = explode('/',plugin_dir_path( __FILE__ )); + $files = array_diff($files,$dirs); + $file = implode('/',$files); + $msg='DEBUG_MSG:'.($trace?' --------------- ':''); + if (is_array($message) || is_object($message)) { + $msg.=$prefix.print_r($message, true); + } else { + $msg.=$prefix.$message; + } + if(true===$trace || ($file != $debug_msg_last_file && $line != $debug_msg_last_line)){ + if($trace===true){ + $trace = sizeof($backtrace); + $msg.=PHP_EOL; + } + for($idx=($trace-1); $idx>0; $idx--){ + $msg.='['.$backtrace[$idx]['line'].']->/'.$backtrace[$idx]['file'].PHP_EOL; + } + $msg.= ($trace?'':PHP_EOL)."/$file:$line"; + $debug_msg_last_file=$file; + $debug_msg_last_line=$line; + if($trace) $msg.=PHP_EOL.'-----------------------------------------------------'; } + error_log($msg); + } } } ?> diff --git a/languages/cf7-polylang.pot b/languages/cf7-polylang.pot old mode 100644 new mode 100755 diff --git a/languages/en_GB.mo b/languages/en_GB.mo old mode 100644 new mode 100755 diff --git a/languages/en_GB.po b/languages/en_GB.po old mode 100644 new mode 100755 diff --git a/languages/es_ES.mo b/languages/es_ES.mo old mode 100644 new mode 100755 diff --git a/languages/es_ES.po b/languages/es_ES.po old mode 100644 new mode 100755 diff --git a/languages/fr_FR.mo b/languages/fr_FR.mo old mode 100644 new mode 100755 diff --git a/languages/fr_FR.po b/languages/fr_FR.po old mode 100644 new mode 100755 diff --git a/public/class-cf7-polylang-public.php b/public/class-cf7-polylang-public.php index 0b63e7a..a35800e 100755 --- a/public/class-cf7-polylang-public.php +++ b/public/class-cf7-polylang-public.php @@ -63,7 +63,7 @@ public function __construct( $plugin_name, $version ) { * @return String translated id. **/ public function translate_form_id($id, $atts){ - $default_lang = pll_default_language('slug'); + // $default_lang = pll_default_language('slug'); $current_lang = pll_current_language('slug'); $form_id = pll_get_post($id, $current_lang); if(empty($form_id)){ //if a translation does not exists