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
  • MY_ACF_PATH and MY_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:43
  • 1 ACF is specifically designed to be bundled with themes. Most plugins are not. – Jacob Peattie Commented Nov 14, 2021 at 11:55
  • @TomJNowell 1) if someone see woocommerce in the admin menu, why would they install the woocommerce again? 2) who says there will be a plugin access when I totally hide it? 3) this is just for the websites which I'll give to my customers. if you can solve the problem, then I'm waiting for the answer. – SaeedTJ Commented Nov 14, 2021 at 12:43
  • 3 I would advise a calmer demeanour. If you do not explain why then it is natural that people will ask. Context will both avoid people asking, and enhance the answers you get. For example, if you are indeed trying to simplify updating then some solutions will not work for you. Likewise if you want this because you are trying to sell the theme in question that also changes the answer. It's even possible you're doing this to comply with classic WP VIP, for which there is a completely different answer. This isn't a discussion forum, you should provide the context for why, it is important – Tom J Nowell Commented Nov 15, 2021 at 0:21
  • 1 @TomJNowell , Now the problem is solved by your helping hands. I did not know about mu-plugins directory I will post the solution. – SaeedTJ Commented Nov 15, 2021 at 10:45
 |  Show 4 more comments

1 Answer 1

Reset to default 0

Problem solved
Thanks to @TomJNowell
Solution:

  1. make a directory under the wp-content directory and name it mu-plugins
  2. then move your plugin directory (for example woocommerce) in wp-content/mu-plugins
  3. after that you have to call it for your WordPress by crating a file and name it load.php
  4. 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