WpCode.php
122 lines
| 1 | <?php |
| 2 | namespace AIOSEO\Plugin\Common\Integrations; |
| 3 | |
| 4 | // Exit if accessed directly. |
| 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | exit; |
| 7 | } |
| 8 | |
| 9 | /** |
| 10 | * Route class for the API. |
| 11 | * |
| 12 | * @since 4.3.8 |
| 13 | */ |
| 14 | class WpCode { |
| 15 | /** |
| 16 | * Load the WPCode snippets for our desired username or return an empty array if not available. |
| 17 | * |
| 18 | * @since 4.3.8 |
| 19 | * |
| 20 | * @return array The snippets. |
| 21 | */ |
| 22 | public static function loadWpCodeSnippets() { |
| 23 | $snippets = self::getPlaceholderSnippets(); |
| 24 | if ( function_exists( 'wpcode_get_library_snippets_by_username' ) ) { |
| 25 | $snippets = wpcode_get_library_snippets_by_username( 'aioseo' ); |
| 26 | } |
| 27 | |
| 28 | return $snippets; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Checks if the plugin is installed, either the lite or premium version. |
| 33 | * |
| 34 | * @since 4.3.8 |
| 35 | * |
| 36 | * @return bool True if the plugin is installed. |
| 37 | */ |
| 38 | public static function isPluginInstalled() { |
| 39 | return self::isProInstalled() || self::isLiteInstalled(); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Is the pro plugin installed. |
| 44 | * |
| 45 | * @since 4.3.8 |
| 46 | * |
| 47 | * @return bool True if the pro plugin is installed. |
| 48 | */ |
| 49 | public static function isProInstalled() { |
| 50 | $installedPlugins = array_keys( get_plugins() ); |
| 51 | |
| 52 | return in_array( 'wpcode-premium/wpcode.php', $installedPlugins, true ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Is the lite plugin installed. |
| 57 | * |
| 58 | * @since 4.3.8 |
| 59 | * |
| 60 | * @return bool True if the lite plugin is installed. |
| 61 | */ |
| 62 | public static function isLiteInstalled() { |
| 63 | $installedPlugins = array_keys( get_plugins() ); |
| 64 | |
| 65 | return in_array( 'insert-headers-and-footers/ihaf.php', $installedPlugins, true ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Basic check if the plugin is active by looking for the main function. |
| 70 | * |
| 71 | * @since 4.3.8 |
| 72 | * |
| 73 | * @return bool True if the plugin is active. |
| 74 | */ |
| 75 | public static function isPluginActive() { |
| 76 | return function_exists( 'wpcode' ); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Checks if the plugin is active but needs to be updated by checking if the function to load the |
| 81 | * library snippets by username exists. |
| 82 | * |
| 83 | * @since 4.3.8 |
| 84 | * |
| 85 | * @return bool True if the plugin is active but needs to be updated. |
| 86 | */ |
| 87 | public static function pluginNeedsUpdate() { |
| 88 | return self::isPluginActive() && ! function_exists( 'wpcode_get_library_snippets_by_username' ); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Get placeholder snippets if the WPCode snippets are not available. |
| 93 | * |
| 94 | * @since 4.3.8 |
| 95 | * |
| 96 | * @return array The placeholder snippets. |
| 97 | */ |
| 98 | private static function getPlaceholderSnippets() { |
| 99 | $snippetTitles = [ |
| 100 | 'Disable autogenerated shipping details schema for WooCommerce', |
| 101 | 'Disable SEO Preview feature', |
| 102 | 'Disable Shortcode Parsing in All in One SEO', |
| 103 | 'Enable WooCommerce Product Attributes in Search Appearance', |
| 104 | 'Fix LearnPress conflict that hides AIOSEO tabs on settings pages', |
| 105 | 'Limit Meta Description to 160 characters', |
| 106 | 'Limit SEO Title to 60 characters', |
| 107 | 'Noindex Product Search Pages', |
| 108 | 'Noindex Products under a Product Category', |
| 109 | ]; |
| 110 | |
| 111 | $placeholderSnippets = []; |
| 112 | foreach ( $snippetTitles as $snippetTitle ) { |
| 113 | // Add placeholder install link so we show a button. |
| 114 | $placeholderSnippets[] = [ |
| 115 | 'title' => $snippetTitle, |
| 116 | 'install' => 'https://library.wpcode.com/' |
| 117 | ]; |
| 118 | } |
| 119 | |
| 120 | return $placeholderSnippets; |
| 121 | } |
| 122 | } |