From 552643d3e38bc964402cfb338834ec527e88fe27 Mon Sep 17 00:00:00 2001 From: Alec Geatches Date: Fri, 24 May 2024 13:11:58 -0600 Subject: [PATCH] Bump plugin version to 0.9.9, apply automatic PHP lint changes --- edit_flow.php | 158 +++++++++++++++++++++++++++----------------------- 1 file changed, 85 insertions(+), 73 deletions(-) diff --git a/edit_flow.php b/edit_flow.php index 385fbfce..5b0b27b8 100644 --- a/edit_flow.php +++ b/edit_flow.php @@ -4,7 +4,7 @@ Plugin URI: http://editflow.org/ Description: Remixing the WordPress admin for better editorial workflow options. Author: Daniel Bachhuber, Scott Bressler, Mohammad Jangda, Automattic, and others -Version: 0.9.8 +Version: 0.9.9 Author URI: http://editflow.org/ Copyright 2009-2019 Mohammad Jangda, Daniel Bachhuber, Automattic, et al. @@ -46,18 +46,18 @@ function _ef_print_php_version_admin_notice() { } // Define contants -define( 'EDIT_FLOW_VERSION' , '0.9.8' ); -define( 'EDIT_FLOW_ROOT' , dirname(__FILE__) ); -define( 'EDIT_FLOW_FILE_PATH' , EDIT_FLOW_ROOT . '/' . basename(__FILE__) ); -define( 'EDIT_FLOW_URL' , plugins_url( '/', __FILE__ ) ); -define( 'EDIT_FLOW_SETTINGS_PAGE' , add_query_arg( 'page', 'ef-settings', get_admin_url( null, 'admin.php' ) ) ); +define( 'EDIT_FLOW_VERSION', '0.9.9' ); +define( 'EDIT_FLOW_ROOT', __DIR__ ); +define( 'EDIT_FLOW_FILE_PATH', EDIT_FLOW_ROOT . '/' . basename( __FILE__ ) ); +define( 'EDIT_FLOW_URL', plugins_url( '/', __FILE__ ) ); +define( 'EDIT_FLOW_SETTINGS_PAGE', add_query_arg( 'page', 'ef-settings', get_admin_url( null, 'admin.php' ) ) ); // Core class #[\AllowDynamicProperties] class edit_flow { // Unique identified added as a prefix to all options - var $options_group = 'edit_flow_'; + var $options_group = 'edit_flow_'; var $options_group_name = 'edit_flow_options'; /** @@ -100,7 +100,7 @@ class edit_flow { */ public static function instance() { if ( ! isset( self::$instance ) ) { - self::$instance = new edit_flow; + self::$instance = new edit_flow(); self::$instance->setup_globals(); self::$instance->setup_actions(); // Backwards compat for when we promoted use of the $edit_flow global @@ -115,7 +115,7 @@ private function __construct() { } private function setup_globals() { - $this->modules = new stdClass(); + $this->modules = new stdClass(); $this->modules_count = 0; } @@ -125,32 +125,33 @@ private function setup_globals() { private function load_modules() { // We use the WP_List_Table API for some of the table gen - if ( !class_exists( 'WP_List_Table' ) ) - require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); + if ( ! class_exists( 'WP_List_Table' ) ) { + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; + } // Edit Flow base module - require_once( EDIT_FLOW_ROOT . '/common/php/class-module.php' ); + require_once EDIT_FLOW_ROOT . '/common/php/class-module.php'; // Edit Flow Block Editor Compat trait - require_once( EDIT_FLOW_ROOT . '/common/php/trait-block-editor-compatible.php' ); + require_once EDIT_FLOW_ROOT . '/common/php/trait-block-editor-compatible.php'; // Scan the modules directory and include any modules that exist there $module_dirs = scandir( EDIT_FLOW_ROOT . '/modules/' ); $class_names = array(); - foreach( $module_dirs as $module_dir ) { + foreach ( $module_dirs as $module_dir ) { if ( file_exists( EDIT_FLOW_ROOT . "/modules/{$module_dir}/$module_dir.php" ) ) { - include_once( EDIT_FLOW_ROOT . "/modules/{$module_dir}/$module_dir.php" ); + include_once EDIT_FLOW_ROOT . "/modules/{$module_dir}/$module_dir.php"; // Prepare the class name because it should be standardized - $tmp = explode( '-', $module_dir ); + $tmp = explode( '-', $module_dir ); $class_name = ''; - $slug_name = ''; - foreach( $tmp as $word ) { + $slug_name = ''; + foreach ( $tmp as $word ) { $class_name .= ucfirst( $word ) . '_'; - $slug_name .= $word . '_'; + $slug_name .= $word . '_'; } - $slug_name = rtrim( $slug_name, '_' ); - $class_names[$slug_name] = 'EF_' . rtrim( $class_name, '_' ); + $slug_name = rtrim( $slug_name, '_' ); + $class_names[ $slug_name ] = 'EF_' . rtrim( $class_name, '_' ); } } @@ -159,11 +160,11 @@ private function load_modules() { $this->helpers = new EF_Module(); // Other utils - require_once( EDIT_FLOW_ROOT . '/common/php/util.php' ); + require_once EDIT_FLOW_ROOT . '/common/php/util.php'; // Instantiate all of our classes onto the Edit Flow object // but make sure they exist too - foreach( $class_names as $slug => $class_name ) { + foreach ( $class_names as $slug => $class_name ) { if ( class_exists( $class_name ) ) { $this->$slug = new $class_name(); } @@ -176,7 +177,6 @@ private function load_modules() { * */ do_action( 'ef_modules_loaded' ); - } /** @@ -217,9 +217,11 @@ function action_init() { // Load all of the modules that are enabled. // Modules won't have an options value if they aren't enabled - foreach ( $this->modules as $mod_name => $mod_data ) - if ( isset( $mod_data->options->enabled ) && $mod_data->options->enabled == 'on' ) + foreach ( $this->modules as $mod_name => $mod_data ) { + if ( isset( $mod_data->options->enabled ) && $mod_data->options->enabled == 'on' ) { $this->$mod_name->init(); + } + } /** * Fires after edit_flow has loaded all modules and module options. @@ -239,26 +241,27 @@ function action_admin_init() { $previous_version = get_option( $this->options_group . 'version' ); if ( $previous_version && version_compare( $previous_version, EDIT_FLOW_VERSION, '<' ) ) { foreach ( $this->modules as $mod_name => $mod_data ) { - if ( method_exists( $this->$mod_name, 'upgrade' ) ) + if ( method_exists( $this->$mod_name, 'upgrade' ) ) { $this->$mod_name->upgrade( $previous_version ); + } } update_option( $this->options_group . 'version', EDIT_FLOW_VERSION ); - } else if ( !$previous_version ) { + } elseif ( ! $previous_version ) { update_option( $this->options_group . 'version', EDIT_FLOW_VERSION ); } // For each module that's been loaded, auto-load data if it's never been run before foreach ( $this->modules as $mod_name => $mod_data ) { // If the module has never been loaded before, run the install method if there is one - if ( !isset( $mod_data->options->loaded_once ) || !$mod_data->options->loaded_once ) { - if ( method_exists( $this->$mod_name, 'install' ) ) + if ( ! isset( $mod_data->options->loaded_once ) || ! $mod_data->options->loaded_once ) { + if ( method_exists( $this->$mod_name, 'install' ) ) { $this->$mod_name->install(); + } $this->update_module_option( $mod_name, 'loaded_once', true ); } } $this->register_scripts_and_styles(); - } /** @@ -267,47 +270,52 @@ function action_admin_init() { public function register_module( $name, $args = array() ) { // A title and name is required for every module - if ( !isset( $args['title'], $name ) ) + if ( ! isset( $args['title'], $name ) ) { return false; + } $defaults = array( - 'title' => '', - 'short_description' => '', + 'title' => '', + 'short_description' => '', 'extended_description' => '', - 'img_url' => false, - 'slug' => '', - 'post_type_support' => '', - 'default_options' => array(), - 'options' => false, - 'configure_page_cb' => false, - 'configure_link_text' => __( 'Configure', 'edit-flow' ), + 'img_url' => false, + 'slug' => '', + 'post_type_support' => '', + 'default_options' => array(), + 'options' => false, + 'configure_page_cb' => false, + 'configure_link_text' => __( 'Configure', 'edit-flow' ), // These messages are applied to modules and can be overridden if custom messages are needed - 'messages' => array( - 'settings-updated' => __( 'Settings updated.', 'edit-flow' ), - 'form-error' => __( 'Please correct your form errors below and try again.', 'edit-flow' ), - 'nonce-failed' => __( 'Cheatin’ uh?', 'edit-flow' ), + 'messages' => array( + 'settings-updated' => __( 'Settings updated.', 'edit-flow' ), + 'form-error' => __( 'Please correct your form errors below and try again.', 'edit-flow' ), + 'nonce-failed' => __( 'Cheatin’ uh?', 'edit-flow' ), 'invalid-permissions' => __( 'You do not have necessary permissions to complete this action.', 'edit-flow' ), - 'missing-post' => __( 'Post does not exist', 'edit-flow' ), + 'missing-post' => __( 'Post does not exist', 'edit-flow' ), ), - 'autoload' => false, // autoloading a module will remove the ability to enable or disable it + 'autoload' => false, // autoloading a module will remove the ability to enable or disable it ); - if ( isset( $args['messages'] ) ) - $args['messages'] = array_merge( (array)$args['messages'], $defaults['messages'] ); - $args = array_merge( $defaults, $args ); - $args['name'] = $name; + if ( isset( $args['messages'] ) ) { + $args['messages'] = array_merge( (array) $args['messages'], $defaults['messages'] ); + } + $args = array_merge( $defaults, $args ); + $args['name'] = $name; $args['options_group_name'] = $this->options_group . $name . '_options'; - if ( !isset( $args['settings_slug'] ) ) + if ( ! isset( $args['settings_slug'] ) ) { $args['settings_slug'] = 'ef-' . $args['slug'] . '-settings'; - if ( empty( $args['post_type_support'] ) ) + } + if ( empty( $args['post_type_support'] ) ) { $args['post_type_support'] = 'ef_' . $name; + } // If there's a Help Screen registered for the module, make sure we // auto-load it - if ( !empty( $args['settings_help_tab'] ) ) + if ( ! empty( $args['settings_help_tab'] ) ) { add_action( 'load-edit-flow_page_' . $args['settings_slug'], array( &$this->$name, 'action_settings_help_menu' ) ); + } $this->modules->$name = (object) $args; - $this->modules_count++; + ++$this->modules_count; /** * Fires after edit_flow has registered a module. @@ -328,10 +336,11 @@ function load_module_options() { foreach ( $this->modules as $mod_name => $mod_data ) { - $this->modules->$mod_name->options = get_option( $this->options_group . $mod_name . '_options', new stdClass ); + $this->modules->$mod_name->options = get_option( $this->options_group . $mod_name . '_options', new stdClass() ); foreach ( $mod_data->default_options as $default_key => $default_value ) { - if ( !isset( $this->modules->$mod_name->options->$default_key ) ) + if ( ! isset( $this->modules->$mod_name->options->$default_key ) ) { $this->modules->$mod_name->options->$default_key = $default_value; + } } $this->$mod_name->module = $this->modules->$mod_name; @@ -354,8 +363,9 @@ function load_module_options() { function action_init_after() { foreach ( $this->modules as $mod_name => $mod_data ) { - if ( isset( $this->modules->$mod_name->options->post_types ) ) + if ( isset( $this->modules->$mod_name->options->post_types ) ) { $this->modules->$mod_name->options->post_types = $this->helpers->clean_post_type_options( $this->modules->$mod_name->options->post_types, $mod_data->post_type_support ); + } $this->$mod_name->module = $this->modules->$mod_name; } @@ -372,11 +382,12 @@ function get_module_by( $key, $value ) { foreach ( $this->modules as $mod_name => $mod_data ) { if ( $key == 'name' && $value == $mod_name ) { - $module = $this->modules->$mod_name; + $module = $this->modules->$mod_name; } else { - foreach( $mod_data as $mod_data_key => $mod_data_value ) { - if ( $mod_data_key == $key && $mod_data_value == $value ) + foreach ( $mod_data as $mod_data_key => $mod_data_value ) { + if ( $mod_data_key == $key && $mod_data_value == $value ) { $module = $this->modules->$mod_name; + } } } } @@ -388,15 +399,16 @@ function get_module_by( $key, $value ) { */ function update_module_option( $mod_name, $key, $value ) { $this->modules->$mod_name->options->$key = $value; - $this->$mod_name->module = $this->modules->$mod_name; + $this->$mod_name->module = $this->modules->$mod_name; return update_option( $this->options_group . $mod_name . '_options', $this->modules->$mod_name->options ); } function update_all_module_options( $mod_name, $new_options ) { - if ( is_array( $new_options ) ) - $new_options = (object)$new_options; + if ( is_array( $new_options ) ) { + $new_options = (object) $new_options; + } $this->modules->$mod_name->options = $new_options; - $this->$mod_name->module = $this->modules->$mod_name; + $this->$mod_name->module = $this->modules->$mod_name; return update_option( $this->options_group . $mod_name . '_options', $this->modules->$mod_name->options ); } @@ -410,17 +422,17 @@ function register_scripts_and_styles() { wp_register_style( 'jquery-listfilterizer', EDIT_FLOW_URL . 'common/css/jquery.listfilterizer.css', false, EDIT_FLOW_VERSION, 'all' ); - wp_localize_script( 'jquery-listfilterizer', - '__i18n_jquery_filterizer', - array( - 'all' => esc_html__( 'All', 'edit-flow' ), - 'selected' => esc_html__( 'Selected', 'edit-flow' ), - ) ); + wp_localize_script( + 'jquery-listfilterizer', + '__i18n_jquery_filterizer', + array( + 'all' => esc_html__( 'All', 'edit-flow' ), + 'selected' => esc_html__( 'Selected', 'edit-flow' ), + ) + ); wp_register_script( 'jquery-quicksearch', EDIT_FLOW_URL . 'common/js/jquery.quicksearch.js', array( 'jquery' ), EDIT_FLOW_VERSION, true ); - } - } function EditFlow() {