PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.11.14
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.11.14
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / codeinwp / themeisle-sdk / src / Common / Abstract_module.php

Abstract_module.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.11.14, at vendor/codeinwp/themeisle-sdk/src/Common/Abstract_module.php

234 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 ];
46
47 /**
48 * Product which use the module.
49 *
50 * @var Product $product Product object.
51 */
52 protected $product = null;
53
54 /**
55 * Can load the module for the selected product.
56 *
57 * @param Product $product Product data.
58 *
59 * @return bool Should load module?
60 */
61 abstract public function can_load( $product );
62
63 /**
64 * Bootstrap the module.
65 *
66 * @param Product $product Product object.
67 */
68 abstract public function load( $product );
69
70 /**
71 * Check if the product is from partner.
72 *
73 * @param Product $product Product data.
74 *
75 * @return bool Is product from partner.
76 */
77 public function is_from_partner( $product ) {
78 foreach ( Module_Factory::$domains as $partner_domain ) {
79 if ( strpos( $product->get_store_url(), $partner_domain ) !== false ) {
80 return true;
81 }
82 }
83
84 return array_key_exists( $product->get_slug(), Module_Factory::$slugs );
85 }
86
87 /**
88 * Wrapper for wp_remote_get on VIP environments.
89 *
90 * @param string $url Url to check.
91 * @param array $args Option params.
92 *
93 * @return array|\WP_Error
94 */
95 public function safe_get( $url, $args = array() ) {
96 return function_exists( 'vip_safe_wp_remote_get' )
97 ? vip_safe_wp_remote_get( $url )
98 : wp_remote_get( //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get, Already used.
99 $url,
100 $args
101 );
102 }
103
104 /**
105 * Get the SDK base url.
106 *
107 * @return string
108 */
109 public function get_sdk_uri() {
110 global $themeisle_sdk_max_path;
111
112 /**
113 * $themeisle_sdk_max_path can point to the theme when the theme version is higher.
114 * hence we also need to check that the path does not point to the theme else this will break the URL.
115 * References: https://github.com/Codeinwp/neve-pro-addon/issues/2403
116 */
117 if ( ( $this->product->is_plugin() || $this->product->is_theme() ) && false === strpos( $themeisle_sdk_max_path, get_template_directory() ) ) {
118 return plugins_url( '/', $themeisle_sdk_max_path . '/themeisle-sdk/' );
119 };
120
121 return get_template_directory_uri() . '/vendor/codeinwp/themeisle-sdk/';
122 }
123
124 /**
125 * Call plugin api
126 *
127 * @param string $slug plugin slug.
128 *
129 * @return array|mixed|object
130 */
131 public function call_plugin_api( $slug ) {
132 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
133
134 $call_api = get_transient( 'ti_plugin_info_' . $slug );
135
136 if ( false === $call_api ) {
137 $call_api = plugins_api(
138 'plugin_information',
139 array(
140 'slug' => $slug,
141 'fields' => array(
142 'downloaded' => false,
143 'rating' => false,
144 'description' => false,
145 'short_description' => true,
146 'donate_link' => false,
147 'tags' => false,
148 'sections' => true,
149 'homepage' => true,
150 'added' => false,
151 'last_updated' => false,
152 'compatibility' => false,
153 'tested' => false,
154 'requires' => false,
155 'downloadlink' => false,
156 'icons' => true,
157 'banners' => true,
158 ),
159 )
160 );
161 set_transient( 'ti_plugin_info_' . $slug, $call_api, 30 * MINUTE_IN_SECONDS );
162 }
163
164 return $call_api;
165 }
166
167 /**
168 * Get the plugin status.
169 *
170 * @param string $plugin Plugin slug.
171 *
172 * @return bool
173 */
174 public function is_plugin_installed( $plugin ) {
175 if ( ! isset( $this->plugin_paths[ $plugin ] ) ) {
176 return false;
177 }
178
179 if ( file_exists( WP_CONTENT_DIR . '/plugins/' . $this->plugin_paths[ $plugin ] ) ) {
180 return true;
181 }
182
183 return false;
184 }
185
186 /**
187 * Get plugin activation link.
188 *
189 * @param string $slug The plugin slug.
190 *
191 * @return string
192 */
193 public function get_plugin_activation_link( $slug ) {
194 $reference_key = $slug === 'otter-blocks' ? 'reference_key' : 'optimole_reference_key';
195 $plugin = isset( $this->plugin_paths[ $slug ] ) ? $this->plugin_paths[ $slug ] : $slug . '/' . $slug . '.php';
196
197 return add_query_arg(
198 array(
199 'plugin_status' => 'all',
200 'paged' => '1',
201 'action' => 'activate',
202 $reference_key => $this->product->get_key(),
203 'plugin' => rawurlencode( $plugin ),
204 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin ),
205 ),
206 admin_url( 'plugins.php' )
207 );
208 }
209
210 /**
211 * Checks if a plugin is active.
212 *
213 * @param string $plugin plugin slug.
214 *
215 * @return bool
216 */
217 public function is_plugin_active( $plugin ) {
218 include_once ABSPATH . 'wp-admin/includes/plugin.php';
219
220 $plugin = isset( $this->plugin_paths[ $plugin ] ) ? $this->plugin_paths[ $plugin ] : $plugin . '/' . $plugin . '.php';
221
222 return is_plugin_active( $plugin );
223 }
224
225 /**
226 * Get the current date.
227 *
228 * @return \DateTime The date time.
229 */
230 public function get_current_date() {
231 return apply_filters( 'themeisle_sdk_current_date', new \DateTime( 'now' ) );
232 }
233 }
234