From 1cac92d58f0c5fb5df79097af1ef033c77188f44 Mon Sep 17 00:00:00 2001 From: Nikita Date: Fri, 14 Jul 2023 10:35:15 +0300 Subject: [PATCH] changed PHP arrays to [] --- .gitignore | 3 +++ .prettierrc.js | 4 +-- classes/class-admin.php | 4 +-- classes/class-assets.php | 10 ++++---- classes/class-settings.php | 27 ++++++++++---------- mind.php | 7 +++--- vendors/class-settings-api.php | 46 +++++++++++++++++----------------- webpack.config.js | 21 ++++++++++++++++ 8 files changed, 72 insertions(+), 50 deletions(-) create mode 100644 webpack.config.js diff --git a/.gitignore b/.gitignore index aef3730..7cfdfb6 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ node_modules/ # dotenv environment variables file .env + +# system files +.DS_Store diff --git a/.prettierrc.js b/.prettierrc.js index 548adf7..e596d24 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,3 +1 @@ -// Import the default config file and expose it in the project root. -// Useful for editor integrations. -module.exports = require("@wordpress/prettier-config"); +module.exports = require('@wordpress/prettier-config'); diff --git a/classes/class-admin.php b/classes/class-admin.php index 84967ac..888006b 100644 --- a/classes/class-admin.php +++ b/classes/class-admin.php @@ -17,7 +17,7 @@ class Mind_Admin { * Mind_Admin constructor. */ public function __construct() { - add_action( 'admin_menu', array( $this, 'register_admin_menu' ), 20 ); + add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 20 ); } /** @@ -35,7 +35,7 @@ class Mind_Admin { esc_html__( 'Mind', 'mind' ), 'manage_options', 'mind', - array( 'Mind_Settings', 'print_settings_page' ), + [ 'Mind_Settings', 'print_settings_page' ], // phpcs:ignore 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( mind()->plugin_path . 'assets/images/admin-icon.svg' ) ), '58.7' diff --git a/classes/class-assets.php b/classes/class-assets.php index 9786d87..04f1c3d 100644 --- a/classes/class-assets.php +++ b/classes/class-assets.php @@ -17,7 +17,7 @@ class Mind_Assets { * Mind_Assets constructor. */ public function __construct() { - add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) ); + add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_block_editor_assets' ] ); } /** @@ -35,10 +35,10 @@ class Mind_Assets { return include $asset_path; } - return array( - 'dependencies' => array(), + return [ + 'dependencies' => [], 'version' => MIND_VERSION, - ); + ]; } /** @@ -58,7 +58,7 @@ class Mind_Assets { wp_enqueue_style( 'mind-editor', mind()->plugin_url . 'build/style-index.css', - array(), + [], $asset_data['version'] ); } diff --git a/classes/class-settings.php b/classes/class-settings.php index 950af1d..6310491 100644 --- a/classes/class-settings.php +++ b/classes/class-settings.php @@ -42,11 +42,10 @@ class Mind_Settings { * * @param string $option - option name. * @param string $section - section name. - * @param string $deprecated_default - default option value. * * @return bool|string */ - public static function get_option( $option, $section, $deprecated_default = '' ) { + public static function get_option( $option, $section ) { $options = get_option( $section ); $result = ''; @@ -79,7 +78,7 @@ class Mind_Settings { $options = get_option( $section ); if ( ! is_array( $options ) ) { - $options = array(); + $options = []; } $options[ $option ] = $value; @@ -93,7 +92,7 @@ class Mind_Settings { public static function init_actions() { self::$settings_api = new Mind_Settings_API(); - add_action( 'admin_init', array( __CLASS__, 'admin_init' ) ); + add_action( 'admin_init', [ __CLASS__, 'admin_init' ] ); } /** @@ -116,13 +115,13 @@ class Mind_Settings { * @return array */ public static function get_settings_sections() { - $sections = array( - array( + $sections = [ + [ 'id' => 'mind_general', 'title' => esc_html__( 'General', 'mind' ), 'icon' => '', - ), - ); + ], + ]; return apply_filters( 'mind_settings_sections', $sections ); } @@ -145,17 +144,17 @@ class Mind_Settings { $openai_key = $general_settings['openai_key']; } - $settings_fields = array( - 'mind_general' => array( - array( + $settings_fields = [ + 'mind_general' => [ + [ 'name' => 'openai_key', 'label' => esc_html__( 'OpenAI API Key', 'mind' ), 'desc' => esc_html__( 'This setting is required, since our plugin works with OpenAI.', 'mind' ) . ' Create API key', 'type' => $openai_key ? 'password' : 'text', 'default' => '', - ), - ), - ); + ], + ], + ]; self::$cached_settings_fields = apply_filters( 'mind_settings_fields', $settings_fields ); diff --git a/mind.php b/mind.php index af34858..1e59c65 100644 --- a/mind.php +++ b/mind.php @@ -5,7 +5,7 @@ * Requires at least: 6.0 * Requires PHP: 7.2 * Version: 0.1.0 - * Author: WPMind Team + * Author: Mind Team * Author URI: https://wp-mind.com/?utm_source=wordpress.org&utm_medium=readme&utm_campaign=byline * License: GPLv2 or later * License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -117,6 +117,7 @@ class Mind { require_once $this->plugin_path . 'classes/class-settings.php'; require_once $this->plugin_path . 'classes/class-admin.php'; require_once $this->plugin_path . 'classes/class-assets.php'; + require_once $this->plugin_path . 'classes/class-rest.php'; } } @@ -130,5 +131,5 @@ function mind() { } add_action( 'plugins_loaded', 'mind' ); -register_activation_hook( __FILE__, array( mind(), 'activation_hook' ) ); -register_deactivation_hook( __FILE__, array( mind(), 'deactivation_hook' ) ); +register_activation_hook( __FILE__, [ mind(), 'activation_hook' ] ); +register_deactivation_hook( __FILE__, [ mind(), 'deactivation_hook' ] ); diff --git a/vendors/class-settings-api.php b/vendors/class-settings-api.php index 0891022..7a4bf39 100644 --- a/vendors/class-settings-api.php +++ b/vendors/class-settings-api.php @@ -22,20 +22,20 @@ class Mind_Settings_API { * * @var array */ - protected $settings_sections = array(); + protected $settings_sections = []; /** * Settings fields array * * @var array */ - protected $settings_fields = array(); + protected $settings_fields = []; /** * Mind_Settings_API constructor. */ public function __construct() { - // add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); + // add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] ); } /** @@ -47,10 +47,10 @@ class Mind_Settings_API { wp_enqueue_media(); wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_script( 'jquery' ); - wp_enqueue_script( 'conditionize', mind()->plugin_url . 'vendors/assets/conditionize/conditionize.min.js', array( 'jquery' ), '1.0.5' ); + wp_enqueue_script( 'conditionize', mind()->plugin_url . 'vendors/assets/conditionize/conditionize.min.js', [ 'jquery' ], '1.0.5' ); - wp_enqueue_style( 'select2', mind()->plugin_url . 'vendors/assets/select2/select2.min.css', array(), '4.0.13' ); - wp_enqueue_script( 'select2', mind()->plugin_url . 'vendors/assets/select2/select2.min.js', array( 'jquery' ), '4.0.13' ); + wp_enqueue_style( 'select2', mind()->plugin_url . 'vendors/assets/select2/select2.min.css', [], '4.0.13' ); + wp_enqueue_script( 'select2', mind()->plugin_url . 'vendors/assets/select2/select2.min.js', [ 'jquery' ], '4.0.13' ); } /** @@ -87,13 +87,13 @@ class Mind_Settings_API { } public function add_field( $section, $field ) { - $defaults = array( - 'name' => '', + $defaults = [ + 'name' => '', 'label' => '', 'desc' => '', 'type' => 'text', 'is_pro' => false, - ); + ]; $arg = wp_parse_args( $field, $defaults ); $this->settings_fields[ $section ][] = $arg; @@ -135,23 +135,23 @@ class Mind_Settings_API { $name = $option['name']; $type = isset( $option['type'] ) ? $option['type'] : 'text'; $label = isset( $option['label'] ) ? $option['label'] : ''; - $callback = isset( $option['callback'] ) ? $option['callback'] : array( $this, 'callback_' . $type ); + $callback = isset( $option['callback'] ) ? $option['callback'] : [ $this, 'callback_' . $type ]; $class_name = isset( $option['class'] ) ? $option['class'] : $name; $is_pro = isset( $option['is_pro'] ) ? $option['is_pro'] : false; if ( $is_pro ) { $class_name .= ' mind-settings-control-pro'; $go_pro_url = Visual_Portfolio_Admin::get_plugin_site_url( - array( - 'utm_medium' => 'settings_page', + [ + 'utm_medium' => 'settings_page', 'utm_campaign' => esc_attr( $name ), - ) + ] ); $label .= '?' . esc_html__( 'This feature is available in the Pro plugin only.', '@@text_domain' ) . ''; } - $args = array( - 'id' => $name, + $args = [ + 'id' => $name, 'class' => $class_name, 'label_for' => "{$section}[{$name}]", 'desc' => isset( $option['desc'] ) ? $option['desc'] : '', @@ -169,7 +169,7 @@ class Mind_Settings_API { 'is_pro' => isset( $option['is_pro'] ) ? $option['is_pro'] : false, 'condition' => isset( $option['condition'] ) ? $option['condition'] : null, 'conditionize' => isset( $option['condition'] ) ? $this->convert_arguments_to_conditionize_string( $option['condition'] ) : '', - ); + ]; add_settings_field( "{$section}[{$name}]", $label, $callback, $section, $section, $args ); } @@ -177,7 +177,7 @@ class Mind_Settings_API { // creates our settings in the options table foreach ( $this->settings_sections as $section ) { - register_setting( $section['id'], $section['id'], array( $this, 'sanitize_options' ) ); + register_setting( $section['id'], $section['id'], [ $this, 'sanitize_options' ] ); } } @@ -377,11 +377,11 @@ class Mind_Settings_API { echo '
'; - $editor_settings = array( - 'teeny' => true, + $editor_settings = [ + 'teeny' => true, 'textarea_name' => $args['section'] . '[' . $args['id'] . ']', 'textarea_rows' => 10, - ); + ]; if ( isset( $args['options'] ) && is_array( $args['options'] ) ) { $editor_settings = array_merge( $editor_settings, $args['options'] ); @@ -476,12 +476,12 @@ class Mind_Settings_API { */ public function callback_pages( $args ) { - $dropdown_args = array( - 'selected' => esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) ), + $dropdown_args = [ + 'selected' => esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) ), 'name' => $args['section'] . '[' . $args['id'] . ']', 'id' => $args['section'] . '[' . $args['id'] . ']', 'echo' => 0, - ); + ]; $html = wp_dropdown_pages( $dropdown_args ); echo $html; } diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..5af425d --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,21 @@ +const defaultConfig = require('@wordpress/scripts/config/webpack.config'); + +const isProduction = process.env.NODE_ENV === 'production'; + +const newConfig = { + ...defaultConfig, + + // Display minimum info in terminal. + stats: 'minimal', +}; + +// Development only. +if (!isProduction) { + newConfig.devServer = { + ...newConfig.devServer, + // Support for dev server on all domains. + allowedHosts: 'all', + }; +} + +module.exports = newConfig;