From 44f89a8d130905a6dcbc062ab8161d94df091f20 Mon Sep 17 00:00:00 2001 From: meloniq Date: Mon, 5 Aug 2013 20:00:59 +0200 Subject: [PATCH 01/11] import changes submitted by WPML team, needs testing and cleanup --- wpml-actions.php | 143 +++++++++++++++++++++++++++++++++++++++++++++++ wpml-config.xml | 1 + wpml.php | 4 +- 3 files changed, 146 insertions(+), 2 deletions(-) diff --git a/wpml-actions.php b/wpml-actions.php index 7e0ebe9..0f05d56 100644 --- a/wpml-actions.php +++ b/wpml-actions.php @@ -41,6 +41,15 @@ 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 ) ) $result->field_tooltip = icl_translate( APP_TD, 'tooltip_' . $result->field_name, $result->field_tooltip ); + if ( ! empty( $result->field_values ) ) { + $options = explode(',',$result->field_values); + $new_options = array(); + foreach ($options as $value) { + $new_options[] = icl_t('classipress','value_'.$result->field_name." ".trim($value),$value); + } + + $result->field_values = implode($new_options,','); + } return $result; } add_filter( 'cp_formbuilder_field', 'app_wpml_cp_formbuilder_field' ); @@ -80,3 +89,137 @@ function app_wpml_cp_display_message( $message, $tag ) { add_filter( 'cp_display_message', 'app_wpml_cp_display_message', 10, 2 ); +/** + * ClassiPress: language selector (for frontend edit-ad and order pages) + * + */ +function app_wpml_ls($languages) { + global $sitepress, $post; + $lang_code = $sitepress->get_current_language(); + + if (isset($_GET['aid'])) { + // edit ad + $aid = $_GET['aid']; + $trid = $sitepress->get_element_trid($aid,'post_ad_listing'); + $translations = $sitepress->get_element_translations($trid,'post_ad_listing'); + + foreach ($translations as $code => $translation) { + if ($code != $lang_code) { + $translated_aid = $translation->element_id; + $edit_page = $sitepress->language_url($code).'edit-item/'; + $url = add_query_arg('aid',$translated_aid,$edit_page); + $languages[$code]['url'] = $url; + } + } + } else if (is_singular() && empty($languages) && get_post_type() == 'transaction') { + //orders + remove_filter('icl_ls_languages','app_wpml_ls'); + $languages = $sitepress->get_ls_languages(array('skip_missing' => false)); + $url = get_permalink($post->ID); + foreach ($languages as $code => &$lang) { + $lang['url'] = $sitepress->convert_url($url,$code); + } + add_filter('icl_ls_languages','app_wpml_ls'); + } + return $languages; +} + +add_filter('icl_ls_languages','app_wpml_ls'); + +/** +* Classipress: filter registration url +*/ +function app_wpml_register($link) { + //

Registrarse

+ $url = appthemes_get_registration_url(); + return preg_replace('/href=".*"/s','href="'.$url.'"',$link); +} +add_filter('register','app_wpml_register'); + +/** +* Classipress: show categories in all languages for form layouts +* This way one can define a single form for all languages, with custom +* field labels translated through string translation +*/ + + + +function show_all_categories_in_form_properties() { + if (isset($_GET['action']) && + in_array($_GET['action'], array('editform','addform')) && + (!isset($_GET['lang']))) { //|| $_GET['lang'] != 'all') + $url = add_query_arg('lang','all'); + wp_redirect($url); + } +} + +add_action('init','show_all_categories_in_form_properties'); + +function app_wpml_custom_fields($action,$field_id) { + global $wpdb; + + $query = "SELECT * FROM {$wpdb->prefix}cp_ad_fields WHERE field_id=%d"; + $field = $wpdb->get_row($wpdb->prepare($query,$field_id)); + + switch($action) { + case 'addfield': + case 'editfield': + icl_register_string('classipress','label_'.$field->field_name,$field->field_label); + icl_register_string('classipress','tooltip_'.$field->field_name,$field->field_tooltip); + if (!empty($field->field_values)) { + $options = array_map('trim',explode( ',', $field->field_values )); + foreach($options as $val) { + icl_register_string('classipress','value_'.$field->field_name." $val",$val); + } + } + break; + case 'delete': + icl_unregister_string('classipress','label_'.$field->field_name,$field->field_label); + icl_unregister_string('classipress','tooltip_'.$field->field_name,$field->field_tooltip); + if (!empty($field->field_values)) { + $options = array_map('trim',explode( ',', $field->field_values )); + foreach($options as $val) { + icl_unregister_string('classipress','value_'.$field->field_name." $val",$val); + } + } + break; + default: error_log('Invalid action in '.__FUNCTION__); + break; + } + +} + +add_action('cp_custom_fields','app_wpml_custom_fields',10,2); + +function app_wpml_custom_field_values($options, $field_name) { + $translated_options = array(); + foreach ($options as $value) { + $translated_options[] = icl_t('classipress','value_'.$field_name,$value); + } + + return $translated_options; +} + +add_filter('cp_custom_field_values','app_wpml_custom_field_values'); + +function app_wpml_convert_url($url) { + global $sitepress; + return $sitepress->convert_url($url); +} + +add_filter( 'appthemes_order_return_url','app_wpml_convert_url'); +//add_filter('register','app_wpml_convert_url'); + +/** +* Orders +*/ + +function app_wpml_create_order($order_id,$order) { + global $sitepress; + if ($order->post_type != 'transaction') + return; + $sitepress->set_element_language_details( $order_id, 'post_transaction', null, $sitepress->get_current_language() ); +} + +add_action('save_post','app_wpml_create_order',20,2); //after WPML's save_post_actions + diff --git a/wpml-config.xml b/wpml-config.xml index 566dde0..3f0c25e 100644 --- a/wpml-config.xml +++ b/wpml-config.xml @@ -1,6 +1,7 @@ ad_listing + transaction ad_cat diff --git a/wpml.php b/wpml.php index 34df242..9f9d1c5 100644 --- a/wpml.php +++ b/wpml.php @@ -5,7 +5,7 @@ AppThemes ID: appthemes-wpml -Version: 1.0 +Version: 3.0 Author: AppThemes Author URI: http://appthemes.com Text Domain: appthemes-wpml @@ -15,7 +15,7 @@ /** * Plugin version and textdomain constants. */ -define( 'APP_WPML_VERSION', '1.0' ); +define( 'APP_WPML_VERSION', '3.0' ); define( 'APP_WPML_TD', 'appthemes-wpml' ); From a7a1065ae0c2cb22fc122d3a2c1fdbb502481876 Mon Sep 17 00:00:00 2001 From: meloniq Date: Fri, 16 Aug 2013 20:28:47 +0400 Subject: [PATCH 02/11] correct code formatting, minor corrections, add proper function doc headers, and personal comments on some of them --- wpml-actions.php | 231 +++++++++++++++++++++++++---------------------- wpml-config.xml | 14 +-- 2 files changed, 130 insertions(+), 115 deletions(-) diff --git a/wpml-actions.php b/wpml-actions.php index 0f05d56..3f2289d 100644 --- a/wpml-actions.php +++ b/wpml-actions.php @@ -10,6 +10,33 @@ function app_wpml_appthemes_page_id_for_template( $page_id, $template ) { add_filter( 'appthemes_page_id_for_template', 'app_wpml_appthemes_page_id_for_template', 10, 2 ); +/** + * Payments: Set proper language for new order + * Note: Orders probably should be excluded from localization ?! + */ +function app_wpml_create_order( $order_id, $order ) { + global $sitepress; + + if ( $order->post_type != 'transaction' ) + return; + + $sitepress->set_element_language_details( $order_id, 'post_transaction', null, $sitepress->get_current_language() ); +} +add_action( 'save_post', 'app_wpml_create_order', 20, 2 ); // after WPML's save_post_actions + + +/** + * Payments: Add language parameter to url + * Note: Orders probably should be excluded from localization ?! + */ +function app_wpml_appthemes_order_return_url( $url ) { + global $sitepress; + + return $sitepress->convert_url( $url ); +} +add_filter( 'appthemes_order_return_url', 'app_wpml_appthemes_order_return_url' ); + + /** * ClassiPress: hook into cp_add_new_listing(), set proper language for new listing */ @@ -24,6 +51,7 @@ function app_wpml_cp_add_new_listing( $post_id ) { } add_action( 'cp_action_add_new_listing', 'app_wpml_cp_add_new_listing' ); + /** * ClassiPress: hook into cp_get_ad_details() */ @@ -39,17 +67,20 @@ function app_wpml_cp_ad_details_field( $result, $post, $location ) { */ 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 ) ) $result->field_tooltip = icl_translate( APP_TD, 'tooltip_' . $result->field_name, $result->field_tooltip ); - if ( ! empty( $result->field_values ) ) { - $options = explode(',',$result->field_values); - $new_options = array(); - foreach ($options as $value) { - $new_options[] = icl_t('classipress','value_'.$result->field_name." ".trim($value),$value); - } - - $result->field_values = implode($new_options,','); + + if ( ! empty( $result->field_values ) ) { + $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 ); + } + + $result->field_values = implode( $new_options, ',' ); } + return $result; } add_filter( 'cp_formbuilder_field', 'app_wpml_cp_formbuilder_field' ); @@ -89,137 +120,121 @@ function app_wpml_cp_display_message( $message, $tag ) { add_filter( 'cp_display_message', 'app_wpml_cp_display_message', 10, 2 ); +/** + * ClassiPress: hook into cp_custom_fields(), (un)registers strings immediately on maintaining custom fields + */ +function app_wpml_cp_custom_fields( $action, $field_id ) { + global $wpdb; + + $query = "SELECT * FROM $wpdb->cp_ad_fields WHERE field_id = %d"; + $field = $wpdb->get_row( $wpdb->prepare( $query, $field_id ) ); + + switch ( $action ) { + case 'addfield': + case 'editfield': + 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 ) ); + foreach ( $options as $option ) { + icl_register_string( APP_TD, 'value_' . $field->field_name . ' ' . $option, $option ); + } + } + break; + case 'delete': + 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 ) ); + foreach ( $options as $option ) { + icl_unregister_string( APP_TD, 'value_' . $field->field_name . ' ' . $option, $option ); + } + } + break; + default: + break; + } + +} +add_action( 'cp_custom_fields', 'app_wpml_cp_custom_fields', 10, 2 ); + + /** * ClassiPress: language selector (for frontend edit-ad and order pages) - * + * Note: Needs testing */ -function app_wpml_ls($languages) { +function app_wpml_ls( $languages ) { global $sitepress, $post; $lang_code = $sitepress->get_current_language(); - if (isset($_GET['aid'])) { - // edit ad + // CP: Edit ad + if ( isset( $_GET['aid'] ) ) { $aid = $_GET['aid']; - $trid = $sitepress->get_element_trid($aid,'post_ad_listing'); - $translations = $sitepress->get_element_translations($trid,'post_ad_listing'); + $trid = $sitepress->get_element_trid( $aid, 'post_ad_listing' ); + $translations = $sitepress->get_element_translations( $trid, 'post_ad_listing' ); - foreach ($translations as $code => $translation) { - if ($code != $lang_code) { + foreach ( $translations as $code => $translation ) { + if ( $code != $lang_code ) { $translated_aid = $translation->element_id; - $edit_page = $sitepress->language_url($code).'edit-item/'; - $url = add_query_arg('aid',$translated_aid,$edit_page); - $languages[$code]['url'] = $url; + $edit_page = $sitepress->language_url( $code ) . 'edit-item/'; + $url = add_query_arg( 'aid', $translated_aid, $edit_page ); + $languages[ $code ]['url'] = $url; } } - } else if (is_singular() && empty($languages) && get_post_type() == 'transaction') { - //orders - remove_filter('icl_ls_languages','app_wpml_ls'); - $languages = $sitepress->get_ls_languages(array('skip_missing' => false)); - $url = get_permalink($post->ID); - foreach ($languages as $code => &$lang) { - $lang['url'] = $sitepress->convert_url($url,$code); + // Orders + } else if ( is_singular() && empty( $languages ) && get_post_type() == 'transaction' ) { + remove_filter( 'icl_ls_languages', 'app_wpml_ls' ); + $languages = $sitepress->get_ls_languages( array( 'skip_missing' => false ) ); + $url = get_permalink( $post->ID ); + foreach ( $languages as $code => &$lang ) { + $lang['url'] = $sitepress->convert_url( $url, $code ); } - add_filter('icl_ls_languages','app_wpml_ls'); + add_filter( 'icl_ls_languages', 'app_wpml_ls' ); } return $languages; } +add_filter( 'icl_ls_languages', 'app_wpml_ls' ); -add_filter('icl_ls_languages','app_wpml_ls'); /** -* Classipress: filter registration url -*/ -function app_wpml_register($link) { - //

Registrarse

+ * WP: filter registration url + * Note: We use in framework new WP filter for this purpose ?! + */ +function app_wpml_register( $link ) { $url = appthemes_get_registration_url(); - return preg_replace('/href=".*"/s','href="'.$url.'"',$link); + return preg_replace( '/href=".*"/s', 'href="' . $url . '"', $link ); } -add_filter('register','app_wpml_register'); - -/** -* Classipress: show categories in all languages for form layouts -* This way one can define a single form for all languages, with custom -* field labels translated through string translation -*/ - +add_filter( 'register', 'app_wpml_register' ); +/** + * ClassiPress: show categories in all languages for form layouts + * This way one can define a single form for all languages, with custom + * field labels translated through string translation + * + * Note: Need testing, and refine it to admin only + */ function show_all_categories_in_form_properties() { - if (isset($_GET['action']) && - in_array($_GET['action'], array('editform','addform')) && - (!isset($_GET['lang']))) { //|| $_GET['lang'] != 'all') - $url = add_query_arg('lang','all'); - wp_redirect($url); + if ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'editform', 'addform' ) ) && ( ! isset( $_GET['lang'] ) ) ) { + $url = add_query_arg( 'lang', 'all' ); + wp_redirect( $url ); } } +add_action( 'init', 'show_all_categories_in_form_properties' ); -add_action('init','show_all_categories_in_form_properties'); -function app_wpml_custom_fields($action,$field_id) { - global $wpdb; - - $query = "SELECT * FROM {$wpdb->prefix}cp_ad_fields WHERE field_id=%d"; - $field = $wpdb->get_row($wpdb->prepare($query,$field_id)); - - switch($action) { - case 'addfield': - case 'editfield': - icl_register_string('classipress','label_'.$field->field_name,$field->field_label); - icl_register_string('classipress','tooltip_'.$field->field_name,$field->field_tooltip); - if (!empty($field->field_values)) { - $options = array_map('trim',explode( ',', $field->field_values )); - foreach($options as $val) { - icl_register_string('classipress','value_'.$field->field_name." $val",$val); - } - } - break; - case 'delete': - icl_unregister_string('classipress','label_'.$field->field_name,$field->field_label); - icl_unregister_string('classipress','tooltip_'.$field->field_name,$field->field_tooltip); - if (!empty($field->field_values)) { - $options = array_map('trim',explode( ',', $field->field_values )); - foreach($options as $val) { - icl_unregister_string('classipress','value_'.$field->field_name." $val",$val); - } - } - break; - default: error_log('Invalid action in '.__FUNCTION__); - break; - } - -} - -add_action('cp_custom_fields','app_wpml_custom_fields',10,2); - -function app_wpml_custom_field_values($options, $field_name) { +/** + * ClassiPress + * Note: We not have an 'cp_custom_field_values' filter ?! + */ +function app_wpml_custom_field_values( $options, $field_name ) { $translated_options = array(); - foreach ($options as $value) { - $translated_options[] = icl_t('classipress','value_'.$field_name,$value); + foreach ( $options as $option ) { + $translated_options[] = icl_t( APP_TD, 'value_' . $field_name, $option ); } return $translated_options; } +add_filter( 'cp_custom_field_values', 'app_wpml_custom_field_values' ); -add_filter('cp_custom_field_values','app_wpml_custom_field_values'); - -function app_wpml_convert_url($url) { - global $sitepress; - return $sitepress->convert_url($url); -} - -add_filter( 'appthemes_order_return_url','app_wpml_convert_url'); -//add_filter('register','app_wpml_convert_url'); - -/** -* Orders -*/ - -function app_wpml_create_order($order_id,$order) { - global $sitepress; - if ($order->post_type != 'transaction') - return; - $sitepress->set_element_language_details( $order_id, 'post_transaction', null, $sitepress->get_current_language() ); -} - -add_action('save_post','app_wpml_create_order',20,2); //after WPML's save_post_actions diff --git a/wpml-config.xml b/wpml-config.xml index 3f0c25e..063fbe2 100644 --- a/wpml-config.xml +++ b/wpml-config.xml @@ -1,10 +1,10 @@ - - ad_listing - transaction - - - ad_cat + + ad_listing + transaction + + + ad_cat ad_tag - + From e3bf6ad5a8e637ae4c7e4611b5ba04fc49c1dd4a Mon Sep 17 00:00:00 2001 From: meloniq Date: Fri, 16 Aug 2013 20:45:52 +0400 Subject: [PATCH 03/11] remove function that apply on filter which does not exist --- wpml-actions.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/wpml-actions.php b/wpml-actions.php index 3f2289d..fde44e2 100644 --- a/wpml-actions.php +++ b/wpml-actions.php @@ -223,18 +223,3 @@ function show_all_categories_in_form_properties() { add_action( 'init', 'show_all_categories_in_form_properties' ); -/** - * ClassiPress - * Note: We not have an 'cp_custom_field_values' filter ?! - */ -function app_wpml_custom_field_values( $options, $field_name ) { - $translated_options = array(); - foreach ( $options as $option ) { - $translated_options[] = icl_t( APP_TD, 'value_' . $field_name, $option ); - } - - return $translated_options; -} -add_filter( 'cp_custom_field_values', 'app_wpml_custom_field_values' ); - - From 04b90f1be432a8d51df0ce8bf434b1cec5f73bbf Mon Sep 17 00:00:00 2001 From: meloniq Date: Fri, 16 Aug 2013 20:51:40 +0400 Subject: [PATCH 04/11] remove registration filter, we already have it, see Framework#140 --- wpml-actions.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/wpml-actions.php b/wpml-actions.php index fde44e2..3b9252d 100644 --- a/wpml-actions.php +++ b/wpml-actions.php @@ -196,17 +196,6 @@ function app_wpml_ls( $languages ) { add_filter( 'icl_ls_languages', 'app_wpml_ls' ); -/** - * WP: filter registration url - * Note: We use in framework new WP filter for this purpose ?! - */ -function app_wpml_register( $link ) { - $url = appthemes_get_registration_url(); - return preg_replace( '/href=".*"/s', 'href="' . $url . '"', $link ); -} -add_filter( 'register', 'app_wpml_register' ); - - /** * ClassiPress: show categories in all languages for form layouts * This way one can define a single form for all languages, with custom From 88f847d5c02d188a343372e5704d2870ac57ce85 Mon Sep 17 00:00:00 2001 From: meloniq Date: Fri, 16 Aug 2013 21:10:45 +0400 Subject: [PATCH 05/11] fix orders url --- wpml-actions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpml-actions.php b/wpml-actions.php index 3b9252d..ea002f5 100644 --- a/wpml-actions.php +++ b/wpml-actions.php @@ -32,7 +32,7 @@ function app_wpml_create_order( $order_id, $order ) { function app_wpml_appthemes_order_return_url( $url ) { global $sitepress; - return $sitepress->convert_url( $url ); + return str_replace( '&', '&', $sitepress->convert_url( $url ) ); } add_filter( 'appthemes_order_return_url', 'app_wpml_appthemes_order_return_url' ); From cf4980ed3303266d96593ecaf95b4a3876ad1a0b Mon Sep 17 00:00:00 2001 From: meloniq Date: Fri, 16 Aug 2013 21:36:38 +0400 Subject: [PATCH 06/11] remove language metabox for orders --- wpml-actions.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wpml-actions.php b/wpml-actions.php index ea002f5..e67e74d 100644 --- a/wpml-actions.php +++ b/wpml-actions.php @@ -37,6 +37,16 @@ function app_wpml_appthemes_order_return_url( $url ) { add_filter( 'appthemes_order_return_url', 'app_wpml_appthemes_order_return_url' ); +/** + * Payments: Removes language metabox for orders + */ +function app_wpml_orders_remove_language_metabox() { + + remove_meta_box( 'icl_div', 'transaction', 'side' ); +} +add_action( 'admin_head', 'app_wpml_orders_remove_language_metabox', 11 ); + + /** * ClassiPress: hook into cp_add_new_listing(), set proper language for new listing */ From 897371565445a3ab9185577dba5d3174fd64859b Mon Sep 17 00:00:00 2001 From: meloniq Date: Fri, 16 Aug 2013 21:56:32 +0400 Subject: [PATCH 07/11] refine layouts lang redirect to show all categories, rename function --- wpml-actions.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/wpml-actions.php b/wpml-actions.php index e67e74d..24ca633 100644 --- a/wpml-actions.php +++ b/wpml-actions.php @@ -169,6 +169,22 @@ function app_wpml_cp_custom_fields( $action, $field_id ) { add_action( 'cp_custom_fields', 'app_wpml_cp_custom_fields', 10, 2 ); +/** + * ClassiPress: show categories in all languages for form layouts + * This way one can define a single form for all languages, with custom + * field labels translated through string translation + */ +function app_wpml_cp_form_layouts_show_all_categories() { + if ( isset( $_GET['page'] ) && isset( $_GET['action'] ) && ! isset( $_GET['lang'] ) ) { + if ( ( $_GET['page'] == 'layouts' ) && in_array( $_GET['action'], array( 'editform', 'addform' ) ) ) { + $url = add_query_arg( 'lang', 'all' ); + wp_redirect( $url ); + } + } +} +add_action( 'admin_init', 'app_wpml_cp_form_layouts_show_all_categories' ); + + /** * ClassiPress: language selector (for frontend edit-ad and order pages) * Note: Needs testing @@ -206,19 +222,3 @@ function app_wpml_ls( $languages ) { add_filter( 'icl_ls_languages', 'app_wpml_ls' ); -/** - * ClassiPress: show categories in all languages for form layouts - * This way one can define a single form for all languages, with custom - * field labels translated through string translation - * - * Note: Need testing, and refine it to admin only - */ -function show_all_categories_in_form_properties() { - if ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'editform', 'addform' ) ) && ( ! isset( $_GET['lang'] ) ) ) { - $url = add_query_arg( 'lang', 'all' ); - wp_redirect( $url ); - } -} -add_action( 'init', 'show_all_categories_in_form_properties' ); - - From b722fc034a97fb60bdec376bfe8f8b3f7910619c Mon Sep 17 00:00:00 2001 From: meloniq Date: Fri, 16 Aug 2013 22:18:47 +0400 Subject: [PATCH 08/11] divide language selector filter on 2, for cp, and for orders --- wpml-actions.php | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/wpml-actions.php b/wpml-actions.php index 24ca633..0064b5e 100644 --- a/wpml-actions.php +++ b/wpml-actions.php @@ -47,6 +47,29 @@ function app_wpml_orders_remove_language_metabox() { add_action( 'admin_head', 'app_wpml_orders_remove_language_metabox', 11 ); +/** + * Payments: language selector (for frontend order pages) + */ +function app_wpml_orders_ls( $languages ) { + global $sitepress, $post; + + $lang_code = $sitepress->get_current_language(); + + if ( is_singular() && empty( $languages ) && get_post_type() == 'transaction' ) { + remove_filter( 'icl_ls_languages', 'app_wpml_orders_ls' ); + $languages = $sitepress->get_ls_languages( array( 'skip_missing' => false ) ); + $url = get_permalink( $post->ID ); + foreach ( $languages as $code => &$lang ) { + $lang['url'] = $sitepress->convert_url( $url, $code ); + } + add_filter( 'icl_ls_languages', 'app_wpml_orders_ls' ); + } + + return $languages; +} +add_filter( 'icl_ls_languages', 'app_wpml_orders_ls' ); + + /** * ClassiPress: hook into cp_add_new_listing(), set proper language for new listing */ @@ -186,15 +209,14 @@ function app_wpml_cp_form_layouts_show_all_categories() { /** - * ClassiPress: language selector (for frontend edit-ad and order pages) - * Note: Needs testing + * ClassiPress: language selector (for frontend edit-ad page) */ -function app_wpml_ls( $languages ) { +function app_wpml_cp_ls( $languages ) { global $sitepress, $post; + $lang_code = $sitepress->get_current_language(); - // CP: Edit ad - if ( isset( $_GET['aid'] ) ) { + if ( is_page_template( 'tpl-edit-item.php' ) && isset( $_GET['aid'] ) ) { $aid = $_GET['aid']; $trid = $sitepress->get_element_trid( $aid, 'post_ad_listing' ); $translations = $sitepress->get_element_translations( $trid, 'post_ad_listing' ); @@ -207,18 +229,10 @@ function app_wpml_ls( $languages ) { $languages[ $code ]['url'] = $url; } } - // Orders - } else if ( is_singular() && empty( $languages ) && get_post_type() == 'transaction' ) { - remove_filter( 'icl_ls_languages', 'app_wpml_ls' ); - $languages = $sitepress->get_ls_languages( array( 'skip_missing' => false ) ); - $url = get_permalink( $post->ID ); - foreach ( $languages as $code => &$lang ) { - $lang['url'] = $sitepress->convert_url( $url, $code ); - } - add_filter( 'icl_ls_languages', 'app_wpml_ls' ); } + return $languages; } -add_filter( 'icl_ls_languages', 'app_wpml_ls' ); +add_filter( 'icl_ls_languages', 'app_wpml_cp_ls' ); From e84a732b43e243d04466076bc62d3fb94cd6080e Mon Sep 17 00:00:00 2001 From: meloniq Date: Fri, 16 Aug 2013 22:41:44 +0400 Subject: [PATCH 09/11] fix language selector for edit ad page --- wpml-actions.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wpml-actions.php b/wpml-actions.php index 0064b5e..ffcfc0e 100644 --- a/wpml-actions.php +++ b/wpml-actions.php @@ -209,7 +209,7 @@ function app_wpml_cp_form_layouts_show_all_categories() { /** - * ClassiPress: language selector (for frontend edit-ad page) + * ClassiPress: language selector for frontend Edit Ad page */ function app_wpml_cp_ls( $languages ) { global $sitepress, $post; @@ -224,9 +224,11 @@ function app_wpml_cp_ls( $languages ) { foreach ( $translations as $code => $translation ) { if ( $code != $lang_code ) { $translated_aid = $translation->element_id; - $edit_page = $sitepress->language_url( $code ) . 'edit-item/'; + $edit_page = $sitepress->convert_url( get_permalink( CP_Edit_Item::get_id() ), $code ); $url = add_query_arg( 'aid', $translated_aid, $edit_page ); $languages[ $code ]['url'] = $url; + } else { + $languages[ $code ]['url'] = add_query_arg( 'aid', $aid ); } } } From 8bee2e2aadf8b2174a303e12b95023faf8474f98 Mon Sep 17 00:00:00 2001 From: meloniq Date: Sat, 17 Aug 2013 00:23:29 +0400 Subject: [PATCH 10/11] remove other not available languages from selector for orders --- wpml-actions.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/wpml-actions.php b/wpml-actions.php index ffcfc0e..1eadbbd 100644 --- a/wpml-actions.php +++ b/wpml-actions.php @@ -48,19 +48,23 @@ function app_wpml_orders_remove_language_metabox() { /** - * Payments: language selector (for frontend order pages) + * Payments: language selector for frontend order pages + * Orders are available only in one language, remove others from language selector */ function app_wpml_orders_ls( $languages ) { global $sitepress, $post; $lang_code = $sitepress->get_current_language(); - if ( is_singular() && empty( $languages ) && get_post_type() == 'transaction' ) { + if ( is_singular() && get_post_type() == 'transaction' ) { remove_filter( 'icl_ls_languages', 'app_wpml_orders_ls' ); $languages = $sitepress->get_ls_languages( array( 'skip_missing' => false ) ); $url = get_permalink( $post->ID ); - foreach ( $languages as $code => &$lang ) { - $lang['url'] = $sitepress->convert_url( $url, $code ); + foreach ( $languages as $code => $lang ) { + if ( $code == $lang_code ) + $languages[ $code ]['url'] = $sitepress->convert_url( $url, $code ); + else + unset( $languages[ $code ] ); } add_filter( 'icl_ls_languages', 'app_wpml_orders_ls' ); } From b0dd88de37436572186416c1379534df3409a567 Mon Sep 17 00:00:00 2001 From: meloniq Date: Sat, 17 Aug 2013 12:58:32 +0400 Subject: [PATCH 11/11] remove WPML sticky posts filtering, see CP LH 1209 --- wpml-actions.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wpml-actions.php b/wpml-actions.php index 1eadbbd..725fdbe 100644 --- a/wpml-actions.php +++ b/wpml-actions.php @@ -242,3 +242,19 @@ function app_wpml_cp_ls( $languages ) { add_filter( 'icl_ls_languages', 'app_wpml_cp_ls' ); +/** + * ClassiPress: Removes WPML sticky posts filtering which isn't working well with CP + */ +function app_wpml_cp_sticky_posts() { + global $sitepress, $pagenow; + + if ( ( $pagenow == 'edit.php' ) && ! isset( $_GET['post_type'] ) ) + return; + + remove_filter( 'option_sticky_posts', array( $sitepress, 'option_sticky_posts' ) ); +} +add_action( 'init', 'app_wpml_cp_sticky_posts', 11 ); +add_action( 'admin_init', 'app_wpml_cp_sticky_posts', 11 ); +add_action( 'admin_head', 'app_wpml_cp_sticky_posts', 11 ); + +