• Jon

    (@freshyjon)


    We would like to inject a Gravity Form (e.g., via shortcode) after your plugin’s Password input.

    Basically, if a user doesn’t know the password, we’d like to have a form under the input… so that the user can request the password via a Gravity Form. We have the Gravity Form ready, but can’t figure out how to add it below your password input.

    Do you have a PHP filter/hook that we can use, to be able to add PHP code after the password input?

    I see this here: https://i.imgur.com/Af81Hnh.png

    And we’d like to add our Gravity Form shortcode after your acpwd-container div but I wasn’t sure the best way to do that, without editing your actual plugin file.

    • This topic was modified 5 years, 2 months ago by Jon.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author jojaba

    (@jojaba)

    Hello Jon.

    I would suggest you to do it dynamicaly using JavaScript. This way you could avoid depending on the plugin updates. The HTML generated by the plugin (you can see it in the settings page) :

    <div class="acpwd-container">
       <p class="acpwd-added-excerpt">Here comes the Excerpt if enabled…</p>
       <p class="acpwd-info-message">This content has restricted access, please type the password below and get access.</p>
       <form class="acpwd-form" action="" method="post">
          <input class="acpwd-pass" type="password" name="acpwd-pass">
          <input class="acpwd-submit" type="submit" value="Get access">
       </form>
       <p class="acpwd-error-message">Sorry, but this is the wrong password.</p>
    </div>
    Thread Starter Jon

    (@freshyjon)

    Yes, I thought about inserting it with jQuery, but we are trying to add a Gravity Form. To do that, we need to be able to inject it via a shortcode. Unfortunately (as far as I know), jQuery doesn’t render PHP shortcodes when injecting it. It’d need to be done via some PHP method for the shortcode to be rendered properly.

    Plugin Author jojaba

    (@jojaba)

    As you can see in the code you gave, the form is inserted by filtering content and excerpt :

    add_filter( 'the_content', 'acpwd_frontend_changes', 2 );
    add_filter( 'the_excerpt', 'acpwd_frontend_changes', 3 );

    I’m not sure this will work, but you can add your shortcode using this filter and giving him a priority over 3.
    As I said, not sure that the shortcode will work, you have to see when it is converted to HTML…

    • This reply was modified 5 years, 2 months ago by jojaba.
    Thread Starter Jon

    (@freshyjon)

    This is what I ended up doing:

    /* add custom content related to Access Category Password plugin */
    
    // add content below existing content
    add_filter( 'the_content', 'fs_add_form_below_password_plugin' );
    function fs_add_form_below_password_plugin( $content ) {
    	
    	// set the variable of new_content to be regular content (in case our criteria isn't met, it will output regular content still)
    	$new_content = $content;
    
    	// get the options of the plugin settings
    	$acpwd_options = get_option('acpwd_settings_options');
    	
    	// check for the categories that were set to be impacted
    	$impacted_categories = (isset($acpwd_options['impacted_categories'])) ? $acpwd_options['impacted_categories'] : array();
    	
    	// if we are viewing a post within one of those categories
    	if ( in_category($impacted_categories) ) {
    		
    		// then add new content (Gravity Form shortcode with div wrapper) below the existing content
    		$new_content = '<div id="fs-password-form">[gravityform id="3" title="false" description="false" ajax="true"]</div>';
    		
    		// the content to output is the regular content plus the new_content
    		$content .= $new_content;
    		
    		// output all the content now
    		return $content;
    		
    	}
    	
    	// if the logic above wasn't met, then we still need to output the content
    	return $content;
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘PHP hooks to add additional content?’ is closed to new replies.