forked from vincentorback/clean-wordpress-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextras.php
127 lines (101 loc) · 2.73 KB
/
extras.php
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* Check if on posts-page
*/
function is_page_for_posts () {
return ( is_home() || ( is_archive() && ! is_post_type_archive() ) );
}
/**
* Check if is search page
* @return boolean [description]
*/
function is_search_page () {
if ( is_search() ) {
return true;
}
$search_template_page = get_pages_with_template( 'search.php' );
if ( $search_template_page && is_page( $search_template_page[0]->ID ) ) {
return true;
}
}
/**
* Get pages using a specific template
* @param $template - Name of template file
*/
function get_pages_with_template( $template ) {
return get_pages(array(
'meta_key' => '_wp_page_template',
'meta_value' => $template
));
}
/**
* Get page depth
*/
function get_page_depth ( $page ) {
if ( ! $page ) {
return;
}
$parent_id = $page->post_parent;
$depth = 0;
while ( $parent_id > 0 ) {
$parent = get_page( $parent_id );
$parent_id = $parent->post_parent;
$depth++;
}
return $depth;
}
/**
* Nice debugging replacement to var_dump
* @param $data Object you want to test.
*/
function show ( $data ) {
echo '<pre style="box-sizing: border-box; height: 50vh; resize: vertical;
outline: 2px solid; background: #fff; font: 13px/1.3 monospace">';
print_r( $data );
echo '</pre>';
}
/**
* Totaly disable comments
*/
add_action( 'init', function () {
remove_post_type_support( 'post', 'comments' );
remove_post_type_support( 'page', 'comments' );
});
add_action( 'admin_menu', function () {
remove_menu_page( 'edit-comments.php' );
});
add_action( 'wp_before_admin_bar_render', function () {
global $wp_admin_bar;
$wp_admin_bar->remove_menu( 'comments' );
});
/**
* Custom avatars.
* @link https://codex.wordpress.org/How_to_Use_Gravatars_in_WordPress
* @param $user_contact Existing avatars
*/
add_filter( 'avatar_defaults', function ( $avatar_defaults ) {
$my_avatar = get_bloginfo( 'template_directory' ) . '/images/my-avatar.gif';
$avatar_defaults[$my_avatar] = "My Avatar";
return $avatar_defaults;
}, 999);
/**
* Custom left admin footer text
* @link https://developer.wordpress.org/reference/hooks/admin_footer_text/
*/
add_filter( 'admin_footer_text', function () {
return '<span id="footer-thankyou">Website by <a href="//vincentorback.se" target="_blank">Vincent Orback</a></span>';
}, 999);
/**
* Custom right admin footer text (where the WordPress version nr is)
* @link https://developer.wordpress.org/reference/hooks/update_footer/
*/
add_filter( 'update_footer', function () {
return '¯\_(ツ)_/¯';
}, 999);
/**
* Stay logged in for longer
* @link https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/
*/
add_filter( 'auth_cookie_expiration', function () {
return 31556926; // 1 year
});