直接访问插件时重新定义插件目录路径


Redefining plugin directory path when accessing a plugin directly?

因此,我试图为Wordpress创建一个插件,使其也可以合并到主题中并直接访问。经过一些挖掘,我已经找到了在类尚未加载的情况下如何包含插件的方法,但我很难为插件所需的任何CSS或js重新定义插件路径。有没有办法在函数中重新定义插件URL和目录路径,使其指向正确的目录并覆盖插件的默认值?

尝试使用此方法,将退出部分更改为所需的部分。重定向或其他

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

我能够通过创建一个过滤器来解决这个问题:

define( 'THEME_MODE', apply_filters( 'theme_mode', false ) );

然后创建if/else函数:

if ( false == THEME_MODE) {
        define( 'PLUGIN_URI', plugin_dir_url( __FILE__ ));
        define( 'PLUGIN_DIR', plugin_dir_url( __FILE__ ));
  } else {
    if ( true == THEME_MODE ) {
          $path = ltrim( end( @explode( get_stylesheet(), str_replace( '''', '/', dirname( __FILE__ ) ) ) ), '/' );
          define( 'PLUGIN_URI',  trailingslashit(trailingslashit(get_bloginfo('template_directory') ). $path));
          define( 'PLUGIN_DIR', trailingslashit(trailingslashit(get_bloginfo('template_directory') ) . $path ));
    }
  }

然后我调用了functions.php 中的函数

add_action('after_setup_theme', 'load_shortcodes');
add_filter( 'theme_mode', '__return_true' );
function load_shortcodes() {
if( ! class_exists('Shortcodes') ) {    
    // load if not already loaded
    include_once( TEMPLATEPATH. '/shortcodes/aa-shortcodes.php' );      
    }
}