PluginProbe ʕ •ᴥ•ʔ
Starter Sites & Templates by Neve / 1.4.1
Starter Sites & Templates by Neve v1.4.1
1.4.1 1.4.0 1.3.0 1.2.29 1.2.28 1.2.6 1.2.7 1.2.8 1.2.9 trunk 1.0.10 1.0.11 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.27 1.1.28 1.1.29 1.1.3 1.1.30 1.1.31 1.1.32 1.1.33 1.1.34 1.1.35 1.1.36 1.1.37 1.1.38 1.1.39 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.3 1.2.4 1.2.5
templates-patterns-collection / vendor / codeinwp / themeisle-sdk / src / Common / Abstract_module.php
templates-patterns-collection / vendor / codeinwp / themeisle-sdk / src / Common Last commit date
Abstract_module.php 1 month ago Module_factory.php 5 years ago
Abstract_module.php
236 lines
1 <?php
2 /**
3 * The abstract class for module definition.
4 *
5 * @package ThemeIsleSDK
6 * @subpackage Loader
7 * @copyright Copyright (c) 2017, Marius Cristea
8 * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
9 * @since 3.0.0
10 */
11
12 namespace ThemeisleSDK\Common;
13
14 use ThemeisleSDK\Product;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20 /**
21 * Class Abstract_Module.
22 *
23 * @package ThemeisleSDK\Common
24 */
25 abstract class Abstract_Module {
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 'learning-management-system' => 'learning-management-system/lms.php',
45 'wp-cloudflare-page-cache' => 'wp-cloudflare-page-cache/wp-cloudflare-super-page-cache.php',
46 ];
47
48 /**
49 * Product which use the module.
50 *
51 * @var Product $product Product object.
52 */
53 protected $product = null;
54
55 /**
56 * Can load the module for the selected product.
57 *
58 * @param Product $product Product data.
59 *
60 * @return bool Should load module?
61 */
62 abstract public function can_load( $product );
63
64 /**
65 * Bootstrap the module.
66 *
67 * @param Product $product Product object.
68 */
69 abstract public function load( $product );
70
71 /**
72 * Check if the product is from partner.
73 *
74 * @param Product $product Product data.
75 *
76 * @return bool Is product from partner.
77 */
78 public function is_from_partner( $product ) {
79 foreach ( Module_Factory::$domains as $partner_domain ) {
80 if ( strpos( $product->get_store_url(), $partner_domain ) !== false ) {
81 return true;
82 }
83 }
84
85 return array_key_exists( $product->get_slug(), Module_Factory::$slugs );
86 }
87
88 /**
89 * Wrapper for wp_remote_get on VIP environments.
90 *
91 * @param string $url Url to check.
92 * @param array $args Option params.
93 *
94 * @return array|\WP_Error
95 */
96 public function safe_get( $url, $args = array() ) {
97 return function_exists( 'vip_safe_wp_remote_get' )
98 ? vip_safe_wp_remote_get( $url )
99 : wp_remote_get( //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get, Already used.
100 $url,
101 $args
102 );
103 }
104
105 /**
106 * Get the SDK base url.
107 *
108 * @return string
109 */
110 public function get_sdk_uri() {
111 global $themeisle_sdk_max_path;
112
113 /**
114 * $themeisle_sdk_max_path can point to the theme when the theme version is higher.
115 * hence we also need to check that the path does not point to the theme else this will break the URL.
116 * References: https://github.com/Codeinwp/neve-pro-addon/issues/2403
117 */
118 if ( ( $this->product->is_plugin() || $this->product->is_theme() ) && false === strpos( $themeisle_sdk_max_path, get_template_directory() ) ) {
119 return plugins_url( '/', $themeisle_sdk_max_path . '/themeisle-sdk/' );
120 };
121
122 return get_template_directory_uri() . '/vendor/codeinwp/themeisle-sdk/';
123 }
124
125 /**
126 * Call plugin api
127 *
128 * @param string $slug plugin slug.
129 *
130 * @return array|mixed|object
131 */
132 public function call_plugin_api( $slug ) {
133 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
134
135 $call_api = get_transient( 'ti_plugin_info_' . $slug );
136
137 if ( false === $call_api ) {
138 $call_api = plugins_api(
139 'plugin_information',
140 array(
141 'slug' => $slug,
142 'fields' => array(
143 'downloaded' => false,
144 'rating' => true,
145 'ratings' => true,
146 'description' => false,
147 'short_description' => true,
148 'donate_link' => false,
149 'tags' => false,
150 'sections' => true,
151 'homepage' => true,
152 'added' => false,
153 'last_updated' => false,
154 'compatibility' => false,
155 'tested' => false,
156 'requires' => false,
157 'downloadlink' => false,
158 'icons' => true,
159 'banners' => true,
160 ),
161 )
162 );
163 set_transient( 'ti_plugin_info_' . $slug, $call_api, 30 * MINUTE_IN_SECONDS );
164 }
165
166 return $call_api;
167 }
168
169 /**
170 * Get the plugin status.
171 *
172 * @param string $plugin Plugin slug.
173 *
174 * @return bool
175 */
176 public function is_plugin_installed( $plugin ) {
177 if ( ! isset( $this->plugin_paths[ $plugin ] ) ) {
178 return false;
179 }
180
181 if ( file_exists( WP_CONTENT_DIR . '/plugins/' . $this->plugin_paths[ $plugin ] ) ) {
182 return true;
183 }
184
185 return false;
186 }
187
188 /**
189 * Get plugin activation link.
190 *
191 * @param string $slug The plugin slug.
192 *
193 * @return string
194 */
195 public function get_plugin_activation_link( $slug ) {
196 $reference_key = $slug === 'otter-blocks' ? 'reference_key' : 'optimole_reference_key';
197 $plugin = isset( $this->plugin_paths[ $slug ] ) ? $this->plugin_paths[ $slug ] : $slug . '/' . $slug . '.php';
198
199 return add_query_arg(
200 array(
201 'plugin_status' => 'all',
202 'paged' => '1',
203 'action' => 'activate',
204 $reference_key => $this->product->get_key(),
205 'plugin' => rawurlencode( $plugin ),
206 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin ),
207 ),
208 admin_url( 'plugins.php' )
209 );
210 }
211
212 /**
213 * Checks if a plugin is active.
214 *
215 * @param string $plugin plugin slug.
216 *
217 * @return bool
218 */
219 public function is_plugin_active( $plugin ) {
220 include_once ABSPATH . 'wp-admin/includes/plugin.php';
221
222 $plugin = isset( $this->plugin_paths[ $plugin ] ) ? $this->plugin_paths[ $plugin ] : $plugin . '/' . $plugin . '.php';
223
224 return is_plugin_active( $plugin );
225 }
226
227 /**
228 * Get the current date.
229 *
230 * @return \DateTime The date time.
231 */
232 public function get_current_date() {
233 return apply_filters( 'themeisle_sdk_current_date', new \DateTime( 'now' ) );
234 }
235 }
236