| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handle 3rd party plugin snippets. |
| 4 |
* |
| 5 |
* @package sharing-image |
| 6 |
* @author Anton Lukin |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace Sharing_Image; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
die; |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Snippets class. |
| 17 |
* |
| 18 |
* @class Snippets |
| 19 |
*/ |
| 20 |
class Snippets { |
| 21 |
/** |
| 22 |
* Store list of plugin snippets. |
| 23 |
* |
| 24 |
* @var array |
| 25 |
*/ |
| 26 |
private static $snippets = array(); |
| 27 |
|
| 28 |
/** |
| 29 |
* Init class actions and filters. |
| 30 |
*/ |
| 31 |
public static function init() { |
| 32 |
add_action( 'init', array( __CLASS__, 'init_snippets' ) ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Init plugin snippets. |
| 37 |
*/ |
| 38 |
public static function init_snippets() { |
| 39 |
$list = array( |
| 40 |
'Sharing_Image\Snippets\YoastSeo' => SHARING_IMAGE_DIR . 'snippets/class-yoastseo.php', |
| 41 |
'Sharing_Image\Snippets\RankMath' => SHARING_IMAGE_DIR . 'snippets/class-rankmath.php', |
| 42 |
'Sharing_Image\Snippets\TheSEOFramework' => SHARING_IMAGE_DIR . 'snippets/class-theseoframework.php', |
| 43 |
'Sharing_Image\Snippets\Squirrly' => SHARING_IMAGE_DIR . 'snippets/class-squirrly.php', |
| 44 |
'Sharing_Image\Snippets\SEOPress' => SHARING_IMAGE_DIR . 'snippets/class-seopress.php', |
| 45 |
'Sharing_Image\Snippets\SlimSEO' => SHARING_IMAGE_DIR . 'snippets/class-slimseo.php', |
| 46 |
'Sharing_Image\Snippets\AIOSEO' => SHARING_IMAGE_DIR . 'snippets/class-aioseo.php', |
| 47 |
); |
| 48 |
|
| 49 |
/** |
| 50 |
* Filter 3rd party plugin snippets list. |
| 51 |
* |
| 52 |
* @param array $snippets A key-value array with class name key and path to the file as value. |
| 53 |
*/ |
| 54 |
$list = apply_filters( 'sharing_image_snippets', $list ); |
| 55 |
|
| 56 |
foreach ( $list as $plugin_class => $path ) { |
| 57 |
include_once $path; |
| 58 |
|
| 59 |
if ( ! class_exists( $plugin_class ) ) { |
| 60 |
continue; |
| 61 |
} |
| 62 |
|
| 63 |
if ( ! $plugin_class::is_activated() ) { |
| 64 |
continue; |
| 65 |
} |
| 66 |
|
| 67 |
if ( Config::is_active_snippets() ) { |
| 68 |
$plugin_class::init_filters(); |
| 69 |
} |
| 70 |
|
| 71 |
self::$snippets[] = $plugin_class::get_name(); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Get list of snippets plugins names and links. |
| 77 |
* |
| 78 |
* @return array List of snippets. |
| 79 |
*/ |
| 80 |
public static function get_snippets() { |
| 81 |
/** |
| 82 |
* Filters list of plugin snippets names. |
| 83 |
* |
| 84 |
* @since 3.0 |
| 85 |
* |
| 86 |
* @param array $names List of snippets names. |
| 87 |
*/ |
| 88 |
return apply_filters( 'sharing_image_get_snippets', self::$snippets ); |
| 89 |
} |
| 90 |
} |
| 91 |
|