Last active
April 2, 2016 14:54
-
-
Save andymantell/5956960 to your computer and use it in GitHub Desktop.
Quick and dirty wordpress deployment plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Deployment routines | |
Description: Runs update routines allowing code based database updates. | |
Author: Andy Mantell | |
Version: 1.0 | |
*/ | |
add_action('admin_init', 'deployment_admin_init'); | |
/** | |
* Attached to init. Runs any necessary update routines | |
*/ | |
function deployment_admin_init() { | |
// What is the current version of this plugin? | |
$deployment_version = 1; | |
// What is the current version in the db | |
$db_version = get_option('deployment_version', 0); | |
// Is the db out of date? | |
if($db_version < $deployment_version) { | |
// If so, loop over all subsequent version numbers and attempt to run corresponding deployment_update_N functions | |
for($version = $db_version + 1; $version <= $deployment_version; $version++) { | |
if(function_exists('deployment_update_' . $version)) { | |
$success = call_user_func('deployment_update_' . $version); | |
// If the function returns a boolean false, log an error and bail out. Subsequent updates may rely on this update | |
// so we shouldn't proceed any further. | |
if($success === FALSE) { | |
// @TODO: log error here | |
break; | |
} | |
} | |
// If we've reached this far without error, update the db version | |
update_option('deployment_version', $version); | |
} | |
// @TODO: output update summary on success | |
} | |
} | |
/** | |
* Update functions. | |
*/ | |
/** | |
* Disable the wordpress-meta-description plugin. | |
* Enable and configure the add-meta-tags plugin | |
*/ | |
function deployment_update_1() { | |
// Include the plugin.php file so you have access to the activate_plugin() function | |
require_once(ABSPATH .'/wp-admin/includes/plugin.php'); | |
deactivate_plugins(WP_PLUGIN_DIR . '/wordpress-meta-description/wp-meta-description.php'); | |
activate_plugins(WP_PLUGIN_DIR . '/add-meta-tags/add-meta-tags.php'); | |
update_option('add_meta_tags_opts', array( | |
'settings_version' => 2, | |
'site_description' => 'Site description here', | |
'site_keywords' => 'site, keywords, here', | |
'global_keywords' => 'global, keywords, here', | |
'site_wide_meta' => '', | |
'auto_description' => '1', | |
'auto_keywords' => '1', | |
'auto_opengraph' => '0', | |
'auto_dublincore' => '0', | |
'noodp_description' => '0', | |
'noindex_search_results' => '1', | |
'noindex_date_archives' => '0', | |
'noindex_category_archives' => '0', | |
'noindex_tag_archives' => '0', | |
'noindex_author_archives' => '0', | |
'copyright_url' => '', | |
'default_image_url' => '', | |
'i_have_donated' => '0', | |
)); | |
return TRUE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment