Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a few plugins that I always set the configuration for exactly the same way. Every time I create a new site, the same plugins go in, and the same amount of time is needed to set them up.

Would it be possible to create a config file that overrides whatever wp_options are set per plugin?

share|improve this question
1  
Would you mind explaining a bit more, are you referring to options created by plugins and stored in the options table? –  t31os Mar 22 '11 at 17:11
    
Yes. Preferably without need of the DB, but I don't think that can be accomplished since all the plugins are calling get_option. –  Dan Gayle Mar 29 '11 at 16:02
add comment

3 Answers

up vote 1 down vote accepted

You could check which options they add (look at the source code) and then simply write a function like this:

/*
Plugin Name:    Mother of all plugins
Plugin URI:  http://wordpress.org/extend/plugins/
Description:    Offers the <code>$all_plugin_options;</code> var to access all predefined plugin options
Author:      Franz Josef Kaiser
Author URI:     http://say-hello-code.com
Version:        0.1
License:        GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/

// Template Tag
function get_all_plugin_options() 
{
    // First we call the class
    $class = new MotherOfAllPlugins;
    $data = $class->predefined_plugin_options()
    return $data;
}

if ( ! class_exists('MotherOfAllPlugins') )
{

class MotherOfAllPlugins
{
    protected $plugin_options;

    public function __construct( $plugin_options )
    {
      // defaults
      $default_options = array(
         'plugin_a' => array(
             'deprecated' => ''
            ,'name'       => 'value'
            ,'key'        => 'value'
          )
        ,'plugin_b' => array(
             'deprecated' => ''
            ,'name'       => 'value'
            ,'key'        => 'value'
          )
      );
      // Now overwrite the 
      $this->plugin_options = array_merge( $default_options, $plugin_options );

      add_action( 'init', 'predefined_plugin_options' );
    }

    function predefined_plugin_options() 
    {

      // Set the flag if we have already done this
      // _EDIT #1:_ This sets an option in the wp_options table containing TRUE if your plugin predef options are already present in the DB
      if ( !get_option( 'predef_plugins_setup' ) === TRUE )
         add_option( 'predef_plugins_setup', TRUE );

      if ( !get_option( 'predef_plugins_setup' ) === TRUE )
      {
         // Add the options for the plugins
         foreach ( $plugin_options as $plugin => $options ) 
         {
            add_option( $plugin, $options, $options['deprecated'], 'yes' );
         }
      }

      // _EDIT #2:_ return the initial array for use in a global
      return $plugin_options
    }

} // END Class MotherOfAllPlugins

} // endif;

To get your plugin options inside your theme:

// Now we take the return value & add it into global scope for further useage.
// This way we can access all options easily without a call to the DB.
// You can now access these values from anywhere in your theme.
$all_plugin_options = get_all_plugin_options();

Be careful to really add the options exactly the way the plugins does it. Else stuff won't work.

share|improve this answer
    
So this is actually writing the options to the DB upon activation, instead of being read from disk? –  Dan Gayle Mar 22 '11 at 21:24
    
The DB is on your/servers disk... –  kaiser Mar 22 '11 at 23:11
    
I meant from a config file, just like we can set WP_HOME within wp-config.php –  Dan Gayle Mar 29 '11 at 15:52
    
Not sure if i completely understood you. You want a global constant that holds an object or array that comes from a ini/xml/json/yaml file? Hm. interesting idea, but I'm not sure if it would work. I guess most plugins use get_option and the settings API. At the right moment i'm not really sure how you'd work around the get_option call that points to the DB. –  kaiser Mar 29 '11 at 16:18
1  
I edited the A and quickly made a plugin out of it that adds the $all_plugin_options; global variable to access the data from your theme. It's not tested so far. But tell me if it works and feel free to correct it with editing my answer. –  kaiser Mar 30 '11 at 20:10
show 4 more comments

You could put something like this in your theme's function.php. This way it only runs once (when the theme is activated).

add_option('my_initial_options', false);

if ( get_option('my_initial_options')== false ){
    addmyOptions();
    update_option( 'my_initial_options', true,'','yes' );
}

function addmyOptions(){

update_option("posts_per_page",1);
update_option( 'show_on_front', 'page' );

}
share|improve this answer
    
Oh, I like this option –  Dan Gayle Mar 29 '11 at 15:53
add comment

Not sure if something like that is possible but a workaround would be to use a dummy database of default WP install configured with all those plugins. Now whenever you need to setup another site, put in this database and edit the home url and site url.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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