Changeset 1462179
- Timestamp:
- 07/28/2016 10:55:01 AM (10 years ago)
- Location:
- author-filters
- Files:
-
- 15 added
- 2 edited
-
tags/1.0.0 (added)
-
tags/1.0.0/author-filters.php (added)
-
tags/1.0.0/index.html (added)
-
tags/1.0.0/readme.txt (added)
-
tags/1.0.0/screenshot-1.png (added)
-
tags/1.0.1 (added)
-
tags/1.0.1/author-filters.php (added)
-
tags/1.0.1/index.html (added)
-
tags/1.0.1/readme.txt (added)
-
tags/1.0.1/screenshot-1.png (added)
-
tags/2.0.0 (added)
-
tags/2.0.0/author-filters.php (added)
-
tags/2.0.0/index.html (added)
-
tags/2.0.0/readme.txt (added)
-
tags/2.0.0/screenshot-1.png (added)
-
trunk/author-filters.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
author-filters/trunk/author-filters.php
r1444844 r1462179 2 2 /** 3 3 * Plugin Name: Author Filters 4 * Version: 1.0.15 * Description: Author filters plugin integrates an author filter drop down to sort listing on post, page, custom post type in admin.4 * Version: 2.0.0 5 * Description: Author filters plugin integrates an author filter drop down to sort listing with respect to an author on post, page, custom post type in administration. 6 6 * Author: Clarion Technologies 7 7 * Author URI: http://www.clariontechnologies.co.in … … 11 11 */ 12 12 13 defined('ABSPATH') or die('Direct Access Restricted!'); 13 defined('ABSPATH') or die('Direct Access Restricted!'); // Check point to restrict direct access to the file 14 15 /* 16 Class: author_filters 17 */ 14 18 15 function author_filters_install() { 19 class author_filters{ 20 21 /* 22 Function: author_filters_install 23 Description: 24 * function is attached to plugin activation hook, 25 * performs pre-configuration activities 26 */ 16 27 17 // Clear/Flush the rewrite rules after the post type has been registered 18 flush_rewrite_rules(); 19 } 28 public static function author_filters_install() { 20 29 21 register_activation_hook(__FILE__, 'author_filters_install'); 22 23 function author_filters_deactivation() { 24 25 // Clear/Flush the permalinks to remove our post type's rules 26 flush_rewrite_rules(); 27 } 28 29 register_deactivation_hook(__FILE__, 'author_filters_deactivation'); 30 31 function author_filters_post_types() { 32 33 $args = array( 34 'public' => true, 35 '_builtin' => true 36 ); 37 38 $output = ''; // names or objects, note names is the default 39 $operator = 'or'; // 'and' or 'or' 40 41 $post_types_arrays = get_post_types($args, $output, $operator); 42 43 $return_types_array = array(); 44 45 $exclude_post_types = array("revision", "attachment", "nav_menu_item"); 46 47 foreach ($post_types_arrays as $post_types_aray) { 48 if (!in_array($post_types_aray->name, $exclude_post_types)) { 49 array_push($return_types_array, $post_types_aray->name); 50 } 30 // Clear the permalinks after the post type has been registered 31 flush_rewrite_rules(); 51 32 } 52 33 53 return $return_types_array; 54 } 34 /* 35 Function: author_filters_deactivation 36 Description: 37 * function is attached to plugin deactivation hook, 38 * a call to flush_rewrite_rules function is done to Clear the permalinks to remove rewrite rules 39 */ 40 41 public static function author_filters_deactivation() { 55 42 56 #Filtering by Author57 //defining the filter that will be used so we can select posts by 'author'58 function author_filters_admin() {43 // Clear the permalinks to remove our post type's rules 44 flush_rewrite_rules(); 45 } 59 46 60 $types_array = author_filters_post_types(); 47 /* 48 Function: author_filters_post_types 49 Description: 50 * function is attached to plugin deactivation hook, 51 * a call to flush_rewrite_rules function is done to Clear the permalinks to remove rewrite rules 52 */ 53 54 public static function author_filters_post_types() { 61 55 62 //execute only on the 'post' or 'page' content type 63 global $post_type; 64 65 if (in_array($post_type, $types_array)) { 66 //get a listing of all users that are 'author' or above 67 $user_args = array( 68 'show_option_all' => 'All Users', 69 'orderby' => 'display_name', 70 'order' => 'ASC', 71 'name' => 'author_admin_filter', 72 'who' => 'authors', 73 'include_selected' => true 56 $args = array( 57 'public' => true, 58 '_builtin' => true 74 59 ); 75 60 76 //determine if we have selected a user to be filtered by already 77 if (isset($_GET['author_admin_filter'])) { 78 //set the selected value to the value of the author 79 $user_args['selected'] = (int) sanitize_text_field($_GET['author_admin_filter']); 61 $output = ''; // names or objects, note names is the default 62 $operator = 'or'; // 'and' or 'or' 63 64 $post_types_arrays = get_post_types($args, $output, $operator); //get & store posty types supported by the system 65 66 $types_array = array(); //initialise an array 67 68 $exclude_post_types = array('attachment', 'revision', 'nav_menu_item'); //array of post types to be excluded from array of post types of system 69 70 foreach ($post_types_arrays as $post_types_aray) { // foreach - iteration to list through array of post types supported by the system 71 72 if (!in_array($post_types_aray->name, $exclude_post_types)) { 73 74 array_push($types_array, $post_types_aray->name); //populate $types_array 75 76 } 77 78 } // end: foreach 79 80 return $types_array; 81 } 82 83 /* 84 Function: author_filters_admin 85 Description: 86 * function is attached to restrict_manage_posts hook of core system 87 * generates user drop-down select box 88 * defining the filter that will be used so we can select posts by 'author' 89 */ 90 91 public static function author_filters_admin() { 92 93 $types_array = self::author_filters_post_types(); 94 95 //execute only on the 'post' or 'page' content type 96 global $post_type; 97 98 if (in_array($post_type, $types_array)) { 99 //get a listing of all users that are 'author' or above 100 $user_args = array( 101 'show_option_all' => 'All Users', 102 'orderby' => 'display_name', 103 'order' => 'ASC', 104 'name' => 'author_admin_filter', 105 'who' => 'authors', 106 'include_selected' => true 107 ); 108 109 //determine if we have selected a user to be filtered by already 110 if (isset($_GET['author_admin_filter'])) { 111 //set the selected value to the value of the author 112 $user_args['selected'] = (int) sanitize_text_field($_GET['author_admin_filter']); 113 } 114 115 wp_dropdown_users($user_args); //display the users as a drop down 80 116 } 117 } //end: author_filters_admin() 81 118 82 //display the users as a drop down 83 wp_dropdown_users($user_args); 84 } 85 } 119 /* 120 Function: author_filters_query 121 Description: 122 * function is attached to pre_get_posts hook of core system 123 * restrict the posts or pages by an additional author filter 124 */ 125 126 public static function author_filters_query($query) { 86 127 87 //end: author_filters_admin() 128 global $post_type, $pagenow; 129 130 $types_array = self::author_filters_post_types(); 88 131 89 add_action('restrict_manage_posts', 'author_filters_admin');132 //if we are currently on the edit screen of the post or page type listings 90 133 91 #Filtering by Author 92 //restrict the posts or pages by an additional author filter 93 function author_filters_query($query) { 134 if ('edit.php' == $pagenow && (in_array($post_type, $types_array))) { 94 135 95 global $post_type, $pagenow; 96 97 $types_array = author_filters_post_types(); 136 if (isset($_GET['author_admin_filter'])) { 98 137 99 //if we are currently on the edit screen of the post or page type listings 100 101 if ('edit.php' == $pagenow && (in_array($post_type, $types_array))) { 138 //set the query variable for 'author' to the desired value 139 $author_id = sanitize_text_field($_GET['author_admin_filter']); 102 140 103 if (isset($_GET['author_admin_filter'])) { 104 105 //set the query variable for 'author' to the desired value 106 $author_id = sanitize_text_field($_GET['author_admin_filter']); 107 108 //if the author is not 0 (meaning all) 109 if (0 != $author_id) { 110 $query->query_vars['author'] = $author_id; 141 //if the author is not 0 (meaning all) 142 if (0 != $author_id) { 143 $query->query_vars['author'] = $author_id; 144 } 111 145 } 112 146 } 113 } 114 } 147 } //end: author_filters_query() 148 149 } //end: class - author_filters 150 151 152 register_activation_hook(__FILE__, array('author_filters', 'author_filters_install')); 153 154 register_deactivation_hook(__FILE__, array('author_filters', 'author_filters_deactivation')); 155 156 add_action('pre_get_posts', array('author_filters', 'author_filters_query')); 115 157 116 //end: author_filters_query() 117 118 add_action('pre_get_posts', 'author_filters_query'); 158 add_action('restrict_manage_posts', array('author_filters', 'author_filters_admin')); -
author-filters/trunk/readme.txt
r1448346 r1462179 3 3 Tags: posts, pages, custom post types, author, sorting, filters 4 4 Requires at least: 3.0.1 5 Tested up to: 4. 5.36 Stable tag: 4. 5.35 Tested up to: 4.6 6 Stable tag: 4.6 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 34 34 35 35 1. Screenshot overview to display author filters drop down on post listing page in admin panel. 36 37 == Changelog == 38 = 2.0.0 = 39 Second version - Update in readme text to add Changelog section. And upgraded version to 2.0.0. 40 41 = 1.0 = 42 First version - Initial code repository.
Note: See TracChangeset
for help on using the changeset viewer.