Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #139 from xwp/fix/locate-plugin
Browse files Browse the repository at this point in the history
Remove wp-content directory requirement
  • Loading branch information
westonruter authored Jul 16, 2017
2 parents 0f92f0d + a388bb9 commit 71c964a
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions php/class-plugin-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,14 @@ public function locate_plugin() {
if ( '/' !== \DIRECTORY_SEPARATOR ) {
$file_name = str_replace( \DIRECTORY_SEPARATOR, '/', $file_name ); // Windows compat.
}
$plugin_dir = preg_replace( '#(.*plugins[^/]*/[^/]+)(/.*)?#', '$1', $file_name, 1, $count );
if ( 0 === $count ) {
throw new Exception( "Class not located within a directory tree containing 'plugins': $file_name" );
}

// Make sure that we can reliably get the relative path inside of the content directory.
$plugin_path = $this->relative_path( $plugin_dir, 'wp-content', \DIRECTORY_SEPARATOR );
if ( '' === $plugin_path ) {
throw new Exception( 'Plugin dir is not inside of the `wp-content` directory' );
}
$plugin_dir = dirname( dirname( $file_name ) );
$plugin_path = $this->relative_path( $plugin_dir, basename( content_url() ), \DIRECTORY_SEPARATOR );

$dir_url = content_url( trailingslashit( $plugin_path ) );
$dir_path = $plugin_dir;
$dir_url = content_url( trailingslashit( $plugin_path ) );
$dir_path = $plugin_dir;
$dir_basename = basename( $plugin_dir );

return compact( 'dir_url', 'dir_path', 'dir_basename' );
}

Expand Down

0 comments on commit 71c964a

Please sign in to comment.