Created
March 28, 2016 12:00
-
-
Save q2amarket/fdc658f7f645a2c14b2c to your computer and use it in GitHub Desktop.
Get plugin path and url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* To set pluign path I used below | |
* | |
* Since my core class is in sub-directory of plugin, I had to point upward to get root directory | |
*/ | |
define( 'Q2AM_DIR', q2am_trailingslash_dir( realpath( __DIR__ . '/../..' ) ) ); | |
/* | |
* To set pluign url | |
* | |
* I have done bit it different way. Maybe this is not the best way | |
* but it worked for me. If you find better way let me know | |
*/ | |
$q2am_dir = str_replace( [ '/', '\\' ], '/', Q2AM_DIR ); // this will gives pluign root directory | |
$plugin_dir = str_replace( [ '/', '\\' ], '/', QA_PLUGIN_DIR ); // this will give qa-plugin directory path | |
$path = explode( '/', q2am_untrailingslash( $q2am_dir ) ); //Q2A Market function | |
$qa_plugin = explode( '/', q2am_untrailingslash( $plugin_dir ) ); //Q2A Market function | |
$key = array_search( end( $qa_plugin ), $path ); | |
if ( ( $key == array_search( end( $qa_plugin ), $path ) ) !== FALSE ) { | |
$plugin_path = array_slice( $path, $key ); | |
} | |
$q2am_url = implode( '/', $plugin_path ); | |
// Finally, define the plugin url | |
define( 'Q2AM_URL', q2am_trailingslash( q2am_trailingslash( qa_opt( 'site_url' ) ) . $q2am_url ) ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment