post_status = $post_status; $this->post_types = $post_types; $this->action_label = isset( $args['label'] ) ? $args['label'] : $post_status; $this->applied_label = isset( $args['applied_label'] ) ? $args['applied_label'] : $this->action_label; $this->args = $args; // Removes the arguments that do not belong to register_post_type unset( $this->args['applied_label'] ); if( ! isset( $this->args['label_count'] ) ) { $this->args['label_count'] = _n_noop( $this->applied_label . ' (%s)', $this->applied_label . ' (%s)', 'avalon-b' ); } // Register post status add_action( 'init', array( $this, 'register_post_status' ) ); // Add meta tags to pass args add_action( 'admin_head', array( $this, 'meta_tags' ) ); // Load scripts add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) ); } /** * Register the Custom Post Status with Wordpress ;) * * @param string $post_status The name of Custom Post Status. * @param array $args Array of arguments to pass register_post_status() **/ public function register_post_status() { register_post_status( $this->post_status, $this->args ); } /** * Add meta tags to JS */ public function meta_tags() { $screen = get_current_screen(); if( ! in_array( $screen->post_type, $this->post_types ) ) { return; } $args = array( 'postTypes' => $this->post_types, 'appliedLabel' => $this->applied_label, 'slug' => $this->post_status, ); if( $screen->base === 'post' ) { global $post; if( is_object( $post ) && $post->post_status === $this->post_status ) { $args['select'] = true; } } printf( '', esc_attr( json_encode( $args ) ) ); } /** * Load post status scripts and inject JS vars */ public function scripts() { // Load admin JS wp_enqueue_script( 'odin-custom-status', get_template_directory_uri() . '/core/assets/js/admin-custom-status.js', array( 'jquery' ), null, true ); } }