@@ -47,7 +47,7 @@ function wp_admin_bar( $wp_admin_bar ) {
4747 [
4848 'id ' => 'show-git-branch ' ,
4949 /* Translators: The branch name */
50- 'title ' => sprintf ( __ ( 'Git branch: %s ' , 'display-git-branch ' ), branch () ),
50+ 'title ' => sprintf ( __ ( 'Git branch: %s ' , 'display-git-branch ' ), esc_attr ( branch () ) ),
5151 ]
5252 );
5353
@@ -64,18 +64,20 @@ function branch() {
6464 $ branch = esc_html ( __ ( 'Not detected ' , 'display-git-branch ' ) );
6565
6666 // Paths to search for a git branch
67- $ paths = apply_filters ( 'display_git_branch_paths ' ,
67+ $ paths = apply_filters (
68+ 'display_git_branch_paths ' ,
6869 [
69- trailingslashit ( WP_CONTENT_DIR ), // Content directory
70- trailingslashit ( ABSPATH ), // Site root
70+ trailingslashit ( WP_CONTENT_DIR ), // Content directory
71+ trailingslashit ( ABSPATH ), // Site root
72+ trailingslashit ( dirname ( ABSPATH ) ), // One level above site
7173 ]
7274 );
7375
7476 // Run through the paths and check each, break on success
7577 // PHPCS suggests wp_remote_get instead of file_get_contents - this does not work as our path is relative
7678 foreach ( $ paths as $ location ) {
7779 if ( file_exists ( $ location . '.git/HEAD ' ) ) {
78- $ branch = str_replace ( "\n" , '' , implode ( '/ ' , array_slice ( explode ( '/ ' , file_get_contents ( $ location . '.git/HEAD ' ) ), 2 ) ) );
80+ $ branch = str_replace ( "\n" , '' , implode ( '/ ' , array_slice ( explode ( '/ ' , file_get_contents ( $ location . '.git/HEAD ' ) ), 2 ) ) ); // phpcs:ignore
7981 break ;
8082 }
8183 }
@@ -92,11 +94,11 @@ function branch() {
9294 */
9395function restricted_branches () {
9496
95- return apply_filters ( 'display_git_branch_restricted_branches ' ,
97+ return apply_filters (
98+ 'display_git_branch_restricted_branches ' ,
9699 [
97100 'trunk ' ,
98- 'master ' , // WARNING: this will be deprecated in a future release
99- 'develop ' , // WARNING: this will be deprecated in a future release
101+ 'develop ' ,
100102 ]
101103 );
102104
@@ -108,7 +110,6 @@ function restricted_branches() {
108110 * Defines the style for the WP Admin Bar node
109111 */
110112function style () {
111-
112113 ?>
113114 <style type="text/css">#wp-admin-bar-show-git-branch .ab-item:before { content: "\f237"; top: 2px; }</style>
114115 <?php
@@ -121,7 +122,6 @@ function style() {
121122 * Defines the style for the WP Admin Bar node
122123 */
123124function warning_style () {
124-
125125 ?>
126126 <style type="text/css">#wp-admin-bar-show-git-branch .ab-item { background: #c00; }</style>
127127 <?php
0 commit comments