PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.10.8
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.10.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 3.10.4 All 148 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.10.8, at vendor/codeinwp/themeisle-sdk/src/Common/Abstract_module.php

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