Advertisement
designbymerovingi

Disable myCRED shortcode usage by non admins

May 27th, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. /**
  2.  * Disable myCRED Shortcodes
  3.  * Disable / Remove myCRED shortcodes from wp content,
  4.  * BuddyPress activity and messages.
  5.  * @version 1.0
  6.  */
  7. add_filter( 'the_content', 'mycred_pro_disable_shortcodes' );
  8. function mycred_pro_disable_shortcodes( $content = '' ) {
  9.  
  10.     if ( is_admin() ) return;
  11.  
  12.     global $post;
  13.  
  14.     if ( ! isset( $post->post_content ) || user_can( $post->post_author, 'edit_users' ) ) return;
  15.  
  16.     $content = str_replace( array( '[mycred', '[ mycred' ), '[not allowed', $content );
  17.  
  18.     return $content;
  19.  
  20. }
  21.  
  22. add_filter( 'bp_get_activity_content_body', 'mycred_pro_disable_shortcodes_bp' );
  23. function mycred_pro_disable_shortcodes_bp( $content, $activity ) {
  24.  
  25.     if ( ! isset( $activity->user_id ) || user_can( $activity->user_id, 'edit_users' ) ) return;
  26.  
  27.     $content = str_replace( array( '[mycred', '[ mycred' ), '[not allowed', $content );
  28.  
  29.     return $content;
  30.  
  31. }
  32.  
  33. add_action( 'messages_message_before_save', 'mycred_pro_disable_shortcodes_bp_message' );
  34. function mycred_pro_disable_shortcodes_bp_message( $message ) {
  35.  
  36.     if ( ! isset( $message->sender_id ) || user_can( $message->sender_id, 'edit_users' ) ) return;
  37.  
  38.     $message->message = str_replace( array( '[mycred', '[ mycred' ), '[not allowed', $message->message );
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement