@@ -47,7 +47,7 @@ function wp_admin_bar( $wp_admin_bar ) {
47
47
[
48
48
'id ' => 'show-git-branch ' ,
49
49
/* 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 () ) ),
51
51
]
52
52
);
53
53
@@ -64,18 +64,20 @@ function branch() {
64
64
$ branch = esc_html ( __ ( 'Not detected ' , 'display-git-branch ' ) );
65
65
66
66
// Paths to search for a git branch
67
- $ paths = apply_filters ( 'display_git_branch_paths ' ,
67
+ $ paths = apply_filters (
68
+ 'display_git_branch_paths ' ,
68
69
[
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
71
73
]
72
74
);
73
75
74
76
// Run through the paths and check each, break on success
75
77
// PHPCS suggests wp_remote_get instead of file_get_contents - this does not work as our path is relative
76
78
foreach ( $ paths as $ location ) {
77
79
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
79
81
break ;
80
82
}
81
83
}
@@ -92,11 +94,11 @@ function branch() {
92
94
*/
93
95
function restricted_branches () {
94
96
95
- return apply_filters ( 'display_git_branch_restricted_branches ' ,
97
+ return apply_filters (
98
+ 'display_git_branch_restricted_branches ' ,
96
99
[
97
100
'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 ' ,
100
102
]
101
103
);
102
104
@@ -108,7 +110,6 @@ function restricted_branches() {
108
110
* Defines the style for the WP Admin Bar node
109
111
*/
110
112
function style () {
111
-
112
113
?>
113
114
<style type="text/css">#wp-admin-bar-show-git-branch .ab-item:before { content: "\f237"; top: 2px; }</style>
114
115
<?php
@@ -121,7 +122,6 @@ function style() {
121
122
* Defines the style for the WP Admin Bar node
122
123
*/
123
124
function warning_style () {
124
-
125
125
?>
126
126
<style type="text/css">#wp-admin-bar-show-git-branch .ab-item { background: #c00; }</style>
127
127
<?php
0 commit comments