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
|
# dotenv environment variables file
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
# system files
|
||||||
|
.DS_Store
|
||||||
|
|
|
@ -1,3 +1 @@
|
||||||
// Import the default config file and expose it in the project root.
|
module.exports = require('@wordpress/prettier-config');
|
||||||
// Useful for editor integrations.
|
|
||||||
module.exports = require("@wordpress/prettier-config");
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Mind_Admin {
|
||||||
* Mind_Admin constructor.
|
* Mind_Admin constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
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' ),
|
esc_html__( 'Mind', 'mind' ),
|
||||||
'manage_options',
|
'manage_options',
|
||||||
'mind',
|
'mind',
|
||||||
array( 'Mind_Settings', 'print_settings_page' ),
|
[ 'Mind_Settings', 'print_settings_page' ],
|
||||||
// phpcs:ignore
|
// phpcs:ignore
|
||||||
'data:image/svg+xml;base64,' . base64_encode( file_get_contents( mind()->plugin_path . 'assets/images/admin-icon.svg' ) ),
|
'data:image/svg+xml;base64,' . base64_encode( file_get_contents( mind()->plugin_path . 'assets/images/admin-icon.svg' ) ),
|
||||||
'58.7'
|
'58.7'
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Mind_Assets {
|
||||||
* Mind_Assets constructor.
|
* Mind_Assets constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
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 include $asset_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return [
|
||||||
'dependencies' => array(),
|
'dependencies' => [],
|
||||||
'version' => MIND_VERSION,
|
'version' => MIND_VERSION,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,7 +58,7 @@ class Mind_Assets {
|
||||||
wp_enqueue_style(
|
wp_enqueue_style(
|
||||||
'mind-editor',
|
'mind-editor',
|
||||||
mind()->plugin_url . 'build/style-index.css',
|
mind()->plugin_url . 'build/style-index.css',
|
||||||
array(),
|
[],
|
||||||
$asset_data['version']
|
$asset_data['version']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,10 @@ class Mind_Settings {
|
||||||
*
|
*
|
||||||
* @param string $option - option name.
|
* @param string $option - option name.
|
||||||
* @param string $section - section name.
|
* @param string $section - section name.
|
||||||
* @param string $deprecated_default - default option value.
|
|
||||||
*
|
*
|
||||||
* @return bool|string
|
* @return bool|string
|
||||||
*/
|
*/
|
||||||
public static function get_option( $option, $section, $deprecated_default = '' ) {
|
public static function get_option( $option, $section ) {
|
||||||
$options = get_option( $section );
|
$options = get_option( $section );
|
||||||
$result = '';
|
$result = '';
|
||||||
|
|
||||||
|
@ -79,7 +78,7 @@ class Mind_Settings {
|
||||||
$options = get_option( $section );
|
$options = get_option( $section );
|
||||||
|
|
||||||
if ( ! is_array( $options ) ) {
|
if ( ! is_array( $options ) ) {
|
||||||
$options = array();
|
$options = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$options[ $option ] = $value;
|
$options[ $option ] = $value;
|
||||||
|
@ -93,7 +92,7 @@ class Mind_Settings {
|
||||||
public static function init_actions() {
|
public static function init_actions() {
|
||||||
self::$settings_api = new Mind_Settings_API();
|
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
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function get_settings_sections() {
|
public static function get_settings_sections() {
|
||||||
$sections = array(
|
$sections = [
|
||||||
array(
|
[
|
||||||
'id' => 'mind_general',
|
'id' => 'mind_general',
|
||||||
'title' => esc_html__( 'General', 'mind' ),
|
'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>',
|
'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 );
|
return apply_filters( 'mind_settings_sections', $sections );
|
||||||
}
|
}
|
||||||
|
@ -145,17 +144,17 @@ class Mind_Settings {
|
||||||
$openai_key = $general_settings['openai_key'];
|
$openai_key = $general_settings['openai_key'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$settings_fields = array(
|
$settings_fields = [
|
||||||
'mind_general' => array(
|
'mind_general' => [
|
||||||
array(
|
[
|
||||||
'name' => 'openai_key',
|
'name' => 'openai_key',
|
||||||
'label' => esc_html__( 'OpenAI API Key', 'mind' ),
|
'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>',
|
'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',
|
'type' => $openai_key ? 'password' : 'text',
|
||||||
'default' => '',
|
'default' => '',
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
|
|
||||||
self::$cached_settings_fields = apply_filters( 'mind_settings_fields', $settings_fields );
|
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 at least: 6.0
|
||||||
* Requires PHP: 7.2
|
* Requires PHP: 7.2
|
||||||
* Version: 0.1.0
|
* 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
|
* Author URI: https://wp-mind.com/?utm_source=wordpress.org&utm_medium=readme&utm_campaign=byline
|
||||||
* License: GPLv2 or later
|
* License: GPLv2 or later
|
||||||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
* 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-settings.php';
|
||||||
require_once $this->plugin_path . 'classes/class-admin.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-assets.php';
|
||||||
|
require_once $this->plugin_path . 'classes/class-rest.php';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,5 +131,5 @@ function mind() {
|
||||||
}
|
}
|
||||||
add_action( 'plugins_loaded', 'mind' );
|
add_action( 'plugins_loaded', 'mind' );
|
||||||
|
|
||||||
register_activation_hook( __FILE__, array( mind(), 'activation_hook' ) );
|
register_activation_hook( __FILE__, [ mind(), 'activation_hook' ] );
|
||||||
register_deactivation_hook( __FILE__, array( mind(), 'deactivation_hook' ) );
|
register_deactivation_hook( __FILE__, [ mind(), 'deactivation_hook' ] );
|
||||||
|
|
46
vendors/class-settings-api.php
vendored
46
vendors/class-settings-api.php
vendored
|
@ -22,20 +22,20 @@ class Mind_Settings_API {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $settings_sections = array();
|
protected $settings_sections = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings fields array
|
* Settings fields array
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $settings_fields = array();
|
protected $settings_fields = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mind_Settings_API constructor.
|
* Mind_Settings_API constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
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_media();
|
||||||
wp_enqueue_script( 'wp-color-picker' );
|
wp_enqueue_script( 'wp-color-picker' );
|
||||||
wp_enqueue_script( 'jquery' );
|
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_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', array( 'jquery' ), '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 ) {
|
public function add_field( $section, $field ) {
|
||||||
$defaults = array(
|
$defaults = [
|
||||||
'name' => '',
|
'name' => '',
|
||||||
'label' => '',
|
'label' => '',
|
||||||
'desc' => '',
|
'desc' => '',
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'is_pro' => false,
|
'is_pro' => false,
|
||||||
);
|
];
|
||||||
|
|
||||||
$arg = wp_parse_args( $field, $defaults );
|
$arg = wp_parse_args( $field, $defaults );
|
||||||
$this->settings_fields[ $section ][] = $arg;
|
$this->settings_fields[ $section ][] = $arg;
|
||||||
|
@ -135,23 +135,23 @@ class Mind_Settings_API {
|
||||||
$name = $option['name'];
|
$name = $option['name'];
|
||||||
$type = isset( $option['type'] ) ? $option['type'] : 'text';
|
$type = isset( $option['type'] ) ? $option['type'] : 'text';
|
||||||
$label = isset( $option['label'] ) ? $option['label'] : '';
|
$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;
|
$class_name = isset( $option['class'] ) ? $option['class'] : $name;
|
||||||
$is_pro = isset( $option['is_pro'] ) ? $option['is_pro'] : false;
|
$is_pro = isset( $option['is_pro'] ) ? $option['is_pro'] : false;
|
||||||
|
|
||||||
if ( $is_pro ) {
|
if ( $is_pro ) {
|
||||||
$class_name .= ' mind-settings-control-pro';
|
$class_name .= ' mind-settings-control-pro';
|
||||||
$go_pro_url = Visual_Portfolio_Admin::get_plugin_site_url(
|
$go_pro_url = Visual_Portfolio_Admin::get_plugin_site_url(
|
||||||
array(
|
[
|
||||||
'utm_medium' => 'settings_page',
|
'utm_medium' => 'settings_page',
|
||||||
'utm_campaign' => esc_attr( $name ),
|
'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>';
|
$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,
|
'id' => $name,
|
||||||
'class' => $class_name,
|
'class' => $class_name,
|
||||||
'label_for' => "{$section}[{$name}]",
|
'label_for' => "{$section}[{$name}]",
|
||||||
'desc' => isset( $option['desc'] ) ? $option['desc'] : '',
|
'desc' => isset( $option['desc'] ) ? $option['desc'] : '',
|
||||||
|
@ -169,7 +169,7 @@ class Mind_Settings_API {
|
||||||
'is_pro' => isset( $option['is_pro'] ) ? $option['is_pro'] : false,
|
'is_pro' => isset( $option['is_pro'] ) ? $option['is_pro'] : false,
|
||||||
'condition' => isset( $option['condition'] ) ? $option['condition'] : null,
|
'condition' => isset( $option['condition'] ) ? $option['condition'] : null,
|
||||||
'conditionize' => isset( $option['condition'] ) ? $this->convert_arguments_to_conditionize_string( $option['condition'] ) : '',
|
'conditionize' => isset( $option['condition'] ) ? $this->convert_arguments_to_conditionize_string( $option['condition'] ) : '',
|
||||||
);
|
];
|
||||||
|
|
||||||
add_settings_field( "{$section}[{$name}]", $label, $callback, $section, $section, $args );
|
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
|
// creates our settings in the options table
|
||||||
foreach ( $this->settings_sections as $section ) {
|
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 . ';">';
|
echo '<div style="max-width: ' . $size . ';">';
|
||||||
|
|
||||||
$editor_settings = array(
|
$editor_settings = [
|
||||||
'teeny' => true,
|
'teeny' => true,
|
||||||
'textarea_name' => $args['section'] . '[' . $args['id'] . ']',
|
'textarea_name' => $args['section'] . '[' . $args['id'] . ']',
|
||||||
'textarea_rows' => 10,
|
'textarea_rows' => 10,
|
||||||
);
|
];
|
||||||
|
|
||||||
if ( isset( $args['options'] ) && is_array( $args['options'] ) ) {
|
if ( isset( $args['options'] ) && is_array( $args['options'] ) ) {
|
||||||
$editor_settings = array_merge( $editor_settings, $args['options'] );
|
$editor_settings = array_merge( $editor_settings, $args['options'] );
|
||||||
|
@ -476,12 +476,12 @@ class Mind_Settings_API {
|
||||||
*/
|
*/
|
||||||
public function callback_pages( $args ) {
|
public function callback_pages( $args ) {
|
||||||
|
|
||||||
$dropdown_args = array(
|
$dropdown_args = [
|
||||||
'selected' => esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) ),
|
'selected' => esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) ),
|
||||||
'name' => $args['section'] . '[' . $args['id'] . ']',
|
'name' => $args['section'] . '[' . $args['id'] . ']',
|
||||||
'id' => $args['section'] . '[' . $args['id'] . ']',
|
'id' => $args['section'] . '[' . $args['id'] . ']',
|
||||||
'echo' => 0,
|
'echo' => 0,
|
||||||
);
|
];
|
||||||
$html = wp_dropdown_pages( $dropdown_args );
|
$html = wp_dropdown_pages( $dropdown_args );
|
||||||
echo $html;
|
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