-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added og:locale:alternate (WPML integration) - added check for wp_get_attachment_image_src() result
- Loading branch information
Showing
4 changed files
with
251 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...opengraph/integrations/class-iworks-opengraph-integrations-sitepress-multilingual-cms.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* The WordPress Multilingual Plugin | ||
* https://wpml.org/ | ||
* | ||
* @since 3.2.0 | ||
*/ | ||
class iWorks_OpenGraph_Integrations_Sitepress_Multilingual_CMS extends iWorks_OpenGraph_Integrations { | ||
|
||
public function __construct() { | ||
add_filter( 'og_og_array', array( $this, 'maybe_add_alternate_locale' ) ); | ||
} | ||
|
||
/** | ||
* Try to add alternate locale | ||
* | ||
* @since 3.2.0 | ||
*/ | ||
public function maybe_add_alternate_locale( $data ) { | ||
if ( ! is_singular() ) { | ||
return $data; | ||
} | ||
if ( ! function_exists( 'icl_get_languages_locales' ) ) { | ||
return $data; | ||
} | ||
$result = icl_get_languages_locales(); | ||
if ( empty( $result ) ) { | ||
return $data; | ||
} | ||
$type = apply_filters( 'wpml_element_type', get_post_type( get_the_ID() ) ); | ||
if ( empty( $type ) ) { | ||
return $data; | ||
} | ||
$trid = apply_filters( 'wpml_element_trid', false, get_the_ID(), $type ); | ||
if ( empty( $trid ) ) { | ||
return $data; | ||
} | ||
$translations = apply_filters( 'wpml_get_element_translations', array(), $trid, $type ); | ||
if ( empty( $translations ) ) { | ||
return $data; | ||
} | ||
foreach ( $translations as $lang => $translation ) { | ||
if ( ! is_array( $data['locale'] ) ) { | ||
$data['locale'] = array( | ||
$data['locale'], | ||
'alternate' => array(), | ||
); | ||
} | ||
if ( | ||
isset( $result[ $translation->language_code ] ) | ||
& $data['locale'][0] !== $result[ $translation->language_code ] | ||
) { | ||
$data['locale']['alternate'][] = $result[ $translation->language_code ]; | ||
} | ||
} | ||
return $data; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.