Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

not-best-idea.php

By: jan_dembowski on Nov 25th, 2012  |  syntax: PHP  |  size: 1.60 KB  |  views: 49  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /*
  3. Plugin Name: Replace old shortcode
  4. Description: This will remove the Blackbird Pie shortcode when it's found via a filter
  5. Version: 0.2
  6.  
  7. From http://wordpress.org/support/topic/how-do-i-remove-only-a-part-of-a-shortcode
  8.  
  9. */
  10.  
  11. add_filter( 'the_content' , 'mh_remove_shortcode' , 0 );
  12.  
  13. function mh_remove_shortcode( $content ) {
  14. global $wpdb, $post;
  15. // Regex to find all [blackbirdpie url="twitter"] shotcodes.
  16. $mh_url_regex = "/\[blackbirdpie\ url\=\"(http|https)\:\/\/twitter\.com\/.*\"]/";
  17.  
  18. // If we get any hits then remove the the shortcode
  19. if ( preg_match_all( $mh_url_regex , $content, $mh_matches ) ) {;
  20.         // Go through that array and remove the shortcode
  21.         for ( $mh_count = 0; $mh_count < count( $mh_matches[0] ); $mh_count++ )
  22.                 {
  23.                 $mh_with_shortcode = $mh_matches[0][$mh_count];
  24.                 $mh_without = str_replace( '[blackbirdpie url="' , '' , $mh_matches[0][$mh_count] );
  25.                 $mh_without = str_replace( '"]' , '' , $mh_without );
  26.  
  27.                 $content = str_replace( $mh_with_shortcode  , $mh_without , $content );
  28.                 // This is probably all wrong...
  29.                 $wpdb->update( $wpdb->posts, array( 'post_content' => $content ),
  30.                         array( 'ID' => $post->ID )
  31.                         );
  32.                 }
  33.                 // Make the page reload
  34.                 add_filter( 'wp_head' , 'mh_insert_redirect' );
  35.         }
  36. return $content;
  37. }
  38.  
  39. function mh_insert_redirect() {
  40. global $post;
  41.         echo '<meta http-equiv="refresh" content="0;url=' . get_permalink( $post->ID ) . '">';
  42. }
clone this paste RAW Paste Data