Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7889061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:59:59+00:00 2026-06-03T05:59:59+00:00

My dream is to include a php file in a theme which checks if

  • 0

My dream is to include a php file in a theme which checks if a set of plugins are installed, and installs the ones which are not. Kind of like a set of dependencies for the theme, but also just a good way to package theme development to include a set of good plugins.

My questions…

  1. Is there something like this in existence?
  2. Is it possible to achieve from a single php file in a theme folder?
  3. Are there any obvious pit-falls or problems with this approach?
  4. How would I go about achieving this?
    • is it possible to enumerate installed plugins from within theme folder?
    • is it possible to download and place plugin files in the plugins folder?
    • is it possible to activate plugins from within theme directory?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:00:01+00:00Added an answer on June 3, 2026 at 6:00 am

    07/06/2018 EDIT: If you are coming across this answer, the code highlighted below is extremely outdated and insecure and should not be used in any capacity outside of experimentation on a local server. If you are looking for a more modern solution for plugin management, consider installing WordPress via Composer and Bedrock


    I would advise NOT programatically checking for the existence of certain plugins, downloading, installing, and activating them from within any theme file. You have to consider that the check will be run every time the given page is loaded, and can result in a lot of superfluous code and unnecessary activity.

    Instead, my advice would be to package any plugins on which your theme depends as a part of the theme itself, and NOT as a plugin. Plugins should be installed at the discretion of the user. If a theme depends on a plugin to function properly or efficiently, then it really should be packaged and downloaded with the theme itself.

    But to answer your questions directly:

    1. Probably. It is certainly possible to do.
    2. Yes.
    3. See the above. You potentially run into more issues by constantly checking for plugins and running a series of actions based on those conditions rather than just including everything needed.
    4. Plenty of research

      • Probably
      • Yes
      • Yes

    I cannot stress enough, however, that the purpose of a PLUGIN is to give the user the option to extend a given theme’s capabilities. If your theme’s capabilities DEPEND on existing plugins, then you really REALLY should include all the files when somebody downloads your theme.

    Though if you feel that your approach benefits your theme in ways that I might be missing, feel free to write it however you like.

    COMPLETE ANSWER: I decided to help create a proof of concept for you, because I got bored and curious. Much of this should be self explanatory. Add these functions:

    function mm_get_plugins($plugins)
    {
        $args = array(
                'path' => ABSPATH.'wp-content/plugins/',
                'preserve_zip' => false
        );
    
        foreach($plugins as $plugin)
        {
                mm_plugin_download($plugin['path'], $args['path'].$plugin['name'].'.zip');
                mm_plugin_unpack($args, $args['path'].$plugin['name'].'.zip');
                mm_plugin_activate($plugin['install']);
        }
    }
    function mm_plugin_download($url, $path) 
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $data = curl_exec($ch);
        curl_close($ch);
        if(file_put_contents($path, $data))
                return true;
        else
                return false;
    }
    function mm_plugin_unpack($args, $target)
    {
        if($zip = zip_open($target))
        {
                while($entry = zip_read($zip))
                {
                        $is_file = substr(zip_entry_name($entry), -1) == '/' ? false : true;
                        $file_path = $args['path'].zip_entry_name($entry);
                        if($is_file)
                        {
                                if(zip_entry_open($zip,$entry,"r")) 
                                {
                                        $fstream = zip_entry_read($entry, zip_entry_filesize($entry));
                                        file_put_contents($file_path, $fstream );
                                        chmod($file_path, 0777);
                                        //echo "save: ".$file_path."<br />";
                                }
                                zip_entry_close($entry);
                        }
                        else
                        {
                                if(zip_entry_name($entry))
                                {
                                        mkdir($file_path);
                                        chmod($file_path, 0777);
                                        //echo "create: ".$file_path."<br />";
                                }
                        }
                }
                zip_close($zip);
        }
        if($args['preserve_zip'] === false)
        {
                unlink($target);
        }
    }
    function mm_plugin_activate($installer)
    {
        $current = get_option('active_plugins');
        $plugin = plugin_basename(trim($installer));
    
        if(!in_array($plugin, $current))
        {
                $current[] = $plugin;
                sort($current);
                do_action('activate_plugin', trim($plugin));
                update_option('active_plugins', $current);
                do_action('activate_'.trim($plugin));
                do_action('activated_plugin', trim($plugin));
                return true;
        }
        else
                return false;
    }
    

    … and then execute like so:

    $plugins = array(
        array('name' => 'jetpack', 'path' => 'http://downloads.wordpress.org/plugin/jetpack.1.3.zip', 'install' => 'jetpack/jetpack.php'),
        array('name' => 'buddypress', 'path' => 'http://downloads.wordpress.org/plugin/buddypress.1.5.5.zip', 'install' => 'buddypress/bp-loader.php'),
        array('name' => 'tumblr-importer', 'path' => 'http://downloads.wordpress.org/plugin/tumblr-importer.0.5.zip', 'install' => 'tumblr-importer/tumblr-importer.php')
    );
    mm_get_plugins($plugins);
    

    ‘name’ can be anything, as it serves to be more of a temporary value. ‘path’ is exactly what it looks like, and is the direct URL to the zip file on the WordPress server. The ‘install’ value is simply the path to the main PHP script that has all of the plugin information. You will have to know the layout of that particular plugin directory in order to fill out this information, as this is also required for the activation hack to work.

    Activation function was found here (credit to sorich87): https://wordpress.stackexchange.com/questions/4041/how-to-activate-plugins-via-code

    WARNING: This is by no means a very safe way to do things. I actually think that this can be abused quite easily, so our best bet is to use this as our baseline and try and improve from there.

    If you should decide to use this approach, all I ask is that I’m credited with the initial overall script, along with sorich87 for his activation process may God have mercy on your soul.

    07/06/2018 EDIT: Seriously, don’t do this. By today’s standards, this code is hot garbage. Plugin management should be done through Composer and Bedrock.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I dream of creating a control which works something like this: <asp:SqlDataSource id=dsFoo runat=server
In Maven, dependencies are usually set up like this: <dependency> <groupId>wonderful-inc</groupId> <artifactId>dream-library</artifactId> <version>1.2.3</version> </dependency>
I am using dream weaver for creating php pages, and I set the charset=utf-8
Here's what I need to do -- either : include an external file in
Open-source urban driving simulator needed to build an automated taxi driver. The dream feature-set
I have a question, which may be a pipe-dream, but I wanted to know
My dream IDE does full code hints, explains and completes PHP, Javascript, HTML and
I developed a simple PHP web page using Dream Weaver CS5 Version 11.0 Build
Phonegap:build sounds like a dream come true, code once release on all mobile platforms.
Maybe this is kind of a pie-in-the-ski dream/question. Does anyone know of a tool

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.