diff --git a/.github/workflows/php-tests.yml b/.github/workflows/php-tests.yml index dc91c783..ac321ecc 100644 --- a/.github/workflows/php-tests.yml +++ b/.github/workflows/php-tests.yml @@ -44,15 +44,14 @@ jobs: with: composer-options: --prefer-dist --no-progress + - name: Run PHPCS + run: composer run cs + - name: Setup wp-env run: wp-env start env: WP_ENV_CORE: WordPress/WordPress#${{ matrix.wp }} - # Commented out until we finish linting all the files - # - name: Run PHPCS diff tests - # run: bash bin/phpcs-diff.sh - - name: Run PHPUnit tests (single site) run: composer integration diff --git a/modules/custom-status/custom-status.php b/modules/custom-status/custom-status.php index f8ec5739..deaef06f 100644 --- a/modules/custom-status/custom-status.php +++ b/modules/custom-status/custom-status.php @@ -15,7 +15,7 @@ class EF_Custom_Status extends EF_Module { public $module; - private $custom_statuses_cache = array(); + private $custom_statuses_cache = []; // This is taxonomy name used to store all our custom statuses // phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase @@ -28,41 +28,41 @@ public function __construct() { $this->module_url = $this->get_module_url( __FILE__ ); // Register the module with Edit Flow - $args = array( - 'title' => __( 'Custom Statuses', 'edit-flow' ), - 'short_description' => __( 'Create custom post statuses to define the stages of your workflow.', 'edit-flow' ), - 'extended_description' => __( 'Create your own post statuses to add structure your publishing workflow. You can change existing or add new ones anytime, and drag and drop to change their order.', 'edit-flow' ), - 'module_url' => $this->module_url, - 'img_url' => $this->module_url . 'lib/custom_status_s128.png', - 'slug' => 'custom-status', - 'default_options' => array( - 'enabled' => 'on', - 'default_status' => 'pitch', + $args = [ + 'title' => __( 'Custom Statuses', 'edit-flow' ), + 'short_description' => __( 'Create custom post statuses to define the stages of your workflow.', 'edit-flow' ), + 'extended_description' => __( 'Create your own post statuses to add structure your publishing workflow. You can change existing or add new ones anytime, and drag and drop to change their order.', 'edit-flow' ), + 'module_url' => $this->module_url, + 'img_url' => $this->module_url . 'lib/custom_status_s128.png', + 'slug' => 'custom-status', + 'default_options' => [ + 'enabled' => 'on', + 'default_status' => 'pitch', 'always_show_dropdown' => 'off', - 'post_types' => array( + 'post_types' => [ 'post' => 'on', 'page' => 'on', - ), - ), - 'post_type_support' => 'ef_custom_statuses', // This has been plural in all of our docs - 'configure_page_cb' => 'print_configure_view', - 'configure_link_text' => __( 'Edit Statuses', 'edit-flow' ), - 'messages' => array( - 'status-added' => __( 'Post status created.', 'edit-flow' ), - 'status-missing' => __( "Post status doesn't exist.", 'edit-flow' ), - 'default-status-changed' => __( 'Default post status has been changed.', 'edit-flow' ), - 'term-updated' => __( 'Post status updated.', 'edit-flow' ), - 'status-deleted' => __( 'Post status deleted.', 'edit-flow' ), + ], + ], + 'post_type_support' => 'ef_custom_statuses', // This has been plural in all of our docs + 'configure_page_cb' => 'print_configure_view', + 'configure_link_text' => __( 'Edit Statuses', 'edit-flow' ), + 'messages' => [ + 'status-added' => __( 'Post status created.', 'edit-flow' ), + 'status-missing' => __( "Post status doesn't exist.", 'edit-flow' ), + 'default-status-changed' => __( 'Default post status has been changed.', 'edit-flow' ), + 'term-updated' => __( 'Post status updated.', 'edit-flow' ), + 'status-deleted' => __( 'Post status deleted.', 'edit-flow' ), 'status-position-updated' => __( 'Status order updated.', 'edit-flow' ), - ), - 'autoload' => false, - 'settings_help_tab' => array( - 'id' => 'ef-custom-status-overview', - 'title' => __( 'Overview', 'edit-flow' ), + ], + 'autoload' => false, + 'settings_help_tab' => [ + 'id' => 'ef-custom-status-overview', + 'title' => __( 'Overview', 'edit-flow' ), 'content' => __( '
Edit Flow’s custom statuses allow you to define the most important stages of your editorial workflow. Out of the box, WordPress only offers “Draft” and “Pending Review” as post states. With custom statuses, you can create your own post states like “In Progress”, “Pitch”, or “Waiting for Edit” and keep or delete the originals. You can also drag and drop statuses to set the best order for your workflow.
Custom statuses are fully integrated into the rest of Edit Flow and the WordPress admin. On the calendar and story budget, you can filter your view to see only posts of a specific post state. Furthermore, email notifications can be sent to a specific group of users when a post changes state.
', 'edit-flow' ), - ), + ], 'settings_help_sidebar' => __( 'For more information:
', 'edit-flow' ), - ); + ]; $this->module = EditFlow()->register_module( 'custom_status', $args ); } @@ -76,50 +76,50 @@ public function init() { $this->register_custom_statuses(); // Register our settings - add_action( 'admin_init', array( $this, 'register_settings' ) ); + add_action( 'admin_init', [ $this, 'register_settings' ] ); if ( ! $this->disable_custom_statuses_for_post_type() ) { // Load CSS and JS resources that we probably need in the admin page - add_action( 'admin_enqueue_scripts', array( $this, 'action_admin_enqueue_scripts' ) ); + add_action( 'admin_enqueue_scripts', [ $this, 'action_admin_enqueue_scripts' ] ); // Assets for block editor UI. - add_action( 'enqueue_block_editor_assets', array( $this, 'load_scripts_for_block_editor' ) ); + add_action( 'enqueue_block_editor_assets', [ $this, 'load_scripts_for_block_editor' ] ); // Assets for iframed block editor and editor UI. - add_action( 'enqueue_block_editor_assets', array( $this, 'load_styles_for_block_editor' ) ); + add_action( 'enqueue_block_editor_assets', [ $this, 'load_styles_for_block_editor' ] ); } - add_action( 'admin_notices', array( $this, 'no_js_notice' ) ); - add_action( 'admin_print_scripts', array( $this, 'post_admin_header' ) ); + add_action( 'admin_notices', [ $this, 'no_js_notice' ] ); + add_action( 'admin_print_scripts', [ $this, 'post_admin_header' ] ); // Add custom statuses to the post states. - add_filter( 'display_post_states', array( $this, 'add_status_to_post_states' ), 10, 2 ); + add_filter( 'display_post_states', [ $this, 'add_status_to_post_states' ], 10, 2 ); // Methods for handling the actions of creating, making default, and deleting post stati - add_action( 'admin_init', array( $this, 'handle_add_custom_status' ) ); - add_action( 'admin_init', array( $this, 'handle_edit_custom_status' ) ); - add_action( 'admin_init', array( $this, 'handle_make_default_custom_status' ) ); - add_action( 'admin_init', array( $this, 'handle_delete_custom_status' ) ); - add_action( 'wp_ajax_update_status_positions', array( $this, 'handle_ajax_update_status_positions' ) ); - add_action( 'wp_ajax_inline_save_status', array( $this, 'ajax_inline_save_status' ) ); + add_action( 'admin_init', [ $this, 'handle_add_custom_status' ] ); + add_action( 'admin_init', [ $this, 'handle_edit_custom_status' ] ); + add_action( 'admin_init', [ $this, 'handle_make_default_custom_status' ] ); + add_action( 'admin_init', [ $this, 'handle_delete_custom_status' ] ); + add_action( 'wp_ajax_update_status_positions', [ $this, 'handle_ajax_update_status_positions' ] ); + add_action( 'wp_ajax_inline_save_status', [ $this, 'ajax_inline_save_status' ] ); // These seven-ish methods are hacks for fixing bugs in WordPress core - add_action( 'admin_init', array( $this, 'check_timestamp_on_publish' ) ); - add_filter( 'wp_insert_post_data', array( $this, 'fix_custom_status_timestamp' ), 10, 2 ); - add_filter( 'wp_insert_post_data', array( $this, 'maybe_keep_post_name_empty' ), 10, 2 ); - add_filter( 'pre_wp_unique_post_slug', array( $this, 'fix_unique_post_slug' ), 10, 6 ); - add_filter( 'preview_post_link', array( $this, 'fix_preview_link_part_one' ) ); - add_filter( 'post_link', array( $this, 'fix_preview_link_part_two' ), 10, 3 ); - add_filter( 'page_link', array( $this, 'fix_preview_link_part_two' ), 10, 3 ); - add_filter( 'post_type_link', array( $this, 'fix_preview_link_part_two' ), 10, 3 ); - add_filter( 'preview_post_link', array( $this, 'fix_preview_link_part_three' ), 11, 2 ); - add_filter( 'get_sample_permalink', array( $this, 'fix_get_sample_permalink' ), 10, 5 ); - add_filter( 'get_sample_permalink_html', array( $this, 'fix_get_sample_permalink_html' ), 10, 5 ); - add_filter( 'post_row_actions', array( $this, 'fix_post_row_actions' ), 10, 2 ); - add_filter( 'page_row_actions', array( $this, 'fix_post_row_actions' ), 10, 2 ); + add_action( 'admin_init', [ $this, 'check_timestamp_on_publish' ] ); + add_filter( 'wp_insert_post_data', [ $this, 'fix_custom_status_timestamp' ], 10, 2 ); + add_filter( 'wp_insert_post_data', [ $this, 'maybe_keep_post_name_empty' ], 10, 2 ); + add_filter( 'pre_wp_unique_post_slug', [ $this, 'fix_unique_post_slug' ], 10, 6 ); + add_filter( 'preview_post_link', [ $this, 'fix_preview_link_part_one' ] ); + add_filter( 'post_link', [ $this, 'fix_preview_link_part_two' ], 10, 3 ); + add_filter( 'page_link', [ $this, 'fix_preview_link_part_two' ], 10, 3 ); + add_filter( 'post_type_link', [ $this, 'fix_preview_link_part_two' ], 10, 3 ); + add_filter( 'preview_post_link', [ $this, 'fix_preview_link_part_three' ], 11, 2 ); + add_filter( 'get_sample_permalink', [ $this, 'fix_get_sample_permalink' ], 10, 5 ); + add_filter( 'get_sample_permalink_html', [ $this, 'fix_get_sample_permalink_html' ], 10, 5 ); + add_filter( 'post_row_actions', [ $this, 'fix_post_row_actions' ], 10, 2 ); + add_filter( 'page_row_actions', [ $this, 'fix_post_row_actions' ], 10, 2 ); // Pagination for custom post statuses when previewing posts - add_filter( 'wp_link_pages_link', array( $this, 'modify_preview_link_pagination_url' ), 10, 2 ); + add_filter( 'wp_link_pages_link', [ $this, 'modify_preview_link_pagination_url' ], 10, 2 ); } /** @@ -129,48 +129,48 @@ public function init() { */ public function install() { - $default_terms = array( - array( + $default_terms = [ + [ 'term' => __( 'Pitch', 'edit-flow' ), - 'args' => array( - 'slug' => 'pitch', + 'args' => [ + 'slug' => 'pitch', 'description' => __( 'Idea proposed; waiting for acceptance.', 'edit-flow' ), - 'position' => 1, - ), - ), - array( + 'position' => 1, + ], + ], + [ 'term' => __( 'Assigned', 'edit-flow' ), - 'args' => array( - 'slug' => 'assigned', + 'args' => [ + 'slug' => 'assigned', 'description' => __( 'Post idea assigned to writer.', 'edit-flow' ), - 'position' => 2, - ), - ), - array( + 'position' => 2, + ], + ], + [ 'term' => __( 'In Progress', 'edit-flow' ), - 'args' => array( - 'slug' => 'in-progress', + 'args' => [ + 'slug' => 'in-progress', 'description' => __( 'Writer is working on the post.', 'edit-flow' ), - 'position' => 3, - ), - ), - array( + 'position' => 3, + ], + ], + [ 'term' => __( 'Draft', 'edit-flow' ), - 'args' => array( - 'slug' => 'draft', + 'args' => [ + 'slug' => 'draft', 'description' => __( 'Post is a draft; not ready for review or publication.', 'edit-flow' ), - 'position' => 4, - ), - ), - array( + 'position' => 4, + ], + ], + [ 'term' => __( 'Pending Review' ), - 'args' => array( - 'slug' => 'pending', + 'args' => [ + 'slug' => 'pending', 'description' => __( 'Post needs to be reviewed by an editor.', 'edit-flow' ), - 'position' => 5, - ), - ), - ); + 'position' => 5, + ], + ], + ]; // Okay, now add the default statuses to the db if they don't already exist foreach ( $default_terms as $term ) { @@ -229,14 +229,14 @@ public function register_custom_statuses() { // Register new taxonomy so that we can store all our fancy new custom statuses (or is it stati?) if ( ! taxonomy_exists( self::taxonomy_key ) ) { - $args = array( - 'hierarchical' => false, + $args = [ + 'hierarchical' => false, 'update_count_callback' => '_update_post_term_count', - 'label' => false, - 'query_var' => false, - 'rewrite' => false, - 'show_ui' => false, - ); + 'label' => false, + 'query_var' => false, + 'rewrite' => false, + 'show_ui' => false, + ]; register_taxonomy( self::taxonomy_key, 'post', $args ); } @@ -254,12 +254,12 @@ public function register_custom_statuses() { // all post statuses for a post type appearing at the top // of manage posts if there is a post with the status foreach ( $custom_statuses as $status ) { - register_post_status( $status->slug, array( + register_post_status( $status->slug, [ 'label' => $status->name, 'protected' => true, '_builtin' => false, 'label_count' => _n_noop( "{$status->name} (%s)", "{$status->name} (%s)" ), - ) ); + ] ); } } } @@ -276,7 +276,7 @@ public function disable_custom_statuses_for_post_type( $post_type = null ) { global $pagenow; // Only allow deregistering on 'edit.php' and 'post.php' - if ( ! in_array( $pagenow, array( 'edit.php', 'post.php', 'post-new.php' ) ) ) { + if ( ! in_array( $pagenow, [ 'edit.php', 'post.php', 'post-new.php' ] ) ) { return false; } @@ -301,13 +301,17 @@ public function action_admin_enqueue_scripts() { // Load Javascript we need to use on the configuration views (jQuery Sortable and Quick Edit) if ( $this->is_whitelisted_settings_view( $this->module->name ) ) { wp_enqueue_script( 'jquery-ui-sortable' ); - wp_enqueue_script( 'edit-flow-custom-status-configure', $this->module_url . 'lib/custom-status-configure.js', array( 'jquery', 'jquery-ui-sortable', 'edit-flow-settings-js' ), EDIT_FLOW_VERSION, true ); + wp_enqueue_script( 'edit-flow-custom-status-configure', $this->module_url . 'lib/custom-status-configure.js', [ 'jquery', 'jquery-ui-sortable', 'edit-flow-settings-js' ], EDIT_FLOW_VERSION, true ); + + wp_localize_script( 'edit-flow-custom-status-configure', '__ef_localize_custom_status_configure', [ + 'delete_status_string' => __( 'Are you sure you want to delete the post status? All posts with this status will be assigned to the default status.', 'edit-flow' ), + ] ); } // Custom javascript to modify the post status dropdown where it shows up if ( $this->is_whitelisted_page() ) { - wp_enqueue_script( 'edit_flow-custom_status', $this->module_url . 'lib/custom-status.js', array( 'jquery', 'post' ), EDIT_FLOW_VERSION, true ); - wp_localize_script('edit_flow-custom_status', '__ef_localize_custom_status', array( + wp_enqueue_script( 'edit_flow-custom_status', $this->module_url . 'lib/custom-status.js', [ 'jquery', 'post' ], EDIT_FLOW_VERSION, true ); + wp_localize_script('edit_flow-custom_status', '__ef_localize_custom_status', [ 'no_change' => esc_html__( '— No Change —', 'edit-flow' ), 'published' => esc_html__( 'Published', 'edit-flow' ), 'save_as' => esc_html__( 'Save as', 'edit-flow' ), @@ -315,14 +319,14 @@ public function action_admin_enqueue_scripts() { 'edit' => esc_html__( 'Edit', 'edit-flow' ), 'ok' => esc_html__( 'OK', 'edit-flow' ), 'cancel' => esc_html__( 'Cancel', 'edit-flow' ), - )); + ] ); } } public function load_scripts_for_block_editor() { global $post; - wp_enqueue_script( 'edit-flow-block-custom-status-script', EDIT_FLOW_URL . 'dist/custom-status.build.js', array( 'wp-blocks', 'wp-element', 'wp-edit-post', 'wp-plugins', 'wp-components' ), EDIT_FLOW_VERSION ); + wp_enqueue_script( 'edit-flow-block-custom-status-script', EDIT_FLOW_URL . 'dist/custom-status.build.js', [ 'wp-blocks', 'wp-element', 'wp-edit-post', 'wp-plugins', 'wp-components' ], EDIT_FLOW_VERSION ); $custom_statuses = apply_filters( 'ef_custom_status_list', $this->get_custom_statuses(), $post ); @@ -375,7 +379,7 @@ public function is_whitelisted_page() { } // Only add the script to Edit Post and Edit Page pages -- don't want to bog down the rest of the admin with unnecessary javascript - return in_array( $pagenow, array( 'post.php', 'edit.php', 'post-new.php', 'page.php', 'edit-pages.php', 'page-new.php' ) ); + return in_array( $pagenow, [ 'post.php', 'edit.php', 'post-new.php', 'page.php', 'edit-pages.php', 'page-new.php' ] ); } /** @@ -399,7 +403,7 @@ public function post_admin_header() { $custom_statuses = $this->get_custom_statuses(); // $selected can be empty, but must be set because it's used as a JS variable - $selected = ''; + $selected = ''; $selected_name = ''; if ( ! empty( $post ) ) { @@ -422,32 +426,32 @@ public function post_admin_header() { $custom_statuses = apply_filters( 'ef_custom_status_list', $custom_statuses, $post ); // All right, we want to set up the JS var which contains all custom statuses - $all_statuses = array(); + $all_statuses = []; // The default statuses from WordPress - $all_statuses[] = array( - 'name' => __( 'Published', 'edit-flow' ), - 'slug' => 'publish', + $all_statuses[] = [ + 'name' => __( 'Published', 'edit-flow' ), + 'slug' => 'publish', 'description' => '', - ); - $all_statuses[] = array( - 'name' => __( 'Privately Published', 'edit-flow' ), - 'slug' => 'private', + ]; + $all_statuses[] = [ + 'name' => __( 'Privately Published', 'edit-flow' ), + 'slug' => 'private', 'description' => '', - ); - $all_statuses[] = array( - 'name' => __( 'Scheduled', 'edit-flow' ), - 'slug' => 'future', + ]; + $all_statuses[] = [ + 'name' => __( 'Scheduled', 'edit-flow' ), + 'slug' => 'future', 'description' => '', - ); + ]; // Load the custom statuses foreach ( $custom_statuses as $status ) { - $all_statuses[] = array( - 'name' => esc_js( $status->name ), - 'slug' => esc_js( $status->slug ), + $all_statuses[] = [ + 'name' => esc_js( $status->name ), + 'slug' => esc_js( $status->slug ), 'description' => esc_js( $status->description ), - ); + ]; } $always_show_dropdown = ( 'on' == $this->module->options->always_show_dropdown ) ? 1 : 0; @@ -487,17 +491,17 @@ public function post_admin_header() { * @param array|string $args Change the values of the inserted term * @return array|WP_Error $response The Term ID and Term Taxonomy ID */ - public function add_custom_status( $term, $args = array() ) { + public function add_custom_status( $term, $args = [] ) { $slug = ( ! empty( $args['slug'] ) ) ? $args['slug'] : sanitize_title( $term ); unset( $args['slug'] ); $encoded_description = $this->get_encoded_description( $args ); - $response = wp_insert_term( $term, self::taxonomy_key, array( - 'slug' => $slug, + $response = wp_insert_term( $term, self::taxonomy_key, [ + 'slug' => $slug, 'description' => $encoded_description, - ) ); + ] ); // Reset our internal object cache - $this->custom_statuses_cache = array(); + $this->custom_statuses_cache = []; return $response; } @@ -509,7 +513,7 @@ public function add_custom_status( $term, $args = array() ) { * @param array $args Any arguments to be updated * @return object $updated_status Newly updated status object */ - public function update_custom_status( $status_id, $args = array() ) { + public function update_custom_status( $status_id, $args = [] ) { global $edit_flow; $old_status = $this->get_custom_status_by( 'id', $status_id ); @@ -518,15 +522,15 @@ public function update_custom_status( $status_id, $args = array() ) { } // Reset our internal object cache - $this->custom_statuses_cache = array(); + $this->custom_statuses_cache = []; // Prevent user from changing draft name or slug if ( 'draft' === $old_status->slug - && ( - ( isset( $args['name'] ) && $args['name'] !== $old_status->name ) - || - ( isset( $args['slug'] ) && $args['slug'] !== $old_status->slug ) - ) ) { + && ( + ( isset( $args['name'] ) && $args['name'] !== $old_status->name ) + || + ( isset( $args['slug'] ) && $args['slug'] !== $old_status->slug ) + ) ) { return new WP_Error( 'invalid', __( 'Changing the name and slug of "Draft" is not allowed', 'edit-flow' ) ); } @@ -546,14 +550,14 @@ public function update_custom_status( $status_id, $args = array() ) { } } // We're encoding metadata that isn't supported by default in the term's description field - $args_to_encode = array(); + $args_to_encode = []; $args_to_encode['description'] = ( isset( $args['description'] ) ) ? $args['description'] : $old_status->description; - $args_to_encode['position'] = ( isset( $args['position'] ) ) ? $args['position'] : $old_status->position; - $encoded_description = $this->get_encoded_description( $args_to_encode ); - $args['description'] = $encoded_description; + $args_to_encode['position'] = ( isset( $args['position'] ) ) ? $args['position'] : $old_status->position; + $encoded_description = $this->get_encoded_description( $args_to_encode ); + $args['description'] = $encoded_description; $updated_status_array = wp_update_term( $status_id, self::taxonomy_key, $args ); - $updated_status = $this->get_custom_status_by( 'id', $updated_status_array['term_id'] ); + $updated_status = $this->get_custom_status_by( 'id', $updated_status_array['term_id'] ); return $updated_status; } @@ -564,7 +568,7 @@ public function update_custom_status( $status_id, $args = array() ) { * Partly a wrapper for the wp_delete_term function. * BUT, also reassigns posts that currently have the deleted status assigned. */ - public function delete_custom_status( $status_id, $args = array(), $reassign = '' ) { + public function delete_custom_status( $status_id, $args = [], $reassign = '' ) { global $edit_flow; // Reassign posts to alternate status @@ -576,7 +580,7 @@ public function delete_custom_status( $status_id, $args = array(), $reassign = ' } // Reset our internal object cache - $this->custom_statuses_cache = array(); + $this->custom_statuses_cache = []; if ( ! $this->is_restricted_status( $old_status ) && 'draft' !== $old_status ) { $default_status = $this->get_default_custom_status()->slug; @@ -606,7 +610,7 @@ public function delete_custom_status( $status_id, $args = array(), $reassign = ' * @param array $args * @return array $statuses All of the statuses */ - public function get_custom_statuses( $args = array() ) { + public function get_custom_statuses( $args = [] ) { global $wp_post_statuses; if ( $this->disable_custom_statuses_for_post_type() ) { @@ -620,18 +624,18 @@ public function get_custom_statuses( $args = array() ) { } // Handle if the requested taxonomy doesn't exist - $statuses = get_terms( array( + $statuses = get_terms( [ 'taxonomy' => self::taxonomy_key, 'hide_empty' => false, - )); + ]); if ( is_wp_error( $statuses ) || empty( $statuses ) ) { - $statuses = array(); + $statuses = []; } // Expand and order the statuses - $ordered_statuses = array(); - $hold_to_end = array(); + $ordered_statuses = []; + $hold_to_end = []; foreach ( $statuses as $key => $status ) { // Unencode and set all of our psuedo term meta because we need the position if it exists $unencoded_description = $this->get_unencoded_description( $status->description ); @@ -672,7 +676,7 @@ public function get_custom_statuses( $args = array() ) { */ public function get_custom_status_by( $field, $value ) { - if ( ! in_array( $field, array( 'id', 'slug', 'name' ) ) ) { + if ( ! in_array( $field, [ 'id', 'slug', 'name' ] ) ) { return false; } @@ -681,7 +685,7 @@ public function get_custom_status_by( $field, $value ) { } $custom_statuses = $this->get_custom_statuses(); - $custom_status = wp_filter_object_list( $custom_statuses, array( $field => $value ) ); + $custom_status = wp_filter_object_list( $custom_statuses, [ $field => $value ] ); if ( ! empty( $custom_status ) ) { return array_shift( $custom_status ); @@ -699,7 +703,7 @@ public function get_default_custom_status() { $default_status = $this->get_custom_status_by( 'slug', $this->module->options->default_status ); if ( ! $default_status ) { $custom_statuses = $this->get_custom_statuses(); - $default_status = array_shift( $custom_statuses ); + $default_status = array_shift( $custom_statuses ); } return $default_status; } @@ -718,7 +722,7 @@ public function reassign_post_status( $old_status, $new_status = '' ) { } // Make the database call - $result = $wpdb->update( $wpdb->posts, array( 'post_status' => $new_status ), array( 'post_status' => $old_status ), array( '%s' ) ); + $result = $wpdb->update( $wpdb->posts, [ 'post_status' => $new_status ], [ 'post_status' => $old_status ], [ '%s' ] ); } /** @@ -743,7 +747,7 @@ public function add_status_to_post_states( $post_states, $post ) { return $post_states; } - $statuses_to_ignore = array( 'future', 'trash', 'publish' ); + $statuses_to_ignore = [ 'future', 'trash', 'publish' ]; if ( in_array( $post_status->name, $statuses_to_ignore, true ) ) { // Let WP core handle these more gracefully. return $post_states; @@ -799,8 +803,8 @@ public function handle_add_custom_status() { } // Validate and sanitize the form data - $status_name = isset( $_POST['status_name'] ) ? sanitize_text_field( trim( $_POST['status_name'] ) ) : ''; - $status_slug = sanitize_title( $status_name ); + $status_name = isset( $_POST['status_name'] ) ? sanitize_text_field( trim( $_POST['status_name'] ) ) : ''; + $status_slug = sanitize_title( $status_name ); $status_description = isset( $_POST['status_description'] ) ? stripslashes( wp_filter_nohtml_kses( trim( $_POST['status_description'] ) ) ) : ''; /** @@ -808,7 +812,7 @@ public function handle_add_custom_status() { * - Name is required and can't conflict with an existing name or slug * - Description is optional */ - $_REQUEST['form-errors'] = array(); + $_REQUEST['form-errors'] = []; // Check if name field was filled in if ( empty( $status_name ) ) { $_REQUEST['form-errors']['name'] = __( 'Please enter a name for the status', 'edit-flow' ); @@ -838,17 +842,17 @@ public function handle_add_custom_status() { } // Try to add the status - $status_args = array( + $status_args = [ 'description' => $status_description, - 'slug' => $status_slug, - ); - $return = $this->add_custom_status( $status_name, $status_args ); + 'slug' => $status_slug, + ]; + $return = $this->add_custom_status( $status_name, $status_args ); if ( is_wp_error( $return ) ) { /* translators: %s: error message */ wp_die( esc_html( sprintf( __( 'Could not add status: %s', 'edit-flow' ), $return->get_error_message() ) ) ); } // Redirect if successful - $redirect_url = $this->get_link( array( 'message' => 'status-added' ) ); + $redirect_url = $this->get_link( [ 'message' => 'status-added' ] ); wp_redirect( $redirect_url ); exit; } @@ -877,7 +881,7 @@ public function handle_edit_custom_status() { wp_die( esc_html( $this->module->messages['status-missing'] ) ); } - $name = isset( $_POST['name'] ) ? sanitize_text_field( trim( $_POST['name'] ) ) : ''; + $name = isset( $_POST['name'] ) ? sanitize_text_field( trim( $_POST['name'] ) ) : ''; $description = isset( $_POST['description'] ) ? stripslashes( wp_filter_nohtml_kses( trim( $_POST['description'] ) ) ) : ''; /** @@ -887,7 +891,7 @@ public function handle_edit_custom_status() { * - 'name' is a required field and can't conflict with existing name or slug * - 'description' is optional */ - $_REQUEST['form-errors'] = array(); + $_REQUEST['form-errors'] = []; // Check if name field was filled in if ( empty( $name ) ) { $_REQUEST['form-errors']['name'] = __( 'Please enter a name for the status', 'edit-flow' ); @@ -923,17 +927,17 @@ public function handle_edit_custom_status() { } // Try to add the new post status - $args = array( - 'name' => $name, - 'slug' => sanitize_title( $name ), + $args = [ + 'name' => $name, + 'slug' => sanitize_title( $name ), 'description' => $description, - ); + ]; $return = $this->update_custom_status( $existing_status->term_id, $args ); if ( is_wp_error( $return ) ) { wp_die( esc_html__( 'Error updating post status.', 'edit-flow' ) ); } - $redirect_url = $this->get_link( array( 'message' => 'status-updated' ) ); + $redirect_url = $this->get_link( [ 'message' => 'status-updated' ] ); wp_redirect( $redirect_url ); exit; } @@ -963,11 +967,11 @@ public function handle_make_default_custom_status() { } $term_id = (int) $_GET['term-id']; - $term = $this->get_custom_status_by( 'id', $term_id ); + $term = $this->get_custom_status_by( 'id', $term_id ); if ( is_object( $term ) ) { $edit_flow->update_module_option( $this->module->name, 'default_status', $term->slug ); // @todo How do we want to handle users who click the link from "Add New Status" - $redirect_url = $this->get_link( array( 'message' => 'default-status-changed' ) ); + $redirect_url = $this->get_link( [ 'message' => 'default-status-changed' ] ); wp_redirect( $redirect_url ); exit; } else { @@ -1000,7 +1004,7 @@ public function handle_delete_custom_status() { // Check to make sure the status isn't already deleted $term_id = (int) $_GET['term-id']; - $term = $this->get_custom_status_by( 'id', $term_id ); + $term = $this->get_custom_status_by( 'id', $term_id ); if ( ! $term ) { wp_die( esc_html__( 'Status does not exist.', 'edit-flow' ) ); } @@ -1015,7 +1019,7 @@ public function handle_delete_custom_status() { wp_die( esc_html( __( 'Could not delete the status: ', 'edit-flow' ) . $return->get_error_message() ) ); } - $redirect_url = $this->get_link( array( 'message' => 'status-deleted' ) ); + $redirect_url = $this->get_link( [ 'message' => 'status-deleted' ] ); wp_redirect( $redirect_url ); exit; } @@ -1028,7 +1032,7 @@ public function handle_delete_custom_status() { * @param array $args (optional) Action and any query args to add to the URL * @return string $link Direct link to complete the action */ - public function get_link( $args = array() ) { + public function get_link( $args = [] ) { if ( ! isset( $args['action'] ) ) { $args['action'] = ''; } @@ -1070,9 +1074,9 @@ public function handle_ajax_update_status_positions() { foreach ( $_POST['status_positions'] as $position => $term_id ) { // Have to add 1 to the position because the index started with zero - $args = array( + $args = [ 'position' => (int) $position + 1, - ); + ]; $return = $this->update_custom_status( (int) $term_id, $args ); // @todo check that this was a valid return } @@ -1095,9 +1099,9 @@ public function ajax_inline_save_status() { die( esc_html( $this->module->messages['invalid-permissions'] ) ); } - $term_id = isset( $_POST['status_id'] ) ? (int) $_POST['status_id'] : 0; - $status_name = isset( $_POST['name'] ) ? sanitize_text_field( trim( $_POST['name'] ) ) : ''; - $status_slug = isset( $_POST['name'] ) ? sanitize_title( trim( $_POST['name'] ) ) : ''; + $term_id = isset( $_POST['status_id'] ) ? (int) $_POST['status_id'] : 0; + $status_name = isset( $_POST['name'] ) ? sanitize_text_field( trim( $_POST['name'] ) ) : ''; + $status_slug = isset( $_POST['name'] ) ? sanitize_title( trim( $_POST['name'] ) ) : ''; $status_description = isset( $_POST['description'] ) ? stripslashes( wp_filter_nohtml_kses( trim( $_POST['description'] ) ) ) : ''; // Check if name field was filled in @@ -1138,11 +1142,11 @@ public function ajax_inline_save_status() { } // get status_name & status_description - $args = array( - 'name' => $status_name, + $args = [ + 'name' => $status_name, 'description' => $status_description, - 'slug' => $status_slug, - ); + 'slug' => $status_slug, + ]; $return = $this->update_custom_status( $term_id, $args ); if ( ! is_wp_error( $return ) ) { set_current_screen( 'edit-custom-status' ); @@ -1166,8 +1170,8 @@ public function ajax_inline_save_status() { public function register_settings() { add_settings_section( $this->module->options_group_name . '_general', false, '__return_false', $this->module->options_group_name ); - add_settings_field( 'post_types', __( 'Use on these post types:', 'edit-flow' ), array( $this, 'settings_post_types_option' ), $this->module->options_group_name, $this->module->options_group_name . '_general' ); - add_settings_field( 'always_show_dropdown', __( 'Always show dropdown:', 'edit-flow' ), array( $this, 'settings_always_show_dropdown_option' ), $this->module->options_group_name, $this->module->options_group_name . '_general' ); + add_settings_field( 'post_types', __( 'Use on these post types:', 'edit-flow' ), [ $this, 'settings_post_types_option' ], $this->module->options_group_name, $this->module->options_group_name . '_general' ); + add_settings_field( 'always_show_dropdown', __( 'Always show dropdown:', 'edit-flow' ), [ $this, 'settings_always_show_dropdown_option' ], $this->module->options_group_name, $this->module->options_group_name . '_general' ); } /** @@ -1186,10 +1190,10 @@ public function settings_post_types_option() { * @since 0.7 */ public function settings_always_show_dropdown_option() { - $options = array( + $options = [ 'off' => __( 'Disabled', 'edit-flow' ), - 'on' => __( 'Enabled', 'edit-flow' ), - ); + 'on' => __( 'Enabled', 'edit-flow' ), + ]; echo '