Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

DC patch v.2.4.2 #188

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
651a87d
Merge tag '2.4.1' into develop
VaLeXaR Oct 28, 2019
709bdd5
fixed translate '_post_name' tag in CF7
Oct 30, 2019
978594e
Add Integration for Elementor plugin.
aubvmk Dec 9, 2019
12deec5
Add Integration for Elementor plugin. (#134)
VaLeXaR Dec 12, 2019
f1d0cea
fix translate escaping text
VaLeXaR Jan 8, 2020
7c5f722
Merge remote-tracking branch 'origin/develop' into develop
VaLeXaR Jan 8, 2020
4c706d5
Make sure ACF Gutenberg Blocks render properly with wysiwyg, text and…
damircalusic Feb 28, 2021
9ec27b4
Made sure that ACF options pages are translating
damircalusic Apr 18, 2021
7d00968
Fix translation of the "title" attribute in the shortcode of Contact …
damircalusic May 7, 2021
4cd1597
Added support for WordPress update_{$meta_type}_metadata_by_mid funct…
damircalusic May 7, 2021
fbcc11d
Fix so flag width and height outputs properly on wpml langauge listin…
damircalusic May 7, 2021
cc0906c
Fix so flag width and height outputs properly on wpml langauge listin…
damircalusic May 7, 2021
f4d6850
Fix of wpseo_og:locale:alternate to be set properly
damircalusic May 7, 2021
43a91d3
Added support for ACF repeater field and ACF image field
damircalusic May 7, 2021
0852975
Fix post title "Auto Draft" bug
damircalusic May 7, 2021
5508a8a
Fix Rank Math custom fields getting duplicated on the translated posts
damircalusic May 7, 2021
bc39204
Fix display of alternate links when languages are selected in WP Dash…
damircalusic May 7, 2021
e36b3c4
Added Russian language (thanks @Balya)
damircalusic May 7, 2021
4a660fa
Update of Readme
damircalusic May 7, 2021
e189e8c
Changed version
damircalusic May 7, 2021
9a7dcc3
Changed wp_localize_script to wp_add_inline_script du to deprecation …
damircalusic May 8, 2021
85112ed
Changed wp_localize_script to wp_add_inline_script du to deprecation …
damircalusic May 8, 2021
7a7a7fc
Changed wp_localize_script to wp_add_inline_script du to deprecation …
damircalusic May 8, 2021
a6c8413
Changed wp_localize_script to wp_add_inline_script du to deprecation …
damircalusic May 8, 2021
7d6ad71
Changed wp_localize_script to wp_add_inline_script du to deprecation …
damircalusic May 8, 2021
f29aa57
Update readme.txt
damircalusic May 8, 2021
7655f40
Fixed a Class for Yoast SEO Presenters
damircalusic May 8, 2021
4c1f39a
Fixed compatibilty for Yoast SEO version 14+ for open graph meta
damircalusic May 8, 2021
dc533a6
Update readme.txt
damircalusic May 8, 2021
3eb3057
Fixed (admin_html_tags) leaving empty fields
damircalusic May 9, 2021
a08724b
Fixed (admin_html_tags) leaving empty fields
damircalusic May 9, 2021
1e7f86d
Update readme.txt
damircalusic May 9, 2021
f07099b
Removed error_log()
damircalusic May 26, 2021
ed59021
Fixed shop_order translation and an option setting for wc_settings
damircalusic Aug 6, 2021
d31c2e8
Merge pull request #1 from damircalusic/dc-patch-v.2.4.3
damircalusic Aug 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/scripts/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ var wpm_translator = {

blocks.forEach(function(block, index) {
if (index % 2 === 1) {
lang = block;
} else if (!!results[lang]) {
lang = block.replace(/\[|\]|:/g,'');
} else if (lang in results) {
results[lang] += block.trim();
}
});
Expand Down
2 changes: 1 addition & 1 deletion assets/scripts/translator.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions configs/plugins/elementor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"post_fields": {
"_elementor_data": {},
"_elementor_css": {},
"_elementor_controls_usage": {}
}
}
20 changes: 18 additions & 2 deletions configs/plugins/seo-by-rank-math.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,24 @@
"rank_math_rich_snippet": {},
"rank_math_facebook_title": {},
"rank_math_facebook_description": {},
"rank_math_snippet_name": {},
"rank_math_snippet_desc": {},
"rank_math_snippet_article_type": {},
"rank_math_facebook_enable_image_overlay": {},
"rank_math_facebook_image_id": {},
"rank_math_facebook_image": {},
"rank_math_twitter_use_facebook": {},
"rank_math_twitter_card_type": {},
"rank_math_twitter_title": {},
"rank_math_twitter_description": {}
"rank_math_twitter_description": {},
"rank_math_twitter_enable_image_overlay": {},
"rank_math_twitter_image_id": {},
"rank_math_twitter_image": {},
"rank_math_twitter_image_overlay": {},
"rank_math_canonical_url": {},
"rank_math_breadcrumb_title": {},
"redirection_header_code": {},
"redirection_url_to": {}
},
"admin_pages": [
"toplevel_page_rank-math"
Expand All @@ -27,7 +43,7 @@
"date_archive_title" : {},
"date_archive_description" : {},
"search_title" : {},
"404_title" : {},
"404_title" : {}
},
"rank-math-options-general": {
"breadcrumbs_home_label" : {},
Expand Down
9 changes: 9 additions & 0 deletions configs/plugins/woocommerce.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"post_types": {
"shop_order": {},
"product": {},
"product_variation": {},
"shop_coupon": {
Expand Down Expand Up @@ -111,6 +112,14 @@
}
},
"admin_html_tags": {
"woocommerce_page_wc-settings": {
"option": [
"#woocommerce_cart_page_id",
"#woocommerce_checkout_page_id",
"#woocommerce_myaccount_page_id",
"#woocommerce_terms_page_id"
]
},
"product_page_product_attributes": {
"value": [
"#attribute_label"
Expand Down
123 changes: 123 additions & 0 deletions includes/abstracts/abstract-wpm-object.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,129 @@ public function update_meta_field( $check, $object_id, $meta_key, $meta_value, $
return true;
}

/**
* Save meta by meta_id with translations (since WP 5.0.0)
*
* @param null|bool $check Whether to allow updating metadata for the given type.
* @param int $meta_id Meta ID.
* @param mixed $meta_value Meta value. Must be serializable if non-scalar.
* @param string|bool $meta_key New meta key or false if it mustn't be changed.
*
* @return bool|null Returning a non-null value will short-circuit the WP update function
*/
public function update_meta_field_by_mid( $check, $meta_id, $meta_value, $meta_key ) {
global $wpdb;

$meta_type = $this->object_type;

// Fetch the meta and go on if it's found.
$meta = get_metadata_by_mid( $meta_type, $meta_id );
if ( ! $meta ) {
return false;
}

$column = sanitize_key( $this->object_type . '_id' );
$original_key = $meta->meta_key;
$object_id = $meta->{$column};

switch ( $this->object_type ) {

case 'post':
if ( null === wpm_get_post_config( get_post_type( $object_id ) ) ) {
return $check;
}

break;

case 'term':
$term = get_term( $object_id );
if ( ! $term || null === wpm_get_taxonomy_config( $term->taxonomy ) ) {
return $check;
}
}

$config = wpm_get_config();
$object_fields_config = apply_filters( "wpm_{$this->object_type}_fields_config", $config[ "{$this->object_type}_fields" ] );

if ( ! isset( $object_fields_config[ $meta_key ] ) ) {
return $check;
}

$meta_config = apply_filters( "wpm_{$meta_key}_meta_config", $object_fields_config[ $meta_key ], $meta_value, $object_id );
$meta_config = apply_filters( "wpm_{$this->object_type}_meta_{$meta_key}_config", $meta_config, $meta_value, $object_id );

$table = $wpdb->{$this->object_table};
$id_column = 'user' === $this->object_type ? 'umeta_id' : 'meta_id';
$meta_value = apply_filters( 'wpm_update_meta_value', $meta_value, $meta_key );
$meta_value = apply_filters( "wpm_update_{$meta_key}_meta_value", $meta_value );
$meta_value = apply_filters( "wpm_update_{$this->object_type}_meta_{$meta_key}_value", $meta_value );

if ( null === $meta_config ) {
return $check;
}

// If a new meta_key (last parameter) was specified, change the meta key,
// otherwise use the original key in the update statement.
if ( false === $meta_key ) {
$meta_key = $original_key;
} elseif ( ! is_string( $meta_key ) ) {
return false;
}

$meta_subtype = get_object_subtype( $meta_type, $object_id );

// Sanitize the meta.
$_meta_value = $meta_value;

if ( ! wpm_is_ml_value( $meta_value ) ) {
$old_value = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->{$this->object_table}} WHERE meta_key = %s AND {$column} = %d LIMIT 1;", $meta_key, $object_id ) );
$old_value = maybe_unserialize( $old_value );
$old_value = apply_filters( "wpm_filter_old_{$meta_key}_meta_value", $old_value, $meta_value, $meta_config );
$meta_value = wpm_set_new_value( $old_value, $meta_value, $meta_config );
$meta_value = apply_filters( "wpm_filter_new_{$meta_key}_meta_value", $meta_value, $old_value, $meta_config );
}

$meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type, $meta_subtype );
$meta_value = maybe_serialize( $meta_value );

// Format the data query arguments.
$data = array(
'meta_key' => $meta_key,
'meta_value' => $meta_value,
);

// Format the where query arguments.
$where = array();
$where[ $id_column ] = $meta_id;

/** This action is documented in wp-includes/meta.php */
do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );

if ( 'post' === $meta_type ) {
/** This action is documented in wp-includes/meta.php */
do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
}

// Run the update query, all fields in $data are %s, $where is a %d.
$result = $wpdb->update( $table, $data, $where, '%s', '%d' );
if ( ! $result ) {
return false;
}

// Clear the caches.
wp_cache_delete( $object_id, $meta_type . '_meta' );

/** This action is documented in wp-includes/meta.php */
do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );

if ( 'post' === $meta_type ) {
/** This action is documented in wp-includes/meta.php */
do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
}

return true;
}

/**
* Add new meta for translation
*
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/class-wpm-admin-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function admin_scripts() {
'language' => wpm_get_language(),
'show_untranslated_strings' => get_option( 'wpm_show_untranslated_strings', 'yes' ),
);
wp_localize_script( 'wpm_translator', 'wpm_translator_params', $translator_params );
wp_add_inline_script( 'wpm_translator', 'const wpm_translator_params = '.json_encode($translator_params), 'before' );
wp_register_script( 'wpm_additional_settings', wpm_asset_path( 'scripts/additional-settings' . $suffix . '.js' ), array( 'jquery' ), WPM_VERSION );

$script = "
Expand Down
7 changes: 4 additions & 3 deletions includes/admin/class-wpm-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ public static function output() {

wp_enqueue_script( 'wpm_settings', wpm_asset_path( 'scripts/settings' . $suffix . '.js' ), array( 'jquery' ), wpm()->version, true );

wp_localize_script( 'wpm_settings', 'wpm_settings_params', array(
'nav_warning' => __( 'The changes you made will be lost if you navigate away from this page.', 'wp-multilang' ),
) );
$main_params = array(
'nav_warning' => __( 'The changes you made will be lost if you navigate away from this page.', 'wp-multilang' )
);
wp_add_inline_script( 'wpm_settings', 'const wpm_settings_params = '.json_encode($main_params), 'before' );

// Get tabs for the settings page
$tabs = apply_filters( 'wpm_settings_tabs_array', array() );
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/settings/class-wpm-settings-additional.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function output() {
'qtx_import_nonce' => wp_create_nonce( 'qtx-import' ),
'confirm_question' => __( 'Are you sure you want to delete this localization?', 'wp-multilang' ),
);
wp_localize_script( 'wpm_additional_settings', 'wpm_additional_settings_params', $main_params );
wp_add_inline_script( 'wpm_additional_settings', 'const wpm_additional_settings_params = '.json_encode($main_params), 'before' );
wp_enqueue_script( 'wpm_additional_settings' );

parent::output();
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/settings/class-wpm-settings-languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function get_languages( $value ) {
'delete_lang_nonce' => wp_create_nonce( 'delete-lang' ),
'confirm_question' => __( 'Are you sure you want to delete this language?', 'wp-multilang' ),
);
wp_localize_script( 'wpm_languages', 'wpm_languages_params', $main_params );
wp_add_inline_script( 'wpm_languages', 'const wpm_languages_params = '.json_encode($main_params), 'before' );

wp_enqueue_script( 'wpm_languages' );
wp_enqueue_style( 'select2' );
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wpm-frontend-scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private static function localize_script( $handle ) {
if ( ! in_array( $handle, self::$wp_localize_scripts, true ) && wp_script_is( $handle ) && ( $data = self::get_script_data( $handle ) ) ) {
$name = str_replace( '-', '_', $handle ) . '_params';
self::$wp_localize_scripts[] = $handle;
wp_localize_script( $handle, $name, apply_filters( $name, $data ) );
wp_add_inline_script( $handle, 'const {$name} = '.json_encode( apply_filters( $name, $data ) ), 'before' );
}
}

Expand Down
9 changes: 9 additions & 0 deletions includes/class-wpm-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function __construct() {
add_action( 'parse_query', array( $this, 'filter_posts_by_language' ) );
add_filter( "get_{$this->object_type}_metadata", array( $this, 'get_meta_field' ), 5, 3 );
add_filter( "update_{$this->object_type}_metadata", array( $this, 'update_meta_field' ), 99, 5 );
add_filter( "update_{$this->object_type}_metadata_by_mid", array( $this, 'update_meta_field_by_mid' ), 99, 4 );
add_filter( "add_{$this->object_type}_metadata", array( $this, 'add_meta_field' ), 99, 5 );
add_action( "delete_{$this->object_type}_metadata", array( $this, 'delete_meta_field' ), 99, 3 );
add_action( 'wp', array( $this, 'translate_queried_object' ), 5 );
Expand Down Expand Up @@ -179,6 +180,14 @@ public function save_post( $data, $postarr ) {

if ( $post_id ) {
$old_value = get_post_field( $key, $post_id, 'edit' );

// Override "(Auto Draft)" new post default title with empty string.
if ( 'post_title' === $key ) {
$old_post_status = get_post_field( 'post_status', $post_id, 'edit' );
if ( 'auto-draft' === $old_post_status ) {
$old_value = '';
}
}
} else {
$old_value = '';
}
Expand Down
1 change: 1 addition & 0 deletions includes/class-wpm-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ public function load_integrations() {
'woocommerce' => __NAMESPACE__ . '\Integrations\WPM_WooCommerce',
'wordpress-seo' => __NAMESPACE__ . '\Integrations\WPM_Yoast_Seo',
'seo-by-rank-math' => __NAMESPACE__ . '\Integrations\WPM_Rank_Math',
'elementor' => __NAMESPACE__ . '\Integrations\WPM_Elementor',
) );

$active_plugins = wp_cache_get( 'active_plugins', 'wpm' );
Expand Down
12 changes: 8 additions & 4 deletions includes/integrations/class-wpm-acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* @author Valentyn Riaboshtan
*/
class WPM_Acf {

/**
* WPM_Acf constructor.
*/
Expand All @@ -31,12 +30,13 @@ public function __construct() {
add_filter( 'wpm_acf_field_text_config', array( $this, 'add_text_field_config' ) );
add_filter( 'wpm_acf_field_textarea_config', array( $this, 'add_text_field_config' ) );
add_filter( 'wpm_acf_field_wysiwyg_config', array( $this, 'add_text_field_config' ) );
add_filter( 'wpm_acf_field_image_config', array( $this, 'add_image_field_config' ) );
add_filter( 'wpm_acf_text_config', '__return_empty_array' );
add_filter( 'wpm_acf_textarea_config', '__return_empty_array' );
add_filter( 'wpm_acf_wysiwyg_config', '__return_empty_array' );
add_filter( 'wpm_acf_image_config', '__return_empty_array' );
}


/**
* Add config for 'acf' post types
*
Expand Down Expand Up @@ -116,12 +116,15 @@ public function add_text_field_config( $config ) {
*
* @return array|bool|string
*/
public function update_value( $value, $post_id, $field ) {

public function update_value( $value, $post_id, $field ) {
if ( wpm_is_ml_value( $value ) ) {
return $value;
}

if ( ( strpos($post_id, 'block') !== false ) && ( $field['type'] == 'wysiwyg' || $field['type'] == 'text' || $field['type'] == 'textarea' ) ) {
return $value;
}

$info = acf_get_post_id_info( $post_id );

switch ( $info['type'] ) {
Expand All @@ -144,6 +147,7 @@ public function update_value( $value, $post_id, $field ) {
$acf_field_config = apply_filters( "wpm_acf_{$info['type']}_config", null, $value, $post_id, $field );
$acf_field_config = apply_filters( "wpm_acf_{$field['type']}_config", $acf_field_config, $value, $post_id, $field );
$acf_field_config = apply_filters( "wpm_acf_name_{$field['name']}_config", $acf_field_config, $value, $post_id, $field );
$acf_field_config = apply_filters( "wpm_acf_name_{$field['_name']}_config", $acf_field_config, $value, $post_id, $field );

if ( null === $acf_field_config ) {
return $value;
Expand Down
26 changes: 26 additions & 0 deletions includes/integrations/class-wpm-cf7.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class WPM_CF7 {
*/
public function __construct() {
add_filter( 'wpcf7_special_mail_tags', array( $this, 'add_language_tag' ), 10, 2 );
add_filter( 'wpcf7_special_mail_tags', array( $this, 'translate_post_title' ), 11, 2 );
add_filter( 'wpcf7_form_hidden_fields', array( $this, 'add_lang_field' ) );
add_action( 'wpcf7_contact_form', array( $this, 'edit_form_translate_shortcode_title_attr' ), 10, 1 );
}

public function add_language_tag( $output, $name ) {
Expand All @@ -35,6 +37,21 @@ public function add_language_tag( $output, $name ) {
return $output;
}

/**
* Translate post title
*
* @param $output string
* @param $name string
*
* @return string
*/
public function translate_post_title( $output, $name ) {
if ( '_post_name' == $name ) {
return wpm_translate_string( $output);
}

return $output;
}

/**
* Add current user language hidden field
Expand All @@ -48,4 +65,13 @@ public function add_lang_field( $fields ) {

return $fields;
}

/**
* Fix translation of the "title" attribute in the shortcode for copying, on the form edit page
*
* @param $wpcf7 current Contacts Form 7 instance
*/
public function edit_form_translate_shortcode_title_attr( $wpcf7 ) {
$wpcf7->set_title( wpm_translate_string( $wpcf7->title() ) );
}
}
Loading