Skip to content

Commit 3e37f94

Browse files
Merge pull request #3 from jamesmorrison/feature/v1.0.0-updates
Updated to v1.0.0; added level above WP to check.
2 parents 5accd3f + 4a7e4d6 commit 3e37f94

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "jamesmorrison/display-git-branch",
33
"description": "Display Git Branch",
44
"homepage": "https://github.com/jamesmorrison/display-git-branch",
5-
"version": "0.1.1",
5+
"version": "1.0.0",
66
"keywords": [
77
"wordpress"
88
],
@@ -11,8 +11,7 @@
1111
"authors": [
1212
{
1313
"name": "James Morrison",
14-
"email": "[email protected]",
15-
"homepage": "https://morrison.uk"
14+
"homepage": "https://jamesmorrison.uk"
1615
}
1716
],
1817
"support": {

display-git-branch.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Shows which Git branch you're working on. Highlights configurable restricted branches in red.
66
* Version: 0.1.1
77
* Author: James Morrison
8-
* Author URI: https://morrison.uk/
8+
* Author URI: https://jamesmorrison.uk/
99
* Text Domain: display-git-branch
1010
*
1111
* @package Display_Git_Branch
@@ -15,7 +15,7 @@
1515
defined( 'ABSPATH' ) || die();
1616

1717
// Useful global constants
18-
define( 'DISPLAY_GIT_BRANCH_VERSION', '0.1.1' );
18+
define( 'DISPLAY_GIT_BRANCH_VERSION', '1.0.0' );
1919
define( 'DISPLAY_GIT_BRANCH_URL', plugin_dir_url( __FILE__ ) );
2020
define( 'DISPLAY_GIT_BRANCH_PATH', dirname( __FILE__ ) . '/' );
2121
define( 'DISPLAY_GIT_BRANCH_INC', DISPLAY_GIT_BRANCH_PATH . 'includes/' );

includes/core.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
9395
function 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
*/
110112
function 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
*/
123124
function 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

Comments
 (0)