author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Toolbar API: Top-level Toolbar functionality |
0 | 4 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5 |
* @package WordPress |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
* @subpackage Toolbar |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @since 3.1.0 |
0 | 8 |
*/ |
9 |
||
10 |
/** |
|
19 | 11 |
* Instantiates the admin bar object and set it up as a global for access elsewhere. |
0 | 12 |
* |
13 |
* UNHOOKING THIS FUNCTION WILL NOT PROPERLY REMOVE THE ADMIN BAR. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* For that, use show_admin_bar(false) or the {@see 'show_admin_bar'} filter. |
0 | 15 |
* |
16 |
* @since 3.1.0 |
|
17 |
* @access private |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
* @global WP_Admin_Bar $wp_admin_bar |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* |
0 | 21 |
* @return bool Whether the admin bar was successfully initialized. |
22 |
*/ |
|
23 |
function _wp_admin_bar_init() { |
|
24 |
global $wp_admin_bar; |
|
25 |
||
9 | 26 |
if ( ! is_admin_bar_showing() ) { |
0 | 27 |
return false; |
9 | 28 |
} |
0 | 29 |
|
30 |
/* Load the admin bar class code ready for instantiation */ |
|
16 | 31 |
require_once ABSPATH . WPINC . '/class-wp-admin-bar.php'; |
0 | 32 |
|
33 |
/* Instantiate the admin bar */ |
|
5 | 34 |
|
35 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
* Filters the admin bar class to instantiate. |
5 | 37 |
* |
38 |
* @since 3.1.0 |
|
39 |
* |
|
40 |
* @param string $wp_admin_bar_class Admin bar class to use. Default 'WP_Admin_Bar'. |
|
41 |
*/ |
|
0 | 42 |
$admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' ); |
9 | 43 |
if ( class_exists( $admin_bar_class ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
44 |
$wp_admin_bar = new $admin_bar_class(); |
9 | 45 |
} else { |
0 | 46 |
return false; |
9 | 47 |
} |
0 | 48 |
|
49 |
$wp_admin_bar->initialize(); |
|
50 |
$wp_admin_bar->add_menus(); |
|
51 |
||
52 |
return true; |
|
53 |
} |
|
54 |
||
55 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
* Renders the admin bar to the page based on the $wp_admin_bar->menu member var. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* |
16 | 58 |
* This is called very early on the {@see 'wp_body_open'} action so that it will render |
59 |
* before anything else being added to the page body. |
|
60 |
* |
|
61 |
* For backward compatibility with themes not using the 'wp_body_open' action, |
|
62 |
* the function is also called late on {@see 'wp_footer'}. |
|
0 | 63 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
* It includes the {@see 'admin_bar_menu'} action which should be used to hook in and |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
65 |
* add new menus to the admin bar. This also gives you access to the `$post` global, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
66 |
* among others. |
0 | 67 |
* |
68 |
* @since 3.1.0 |
|
16 | 69 |
* @since 5.4.0 Called on 'wp_body_open' action first, with 'wp_footer' as a fallback. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
* @global WP_Admin_Bar $wp_admin_bar |
0 | 72 |
*/ |
73 |
function wp_admin_bar_render() { |
|
74 |
global $wp_admin_bar; |
|
16 | 75 |
static $rendered = false; |
76 |
||
77 |
if ( $rendered ) { |
|
78 |
return; |
|
79 |
} |
|
0 | 80 |
|
9 | 81 |
if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
return; |
9 | 83 |
} |
0 | 84 |
|
5 | 85 |
/** |
19 | 86 |
* Loads all necessary admin bar items. |
5 | 87 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
88 |
* This hook can add, remove, or manipulate admin bar items. The priority |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
89 |
* determines the placement for new items, and changes to existing items |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
90 |
* would require a high priority. To remove or manipulate existing nodes |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
91 |
* without a specific priority, use `wp_before_admin_bar_render`. |
5 | 92 |
* |
93 |
* @since 3.1.0 |
|
94 |
* |
|
19 | 95 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance, passed by reference. |
5 | 96 |
*/ |
0 | 97 |
do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) ); |
98 |
||
5 | 99 |
/** |
100 |
* Fires before the admin bar is rendered. |
|
101 |
* |
|
102 |
* @since 3.1.0 |
|
103 |
*/ |
|
0 | 104 |
do_action( 'wp_before_admin_bar_render' ); |
105 |
||
106 |
$wp_admin_bar->render(); |
|
107 |
||
5 | 108 |
/** |
109 |
* Fires after the admin bar is rendered. |
|
110 |
* |
|
111 |
* @since 3.1.0 |
|
112 |
*/ |
|
0 | 113 |
do_action( 'wp_after_admin_bar_render' ); |
16 | 114 |
|
115 |
$rendered = true; |
|
0 | 116 |
} |
117 |
||
118 |
/** |
|
19 | 119 |
* Adds the WordPress logo menu. |
0 | 120 |
* |
121 |
* @since 3.3.0 |
|
122 |
* |
|
19 | 123 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
0 | 124 |
*/ |
125 |
function wp_admin_bar_wp_menu( $wp_admin_bar ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
if ( current_user_can( 'read' ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
127 |
$about_url = self_admin_url( 'about.php' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
128 |
$contribute_url = self_admin_url( 'contribute.php' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
} elseif ( is_multisite() ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
130 |
$about_url = get_dashboard_url( get_current_user_id(), 'about.php' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
131 |
$contribute_url = get_dashboard_url( get_current_user_id(), 'contribute.php' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
133 |
$about_url = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
134 |
$contribute_url = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
$wp_logo_menu_args = array( |
0 | 138 |
'id' => 'wp-logo', |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
139 |
'title' => '<span class="ab-icon" aria-hidden="true"></span><span class="screen-reader-text">' . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
140 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
141 |
__( 'About WordPress' ) . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
142 |
'</span>', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
'href' => $about_url, |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
144 |
'meta' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
145 |
'menu_title' => __( 'About WordPress' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
146 |
), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
); |
0 | 148 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
// Set tabindex="0" to make sub menus accessible when no URL is available. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
if ( ! $about_url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
$wp_logo_menu_args['meta'] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
'tabindex' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
154 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
|
16 | 156 |
$wp_admin_bar->add_node( $wp_logo_menu_args ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
if ( $about_url ) { |
16 | 159 |
// Add "About WordPress" link. |
160 |
$wp_admin_bar->add_node( |
|
9 | 161 |
array( |
162 |
'parent' => 'wp-logo', |
|
163 |
'id' => 'about', |
|
164 |
'title' => __( 'About WordPress' ), |
|
165 |
'href' => $about_url, |
|
166 |
) |
|
167 |
); |
|
0 | 168 |
} |
169 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
170 |
if ( $contribute_url ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
171 |
// Add contribute link. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
172 |
$wp_admin_bar->add_node( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
173 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
174 |
'parent' => 'wp-logo', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
175 |
'id' => 'contribute', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
176 |
'title' => __( 'Get Involved' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
177 |
'href' => $contribute_url, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
178 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
179 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
180 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
181 |
|
16 | 182 |
// Add WordPress.org link. |
183 |
$wp_admin_bar->add_node( |
|
9 | 184 |
array( |
185 |
'parent' => 'wp-logo-external', |
|
186 |
'id' => 'wporg', |
|
187 |
'title' => __( 'WordPress.org' ), |
|
188 |
'href' => __( 'https://wordpress.org/' ), |
|
189 |
) |
|
190 |
); |
|
0 | 191 |
|
18 | 192 |
// Add documentation link. |
16 | 193 |
$wp_admin_bar->add_node( |
9 | 194 |
array( |
195 |
'parent' => 'wp-logo-external', |
|
196 |
'id' => 'documentation', |
|
197 |
'title' => __( 'Documentation' ), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
198 |
'href' => __( 'https://wordpress.org/documentation/' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
199 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
200 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
201 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
202 |
// Add learn link. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
203 |
$wp_admin_bar->add_node( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
204 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
205 |
'parent' => 'wp-logo-external', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
206 |
'id' => 'learn', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
207 |
'title' => __( 'Learn WordPress' ), |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
208 |
'href' => __( 'https://learn.wordpress.org/' ), |
9 | 209 |
) |
210 |
); |
|
0 | 211 |
|
16 | 212 |
// Add forums link. |
213 |
$wp_admin_bar->add_node( |
|
9 | 214 |
array( |
215 |
'parent' => 'wp-logo-external', |
|
216 |
'id' => 'support-forums', |
|
217 |
'title' => __( 'Support' ), |
|
18 | 218 |
'href' => __( 'https://wordpress.org/support/forums/' ), |
9 | 219 |
) |
220 |
); |
|
0 | 221 |
|
16 | 222 |
// Add feedback link. |
223 |
$wp_admin_bar->add_node( |
|
9 | 224 |
array( |
225 |
'parent' => 'wp-logo-external', |
|
226 |
'id' => 'feedback', |
|
227 |
'title' => __( 'Feedback' ), |
|
228 |
'href' => __( 'https://wordpress.org/support/forum/requests-and-feedback' ), |
|
229 |
) |
|
230 |
); |
|
0 | 231 |
} |
232 |
||
233 |
/** |
|
19 | 234 |
* Adds the sidebar toggle button. |
5 | 235 |
* |
236 |
* @since 3.8.0 |
|
237 |
* |
|
19 | 238 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
5 | 239 |
*/ |
240 |
function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) { |
|
241 |
if ( is_admin() ) { |
|
16 | 242 |
$wp_admin_bar->add_node( |
9 | 243 |
array( |
244 |
'id' => 'menu-toggle', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
245 |
'title' => '<span class="ab-icon" aria-hidden="true"></span><span class="screen-reader-text">' . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
246 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
247 |
__( 'Menu' ) . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
248 |
'</span>', |
9 | 249 |
'href' => '#', |
250 |
) |
|
251 |
); |
|
5 | 252 |
} |
253 |
} |
|
254 |
||
255 |
/** |
|
19 | 256 |
* Adds the "My Account" item. |
0 | 257 |
* |
258 |
* @since 3.3.0 |
|
259 |
* |
|
19 | 260 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
0 | 261 |
*/ |
262 |
function wp_admin_bar_my_account_item( $wp_admin_bar ) { |
|
263 |
$user_id = get_current_user_id(); |
|
264 |
$current_user = wp_get_current_user(); |
|
265 |
||
9 | 266 |
if ( ! $user_id ) { |
0 | 267 |
return; |
9 | 268 |
} |
0 | 269 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
if ( current_user_can( 'read' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
$profile_url = get_edit_profile_url( $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
} elseif ( is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
$profile_url = get_dashboard_url( $user_id, 'profile.php' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
$profile_url = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
|
5 | 278 |
$avatar = get_avatar( $user_id, 26 ); |
16 | 279 |
/* translators: %s: Current user's display name. */ |
9 | 280 |
$howdy = sprintf( __( 'Howdy, %s' ), '<span class="display-name">' . $current_user->display_name . '</span>' ); |
281 |
$class = empty( $avatar ) ? '' : 'with-avatar'; |
|
0 | 282 |
|
16 | 283 |
$wp_admin_bar->add_node( |
9 | 284 |
array( |
285 |
'id' => 'my-account', |
|
286 |
'parent' => 'top-secondary', |
|
287 |
'title' => $howdy . $avatar, |
|
288 |
'href' => $profile_url, |
|
289 |
'meta' => array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
290 |
'class' => $class, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
291 |
/* translators: %s: Current user's display name. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
292 |
'menu_title' => sprintf( __( 'Howdy, %s' ), $current_user->display_name ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
293 |
'tabindex' => ( false !== $profile_url ) ? '' : 0, |
9 | 294 |
), |
295 |
) |
|
296 |
); |
|
0 | 297 |
} |
298 |
||
299 |
/** |
|
19 | 300 |
* Adds the "My Account" submenu items. |
0 | 301 |
* |
302 |
* @since 3.1.0 |
|
303 |
* |
|
19 | 304 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
0 | 305 |
*/ |
306 |
function wp_admin_bar_my_account_menu( $wp_admin_bar ) { |
|
307 |
$user_id = get_current_user_id(); |
|
308 |
$current_user = wp_get_current_user(); |
|
309 |
||
9 | 310 |
if ( ! $user_id ) { |
0 | 311 |
return; |
9 | 312 |
} |
0 | 313 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
if ( current_user_can( 'read' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
$profile_url = get_edit_profile_url( $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
} elseif ( is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
$profile_url = get_dashboard_url( $user_id, 'profile.php' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
$profile_url = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
320 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
|
9 | 322 |
$wp_admin_bar->add_group( |
323 |
array( |
|
324 |
'parent' => 'my-account', |
|
325 |
'id' => 'user-actions', |
|
326 |
) |
|
327 |
); |
|
0 | 328 |
|
329 |
$user_info = get_avatar( $user_id, 64 ); |
|
330 |
$user_info .= "<span class='display-name'>{$current_user->display_name}</span>"; |
|
331 |
||
9 | 332 |
if ( $current_user->display_name !== $current_user->user_login ) { |
0 | 333 |
$user_info .= "<span class='username'>{$current_user->user_login}</span>"; |
9 | 334 |
} |
0 | 335 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
336 |
if ( false !== $profile_url ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
337 |
$user_info .= "<span class='display-name edit-profile'>" . __( 'Edit Profile' ) . '</span>'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
338 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
339 |
|
16 | 340 |
$wp_admin_bar->add_node( |
9 | 341 |
array( |
342 |
'parent' => 'user-actions', |
|
343 |
'id' => 'user-info', |
|
344 |
'title' => $user_info, |
|
345 |
'href' => $profile_url, |
|
346 |
) |
|
347 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
|
16 | 349 |
$wp_admin_bar->add_node( |
9 | 350 |
array( |
351 |
'parent' => 'user-actions', |
|
352 |
'id' => 'logout', |
|
353 |
'title' => __( 'Log Out' ), |
|
354 |
'href' => wp_logout_url(), |
|
355 |
) |
|
356 |
); |
|
0 | 357 |
} |
358 |
||
359 |
/** |
|
19 | 360 |
* Adds the "Site Name" menu. |
0 | 361 |
* |
362 |
* @since 3.3.0 |
|
363 |
* |
|
19 | 364 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
0 | 365 |
*/ |
366 |
function wp_admin_bar_site_menu( $wp_admin_bar ) { |
|
367 |
// Don't show for logged out users. |
|
9 | 368 |
if ( ! is_user_logged_in() ) { |
0 | 369 |
return; |
9 | 370 |
} |
0 | 371 |
|
372 |
// Show only when the user is a member of this site, or they're a super admin. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
if ( ! is_user_member_of_blog() && ! current_user_can( 'manage_network' ) ) { |
0 | 374 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
} |
0 | 376 |
|
9 | 377 |
$blogname = get_bloginfo( 'name' ); |
0 | 378 |
|
5 | 379 |
if ( ! $blogname ) { |
0 | 380 |
$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
5 | 381 |
} |
0 | 382 |
|
383 |
if ( is_network_admin() ) { |
|
16 | 384 |
/* translators: %s: Site title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
$blogname = sprintf( __( 'Network Admin: %s' ), esc_html( get_network()->site_name ) ); |
0 | 386 |
} elseif ( is_user_admin() ) { |
16 | 387 |
/* translators: %s: Site title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
$blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) ); |
0 | 389 |
} |
390 |
||
391 |
$title = wp_html_excerpt( $blogname, 40, '…' ); |
|
392 |
||
16 | 393 |
$wp_admin_bar->add_node( |
9 | 394 |
array( |
395 |
'id' => 'site-name', |
|
396 |
'title' => $title, |
|
397 |
'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
398 |
'meta' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
399 |
'menu_title' => $title, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
400 |
), |
9 | 401 |
) |
402 |
); |
|
0 | 403 |
|
404 |
// Create submenu items. |
|
405 |
||
406 |
if ( is_admin() ) { |
|
407 |
// Add an option to visit the site. |
|
16 | 408 |
$wp_admin_bar->add_node( |
9 | 409 |
array( |
410 |
'parent' => 'site-name', |
|
411 |
'id' => 'view-site', |
|
412 |
'title' => __( 'Visit Site' ), |
|
413 |
'href' => home_url( '/' ), |
|
414 |
) |
|
415 |
); |
|
0 | 416 |
|
417 |
if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) { |
|
16 | 418 |
$wp_admin_bar->add_node( |
9 | 419 |
array( |
420 |
'parent' => 'site-name', |
|
421 |
'id' => 'edit-site', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
422 |
'title' => __( 'Manage Site' ), |
9 | 423 |
'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ), |
424 |
) |
|
425 |
); |
|
0 | 426 |
} |
9 | 427 |
} elseif ( current_user_can( 'read' ) ) { |
0 | 428 |
// We're on the front end, link to the Dashboard. |
16 | 429 |
$wp_admin_bar->add_node( |
9 | 430 |
array( |
431 |
'parent' => 'site-name', |
|
432 |
'id' => 'dashboard', |
|
433 |
'title' => __( 'Dashboard' ), |
|
434 |
'href' => admin_url(), |
|
435 |
) |
|
436 |
); |
|
0 | 437 |
|
438 |
// Add the appearance submenu items. |
|
439 |
wp_admin_bar_appearance_menu( $wp_admin_bar ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
440 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
441 |
// Add a Plugins link. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
442 |
if ( current_user_can( 'activate_plugins' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
443 |
$wp_admin_bar->add_node( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
444 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
445 |
'parent' => 'site-name', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
446 |
'id' => 'plugins', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
447 |
'title' => __( 'Plugins' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
448 |
'href' => admin_url( 'plugins.php' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
449 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
450 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
451 |
} |
0 | 452 |
} |
453 |
} |
|
454 |
||
455 |
/** |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
456 |
* Adds the "Edit Site" link to the Toolbar. |
19 | 457 |
* |
458 |
* @since 5.9.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
459 |
* @since 6.3.0 Added `$_wp_current_template_id` global for editing of current template directly from the admin bar. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
460 |
* @since 6.6.0 Added the `canvas` query arg to the Site Editor link. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
461 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
462 |
* @global string $_wp_current_template_id |
19 | 463 |
* |
464 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
|
465 |
*/ |
|
466 |
function wp_admin_bar_edit_site_menu( $wp_admin_bar ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
467 |
global $_wp_current_template_id; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
468 |
|
19 | 469 |
// Don't show if a block theme is not activated. |
470 |
if ( ! wp_is_block_theme() ) { |
|
471 |
return; |
|
472 |
} |
|
473 |
||
474 |
// Don't show for users who can't edit theme options or when in the admin. |
|
475 |
if ( ! current_user_can( 'edit_theme_options' ) || is_admin() ) { |
|
476 |
return; |
|
477 |
} |
|
478 |
||
479 |
$wp_admin_bar->add_node( |
|
480 |
array( |
|
481 |
'id' => 'site-editor', |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
482 |
'title' => __( 'Edit Site' ), |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
483 |
'href' => add_query_arg( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
484 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
485 |
'postType' => 'wp_template', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
486 |
'postId' => $_wp_current_template_id, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
487 |
'canvas' => 'edit', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
488 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
489 |
admin_url( 'site-editor.php' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
490 |
), |
19 | 491 |
) |
492 |
); |
|
493 |
} |
|
494 |
||
495 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
* Adds the "Customize" link to the Toolbar. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
500 |
* @global WP_Customize_Manager $wp_customize |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
501 |
* |
19 | 502 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
function wp_admin_bar_customize_menu( $wp_admin_bar ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
global $wp_customize; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
|
19 | 507 |
// Don't show if a block theme is activated and no plugins use the customizer. |
508 |
if ( wp_is_block_theme() && ! has_action( 'customize_register' ) ) { |
|
509 |
return; |
|
510 |
} |
|
511 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
// Don't show for users who can't access the customizer or when in the admin. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
if ( ! current_user_can( 'customize' ) || is_admin() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
// Don't show if the user cannot edit a given customize_changeset post currently being previewed. |
16 | 518 |
if ( is_customize_preview() && $wp_customize->changeset_post_id() |
519 |
&& ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() ) |
|
520 |
) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
if ( is_customize_preview() && $wp_customize->changeset_uuid() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
$current_url = remove_query_arg( 'customize_changeset_uuid', $current_url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
$customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
if ( is_customize_preview() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
$customize_url = add_query_arg( array( 'changeset_uuid' => $wp_customize->changeset_uuid() ), $customize_url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
|
16 | 534 |
$wp_admin_bar->add_node( |
9 | 535 |
array( |
536 |
'id' => 'customize', |
|
537 |
'title' => __( 'Customize' ), |
|
538 |
'href' => $customize_url, |
|
539 |
'meta' => array( |
|
540 |
'class' => 'hide-if-no-customize', |
|
541 |
), |
|
542 |
) |
|
543 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
544 |
add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
/** |
19 | 548 |
* Adds the "My Sites/[Site Name]" menu and all submenus. |
0 | 549 |
* |
550 |
* @since 3.1.0 |
|
551 |
* |
|
19 | 552 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
0 | 553 |
*/ |
554 |
function wp_admin_bar_my_sites_menu( $wp_admin_bar ) { |
|
555 |
// Don't show for logged out users or single site mode. |
|
9 | 556 |
if ( ! is_user_logged_in() || ! is_multisite() ) { |
0 | 557 |
return; |
9 | 558 |
} |
0 | 559 |
|
560 |
// Show only when the user has at least one site, or they're a super admin. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
if ( count( $wp_admin_bar->user->blogs ) < 1 && ! current_user_can( 'manage_network' ) ) { |
0 | 562 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
} |
0 | 564 |
|
5 | 565 |
if ( $wp_admin_bar->user->active_blog ) { |
566 |
$my_sites_url = get_admin_url( $wp_admin_bar->user->active_blog->blog_id, 'my-sites.php' ); |
|
567 |
} else { |
|
568 |
$my_sites_url = admin_url( 'my-sites.php' ); |
|
569 |
} |
|
570 |
||
16 | 571 |
$wp_admin_bar->add_node( |
9 | 572 |
array( |
573 |
'id' => 'my-sites', |
|
574 |
'title' => __( 'My Sites' ), |
|
575 |
'href' => $my_sites_url, |
|
576 |
) |
|
577 |
); |
|
0 | 578 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
if ( current_user_can( 'manage_network' ) ) { |
9 | 580 |
$wp_admin_bar->add_group( |
581 |
array( |
|
582 |
'parent' => 'my-sites', |
|
583 |
'id' => 'my-sites-super-admin', |
|
584 |
) |
|
585 |
); |
|
0 | 586 |
|
16 | 587 |
$wp_admin_bar->add_node( |
9 | 588 |
array( |
589 |
'parent' => 'my-sites-super-admin', |
|
590 |
'id' => 'network-admin', |
|
591 |
'title' => __( 'Network Admin' ), |
|
592 |
'href' => network_admin_url(), |
|
593 |
) |
|
594 |
); |
|
0 | 595 |
|
16 | 596 |
$wp_admin_bar->add_node( |
9 | 597 |
array( |
598 |
'parent' => 'network-admin', |
|
599 |
'id' => 'network-admin-d', |
|
600 |
'title' => __( 'Dashboard' ), |
|
601 |
'href' => network_admin_url(), |
|
602 |
) |
|
603 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
if ( current_user_can( 'manage_sites' ) ) { |
16 | 606 |
$wp_admin_bar->add_node( |
9 | 607 |
array( |
608 |
'parent' => 'network-admin', |
|
609 |
'id' => 'network-admin-s', |
|
610 |
'title' => __( 'Sites' ), |
|
611 |
'href' => network_admin_url( 'sites.php' ), |
|
612 |
) |
|
613 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
if ( current_user_can( 'manage_network_users' ) ) { |
16 | 617 |
$wp_admin_bar->add_node( |
9 | 618 |
array( |
619 |
'parent' => 'network-admin', |
|
620 |
'id' => 'network-admin-u', |
|
621 |
'title' => __( 'Users' ), |
|
622 |
'href' => network_admin_url( 'users.php' ), |
|
623 |
) |
|
624 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
if ( current_user_can( 'manage_network_themes' ) ) { |
16 | 628 |
$wp_admin_bar->add_node( |
9 | 629 |
array( |
630 |
'parent' => 'network-admin', |
|
631 |
'id' => 'network-admin-t', |
|
632 |
'title' => __( 'Themes' ), |
|
633 |
'href' => network_admin_url( 'themes.php' ), |
|
634 |
) |
|
635 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
if ( current_user_can( 'manage_network_plugins' ) ) { |
16 | 639 |
$wp_admin_bar->add_node( |
9 | 640 |
array( |
641 |
'parent' => 'network-admin', |
|
642 |
'id' => 'network-admin-p', |
|
643 |
'title' => __( 'Plugins' ), |
|
644 |
'href' => network_admin_url( 'plugins.php' ), |
|
645 |
) |
|
646 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
647 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
if ( current_user_can( 'manage_network_options' ) ) { |
16 | 650 |
$wp_admin_bar->add_node( |
9 | 651 |
array( |
652 |
'parent' => 'network-admin', |
|
653 |
'id' => 'network-admin-o', |
|
654 |
'title' => __( 'Settings' ), |
|
655 |
'href' => network_admin_url( 'settings.php' ), |
|
656 |
) |
|
657 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
} |
0 | 659 |
} |
660 |
||
16 | 661 |
// Add site links. |
9 | 662 |
$wp_admin_bar->add_group( |
663 |
array( |
|
664 |
'parent' => 'my-sites', |
|
665 |
'id' => 'my-sites-list', |
|
666 |
'meta' => array( |
|
667 |
'class' => current_user_can( 'manage_network' ) ? 'ab-sub-secondary' : '', |
|
668 |
), |
|
669 |
) |
|
670 |
); |
|
0 | 671 |
|
19 | 672 |
/** |
673 |
* Filters whether to show the site icons in toolbar. |
|
674 |
* |
|
675 |
* Returning false to this hook is the recommended way to hide site icons in the toolbar. |
|
676 |
* A truthy return may have negative performance impact on large multisites. |
|
677 |
* |
|
678 |
* @since 6.0.0 |
|
679 |
* |
|
680 |
* @param bool $show_site_icons Whether site icons should be shown in the toolbar. Default true. |
|
681 |
*/ |
|
682 |
$show_site_icons = apply_filters( 'wp_admin_bar_show_site_icons', true ); |
|
683 |
||
0 | 684 |
foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { |
685 |
switch_to_blog( $blog->userblog_id ); |
|
686 |
||
19 | 687 |
if ( true === $show_site_icons && has_site_icon() ) { |
18 | 688 |
$blavatar = sprintf( |
19 | 689 |
'<img class="blavatar" src="%s" srcset="%s 2x" alt="" width="16" height="16"%s />', |
18 | 690 |
esc_url( get_site_icon_url( 16 ) ), |
19 | 691 |
esc_url( get_site_icon_url( 32 ) ), |
692 |
( wp_lazy_loading_enabled( 'img', 'site_icon_in_toolbar' ) ? ' loading="lazy"' : '' ) |
|
18 | 693 |
); |
694 |
} else { |
|
695 |
$blavatar = '<div class="blavatar"></div>'; |
|
696 |
} |
|
0 | 697 |
|
5 | 698 |
$blogname = $blog->blogname; |
699 |
||
700 |
if ( ! $blogname ) { |
|
701 |
$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
|
702 |
} |
|
703 |
||
9 | 704 |
$menu_id = 'blog-' . $blog->userblog_id; |
0 | 705 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
if ( current_user_can( 'read' ) ) { |
16 | 707 |
$wp_admin_bar->add_node( |
9 | 708 |
array( |
709 |
'parent' => 'my-sites-list', |
|
710 |
'id' => $menu_id, |
|
711 |
'title' => $blavatar . $blogname, |
|
712 |
'href' => admin_url(), |
|
713 |
) |
|
714 |
); |
|
0 | 715 |
|
16 | 716 |
$wp_admin_bar->add_node( |
9 | 717 |
array( |
718 |
'parent' => $menu_id, |
|
719 |
'id' => $menu_id . '-d', |
|
720 |
'title' => __( 'Dashboard' ), |
|
721 |
'href' => admin_url(), |
|
722 |
) |
|
723 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
724 |
} else { |
16 | 725 |
$wp_admin_bar->add_node( |
9 | 726 |
array( |
727 |
'parent' => 'my-sites-list', |
|
728 |
'id' => $menu_id, |
|
729 |
'title' => $blavatar . $blogname, |
|
730 |
'href' => home_url(), |
|
731 |
) |
|
732 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
} |
0 | 734 |
|
735 |
if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { |
|
16 | 736 |
$wp_admin_bar->add_node( |
9 | 737 |
array( |
738 |
'parent' => $menu_id, |
|
739 |
'id' => $menu_id . '-n', |
|
740 |
'title' => get_post_type_object( 'post' )->labels->new_item, |
|
741 |
'href' => admin_url( 'post-new.php' ), |
|
742 |
) |
|
743 |
); |
|
0 | 744 |
} |
745 |
||
746 |
if ( current_user_can( 'edit_posts' ) ) { |
|
16 | 747 |
$wp_admin_bar->add_node( |
9 | 748 |
array( |
749 |
'parent' => $menu_id, |
|
750 |
'id' => $menu_id . '-c', |
|
751 |
'title' => __( 'Manage Comments' ), |
|
752 |
'href' => admin_url( 'edit-comments.php' ), |
|
753 |
) |
|
754 |
); |
|
0 | 755 |
} |
756 |
||
16 | 757 |
$wp_admin_bar->add_node( |
9 | 758 |
array( |
759 |
'parent' => $menu_id, |
|
760 |
'id' => $menu_id . '-v', |
|
761 |
'title' => __( 'Visit Site' ), |
|
762 |
'href' => home_url( '/' ), |
|
763 |
) |
|
764 |
); |
|
0 | 765 |
|
766 |
restore_current_blog(); |
|
767 |
} |
|
768 |
} |
|
769 |
||
770 |
/** |
|
19 | 771 |
* Provides a shortlink. |
0 | 772 |
* |
773 |
* @since 3.1.0 |
|
774 |
* |
|
19 | 775 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
0 | 776 |
*/ |
777 |
function wp_admin_bar_shortlink_menu( $wp_admin_bar ) { |
|
778 |
$short = wp_get_shortlink( 0, 'query' ); |
|
9 | 779 |
$id = 'get-shortlink'; |
0 | 780 |
|
9 | 781 |
if ( empty( $short ) ) { |
0 | 782 |
return; |
9 | 783 |
} |
0 | 784 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
785 |
$html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" aria-label="' . __( 'Shortlink' ) . '" />'; |
0 | 786 |
|
16 | 787 |
$wp_admin_bar->add_node( |
9 | 788 |
array( |
789 |
'id' => $id, |
|
790 |
'title' => __( 'Shortlink' ), |
|
791 |
'href' => $short, |
|
792 |
'meta' => array( 'html' => $html ), |
|
793 |
) |
|
794 |
); |
|
0 | 795 |
} |
796 |
||
797 |
/** |
|
19 | 798 |
* Provides an edit link for posts and terms. |
0 | 799 |
* |
800 |
* @since 3.1.0 |
|
18 | 801 |
* @since 5.5.0 Added a "View Post" link on Comments screen for a single post. |
0 | 802 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
803 |
* @global WP_Term $tag |
16 | 804 |
* @global WP_Query $wp_the_query WordPress Query object. |
9 | 805 |
* @global int $user_id The ID of the user being edited. Not to be confused with the |
806 |
* global $user_ID, which contains the ID of the current user. |
|
16 | 807 |
* @global int $post_id The ID of the post when editing comments for a single post. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
808 |
* |
19 | 809 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
0 | 810 |
*/ |
811 |
function wp_admin_bar_edit_menu( $wp_admin_bar ) { |
|
16 | 812 |
global $tag, $wp_the_query, $user_id, $post_id; |
0 | 813 |
|
814 |
if ( is_admin() ) { |
|
16 | 815 |
$current_screen = get_current_screen(); |
816 |
$post = get_post(); |
|
817 |
$post_type_object = null; |
|
0 | 818 |
|
16 | 819 |
if ( 'post' === $current_screen->base ) { |
820 |
$post_type_object = get_post_type_object( $post->post_type ); |
|
821 |
} elseif ( 'edit' === $current_screen->base ) { |
|
822 |
$post_type_object = get_post_type_object( $current_screen->post_type ); |
|
823 |
} elseif ( 'edit-comments' === $current_screen->base && $post_id ) { |
|
824 |
$post = get_post( $post_id ); |
|
825 |
if ( $post ) { |
|
826 |
$post_type_object = get_post_type_object( $post->post_type ); |
|
827 |
} |
|
828 |
} |
|
829 |
||
830 |
if ( ( 'post' === $current_screen->base || 'edit-comments' === $current_screen->base ) |
|
831 |
&& 'add' !== $current_screen->action |
|
832 |
&& ( $post_type_object ) |
|
0 | 833 |
&& current_user_can( 'read_post', $post->ID ) |
834 |
&& ( $post_type_object->public ) |
|
9 | 835 |
&& ( $post_type_object->show_in_admin_bar ) ) { |
16 | 836 |
if ( 'draft' === $post->post_status ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
$preview_link = get_preview_post_link( $post ); |
16 | 838 |
$wp_admin_bar->add_node( |
9 | 839 |
array( |
840 |
'id' => 'preview', |
|
841 |
'title' => $post_type_object->labels->view_item, |
|
842 |
'href' => esc_url( $preview_link ), |
|
843 |
'meta' => array( 'target' => 'wp-preview-' . $post->ID ), |
|
844 |
) |
|
845 |
); |
|
5 | 846 |
} else { |
16 | 847 |
$wp_admin_bar->add_node( |
9 | 848 |
array( |
849 |
'id' => 'view', |
|
850 |
'title' => $post_type_object->labels->view_item, |
|
851 |
'href' => get_permalink( $post->ID ), |
|
852 |
) |
|
853 |
); |
|
5 | 854 |
} |
16 | 855 |
} elseif ( 'edit' === $current_screen->base |
856 |
&& ( $post_type_object ) |
|
9 | 857 |
&& ( $post_type_object->public ) |
858 |
&& ( $post_type_object->show_in_admin_bar ) |
|
859 |
&& ( get_post_type_archive_link( $post_type_object->name ) ) |
|
860 |
&& ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) { |
|
861 |
$wp_admin_bar->add_node( |
|
862 |
array( |
|
863 |
'id' => 'archive', |
|
864 |
'title' => $post_type_object->labels->view_items, |
|
865 |
'href' => get_post_type_archive_link( $current_screen->post_type ), |
|
866 |
) |
|
867 |
); |
|
16 | 868 |
} elseif ( 'term' === $current_screen->base && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) ) { |
869 |
$tax = get_taxonomy( $tag->taxonomy ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
870 |
if ( is_term_publicly_viewable( $tag ) ) { |
16 | 871 |
$wp_admin_bar->add_node( |
872 |
array( |
|
873 |
'id' => 'view', |
|
874 |
'title' => $tax->labels->view_item, |
|
875 |
'href' => get_term_link( $tag ), |
|
876 |
) |
|
877 |
); |
|
878 |
} |
|
879 |
} elseif ( 'user-edit' === $current_screen->base && isset( $user_id ) ) { |
|
880 |
$user_object = get_userdata( $user_id ); |
|
881 |
$view_link = get_author_posts_url( $user_object->ID ); |
|
882 |
if ( $user_object->exists() && $view_link ) { |
|
883 |
$wp_admin_bar->add_node( |
|
884 |
array( |
|
885 |
'id' => 'view', |
|
886 |
'title' => __( 'View User' ), |
|
887 |
'href' => $view_link, |
|
888 |
) |
|
889 |
); |
|
890 |
} |
|
0 | 891 |
} |
892 |
} else { |
|
893 |
$current_object = $wp_the_query->get_queried_object(); |
|
894 |
||
9 | 895 |
if ( empty( $current_object ) ) { |
0 | 896 |
return; |
9 | 897 |
} |
0 | 898 |
|
16 | 899 |
if ( ! empty( $current_object->post_type ) ) { |
900 |
$post_type_object = get_post_type_object( $current_object->post_type ); |
|
901 |
$edit_post_link = get_edit_post_link( $current_object->ID ); |
|
902 |
if ( $post_type_object |
|
903 |
&& $edit_post_link |
|
904 |
&& current_user_can( 'edit_post', $current_object->ID ) |
|
905 |
&& $post_type_object->show_in_admin_bar ) { |
|
906 |
$wp_admin_bar->add_node( |
|
907 |
array( |
|
908 |
'id' => 'edit', |
|
909 |
'title' => $post_type_object->labels->edit_item, |
|
910 |
'href' => $edit_post_link, |
|
911 |
) |
|
912 |
); |
|
913 |
} |
|
914 |
} elseif ( ! empty( $current_object->taxonomy ) ) { |
|
915 |
$tax = get_taxonomy( $current_object->taxonomy ); |
|
916 |
$edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ); |
|
917 |
if ( $tax && $edit_term_link && current_user_can( 'edit_term', $current_object->term_id ) ) { |
|
918 |
$wp_admin_bar->add_node( |
|
919 |
array( |
|
920 |
'id' => 'edit', |
|
921 |
'title' => $tax->labels->edit_item, |
|
922 |
'href' => $edit_term_link, |
|
923 |
) |
|
924 |
); |
|
925 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
926 |
} elseif ( $current_object instanceof WP_User && current_user_can( 'edit_user', $current_object->ID ) ) { |
16 | 927 |
$edit_user_link = get_edit_user_link( $current_object->ID ); |
928 |
if ( $edit_user_link ) { |
|
929 |
$wp_admin_bar->add_node( |
|
930 |
array( |
|
931 |
'id' => 'edit', |
|
932 |
'title' => __( 'Edit User' ), |
|
933 |
'href' => $edit_user_link, |
|
934 |
) |
|
935 |
); |
|
936 |
} |
|
0 | 937 |
} |
938 |
} |
|
939 |
} |
|
940 |
||
941 |
/** |
|
19 | 942 |
* Adds "Add New" menu. |
0 | 943 |
* |
944 |
* @since 3.1.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
945 |
* @since 6.5.0 Added a New Site link for network installations. |
0 | 946 |
* |
19 | 947 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
0 | 948 |
*/ |
949 |
function wp_admin_bar_new_content_menu( $wp_admin_bar ) { |
|
950 |
$actions = array(); |
|
951 |
||
952 |
$cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ); |
|
953 |
||
9 | 954 |
if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) ) { |
955 |
$actions['post-new.php'] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); |
|
956 |
} |
|
0 | 957 |
|
9 | 958 |
if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) { |
959 |
$actions['media-new.php'] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' ); |
|
960 |
} |
|
0 | 961 |
|
9 | 962 |
if ( current_user_can( 'manage_links' ) ) { |
963 |
$actions['link-add.php'] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); |
|
964 |
} |
|
0 | 965 |
|
9 | 966 |
if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) ) { |
967 |
$actions['post-new.php?post_type=page'] = array( $cpts['page']->labels->name_admin_bar, 'new-page' ); |
|
968 |
} |
|
0 | 969 |
|
970 |
unset( $cpts['post'], $cpts['page'], $cpts['attachment'] ); |
|
971 |
||
972 |
// Add any additional custom post types. |
|
973 |
foreach ( $cpts as $cpt ) { |
|
9 | 974 |
if ( ! current_user_can( $cpt->cap->create_posts ) ) { |
0 | 975 |
continue; |
9 | 976 |
} |
0 | 977 |
|
9 | 978 |
$key = 'post-new.php?post_type=' . $cpt->name; |
0 | 979 |
$actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name ); |
980 |
} |
|
981 |
// Avoid clash with parent node and a 'content' post type. |
|
9 | 982 |
if ( isset( $actions['post-new.php?post_type=content'] ) ) { |
0 | 983 |
$actions['post-new.php?post_type=content'][1] = 'add-new-content'; |
9 | 984 |
} |
0 | 985 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
986 |
if ( current_user_can( 'create_users' ) || ( is_multisite() && current_user_can( 'promote_users' ) ) ) { |
9 | 987 |
$actions['user-new.php'] = array( _x( 'User', 'add new from admin bar' ), 'new-user' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
} |
0 | 989 |
|
9 | 990 |
if ( ! $actions ) { |
0 | 991 |
return; |
9 | 992 |
} |
0 | 993 |
|
18 | 994 |
$title = '<span class="ab-icon" aria-hidden="true"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>'; |
0 | 995 |
|
16 | 996 |
$wp_admin_bar->add_node( |
9 | 997 |
array( |
998 |
'id' => 'new-content', |
|
999 |
'title' => $title, |
|
1000 |
'href' => admin_url( current( array_keys( $actions ) ) ), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1001 |
'meta' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1002 |
'menu_title' => _x( 'New', 'admin bar menu group label' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1003 |
), |
9 | 1004 |
) |
1005 |
); |
|
0 | 1006 |
|
1007 |
foreach ( $actions as $link => $action ) { |
|
1008 |
list( $title, $id ) = $action; |
|
1009 |
||
16 | 1010 |
$wp_admin_bar->add_node( |
9 | 1011 |
array( |
1012 |
'parent' => 'new-content', |
|
1013 |
'id' => $id, |
|
1014 |
'title' => $title, |
|
1015 |
'href' => admin_url( $link ), |
|
1016 |
) |
|
1017 |
); |
|
0 | 1018 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1019 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1020 |
if ( is_multisite() && current_user_can( 'create_sites' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1021 |
$wp_admin_bar->add_node( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1022 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1023 |
'parent' => 'new-content', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1024 |
'id' => 'add-new-site', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1025 |
'title' => _x( 'Site', 'add new from admin bar' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1026 |
'href' => network_admin_url( 'site-new.php' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1027 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1028 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1029 |
} |
0 | 1030 |
} |
1031 |
||
1032 |
/** |
|
19 | 1033 |
* Adds edit comments link with awaiting moderation count bubble. |
0 | 1034 |
* |
1035 |
* @since 3.1.0 |
|
1036 |
* |
|
19 | 1037 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
0 | 1038 |
*/ |
1039 |
function wp_admin_bar_comments_menu( $wp_admin_bar ) { |
|
9 | 1040 |
if ( ! current_user_can( 'edit_posts' ) ) { |
0 | 1041 |
return; |
9 | 1042 |
} |
0 | 1043 |
|
9 | 1044 |
$awaiting_mod = wp_count_comments(); |
1045 |
$awaiting_mod = $awaiting_mod->moderated; |
|
1046 |
$awaiting_text = sprintf( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1047 |
/* translators: Hidden accessibility text. %s: Number of comments. */ |
9 | 1048 |
_n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ), |
1049 |
number_format_i18n( $awaiting_mod ) |
|
1050 |
); |
|
0 | 1051 |
|
18 | 1052 |
$icon = '<span class="ab-icon" aria-hidden="true"></span>'; |
9 | 1053 |
$title = '<span class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>'; |
1054 |
$title .= '<span class="screen-reader-text comments-in-moderation-text">' . $awaiting_text . '</span>'; |
|
0 | 1055 |
|
16 | 1056 |
$wp_admin_bar->add_node( |
9 | 1057 |
array( |
1058 |
'id' => 'comments', |
|
1059 |
'title' => $icon . $title, |
|
1060 |
'href' => admin_url( 'edit-comments.php' ), |
|
1061 |
) |
|
1062 |
); |
|
0 | 1063 |
} |
1064 |
||
1065 |
/** |
|
19 | 1066 |
* Adds appearance submenu items to the "Site Name" menu. |
0 | 1067 |
* |
1068 |
* @since 3.1.0 |
|
1069 |
* |
|
19 | 1070 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
0 | 1071 |
*/ |
1072 |
function wp_admin_bar_appearance_menu( $wp_admin_bar ) { |
|
9 | 1073 |
$wp_admin_bar->add_group( |
1074 |
array( |
|
1075 |
'parent' => 'site-name', |
|
1076 |
'id' => 'appearance', |
|
1077 |
) |
|
1078 |
); |
|
0 | 1079 |
|
5 | 1080 |
if ( current_user_can( 'switch_themes' ) ) { |
16 | 1081 |
$wp_admin_bar->add_node( |
9 | 1082 |
array( |
1083 |
'parent' => 'appearance', |
|
1084 |
'id' => 'themes', |
|
1085 |
'title' => __( 'Themes' ), |
|
1086 |
'href' => admin_url( 'themes.php' ), |
|
1087 |
) |
|
1088 |
); |
|
5 | 1089 |
} |
1090 |
||
1091 |
if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
1092 |
return; |
|
1093 |
} |
|
0 | 1094 |
|
9 | 1095 |
if ( current_theme_supports( 'widgets' ) ) { |
16 | 1096 |
$wp_admin_bar->add_node( |
9 | 1097 |
array( |
1098 |
'parent' => 'appearance', |
|
1099 |
'id' => 'widgets', |
|
1100 |
'title' => __( 'Widgets' ), |
|
1101 |
'href' => admin_url( 'widgets.php' ), |
|
1102 |
) |
|
1103 |
); |
|
5 | 1104 |
} |
1105 |
||
9 | 1106 |
if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) { |
16 | 1107 |
$wp_admin_bar->add_node( |
9 | 1108 |
array( |
1109 |
'parent' => 'appearance', |
|
1110 |
'id' => 'menus', |
|
1111 |
'title' => __( 'Menus' ), |
|
1112 |
'href' => admin_url( 'nav-menus.php' ), |
|
1113 |
) |
|
1114 |
); |
|
1115 |
} |
|
0 | 1116 |
|
5 | 1117 |
if ( current_theme_supports( 'custom-background' ) ) { |
16 | 1118 |
$wp_admin_bar->add_node( |
9 | 1119 |
array( |
1120 |
'parent' => 'appearance', |
|
1121 |
'id' => 'background', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1122 |
'title' => _x( 'Background', 'custom background' ), |
9 | 1123 |
'href' => admin_url( 'themes.php?page=custom-background' ), |
1124 |
'meta' => array( |
|
1125 |
'class' => 'hide-if-customize', |
|
1126 |
), |
|
1127 |
) |
|
1128 |
); |
|
5 | 1129 |
} |
0 | 1130 |
|
5 | 1131 |
if ( current_theme_supports( 'custom-header' ) ) { |
16 | 1132 |
$wp_admin_bar->add_node( |
9 | 1133 |
array( |
1134 |
'parent' => 'appearance', |
|
1135 |
'id' => 'header', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1136 |
'title' => _x( 'Header', 'custom image header' ), |
9 | 1137 |
'href' => admin_url( 'themes.php?page=custom-header' ), |
1138 |
'meta' => array( |
|
1139 |
'class' => 'hide-if-customize', |
|
1140 |
), |
|
1141 |
) |
|
1142 |
); |
|
5 | 1143 |
} |
0 | 1144 |
} |
1145 |
||
1146 |
/** |
|
19 | 1147 |
* Provides an update link if theme/plugin/core updates are available. |
0 | 1148 |
* |
1149 |
* @since 3.1.0 |
|
1150 |
* |
|
19 | 1151 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
0 | 1152 |
*/ |
1153 |
function wp_admin_bar_updates_menu( $wp_admin_bar ) { |
|
1154 |
||
1155 |
$update_data = wp_get_update_data(); |
|
1156 |
||
9 | 1157 |
if ( ! $update_data['counts']['total'] ) { |
0 | 1158 |
return; |
9 | 1159 |
} |
0 | 1160 |
|
18 | 1161 |
$updates_text = sprintf( |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1162 |
/* translators: Hidden accessibility text. %s: Total number of updates available. */ |
18 | 1163 |
_n( '%s update available', '%s updates available', $update_data['counts']['total'] ), |
1164 |
number_format_i18n( $update_data['counts']['total'] ) |
|
1165 |
); |
|
1166 |
||
1167 |
$icon = '<span class="ab-icon" aria-hidden="true"></span>'; |
|
1168 |
$title = '<span class="ab-label" aria-hidden="true">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>'; |
|
1169 |
$title .= '<span class="screen-reader-text updates-available-text">' . $updates_text . '</span>'; |
|
0 | 1170 |
|
16 | 1171 |
$wp_admin_bar->add_node( |
9 | 1172 |
array( |
1173 |
'id' => 'updates', |
|
18 | 1174 |
'title' => $icon . $title, |
9 | 1175 |
'href' => network_admin_url( 'update-core.php' ), |
1176 |
) |
|
1177 |
); |
|
0 | 1178 |
} |
1179 |
||
1180 |
/** |
|
19 | 1181 |
* Adds search form. |
0 | 1182 |
* |
1183 |
* @since 3.3.0 |
|
1184 |
* |
|
19 | 1185 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
0 | 1186 |
*/ |
1187 |
function wp_admin_bar_search_menu( $wp_admin_bar ) { |
|
9 | 1188 |
if ( is_admin() ) { |
0 | 1189 |
return; |
9 | 1190 |
} |
0 | 1191 |
|
1192 |
$form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">'; |
|
1193 |
$form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />'; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1194 |
$form .= '<label for="adminbar-search" class="screen-reader-text">' . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1195 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1196 |
__( 'Search' ) . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1197 |
'</label>'; |
18 | 1198 |
$form .= '<input type="submit" class="adminbar-button" value="' . __( 'Search' ) . '" />'; |
0 | 1199 |
$form .= '</form>'; |
1200 |
||
16 | 1201 |
$wp_admin_bar->add_node( |
9 | 1202 |
array( |
1203 |
'parent' => 'top-secondary', |
|
1204 |
'id' => 'search', |
|
1205 |
'title' => $form, |
|
1206 |
'meta' => array( |
|
1207 |
'class' => 'admin-bar-search', |
|
1208 |
'tabindex' => -1, |
|
1209 |
), |
|
0 | 1210 |
) |
9 | 1211 |
); |
1212 |
} |
|
1213 |
||
1214 |
/** |
|
19 | 1215 |
* Adds a link to exit recovery mode when Recovery Mode is active. |
9 | 1216 |
* |
1217 |
* @since 5.2.0 |
|
1218 |
* |
|
19 | 1219 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
9 | 1220 |
*/ |
1221 |
function wp_admin_bar_recovery_mode_menu( $wp_admin_bar ) { |
|
1222 |
if ( ! wp_is_recovery_mode() ) { |
|
1223 |
return; |
|
1224 |
} |
|
1225 |
||
1226 |
$url = wp_login_url(); |
|
1227 |
$url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url ); |
|
1228 |
$url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION ); |
|
1229 |
||
16 | 1230 |
$wp_admin_bar->add_node( |
9 | 1231 |
array( |
1232 |
'parent' => 'top-secondary', |
|
1233 |
'id' => 'recovery-mode', |
|
1234 |
'title' => __( 'Exit Recovery Mode' ), |
|
1235 |
'href' => $url, |
|
1236 |
) |
|
1237 |
); |
|
0 | 1238 |
} |
1239 |
||
1240 |
/** |
|
19 | 1241 |
* Adds secondary menus. |
0 | 1242 |
* |
1243 |
* @since 3.3.0 |
|
1244 |
* |
|
19 | 1245 |
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
0 | 1246 |
*/ |
1247 |
function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) { |
|
9 | 1248 |
$wp_admin_bar->add_group( |
1249 |
array( |
|
1250 |
'id' => 'top-secondary', |
|
1251 |
'meta' => array( |
|
1252 |
'class' => 'ab-top-secondary', |
|
1253 |
), |
|
1254 |
) |
|
1255 |
); |
|
0 | 1256 |
|
9 | 1257 |
$wp_admin_bar->add_group( |
1258 |
array( |
|
1259 |
'parent' => 'wp-logo', |
|
1260 |
'id' => 'wp-logo-external', |
|
1261 |
'meta' => array( |
|
1262 |
'class' => 'ab-sub-secondary', |
|
1263 |
), |
|
1264 |
) |
|
1265 |
); |
|
0 | 1266 |
} |
1267 |
||
1268 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1269 |
* Enqueues inline style to hide the admin bar when printing. |
0 | 1270 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1271 |
* @since 6.4.0 |
0 | 1272 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1273 |
function wp_enqueue_admin_bar_header_styles() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1274 |
// Back-compat for plugins that disable functionality by unhooking this action. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1275 |
$action = is_admin() ? 'admin_head' : 'wp_head'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1276 |
if ( ! has_action( $action, 'wp_admin_bar_header' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1277 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1278 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1279 |
remove_action( $action, 'wp_admin_bar_header' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1280 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1281 |
wp_add_inline_style( 'admin-bar', '@media print { #wpadminbar { display:none; } }' ); |
0 | 1282 |
} |
1283 |
||
1284 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1285 |
* Enqueues inline bump styles to make room for the admin bar. |
0 | 1286 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1287 |
* @since 6.4.0 |
0 | 1288 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1289 |
function wp_enqueue_admin_bar_bump_styles() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1290 |
if ( current_theme_supports( 'admin-bar' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1291 |
$admin_bar_args = get_theme_support( 'admin-bar' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1292 |
$header_callback = $admin_bar_args[0]['callback']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1293 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1294 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1295 |
if ( empty( $header_callback ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1296 |
$header_callback = '_admin_bar_bump_cb'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1297 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1298 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1299 |
if ( '_admin_bar_bump_cb' !== $header_callback ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1300 |
return; |
5 | 1301 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1302 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1303 |
// Back-compat for plugins that disable functionality by unhooking this action. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1304 |
if ( ! has_action( 'wp_head', $header_callback ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1305 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1306 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1307 |
remove_action( 'wp_head', $header_callback ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1308 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1309 |
$css = ' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1310 |
@media screen { html { margin-top: 32px !important; } } |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1311 |
@media screen and ( max-width: 782px ) { html { margin-top: 46px !important; } } |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1312 |
'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1313 |
wp_add_inline_style( 'admin-bar', $css ); |
0 | 1314 |
} |
1315 |
||
1316 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
* Sets the display status of the admin bar. |
0 | 1318 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1319 |
* This can be called immediately upon plugin load. It does not need to be called |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1320 |
* from a function hooked to the {@see 'init'} action. |
0 | 1321 |
* |
1322 |
* @since 3.1.0 |
|
1323 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
* @global bool $show_admin_bar |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1325 |
* |
0 | 1326 |
* @param bool $show Whether to allow the admin bar to show. |
1327 |
*/ |
|
1328 |
function show_admin_bar( $show ) { |
|
1329 |
global $show_admin_bar; |
|
1330 |
$show_admin_bar = (bool) $show; |
|
1331 |
} |
|
1332 |
||
1333 |
/** |
|
9 | 1334 |
* Determines whether the admin bar should be showing. |
1335 |
* |
|
1336 |
* For more information on this and similar theme functions, check out |
|
1337 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
1338 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 1339 |
* |
1340 |
* @since 3.1.0 |
|
1341 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
* @global bool $show_admin_bar |
19 | 1343 |
* @global string $pagenow The filename of the current screen. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
* |
0 | 1345 |
* @return bool Whether the admin bar should be showing. |
1346 |
*/ |
|
1347 |
function is_admin_bar_showing() { |
|
1348 |
global $show_admin_bar, $pagenow; |
|
1349 |
||
1350 |
// For all these types of requests, we never want an admin bar. |
|
9 | 1351 |
if ( defined( 'XMLRPC_REQUEST' ) || defined( 'DOING_AJAX' ) || defined( 'IFRAME_REQUEST' ) || wp_is_json_request() ) { |
0 | 1352 |
return false; |
9 | 1353 |
} |
0 | 1354 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1355 |
if ( is_embed() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1356 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1357 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1358 |
|
0 | 1359 |
// Integrated into the admin. |
9 | 1360 |
if ( is_admin() ) { |
0 | 1361 |
return true; |
9 | 1362 |
} |
0 | 1363 |
|
1364 |
if ( ! isset( $show_admin_bar ) ) { |
|
16 | 1365 |
if ( ! is_user_logged_in() || 'wp-login.php' === $pagenow ) { |
0 | 1366 |
$show_admin_bar = false; |
1367 |
} else { |
|
1368 |
$show_admin_bar = _get_admin_bar_pref(); |
|
1369 |
} |
|
1370 |
} |
|
1371 |
||
5 | 1372 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
* Filters whether to show the admin bar. |
5 | 1374 |
* |
1375 |
* Returning false to this hook is the recommended way to hide the admin bar. |
|
1376 |
* The user's display preference is used for logged in users. |
|
1377 |
* |
|
1378 |
* @since 3.1.0 |
|
1379 |
* |
|
1380 |
* @param bool $show_admin_bar Whether the admin bar should be shown. Default false. |
|
1381 |
*/ |
|
0 | 1382 |
$show_admin_bar = apply_filters( 'show_admin_bar', $show_admin_bar ); |
1383 |
||
1384 |
return $show_admin_bar; |
|
1385 |
} |
|
1386 |
||
1387 |
/** |
|
19 | 1388 |
* Retrieves the admin bar display preference of a user. |
0 | 1389 |
* |
1390 |
* @since 3.1.0 |
|
1391 |
* @access private |
|
1392 |
* |
|
1393 |
* @param string $context Context of this preference check. Defaults to 'front'. The 'admin' |
|
16 | 1394 |
* preference is no longer used. |
1395 |
* @param int $user Optional. ID of the user to check, defaults to 0 for current user. |
|
0 | 1396 |
* @return bool Whether the admin bar should be showing for this user. |
1397 |
*/ |
|
1398 |
function _get_admin_bar_pref( $context = 'front', $user = 0 ) { |
|
1399 |
$pref = get_user_option( "show_admin_bar_{$context}", $user ); |
|
9 | 1400 |
if ( false === $pref ) { |
0 | 1401 |
return true; |
9 | 1402 |
} |
0 | 1403 |
|
1404 |
return 'true' === $pref; |
|
1405 |
} |