Skip to content

Commit

Permalink
v2.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
aurovrata committed Jan 12, 2022
1 parent b92b8f0 commit 6642e35
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 29 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
6 changes: 4 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,14 +137,16 @@ 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.
3. Creating a new translation form, with polylang language metabox options.
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.
Expand Down
35 changes: 34 additions & 1 deletion admin/class-cf7-polylang-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -521,7 +522,6 @@ protected function load_l10n_domains($locale){
$locale = $locales[0];
}
}

if ( is_textdomain_loaded( $plugin ) ) {
unload_textdomain( $plugin );
}
Expand All @@ -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;
}
}
Empty file modified assets/persist-admin-notices/dismiss-notice.js
100644 → 100755
Empty file.
Empty file.
Empty file modified changelog.txt
100644 → 100755
Empty file.
3 changes: 3 additions & 0 deletions includes/class-cf7-polylang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
59 changes: 34 additions & 25 deletions includes/wordpress-gurus-debug-api.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
} ?>
Empty file modified languages/cf7-polylang.pot
100644 → 100755
Empty file.
Empty file modified languages/en_GB.mo
100644 → 100755
Empty file.
Empty file modified languages/en_GB.po
100644 → 100755
Empty file.
Empty file modified languages/es_ES.mo
100644 → 100755
Empty file.
Empty file modified languages/es_ES.po
100644 → 100755
Empty file.
Empty file modified languages/fr_FR.mo
100644 → 100755
Empty file.
Empty file modified languages/fr_FR.po
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion public/class-cf7-polylang-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6642e35

Please sign in to comment.