• Resolved robertogcalle

    (@robertogcalle)


    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

    (@robertogcalle)

    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

    (@wpmudev-support2)

    Hello @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

    (@jdailey)

    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.