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