Skip to content

Instantly share code, notes, and snippets.

@q2amarket
Created March 28, 2016 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save q2amarket/fdc658f7f645a2c14b2c to your computer and use it in GitHub Desktop.
Save q2amarket/fdc658f7f645a2c14b2c to your computer and use it in GitHub Desktop.
Get plugin path and url
<?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