• Resolved mathieuhays

    (@mathieuhays)


    Hi,

    The move to the REST API has removed the access to user info in some of the hooks made available by the plugin. (wpcf7_before_send_mail in my use-case)

    Can you please add the required Nonce to the ajax request performing the request so that we have access to the logged-in user within these hooks.

    I would have gladly done a pull-request but I haven’t found any link to a github/gitlab account.

    You can add a nonce in includes/controller.php l.56

    
    $wpcf7 = array(
      'apiSettings' => array(
        'root' => esc_url_raw( rest_url( 'contact-form-7/v1' ) ),
        'namespace' => 'contact-form-7/v1',
        'nonce' => wp_create_nonce( 'wp_rest' ),
      ),
      'recaptcha' => array(
        'messages' => array(
          'empty' =>
            __( 'Please verify that you are not a robot.', 'contact-form-7' ),
        ),
      ),
    );
    

    and change the ajax request parameters in includes/js/scripts.js l.335

    
    $.ajax( {
      type: 'POST',
      url: wpcf7.apiSettings.getRoute(
        '/contact-forms/' + wpcf7.getId( $form ) + '/feedback' ),
      data: formData,
      dataType: 'json',
      processData: false,
      contentType: false,
      beforeSend: function( xhr ) {
        xhr.setRequestHeader( 'X-WP-Nonce', wpcf7.apiSettings.nonce );
      }
    } ).done( function( data, status, xhr ) {
      ajaxSuccess( data, status, xhr, $form );
      $( '.ajax-loader', $form ).removeClass( 'is-active' );
    } ).fail( function( xhr, status, error ) {
      var $e = $( '<div class="ajax-error"></div>' ).text( error.message );
      $form.after( $e );
    } );
    

    Thanks ??

    • This topic was modified 7 years, 3 months ago by mathieuhays.
    • This topic was modified 7 years, 3 months ago by mathieuhays.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Fix user info access after submission’ is closed to new replies.