Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '5251b513e6d79d6db665');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'ce9fb537cd9123eea4e3');
2 changes: 1 addition & 1 deletion dist/modules/custom-status/custom-status-configure.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '4067d0acecbb75577473');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => 'e5480c7ff4439f7dc325');

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 6 additions & 31 deletions modules/custom-status/custom-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class CustomStatus {
const METADATA_REQ_USER_IDS_KEY = 'required_user_ids';
const METADATA_REQ_USERS_KEY = 'required_users';

private static $custom_statuses_cache = [];

public static function init(): void {
// Register the taxonomy we use with WordPress core, and ensure it's registered after editorial metadata
add_action( 'init', [ __CLASS__, 'register_custom_status_taxonomy' ] );
Expand Down Expand Up @@ -210,7 +208,7 @@ public static function action_admin_enqueue_scripts(): void {
wp_enqueue_style( 'vip-workflow-custom-status-styles', VIP_WORKFLOW_URL . 'dist/modules/custom-status/custom-status-configure.css', [ 'wp-components' ], $asset_file['version'] );

wp_localize_script( 'vip-workflow-custom-status-configure', 'VW_CUSTOM_STATUS_CONFIGURE', [
'custom_statuses' => self::modify_custom_statuses_with_editorial_metadata(),
'custom_statuses' => self::get_custom_statuses(),
'editorial_metadatas' => EditorialMetadata::get_editorial_metadata_terms(),
'url_edit_status' => CustomStatusEndpoint::get_crud_url(),
'url_reorder_status' => CustomStatusEndpoint::get_reorder_url(),
Expand Down Expand Up @@ -525,7 +523,7 @@ public static function add_custom_status( array $args ): WP_Term|WP_Error {

// Check to make sure the slug is not restricted
if ( self::is_restricted_status( $term_to_save['slug'] ) ) {
return new WP_Error( 'invalid', 'Status name is restricted. Please chose another name.' );
return new WP_Error( 'invalid', 'Status name is restricted. Please chose another name.', array( 'status' => 400 ) );
}

if ( ! isset( $args['position'] ) ) {
Expand All @@ -547,9 +545,6 @@ public static function add_custom_status( array $args ): WP_Term|WP_Error {
return $inserted_term;
}

// Reset our internal object cache
self::$custom_statuses_cache = [];

$term_id = $inserted_term['term_id'];

$position = $args[ self::METADATA_POSITION_KEY ];
Expand Down Expand Up @@ -590,20 +585,17 @@ public static function update_custom_status( int $status_id, array $args = [] ):
if ( is_wp_error( $old_status ) ) {
return $old_status;
} else if ( ! $old_status ) {
return new WP_Error( 'invalid', __( "Custom status doesn't exist.", 'vip-workflow' ) );
return new WP_Error( 'invalid', __( "Custom status doesn't exist.", 'vip-workflow' ), array( 'status' => 400 ) );
}

// Reset our internal object cache
self::$custom_statuses_cache = [];

// If the name was changed, we need to change the slug unless its banned from slug updates
if ( isset( $args['name'] ) && $args['name'] !== $old_status->name && ! self::is_status_banned_from_slug_changes( $old_status->slug ) ) {
$args['slug'] = sanitize_title( $args['name'] );
}

// Check to make sure the slug is not restricted
if ( isset( $args['slug'] ) && self::is_restricted_status( $args['slug'] ) ) {
return new WP_Error( 'invalid', 'Status name is restricted. Please chose another name.' );
return new WP_Error( 'invalid', 'Status name is restricted. Please chose another name.', array( 'status' => 400 ) );
}

// If the status is banned from updates, we shouldn't allow the user to change the slug
Expand Down Expand Up @@ -652,9 +644,6 @@ public static function update_custom_status( int $status_id, array $args = [] ):

$updated_term = wp_update_term( $status_id, self::TAXONOMY_KEY, $term_fields_to_update );

// Reset status cache again, as reassign_post_status() will recache prior statuses
self::$custom_statuses_cache = [];

if ( is_wp_error( $updated_term ) ) {
return $updated_term;
}
Expand All @@ -676,19 +665,16 @@ public static function delete_custom_status( int $status_id ): bool|WP_Error {
if ( is_wp_error( $old_status ) ) {
return $old_status;
} else if ( ! $old_status ) {
return new WP_Error( 'invalid', __( "Custom status doesn't exist.", 'vip-workflow' ) );
return new WP_Error( 'invalid', __( "Custom status doesn't exist.", 'vip-workflow' ), array( 'status' => 400 ) );
}

$old_status_slug = $old_status->slug;

if ( self::is_restricted_status( $old_status_slug ) || self::is_status_banned_from_slug_changes( $old_status_slug ) ) {
// translators: %s: Post status, like "Draft"
return new WP_Error( 'restricted', sprintf( __( 'Restricted status (%s) cannot be deleted.', 'vip-workflow' ), $old_status->name ) );
return new WP_Error( 'restricted', sprintf( __( 'Restricted status (%s) cannot be deleted.', 'vip-workflow' ), $old_status->name ), array( 'status' => 400 ) );
}

// Reset our internal object cache
self::$custom_statuses_cache = [];

// Get the new status to reassign posts to, which would be the first custom status.
// In the event that the first custom status is being deleted, we'll reassign to the second custom status.
// Since draft and pending review cannot be deleted, we don't need to worry about ever getting index out of bounds.
Expand All @@ -712,9 +698,6 @@ public static function delete_custom_status( int $status_id ): bool|WP_Error {
return new WP_Error( 'invalid', __( 'Unable to delete custom status.', 'vip-workflow' ) );
}

// Reset status cache again, as reassign_post_status() will recache prior statuses
self::$custom_statuses_cache = [];

// Re-order the positions after deletion
$custom_statuses = self::get_custom_statuses();

Expand All @@ -741,11 +724,6 @@ public static function get_custom_statuses(): array {
return self::get_core_statuses();
}

// Internal object cache for repeat requests
if ( ! empty( self::$custom_statuses_cache ) ) {
return self::$custom_statuses_cache;
}

$statuses = get_terms( [
'taxonomy' => self::TAXONOMY_KEY,
'hide_empty' => false,
Expand All @@ -766,9 +744,6 @@ public static function get_custom_statuses(): array {
return $status;
}, $statuses );

// Set the internal object cache
self::$custom_statuses_cache = $statuses;

return $statuses;
}

Expand Down
Loading