mirror of
https://github.com/WenPai-org/wpmind.git
synced 2025-08-03 02:48:41 +08:00
changed PHP arrays to []
This commit is contained in:
parent
5e6716e068
commit
1cac92d58f
8 changed files with 72 additions and 50 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -38,3 +38,6 @@ node_modules/
|
|||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# system files
|
||||
.DS_Store
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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']
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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' => '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4" /></svg>',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
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' ) . ' <a href="https://platform.openai.com/account/api-keys" target="_blank">Create API key</a>',
|
||||
'type' => $openai_key ? 'password' : 'text',
|
||||
'default' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
self::$cached_settings_fields = apply_filters( 'mind_settings_fields', $settings_fields );
|
||||
|
||||
|
|
7
mind.php
7
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' ] );
|
||||
|
|
36
vendors/class-settings-api.php
vendored
36
vendors/class-settings-api.php
vendored
|
@ -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(
|
||||
$defaults = [
|
||||
'name' => '',
|
||||
'label' => '',
|
||||
'desc' => '',
|
||||
'type' => 'text',
|
||||
'is_pro' => false,
|
||||
);
|
||||
];
|
||||
|
||||
$arg = wp_parse_args( $field, $defaults );
|
||||
$this->settings_fields[ $section ][] = $arg;
|
||||
|
@ -135,22 +135,22 @@ 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_campaign' => esc_attr( $name ),
|
||||
)
|
||||
]
|
||||
);
|
||||
$label .= '<a class="mind-settings-control-pro-label" target="_blank" rel="noopener noreferrer" href="' . esc_url( $go_pro_url ) . '">?<span>' . esc_html__( 'This feature is available in the Pro plugin only.', '@@text_domain' ) . '</span></a>';
|
||||
}
|
||||
|
||||
$args = array(
|
||||
$args = [
|
||||
'id' => $name,
|
||||
'class' => $class_name,
|
||||
'label_for' => "{$section}[{$name}]",
|
||||
|
@ -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 '<div style="max-width: ' . $size . ';">';
|
||||
|
||||
$editor_settings = array(
|
||||
$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(
|
||||
$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;
|
||||
}
|
||||
|
|
21
webpack.config.js
Normal file
21
webpack.config.js
Normal file
|
@ -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;
|
Loading…
Add table
Add a link
Reference in a new issue