-1

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?

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
    Nov 14, 2021 at 11:43
  • 1
    ACF is specifically designed to be bundled with themes. Most plugins are not. 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
    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.com 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
    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
    Nov 15, 2021 at 10:45

1 Answer 1

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 :)

4
  • You shouldn't have to require files from mu-plugins I don't think? They should get loaded automatically before any other plugins.
    – Rup
    Nov 16, 2021 at 11:43
  • But I'm not really sure woocommerce belongs in mu-plugins anyway.
    – Rup
    Nov 16, 2021 at 11:43
  • @Rup mu-plugins will only load PHP files directly in the mu-plugins/ directory. If you put a folder in there nothing will load. You need a PHP file that includes the main file from the plugin folder. Nov 17, 2021 at 12:26
  • @JacobPeattie Thanks, didn't know that, I've only used it for single file plugins.
    – Rup
    Nov 17, 2021 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.