PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.11.10
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.11.10
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
← All changes | vendor/codeinwp/themeisle-sdk/src/Modules/Featured_plugins.php +3 -128 4.0.73.11.10 View file →
@@ -12,9 +12,8 @@
12 12 */
13 13 namespace ThemeisleSDK\Modules;
14 14
15 15 use ThemeisleSDK\Common\Abstract_Module;
16 -use ThemeisleSDK\Loader;
17 16 use ThemeisleSDK\Product;
18 17
19 18 // Exit if accessed directly.
20 19 if ( ! defined( 'ABSPATH' ) ) {
@@ -33,15 +32,8 @@
33 32 */
34 33 private $transient_key = 'themeisle_sdk_featured_plugins_';
35 34
36 35 /**
37 - * The current product instance.
38 - *
39 - * @var Product|null
40 - */
41 - protected $product = null;
42 -
43 - /**
44 36 * Check if the module can be loaded.
45 37 *
46 38 * @param Product $product Product data.
47 39 *
@@ -66,10 +58,8 @@
66 58 *
67 59 * @return void
68 60 */
69 61 public function load( $product ) {
70 - $this->product = $product;
71 -
72 62 if ( ! current_user_can( 'install_plugins' ) ) {
73 63 return;
74 64 }
75 65
@@ -78,63 +68,12 @@
78 68 return;
79 69 }
80 70 add_filter( 'themeisle_sdk_plugin_api_filter_registered', '__return_true' );
81 71
82 - add_filter( 'plugins_api_result', [ $this, 'filter_plugin_api_results' ], 11, 3 );
83 -
84 - // Enqueue inline JS only on plugin-install.php.
85 - add_action( 'admin_enqueue_scripts', [ $this, 'maybe_add_inline_js' ] );
72 + add_filter( 'plugins_api_result', [ $this, 'filter_plugin_api_results' ], 10, 3 );
86 73 }
87 74
88 75 /**
89 - * Enqueue inline JavaScript only on plugin-install.php.
90 - *
91 - * @return void
92 - */
93 - public function maybe_add_inline_js() {
94 - $screen = get_current_screen();
95 - if ( isset( $screen->base ) && 'plugin-install' === $screen->base ) {
96 - add_action(
97 - 'admin_footer',
98 - function() {
99 - $text = esc_html( sprintf( Loader::$labels['promotions']['recommended'], $this->product->get_friendly_name() ) );
100 -
101 - echo '<script>(function(){
102 - function onPluginCardFound(card) {
103 - var recommendedDiv = document.createElement("div");
104 - Object.assign(recommendedDiv.style, {
105 - display: "block",
106 - textAlign: "center",
107 - padding: "0 12px 12px",
108 - background: "#f6f7f7"
109 - });
110 - recommendedDiv.innerHTML = "' . esc_html( $text ) . '";
111 - card.appendChild(recommendedDiv);
112 - }
113 -
114 - function checkAndRun() {
115 - var card = document.querySelector(".plugin-card-learning-management-system");
116 - if (card && !card.dataset.recommendedAdded) {
117 - onPluginCardFound(card);
118 - card.dataset.recommendedAdded = "true";
119 - }
120 - }
121 -
122 - var observer = new MutationObserver(function(mutations) {
123 - checkAndRun();
124 - });
125 -
126 - observer.observe(document.body, { childList: true, subtree: true });
127 -
128 - // Initial check in case the card is already present.
129 - checkAndRun();
130 - })();</script>';
131 - }
132 - );
133 - }
134 - }
135 -
136 - /**
137 76 * Filter the plugin API results to include the featured plugins.
138 77 *
139 78 * @param object $res The result object.
140 79 * @param string $action The type of information being requested from the Plugin Install API.
@@ -147,13 +86,8 @@
147 86 if ( 'query_plugins' !== $action ) {
148 87 return $res;
149 88 }
150 89
151 - if ( isset( $args->page ) && 1 === (int) $args->page && isset( $args->search ) && ! empty( $args->search ) ) {
152 - $res->plugins = $this->maybe_prepend_lms_plugin( $res->plugins, $args );
153 - return $res;
154 - }
155 -
156 90 if ( ! isset( $args->browse ) || $args->browse !== 'featured' ) {
157 91 return $res;
158 92 }
159 93
@@ -166,67 +100,8 @@
166 100 return $res;
167 101 }
168 102
169 103 /**
170 - * Prepend the LMS plugin if the search query matches LMS-related terms.
171 - *
172 - * @param array $plugins The plugins array.
173 - * @param object $args The plugin API arguments.
174 - * @return array
175 - */
176 - private function maybe_prepend_lms_plugin( $plugins, $args ) {
177 - $search = isset( $args->search ) ? strtolower( $args->search ) : '';
178 - if ( $this->matches_lms_search_keywords( $search ) ) {
179 - $filter_slugs = apply_filters( 'themeisle_sdk_masteriyo_filter_slugs', [ 'learning-management-system' ] );
180 - $masteriyo = $this->get_plugins_filtered_from_author( $args, $filter_slugs, 'masteriyo' );
181 -
182 - if ( ! empty( $masteriyo ) ) {
183 - // Remove existing LMS plugin if present to avoid duplicates.
184 - $plugins = array_filter(
185 - $plugins,
186 - function( $plugin ) {
187 - return ( is_object( $plugin ) && isset( $plugin->slug ) && $plugin->slug !== 'learning-management-system' ) ||
188 - ( is_array( $plugin ) && isset( $plugin['slug'] ) && $plugin['slug'] !== 'learning-management-system' );
189 - }
190 - );
191 -
192 - $plugins = array_merge( $masteriyo, $plugins );
193 - }
194 - }
195 - return $plugins;
196 - }
197 -
198 - /**
199 - * Check if a plugin search query matches LMS-related terms.
200 - *
201 - * @param string $search Search query.
202 - *
203 - * @return bool True if the search query matches LMS-related terms.
204 - */
205 - private function matches_lms_search_keywords( $search ) {
206 - $lms_keywords = array(
207 - 'lms',
208 - 'learn',
209 - 'course',
210 - 'courses',
211 - 'learning',
212 - 'academy',
213 - 'training',
214 - 'student',
215 - 'students',
216 - 'quiz',
217 - );
218 -
219 - foreach ( $lms_keywords as $keyword ) {
220 - if ( preg_match( '/(^|[^a-z0-9])' . preg_quote( $keyword, '/' ) . '([^a-z0-9]|$)/', $search ) === 1 ) {
221 - return true;
222 - }
223 - }
224 -
225 - return false;
226 - }
227 -
228 - /**
229 104 * Query plugins by author.
230 105 *
231 106 * @param object $args The arguments for the query.
232 107 *
@@ -238,9 +113,9 @@
238 113 $optimole_filter_slugs = apply_filters( 'themeisle_sdk_optimole_filter_slugs', [ 'optimole-wp' ] );
239 114 $filtered_from_optimole = $this->get_plugins_filtered_from_author( $args, $optimole_filter_slugs, 'Optimole' );
240 115 $featured = array_merge( $featured, $filtered_from_optimole );
241 116
242 - $themeisle_filter_slugs = apply_filters( 'themeisle_sdk_themeisle_filter_slugs', [ 'otter-blocks', 'wp-cloudflare-page-cache' ] );
117 + $themeisle_filter_slugs = apply_filters( 'themeisle_sdk_themeisle_filter_slugs', [ 'otter-blocks' ] );
243 118 $filtered_from_themeisle = $this->get_plugins_filtered_from_author( $args, $themeisle_filter_slugs );
244 119 $featured = array_merge( $featured, $filtered_from_themeisle );
245 120
246 121 return $featured;
@@ -254,9 +129,9 @@
254 129 * @param string $author The author to filter.
255 130 *
256 131 * @return array
257 132 */
258 - protected function get_plugins_filtered_from_author( $args, $filter_slugs = [], $author = 'Themeisle' ) {
133 + private function get_plugins_filtered_from_author( $args, $filter_slugs = [], $author = 'Themeisle' ) {
259 134
260 135 $cached = get_transient( $this->transient_key . $author );
261 136 if ( $cached ) {
262 137 return $cached;