Support » Plugin: WP Simple Adsense Insertion » Simplified Shortcode Functions

  • WhoTnT

    (@wpwho)


    I just thought I would let you know that you can simplify your shortcode functions as follows:
    ORIGINAL

    function show_ad_camp_1() {
    	$ad_camp_encoded_value_1 = get_option( 'wp_ad_camp_1_code' );
    	$ad_camp_decoded_value_1 = html_entity_decode( $ad_camp_encoded_value_1, ENT_COMPAT );
    
    	if ( !empty( $ad_camp_decoded_value_1 ) ) {
    		$output = " $ad_camp_decoded_value_1";
    	}
    	return $output;
    }

    NEW

    function show_ad_camp_1() {
    		return html_entity_decode(get_option( 'wp_ad_camp_1_code' ));	
    }

    With your code there is the possibility of trying to return a non-existent $output variable if the if condition is false. As far as I can tell, there is no reason to check if the value you are returning is empty since if it is empty nothing will be displayed anyway.

Viewing 1 replies (of 1 total)
  • Plugin Support mbrsolution

    (@mbrsolution)

    Thank you for sharing your modified code.

    The plugin developers will investigate further your suggestion.

    Kind regards

Viewing 1 replies (of 1 total)
  • The topic ‘Simplified Shortcode Functions’ is closed to new replies.