7 posts
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in United States
CNW says

This seems like an obvious, though novice, question: I was rummaging for a good way to include WP plugins in my themes so that when the client installs them, PHP will copy the plugin files into the “plugins” folder in wordpress.

It seems (very) impractical to do that, so I wanted to ask how do you as theme designers tackle having to bundle plugins with your theme? Do you simply indicate the customer “please download this and that plugin for the ultimate user-exprience”?

374 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+3 more
_rohan says
This seems like an obvious, though novice, question: I was rummaging for a good way to include WP plugins in my themes so that when the client installs them, PHP will copy the plugin files into the “plugins” folder in wordpress. It seems (very) impractical to do that, so I wanted to ask how do you as theme designers tackle having to bundle plugins with your theme? Do you simply indicate the customer “please download this and that plugin for the ultimate user-exprience”?

if you include(php include or require) the plugin from your theme’s functions.php file, its the same as having the plugin installed.

7 posts
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in United States
CNW says
This seems like an obvious, though novice, question: I was rummaging for a good way to include WP plugins in my themes so that when the client installs them, PHP will copy the plugin files into the “plugins” folder in wordpress. It seems (very) impractical to do that, so I wanted to ask how do you as theme designers tackle having to bundle plugins with your theme? Do you simply indicate the customer “please download this and that plugin for the ultimate user-exprience”?
if you include(php include or require) the plugin from your theme’s functions.php file, its the same as having the plugin installed.

Actually, some plugins rely on the fact that they should dwell inside wp-content/plugins directory (e.g. make require_once calls for a file that technically does not exist). Furthermore, from my experience, when you include a plugin like that, it does not appear in your “plugins” menu on WordPress and thus you don’t get the added benefit of perhaps updating it when it is revamped.

Better solution?

374 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+3 more
_rohan says

Actually, some plugins rely on the fact that they should dwell inside wp-content/plugins directory (e.g. make require_once calls for a file that technically does not exist). Furthermore, from my experience, when you include a plugin like that, it does not appear in your “plugins” menu on WordPress and thus you don’t get the added benefit of perhaps updating it when it is revamped.

Better solution?

Plugins like that are often not written with such great code.

Anyway, if thats what you want, you can use a script to move files on theme activation. Use the PHP copy function to copy files from your theme directory to the plugins directory.

7 posts
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in United States
CNW says

Actually, some plugins rely on the fact that they should dwell inside wp-content/plugins directory (e.g. make require_once calls for a file that technically does not exist). Furthermore, from my experience, when you include a plugin like that, it does not appear in your “plugins” menu on WordPress and thus you don’t get the added benefit of perhaps updating it when it is revamped.

Better solution?

Plugins like that are often not written with such great code.

Anyway, if thats what you want, you can use a script to move files on theme activation. Use the PHP copy function to copy files from your theme directory to the plugins directory.

I agree with you on that; though I was hoping for some magic WP built-in function.

2 posts
  • Has been part of the Envato Community for over 3 years
  • Has collected 10+ items on Envato Market
  • Located in United States
Adal says

Actually, some plugins rely on the fact that they should dwell inside wp-content/plugins directory (e.g. make require_once calls for a file that technically does not exist). Furthermore, from my experience, when you include a plugin like that, it does not appear in your “plugins” menu on WordPress and thus you don’t get the added benefit of perhaps updating it when it is revamped.

Better solution?

Yes! There is a better solution. The code was written by WPML but for some reason they recently discontinued it’s distribution.

I took upon myself the responsibility to continue distributing this terribly useful piece of work, and do not claim to take any credit for it. When I have time though, I might work on extending or optimizing it.

For full instructions on how [self promotion removed] and even have them install automatically, check out the link.

Cheers!

2579 posts Put a Donk On It
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+10 more
ThemeProvince says

Heres the code:


if (is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" ) {

$theme_url = get_bloginfo('template_url');
$theme_url_split = explode("/", $theme_url);
$theme_url_split_length = count($theme_url_split);
$theme_name = $theme_url_split[$theme_url_split_length-1];

$plugin_source = "../wp-content/themes/".$theme_name."/p_framework/option-tree-phoenix";
$plugin_target = "../wp-content/plugins/option-tree-phoenix";

function full_copy( $source, $target ) {
    if ( is_dir( $source ) ) {
        @mkdir( $target );
        $d = dir( $source );
        while ( FALSE !== ( $entry = $d->read() ) ) {
            if ( $entry == '.' || $entry == '..' ) {
                continue;
            }
            $Entry = $source . '/' . $entry; 
            if ( is_dir( $Entry ) ) {
                full_copy( $Entry, $target . '/' . $entry );
                continue;
            }
            copy( $Entry, $target . '/' . $entry );
        }

        $d->close();
        $plugin_path = 'option-tree-phoenix/index.php';
        $active_plugins = get_option('active_plugins');
        if (!isset($active_plugins[$plugin_path])) run_activate_plugin( 'option-tree-phoenix/index.php' );

    }
}

function run_activate_plugin( $plugin ) {
    $current = get_option( 'active_plugins' );
    $plugin = plugin_basename( trim( $plugin ) );

    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 null;
}

full_copy($plugin_source, $plugin_target);

} 

2 posts
  • Has been part of the Envato Community for over 3 years
  • Has collected 10+ items on Envato Market
  • Located in United States
Adal says

Yes! There is a better solution. The code was written by WPML but for some reason they recently discontinued it’s distribution.

I took upon myself the responsibility to continue distributing this terribly useful piece of work, and do not claim to take any credit for it. When I have time though, I might work on extending or optimizing it.

Just search Blundling Plugins with Themes for instructions.

Phoenix, that’s some tight code, thanks for sharing! Do you just change your functions file every-time you add/remove a plugin from the package then?

2579 posts Put a Donk On It
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+10 more
ThemeProvince says

Not sure what you mean :)

1 post
  • Has been part of the Envato Community for over 5 years
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
  • Located in United Kingdom
morrg says

Might be a silly question but, do I just add the above code to the functions file in my theme and adjust it to the relevant plugin information? A nice feature to add if you decide to develop it further would be to scan the directory in the theme and copy all plugins within it.

Thanks,

Matt

by
by
by
by
by
by