Skip to content

Instantly share code, notes, and snippets.

@technosailor
Created December 15, 2013 18:45
Show Gist options
  • Save technosailor/7976564 to your computer and use it in GitHub Desktop.
Save technosailor/7976564 to your computer and use it in GitHub Desktop.
Saves default WordPress edit page filters as usermeta
<?php
/*
Plugin Name: AB Edit Filter Save
Version: 0.1
Author: Aaron Brazell
Author URI: http://technosailor.com
Description: Saves default WordPress edit page filters as usermeta
License: GPLv2
*/
class AB_Filter_Save {
public function __construct() {
if( !is_admin() )
return false;
if( !current_user_can( 'edit_posts' ) )
return false;
if( get_current_screen()->parent_base != 'edit' )
return false;
$this->hooks();
}
public function hooks() {
add_action( 'admin_init', array( $this, 'save_search' ) );
add_action( 'admin_init', array( $this, 'edit_page_filter' ) );
}
public function save_search() {
global $current_user;
$saved = array();
if( isset( $_GET['m'] ) )
$saved['m'] = $_GET['m'];
if( isset( $_GET['cat'] ) )
$saved['cat'] = $_GET['m'];
update_user_meta( $current_user->ID, '_saved_search_edit', $saved );
}
public function edit_page_filter() {
global $current_user;
$url = admin_url( 'edit.php?s' );
if( $gets = get_user_meta( $current_user->ID, '_saved_search_edit', true ) ) {
if( isset( $gets['m'] ) )
$url .= '&m=' . $gets['m'];
if( isset( $gets['cat'] ) )
$url .= '&cat=' . $gets['cat'];
wp_safe_redirect( esc_url( $url ) );
exit;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment