__( 'Archived', 'archived-post-status' ), 'public' => apply_filters( 'aps_status_arg_public', false ), 'exclude_from_search' => apply_filters( 'aps_status_arg_exclude_from_search', true ), 'show_in_admin_all_list' => apply_filters( 'aps_status_arg_show_in_admin_all_list', true ), 'show_in_admin_status_list' => apply_filters( 'aps_status_arg_show_in_admin_status_list', true ), 'label_count' => _n_noop( 'Archived (%s)', 'Archived (%s)', 'archived-post-status' ), ); register_post_status( 'archive', $args ); } add_action( 'init', 'aps_register_archive_post_status' ); /** * Returns TRUE if in the WP Admin, otherwise FALSE * * @filter aps_status_arg_public * @filter aps_status_arg_show_in_admin_all_list * @filter aps_status_arg_show_in_admin_status_list * * @return bool */ function aps_is_admin() { return is_admin(); } add_filter( 'aps_status_arg_public', 'aps_is_admin' ); add_filter( 'aps_status_arg_show_in_admin_all_list', 'aps_is_admin' ); add_filter( 'aps_status_arg_show_in_admin_status_list', 'aps_is_admin' ); /** * Returns TRUE if on the frontend, otherwise FALSE * * @filter aps_status_arg_exclude_from_search * * @return bool */ function aps_is_frontend() { return ! is_admin(); } add_filter( 'aps_status_arg_exclude_from_search', 'aps_is_frontend' ); /** * Modify the DOM on post screens * * @action admin_footer-post.php * * @return void */ function aps_post_screen_js() { global $post; $excluded = apply_filters( 'aps_excluded_post_types', array( 'attachment' ) ); if ( in_array( $post->post_type, $excluded ) ) { return; } if ( 'draft' !== $post->post_status && 'pending' !== $post->post_status ) { ?> post_status ) || 'archive' !== $post->post_status ) { return; } // Redirect to list table after saving as Archived if ( 'edit' === $action && 1 === $message ) { wp_safe_redirect( add_query_arg( array( 'post_type' => $post->post_type ), admin_url( 'edit.php' ) ), 302 ); exit; } wp_die( __( "You can't edit this item because it has been Archived. Please change the post status and try again.", 'archived-post-status' ), __( 'WordPress › Error' ) ); } add_action( 'load-post.php', 'aps_load_post_screen' ); /** * Display custom post state text next to post titles that are Archived * * @filter display_post_states * * @param array $post_states An array of post display states * @param object $post WP_Post * * @return array */ function aps_display_post_states( $post_states, $post ) { if ( 'archive' !== $post->post_status || 'archive' === get_query_var( 'post_status' ) ) { return $post_states; } return array( __( 'Archived', 'archived-post-status' ) ); } add_filter( 'display_post_states', 'aps_display_post_states', 10, 2 );