Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Replace old shortcode
- Description: This will remove the Blackbird Pie shortcode when it's found via a filter
- Version: 0.2
- From http://wordpress.org/support/topic/how-do-i-remove-only-a-part-of-a-shortcode
- */
- add_filter( 'the_content' , 'mh_remove_shortcode' , 0 );
- function mh_remove_shortcode( $content ) {
- global $wpdb, $post;
- // Regex to find all [blackbirdpie url="twitter"] shotcodes.
- $mh_url_regex = "/\[blackbirdpie\ url\=\"(http|https)\:\/\/twitter\.com\/.*\"]/";
- // If we get any hits then remove the the shortcode
- if ( preg_match_all( $mh_url_regex , $content, $mh_matches ) ) {;
- // Go through that array and remove the shortcode
- for ( $mh_count = 0; $mh_count < count( $mh_matches[0] ); $mh_count++ )
- {
- $mh_with_shortcode = $mh_matches[0][$mh_count];
- $mh_without = str_replace( '[blackbirdpie url="' , '' , $mh_matches[0][$mh_count] );
- $mh_without = str_replace( '"]' , '' , $mh_without );
- $content = str_replace( $mh_with_shortcode , $mh_without , $content );
- // This is probably all wrong...
- $wpdb->update( $wpdb->posts, array( 'post_content' => $content ),
- array( 'ID' => $post->ID )
- );
- }
- // Make the page reload
- add_filter( 'wp_head' , 'mh_insert_redirect' );
- }
- return $content;
- }
- function mh_insert_redirect() {
- global $post;
- echo '<meta http-equiv="refresh" content="0;url=' . get_permalink( $post->ID ) . '">';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement