Skip to content

Instantly share code, notes, and snippets.

@jesgs
Last active December 20, 2015 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesgs/6ab0a7365b4eb1417f5c to your computer and use it in GitHub Desktop.
Save jesgs/6ab0a7365b4eb1417f5c to your computer and use it in GitHub Desktop.
<?php
/**
* WordPress Sandbox
*
* @package WordPress_Sandbox
* @subpackage current-screen-test
* @author Jess Green <jgreen@psy-dreamer.com>
* @version $Id$
*/
add_action('current_screen', '_current_screen_test');
function _current_screen_test()
{
}
add_filter('views_edit-post', '_edit_posts_screen');
/**
* Add our tab
*
* @param array $views
* @return array
*/
function _edit_posts_screen($views)
{
$views['archive'] = "<a href='edit.php?post_status=archived'>Archive <span class='count'>(0)</span></a>";
return $views;
}
/**
* Adds new variables to query var list.
* Only use if you need to add new query vars
*
* @param array $vars Current list of query vars
* @return array
*/
//add_filter('query_vars','_add_query_vars');
//function _add_query_vars($vars)
//{
// array_push($vars, 'archive-category');
// return $vars;
//}
add_filter('pre_get_posts', '_create_editposts_filter');
/**
* Create a filter specifically for the post listing screen
*
* @param WP_Query $query
* @return WP_Query
*/
function _create_editposts_filter(WP_Query $query)
{
$screen = get_current_screen();
if (isset($screen->id) && $screen->id == 'edit-post') {
$query = apply_filters('pre_get_posts-edit-post', $query);
}
return $query;
}
add_filter('pre_get_posts-edit-post', '_pre_get_posts_edit_post');
function _pre_get_posts_edit_post(WP_Query $query)
{
if (isset($_REQUEST['post_status']) && $_REQUEST['post_status'] == 'archived') {
$query->set('post_status', 'archived');
// var_dump($query); die();
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment