[wp-hackers] How to Exclude shortcode in databse

Chris McCoy chris at lod.com
Thu Jul 12 20:07:54 UTC 2012


You will only need to run it once also you could even just do
remove_shortcode('shortcodename'); but that wouldn't remove it from the db
in total.



-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com
[mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Diana K. C
Sent: Thursday, July 12, 2012 12:57 PM
To: wp-hackers at lists.automattic.com
Subject: Re: [wp-hackers] How to Exclude shortcode in databse

Thanks that worked!


I add as an action:
add_action('init','remove_shortcode_from_db');



----- Original Message ----- 
From: "Chris McCoy" <chris at lod.com>
To: <wp-hackers at lists.automattic.com>
Sent: Thursday, July 12, 2012 2:16 AM
Subject: Re: [wp-hackers] How to Exclude shortcode in databse


> Kinda hacky way of doing it, but here is something I did a while back
>
> function remove_shortcode_from_db($shortcode = 'button') {
>
>    global $wpdb;
>
>    $posts = $wpdb->get_results("SELECT ID,post_title,post_content FROM
> $wpdb->posts");
>    $regex =
>
'/\[(\[?)('.$shortcode.')\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([
> ^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/s';
>
>    foreach($posts as $post) {
>        $final = preg_replace($regex,'',$post->post_content);
>        $change = $wpdb->update( $wpdb->posts, array('post_content' =>
> $final), array('ID' => $post->ID));
>    }
> }
>
> Will accept any parameter being atgallery will look for all attribs and
> remove
>
> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com
> [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Diana K. C
> Sent: Wednesday, July 11, 2012 10:21 PM
> To: wp-hackers at lists.automattic.com
> Subject: [wp-hackers] How to Exclude shortcode in databse
>
> That't quick I think:
>
> I found some SQL commands around, but all deal with fix shortcodes like
> [tweet], I need to exlcude shortcodes like [atgallery id="144"], 
> [tagellery
> = "12"] etc
>
> Thanks for help!
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers 

_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list