-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter-admin-published-default.php
More file actions
85 lines (75 loc) · 2.11 KB
/
filter-admin-published-default.php
File metadata and controls
85 lines (75 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* Filter Admin Published Default
*
* @package Filter_Admin_Published_Default
* @author Chuck Reynolds
* @link https://chuckreynolds.com
* @copyright 2013 Rynoweb LLC
* @license GPL-2.0-or-later
*
* Plugin Name: Filter Admin Published Default
* Plugin URI: https://github.com/chuckreynolds/wp-filter-admin-published-default
* Description: Enables all public post types (posts, pages, etc) in wp-admin to show the Published filter by default.
* Version: 2.0.0
* Requires at least: 5.2
* Author: Chuck Reynolds
* Author URI: https://chuckreynolds.com
* Text Domain: filter-admin-published-default
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
// Only run plugin in the admin
if ( ! is_admin() ) {
return;
}
/**
* Change the default URL for post types to only show published items.
*
* @return void
*/
function chuck_filter_admin_published_default() {
$types = chuck_fetch_post_types();
if ( empty( $types ) ) {
return;
}
global $submenu;
foreach ( $types as $type ) {
// Posts use a different submenu key than other post types.
if ( 'post' === $type ) {
$submenu['edit.php'][5][2] = 'edit.php?post_status=publish';
} else {
$submenu[ 'edit.php?post_type=' . esc_attr( $type ) ][5][2] = 'edit.php?post_type=' . esc_attr( $type ) . '&post_status=publish';
}
}
}
add_action( 'admin_menu', 'chuck_filter_admin_published_default', 20 );
/**
* Fetch all public post types.
*
* @return array Post type names.
*/
function chuck_fetch_post_types() {
$types = array( 'post', 'page' );
$custom = get_post_types(
array(
'public' => true,
'_builtin' => false,
),
'names',
'and'
);
if ( ! empty( $custom ) ) {
$types = array_merge( $types, $custom );
}
/**
* Filter the post types that get the published default in wp-admin.
*
* @param array $types Post type names.
*/
return apply_filters( 'chuck_admin_publish_link_types', $types );
}