Created
December 28, 2012 23:12
-
-
Save matthewsimo/4402952 to your computer and use it in GitHub Desktop.
Boilerplate code for a plugin with the purpose of a SQL query.
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: Fix Such and Such Problem | |
| Description: This plugin fixes such and such because such and such is broken | |
| Version: 0.1 | |
| Author: Awesome Plugin Meister | |
| */ | |
| if(!class_exists('Such_Such_Fixer')){ | |
| class Such_Such_Fixer{ | |
| public function __construct(){ | |
| #Keep this behind the login firewall | |
| add_action('admin_init', array($this, 'fix_it'), 9999); | |
| } | |
| public function fix_it(){ | |
| $trigger = 'fix-such-such'; | |
| $key = 'magic456'; | |
| #Keep this obscure so only you can pull the trigger | |
| if(!isset($_GET[$trigger])) | |
| return; | |
| if($_GET[$trigger] === $key){ | |
| global $wpdb; | |
| $sql = $wpdb->prepare(" | |
| UPDATE $wpdb->posts | |
| SET $wpdb->posts.post_content = REPLACE($wpdb->posts.post_content,'[gallery]','') | |
| WHERE $wpdb->posts.post_type = 'galleries' | |
| "); | |
| $result = $wpdb->query($sql); | |
| if($result) | |
| show_message('Galleries shortcode deleted for all posts.'); | |
| else | |
| show_message('Somefing happened when I tried to delete all Z gallery shortcodes.'); | |
| exit; | |
| } | |
| } | |
| } | |
| new Such_Such_Fixer; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment