← All changes
|
vendor/codeinwp/themeisle-sdk/src/Common/Abstract_module.php
+141
-1
3.10.0
→
3.11.10
View file →
| @@ -23,8 +23,28 @@ | ||
| 23 | 23 | * @package ThemeisleSDK\Common |
| 24 | 24 | */ |
| 25 | 25 | abstract class Abstract_Module { |
| 26 | 26 | /** |
| 27 | + * Plugin paths. | |
| 28 | + * | |
| 29 | + * @var string[] $plugin_paths Plugin paths. | |
| 30 | + */ | |
| 31 | + private $plugin_paths = [ | |
| 32 | + 'otter-blocks' => 'otter-blocks/otter-blocks.php', | |
| 33 | + 'optimole-wp' => 'optimole-wp/optimole-wp.php', | |
| 34 | + 'tweet-old-post' => 'tweet-old-post/tweet-old-post.php', | |
| 35 | + 'feedzy-rss-feeds' => 'feedzy-rss-feeds/feedzy-rss-feed.php', | |
| 36 | + 'woocommerce-product-addon' => 'woocommerce-product-addon/woocommerce-product-addon.php', | |
| 37 | + 'visualizer' => 'visualizer/index.php', | |
| 38 | + 'wp-landing-kit' => 'wp-landing-kit/wp-landing-kit.php', | |
| 39 | + 'multiple-pages-generator-by-porthas' => 'multiple-pages-generator-by-porthas/porthas-multi-pages-generator.php', | |
| 40 | + 'sparks-for-woocommerce' => 'sparks-for-woocommerce/sparks-for-woocommerce.php', | |
| 41 | + 'templates-patterns-collection' => 'templates-patterns-collection/templates-patterns-collection.php', | |
| 42 | + 'wpcf7-redirect' => 'wpcf7-redirect/wpcf7-redirect.php', | |
| 43 | + 'wp-full-stripe-free' => 'wp-full-stripe-free/wp-full-stripe.php', | |
| 44 | + ]; | |
| 45 | + | |
| 46 | + /** | |
| 27 | 47 | * Product which use the module. |
| 28 | 48 | * |
| 29 | 49 | * @var Product $product Product object. |
| 30 | 50 | */ |
| @@ -53,9 +73,8 @@ | ||
| 53 | 73 | * |
| 54 | 74 | * @return bool Is product from partner. |
| 55 | 75 | */ |
| 56 | 76 | public function is_from_partner( $product ) { |
| 57 | - | |
| 58 | 77 | foreach ( Module_Factory::$domains as $partner_domain ) { |
| 59 | 78 | if ( strpos( $product->get_store_url(), $partner_domain ) !== false ) { |
| 60 | 79 | return true; |
| 61 | 80 | } |
| @@ -78,6 +97,127 @@ | ||
| 78 | 97 | : wp_remote_get( //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get, Already used. |
| 79 | 98 | $url, |
| 80 | 99 | $args |
| 81 | 100 | ); |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * Get the SDK base url. | |
| 105 | + * | |
| 106 | + * @return string | |
| 107 | + */ | |
| 108 | + public function get_sdk_uri() { | |
| 109 | + global $themeisle_sdk_max_path; | |
| 110 | + | |
| 111 | + /** | |
| 112 | + * $themeisle_sdk_max_path can point to the theme when the theme version is higher. | |
| 113 | + * hence we also need to check that the path does not point to the theme else this will break the URL. | |
| 114 | + * References: https://github.com/Codeinwp/neve-pro-addon/issues/2403 | |
| 115 | + */ | |
| 116 | + if ( ( $this->product->is_plugin() || $this->product->is_theme() ) && false === strpos( $themeisle_sdk_max_path, get_template_directory() ) ) { | |
| 117 | + return plugins_url( '/', $themeisle_sdk_max_path . '/themeisle-sdk/' ); | |
| 118 | + }; | |
| 119 | + | |
| 120 | + return get_template_directory_uri() . '/vendor/codeinwp/themeisle-sdk/'; | |
| 121 | + } | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * Call plugin api | |
| 125 | + * | |
| 126 | + * @param string $slug plugin slug. | |
| 127 | + * | |
| 128 | + * @return array|mixed|object | |
| 129 | + */ | |
| 130 | + public function call_plugin_api( $slug ) { | |
| 131 | + include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; | |
| 132 | + | |
| 133 | + $call_api = get_transient( 'ti_plugin_info_' . $slug ); | |
| 134 | + | |
| 135 | + if ( false === $call_api ) { | |
| 136 | + $call_api = plugins_api( | |
| 137 | + 'plugin_information', | |
| 138 | + array( | |
| 139 | + 'slug' => $slug, | |
| 140 | + 'fields' => array( | |
| 141 | + 'downloaded' => false, | |
| 142 | + 'rating' => false, | |
| 143 | + 'description' => false, | |
| 144 | + 'short_description' => true, | |
| 145 | + 'donate_link' => false, | |
| 146 | + 'tags' => false, | |
| 147 | + 'sections' => true, | |
| 148 | + 'homepage' => true, | |
| 149 | + 'added' => false, | |
| 150 | + 'last_updated' => false, | |
| 151 | + 'compatibility' => false, | |
| 152 | + 'tested' => false, | |
| 153 | + 'requires' => false, | |
| 154 | + 'downloadlink' => false, | |
| 155 | + 'icons' => true, | |
| 156 | + 'banners' => true, | |
| 157 | + ), | |
| 158 | + ) | |
| 159 | + ); | |
| 160 | + set_transient( 'ti_plugin_info_' . $slug, $call_api, 30 * MINUTE_IN_SECONDS ); | |
| 161 | + } | |
| 162 | + | |
| 163 | + return $call_api; | |
| 164 | + } | |
| 165 | + | |
| 166 | + /** | |
| 167 | + * Get the plugin status. | |
| 168 | + * | |
| 169 | + * @param string $plugin Plugin slug. | |
| 170 | + * | |
| 171 | + * @return bool | |
| 172 | + */ | |
| 173 | + public function is_plugin_installed( $plugin ) { | |
| 174 | + if ( ! isset( $this->plugin_paths[ $plugin ] ) ) { | |
| 175 | + return false; | |
| 176 | + } | |
| 177 | + | |
| 178 | + if ( file_exists( WP_CONTENT_DIR . '/plugins/' . $this->plugin_paths[ $plugin ] ) ) { | |
| 179 | + return true; | |
| 180 | + } | |
| 181 | + | |
| 182 | + return false; | |
| 183 | + } | |
| 184 | + | |
| 185 | + /** | |
| 186 | + * Get plugin activation link. | |
| 187 | + * | |
| 188 | + * @param string $slug The plugin slug. | |
| 189 | + * | |
| 190 | + * @return string | |
| 191 | + */ | |
| 192 | + public function get_plugin_activation_link( $slug ) { | |
| 193 | + $reference_key = $slug === 'otter-blocks' ? 'reference_key' : 'optimole_reference_key'; | |
| 194 | + $plugin = isset( $this->plugin_paths[ $slug ] ) ? $this->plugin_paths[ $slug ] : $slug . '/' . $slug . '.php'; | |
| 195 | + | |
| 196 | + return add_query_arg( | |
| 197 | + array( | |
| 198 | + 'plugin_status' => 'all', | |
| 199 | + 'paged' => '1', | |
| 200 | + 'action' => 'activate', | |
| 201 | + $reference_key => $this->product->get_key(), | |
| 202 | + 'plugin' => rawurlencode( $plugin ), | |
| 203 | + '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin ), | |
| 204 | + ), | |
| 205 | + admin_url( 'plugins.php' ) | |
| 206 | + ); | |
| 207 | + } | |
| 208 | + | |
| 209 | + /** | |
| 210 | + * Checks if a plugin is active. | |
| 211 | + * | |
| 212 | + * @param string $plugin plugin slug. | |
| 213 | + * | |
| 214 | + * @return bool | |
| 215 | + */ | |
| 216 | + public function is_plugin_active( $plugin ) { | |
| 217 | + include_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 218 | + | |
| 219 | + $plugin = isset( $this->plugin_paths[ $plugin ] ) ? $this->plugin_paths[ $plugin ] : $plugin . '/' . $plugin . '.php'; | |
| 220 | + | |
| 221 | + return is_plugin_active( $plugin ); | |
| 82 | 222 | } |
| 83 | 223 | } |