Skip to content

Commit

Permalink
fixed bug on subfolder installations
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph committed Jun 30, 2016
1 parent de61a0d commit d77fbc6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Tags: admin bar, admin, development, staging
* Requires at least: 4.0
* Tested up to: 4.5.3
* Stable tag: 0.9.4
* Stable tag: 0.9.5
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -48,6 +48,9 @@ function sites_filter( $sites ) {

## Changelog ##

### 0.9.5 ###
* fixed bug for subfolder installations

### 0.9.4 ###
* added an export and import option
* minor improvements
Expand Down
19 changes: 15 additions & 4 deletions apermo-adminbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @wordpress-plugin
* Plugin Name: Apermo AdminBar
* Version: 0.9.4
* Version: 0.9.5
* Description: A simple plugin that allows you to add custom links to the AdminBar, navigation between your live and dev systems
* Author: Christoph Daum
* Author URI: http://apermo.de/
Expand Down Expand Up @@ -263,13 +263,12 @@ public function admin_bar_filter( $wp_admin_bar ) {
'href' => esc_url( $site['url'] ),
) );
// Check if we are on a different page than the homepage.
// Todo: Will probably break if WordPress installed in a subdirectory.
if ( strlen( $_SERVER['REQUEST_URI'] ) > 1 ) {
if ( strlen( $this->get_request() ) > 1 ) {
$wp_admin_bar->add_node( array(
'id' => esc_attr( 'apermo_adminbar_menu_' . $key . '-same' ),
'title' => esc_html( $site['name'] ) . ' ' . __( '(Same page)', 'apermo-adminbar' ),
'parent' => 'site-name',
'href' => esc_url( $site['url'] . $_SERVER['REQUEST_URI'] ),
'href' => esc_url( $site['url'] . $this->get_request() ),
) );
}
}
Expand All @@ -280,6 +279,18 @@ public function admin_bar_filter( $wp_admin_bar ) {
}
}

/**
* Get the Request Part that is not Subfolder for the WordPress installation.
*/
public function get_request() {
$request = esc_url_raw( $_SERVER['REQUEST_URI'] );
$url = parse_url( $this->sites[ $this->current ]['url'] );
if ( isset( $url['path'] ) && 0 === strpos( $request, $url['path'] ) ) {
return substr( $request, strlen( $url['path'] ) );
}
return $request;
}

/**
* Options page callback
*
Expand Down

0 comments on commit d77fbc6

Please sign in to comment.