admin管理员组文章数量:1279044
before I start the topic, I want you to know that I am aware of what I do and the risk and missing the updates and missing security and etc.
I want to put any plugin in my WordPress theme directory.
for example adding woocommerce plugin in wp-content/themes/my-theme-directory
and I want the plugins directory totally clean of any other plugin.
the solution for Advance Custom Fields plugin is like this:
// Define path and URL to the ACF plugin.
define( 'MY_ACF_PATH', get_stylesheet_directory() . '/includes/acf/' );
define( 'MY_ACF_URL', get_stylesheet_directory_uri() . '/includes/acf/' );
// Include the ACF plugin.
include_once( MY_ACF_PATH . 'acf.php' );
// Customize the url setting to fix incorrect asset URLs.
add_filter('acf/settings/url', 'my_acf_settings_url');
function my_acf_settings_url( $url ) {
return MY_ACF_URL;
}
// (Optional) Hide the ACF admin menu item.
add_filter('acf/settings/show_admin', 'my_acf_settings_show_admin');
function my_acf_settings_show_admin( $show_admin ) {
return false;
}
I did the same for other plugins but I miss some styles and js files. for example after transfering the wpDiscuz plugin to my-theme-directory/includes I put this code in functions.php but I missed styles at the front:
<?php
define( 'MY_WPDZ_PATH', get_stylesheet_directory() . '/includes/wpdiscuz/' );
define( 'MY_WPDZ_URL', get_stylesheet_directory_uri() . '/includes/wpdiscuz/' );
include_once( MY_WPDZ_PATH . 'class.WpdiscuzCore.php' );
?>
what should I do? what is the solution?
before I start the topic, I want you to know that I am aware of what I do and the risk and missing the updates and missing security and etc.
I want to put any plugin in my WordPress theme directory.
for example adding woocommerce plugin in wp-content/themes/my-theme-directory
and I want the plugins directory totally clean of any other plugin.
the solution for Advance Custom Fields plugin is like this:
// Define path and URL to the ACF plugin.
define( 'MY_ACF_PATH', get_stylesheet_directory() . '/includes/acf/' );
define( 'MY_ACF_URL', get_stylesheet_directory_uri() . '/includes/acf/' );
// Include the ACF plugin.
include_once( MY_ACF_PATH . 'acf.php' );
// Customize the url setting to fix incorrect asset URLs.
add_filter('acf/settings/url', 'my_acf_settings_url');
function my_acf_settings_url( $url ) {
return MY_ACF_URL;
}
// (Optional) Hide the ACF admin menu item.
add_filter('acf/settings/show_admin', 'my_acf_settings_show_admin');
function my_acf_settings_show_admin( $show_admin ) {
return false;
}
I did the same for other plugins but I miss some styles and js files. for example after transfering the wpDiscuz plugin to my-theme-directory/includes I put this code in functions.php but I missed styles at the front:
<?php
define( 'MY_WPDZ_PATH', get_stylesheet_directory() . '/includes/wpdiscuz/' );
define( 'MY_WPDZ_URL', get_stylesheet_directory_uri() . '/includes/wpdiscuz/' );
include_once( MY_WPDZ_PATH . 'class.WpdiscuzCore.php' );
?>
what should I do? what is the solution?
Share Improve this question asked Nov 14, 2021 at 11:12 SaeedTJSaeedTJ 264 bronze badges 9 | Show 4 more comments1 Answer
Reset to default 0Problem solved
Thanks to @TomJNowell
Solution:
- make a directory under the
wp-content
directory and name itmu-plugins
- then move your plugin directory (for example woocommerce) in
wp-content/mu-plugins
- after that you have to call it for your WordPress by crating a file and name it
load.php
- introduce the plugin bin
load.php
for example:
<?php require WPMU_PLUGIN_DIR.'/woocommerce/woocommerce.php';
Done :)
本文标签: How to add a plugin in WordPress theme directory
版权声明:本文标题:How to add a plugin in WordPress theme directory? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741220224a2360829.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
MY_ACF_PATH
andMY_ACF_URL
are unique and specific to ACF, this looks like you're asking how to implement a solution, not how to solve your problem. You could just as easily have your theme install the plugins automatically or prompt the user that they're necessary. Right now a user with WooCommerce already installed who activates your theme if you did this would break their site – Tom J Nowell ♦ Commented Nov 14, 2021 at 11:43mu-plugins directory
I will post the solution. – SaeedTJ Commented Nov 15, 2021 at 10:45