Support » Plugin: Extended Post Status » Fix for custom statuses by other plugins

  • Resolved I. Kancijan

    (@ikancijan)


    I had a compatibility issue with this plugin and came up with this simple fix.

    …/extended-post-status/admin/class-extended-post-status-admin.php

    /**
    	 * Override the post query
    	 *
    	 * @param type $query
    	 * @return type
    	 * @since    1.0.1
    	 */
    	public static function override_admin_post_list($query)
    	{
    		$statuses = self::get_status();
    		/* Check if query has no further params */
    		if (
    			(array_key_exists('post_status', $query->query) && empty($query->query['post_status']))
    		) {
    			$statuses_show_in_admin_all_list = self::get_all_post_statuses();
    			foreach ($statuses as $status) {
    				$term_meta = get_option("taxonomy_term_$status->term_id");
    				if (!in_array($status->slug, $statuses_show_in_admin_all_list)) {
    					if ($term_meta['show_in_admin_all_list'] == 1) {
    						$statuses_show_in_admin_all_list[] = $status->slug;
    					}
    				} else {
    					if ($term_meta['show_in_admin_all_list'] != 1) {
    						if (($key = array_search($status->slug, $statuses_show_in_admin_all_list)) !== false) {
    							unset($statuses_show_in_admin_all_list[$key]);
    						}
    					}
    				}
    			}
    			
    			set_query_var('post_status', array_values($statuses_show_in_admin_all_list));
    			return;
    		}
    		return;
    	}
    
    	/**
    	 * Get all available post statuses
    	 *
    	 * @return array
    	 */
    	private static function get_all_post_statuses()
    	{
    		global $wpdb;
    
    		$query = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.post_status as post_status FROM wp_posts WHERE post_status NOT IN ('auto-draft', 'trash', 'inherit')");
    
    		return wp_list_pluck($query, 'post_status');
    	}
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.