WordPress.org

Ready to get started?Download WordPress

Forums

Short code - inside of short code - need help please (10 posts)

  1. MrRedd
    Member
    Posted 1 year ago #

    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:
    http://codex.wordpress.org/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.

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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.

  3. MrRedd
    Member
    Posted 1 year ago #

    This is the "WRAPPER" plugin shortcode [password-protect]...
    Exclusive Content Password Protect
    http://wordpress.org/extend/plugins/exclusive-content-password-protect/

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

    And this is what will go inside the wrapper..
    NextGen Gallery
    http://wordpress.org/extend/plugins/nextgen-gallery/

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

  4. MrRedd
    Member
    Posted 1 year ago #

    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;
    
    }
    ?>
  5. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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:

    http://wordpress.org/support/topic/plugin-exclusive-content-password-protect-no-evaluation-of-shortcodes?replies=2

    (not tested with ngg)

  6. MrRedd
    Member
    Posted 1 year ago #

    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

  7. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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.

    http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
    http://codex.wordpress.org/Plugin_API/Filter_Reference

  8. MrRedd
    Member
    Posted 1 year ago #

    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 :)

  9. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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:

    http://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 ...)

  10. MrRedd
    Member
    Posted 1 year ago #

    to find the code of functions, check for instance:

    http://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.

Topic Closed

This topic has been closed to new replies.

About this Topic