• I’m developing my first plugin extension for Contact Form 7.

    add_action( 'wpcf7_before_send_mail', 'wpcf7ev_verify_email_address' );
    
    function wpcf7ev_verify_email_address( &$wpcf7_form )
    {
        // save submitted form to the database
    
        // send email to the submitter with a verification link to click on
        //$submittersEmail = $wpcf7_form->posted_data["your-email"];
    
        // prevent the form being sent as per usual
        $wpcf7_form->skip_mail = true;
    }

    I’ve started getting an idea how to create it.. but how do I develop it without using something like alert() or console.log statements?

    Typically I would want to print the contents of the object parameter as a debug statement so that I could then work out the code to retrieve, say, the email address.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter magician11

    (@magician11)

    I worked out a long-ish way around.. I could mail the debug statements to myself..

    function wpcf7ev_debug( $message ) {
        wp_mail( '[email protected]', 'Debug code', print_r($message, true));
    }

    I’m sure there is a more efficient way?

    Moderator bcworkz

    (@bcworkz)

    You can use error_log() to enter arbitrary text in your error log.

    You can use var_dump() and print_r() to output values directly to your browser. Sometimes the output disappears because of how WP loads templates. Echoing <pre> tags to enclose the output often helps ensure the debug data remains visible. If all else fails, adding die() afterwards ensures the values are visible, though obviously execution will not continue, so you have to move it down through the code until you identify the error.

    There is some sort of debug framework for PHP. It maybe useful for serious development work, but seems out of scale for WP hacking.

    All crude one way or another. The best thing you can do is shorten the debug cycle time by eliminating the need to FTP or use the limited theme and plugin editors. Develop on a WP version installed locally on your own computer. There’s various versions of Apache that run in this environment, such as XAMPP.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘debugging PHP plugin code’ is closed to new replies.