diff --git a/wpml-actions.php b/wpml-actions.php index 7e0ebe9..725fdbe 100644 --- a/wpml-actions.php +++ b/wpml-actions.php @@ -10,6 +10,70 @@ 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 str_replace( '&', '&', $sitepress->convert_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 ); + + +/** + * 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() && 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 ) { + 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' ); + } + + return $languages; +} +add_filter( 'icl_ls_languages', 'app_wpml_orders_ls' ); + + /** * ClassiPress: hook into cp_add_new_listing(), set proper language for new listing */ @@ -24,6 +88,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,8 +104,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 $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' ); @@ -80,3 +157,104 @@ 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: 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 page + */ +function app_wpml_cp_ls( $languages ) { + global $sitepress, $post; + + $lang_code = $sitepress->get_current_language(); + + 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' ); + + foreach ( $translations as $code => $translation ) { + if ( $code != $lang_code ) { + $translated_aid = $translation->element_id; + $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 ); + } + } + } + + return $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 ); + + diff --git a/wpml-config.xml b/wpml-config.xml index 566dde0..063fbe2 100644 --- a/wpml-config.xml +++ b/wpml-config.xml @@ -1,9 +1,10 @@ - - ad_listing - - - ad_cat + + ad_listing + transaction + + + ad_cat ad_tag - + 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' );