| 1 |
<?php |
| 2 |
/** |
| 3 |
* RankMath Snippet class. |
| 4 |
* |
| 5 |
* @package sharing-image |
| 6 |
* @author Anton Lukin |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace Sharing_Image\Snippets; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
die; |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Snippet class. |
| 17 |
* |
| 18 |
* @class RankMath |
| 19 |
*/ |
| 20 |
class RankMath { |
| 21 |
/** |
| 22 |
* Get snippet name. |
| 23 |
*/ |
| 24 |
public static function get_name() { |
| 25 |
$name = array( |
| 26 |
'title' => 'Rank Math SEO', |
| 27 |
'link' => 'https://wordpress.org/plugins/seo-by-rank-math/', |
| 28 |
); |
| 29 |
|
| 30 |
return $name; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Check if plugin is activated. |
| 35 |
*/ |
| 36 |
public static function is_activated() { |
| 37 |
if ( defined( 'RANK_MATH_VERSION' ) ) { |
| 38 |
return true; |
| 39 |
} |
| 40 |
|
| 41 |
return false; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Init snippet filters. |
| 46 |
*/ |
| 47 |
public static function init_filters() { |
| 48 |
foreach ( array( 'facebook', 'twitter' ) as $network ) { |
| 49 |
add_filter( "rank_math/opengraph/{$network}/image_array", array( __CLASS__, 'update_image_array' ) ); |
| 50 |
} |
| 51 |
|
| 52 |
add_filter( 'sharing_image_show_header', '__return_false' ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Update image array. |
| 57 |
* |
| 58 |
* @param array $attachment Image array data. |
| 59 |
*/ |
| 60 |
public static function update_image_array( $attachment ) { |
| 61 |
$poster = sharing_image_poster_src(); |
| 62 |
|
| 63 |
if ( empty( $poster ) ) { |
| 64 |
return $attachment; |
| 65 |
} |
| 66 |
|
| 67 |
if ( empty( $attachment ) ) { |
| 68 |
$attachment = array(); |
| 69 |
} |
| 70 |
|
| 71 |
$attachment['id'] = 0; |
| 72 |
$attachment['url'] = $poster[0]; |
| 73 |
$attachment['width'] = $poster[1]; |
| 74 |
$attachment['height'] = $poster[2]; |
| 75 |
|
| 76 |
return $attachment; |
| 77 |
} |
| 78 |
} |
| 79 |
|