Skip to content

Commit

Permalink
Merge pull request #3 from jamesmorrison/feature/v1.0.0-updates
Browse files Browse the repository at this point in the history
Updated to v1.0.0; added level above WP to check.
  • Loading branch information
jamesmorrison authored Apr 6, 2022
2 parents 5accd3f + 4a7e4d6 commit 3e37f94
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand All @@ -11,8 +11,7 @@
"authors": [
{
"name": "James Morrison",
"email": "[email protected]",
"homepage": "https://morrison.uk"
"homepage": "https://jamesmorrison.uk"
}
],
"support": {
Expand Down
4 changes: 2 additions & 2 deletions display-git-branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/' );
Expand Down
20 changes: 10 additions & 10 deletions includes/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) ),
]
);

Expand All @@ -64,18 +64,20 @@ 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
]
);

// Run through the paths and check each, break on success
// 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;
}
}
Expand All @@ -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',
]
);

Expand All @@ -108,7 +110,6 @@ function restricted_branches() {
* Defines the style for the WP Admin Bar node
*/
function style() {

?>
<style type="text/css">#wp-admin-bar-show-git-branch .ab-item:before { content: "\f237"; top: 2px; }</style>
<?php
Expand All @@ -121,7 +122,6 @@ function style() {
* Defines the style for the WP Admin Bar node
*/
function warning_style() {

?>
<style type="text/css">#wp-admin-bar-show-git-branch .ab-item { background: #c00; }</style>
<?php
Expand Down

0 comments on commit 3e37f94

Please sign in to comment.