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

Remove wp-content directory requirement #139

Merged
merged 1 commit into from
Jul 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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