Title: Bug in function protect_content_shortcode
Last modified: September 12, 2017

---

# Bug in function protect_content_shortcode

 *  Resolved [robertogcalle](https://wordpress.org/support/users/robertogcalle/)
 * (@robertogcalle)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/bug-in-function-protect_content_shortcode/)
 * Hi everyone,
 * I’ve notice a bug in function “protect_content_shortcode”. This function shows
   a proteccion message instead of the content inside the shortcode [ms-protect-
   content].
    But if you set a custom message this is ignored due to this bug. I’ll
   show you how to fix it.
 * ** ORIGINAL CODE **
    File: class-ms-rules-shortcode-model.php Lines: 154 – 188
 *     ```
       	static public function protect_content_shortcode( $atts, $content = null, $code = '' ) {
       		$atts = apply_filters(
       			'ms_model_shortcode_protect_content_shortcode_atts',
       			shortcode_atts(
       				array(
       					'id' 		=> '',
       					'access' 	=> true,
       					'silent' 	=> false,
       					'msg' 		=> false,
       				),
       				$atts
       			)
       		);
       		extract( $atts );
   
       		$membership_ids = explode( ',', $id );
   
       		if ( $silent ) {
       			$msg = '';
       		} else {
       			if ( ! is_string( $msg ) || ! strlen( $msg ) ) {
       				$settings = MS_Factory::load( 'MS_Model_Settings' );
       				// TO-DO: Need to think about logic here. Tracking ID: 70522969408012/53509795076060
       				if( defined( 'MS_PROTECTED_MESSAGE_REVERSE_RULE' ) && MS_PROTECTED_MESSAGE_REVERSE_RULE ) {
       					$membership_id = $atts['id'];
       				}else{
       					<strong>$membership_id = apply_filters( 'ms_detect_membership_id', 0 );</strong>
       				}
   
       				$msg = $settings->get_protection_message(
       					MS_Model_Settings::PROTECTION_MSG_SHORTCODE,
       					$membership_id
       				);
       			}
       		}
       ```
   
 * ** MODIFIED CODE **
 *     ```
       	static public function protect_content_shortcode( $atts, $content = null, $code = '' ) {
       		$atts = apply_filters(
       			'ms_model_shortcode_protect_content_shortcode_atts',
       			shortcode_atts(
       				array(
       					'id' 		=> '',
       					'access' 	=> true,
       					'silent' 	=> false,
       					'msg' 		=> false,
       				),
       				$atts
       			)
       		);
   
       		extract( $atts );
   
       		$membership_ids = explode( ',', $id );
   
       		if ( $silent ) {
       			$msg = '';
       		} else {
       			if ( ! is_string( $msg ) || ! strlen( $msg ) ) {
       				$settings = MS_Factory::load( 'MS_Model_Settings' );
       				// TO-DO: Need to think about logic here. Tracking ID: 70522969408012/53509795076060
       				if( defined( 'MS_PROTECTED_MESSAGE_REVERSE_RULE' ) && MS_PROTECTED_MESSAGE_REVERSE_RULE ) {
       					$membership_id = $atts['id'];
       				}else{
       					<strong>$membership_id = apply_filters( 'ms_detect_membership_id', $atts['id'] );</strong>
       				}
   
       				$msg = $settings->get_protection_message(
       					MS_Model_Settings::PROTECTION_MSG_SHORTCODE,
       					$membership_id
       				);
   
       			}
       		}
       ```
   
 * Please, notice the difference in the bolded line. You have to pass $atts[‘id’]
   instead of 0 to show up the custom message.
 * Hope this could help.
 * Bests

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [robertogcalle](https://wordpress.org/support/users/robertogcalle/)
 * (@robertogcalle)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/bug-in-function-protect_content_shortcode/#post-9489140)
 * Difference is in line 180 of file class-ms-rules-shortcode-model.php.
 * ORIGINAL: $membership_id = apply_filters( ‘ms_detect_membership_id’, **0** );
   
   MODIFIED: $membership_id = apply_filters( ‘ms_detect_membership_id’, **$atts[‘
   id’]** );
 *  Plugin Support [Amin – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support2/)
 * (@wpmudev-support2)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/bug-in-function-protect_content_shortcode/#post-9503887)
 * Hello [@robertogcalle](https://wordpress.org/support/users/robertogcalle/),
 * To use custom protection messages you need to add this define to wp-config.php
 * `define ( 'MS_PROTECTED_MESSAGE_REVERSE_RULE', true);`
 * If you add this there is no need to change plugin code.
 * kind regards,
    Kasia
 *  Plugin Author [jdailey](https://wordpress.org/support/users/jdailey/)
 * (@jdailey)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/bug-in-function-protect_content_shortcode/#post-9542997)
 * Thank you for using Membership 2. I am going to close this ticket for now. If
   you have any other questions let us know. Enjoy!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Bug in function protect_content_shortcode’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/membership_b8cdaa.svg)
 * [Membership 2](https://wordpress.org/plugins/membership/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/membership/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/membership/)
 * [Active Topics](https://wordpress.org/support/plugin/membership/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/membership/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/membership/reviews/)

## Tags

 * [custom message](https://wordpress.org/support/topic-tag/custom-message/)

 * 3 replies
 * 3 participants
 * Last reply from: [jdailey](https://wordpress.org/support/users/jdailey/)
 * Last activity: [8 years, 8 months ago](https://wordpress.org/support/topic/bug-in-function-protect_content_shortcode/#post-9542997)
 * Status: resolved