From df0766de6f92ab5a665e48de3ffe5c310b970239 Mon Sep 17 00:00:00 2001 From: meloniq Date: Wed, 7 Sep 2016 21:16:30 +0200 Subject: [PATCH 1/2] use new function cp_explode(), fix variable typo, register in wpml also escaped verions of checkbox values --- wpml-actions.php | 97 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 11 deletions(-) diff --git a/wpml-actions.php b/wpml-actions.php index eb7a596..a3cbdca 100644 --- a/wpml-actions.php +++ b/wpml-actions.php @@ -50,6 +50,10 @@ function app_wpml_orders_remove_language_metabox() { /** * Payments: language selector for frontend order pages * Orders are available only in one language, remove others from language selector + * + * @param array $languages + * + * @return array */ function app_wpml_orders_ls( $languages ) { global $sitepress, $post; @@ -61,10 +65,11 @@ function app_wpml_orders_ls( $languages ) { $languages = $sitepress->get_ls_languages( array( 'skip_missing' => false ) ); $url = get_permalink( $post->ID ); foreach ( $languages as $code => $lang ) { - if ( $code == $lang_code ) + if ( $code == $lang_code ) { $languages[ $code ]['url'] = $sitepress->convert_url( $url, $code ); - else + } else { unset( $languages[ $code ] ); + } } add_filter( 'icl_ls_languages', 'app_wpml_orders_ls' ); } @@ -76,12 +81,17 @@ function app_wpml_orders_ls( $languages ) { /** * ClassiPress: hook into cp_add_new_listing(), set proper language for new listing + * + * @param int $post_id + * + * @return void */ function app_wpml_cp_add_new_listing( $post_id ) { global $sitepress; - if ( $sitepress->get_current_language() == $sitepress->get_default_language() ) + if ( $sitepress->get_current_language() == $sitepress->get_default_language() ) { return; + } $post_type = get_post_type( $post_id ); $sitepress->set_element_language_details( $post_id, 'post_' . $post_type, null, $sitepress->get_current_language() ); @@ -91,6 +101,12 @@ function app_wpml_cp_add_new_listing( $post_id ) { /** * ClassiPress: hook into cp_get_ad_details() + * + * @param object $result + * @param object $post + * @param string $location + * + * @return object */ function app_wpml_cp_ad_details_field( $result, $post, $location ) { add_filter( 'cp_ad_details_' . $result->field_name, 'app_wpml_cp_ad_details_concrete_field', 10, 2 ); @@ -98,15 +114,26 @@ function app_wpml_cp_ad_details_field( $result, $post, $location ) { } add_filter( 'cp_ad_details_field', 'app_wpml_cp_ad_details_field', 10, 3 ); -function app_wpml_cp_ad_details_concrete_field ( $args, $field ) { + +/** + * @param array $args + * @param object $result + * + * @return array + */ +function app_wpml_cp_ad_details_concrete_field( $args, $field ) { $args['label'] = icl_translate( APP_TD, 'label_' . $field->field_name, $field->field_label ); $values = (array) $args['value']; if ( 'checkbox' === $field->field_type ) { - $values = explode( ',', $value ); - $values = array_map( 'trim', $value ); + if ( function_exists( 'cp_explode' ) ) { + $values = cp_explode( ',', $values ); + } else { + $values = explode( ',', $values ); + } + $values = array_map( 'trim', $values ); } foreach ( $values as &$value ) { @@ -118,17 +145,27 @@ function app_wpml_cp_ad_details_concrete_field ( $args, $field ) { return $args; } + /** * ClassiPress: hook into cp_formbuilder(), cp_formbuilder_review() + * + * @param object $result + * + * @return object */ function app_wpml_cp_formbuilder_field( $result ) { $result->field_label = icl_translate( APP_TD, 'label_' . $result->field_name, $result->field_label ); - if ( ! empty( $result->field_tooltip ) ) + if ( ! empty( $result->field_tooltip ) ) { $result->field_tooltip = icl_translate( APP_TD, 'tooltip_' . $result->field_name, $result->field_tooltip ); + } if ( ! empty( $result->field_values ) ) { - $options = explode( ',', $result->field_values ); + if ( function_exists( 'cp_explode' ) ) { + $options = cp_explode( ',', $result->field_values ); + } else { + $options = explode( ',', $result->field_values ); + } $new_options = array(); foreach ( $options as $option ) { $new_options[] = icl_t( APP_TD, 'value_' . $result->field_name . ' ' . trim( $option ), $option ); @@ -145,10 +182,16 @@ function app_wpml_cp_formbuilder_field( $result ) { /** * ClassiPress: hook into cp_package_field filter + * + * @param object $result + * @param string $type + * + * @return object */ function app_wpml_cp_package_field( $result, $type ) { $result->pack_name = icl_translate( APP_TD, 'pack_name_' . $result->pack_id, $result->pack_name ); $result->pack_desc = icl_translate( APP_TD, 'pack_desc_' . $result->pack_id, $result->pack_desc ); + return $result; } add_filter( 'cp_package_field', 'app_wpml_cp_package_field', 10, 2 ); @@ -156,6 +199,11 @@ function app_wpml_cp_package_field( $result, $type ) { /** * ClassiPress: hook into get_pack() + * + * @param object $package + * @param int $pack_id + * + * @return object */ function app_wpml_cp_get_package( $package, $pack_id ) { if ( ! empty( $package ) ) { @@ -169,6 +217,11 @@ function app_wpml_cp_get_package( $package, $pack_id ) { /** * ClassiPress: hook into cp_display_message() + * + * @param string $message + * @param string $tag + * + * @return string */ function app_wpml_cp_display_message( $message, $tag ) { return icl_translate( APP_TD, 'message_' . $tag, $message ); @@ -178,6 +231,11 @@ function app_wpml_cp_display_message( $message, $tag ) { /** * ClassiPress: hook into cp_custom_fields(), (un)registers strings immediately on maintaining custom fields + * + * @param string $action + * @param int $field_id + * + * @return void */ function app_wpml_cp_custom_fields( $action, $field_id ) { global $wpdb; @@ -191,7 +249,13 @@ function app_wpml_cp_custom_fields( $action, $field_id ) { icl_register_string( APP_TD, 'label_' . $field->field_name, $field->field_label ); icl_register_string( APP_TD, 'tooltip_' . $field->field_name, $field->field_tooltip ); if ( ! empty( $field->field_values ) ) { - $options = array_map( 'trim', explode( ',', $field->field_values ) ); + if ( function_exists( 'cp_explode' ) ) { + $options = array_map( 'trim', cp_explode( ',', $field->field_values ) ); + } else { + $options = array_map( 'trim', explode( ',', $field->field_values ) ); + } + $options_escaped = array_map( 'esc_attr', $options ); + $options = array_merge( $options, $options_escaped ); foreach ( $options as $option ) { icl_register_string( APP_TD, 'value_' . $field->field_name . ' ' . $option, $option ); } @@ -201,7 +265,13 @@ function app_wpml_cp_custom_fields( $action, $field_id ) { icl_unregister_string( APP_TD, 'label_' . $field->field_name, $field->field_label ); icl_unregister_string( APP_TD, 'tooltip_' . $field->field_name, $field->field_tooltip ); if ( ! empty( $field->field_values ) ) { - $options = array_map( 'trim', explode( ',', $field->field_values ) ); + if ( function_exists( 'cp_explode' ) ) { + $options = array_map( 'trim', cp_explode( ',', $field->field_values ) ); + } else { + $options = array_map( 'trim', explode( ',', $field->field_values ) ); + } + $options_escaped = array_map( 'esc_attr', $options ); + $options = array_merge( $options, $options_escaped ); foreach ( $options as $option ) { icl_unregister_string( APP_TD, 'value_' . $field->field_name . ' ' . $option, $option ); } @@ -233,6 +303,10 @@ function app_wpml_cp_form_layouts_show_all_categories() { /** * ClassiPress: language selector for frontend Edit Ad page + * + * @param array $languages + * + * @return array */ function app_wpml_cp_ls( $languages ) { global $sitepress, $post; @@ -267,8 +341,9 @@ function app_wpml_cp_ls( $languages ) { function app_wpml_cp_sticky_posts() { global $sitepress, $pagenow; - if ( ( $pagenow == 'edit.php' ) && ! isset( $_GET['post_type'] ) ) + if ( ( $pagenow == 'edit.php' ) && ! isset( $_GET['post_type'] ) ) { return; + } remove_filter( 'option_sticky_posts', array( $sitepress, 'option_sticky_posts' ) ); } From ab6d934681a09d4448b215b0342e2bc7757db128 Mon Sep 17 00:00:00 2001 From: meloniq Date: Wed, 7 Sep 2016 21:38:21 +0200 Subject: [PATCH 2/2] correct loading textdomain, update readme and pot file, bump version to 1.3, and tested version --- languages/appthemes-wpml.pot | 21 +++++++++++---------- readme.txt | 13 ++++++++++--- wpml.php | 30 +++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/languages/appthemes-wpml.pot b/languages/appthemes-wpml.pot index 7558e78..ccba1e1 100644 --- a/languages/appthemes-wpml.pot +++ b/languages/appthemes-wpml.pot @@ -1,36 +1,37 @@ +#, fuzzy msgid "" msgstr "" -"Project-Id-Version: AppThemes WPML Bridge 1.0\n" +"Project-Id-Version: AppThemes WPML Bridge\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-02-14 16:07+0100\n" +"POT-Creation-Date: 2016-09-07 21:33+0200\n" "PO-Revision-Date: 2013-02-14 16:07+0100\n" "Last-Translator: AppThemes\n" "Language-Team: AppThemes\n" -"Language: English\n" +"Language: en\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Poedit 1.5.5\n" +"X-Generator: Poedit 1.8.9\n" "X-Poedit-KeywordsList: __;_e;_n:1,2;_nx:1,2;_x:1,2c;_ex:1,2c;esc_attr__;" -"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;" -"_nx_noop:1,2,3c\n" +"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;" +"_n_noop:1,2;_nx_noop:1,2,3c\n" "X-Poedit-SourceCharset: UTF-8\n" "X-Poedit-Basepath: .\n" "X-Poedit-SearchPath-0: ..\n" -#: ../wpml.php:55 +#: ../wpml.php:75 msgid "AppThemes WPML Bridge could not run." msgstr "" -#: ../wpml.php:58 +#: ../wpml.php:78 msgid "AppThemes WPML Bridge does not support the current theme." msgstr "" -#: ../wpml.php:61 +#: ../wpml.php:82 msgid "AppThemes WPML Bridge require WPML Multilingual CMS plugin to work." msgstr "" -#: ../wpml.php:64 +#: ../wpml.php:86 msgid "AppThemes WPML Bridge require WPML String Translation plugin to work." msgstr "" diff --git a/readme.txt b/readme.txt index b06c315..ee580a5 100644 --- a/readme.txt +++ b/readme.txt @@ -1,9 +1,9 @@ === AppThemes WPML Bridge === Contributors: appthemes Tags: appthemes, wpml, integration, language, localization, multilingual, classipress -Requires at least: 3.4 -Tested up to: 3.6 -Stable tag: 1.2 +Requires at least: 4.0 +Tested up to: 4.6.1 +Stable tag: 1.3 This plugin adds additional WPML compatibility for AppThemes themes. @@ -43,6 +43,13 @@ Report it with details on [AppThemes support forum](http://forums.appthemes.com/ == Changelog == += 1.3 = + +* Use new function cp_explode() to properly handle checkbox values +* Register in WPML also escaped checkbox values +* Corrected loading plugin textdomain +* Fix typo in variable name + = 1.2 = * Make all fields labels and values translatable on the single ClassiPress Ad page diff --git a/wpml.php b/wpml.php index 6b7169c..dc5dfaa 100644 --- a/wpml.php +++ b/wpml.php @@ -1,32 +1,41 @@

' . $message . '

'; deactivate_plugins( plugin_basename( __FILE__ ) );