Skip to content

Commit

Permalink
v2.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
aurovrata committed Oct 9, 2020
1 parent e6c306b commit c3d5f70
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 97 deletions.
2 changes: 2 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ function my_cf7_mail_tag($output, $name, $html ) {
4. Ensure you enable translations for Contact Forms in your Polyland settings.

== Changelog ==
= 2.3.4 =
* fix broken translations of new form templates.
= 2.3.3 =
* fix ZipArchive class missing Fatal error for PHP 7.3 onwards.
= 2.3.2 =
Expand Down
53 changes: 32 additions & 21 deletions admin/class-cf7-polylang-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,6 @@ public function add_language_select_to_table_page(){
</script>
<?php
}
/**
* Smart grid default form.
* Hooked to 'wpcf7_default_template'
* @since 2.0.0
* @param string $template the html string for the form tempalte
* @param string $prop the template property required.
* @return string default form.
*/
public function default_cf7_form($template, $prop){

if(!is_plugin_active( 'cf7-grid-layout/cf7-grid-layout.php' )) return $template;

if($prop !== 'form') return $template;
include( plugin_dir_path( __FILE__ ) . '/partials/cf7-default-form.php');
return $template;
}

/**
* Set the form edit page link.
Expand Down Expand Up @@ -317,7 +301,8 @@ public function get_cf7_translations(){
}
//which locales do we need to download, remove default locale en_US
$languages = array_diff($languages, $local_locales, array('en_US'));

debug_msg($languages, 'laguages ');
debug_msg($local_locales, 'locales ');
if(empty($languages)){
return true; //nothing to be loaded
}
Expand All @@ -334,6 +319,7 @@ public function get_cf7_translations(){
}else if( empty( $api['translations'] ) ){
debug_msg('CF7 POLYLANG: CF7 translations are empty, please try again');
}else{
debug_msg($api['translations'], 'api ');
foreach($api['translations'] as $translation){
$cf7_locales[$translation['language']] = $translation['package'];
}
Expand All @@ -359,10 +345,9 @@ public function get_cf7_translations(){
//delete zip file
unlink($zipFile);
//copy the .mo file to the CF7 language folder
if(! copy( WP_LANG_DIR . '/plugins/contact-form-7-'.$locale.'.mo',
WP_LANG_DIR . '/plugins/contact-form-7/contact-form-7-'.$locale.'.mo') ){
debug_msg("CF7 POLYLANG: Unable to copy CF7 translation for locale $zipFile to CF7 plugin folder.");
}
if(! file_exists( $extractPath . 'contact-form-7-'.$locale.'.mo') ){
debug_msg("CF7 POLYLANG: Unable to retrieve tranlsation file contact-form-7-$locale.mo");
}else debug_msg("CF7 POLYLANG: Added translation file contact-form-7-$locale.mo");
}
}else{
//we need to report the missing translation
Expand Down Expand Up @@ -465,4 +450,30 @@ public function cf7_tag_home_url($output, $name, $html ) {
}
return $output;
}
/**
* Filter cf7 template craetion arguments to ensure locales are picked up.
* Hooked to 'cf7sg_new_cf7_form_template_arguments'.
*@since 2.3.4
*@param array $args arument list for cf7 for template.
*@return string text_description
*/
public function new_form_template($args){
if(isset($_GET['locale'])){
$args['locale'] = $_GET['locale'];
}else if(isset($_GET['new_lang'])){
//check for polylang
$locale = $_GET['new_lang'];
if(function_exists('pll_languages_list')){
$langs = pll_languages_list();
$locales = pll_languages_list(array('fields'=>'locale'));
foreach($langs as $idx => $lang){
if($lang == $locale){
$locale = $locales[$idx];
}
}
}
$args['locale'] =$locale;
}else $args['locale'] = get_locale();
return $args;
}
}
66 changes: 0 additions & 66 deletions admin/partials/cf7-default-form.php

This file was deleted.

4 changes: 2 additions & 2 deletions cf7-polylang.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Plugin Name: Contact Form 7 Polylang extension
* Plugin URI: http://wordpress.syllogic.in
* Description: This plugin extends <a target="_blank" href="https://wordpress.org/plugins/contact-form-7/">Contact Form 7</a> plugin to manage multiple language forms using the <a target="_blank" href="https://wordpress.org/plugins/polylang/">PolyLang</a> plugin. It Requires both plugins to be active first.
* Version: 2.3.3
* Version: 2.3.4
* Author: Aurovrata V.
* Author URI: http://syllogic.in
* License: GPL-2.0+
Expand All @@ -30,7 +30,7 @@
die;
}
define( 'CF7_POLYLANG_PATH', plugin_dir_path( __FILE__ ) );
define( 'CF7_POLYLANG_VERSION', '2.3.3' );
define( 'CF7_POLYLANG_VERSION', '2.3.4' );
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-cf7-polylang-activator.php
Expand Down
10 changes: 2 additions & 8 deletions includes/class-cf7-polylang.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,9 @@ private function define_admin_hooks() {
$this->loader->add_action( 'admin_notices',$plugin_admin, 'display_polylang_settings_warning');
//modify the edit page 'add new' button link and add language select
$this->loader->add_action('admin_print_footer_scripts-edit.php',$plugin_admin, 'add_language_select_to_table_page',50);
//modify the edit page 'add new' button link and add language select
// $this->loader->add_action('admin_print_footer_scripts',$plugin_admin, 'add_default_cf7_plugin_table_script',50);
//catch cf7 delete redirection
// $this->loader->add_filter('wpcf7_post_delete',$plugin_admin, 'delete_post');
// $this->loader->add_action( 'before_delete_post', $plugin_admin, 'delete_post');
//make sure our dependent plugins exists.
$this->loader->add_action( 'admin_init', $plugin_admin, 'check_plugin_dependency');
/**** CF7 Hooks *****/
//set the default form for the smart grid plugin, and hook it just after that of the smart grid.
$this->loader->add_filter( 'wpcf7_default_template', $plugin_admin, 'default_cf7_form' , 6,2);
//persist admin notices plugin.
$this->loader->add_action( 'admin_init', 'PAnD', 'init' );
//admin notices display.
Expand All @@ -193,7 +186,8 @@ private function define_admin_hooks() {
$this->loader->add_filter( 'wpcf7_special_mail_tags', $plugin_admin, 'cf7_tag_site_url', 20, 3 );
/** @since 2.3.0 - add home_url mail tag. */
$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');
}


Expand Down

0 comments on commit c3d5f70

Please sign in to comment.