From 4a7e4d6a0dcb9f61687f0eaf29e318aed2372bfc Mon Sep 17 00:00:00 2001 From: James Morrison Date: Wed, 6 Apr 2022 18:17:58 +0100 Subject: [PATCH] Updated to v1.0.0; added level above WP to check. --- composer.json | 5 ++--- display-git-branch.php | 4 ++-- includes/core.php | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index 8463528..fd1ebb8 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "jamesmorrison/display-git-branch", "description": "Display Git Branch", "homepage": "https://github.com/jamesmorrison/display-git-branch", - "version": "0.1.1", + "version": "1.0.0", "keywords": [ "wordpress" ], @@ -11,8 +11,7 @@ "authors": [ { "name": "James Morrison", - "email": "james@morrison.uk", - "homepage": "https://morrison.uk" + "homepage": "https://jamesmorrison.uk" } ], "support": { diff --git a/display-git-branch.php b/display-git-branch.php index 6d5b1e1..3e8c096 100644 --- a/display-git-branch.php +++ b/display-git-branch.php @@ -5,7 +5,7 @@ * Description: Shows which Git branch you're working on. Highlights configurable restricted branches in red. * Version: 0.1.1 * Author: James Morrison - * Author URI: https://morrison.uk/ + * Author URI: https://jamesmorrison.uk/ * Text Domain: display-git-branch * * @package Display_Git_Branch @@ -15,7 +15,7 @@ defined( 'ABSPATH' ) || die(); // Useful global constants -define( 'DISPLAY_GIT_BRANCH_VERSION', '0.1.1' ); +define( 'DISPLAY_GIT_BRANCH_VERSION', '1.0.0' ); define( 'DISPLAY_GIT_BRANCH_URL', plugin_dir_url( __FILE__ ) ); define( 'DISPLAY_GIT_BRANCH_PATH', dirname( __FILE__ ) . '/' ); define( 'DISPLAY_GIT_BRANCH_INC', DISPLAY_GIT_BRANCH_PATH . 'includes/' ); diff --git a/includes/core.php b/includes/core.php index fbe7f26..b98ad93 100644 --- a/includes/core.php +++ b/includes/core.php @@ -47,7 +47,7 @@ function wp_admin_bar( $wp_admin_bar ) { [ 'id' => 'show-git-branch', /* Translators: The branch name */ - 'title' => sprintf( __( 'Git branch: %s', 'display-git-branch' ), branch() ), + 'title' => sprintf( __( 'Git branch: %s', 'display-git-branch' ), esc_attr( branch() ) ), ] ); @@ -64,10 +64,12 @@ function branch() { $branch = esc_html( __( 'Not detected', 'display-git-branch' ) ); // Paths to search for a git branch - $paths = apply_filters( 'display_git_branch_paths', + $paths = apply_filters( + 'display_git_branch_paths', [ - trailingslashit( WP_CONTENT_DIR ), // Content directory - trailingslashit( ABSPATH ), // Site root + trailingslashit( WP_CONTENT_DIR ), // Content directory + trailingslashit( ABSPATH ), // Site root + trailingslashit( dirname( ABSPATH ) ), // One level above site ] ); @@ -75,7 +77,7 @@ function branch() { // PHPCS suggests wp_remote_get instead of file_get_contents - this does not work as our path is relative foreach ( $paths as $location ) { if ( file_exists( $location . '.git/HEAD' ) ) { - $branch = str_replace( "\n", '', implode( '/', array_slice( explode( '/', file_get_contents( $location . '.git/HEAD' ) ), 2 ) ) ); + $branch = str_replace( "\n", '', implode( '/', array_slice( explode( '/', file_get_contents( $location . '.git/HEAD' ) ), 2 ) ) ); // phpcs:ignore break; } } @@ -92,11 +94,11 @@ function branch() { */ function restricted_branches() { - return apply_filters( 'display_git_branch_restricted_branches', + return apply_filters( + 'display_git_branch_restricted_branches', [ 'trunk', - 'master', // WARNING: this will be deprecated in a future release - 'develop', // WARNING: this will be deprecated in a future release + 'develop', ] ); @@ -108,7 +110,6 @@ function restricted_branches() { * Defines the style for the WP Admin Bar node */ function style() { - ?>