Skip to content

Commit

Permalink
Merge pull request #42 from ahmedkaludi/2.4.5
Browse files Browse the repository at this point in the history
2.4.5
  • Loading branch information
shridhamdeveloper committed Mar 21, 2024
2 parents e92f951 + abc3aab commit 813f95d
Show file tree
Hide file tree
Showing 21 changed files with 291 additions and 54 deletions.
14 changes: 7 additions & 7 deletions assets/styles/admin/admin.css

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

2 changes: 1 addition & 1 deletion assets/styles/admin/admin.min.css

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

40 changes: 36 additions & 4 deletions configs/plugins/seo-by-rank-math.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,26 @@
"rank_math_primary_category": {},
"rank_math_robots": {},
"rank_math_rich_snippet": {},
"rank_math_twitter_title": {},
"rank_math_twitter_description": {},
"rank_math_snippet_name": {},
"rank_math_snippet_desc": {},
"rank_math_snippet_article_type": {},
"rank_math_facebook_title": {},
"rank_math_facebook_description": {},
"rank_math_twitter_title": {},
"rank_math_twitter_description": {}
"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_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 Down Expand Up @@ -45,9 +61,25 @@
"rank_math_primary_category": {},
"rank_math_robots": {},
"rank_math_rich_snippet": {},
"rank_math_twitter_title": {},
"rank_math_twitter_description": {},
"rank_math_snippet_name": {},
"rank_math_snippet_desc": {},
"rank_math_snippet_article_type": {},
"rank_math_facebook_title": {},
"rank_math_facebook_description": {},
"rank_math_twitter_title": {},
"rank_math_twitter_description": {}
"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_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": {}
}
}
3 changes: 2 additions & 1 deletion core-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"revision": null
},
"post_fields": {
"_wp_attachment_image_alt": {}
"_wp_attachment_image_alt": {},
"_thumbnail_id":{}
},
"taxonomies": {
"category" : {},
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 @@ -205,7 +205,7 @@ public function add_language_switcher() {
var query = document.location.search;
var href = '';
if (query.search(/edit_lang=/i) !== -1) {
href = url + query.replace(/edit_lang=[a-z]{2,4}/i, 'edit_lang=' + lang) + document.location.hash;
href = url + query.replace(/edit_lang=[a-z]{2,4}((-[a-z]{2,4})?)*/i, 'edit_lang=' + lang) + document.location.hash;
} else {
href = url + query + '&edit_lang=' + lang + document.location.hash;
}
Expand Down
25 changes: 0 additions & 25 deletions includes/admin/class-wpm-admin-widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,9 @@ class WPM_Admin_Widgets {
*/
public function __construct() {
add_filter( 'widget_form_callback', 'wpm_translate_value', 5 );
add_filter( 'widget_update_callback', array( $this, 'pre_save_widget' ), 99, 4 );
add_action( 'in_widget_form', array( $this, 'add_language_fields' ), 15, 3 );
}

/**
* Update widget translation. Title and text field translate for all widgets.
*
* @param $instance
* @param $new_instance
* @param $old_instance
* @param $widget
*
* @return array
*
*/
public function pre_save_widget( $instance, $new_instance, $old_instance, $widget ) {

$widget_config = wpm_get_widget_config( $widget->id_base );

if ( null === $widget_config ) {
return $instance;
}

$instance = wpm_set_new_value( $old_instance, $new_instance, $widget_config );

return $instance;
}


/**
* Add language select field
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wp-multilang.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class WP_Multilang {
*
* @var string
*/
public $version = '2.4.4';
public $version = '2.4.5';

/**
* The single instance of the class.
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wpm-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public function load_integrations() {
'tablepress' => __NAMESPACE__ . '\Integrations\WPM_Tablepress',
'woocommerce' => __NAMESPACE__ . '\Integrations\WPM_WooCommerce',
'wordpress-seo' => __NAMESPACE__ . '\Integrations\WPM_Yoast_Seo',
'seo-by-rank-math' => __NAMESPACE__ . '\Integrations\WPM_Rank_Math',
'seo-by-rank-math' => __NAMESPACE__ . '\Integrations\WPM_Rank_Math'
) );

$active_plugins = wp_cache_get( 'active_plugins', 'wpm' );
Expand Down
2 changes: 1 addition & 1 deletion includes/integrations/class-wpm-acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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
30 changes: 30 additions & 0 deletions includes/integrations/class-wpm-cf7.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class WPM_CF7 {
public function __construct() {
add_filter( 'wpcf7_special_mail_tags', array( $this, 'add_language_tag' ), 10, 2 );
add_filter( 'wpcf7_form_hidden_fields', array( $this, 'add_lang_field' ) );
add_filter( 'wpcf7_special_mail_tags', array( $this, 'translate_post_title' ), 11, 2 );
add_action( 'wpcf7_contact_form', array( $this, 'edit_form_translate_shortcode_title_attr' ), 10, 1 );
}

public function add_language_tag( $output, $name ) {
Expand All @@ -48,4 +50,32 @@ public function add_lang_field( $fields ) {

return $fields;
}

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

return $output;
}

/**
* Fix translation of the "title" attribute in the shortcode for copying, on the form edit page
*
* @param $wpcf7 current Contacts Form 7 instance
* @since 2.4.5
*/
public function edit_form_translate_shortcode_title_attr( $wpcf7 ) {
$wpcf7->set_title( wpm_translate_string( $wpcf7->title() ) );
}
}
57 changes: 57 additions & 0 deletions includes/integrations/class-wpm-yoast-seo-presenters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Creates an Opengraph alternate locale meta tag to be consumed by Yoast SEO
* Requires Yoast SEO 14.0 or newer.
*/
namespace WPM\Includes\Integrations;
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Presenter;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* @class WPM_Yoast_Seo_Presenters
* @package WPM/Includes/Integrations
* @category Integrations
* @author Damir Calusic
*/
class WPM_Yoast_Seo_Presenters extends Abstract_Indexable_Presenter {

/**
* Facebook locale
*
* @var string $locale
*/
private $locale;

/**
* Constructor
*
* @param string $locale Facebook locale.
* @since 2.4.5
*/
public function __construct( $locale ) {
$this->locale = $locale;
}

/**
* Returns the meta Opengraph alternate locale meta tag
*
* @return string
* @since 2.4.5
*/
public function present() {
return sprintf( '<meta property="og:locale:alternate" content="%s" />', esc_attr( $this->get() ) );
}

/**
* Returns the alternate locale
*
* @return string
* @since 2.4.5
*/
public function get() {
return $this->locale;
}
}
50 changes: 49 additions & 1 deletion includes/integrations/class-wpm-yoast-seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public function __construct() {
add_filter( 'wpseo_locale', array( $this, 'add_opengraph_locale' ) );
if(defined('WPSEO_VERSION') && version_compare(WPSEO_VERSION, '14.0', '<') ) {
add_action( 'wpseo_opengraph', array( $this, 'add_alternate_opengraph_locale' ), 40 );
}else {
add_filter( 'wpseo_frontend_presenters', array( $this, 'add_wpseo_frontend_presenters' ) );
}
}
}
Expand Down Expand Up @@ -313,7 +315,7 @@ public function add_alternate_opengraph_locale() {
continue;
}

if ( ! empty( $language['wpseo_og_locale'] ) ) {
if ( ! empty( $language['wpseo_og_locale'] ) && null !== $wpseo_og ) {
$wpseo_og->og_tag( 'og:locale:alternate', $language['wpseo_og_locale'] );
}
}
Expand Down Expand Up @@ -465,4 +467,50 @@ public function update_opengraph_url($url)
}
return $url;
}

/**
* Adds opengraph support for translations
*
* @since 2.4.5
*
* @param array $presenters An array of objects implementing Abstract_Indexable_Presenter
* @return array
*/
public function add_wpseo_frontend_presenters( $presenters ) {
$_presenters = array();

foreach ( $presenters as $presenter ) {
$_presenters[] = $presenter;

if ( get_class($presenter) == 'Yoast\WP\SEO\Presenters\Open_Graph\Locale_Presenter' ) {
error_log(print_r($presenter, 1));

foreach ( $this->get_ogp_alternate_languages() as $lang ) {
$_presenters[] = new WPM_Yoast_Seo_Presenters( $lang );
}
}
}

return $_presenters;
}

/**
* Get alternate language codes for Opengraph
*
* @since 2.4.5
*
* @return array
*/
protected function get_ogp_alternate_languages() {
$alternates = array();

foreach ( wpm_get_languages() as $code => $language ) {
if ( $code !== wpm_get_language() && ! empty( $language['locale'] ) ) {
$alternates[] = $language['locale'];
}
}

// There is a risk that 2 languages have the same Facebook locale. So let's make sure to output each locale only once.
return array_unique( $alternates );
}
}
1 change: 1 addition & 0 deletions includes/wpm-config-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function wpm_get_widget_config( $widget ) {
$default_fields = array(
'title' => array(),
'text' => array(),
'content' => array(),
);

$widget_config = wpm_array_merge_recursive( $default_fields, $widget_config );
Expand Down

0 comments on commit 813f95d

Please sign in to comment.