From ae33b44821616479253b85424b92b78d1a389dc5 Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Thu, 24 Apr 2025 11:55:01 +0200 Subject: [PATCH 01/15] Rename files --- classes/{PluginInstall.class.php => class-plugin-install.php} | 0 classes/{PluginUpdate.class.php => class-plugin-update.php} | 0 classes/{ThemeInstall.class.php => class-theme-install.php} | 0 classes/{ThemeUpdate.class.php => class-theme-update.php} | 0 classes/{WPCLI.class.php => class-wpcli.php} | 0 classes/{Helpers.trait.php => trait-helpers.php} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename classes/{PluginInstall.class.php => class-plugin-install.php} (100%) rename classes/{PluginUpdate.class.php => class-plugin-update.php} (100%) rename classes/{ThemeInstall.class.php => class-theme-install.php} (100%) rename classes/{ThemeUpdate.class.php => class-theme-update.php} (100%) rename classes/{WPCLI.class.php => class-wpcli.php} (100%) rename classes/{Helpers.trait.php => trait-helpers.php} (100%) diff --git a/classes/PluginInstall.class.php b/classes/class-plugin-install.php similarity index 100% rename from classes/PluginInstall.class.php rename to classes/class-plugin-install.php diff --git a/classes/PluginUpdate.class.php b/classes/class-plugin-update.php similarity index 100% rename from classes/PluginUpdate.class.php rename to classes/class-plugin-update.php diff --git a/classes/ThemeInstall.class.php b/classes/class-theme-install.php similarity index 100% rename from classes/ThemeInstall.class.php rename to classes/class-theme-install.php diff --git a/classes/ThemeUpdate.class.php b/classes/class-theme-update.php similarity index 100% rename from classes/ThemeUpdate.class.php rename to classes/class-theme-update.php diff --git a/classes/WPCLI.class.php b/classes/class-wpcli.php similarity index 100% rename from classes/WPCLI.class.php rename to classes/class-wpcli.php diff --git a/classes/Helpers.trait.php b/classes/trait-helpers.php similarity index 100% rename from classes/Helpers.trait.php rename to classes/trait-helpers.php From 6a8ac03cb85b8e198bb9f6b1254e9714feb911b5 Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Thu, 24 Apr 2025 11:56:12 +0200 Subject: [PATCH 02/15] Apply phpcbf --- classes/class-plugin-install.php | 391 ++++++++++++------------ classes/class-plugin-update.php | 285 +++++++++--------- classes/class-theme-install.php | 392 +++++++++++++------------ classes/class-theme-update.php | 89 +++--- classes/class-wpcli.php | 28 +- classes/index.php | 2 +- classes/trait-helpers.php | 15 +- classicpress-directory-integration.php | 172 +++++------ images/index.php | 2 +- includes/constants.php | 38 +-- includes/functions.php | 34 +-- includes/index.php | 2 +- index.php | 2 +- scripts/index.php | 2 +- styles/index.php | 2 +- 15 files changed, 735 insertions(+), 721 deletions(-) diff --git a/classes/class-plugin-install.php b/classes/class-plugin-install.php index 697f989..b5967d0 100644 --- a/classes/class-plugin-install.php +++ b/classes/class-plugin-install.php @@ -4,72 +4,68 @@ require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; -class PluginInstall -{ +class PluginInstall { + use Helpers; private $local_cp_plugins = false; private $page = null; - public function __construct() - { + public function __construct() { // Add menu under plugins. - if (is_multisite()) { - add_action('network_admin_menu', [$this, 'create_menu'], 100); - add_action('network_admin_menu', [$this, 'rename_menu']); + if ( is_multisite() ) { + add_action( 'network_admin_menu', array( $this, 'create_menu' ), 100 ); + add_action( 'network_admin_menu', array( $this, 'rename_menu' ) ); } else { - add_action('admin_menu', [$this, 'create_menu'], 100); - add_action('admin_menu', [$this, 'rename_menu']); + add_action( 'admin_menu', array( $this, 'create_menu' ), 100 ); + add_action( 'admin_menu', array( $this, 'rename_menu' ) ); } - add_action('admin_enqueue_scripts', [$this, 'styles']); - add_action('admin_enqueue_scripts', [$this, 'scripts']); + add_action( 'admin_enqueue_scripts', array( $this, 'styles' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) ); } - public function styles($hook) - { - if ($hook !== $this->page) { + public function styles( $hook ) { + if ( $hook !== $this->page ) { return; } - wp_enqueue_style( 'classicpress-directory-integration-css', plugins_url( '../styles/directory-integration.css', __FILE__ ), []) ; + wp_enqueue_style( 'classicpress-directory-integration-css', plugins_url( '../styles/directory-integration.css', __FILE__ ), array() ); } - public function scripts($hook) - { - if ($hook !== $this->page) { + public function scripts( $hook ) { + if ( $hook !== $this->page ) { return; } wp_enqueue_script( 'classicpress-directory-integration-js', plugins_url( '../scripts/directory-integration.js', __FILE__ ), array( 'wp-i18n' ), false, true ); wp_set_script_translations( 'classicpress-directory-integration-js', 'classicpress-directory-integration', plugin_dir_path( 'classicpress-directory-integration' ) . 'languages' ); } - public function create_menu() - { - if (!current_user_can('install_plugins')) { + public function create_menu() { + if ( ! current_user_can( 'install_plugins' ) ) { return; } $this->page = add_submenu_page( 'plugins.php', - esc_html__('Install ClassicPress Plugins', 'classicpress-directory-integration'), - esc_html__('Install CP Plugins', 'classicpress-directory-integration'), + esc_html__( 'Install ClassicPress Plugins', 'classicpress-directory-integration' ), + esc_html__( 'Install CP Plugins', 'classicpress-directory-integration' ), 'install_plugins', 'classicpress-directory-integration-plugin-install', - [$this, 'render_menu'], + array( $this, 'render_menu' ), 2 ); - add_action('load-' . $this->page, [$this, 'activate_action']); - add_action('load-' . $this->page, [$this, 'install_action']); + add_action( 'load-' . $this->page, array( $this, 'activate_action' ) ); + add_action( 'load-' . $this->page, array( $this, 'install_action' ) ); } public function rename_menu() { global $submenu; foreach ( $submenu['plugins.php'] as $key => $value ) { - if($value[2] !== 'plugin-install.php') { + if ( $value[2] !== 'plugin-install.php' ) { continue; } - $submenu['plugins.php'][$key][0] = esc_html__('Install WP Plugins', 'classicpress-directory-integration'); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + $submenu['plugins.php'][ $key ][0] = esc_html__( 'Install WP Plugins', 'classicpress-directory-integration' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited } } @@ -77,29 +73,28 @@ public function rename_menu() { // This function is different from the one in PluginUpdate class // and considers a plugin from the dir not only if it has UpdateURI // but also if it has RequiresCP. - private function get_local_cp_plugins() - { + private function get_local_cp_plugins() { - if ($this->local_cp_plugins !== false) { + if ( $this->local_cp_plugins !== false ) { return $this->local_cp_plugins; } $all_plugins = get_plugins(); - $cp_plugins = []; - foreach ($all_plugins as $slug => $plugin) { - if (!array_key_exists('UpdateURI', $plugin) && !array_key_exists('RequiresCP', $plugin)) { + $cp_plugins = array(); + foreach ( $all_plugins as $slug => $plugin ) { + if ( ! array_key_exists( 'UpdateURI', $plugin ) && ! array_key_exists( 'RequiresCP', $plugin ) ) { continue; } - if (strpos($plugin['UpdateURI'], \CLASSICPRESS_DIRECTORY_INTEGRATION_URL) !== 0 && !array_key_exists('RequiresCP', $plugin)) { + if ( strpos( $plugin['UpdateURI'], \CLASSICPRESS_DIRECTORY_INTEGRATION_URL ) !== 0 && ! array_key_exists( 'RequiresCP', $plugin ) ) { continue; } - $cp_plugins[dirname($slug)] = [ - 'WPSlug' => $slug, - 'Name' => $plugin['Name'], - 'Version' => $plugin['Version'], - 'PluginURI' => array_key_exists('PluginURI', $plugin) ? $plugin['PluginURI'] : null, - 'Active' => is_plugin_active($slug), - ]; + $cp_plugins[ dirname( $slug ) ] = array( + 'WPSlug' => $slug, + 'Name' => $plugin['Name'], + 'Version' => $plugin['Version'], + 'PluginURI' => array_key_exists( 'PluginURI', $plugin ) ? $plugin['PluginURI'] : null, + 'Active' => is_plugin_active( $slug ), + ); } $this->local_cp_plugins = $cp_plugins; @@ -107,86 +102,84 @@ private function get_local_cp_plugins() } // Validate and sanitize args for quering the ClassicPress Directory - public static function sanitize_args($args) - { - foreach ($args as $key => $value) { + public static function sanitize_args( $args ) { + foreach ( $args as $key => $value ) { $sanitized = false; - switch ($key) { + switch ( $key ) { case 'per_page': case 'page': - $args[$key] = (int) $value; - $sanitized = true; + $args[ $key ] = (int) $value; + $sanitized = true; break; case 'byslug': - $args[$key] = preg_replace('[^A-Za-z0-9\-_]', '', $value); - $sanitized = true; + $args[ $key ] = preg_replace( '[^A-Za-z0-9\-_]', '', $value ); + $sanitized = true; break; case 'search': - $args[$key] = sanitize_text_field($value); - $sanitized = true; + $args[ $key ] = sanitize_text_field( $value ); + $sanitized = true; break; case '_fields': - $args[$key] = preg_replace('[^A-Za-z0-9\-_,]', '', $value); - $sanitized = true; + $args[ $key ] = preg_replace( '[^A-Za-z0-9\-_,]', '', $value ); + $sanitized = true; break; } - if ($sanitized) { + if ( $sanitized ) { continue; } - unset($args[$key]); + unset( $args[ $key ] ); } return $args; } // Query the ClassicPress Directory - public static function do_directory_request($args = [], $type = 'plugins') - { + public static function do_directory_request( $args = array(), $type = 'plugins' ) { $result['success'] = false; - if (!in_array($type, ['plugins', 'themes'])) { + if ( ! in_array( $type, array( 'plugins', 'themes' ) ) ) { $result['error'] = $type . ' is not a supported type'; return $result; } - $args = self::sanitize_args($args); + $args = self::sanitize_args( $args ); $endpoint = \CLASSICPRESS_DIRECTORY_INTEGRATION_URL . $type; - $endpoint = add_query_arg($args, $endpoint); + $endpoint = add_query_arg( $args, $endpoint ); - $response = wp_remote_get($endpoint, ['user-agent' => classicpress_user_agent()]); + $response = wp_remote_get( $endpoint, array( 'user-agent' => classicpress_user_agent() ) ); - if (is_wp_error($response)) { - $result['error'] = rtrim(implode(',', $response->get_error_messages()), '.'); + if ( is_wp_error( $response ) ) { + $result['error'] = rtrim( implode( ',', $response->get_error_messages() ), '.' ); return $result; } - $e = wp_remote_retrieve_response_code($response); - if ($e !== 200) { - $result['error'] = $response['response']['message'].'.'; + $e = wp_remote_retrieve_response_code( $response ); + if ( $e !== 200 ) { + $result['error'] = $response['response']['message'] . '.'; $result['code'] = $response['response']['code']; - if (!isset($response['body']) || !json_validate($response['body'])) { + if ( ! isset( $response['body'] ) || ! json_validate( $response['body'] ) ) { return $result; } - $api_message = json_decode($response['body'], true); - if(!isset($api_message['message'])) { + $api_message = json_decode( $response['body'], true ); + if ( ! isset( $api_message['message'] ) ) { return $result; } - $result['error'] .= ' '.$api_message['message']; + $result['error'] .= ' ' . $api_message['message']; return $result; } - if (!isset($response['headers'])) { + if ( ! isset( $response['headers'] ) ) { $result['error'] = 'No headers found'; return $result; } $headers = $response['headers']->getAll(); - if (!isset($headers['x-wp-total']) || !isset($headers['x-wp-totalpages'])) { + if ( ! isset( $headers['x-wp-total'] ) || ! isset( $headers['x-wp-totalpages'] ) ) { $result['error'] = 'No pagination headers found'; return $result; } - $data_from_dir = json_decode(wp_remote_retrieve_body($response), true); - if ($data_from_dir === null) { + $data_from_dir = json_decode( wp_remote_retrieve_body( $response ), true ); + if ( $data_from_dir === null ) { $result['error'] = 'Failed decoding response'; return $result; } @@ -200,111 +193,107 @@ public static function do_directory_request($args = [], $type = 'plugins') } // Enqueue a notice - private function add_notice($message, $failure = false) - { - $other_notices = get_transient('cpdi_pi_notices'); - $notice = $other_notices === false ? '' : $other_notices; + private function add_notice( $message, $failure = false ) { + $other_notices = get_transient( 'cpdi_pi_notices' ); + $notice = $other_notices === false ? '' : $other_notices; $failure_style = $failure ? 'notice-error' : 'notice-success'; - $notice .= '
'; - $notice .= '

' . esc_html($message) . '

'; - $notice .= '
'; - set_transient('cpdi_pi_notices', $notice, \HOUR_IN_SECONDS); + $notice .= '
'; + $notice .= '

' . esc_html( $message ) . '

'; + $notice .= '
'; + set_transient( 'cpdi_pi_notices', $notice, \HOUR_IN_SECONDS ); } // Display notices - private function display_notices() - { - $notices = get_transient('cpdi_pi_notices'); - if ($notices === false) { + private function display_notices() { + $notices = get_transient( 'cpdi_pi_notices' ); + if ( $notices === false ) { return; } // This contains html formatted from 'add_notice' function that uses 'esc_html'. echo $notices; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - delete_transient('cpdi_pi_notices'); + delete_transient( 'cpdi_pi_notices' ); } // Deal with activation requests - public function activate_action() - { + public function activate_action() { // Load local plugins information $local_cp_plugins = $this->get_local_cp_plugins(); // Security checks - if (!isset($_GET['action'])) { + if ( ! isset( $_GET['action'] ) ) { return; } - if ($_GET['action'] !== 'activate') { + if ( $_GET['action'] !== 'activate' ) { return; } - if (!check_admin_referer('activate', '_cpdi')) { + if ( ! check_admin_referer( 'activate', '_cpdi' ) ) { return; } - if (!current_user_can('activate_plugins')) { + if ( ! current_user_can( 'activate_plugins' ) ) { return; } - if (!isset($_REQUEST['slug'])) { + if ( ! isset( $_REQUEST['slug'] ) ) { return; } // Check if plugin slug is proper - $slug = sanitize_key(wp_unslash($_REQUEST['slug'])); - if (!array_key_exists($slug, $local_cp_plugins)) { + $slug = sanitize_key( wp_unslash( $_REQUEST['slug'] ) ); + if ( ! array_key_exists( $slug, $local_cp_plugins ) ) { return; } // Activate plugin - $result = activate_plugin($local_cp_plugins[$slug]['WPSlug']); + $result = activate_plugin( $local_cp_plugins[ $slug ]['WPSlug'] ); - if ($result !== null) { + if ( $result !== null ) { // Translators: %1$s is the plugin name. - $message = sprintf(esc_html__('Error activating %1$s.', 'classicpress-directory-integration'), $local_cp_plugins[$slug]['Name']); - $this->add_notice($message, true); + $message = sprintf( esc_html__( 'Error activating %1$s.', 'classicpress-directory-integration' ), $local_cp_plugins[ $slug ]['Name'] ); + $this->add_notice( $message, true ); } else { // Translators: %1$s is the plugin name. - $message = sprintf(esc_html__('%1$s activated.', 'classicpress-directory-integration'), $local_cp_plugins[$slug]['Name']); - $this->add_notice($message, false); + $message = sprintf( esc_html__( '%1$s activated.', 'classicpress-directory-integration' ), $local_cp_plugins[ $slug ]['Name'] ); + $this->add_notice( $message, false ); } - $sendback = remove_query_arg(['action', 'slug', '_cpdi'], wp_get_referer()); - wp_safe_redirect($sendback); + $sendback = remove_query_arg( array( 'action', 'slug', '_cpdi' ), wp_get_referer() ); + wp_safe_redirect( $sendback ); exit; } // Deal with installation requests - public function install_action() - { + public function install_action() { // Security checks - if (!isset($_GET['action'])) { + if ( ! isset( $_GET['action'] ) ) { return; } - if ($_GET['action'] !== 'install') { + if ( $_GET['action'] !== 'install' ) { return; } - if (!check_admin_referer('install', '_cpdi')) { + if ( ! check_admin_referer( 'install', '_cpdi' ) ) { return; } - if (!current_user_can('install_plugins')) { + if ( ! current_user_can( 'install_plugins' ) ) { return; } - if (!isset($_REQUEST['slug'])) { + if ( ! isset( $_REQUEST['slug'] ) ) { return; } // Check if plugin slug is proper - $slug = sanitize_key(wp_unslash($_REQUEST['slug'])); + $slug = sanitize_key( wp_unslash( $_REQUEST['slug'] ) ); // Get github release file - $args = [ + $args = array( 'byslug' => $slug, '_fields' => 'meta,title', - ]; - $response = $this->do_directory_request($args, 'plugins'); - if (!$response['success'] || !isset($response['response'][0]['meta']['download_link'])) { + ); + $response = $this->do_directory_request( $args, 'plugins' ); + if ( ! $response['success'] || ! isset( $response['response'][0]['meta']['download_link'] ) ) { // Translators: %1$s is the plugin name. - $message = sprintf(esc_html__('API error.', 'classicpress-directory-integration'), $local_cp_plugins[$slug]['Name']); - $this->add_notice($message, true); - $sendback = remove_query_arg(['action', 'slug', '_cpdi'], wp_get_referer()); - wp_safe_redirect($sendback); + $message = sprintf( esc_html__( 'API error.', 'classicpress-directory-integration' ), $local_cp_plugins[ $slug ]['Name'] ); + $this->add_notice( $message, true ); + $sendback = remove_query_arg( array( 'action', 'slug', '_cpdi' ), wp_get_referer() ); + wp_safe_redirect( $sendback ); exit; } @@ -312,86 +301,86 @@ public function install_action() $plugin_name = $response['response'][0]['title']['rendered']; // Install plugin - $skin = new PluginInstallSkin(['type' => 'plugin']); - $upgrader = new \Plugin_Upgrader($skin); - $response = $upgrader->install($installation_url); + $skin = new PluginInstallSkin( array( 'type' => 'plugin' ) ); + $upgrader = new \Plugin_Upgrader( $skin ); + $response = $upgrader->install( $installation_url ); - if ($response !== true) { + if ( $response !== true ) { // Translators: %1$s is the plugin name. - $message = sprintf(esc_html__('Error installing %1$s.', 'classicpress-directory-integration'), $plugin_name); - $this->add_notice($message, true); + $message = sprintf( esc_html__( 'Error installing %1$s.', 'classicpress-directory-integration' ), $plugin_name ); + $this->add_notice( $message, true ); } else { // Translators: %1$s is the plugin name. - $message = sprintf(esc_html__('%1$s installed.', 'classicpress-directory-integration'), $plugin_name); - $this->add_notice($message, false); + $message = sprintf( esc_html__( '%1$s installed.', 'classicpress-directory-integration' ), $plugin_name ); + $this->add_notice( $message, false ); } - $sendback = remove_query_arg(['action', 'slug', '_cpdi'], wp_get_referer()); - wp_safe_redirect($sendback); + $sendback = remove_query_arg( array( 'action', 'slug', '_cpdi' ), wp_get_referer() ); + wp_safe_redirect( $sendback ); exit; } // Render "Install CP plugins" menu - public function render_menu() - { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh + public function render_menu() { + // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh // Load local plugins information $local_cp_plugins = $this->get_local_cp_plugins(); // Set age number if empty // We check nonces only on activations and installations. // In this function nothing is modified. - $page = isset($_REQUEST['getpage']) ? (int) $_REQUEST['getpage'] : 1; //phpcs:ignore WordPress.Security.NonceVerification.Recommended + $page = isset( $_REQUEST['getpage'] ) ? (int) $_REQUEST['getpage'] : 1; //phpcs:ignore WordPress.Security.NonceVerification.Recommended // Query the directory - $args = [ + $args = array( 'per_page' => 12, 'page' => $page, - ]; + ); - if (isset($_REQUEST['searchfor'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended - $args['search'] = sanitize_text_field(wp_unslash($_REQUEST['searchfor'])); //phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( isset( $_REQUEST['searchfor'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended + $args['search'] = sanitize_text_field( wp_unslash( $_REQUEST['searchfor'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended } // Reset paginations for new searches $searching = $args['search'] ?? ''; - if (isset($_REQUEST['searchingfor']) && $_REQUEST['searchingfor'] !== $searching) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( isset( $_REQUEST['searchingfor'] ) && $_REQUEST['searchingfor'] !== $searching ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended $args['page'] = 1; } - $result = $this->do_directory_request($args); - if ($result['success'] === false) { + $result = $this->do_directory_request( $args ); + if ( $result['success'] === false ) { // Query failed, display errors and exit. - $this->add_notice(esc_html($result['error']).' ('.esc_html($result['code']).').', true); + $this->add_notice( esc_html( $result['error'] ) . ' (' . esc_html( $result['code'] ) . ').', true ); } // Set up variables - $plugins = $result['response'] ?? []; + $plugins = $result['response'] ?? array(); $pages = $result['total-pages'] ?? 0; - if ($plugins === []) { - $this->add_notice(esc_html__('No plugins found.', 'classicpress-directory-integration'), true); + if ( $plugins === array() ) { + $this->add_notice( esc_html__( 'No plugins found.', 'classicpress-directory-integration' ), true ); } // Display notices $this->display_notices(); -?> + ?>
-

-

+

+

-
+ @@ -403,53 +392,80 @@ public function render_menu()
' : ''; - $vetted_article = $plugin['meta']['cpcs_status'] === 'passing' ? ' vetted-plugin' : ''; + $slug = $plugin['meta']['slug']; + $content = $plugin['content']['rendered']; + $vetted = $plugin['meta']['cpcs_status'] === 'passing' ? '' : ''; + $vetted_article = $plugin['meta']['cpcs_status'] === 'passing' ? ' vetted-plugin' : ''; $markdown_contents = self::get_markdown_contents( $content, '
', '
' ); foreach ( $markdown_contents as $markdown_content ) { $content = str_replace( '
' . $markdown_content . '
', $markdown_content, $content ); } - ?> -
+ ?> +
-

-
%1$s.', 'classicpress-directory-integration'), $plugin['meta']['developer_name']), ['b' => []]); ?>
+

+ +

+
%1$s.', 'classicpress-directory-integration' ), $plugin['meta']['developer_name'] ), array( 'b' => array() ) ); ?>
-
+
-
-
-get_directory_data(true); - $slug = dirname($args->slug); - if (!array_key_exists($slug, $dir_data)) { + $dir_data = $this->get_directory_data( true ); + $slug = dirname( $args->slug ); + if ( ! array_key_exists( $slug, $dir_data ) ) { return $result; } // Query the directory - $endpoint = \CLASSICPRESS_DIRECTORY_INTEGRATION_URL.'plugins?byslug='.$slug; - $response = wp_remote_get($endpoint, ['user-agent' => classicpress_user_agent(true)]); + $endpoint = \CLASSICPRESS_DIRECTORY_INTEGRATION_URL . 'plugins?byslug=' . $slug; + $response = wp_remote_get( $endpoint, array( 'user-agent' => classicpress_user_agent( true ) ) ); - if (is_wp_error($response) || empty($response['response']) || wp_remote_retrieve_response_code($response) !== 200) { + if ( is_wp_error( $response ) || empty( $response['response'] ) || wp_remote_retrieve_response_code( $response ) !== 200 ) { return false; } - $data_from_dir = json_decode(wp_remote_retrieve_body($response), true); - $data = $data_from_dir[0]; + $data_from_dir = json_decode( wp_remote_retrieve_body( $response ), true ); + $data = $data_from_dir[0]; - $result = [ + $result = array( 'active_installs' => (int) $data['meta']['active_installations'], 'author' => $data['meta']['developer_name'], - 'banners' => $this->get_plugin_images('banner', $slug), + 'banners' => $this->get_plugin_images( 'banner', $slug ), 'description' => 'false', - 'icons' => $this->get_plugin_images('icon', $slug), + 'icons' => $this->get_plugin_images( 'icon', $slug ), 'name' => $data['title']['rendered'], 'requires_php' => $data['meta']['requires_php'], - 'screenshots' => $this->get_plugin_images('screenshot', $slug), - 'sections' => [ + 'screenshots' => $this->get_plugin_images( 'screenshot', $slug ), + 'sections' => array( 'description' => $data['content']['rendered'], //'faq' => 'frequently asked questions', //'installation' => 'installation', @@ -61,10 +60,10 @@ public function plugin_information($result, $action, $args) { //'reviews' => 'reviews', //'other_notes' => 'other notes', //'changelog' => 'changelog', - ], + ), 'short_description' => $data['excerpt']['rendered'], 'slug' => null, // null so we don't point to WP.org - 'tags' => explode(',', $data['meta']['category_names']), + 'tags' => explode( ',', $data['meta']['category_names'] ), 'version' => $data['meta']['current_version'], //'added' => true, // date //'author_block_count' => true, // int @@ -77,34 +76,33 @@ public function plugin_information($result, $action, $args) { //'downloaded' => false, // int //'homepage' => true, // url //'last_updated' => true, // datetime - //'num_ratings' => 14, // int how many ratings + //'num_ratings' => 14, // int how many ratings //'rating' => 50, // int rating x 100 - //'ratings' =>[ // unuseful? - // 5 => 10, - // 4 => 4, - // 3 => 0, - // 2 => 0, - // 1 => 0, + //'ratings' =>[ // unuseful? + // 5 => 10, + // 4 => 4, + // 3 => 0, + // 2 => 0, + // 1 => 0, //], // array( [5..0] ) //'requires' => true, // version string //'support_threads_resolved' => true, // int //'support_threads' => true, // int //'tested' => true, // version string //'versions' => true, // array( [version] url ) - ]; + ); return (object) $result; - } - private function get_plugin_images($type, $plugin) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh - $images = []; + private function get_plugin_images( $type, $plugin ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh + $images = array(); - if (empty($plugin)) { + if ( empty( $plugin ) ) { return $images; } - if (!in_array($type, ['icon', 'banner', 'screenshot'], true)) { + if ( ! in_array( $type, array( 'icon', 'banner', 'screenshot' ), true ) ) { return $images; } @@ -114,47 +112,55 @@ private function get_plugin_images($type, $plugin) { // phpcs:ignore Generic.Met * The filtered path is relative to the plugin's directory * * Example: - * add_filter( - * 'cpdi_images_folder_' . basename( __DIR__ ), - * function ( $source ) { - * return '/assets/images'; - * } - * ); + * add_filter( + * 'cpdi_images_folder_' . basename( __DIR__ ), + * function ( $source ) { + * return '/assets/images'; + * } + * ); * * * @param string $source Original folder path. */ - $folder = apply_filters("cpdi_images_folder_{$plugin}", '/images'); - $image_path = untrailingslashit(WP_PLUGIN_DIR).'/'.$plugin.$folder; - $image_url = untrailingslashit(WP_PLUGIN_URL).'/'.$plugin.$folder; - - $image_qualities = [ - 'icon' => ['default', '1x', '2x'], - 'banner' => ['default', 'low', 'high'], - ]; - - $image_dimensions = [ - 'icon' => ['default' => '128', '1x' => '128', '2x' => '256'], - 'banner' => ['default' => '772x250', 'low' => '772x250', 'high' => '1544x500'], - ]; - - if ($type === 'icon' || $type === 'banner') { - if (file_exists($image_path.'/'.$type.'.svg')) { - foreach ($image_qualities[$type] as $key) { - $images[$key] = $image_url.'/'.$type.'.svg'; + $folder = apply_filters( "cpdi_images_folder_{$plugin}", '/images' ); + $image_path = untrailingslashit( WP_PLUGIN_DIR ) . '/' . $plugin . $folder; + $image_url = untrailingslashit( WP_PLUGIN_URL ) . '/' . $plugin . $folder; + + $image_qualities = array( + 'icon' => array( 'default', '1x', '2x' ), + 'banner' => array( 'default', 'low', 'high' ), + ); + + $image_dimensions = array( + 'icon' => array( + 'default' => '128', + '1x' => '128', + '2x' => '256', + ), + 'banner' => array( + 'default' => '772x250', + 'low' => '772x250', + 'high' => '1544x500', + ), + ); + + if ( $type === 'icon' || $type === 'banner' ) { + if ( file_exists( $image_path . '/' . $type . '.svg' ) ) { + foreach ( $image_qualities[ $type ] as $key ) { + $images[ $key ] = $image_url . '/' . $type . '.svg'; } } else { - foreach (['jpg', 'png'] as $ext) { - $all_keys = $image_qualities[$type]; - $last_key = array_pop($all_keys); - $middle_key = array_pop($all_keys); - if (file_exists($image_path.'/'.$type.'-'.$image_dimensions[$type][$middle_key].'.'.$ext)) { - foreach ($image_qualities[$type] as $key) { - $images[$key] = $image_url.'/'.$type.'-'.$image_dimensions[$type][$middle_key].'.'.$ext; + foreach ( array( 'jpg', 'png' ) as $ext ) { + $all_keys = $image_qualities[ $type ]; + $last_key = array_pop( $all_keys ); + $middle_key = array_pop( $all_keys ); + if ( file_exists( $image_path . '/' . $type . '-' . $image_dimensions[ $type ][ $middle_key ] . '.' . $ext ) ) { + foreach ( $image_qualities[ $type ] as $key ) { + $images[ $key ] = $image_url . '/' . $type . '-' . $image_dimensions[ $type ][ $middle_key ] . '.' . $ext; } } - if (file_exists($image_path.'/'.$type.'-'.$image_dimensions[$type][$last_key].'.'.$ext)) { // phpcs:ignore SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed - $images[$last_key] = $image_url.'/'.$type.'-'.$image_dimensions[$type][$last_key].'.'.$ext; + if ( file_exists( $image_path . '/' . $type . '-' . $image_dimensions[ $type ][ $last_key ] . '.' . $ext ) ) { // phpcs:ignore SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed + $images[ $last_key ] = $image_url . '/' . $type . '-' . $image_dimensions[ $type ][ $last_key ] . '.' . $ext; } } } @@ -162,211 +168,204 @@ private function get_plugin_images($type, $plugin) { // phpcs:ignore Generic.Met return $images; } - if ($type === 'screenshot') { + if ( $type === 'screenshot' ) { - if (file_exists($image_path)) { + if ( file_exists( $image_path ) ) { - $dir_contents = scandir($image_path); + $dir_contents = scandir( $image_path ); - foreach ($dir_contents as $name) { - if (strpos(strtolower($name), 'screenshot') === 0) { // phpcs:ignore SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed - $start = strpos($name, '-') + 1; - $for = strpos($name, '.') - $start; - $screenshot_number = substr($name, $start, $for); - $images[$screenshot_number] = $image_url.'/'.$name; + foreach ( $dir_contents as $name ) { + if ( strpos( strtolower( $name ), 'screenshot' ) === 0 ) { // phpcs:ignore SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed + $start = strpos( $name, '-' ) + 1; + $for = strpos( $name, '.' ) - $start; + $screenshot_number = substr( $name, $start, $for ); + $images[ $screenshot_number ] = $image_url . '/' . $name; } } - ksort($images); + ksort( $images ); } - } return $images; - } - public function after_plugin_row($plugin_file, $plugin_data, $status) { + public function after_plugin_row( $plugin_file, $plugin_data, $status ) { - $slug = dirname($plugin_file); - $plugins = $this->get_cp_plugins(); + $slug = dirname( $plugin_file ); + $plugins = $this->get_cp_plugins(); - if (!array_key_exists($slug, $plugins)) { + if ( ! array_key_exists( $slug, $plugins ) ) { return; } $dir_data = $this->get_directory_data(); - if (!array_key_exists($slug, $dir_data)) { + if ( ! array_key_exists( $slug, $dir_data ) ) { return; } - $data = $dir_data[$slug]; - $plugin = $plugins[$slug]; + $data = $dir_data[ $slug ]; + $plugin = $plugins[ $slug ]; - if (version_compare($plugin['Version'], $data['Version']) >= 0) { + if ( version_compare( $plugin['Version'], $data['Version'] ) >= 0 ) { // No updates available return false; } $message = ''; - if (version_compare(classicpress_version(), $data['RequiresCP']) === -1) { + if ( version_compare( classicpress_version(), $data['RequiresCP'] ) === -1 ) { // Higher CP version required // Translators: %1$s is the plugin latest version. %2$s is the ClassicPress version required by the plugin. - $message .= sprintf (esc_html__('This plugin has not updated to version %1$s because it needs ClassicPress %2$s.', 'classicpress-directory-integration'), esc_html($data['Version']), esc_html($data['RequiresCP'])); + $message .= sprintf( esc_html__( 'This plugin has not updated to version %1$s because it needs ClassicPress %2$s.', 'classicpress-directory-integration' ), esc_html( $data['Version'] ), esc_html( $data['RequiresCP'] ) ); } - if (version_compare(phpversion(), $data['RequiresPHP']) === -1) { - if ($message !== '') { + if ( version_compare( phpversion(), $data['RequiresPHP'] ) === -1 ) { + if ( $message !== '' ) { $message .= ' '; } // Translators: %1$s is the plugin latest version. %2$s is the PHP version required by the plugin. - $message .= sprintf (esc_html__('This plugin has not updated to version %1$s because it needs PHP %2$s.', 'classicpress-directory-integration'), esc_html($data['Version']), esc_html($data['RequiresPHP'])); + $message .= sprintf( esc_html__( 'This plugin has not updated to version %1$s because it needs PHP %2$s.', 'classicpress-directory-integration' ), esc_html( $data['Version'] ), esc_html( $data['RequiresPHP'] ) ); } - if ($message === '') { + if ( $message === '' ) { return; } - echo '

'; - echo esc_html($message).'

'; - + echo '

'; + echo esc_html( $message ) . '

'; } // Force a refresh of local ClassicPress directory data public function refresh_cp_directory_data() { - $this->get_directory_data(true); + $this->get_directory_data( true ); } // Get all installed ClassicPress plugin private function get_cp_plugins() { - if ($this->cp_plugins !== false) { + if ( $this->cp_plugins !== false ) { return $this->cp_plugins; } $all_plugins = get_plugins(); - $cp_plugins = []; - foreach ($all_plugins as $slug => $plugin) { - if (!array_key_exists('UpdateURI', $plugin)) { + $cp_plugins = array(); + foreach ( $all_plugins as $slug => $plugin ) { + if ( ! array_key_exists( 'UpdateURI', $plugin ) ) { continue; } - if (strpos($plugin['UpdateURI'], \CLASSICPRESS_DIRECTORY_INTEGRATION_URL) !== 0) { + if ( strpos( $plugin['UpdateURI'], \CLASSICPRESS_DIRECTORY_INTEGRATION_URL ) !== 0 ) { continue; } - $cp_plugins[dirname($slug)] = [ + $cp_plugins[ dirname( $slug ) ] = array( 'WPSlug' => $slug, 'Version' => $plugin['Version'], - 'RequiresPHP' => array_key_exists('RequiresPHP', $plugin) ? $plugin['RequiresPHP'] : null, - 'RequiresCP' => array_key_exists('RequiresCP', $plugin) ? $plugin['RequiresCP'] : null, - 'PluginURI' => array_key_exists('PluginURI', $plugin) ? $plugin['PluginURI'] : null, - ]; + 'RequiresPHP' => array_key_exists( 'RequiresPHP', $plugin ) ? $plugin['RequiresPHP'] : null, + 'RequiresCP' => array_key_exists( 'RequiresCP', $plugin ) ? $plugin['RequiresCP'] : null, + 'PluginURI' => array_key_exists( 'PluginURI', $plugin ) ? $plugin['PluginURI'] : null, + ); } $this->cp_plugins = $cp_plugins; return $this->cp_plugins; - } // Get data from the directory for all installed ClassicPress plugin - private function get_directory_data($force = false) { + private function get_directory_data( $force = false ) { // Try to get stored data - if (!$force && $this->cp_plugins_directory_data !== false) { + if ( ! $force && $this->cp_plugins_directory_data !== false ) { // We have it in memory return $this->cp_plugins_directory_data; } - $this->cp_plugins_directory_data = get_transient('cpdi_directory_data_plugins'); - if (!$force && $this->cp_plugins_directory_data !== false) { + $this->cp_plugins_directory_data = get_transient( 'cpdi_directory_data_plugins' ); + if ( ! $force && $this->cp_plugins_directory_data !== false ) { // We have it in transient return $this->cp_plugins_directory_data; } // Query the directory $plugins = $this->get_cp_plugins(); - $endpoint = \CLASSICPRESS_DIRECTORY_INTEGRATION_URL.'plugins?byslug='.implode(',', array_keys($plugins)).'&_fields=meta'; - $response = wp_remote_get($endpoint, ['user-agent' => classicpress_user_agent(true)]); + $endpoint = \CLASSICPRESS_DIRECTORY_INTEGRATION_URL . 'plugins?byslug=' . implode( ',', array_keys( $plugins ) ) . '&_fields=meta'; + $response = wp_remote_get( $endpoint, array( 'user-agent' => classicpress_user_agent( true ) ) ); - if (is_wp_error($response) || empty($response['response']) || wp_remote_retrieve_response_code($response) !== 200) { - return []; + if ( is_wp_error( $response ) || empty( $response['response'] ) || wp_remote_retrieve_response_code( $response ) !== 200 ) { + return array(); } - $data_from_dir = json_decode(wp_remote_retrieve_body($response), true); - $data = []; + $data_from_dir = json_decode( wp_remote_retrieve_body( $response ), true ); + $data = array(); - foreach ($data_from_dir as $single_data) { - $data[$single_data['meta']['slug']] = [ + foreach ( $data_from_dir as $single_data ) { + $data[ $single_data['meta']['slug'] ] = array( 'Download' => $single_data['meta']['download_link'], 'Version' => $single_data['meta']['current_version'], 'RequiresPHP' => $single_data['meta']['requires_php'], 'RequiresCP' => $single_data['meta']['requires_cp'], 'active_installs' => $single_data['meta']['active_installations'], - ]; + ); } $this->cp_plugins_directory_data = $data; - set_transient('cpdi_directory_data_plugins', $this->cp_plugins_directory_data, 3 * HOUR_IN_SECONDS); + set_transient( 'cpdi_directory_data_plugins', $this->cp_plugins_directory_data, 3 * HOUR_IN_SECONDS ); return $this->cp_plugins_directory_data; - } // Filter to trigger updates using Update URI header - public function update_uri_filter($update, $plugin_data, $plugin_file, $locales) { + public function update_uri_filter( $update, $plugin_data, $plugin_file, $locales ) { // https://developer.wordpress.org/reference/hooks/update_plugins_hostname/ // Get the slug from Update URI - if (preg_match('/plugins\?byslug=(.*)/', $plugin_data['UpdateURI'], $matches) !== 1) { + if ( preg_match( '/plugins\?byslug=(.*)/', $plugin_data['UpdateURI'], $matches ) !== 1 ) { return false; } // Check if the slug matches plugin file - if (!isset($matches[1]) || dirname($plugin_file) !== $matches[1]) { + if ( ! isset( $matches[1] ) || dirname( $plugin_file ) !== $matches[1] ) { return false; } $slug = $matches[1]; // Check if we have that plugin in installed ones - $plugins = $this->get_cp_plugins(); - if (!array_key_exists($slug, $plugins)) { + $plugins = $this->get_cp_plugins(); + if ( ! array_key_exists( $slug, $plugins ) ) { return false; } // Check if we have that plugin in directory ones $dir_data = $this->get_directory_data(); - if (!array_key_exists($slug, $dir_data)) { + if ( ! array_key_exists( $slug, $dir_data ) ) { return false; } - $plugin = $plugins[$slug]; - $data = $dir_data[$slug]; + $plugin = $plugins[ $slug ]; + $data = $dir_data[ $slug ]; - if (version_compare($plugin['Version'], $data['Version']) >= 0) { + if ( version_compare( $plugin['Version'], $data['Version'] ) >= 0 ) { // No updates available return false; } - if (version_compare(classicpress_version(), $data['RequiresCP']) === -1) { + if ( version_compare( classicpress_version(), $data['RequiresCP'] ) === -1 ) { // Higher CP version required return false; } - if (version_compare(phpversion(), $data['RequiresPHP']) === -1) { + if ( version_compare( phpversion(), $data['RequiresPHP'] ) === -1 ) { // Higher PHP version required return false; } - $update = [ + $update = array( 'slug' => $plugin_file, 'version' => $data['Version'], 'package' => $data['Download'], 'requires_php' => $data['RequiresPHP'], 'requires_cp' => $data['RequiresCP'], - 'banners' => $this->get_plugin_images('banner', $slug), - 'icons' => $this->get_plugin_images('icon', $slug), + 'banners' => $this->get_plugin_images( 'banner', $slug ), + 'icons' => $this->get_plugin_images( 'icon', $slug ), - ]; + ); return $update; - } - } diff --git a/classes/class-theme-install.php b/classes/class-theme-install.php index b1a93d1..9c186a8 100644 --- a/classes/class-theme-install.php +++ b/classes/class-theme-install.php @@ -4,8 +4,8 @@ require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; -class ThemeInstall -{ +class ThemeInstall { + use Helpers; @@ -13,63 +13,59 @@ class ThemeInstall private $page = null; - public function __construct() - { + public function __construct() { // Add Menu Items. - if (is_multisite()) { - add_action('network_admin_menu', [$this, 'create_menu'], 100); - add_action('network_admin_menu', [$this, 'rename_menu']); + if ( is_multisite() ) { + add_action( 'network_admin_menu', array( $this, 'create_menu' ), 100 ); + add_action( 'network_admin_menu', array( $this, 'rename_menu' ) ); } else { - add_action('admin_menu', [$this, 'create_menu'], 100); + add_action( 'admin_menu', array( $this, 'create_menu' ), 100 ); } - add_action('admin_enqueue_scripts', [$this, 'styles']); - add_action('admin_enqueue_scripts', [$this, 'scripts']); + add_action( 'admin_enqueue_scripts', array( $this, 'styles' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) ); } - public function styles($hook) - { - if ($hook !== $this->page) { + public function styles( $hook ) { + if ( $hook !== $this->page ) { return; } - wp_enqueue_style( 'classicpress-directory-integration-css', plugins_url( '../styles/directory-integration.css', __FILE__ ), [] ); + wp_enqueue_style( 'classicpress-directory-integration-css', plugins_url( '../styles/directory-integration.css', __FILE__ ), array() ); } - public function scripts($hook) - { - if ($hook !== $this->page) { + public function scripts( $hook ) { + if ( $hook !== $this->page ) { return; } wp_enqueue_script( 'classicpress-directory-integration-js', plugins_url( '../scripts/directory-integration.js', __FILE__ ), array( 'wp-i18n' ), false, true ); wp_set_script_translations( 'classicpress-directory-integration-js', 'classicpress-directory-integration', plugin_dir_path( 'classicpress-directory-integration' ) . 'languages' ); } - public function create_menu() - { - if (!current_user_can('install_plugins')) { + public function create_menu() { + if ( ! current_user_can( 'install_plugins' ) ) { return; } $this->page = add_submenu_page( 'themes.php', - esc_html__('ClassicPress Themes', 'classicpress-directory-integration'), - esc_html__('Install CP Themes', 'classicpress-directory-integration'), + esc_html__( 'ClassicPress Themes', 'classicpress-directory-integration' ), + esc_html__( 'Install CP Themes', 'classicpress-directory-integration' ), 'install_themes', 'classicpress-directory-integration-theme-install', - [$this, 'render_menu'], + array( $this, 'render_menu' ), 2 ); - add_action('load-' . $this->page, [$this, 'activate_action']); - add_action('load-' . $this->page, [$this, 'install_action']); + add_action( 'load-' . $this->page, array( $this, 'activate_action' ) ); + add_action( 'load-' . $this->page, array( $this, 'install_action' ) ); } public function rename_menu() { global $submenu; foreach ( $submenu['themes.php'] as $key => $value ) { - if($value[2] !== 'theme-install.php') { + if ( $value[2] !== 'theme-install.php' ) { continue; } - $submenu['themes.php'][$key][0] = esc_html__('Install WP Themes', 'classicpress-directory-integration'); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + $submenu['themes.php'][ $key ][0] = esc_html__( 'Install WP Themes', 'classicpress-directory-integration' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited } } @@ -77,110 +73,106 @@ public function rename_menu() { // This function is different from the one in ThemeUpdate class // and considers a theme from the dir not only if it has UpdateURI // but also if it have RequiresCP. - private function get_local_cp_themes() - { + private function get_local_cp_themes() { - if ($this->local_cp_themes !== false) { + if ( $this->local_cp_themes !== false ) { return $this->local_cp_themes; } $all_themes = wp_get_themes(); - $cp_themes = []; - foreach($all_themes as $slug => $inner){ - $cp_themes[($slug)] = [ - 'WPSlug' => $slug, - 'Name' => $inner->get( 'Name' ), - 'Version' => $inner->get( 'Version' ), - 'ThemeURI' => $inner->get( 'ThemeURI' ), - 'Active' => get_template(), - ]; + $cp_themes = array(); + foreach ( $all_themes as $slug => $inner ) { + $cp_themes[ ( $slug ) ] = array( + 'WPSlug' => $slug, + 'Name' => $inner->get( 'Name' ), + 'Version' => $inner->get( 'Version' ), + 'ThemeURI' => $inner->get( 'ThemeURI' ), + 'Active' => get_template(), + ); } $this->local_cp_themes = $cp_themes; return $this->local_cp_themes; - } // Validate and sanitize args for quering the ClassicPress Directory - public static function sanitize_args($args) - { - foreach ($args as $key => $value) { + public static function sanitize_args( $args ) { + foreach ( $args as $key => $value ) { $sanitized = false; - switch ($key) { + switch ( $key ) { case 'per_page': case 'page': - $args[$key] = (int) $value; - $sanitized = true; + $args[ $key ] = (int) $value; + $sanitized = true; break; case 'byslug': - $args[$key] = preg_replace('[^A-Za-z0-9\-_]', '', $value); - $sanitized = true; + $args[ $key ] = preg_replace( '[^A-Za-z0-9\-_]', '', $value ); + $sanitized = true; break; case 'search': - $args[$key] = sanitize_text_field($value); - $sanitized = true; + $args[ $key ] = sanitize_text_field( $value ); + $sanitized = true; break; case '_fields': - $args[$key] = preg_replace('[^A-Za-z0-9\-_,]', '', $value); - $sanitized = true; + $args[ $key ] = preg_replace( '[^A-Za-z0-9\-_,]', '', $value ); + $sanitized = true; break; } - if ($sanitized) { + if ( $sanitized ) { continue; } - unset($args[$key]); + unset( $args[ $key ] ); } return $args; } // Query the ClassicPress Directory - public static function do_directory_request($args = [], $type = 'themes') - { + public static function do_directory_request( $args = array(), $type = 'themes' ) { $result['success'] = false; - if (!in_array($type, ['themes', 'themes'])) { + if ( ! in_array( $type, array( 'themes', 'themes' ) ) ) { $result['error'] = $type . ' is not a supported type'; return $result; } - $args = self::sanitize_args($args); + $args = self::sanitize_args( $args ); $endpoint = \CLASSICPRESS_DIRECTORY_INTEGRATION_URL . $type; - $endpoint = add_query_arg($args, $endpoint); + $endpoint = add_query_arg( $args, $endpoint ); - $response = wp_remote_get($endpoint, ['user-agent' => classicpress_user_agent()]); + $response = wp_remote_get( $endpoint, array( 'user-agent' => classicpress_user_agent() ) ); - if (is_wp_error($response)) { - $result['error'] = rtrim(implode(',', $response->get_error_messages()), '.'); + if ( is_wp_error( $response ) ) { + $result['error'] = rtrim( implode( ',', $response->get_error_messages() ), '.' ); return $result; } - $e = wp_remote_retrieve_response_code($response); - if ($e !== 200) { - $result['error'] = $response['response']['message'].'.'; + $e = wp_remote_retrieve_response_code( $response ); + if ( $e !== 200 ) { + $result['error'] = $response['response']['message'] . '.'; $result['code'] = $response['response']['code']; - if (!isset($response['body']) || !json_validate($response['body'])) { + if ( ! isset( $response['body'] ) || ! json_validate( $response['body'] ) ) { return $result; } - $api_message = json_decode($response['body'], true); - if(!isset($api_message['message'])) { + $api_message = json_decode( $response['body'], true ); + if ( ! isset( $api_message['message'] ) ) { return $result; } - $result['error'] .= ' '.$api_message['message']; + $result['error'] .= ' ' . $api_message['message']; return $result; } - if (!isset($response['headers'])) { + if ( ! isset( $response['headers'] ) ) { $result['error'] = 'No headers found'; return $result; } $headers = $response['headers']->getAll(); - if (!isset($headers['x-wp-total']) || !isset($headers['x-wp-totalpages'])) { + if ( ! isset( $headers['x-wp-total'] ) || ! isset( $headers['x-wp-totalpages'] ) ) { $result['error'] = 'No pagination headers found'; return $result; } - $data_from_dir = json_decode(wp_remote_retrieve_body($response), true); - if ($data_from_dir === null) { + $data_from_dir = json_decode( wp_remote_retrieve_body( $response ), true ); + if ( $data_from_dir === null ) { $result['error'] = 'Failed decoding response'; return $result; } @@ -194,201 +186,197 @@ public static function do_directory_request($args = [], $type = 'themes') } // Enqueue a notice - private function add_notice($message, $failure = false) - { - $other_notices = get_transient('cpdi_ti_notices'); - $notice = $other_notices === false ? '' : $other_notices; + private function add_notice( $message, $failure = false ) { + $other_notices = get_transient( 'cpdi_ti_notices' ); + $notice = $other_notices === false ? '' : $other_notices; $failure_style = $failure ? 'notice-error' : 'notice-success'; - $notice .= '
'; - $notice .= '

' . esc_html($message) . '

'; - $notice .= '
'; - set_transient('cpdi_ti_notices', $notice, \HOUR_IN_SECONDS); + $notice .= '
'; + $notice .= '

' . esc_html( $message ) . '

'; + $notice .= '
'; + set_transient( 'cpdi_ti_notices', $notice, \HOUR_IN_SECONDS ); } // Display notices - private function display_notices() - { - $notices = get_transient('cpdi_ti_notices'); - if ($notices === false) { + private function display_notices() { + $notices = get_transient( 'cpdi_ti_notices' ); + if ( $notices === false ) { return; } // This contains html formatted from 'add_notice' function that uses 'esc_html'. echo $notices; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - delete_transient('cpdi_ti_notices'); + delete_transient( 'cpdi_ti_notices' ); } // Deal with activation requests - public function activate_action() - { + public function activate_action() { // Load local themes information $local_cp_themes = $this->get_local_cp_themes(); // Security checks - if (!isset($_GET['action'])) { + if ( ! isset( $_GET['action'] ) ) { return; } - if ($_GET['action'] !== 'activate') { + if ( $_GET['action'] !== 'activate' ) { return; } - if (!check_admin_referer('activate', '_cpdi')) { + if ( ! check_admin_referer( 'activate', '_cpdi' ) ) { return; } - if (!current_user_can('install_themes')) { + if ( ! current_user_can( 'install_themes' ) ) { return; } - if (!isset($_REQUEST['slug'])) { + if ( ! isset( $_REQUEST['slug'] ) ) { return; } // Check if theme slug is proper - $slug = sanitize_key(wp_unslash($_REQUEST['slug'])); + $slug = sanitize_key( wp_unslash( $_REQUEST['slug'] ) ); - if (!array_key_exists($slug, $local_cp_themes)) { + if ( ! array_key_exists( $slug, $local_cp_themes ) ) { return; } // Activate Theme - $result = switch_theme($local_cp_themes[$slug]['WPSlug']); + $result = switch_theme( $local_cp_themes[ $slug ]['WPSlug'] ); - if ($result !== null) { + if ( $result !== null ) { // Translators: %1$s is the theme name. - $message = sprintf(esc_html__('Error activating %1$s.', 'classicpress-directory-integration'), $local_cp_themes[$slug]['Name']); - $this->add_notice($message, true); + $message = sprintf( esc_html__( 'Error activating %1$s.', 'classicpress-directory-integration' ), $local_cp_themes[ $slug ]['Name'] ); + $this->add_notice( $message, true ); } else { // Translators: %1$s is the theme name. - $message = sprintf(esc_html__('%1$s activated.', 'classicpress-directory-integration'), $local_cp_themes[$slug]['Name']); - $this->add_notice($message, false); + $message = sprintf( esc_html__( '%1$s activated.', 'classicpress-directory-integration' ), $local_cp_themes[ $slug ]['Name'] ); + $this->add_notice( $message, false ); } - $sendback = remove_query_arg(['action', 'slug', '_cpdi'], wp_get_referer()); - wp_safe_redirect($sendback); + $sendback = remove_query_arg( array( 'action', 'slug', '_cpdi' ), wp_get_referer() ); + wp_safe_redirect( $sendback ); exit; } // Deal with installation requests - public function install_action() - { + public function install_action() { // Security checks - if (!isset($_GET['action'])) { + if ( ! isset( $_GET['action'] ) ) { return; } - if ($_GET['action'] !== 'install') { + if ( $_GET['action'] !== 'install' ) { return; } - if (!check_admin_referer('install', '_cpdi')) { + if ( ! check_admin_referer( 'install', '_cpdi' ) ) { return; } - if (!current_user_can('install_themes')) { + if ( ! current_user_can( 'install_themes' ) ) { return; } - if (!isset($_REQUEST['slug'])) { + if ( ! isset( $_REQUEST['slug'] ) ) { return; } // Check if theme slug is proper - $slug = sanitize_key(wp_unslash($_REQUEST['slug'])); + $slug = sanitize_key( wp_unslash( $_REQUEST['slug'] ) ); // Get github release file - $args = [ + $args = array( 'byslug' => $slug, '_fields' => 'meta,title', - ]; - $response = $this->do_directory_request($args, 'themes'); + ); + $response = $this->do_directory_request( $args, 'themes' ); - if (!$response['success'] || !isset($response['response'][0]['meta']['download_link'])) { + if ( ! $response['success'] || ! isset( $response['response'][0]['meta']['download_link'] ) ) { // Translators: %1$s is the theme name. - $message = sprintf(esc_html__('API error for theme %1$s.', 'classicpress-directory-integration'), $local_cp_themes[$slug]['Name']); - $this->add_notice($message, true); - $sendback = remove_query_arg(['action', 'slug', '_cpdi'], wp_get_referer()); - wp_safe_redirect($sendback); + $message = sprintf( esc_html__( 'API error for theme %1$s.', 'classicpress-directory-integration' ), $local_cp_themes[ $slug ]['Name'] ); + $this->add_notice( $message, true ); + $sendback = remove_query_arg( array( 'action', 'slug', '_cpdi' ), wp_get_referer() ); + wp_safe_redirect( $sendback ); exit; } $installation_url = $response['response'][0]['meta']['download_link']; - $theme_name = $response['response'][0]['title']['rendered']; + $theme_name = $response['response'][0]['title']['rendered']; // Install Theme - $skin = new ThemeInstallSkin(['type' => 'theme']); - $upgrader = new \Theme_Upgrader($skin); - $response = $upgrader->install($installation_url); + $skin = new ThemeInstallSkin( array( 'type' => 'theme' ) ); + $upgrader = new \Theme_Upgrader( $skin ); + $response = $upgrader->install( $installation_url ); - if ($response !== true) { + if ( $response !== true ) { // Translators: %1$s is the theme name. - $message = sprintf(esc_html__('Error installing %1$s.', 'classicpress-directory-integration'), $theme_name); - $this->add_notice($message, true); + $message = sprintf( esc_html__( 'Error installing %1$s.', 'classicpress-directory-integration' ), $theme_name ); + $this->add_notice( $message, true ); } else { // Translators: %1$s is the theme name. - $message = sprintf(esc_html__('%1$s installed.', 'classicpress-directory-integration'), $theme_name); - $this->add_notice($message, false); + $message = sprintf( esc_html__( '%1$s installed.', 'classicpress-directory-integration' ), $theme_name ); + $this->add_notice( $message, false ); } - $sendback = remove_query_arg(['action', 'slug', '_cpdi'], wp_get_referer()); - wp_safe_redirect($sendback); + $sendback = remove_query_arg( array( 'action', 'slug', '_cpdi' ), wp_get_referer() ); + wp_safe_redirect( $sendback ); exit; } // Render "CP Themes" menu - public function render_menu() - { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh + public function render_menu() { + // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh // Load local themes information $local_cp_themes = $this->get_local_cp_themes(); // Set age number if empty // We check nonces only on activations and installations. // In this function nothing is modified. - $page = isset($_REQUEST['getpage']) ? (int) $_REQUEST['getpage'] : 1; //phpcs:ignore WordPress.Security.NonceVerification.Recommended + $page = isset( $_REQUEST['getpage'] ) ? (int) $_REQUEST['getpage'] : 1; //phpcs:ignore WordPress.Security.NonceVerification.Recommended // Query the directory - $args = [ + $args = array( 'per_page' => 12, 'page' => $page, - ]; + ); - if (isset($_REQUEST['searchfor'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended - $args['search'] = sanitize_text_field(wp_unslash($_REQUEST['searchfor'])); //phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( isset( $_REQUEST['searchfor'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended + $args['search'] = sanitize_text_field( wp_unslash( $_REQUEST['searchfor'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended } // Reset paginations for new searches $searching = $args['search'] ?? ''; - if (isset($_REQUEST['searchingfor']) && $_REQUEST['searchingfor'] !== $searching) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( isset( $_REQUEST['searchingfor'] ) && $_REQUEST['searchingfor'] !== $searching ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended $args['page'] = 1; } - $result = $this->do_directory_request($args); - if ($result['success'] === false) { + $result = $this->do_directory_request( $args ); + if ( $result['success'] === false ) { // Query failed, display errors and exit. - $this->add_notice(esc_html($result['error']).' ('.esc_html($result['code']).').', true); + $this->add_notice( esc_html( $result['error'] ) . ' (' . esc_html( $result['code'] ) . ').', true ); } // Set up variables - $themes = $result['response'] ?? []; - $pages = $result['total-pages'] ?? 0; + $themes = $result['response'] ?? array(); + $pages = $result['total-pages'] ?? 0; - if ($themes === []) { - $this->add_notice(esc_html__('No themes found.', 'classicpress-directory-integration'), true); + if ( $themes === array() ) { + $this->add_notice( esc_html__( 'No themes found.', 'classicpress-directory-integration' ), true ); } // Display notices $this->display_notices(); -?> + ?>
-

-

+

+

- + @@ -399,54 +387,81 @@ public function render_menu()
' : ''; - $vetted_article = $theme['meta']['cpcs_status'] === 'passing' ? ' vetted-theme' : ''; + foreach ( $themes as $theme ) { + $slug = $theme['meta']['slug']; + $content = $theme['content']['rendered']; + $vetted = $theme['meta']['cpcs_status'] === 'passing' ? '' : ''; + $vetted_article = $theme['meta']['cpcs_status'] === 'passing' ? ' vetted-theme' : ''; $markdown_contents = self::get_markdown_contents( $content, '
', '
' ); foreach ( $markdown_contents as $markdown_content ) { $content = str_replace( '
' . $markdown_content . '
', $markdown_content, $content ); } - ?> -
+ ?> +
-

-
%1$s.', 'classicpress-directory-integration'), $theme['meta']['developer_name']), ['b' => []]); ?>
+

+ +

+
%1$s.', 'classicpress-directory-integration' ), $theme['meta']['developer_name'] ), array( 'b' => array() ) ); ?>
-
+
-
+
- + 'install', 'slug' => $slug]), 'install', '_cpdi')) . '" class="button install-now">' . esc_html__('Install', 'classicpress-directory-integration') . ''; + if ( ! array_key_exists( $slug, $local_cp_themes ) ) { + echo '' . esc_html__( 'Install', 'classicpress-directory-integration' ) . ''; } - if ( array_key_exists($slug, $local_cp_themes) && ($local_cp_themes[$slug]['Active'] == $slug ) ) { - echo '' . esc_html__('Active', 'classicpress-directory-integration') . ''; + if ( array_key_exists( $slug, $local_cp_themes ) && ( $local_cp_themes[ $slug ]['Active'] == $slug ) ) { + echo '' . esc_html__( 'Active', 'classicpress-directory-integration' ) . ''; } - if ( array_key_exists($slug, $local_cp_themes) && ($local_cp_themes[$slug]['Active'] != $slug ) ) { - echo '' . esc_html__('Activate', 'classicpress-directory-integration') . ''; + if ( array_key_exists( $slug, $local_cp_themes ) && ( $local_cp_themes[ $slug ]['Active'] != $slug ) ) { + echo '' . esc_html__( 'Activate', 'classicpress-directory-integration' ) . ''; } ?>
-
-
-cp_themes !== false) { + if ( $this->cp_themes !== false ) { return $this->cp_themes; } $all_themes = wp_get_themes(); - $cp_themes = []; - foreach ($all_themes as $slug => $theme) { - if ($theme->display('UpdateURI') === '') { + $cp_themes = array(); + foreach ( $all_themes as $slug => $theme ) { + if ( $theme->display( 'UpdateURI' ) === '' ) { continue; } - if (strpos($theme->display('UpdateURI'), \CLASSICPRESS_DIRECTORY_INTEGRATION_URL) !== 0) { + if ( strpos( $theme->display( 'UpdateURI' ), \CLASSICPRESS_DIRECTORY_INTEGRATION_URL ) !== 0 ) { continue; } - $cp_themes[$slug] = [ + $cp_themes[ $slug ] = array( 'WPSlug' => $slug, - 'Version' => $theme->display('UpdateURI'), - 'RequiresPHP' => $theme->display('RequiresPHP'), - 'RequiresCP' => $theme->display('RequiresCP'), - 'PluginURI' => $theme->display('PluginURI'), - ]; + 'Version' => $theme->display( 'UpdateURI' ), + 'RequiresPHP' => $theme->display( 'RequiresPHP' ), + 'RequiresCP' => $theme->display( 'RequiresCP' ), + 'PluginURI' => $theme->display( 'PluginURI' ), + ); } $this->cp_themes = $cp_themes; return $this->cp_themes; - } // Get data from the directory for all installed ClassicPress themes - private function get_directory_data($force = false) { + private function get_directory_data( $force = false ) { // Try to get stored data - if (!$force && $this->cp_themes_directory_data !== false) { + if ( ! $force && $this->cp_themes_directory_data !== false ) { // We have it in memory return $this->cp_themes_directory_data; } - $this->cp_themes_directory_data = get_transient('cpdi_directory_data_themes'); - if (!$force && $this->cp_themes_directory_data !== false) { + $this->cp_themes_directory_data = get_transient( 'cpdi_directory_data_themes' ); + if ( ! $force && $this->cp_themes_directory_data !== false ) { // We have it in transient return $this->cp_themes_directory_data; } // Query the directory $themes = $this->get_cp_themes(); - $endpoint = \CLASSICPRESS_DIRECTORY_INTEGRATION_URL.'themes?byslug='.implode(',', array_keys($themes)).'&_fields=meta'; - $response = wp_remote_get($endpoint, ['user-agent' => classicpress_user_agent(true)]); + $endpoint = \CLASSICPRESS_DIRECTORY_INTEGRATION_URL . 'themes?byslug=' . implode( ',', array_keys( $themes ) ) . '&_fields=meta'; + $response = wp_remote_get( $endpoint, array( 'user-agent' => classicpress_user_agent( true ) ) ); - if (is_wp_error($response) || empty($response['response']) || wp_remote_retrieve_response_code($response) !== 200) { - return []; + if ( is_wp_error( $response ) || empty( $response['response'] ) || wp_remote_retrieve_response_code( $response ) !== 200 ) { + return array(); } - $data_from_dir = json_decode(wp_remote_retrieve_body($response), true); - $data = []; + $data_from_dir = json_decode( wp_remote_retrieve_body( $response ), true ); + $data = array(); - foreach ($data_from_dir as $single_data) { - $data[$single_data['meta']['slug']] = [ + foreach ( $data_from_dir as $single_data ) { + $data[ $single_data['meta']['slug'] ] = array( 'Download' => $single_data['meta']['download_link'], 'Version' => $single_data['meta']['current_version'], 'RequiresPHP' => $single_data['meta']['requires_php'], 'RequiresCP' => $single_data['meta']['requires_cp'], 'active_installs' => $single_data['meta']['active_installations'], - ]; + ); } $this->cp_themes_directory_data = $data; - set_transient('cpdi_directory_data_themes', $this->cp_themes_directory_data, 3 * HOUR_IN_SECONDS); + set_transient( 'cpdi_directory_data_themes', $this->cp_themes_directory_data, 3 * HOUR_IN_SECONDS ); return $this->cp_themes_directory_data; - } // Filter to trigger updates using Update URI header - public function update_uri_filter($update, $theme_data, $theme_stylesheet, $locales) { + public function update_uri_filter( $update, $theme_data, $theme_stylesheet, $locales ) { // https://developer.wordpress.org/reference/hooks/update_themes_hostname/ // Get the slug from Update URI - if (preg_match('/themes\?byslug=(.*)/', $theme_data['UpdateURI'], $matches) !== 1) { + if ( preg_match( '/themes\?byslug=(.*)/', $theme_data['UpdateURI'], $matches ) !== 1 ) { return false; } // Check if the slug matches theme dir - if (!isset($matches[1]) || $theme_stylesheet !== $matches[1]) { + if ( ! isset( $matches[1] ) || $theme_stylesheet !== $matches[1] ) { return false; } $slug = $matches[1]; // Check if we have that theme in installed ones - $themes = $this->get_cp_themes(); + $themes = $this->get_cp_themes(); - if (!array_key_exists($slug, $themes)) { + if ( ! array_key_exists( $slug, $themes ) ) { return false; } // Check if we have that theme in directory ones $dir_data = $this->get_directory_data(); - if (!array_key_exists($slug, $dir_data)) { + if ( ! array_key_exists( $slug, $dir_data ) ) { return false; } - $theme = $themes[$slug]; - $data = $dir_data[$slug]; + $theme = $themes[ $slug ]; + $data = $dir_data[ $slug ]; - if (version_compare($theme['Version'], $data['Version']) >= 0) { + if ( version_compare( $theme['Version'], $data['Version'] ) >= 0 ) { // No updates available return false; } - if (version_compare(classicpress_version(), $theme['RequiresCP']) === -1) { + if ( version_compare( classicpress_version(), $theme['RequiresCP'] ) === -1 ) { // Higher CP version required return false; } - if (version_compare(phpversion(), $theme['RequiresPHP']) === -1) { + if ( version_compare( phpversion(), $theme['RequiresPHP'] ) === -1 ) { // Higher PHP version required return false; } - $update = [ + $update = array( 'slug' => $theme_stylesheet, 'version' => $data['Version'], 'package' => $data['Download'], 'requires_php' => $data['RequiresPHP'], 'requires_cp' => $data['RequiresCP'], - 'url' => 'https://'.wp_parse_url(\CLASSICPRESS_DIRECTORY_INTEGRATION_URL, PHP_URL_HOST).'/themes/'.$theme_stylesheet, - ]; + 'url' => 'https://' . wp_parse_url( \CLASSICPRESS_DIRECTORY_INTEGRATION_URL, PHP_URL_HOST ) . '/themes/' . $theme_stylesheet, + ); return $update; - } - } diff --git a/classes/class-wpcli.php b/classes/class-wpcli.php index 6288a65..a3daa35 100644 --- a/classes/class-wpcli.php +++ b/classes/class-wpcli.php @@ -2,8 +2,8 @@ namespace ClassicPress\Directory; -if (!defined('ABSPATH')) { - die('-1'); +if ( ! defined( 'ABSPATH' ) ) { + die( '-1' ); } /** @@ -17,7 +17,7 @@ * @when after_wp_load */ -class CPDICLI{ +class CPDICLI { /** * Flush ClassicPress Directory Integration data. @@ -29,30 +29,30 @@ class CPDICLI{ * * @when after_wp_load */ - public function flush($args, $assoc_args) { - $transients = [ + public function flush( $args, $assoc_args ) { + $transients = array( 'cpdi_pi_notices', 'cpdi_ti_notices', 'cpdi_directory_data_plugins', 'cpdi_directory_data_themes', - ]; + ); $count = 0; - foreach ($transients as $transient) { - if (delete_transient($transient)) { + foreach ( $transients as $transient ) { + if ( delete_transient( $transient ) ) { continue; } - \WP_CLI::warning("Transient '$transient' not found."); - $count++; + \WP_CLI::warning( "Transient '$transient' not found." ); + ++$count; } - if ($count === count($transients)) { - \WP_CLI::error('No transients deleted.'); + if ( $count === count( $transients ) ) { + \WP_CLI::error( 'No transients deleted.' ); } - $howmany = $count === 0 ? 'all' : count($transients) - $count; + $howmany = $count === 0 ? 'all' : count( $transients ) - $count; - \WP_CLI::success("Deleted $howmany transients."); + \WP_CLI::success( "Deleted $howmany transients." ); } } diff --git a/classes/index.php b/classes/index.php index 6fd199e..b3d9bbc 100755 --- a/classes/index.php +++ b/classes/index.php @@ -1 +1 @@ -

%2$s

', esc_attr($class), esc_html($message)); -} - -const DB_VERSION = 1; - -// Load non namespaced constants and functions -require_once 'includes/constants.php'; -require_once 'includes/functions.php'; - -// Load Helpers trait. -require_once 'classes/Helpers.trait.php'; - -// Load Plugin Update functionality class. -require_once 'classes/PluginUpdate.class.php'; -$plugin_update = new PluginUpdate(); - -// Load Plugin Install functionality class. -require_once 'classes/PluginInstall.class.php'; -$plugin_install = new PluginInstall(); - -// Load Theme Update functionality class. -require_once 'classes/ThemeUpdate.class.php'; -$theme_update = new ThemeUpdate(); - -// Load Theme Install functionality class. -require_once 'classes/ThemeInstall.class.php'; -$theme_install = new ThemeInstall(); - -// Register text domain -function register_text_domain() { - load_plugin_textdomain('classicpress-directory-integration', false, dirname(plugin_basename(__FILE__)).'/languages'); -} -add_action('plugins_loaded', '\ClassicPress\Directory\register_text_domain'); - -// Add commands to WP-CLI -require_once 'classes/WPCLI.class.php'; -if (defined('WP_CLI') && WP_CLI) { - \WP_CLI::add_command('cpdi', '\ClassicPress\Directory\CPDICLI'); -} +

%2$s

', esc_attr( $class ), esc_html( $message ) ); +} + +const DB_VERSION = 1; + +// Load non namespaced constants and functions +require_once 'includes/constants.php'; +require_once 'includes/functions.php'; + +// Load Helpers trait. +require_once 'classes/trait-helpers.php'; + +// Load Plugin Update functionality class. +require_once 'classes/class-plugin-update.php'; +$plugin_update = new PluginUpdate(); + +// Load Plugin Install functionality class. +require_once 'classes/class-plugin-install.php'; +$plugin_install = new PluginInstall(); + +// Load Theme Update functionality class. +require_once 'classes/class-theme-update.php'; +$theme_update = new ThemeUpdate(); + +// Load Theme Install functionality class. +require_once 'classes/class-theme-install.php'; +$theme_install = new ThemeInstall(); + +// Register text domain +function register_text_domain() { + load_plugin_textdomain( 'classicpress-directory-integration', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); +} +add_action( 'plugins_loaded', '\ClassicPress\Directory\register_text_domain' ); + +// Add commands to WP-CLI +require_once 'classes/class-wpcli.php'; +if ( defined( 'WP_CLI' ) && WP_CLI ) { + \WP_CLI::add_command( 'cpdi', '\ClassicPress\Directory\CPDICLI' ); +} diff --git a/images/index.php b/images/index.php index 6fd199e..b3d9bbc 100755 --- a/images/index.php +++ b/images/index.php @@ -1 +1 @@ - Date: Thu, 24 Apr 2025 11:57:51 +0200 Subject: [PATCH 03/15] Fix phpcs --- classes/class-plugin-install.php | 6 +----- classes/class-theme-install.php | 6 +----- classes/trait-helpers.php | 2 +- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/classes/class-plugin-install.php b/classes/class-plugin-install.php index b5967d0..3c152e3 100644 --- a/classes/class-plugin-install.php +++ b/classes/class-plugin-install.php @@ -479,18 +479,14 @@ public function render_menu() { } // End of render_menu() } +// phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound class PluginInstallSkin extends \Plugin_Installer_Skin { - - public function header() { } - public function footer() { } - public function error( $errors ) { } - public function feedback( $string, ...$args ) { } } diff --git a/classes/class-theme-install.php b/classes/class-theme-install.php index 9c186a8..38b2b6d 100644 --- a/classes/class-theme-install.php +++ b/classes/class-theme-install.php @@ -475,18 +475,14 @@ public function render_menu() { } // End of render_menu() } +// phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound class ThemeInstallSkin extends \Theme_Installer_Skin { - - public function header() { } - public function footer() { } - public function error( $errors ) { } - public function feedback( $string, ...$args ) { } } diff --git a/classes/trait-helpers.php b/classes/trait-helpers.php index 97e2de5..b4bbf94 100644 --- a/classes/trait-helpers.php +++ b/classes/trait-helpers.php @@ -14,7 +14,7 @@ trait Helpers { * * See https://stackoverflow.com/a/27078384 */ - function get_markdown_contents( $str, $startDelimiter, $endDelimiter ) { + private function get_markdown_contents( $str, $startDelimiter, $endDelimiter ) { $contents = array(); $startDelimiterLength = strlen( $startDelimiter ); $endDelimiterLength = strlen( $endDelimiter ); From 5eefae432e4ba946becbb8b6f3a8003dde1594b6 Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Thu, 24 Apr 2025 13:38:34 +0200 Subject: [PATCH 04/15] Add wpcs workflow --- .github/workflows/wpcs.yml | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/wpcs.yml diff --git a/.github/workflows/wpcs.yml b/.github/workflows/wpcs.yml new file mode 100644 index 0000000..6a1eaac --- /dev/null +++ b/.github/workflows/wpcs.yml @@ -0,0 +1,56 @@ +name: Coding Standards + +on: + push: + branches: + - develop + pull_request: + workflow_dispatch: + +jobs: + # Runs PHP coding standards checks. + # + # Violations are reported inline with annotations. + # + # Performs the following steps: + # - Checks out the repository. + # - Sets up PHP. + # - Logs debug information. + # - Installs Composer dependencies (use cache if possible). + # - Make Composer packages available globally. + # - Logs PHP_CodeSniffer debug information. + # - Runs PHPCS on the full codebase with warnings suppressed. + phpcs: + name: PHP coding standards + runs-on: ubuntu-latest + if: ${{ github.repository == 'ClassicPress/ClassicPress' || github.event_name == 'pull_request' }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + coverage: none + tools: composer, cs2pr + + - name: Log debug information + run: | + php --version + composer --version + + - name: Install Composer dependencies + uses: ramsey/composer-install@v3 + with: + composer-options: "--no-progress --no-ansi --no-interaction" + + - name: Make Composer packages available globally + run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH + + - name: Log PHPCS debug information + run: phpcs -i + + - name: Run PHPCS on plugin + run: phpcs -q -n --report=checkstyle | cs2pr From 9ce0e1af28b607b0b6a1ffc533e86be3037da380 Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Thu, 24 Apr 2025 13:41:54 +0200 Subject: [PATCH 05/15] Fix workflow --- .github/workflows/wpcs.yml | 74 ++++++++++++-------------------------- 1 file changed, 22 insertions(+), 52 deletions(-) diff --git a/.github/workflows/wpcs.yml b/.github/workflows/wpcs.yml index 6a1eaac..d8eac48 100644 --- a/.github/workflows/wpcs.yml +++ b/.github/workflows/wpcs.yml @@ -1,56 +1,26 @@ -name: Coding Standards +name: WPCS checks. -on: - push: - branches: - - develop - pull_request: - workflow_dispatch: +on: [pull_request, push] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: - # Runs PHP coding standards checks. - # - # Violations are reported inline with annotations. - # - # Performs the following steps: - # - Checks out the repository. - # - Sets up PHP. - # - Logs debug information. - # - Installs Composer dependencies (use cache if possible). - # - Make Composer packages available globally. - # - Logs PHP_CodeSniffer debug information. - # - Runs PHPCS on the full codebase with warnings suppressed. phpcs: - name: PHP coding standards - runs-on: ubuntu-latest - if: ${{ github.repository == 'ClassicPress/ClassicPress' || github.event_name == 'pull_request' }} - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.4' - coverage: none - tools: composer, cs2pr - - - name: Log debug information - run: | - php --version - composer --version - - - name: Install Composer dependencies - uses: ramsey/composer-install@v3 - with: - composer-options: "--no-progress --no-ansi --no-interaction" - - - name: Make Composer packages available globally - run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH - - - name: Log PHPCS debug information - run: phpcs -i - - - name: Run PHPCS on plugin - run: phpcs -q -n --report=checkstyle | cs2pr + name: CPCS + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: CPCS checks + uses: 10up/wpcs-action@stable + with: + use_local_config: 'false' + enable_warnings: 'true' + extra_args: '--report-json=./phpcs.json' + - name: Update summary + run: | + npm i -g github:10up/phpcs-json-to-md + phpcs-json-to-md --path ./phpcs.json --output ./phpcs.md + cat phpcs.md >> $GITHUB_STEP_SUMMARY + if: always() From 2f65876bdbd5c41ec700366c654c0f182d499046 Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Thu, 24 Apr 2025 13:44:47 +0200 Subject: [PATCH 06/15] Use ClassicPress standards --- .gitattributes | 3 +- .github/workflows/wpcs.yml | 2 +- phpcs.xml.dist | 315 +++++++++++++++++++++++++++++++++++++ 3 files changed, 318 insertions(+), 2 deletions(-) create mode 100644 phpcs.xml.dist diff --git a/.gitattributes b/.gitattributes index a200a5a..771aace 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ .gitattributes export-ignore .github export-ignore -.gitignore export-ignore \ No newline at end of file +.gitignore export-ignore +phpcs.xml.dist export-ignore \ No newline at end of file diff --git a/.github/workflows/wpcs.yml b/.github/workflows/wpcs.yml index d8eac48..2537f22 100644 --- a/.github/workflows/wpcs.yml +++ b/.github/workflows/wpcs.yml @@ -15,7 +15,7 @@ jobs: - name: CPCS checks uses: 10up/wpcs-action@stable with: - use_local_config: 'false' + use_local_config: 'true' enable_warnings: 'true' extra_args: '--report-json=./phpcs.json' - name: Update summary diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..4a9ec94 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,315 @@ + + + Apply WordPress Coding Standards to all Core files + + + + + + + + + + + + + + + + + + + + ./src/ + + + ^build/* + + + /node_modules/* + /vendor/* + + /src/wp-admin/includes/class-ftp* + /src/wp-admin/includes/class-pclzip\.php + /src/wp-admin/includes/deprecated\.php + /src/wp-admin/includes/ms-deprecated\.php + + /src/wp-includes/atomlib\.php + /src/wp-includes/class-IXR\.php + /src/wp-includes/class-json\.php + /src/wp-includes/class-phpass\.php + /src/wp-includes/class-pop3\.php + /src/wp-includes/class-requests\.php + /src/wp-includes/class-simplepie\.php + /src/wp-includes/class-snoopy\.php + /src/wp-includes/class-avif-info\.php + /src/wp-includes/deprecated\.php + /src/wp-includes/ms-deprecated\.php + /src/wp-includes/pluggable-deprecated\.php + /src/wp-includes/rss\.php + + /src/wp-includes/assets/* + /src/wp-includes/ID3/* + /src/wp-includes/IXR/* + /src/wp-includes/js/* + /src/wp-includes/PHPMailer/* + /src/wp-includes/Requests/* + /src/wp-includes/SimplePie/* + /src/wp-includes/Text/* + + + /tests/phpunit/build* + /tests/phpunit/data/* + + /tools/* + + + /src/wp-content/advanced-cache\.php + /src/wp-content/blog-deleted\.php + /src/wp-content/blog-inactive\.php + /src/wp-content/blog-suspended\.php + /src/wp-content/db-error\.php + /src/wp-content/db\.php + /src/wp-content/fatal-error-handler\.php + /src/wp-content/install\.php + /src/wp-content/maintenance\.php + /src/wp-content/object-cache\.php + /src/wp-content/php-error\.php + /src/wp-content/sunrise\.php + + + /src/wp-content/mu-plugins/* + + + /src/wp-content/plugins/(?!cp-pepper|classicpress-directory-integration)* + + + /src/wp-content/themes/(?!twenty|the-classicpress-theme)* + + + /src/wp-content/languages/* + + + + + + + warning + + + warning + + + warning + + + warning + + + warning + + + warning + + + warning + + + warning + + + warning + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + warning + + + warning + + + warning + + + + + + * + + + + + /wp-config\.php + /wp-config-sample\.php + + + + + /wp-config\.php + /wp-config-sample\.php + /wp-tests-config\.php + /wp-tests-config-sample\.php + + + + + /wp-tests-config-sample\.php + + + + /tests/phpunit/tests/* + + /src/wp-admin/includes/class-wp-filesystem-ftpsockets\.php + /src/wp-includes/class-wp-oembed\.php + /src/wp-includes/class-wp-oembed-controller\.php + /src/wp-includes/class-wp-xmlrpc-server\.php + /src/wp-includes/class-wp-text-diff-renderer-inline\.php + + + + + /src/wp-admin/includes/class-wp-list-table-compat\.php + /src/wp-includes/class-wp-dependency\.php + /src/wp-includes/class-wp-editor\.php + /src/wp-includes/class-wp-xmlrpc-server\.php + /src/wp-includes/class-wpdb\.php + + + + + /src/wp-includes/class-wpdb\.php + /tests/phpunit/tests/db/charset\.php + + + + + /tests/phpunit/tests/db\.php + + + /tests/phpunit/tests/db\.php + + + /tests/phpunit/tests/db\.php + + + /tests/phpunit/tests/admin/includesSchema\.php + /tests/phpunit/tests/multisite/site\.php + + + + + /tests/phpunit/* + + + + + /src/wp-includes/template\.php + + + + + /src/wp-admin/includes/class-wp-list-table-compat\.php + /src/wp-includes/class-wp-dependency\.php + /src/wp-includes/class-wp-editor\.php + + + + + /src/wp-includes/l10n\.php + /tests/phpunit/tests/l10n\.php + /tests/phpunit/tests/l10n/loadTextdomainJustInTime\.php + + + + + /tests/* + + + From af21466c5c1e2e336255b0c6ea3493c9bf638c07 Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Thu, 24 Apr 2025 13:51:50 +0200 Subject: [PATCH 07/15] Fix ruleset --- phpcs.xml.dist | 162 +------------------------------------------------ 1 file changed, 1 insertion(+), 161 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 4a9ec94..a5b68a3 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -23,74 +23,7 @@ - ./src/ - - - ^build/* - - - /node_modules/* - /vendor/* - - /src/wp-admin/includes/class-ftp* - /src/wp-admin/includes/class-pclzip\.php - /src/wp-admin/includes/deprecated\.php - /src/wp-admin/includes/ms-deprecated\.php - - /src/wp-includes/atomlib\.php - /src/wp-includes/class-IXR\.php - /src/wp-includes/class-json\.php - /src/wp-includes/class-phpass\.php - /src/wp-includes/class-pop3\.php - /src/wp-includes/class-requests\.php - /src/wp-includes/class-simplepie\.php - /src/wp-includes/class-snoopy\.php - /src/wp-includes/class-avif-info\.php - /src/wp-includes/deprecated\.php - /src/wp-includes/ms-deprecated\.php - /src/wp-includes/pluggable-deprecated\.php - /src/wp-includes/rss\.php - - /src/wp-includes/assets/* - /src/wp-includes/ID3/* - /src/wp-includes/IXR/* - /src/wp-includes/js/* - /src/wp-includes/PHPMailer/* - /src/wp-includes/Requests/* - /src/wp-includes/SimplePie/* - /src/wp-includes/Text/* - - - /tests/phpunit/build* - /tests/phpunit/data/* - - /tools/* - - - /src/wp-content/advanced-cache\.php - /src/wp-content/blog-deleted\.php - /src/wp-content/blog-inactive\.php - /src/wp-content/blog-suspended\.php - /src/wp-content/db-error\.php - /src/wp-content/db\.php - /src/wp-content/fatal-error-handler\.php - /src/wp-content/install\.php - /src/wp-content/maintenance\.php - /src/wp-content/object-cache\.php - /src/wp-content/php-error\.php - /src/wp-content/sunrise\.php - - - /src/wp-content/mu-plugins/* - - - /src/wp-content/plugins/(?!cp-pepper|classicpress-directory-integration)* - - - /src/wp-content/themes/(?!twenty|the-classicpress-theme)* - - - /src/wp-content/languages/* + ./ @@ -219,97 +152,4 @@ * - - - /wp-config\.php - /wp-config-sample\.php - - - - - /wp-config\.php - /wp-config-sample\.php - /wp-tests-config\.php - /wp-tests-config-sample\.php - - - - - /wp-tests-config-sample\.php - - - - /tests/phpunit/tests/* - - /src/wp-admin/includes/class-wp-filesystem-ftpsockets\.php - /src/wp-includes/class-wp-oembed\.php - /src/wp-includes/class-wp-oembed-controller\.php - /src/wp-includes/class-wp-xmlrpc-server\.php - /src/wp-includes/class-wp-text-diff-renderer-inline\.php - - - - - /src/wp-admin/includes/class-wp-list-table-compat\.php - /src/wp-includes/class-wp-dependency\.php - /src/wp-includes/class-wp-editor\.php - /src/wp-includes/class-wp-xmlrpc-server\.php - /src/wp-includes/class-wpdb\.php - - - - - /src/wp-includes/class-wpdb\.php - /tests/phpunit/tests/db/charset\.php - - - - - /tests/phpunit/tests/db\.php - - - /tests/phpunit/tests/db\.php - - - /tests/phpunit/tests/db\.php - - - /tests/phpunit/tests/admin/includesSchema\.php - /tests/phpunit/tests/multisite/site\.php - - - - - /tests/phpunit/* - - - - - /src/wp-includes/template\.php - - - - - /src/wp-admin/includes/class-wp-list-table-compat\.php - /src/wp-includes/class-wp-dependency\.php - /src/wp-includes/class-wp-editor\.php - - - - - /src/wp-includes/l10n\.php - /tests/phpunit/tests/l10n\.php - /tests/phpunit/tests/l10n/loadTextdomainJustInTime\.php - - - - - /tests/* - - From 7f47a6873efc0bd99b769be8a3d5828545a916e9 Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Thu, 24 Apr 2025 13:55:07 +0200 Subject: [PATCH 08/15] Suppress warnings as in CP repo --- .github/workflows/wpcs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wpcs.yml b/.github/workflows/wpcs.yml index 2537f22..eff3cc4 100644 --- a/.github/workflows/wpcs.yml +++ b/.github/workflows/wpcs.yml @@ -17,7 +17,7 @@ jobs: with: use_local_config: 'true' enable_warnings: 'true' - extra_args: '--report-json=./phpcs.json' + extra_args: '-q -n' - name: Update summary run: | npm i -g github:10up/phpcs-json-to-md From 0e50d0e8c4cde80c697e4a960646f0e3fbe77ffa Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Thu, 24 Apr 2025 13:57:39 +0200 Subject: [PATCH 09/15] Fix workflow report --- .github/workflows/wpcs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wpcs.yml b/.github/workflows/wpcs.yml index eff3cc4..ae0d380 100644 --- a/.github/workflows/wpcs.yml +++ b/.github/workflows/wpcs.yml @@ -17,7 +17,7 @@ jobs: with: use_local_config: 'true' enable_warnings: 'true' - extra_args: '-q -n' + extra_args: '-q -n --report-json=./phpcs.json' - name: Update summary run: | npm i -g github:10up/phpcs-json-to-md From dc79910242fcc9088c010ce6a05957b04c90806b Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Thu, 24 Apr 2025 14:08:01 +0200 Subject: [PATCH 10/15] Fix workflow name --- .github/workflows/wpcs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wpcs.yml b/.github/workflows/wpcs.yml index ae0d380..aa3d41f 100644 --- a/.github/workflows/wpcs.yml +++ b/.github/workflows/wpcs.yml @@ -8,11 +8,11 @@ concurrency: jobs: phpcs: - name: CPCS + name: WPCS runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: CPCS checks + - name: WPCS checks uses: 10up/wpcs-action@stable with: use_local_config: 'true' From 4042d8669fbfb8470a2944650ecf358b26cbcb42 Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Thu, 24 Apr 2025 15:03:20 +0200 Subject: [PATCH 11/15] Add badges --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d7cb744..42bacf7 100755 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ # ClassicPress Directory integrator. +[![ClassicPress Directory Coding Standard checks.](https://github.com/ClassicPress/classicpress-directory-integration/actions/workflows/cpcs.yml/badge.svg)](https://github.com/ClassicPress/classicpress-directory-integration/actions/workflows/cpcs.yml)[![WPCS checks.](https://github.com/ClassicPress/classicpress-directory-integration/actions/workflows/wpcs.yml/badge.svg)](https://github.com/ClassicPress/classicpress-directory-integration/actions/workflows/wpcs.yml) + ## Features - Plugins and themes from [ClassicPress Directory](https://directory.classicpress.net/) now can update as WP.org plugins. From a14430a2dc8f906b7c21c66a1367fc0e27270bb9 Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Mon, 28 Apr 2025 11:31:30 +0200 Subject: [PATCH 12/15] Add PHP Compatibility workflow --- .gitattributes | 3 ++- .github/workflows/php-compatibility.yml | 18 ++++++++++++++ phpcompat.xml.dist | 31 +++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/php-compatibility.yml create mode 100644 phpcompat.xml.dist diff --git a/.gitattributes b/.gitattributes index 771aace..3960e94 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,5 @@ .gitattributes export-ignore .github export-ignore .gitignore export-ignore -phpcs.xml.dist export-ignore \ No newline at end of file +phpcs.xml.dist export-ignore +phpcompat.xml.dist export-ignore \ No newline at end of file diff --git a/.github/workflows/php-compatibility.yml b/.github/workflows/php-compatibility.yml new file mode 100644 index 0000000..d99d0cf --- /dev/null +++ b/.github/workflows/php-compatibility.yml @@ -0,0 +1,18 @@ +jobs: + phpcs: + name: PHP Compatibility + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: WPCS checks + uses: 10up/wpcs-action@stable + with: + use_local_config: 'true' + enable_warnings: 'true' + extra_args: '--standard=phpcompat.xml.dist -q --report=checkstyle --report-json=./phpcs.json' + - name: Update summary + run: | + npm i -g github:10up/phpcs-json-to-md + phpcs-json-to-md --path ./phpcs.json --output ./phpcs.md + cat phpcs.md >> $GITHUB_STEP_SUMMARY + if: always() diff --git a/phpcompat.xml.dist b/phpcompat.xml.dist new file mode 100644 index 0000000..7856b6e --- /dev/null +++ b/phpcompat.xml.dist @@ -0,0 +1,31 @@ + + + Apply PHP compatibility checks + + + + + + + + + + + + + + + + + + + + + + + + + From 65bb05bbc91b10e1b547476a35637b7099d57f8a Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Mon, 28 Apr 2025 11:33:11 +0200 Subject: [PATCH 13/15] Fix workflow --- .github/workflows/php-compatibility.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/php-compatibility.yml b/.github/workflows/php-compatibility.yml index d99d0cf..614d752 100644 --- a/.github/workflows/php-compatibility.yml +++ b/.github/workflows/php-compatibility.yml @@ -1,3 +1,11 @@ +name: PHP Compatibility. + +on: [pull_request, push] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: phpcs: name: PHP Compatibility From 5dfc044ac3789b2b79a90ad0926e1cdce675d746 Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Mon, 28 Apr 2025 11:35:27 +0200 Subject: [PATCH 14/15] Fix workflow --- .github/workflows/php-compatibility.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/php-compatibility.yml b/.github/workflows/php-compatibility.yml index 614d752..6b00ad9 100644 --- a/.github/workflows/php-compatibility.yml +++ b/.github/workflows/php-compatibility.yml @@ -17,10 +17,5 @@ jobs: with: use_local_config: 'true' enable_warnings: 'true' - extra_args: '--standard=phpcompat.xml.dist -q --report=checkstyle --report-json=./phpcs.json' - - name: Update summary - run: | - npm i -g github:10up/phpcs-json-to-md - phpcs-json-to-md --path ./phpcs.json --output ./phpcs.md - cat phpcs.md >> $GITHUB_STEP_SUMMARY - if: always() + extra_args: '--standard=phpcompat.xml.dist -q --report=checkstyle' + From 07a9a337bb647dec0fa2cad4baff487bc7047245 Mon Sep 17 00:00:00 2001 From: xxsimoxx Date: Mon, 28 Apr 2025 11:42:32 +0200 Subject: [PATCH 15/15] Revert phpcompatibility commits --- .gitattributes | 3 +-- .github/workflows/php-compatibility.yml | 21 ----------------- phpcompat.xml.dist | 31 ------------------------- 3 files changed, 1 insertion(+), 54 deletions(-) delete mode 100644 .github/workflows/php-compatibility.yml delete mode 100644 phpcompat.xml.dist diff --git a/.gitattributes b/.gitattributes index 3960e94..771aace 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,4 @@ .gitattributes export-ignore .github export-ignore .gitignore export-ignore -phpcs.xml.dist export-ignore -phpcompat.xml.dist export-ignore \ No newline at end of file +phpcs.xml.dist export-ignore \ No newline at end of file diff --git a/.github/workflows/php-compatibility.yml b/.github/workflows/php-compatibility.yml deleted file mode 100644 index 6b00ad9..0000000 --- a/.github/workflows/php-compatibility.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: PHP Compatibility. - -on: [pull_request, push] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - phpcs: - name: PHP Compatibility - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: WPCS checks - uses: 10up/wpcs-action@stable - with: - use_local_config: 'true' - enable_warnings: 'true' - extra_args: '--standard=phpcompat.xml.dist -q --report=checkstyle' - diff --git a/phpcompat.xml.dist b/phpcompat.xml.dist deleted file mode 100644 index 7856b6e..0000000 --- a/phpcompat.xml.dist +++ /dev/null @@ -1,31 +0,0 @@ - - - Apply PHP compatibility checks - - - - - - - - - - - - - - - - - - - - - - - - -