PluginProbe ʕ •ᴥ•ʔ
Catch Scroll Progress Bar / 2.1
Catch Scroll Progress Bar v2.1
trunk 1.0.0 1.1 1.2 1.3 1.4 1.5 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 2.0 2.1 2.2
catch-scroll-progress-bar / includes / CatchThemesThemePlugin.php
catch-scroll-progress-bar / includes Last commit date
CatchThemesThemePlugin.php 4 months ago class-catch-scroll-progress-bar-activator.php 4 months ago class-catch-scroll-progress-bar-deactivator.php 4 months ago class-catch-scroll-progress-bar-i18n.php 4 months ago class-catch-scroll-progress-bar-loader.php 4 months ago class-catch-scroll-progress-bar.php 4 months ago ctp-tabs-removal.php 4 months ago index.php 4 months ago
CatchThemesThemePlugin.php
500 lines
1 <?php
2
3 // Exit if accessed directly
4 if (! defined('ABSPATH')) exit;
5
6 class CatchThemesThemePlugin
7 {
8 public function __construct()
9 {
10 remove_action('wp_ajax_query-themes', array($this, 'wp_ajax_query_themes'), 1);
11 add_action('wp_ajax_query-themes', array($this, 'wp_ajax_custom_query_themes'), 1);
12
13 add_action('admin_enqueue_scripts', array($this, 'our_themes_script'));
14
15 if (! is_multisite()) {
16 add_action('customize_register', array($this, 'customize_register'));
17 }
18
19 global $wp_customize;
20 remove_action('wp_ajax_customize_load_themes', array($wp_customize, 'handle_load_themes_request'));
21 add_action('wp_ajax_customize_load_themes', array($this, 'handle_load_themes_request'));
22
23 add_filter('install_plugins_tabs', array($this, 'add_our_plugins_tab'), 1);
24 add_filter('install_plugins_table_api_args_catchplugins', array($this, 'catchplugins'), 1);
25 add_action('install_plugins_catchplugins', array($this, 'plugins_table'));
26 }
27
28 /* Adds Catch Themes tab in Add Theme page to show all themes by Catch Themes in wordpress.org
29 * taken from wp-admin/includes/ajax-action.php wp_ajax_query_themes().
30 * Ajax handler for getting themes from themes_api().
31 *
32 * @since 3.9.0
33 *
34 * @global array $themes_allowedtags
35 * @global array $theme_field_defaults
36 */
37 public function wp_ajax_custom_query_themes()
38 {
39 global $themes_allowedtags, $theme_field_defaults;
40
41 if (! current_user_can('install_themes')) {
42 wp_send_json_error();
43 }
44
45 $args = wp_parse_args(
46 wp_unslash($_REQUEST['request']),
47 array(
48 'per_page' => 20,
49 'fields' => array_merge(
50 (array) $theme_field_defaults,
51 array(
52 'reviews_url' => true, // Explicitly request the reviews URL to be linked from the Add Themes screen.
53 )
54 ),
55 )
56 );
57
58 if (isset($args['browse']) && 'catchthemes' === $args['browse'] && ! isset($args['user'])) {
59 $args['author'] = 'catchthemes';
60 unset($args['browse']);
61 }
62
63 if (isset($args['browse']) && 'favorites' === $args['browse'] && ! isset($args['user'])) {
64 $user = get_user_option('wporg_favorites');
65 if ($user) {
66 $args['user'] = $user;
67 }
68 }
69
70 $old_filter = isset($args['browse']) ? $args['browse'] : 'search';
71
72 /** This filter is documented in wp-admin/includes/class-wp-theme-install-list-table.php */
73 $args = apply_filters('install_themes_table_api_args_' . $old_filter, $args);
74
75 $api = themes_api('query_themes', $args);
76
77 if (is_wp_error($api)) {
78 wp_send_json_error();
79 }
80
81 $update_php = network_admin_url('update.php?action=install-theme');
82 foreach ($api->themes as &$theme) {
83 $theme->install_url = add_query_arg(
84 array(
85 'theme' => $theme->slug,
86 '_wpnonce' => wp_create_nonce('install-theme_' . $theme->slug),
87 ),
88 $update_php
89 );
90
91 if (current_user_can('switch_themes')) {
92 if (is_multisite()) {
93 $theme->activate_url = add_query_arg(
94 array(
95 'action' => 'enable',
96 '_wpnonce' => wp_create_nonce('enable-theme_' . $theme->slug),
97 'theme' => $theme->slug,
98 ),
99 network_admin_url('themes.php')
100 );
101 } else {
102 $theme->activate_url = add_query_arg(
103 array(
104 'action' => 'activate',
105 '_wpnonce' => wp_create_nonce('switch-theme_' . $theme->slug),
106 'stylesheet' => $theme->slug,
107 ),
108 admin_url('themes.php')
109 );
110 }
111 }
112
113 if (! is_multisite() && current_user_can('edit_theme_options') && current_user_can('customize')) {
114 $theme->customize_url = add_query_arg(
115 array(
116 'return' => urlencode(network_admin_url('theme-install.php', 'relative')),
117 ),
118 wp_customize_url($theme->slug)
119 );
120 }
121
122 $theme->name = wp_kses($theme->name, $themes_allowedtags);
123 $theme->author = wp_kses($theme->author['display_name'], $themes_allowedtags);
124 $theme->version = wp_kses($theme->version, $themes_allowedtags);
125 $theme->description = wp_kses($theme->description, $themes_allowedtags);
126
127 $theme->stars = wp_star_rating(
128 array(
129 'rating' => $theme->rating,
130 'type' => 'percent',
131 'number' => $theme->num_ratings,
132 'echo' => false,
133 )
134 );
135
136 $theme->num_ratings = number_format_i18n($theme->num_ratings);
137 $theme->preview_url = set_url_scheme($theme->preview_url);
138 $theme->compatible_wp = is_wp_version_compatible($theme->requires);
139 $theme->compatible_php = is_php_version_compatible($theme->requires_php);
140 }
141
142 wp_send_json_success($api);
143 }
144
145 public function our_themes_script($hook_suffix)
146 {
147
148 if ('theme-install.php' === $hook_suffix) {
149 wp_enqueue_script('our-themes-script', plugin_dir_url(__FILE__) . '../admin/js/our-themes.js', array('jquery'), '2018-05-16');
150 }
151 }
152
153 /* Add Catch Themes Section in Theme in Customizer */
154 public function customize_register($wp_customize)
155 {
156 $wp_customize->add_section(
157 new WP_Customize_Themes_Section(
158 $wp_customize,
159 'catchthemes',
160 array(
161 'title' => __('Themes by CatchThemes', 'catch-scroll-progress-bar'),
162 'action' => 'catchthemes',
163 'capability' => 'install_themes',
164 'panel' => 'themes',
165 'priority' => 6,
166 )
167 )
168 );
169 }
170
171
172
173
174 /**
175 * Load themes into the theme browsing/installation UI.
176 * taken from wp-includes/cllass-wp-customize-manager.php
177 * @since 4.9.0
178 */
179 public function handle_load_themes_request()
180 {
181 check_ajax_referer('switch_themes', 'nonce');
182 if (! current_user_can('switch_themes')) {
183 wp_die(-1);
184 }
185
186 if (empty($_POST['theme_action'])) {
187 wp_send_json_error('missing_theme_action');
188 }
189 $theme_action = sanitize_key($_POST['theme_action']);
190 $themes = array();
191 $args = array();
192
193 // Define query filters based on user input.
194 if (! array_key_exists('search', $_POST)) {
195 $args['search'] = '';
196 } else {
197 $args['search'] = sanitize_text_field(wp_unslash($_POST['search']));
198 }
199
200 if (! array_key_exists('tags', $_POST)) {
201 $args['tag'] = '';
202 } else {
203 $args['tag'] = array_map('sanitize_text_field', wp_unslash((array) $_POST['tags']));
204 }
205
206 if (! array_key_exists('page', $_POST)) {
207 $args['page'] = 1;
208 } else {
209 $args['page'] = absint($_POST['page']);
210 }
211
212 require_once ABSPATH . 'wp-admin/includes/theme.php';
213
214 if ('installed' === $theme_action) {
215
216 // Load all installed themes from wp_prepare_themes_for_js().
217 $themes = array('themes' => wp_prepare_themes_for_js());
218 foreach ($themes['themes'] as &$theme) {
219 $theme['type'] = 'installed';
220 $theme['active'] = (isset($_POST['customized_theme']) && $_POST['customized_theme'] === $theme['id']);
221 }
222 } elseif ('catchthemes' === $theme_action) {
223
224 // Load WordPress.org themes from the .org API and normalize data to match installed theme objects.
225 if (! current_user_can('install_themes')) {
226 wp_die(-1);
227 }
228
229 // Arguments for all queries.
230 $wporg_args = array(
231 'per_page' => 100,
232 'fields' => array(
233 'reviews_url' => true, // Explicitly request the reviews URL to be linked from the customizer.
234 ),
235 );
236
237 $args = array_merge($wporg_args, $args);
238
239 if ('' === $args['search'] && '' === $args['tag']) {
240 $args['browse'] = 'new'; // Sort by latest themes by default.
241 }
242
243 $args['author'] = 'catchthemes';
244
245 // Load themes from the .org API.
246 $themes = themes_api('query_themes', $args);
247 if (is_wp_error($themes)) {
248 wp_send_json_error();
249 }
250
251 // This list matches the allowed tags in wp-admin/includes/theme-install.php.
252 $themes_allowedtags = array_fill_keys(
253 array('a', 'abbr', 'acronym', 'code', 'pre', 'em', 'strong', 'div', 'p', 'ul', 'ol', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img'),
254 array()
255 );
256 $themes_allowedtags['a'] = array_fill_keys(array('href', 'title', 'target'), true);
257 $themes_allowedtags['acronym']['title'] = true;
258 $themes_allowedtags['abbr']['title'] = true;
259 $themes_allowedtags['img'] = array_fill_keys(array('src', 'class', 'alt'), true);
260
261 // Prepare a list of installed themes to check against before the loop.
262 $installed_themes = array();
263 $wp_themes = wp_get_themes();
264 foreach ($wp_themes as $theme) {
265 $installed_themes[] = $theme->get_stylesheet();
266 }
267 $update_php = network_admin_url('update.php?action=install-theme');
268
269 // Set up properties for themes available on WordPress.org.
270 foreach ($themes->themes as &$theme) {
271 $theme->install_url = add_query_arg(
272 array(
273 'theme' => $theme->slug,
274 '_wpnonce' => wp_create_nonce('install-theme_' . $theme->slug),
275 ),
276 $update_php
277 );
278
279 $theme->name = wp_kses($theme->name, $themes_allowedtags);
280 $theme->version = wp_kses($theme->version, $themes_allowedtags);
281 $theme->description = wp_kses($theme->description, $themes_allowedtags);
282 $theme->stars = wp_star_rating(
283 array(
284 'rating' => $theme->rating,
285 'type' => 'percent',
286 'number' => $theme->num_ratings,
287 'echo' => false,
288 )
289 );
290 $theme->num_ratings = number_format_i18n($theme->num_ratings);
291 $theme->preview_url = set_url_scheme($theme->preview_url);
292
293 // Handle themes that are already installed as installed themes.
294 if (in_array($theme->slug, $installed_themes, true)) {
295 $theme->type = 'installed';
296 } else {
297 $theme->type = $theme_action;
298 }
299
300 // Set active based on customized theme.
301 $theme->active = (isset($_POST['customized_theme']) && $_POST['customized_theme'] === $theme->slug);
302
303 // Map available theme properties to installed theme properties.
304 $theme->id = $theme->slug;
305 $theme->screenshot = array($theme->screenshot_url);
306 $theme->authorAndUri = wp_kses($theme->author['display_name'], $themes_allowedtags);
307 $theme->compatibleWP = is_wp_version_compatible($theme->requires); // phpcs:ignore WordPress.NamingConventions.ValidVariableName
308 $theme->compatiblePHP = is_php_version_compatible($theme->requires_php); // phpcs:ignore WordPress.NamingConventions.ValidVariableName
309
310 if (isset($theme->parent)) {
311 $theme->parent = $theme->parent['slug'];
312 } else {
313 $theme->parent = false;
314 }
315 unset($theme->slug);
316 unset($theme->screenshot_url);
317 unset($theme->author);
318 } // End foreach().
319 } elseif ('wporg' === $theme_action) {
320
321 // Load WordPress.org themes from the .org API and normalize data to match installed theme objects.
322 if (! current_user_can('install_themes')) {
323 wp_die(-1);
324 }
325
326 // Arguments for all queries.
327 $wporg_args = array(
328 'per_page' => 100,
329 'fields' => array(
330 'reviews_url' => true, // Explicitly request the reviews URL to be linked from the customizer.
331 ),
332 );
333
334 $args = array_merge($wporg_args, $args);
335
336 if ('' === $args['search'] && '' === $args['tag']) {
337 $args['browse'] = 'new'; // Sort by latest themes by default.
338 }
339
340 // Load themes from the .org API.
341 $themes = themes_api('query_themes', $args);
342 if (is_wp_error($themes)) {
343 wp_send_json_error();
344 }
345
346 // This list matches the allowed tags in wp-admin/includes/theme-install.php.
347 $themes_allowedtags = array_fill_keys(
348 array('a', 'abbr', 'acronym', 'code', 'pre', 'em', 'strong', 'div', 'p', 'ul', 'ol', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img'),
349 array()
350 );
351 $themes_allowedtags['a'] = array_fill_keys(array('href', 'title', 'target'), true);
352 $themes_allowedtags['acronym']['title'] = true;
353 $themes_allowedtags['abbr']['title'] = true;
354 $themes_allowedtags['img'] = array_fill_keys(array('src', 'class', 'alt'), true);
355
356 // Prepare a list of installed themes to check against before the loop.
357 $installed_themes = array();
358 $wp_themes = wp_get_themes();
359 foreach ($wp_themes as $theme) {
360 $installed_themes[] = $theme->get_stylesheet();
361 }
362 $update_php = network_admin_url('update.php?action=install-theme');
363
364 // Set up properties for themes available on WordPress.org.
365 foreach ($themes->themes as &$theme) {
366 $theme->install_url = add_query_arg(
367 array(
368 'theme' => $theme->slug,
369 '_wpnonce' => wp_create_nonce('install-theme_' . $theme->slug),
370 ),
371 $update_php
372 );
373
374 $theme->name = wp_kses($theme->name, $themes_allowedtags);
375 $theme->version = wp_kses($theme->version, $themes_allowedtags);
376 $theme->description = wp_kses($theme->description, $themes_allowedtags);
377 $theme->stars = wp_star_rating(
378 array(
379 'rating' => $theme->rating,
380 'type' => 'percent',
381 'number' => $theme->num_ratings,
382 'echo' => false,
383 )
384 );
385 $theme->num_ratings = number_format_i18n($theme->num_ratings);
386 $theme->preview_url = set_url_scheme($theme->preview_url);
387
388 // Handle themes that are already installed as installed themes.
389 if (in_array($theme->slug, $installed_themes, true)) {
390 $theme->type = 'installed';
391 } else {
392 $theme->type = $theme_action;
393 }
394
395 // Set active based on customized theme.
396 $theme->active = (isset($_POST['customized_theme']) && $_POST['customized_theme'] === $theme->slug);
397
398 // Map available theme properties to installed theme properties.
399 $theme->id = $theme->slug;
400 $theme->screenshot = array($theme->screenshot_url);
401 $theme->authorAndUri = wp_kses($theme->author['display_name'], $themes_allowedtags);
402 $theme->compatibleWP = is_wp_version_compatible($theme->requires); // phpcs:ignore WordPress.NamingConventions.ValidVariableName
403 $theme->compatiblePHP = is_php_version_compatible($theme->requires_php); // phpcs:ignore WordPress.NamingConventions.ValidVariableName
404
405 if (isset($theme->parent)) {
406 $theme->parent = $theme->parent['slug'];
407 } else {
408 $theme->parent = false;
409 }
410 unset($theme->slug);
411 unset($theme->screenshot_url);
412 unset($theme->author);
413 } // End foreach().
414 } // End if().
415
416 /**
417 * Filters the theme data loaded in the customizer.
418 *
419 * This allows theme data to be loading from an external source,
420 * or modification of data loaded from `wp_prepare_themes_for_js()`
421 * or WordPress.org via `themes_api()`.
422 *
423 * @since 4.9.0
424 *
425 * @see wp_prepare_themes_for_js()
426 * @see themes_api()
427 * @see WP_Customize_Manager::__construct()
428 *
429 * @param array $themes Nested array of theme data.
430 * @param array $args List of arguments, such as page, search term, and tags to query for.
431 * @param WP_Customize_Manager $manager Instance of Customize manager.
432 */
433 $themes = apply_filters('customize_load_themes', $themes, $args, $wp_customize);
434
435 wp_send_json_success($themes);
436 }
437
438 /* Plugins */
439 /* Adds Catch Plugins tab in Add Plugin page to show all plugins by Catch Plugins in wordpress.org */
440 public function add_our_plugins_tab($tabs)
441 {
442 // Add our filter here
443 $tabs['catchplugins'] = _x('Catch Plugins', 'Plugin Installer', 'catch-scroll-progress-bar');
444
445 return $tabs;
446 }
447
448 public function catchplugins()
449 {
450 /* From CORE Start */
451 global $paged, $tab;
452 wp_reset_vars(array('tab'));
453
454 $defined_class = new WP_Plugin_Install_List_Table();
455 $paged = $defined_class->get_pagenum();
456
457 $per_page = 30;
458 //$installed_plugins = catch_get_installed_plugins();
459
460 $args = array(
461 'page' => $paged,
462 'per_page' => $per_page,
463 'fields' => array(
464 'last_updated' => true,
465 'icons' => true,
466 'active_installs' => true,
467 ),
468 // Send the locale and installed plugin slugs to the API so it can provide context-sensitive results.
469 'locale' => get_user_locale(),
470 //'installed_plugins' => array_keys( $installed_plugins ),
471 );
472 /* From CORE End */
473
474 // Add author filter for our plugins
475 $args['author'] = 'catchplugins';
476
477 return $args;
478 }
479
480 public function plugins_table()
481 {
482 global $wp_list_table;
483 printf(
484 '<p class="catch-plugins-list">%s</p>',
485 sprintf(
486 // Translators: %s is the URL to the Catch Plugins website.
487 wp_kses_post(__('You can use any of our free plugins or premium plugins from <a href="%s" target="_blank">Catch Plugins</a>.', 'catch-scroll-progress-bar')),
488 esc_url('https://catchplugins.com/')
489 )
490 );
491 ?>
492 <form id="plugin-filter" method="post">
493 <?php $wp_list_table->display(); ?>
494 </form>
495 <?php
496 }
497 }
498
499 $catchthemes_theme_plugin = new CatchThemesThemePlugin();
500