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?
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 asked Mar 22, 2011 at 17:06 Dan GayleDan Gayle 6,1665 gold badges33 silver badges45 bronze badges 2 |4 Answers
Reset to default 1You 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.
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' );
}
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.
Take a look at the pre_option_{option}
hook.
https://developer.wordpress.org/reference/hooks/pre_option_option/
<?php
// Force the blogname (Website Title) no matter what Settings > General says
function myslug_pre_filter_blogname( $pre_option ) {
return 'My Awesome Website';
}
add_filter( 'pre_option_blogname', 'myslug_pre_filter_blogname' );
// Your site is special. It's not "Just Another" anything.
function myslug_pre_filter_blogdescription( $pre_option ) {
return '';
}
add_filter( 'pre_option_blogdescription', 'myslug_pre_filter_blogdescription' );
get_option
. – Dan Gayle Commented Mar 29, 2011 at 16:02