• My knowledge level is very low when it comes to php, codex, functions etc.
    I “fumble” my way through things so please forgive my incorrect lingo at times.

    What I need help with is how to be able to use a short code inside of a short code and get the contents to “parse”? (not sure what else to call it).

    For example on a post I might have a Gallery inserted through a plugin that I want to password protect with another plugin…like this.

    [password-protect]

    [nggallery id=1]

    [/password-protect]

    If I do this now I get the outter short code to work but what’s inside it just gets printed as text instead of actually inserting / doing whatever it should…in this case displaying an embedded gallery.

    I have read enough to know I need to edit the php itself but when I read this page:
    https://codex.www.ads-software.com/Function_Reference/do_shortcode

    I have no clue what to edit..and how to edit it, may as well be written in Latin…lol.

    Your help (hopefully in newbie terms) would be greatly appreciated.
    Thank you.

Viewing 9 replies - 1 through 9 (of 9 total)
  • you need to edit the plugin which provided this shortcode [password-protect] (please post a link to that plugin).

    and find where it returns the output; then add the do_shortcode() there.

    example only (will be different in your actual plugin):

    at the end of the actual function in the plugin:

    return $protected;
    }

    turn that into:

    return do_shortcode($protected);
    }

    please post a (download) link to the ‘protect’ plugin.

    Thread Starter MrRedd

    (@mrredd)

    This is the “WRAPPER” plugin shortcode [password-protect]…
    Exclusive Content Password Protect
    https://www.ads-software.com/extend/plugins/exclusive-content-password-protect/

    or: https://www.cliconomics.com/exclusive-content-password-protect/

    And this is what will go inside the wrapper..
    NextGen Gallery
    https://www.ads-software.com/extend/plugins/nextgen-gallery/

    or: https://www.nextgen-gallery.com/

    Thread Starter MrRedd

    (@mrredd)

    Ok..I just opened the plugin file for the Exclusive Content Password plugin…here is ALL the code on the bottom of the page.

    Hopefully this will post right since there is no preview button and it’s my first attempt at posting code.

    add_shortcode("password-protect", "ecpp_handler");
    
    function ecpp_handler($atts, $content = null) {
    	global $cpp_html, $ecpp_global_password;
    
    	extract(
    		shortcode_atts(
    			array(
    				"password" => $ecpp_global_password
    			),
    			$atts
    		)
    	);
    
    	 // This stores a session PASSWORD for each item..wether its individual or global..this is what will unlock it
    	$perm_hash = md5(get_permalink()) . md5($content);
    	$_SESSION[$perm_hash]['password'] = $password;
    
    	// this sets the global password in a session variable
    	$_SESSION['global_password'] = $ecpp_global_password;
    
    	if(!isset($_COOKIE["cpp-$perm_hash"])){
    		$content = str_replace('{TPLCPP_PERMHASH}', $perm_hash, parse_template($cpp_html));
    	}
    
    	return $content;
    
    }
    ?>

    right at the end of content-password-protect.php in the plugin’s folder, change:

    return $content;

    to:

    return do_shortcode($content);

    or follow the solution in this topic:

    https://www.ads-software.com/support/topic/plugin-exclusive-content-password-protect-no-evaluation-of-shortcodes?replies=2

    (not tested with ngg)

    Thread Starter MrRedd

    (@mrredd)

    YES!…that did the trick ??

    Thank you very much.

    Since I am here though and this really didn’t tell me why it worked…can you tell me what “the_content” is referring to etc.

    From the topic you posted above:

    already found the solution: just add this line BEFORE the final ‘return $content;’ of the main plugin file ‘content-password-protect.php’:

    $content = apply_filters(‘the_content’, $content);

    I get that $content is the output…a filter gets added to do something to it differently and then it gets displayed again…but what does “the_content” do?

    Sorry if it’s a dumb question…lol

    kind of difficult to explain;

    all post and page content gets by default filtered with the ‘the_content’ filter, which for instance takes care of the ‘more tag’, turning shortcodes into output, etc.

    https://codex.www.ads-software.com/Plugin_API/Filter_Reference/the_content
    https://codex.www.ads-software.com/Plugin_API/Filter_Reference

    Thread Starter MrRedd

    (@mrredd)

    Hmm…it sounds like it may be a place holder for the script to use in order to do the filtering??

    Like..name $content to the_content then do all the stuff…then rename it to $content with the filters done?

    Does that sound right?

    Probably not but that’s what I am seeing…lol

    And how about this question…
    Using the above example:
    $content = apply_filters('the_content', $content);

    What (and where) are the filters that are getting applied?
    I would expect to see something like apply_filter(UPPERCASE) or something…and yes that’s a bad example but I don’t know any filters yet..lol

    Man I think I need sleep…I am confusing myself as I am typing this ??

    the default filter are set in /wp-includes/default-filters.php; example:

    add_filter( 'the_content', 'wptexturize'        );
    add_filter( 'the_content', 'convert_smilies'    );
    add_filter( 'the_content', 'convert_chars'      );
    add_filter( 'the_content', 'wpautop'            );
    add_filter( 'the_content', 'shortcode_unautop'  );
    add_filter( 'the_content', 'prepend_attachment' );

    each of the names are referring to some functions which might be in any of the /wp-includes templates (or other folders);

    to find the code of functions, check for instance:

    https://phpxref.ftwr.co.uk/wordpress/nav.html?_functions/index.html

    where you get an alphabetical functions list

    click on a function name …

    this opens a new page, where you could click on the link below ‘Defined at:’ (this already shows the folder and template file name)

    this then opens the corresponding template file, and moves to the correct position in the file to show the full function (this is somtimes quite slow and might take a while …)

    Thread Starter MrRedd

    (@mrredd)

    to find the code of functions, check for instance:

    https://phpxref.ftwr.co.uk/wordpress/nav.html?_functions/index.html

    Wow that is a lot of functions…doh!

    That page isn’t a standard wordpress install is it?
    Meaning my site wouldn’t look like that with that many would it?

    Also…you showed the list of filters and where to find them (which is great) but I am still confused as to what filter is being applied when using the mentioned code:
    $content = apply_filters('the_content', $content);

    Thanks for all your help so far.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Short code – inside of short code – need help please’ is closed to new replies.