Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #87516
    Shawn
    Guest

    Since I couldn’t get the function script to work with PPWP plugin, I was able to modify this script to map the page id with a specific gravity form id. This works a charm – allows me to have multiple forms with multiple pw protected pages. Would be nice if you added this to your tutorial for future users.

    https://codeshare.io/xv3nYN (24h link)

    /*custom pw protected page*/
    /* https://www.boldgrid.com/support/wordpress-tutorials/edit-the-wordpress-password-protected-page/ */
    
    function my_custom_password_form() {
    		global $post;
    		$label = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );
    		
    	$output = '';
    $page_id = get_the_ID(); // Get the current page ID
    
    // Define an array that maps page IDs to form IDs
    $form_map = array(
      6844 => 8, // Map page ID 6844 to form ID 8
      2198 => 9, // Map page ID 2198 to form ID 9
      6990 => 9, // Map post ID 6990 to form ID 9
      // Add more mappings here as needed
    );
    
    if ( isset( $form_map[$page_id] ) ) {
      // If the current page ID is in the map, get the corresponding form ID
      $form_id = $form_map[$page_id];
    
      $output .= '
        <div class="boldgrid-section">
          <div class="container" style="text-align:center;">
            <form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="form-inline post-password-form" method="post">
              <p>' . __( 'To view page, please enter your code below:' ) . '</p>
              <label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" class="form-control" /></label><button type="submit" name="Submit" class="button-primary">' . esc_attr_x( 'Enter', 'post password form' ) . '</button>
            </form>
          </div>
          <div style="width:50%; margin:0 auto;">
            <hr>
            <h2>Request code</h2>
            [gravityform id="' . $form_id . '" title="false" description="false" ajax="true"]
          </div>
        </div>
      ';
    } else {
      // If the page ID is not in the map, return a 404 error
      $output = "404";
    }
    
    // Return the output
    return $output;
    
    }
    add_filter('the_password_form', 'my_custom_password_form', 99);
    
    /*END pw*/
    #87538
    Brandon C
    Keymaster

    Hi Shawn,

    We’ll definitely review your code and test with the PPWP plugin, Gravity forms and our BoldGrid products Crio Pro WordPress theme and BoldGrid Post and Page Builder for WordPress.

    If we feel this is a needed implementation we will definitely create a new article or update the existing one with the new information.

    We appreciate your for working on this and bringing it to our attention! Please let us know if there’s anything else that we can help with!

Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Modified PW protect page to work with Gravity Forms’ is closed to new replies.