Skip to content

Instantly share code, notes, and snippets.

@sirchrispy
Created February 3, 2022 19:43
Show Gist options
  • Save sirchrispy/881cef6cbcd3637b9925bc6e18331605 to your computer and use it in GitHub Desktop.
Save sirchrispy/881cef6cbcd3637b9925bc6e18331605 to your computer and use it in GitHub Desktop.
WordPress Plugin: Clear Out Genesis 2.6 Deprecated Fields (MultiSite Compatible)
<?php
/**
* Plugin Name: Update Deprecated Genesis Options
* Description: Clears out deprecated Genesis RSS options from Genesis < v2.6. Uninstall after activation.
* Version: 1.0.0
* Author: Chris Mower
* Author URI: https://thecookingdish.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: cm-udgo
* Domain Path: /languages
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
/**
* The code that runs during plugin activation.
*
* @since 1.0.0
* @param boolean $network True if plugin is network activated.
*/
register_activation_hook(__FILE__, 'cm_activate_update_deprecated_genesis_options');
function cm_activate_update_deprecated_genesis_options($network)
{
// Check permissions
if (!current_user_can('activate_plugins')) {
die;
}
global $wpdb;
// Check to see if WP install is MultiSite
if (function_exists('is_multisite') && is_multisite()) {
// Determine if the plugin is network activated
if ($network) {
// Get the list of network's blog ids
$blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
// Iterate through each MultiSite blog
foreach ($blog_ids as $id) {
switch_to_blog($id);
cm_update_genesis_deprecated();
}
// Return to current blog
restore_current_blog();
// end
return;
} else {
// If activated on single sites in the network
cm_update_genesis_deprecated();
}
} else {
// If not a MultiSite Install
cm_update_genesis_deprecated();
}
}
/**
* Check for deprecated options, if set, update them.
*
* @since 1.0.0
* @return void
*/
function cm_update_genesis_deprecated()
{
// Get the Genesis Settings option from wp-options
$genesis_options = (array) get_option('genesis-settings');
/**
* Style Selection
*
* '' = clear out existing content, leave empty string
*
* Not deprecated, but for if your current them no longer uses
* a style selection, and you're not going back to the old theme
* that used it.
*
* Comment this part out if you use a style selector.
*/
if (isset($genesis_options['style_selection'])) {
$genesis_options['style_selection'] = '';
}
/**
* Posts Feed URI
*
* '' = clear out existing content, leave empty string
*/
if (isset($genesis_options['feed_uri'])) {
$genesis_options['feed_uri'] = '';
}
/**
* Posts Feed Redirect
*
* 0 = do not redirect
* 1 = redirect
*/
if (isset($genesis_options['redirect_feed'])) {
$genesis_options['redirect_feed'] = '0';
}
/**
* Comments Feed URI
*
* '' = clear out existing content, leave empty string
*/
if (isset($genesis_options['comments_feed_uri'])) {
$genesis_options['comments_feed_uri'] = '';
}
/**
* Comments Feed Redirect
*
* 0 = do not redirect
* 1 = redirect
*/
if (isset($genesis_options['redirect_comments_feed'])) {
$genesis_options['redirect_comments_feed'] = '0';
}
update_option('genesis-settings', $genesis_options);
}
/**
* Load Plugin; Do Nothing
*
* @since 1.0.0
* @return void
*/
function cm_load_update_deprecated_genesis_options_plugin()
{
// plugin runs on activation
}
add_action('admin_init', 'cm_load_update_deprecated_genesis_options_plugin');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment