From b105ec00996455227fc83707af3bf651355f7161 Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Wed, 6 Nov 2019 00:33:28 -0600 Subject: [PATCH] Return early if contributor_post_id is missing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit process_my_pledges_form() is actually called on page load in render_my_pledges(). So to prevent the unnecessary get_post() queries, let’s just return early if the form wasn’t really submitted. --- plugins/wporg-5ftf/includes/contributor.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/wporg-5ftf/includes/contributor.php b/plugins/wporg-5ftf/includes/contributor.php index 3a5ba44..a5b1c62 100644 --- a/plugins/wporg-5ftf/includes/contributor.php +++ b/plugins/wporg-5ftf/includes/contributor.php @@ -306,11 +306,15 @@ function render_my_pledges() { * @return string */ function process_my_pledges_form() { - $message = ''; - $status = false; $contributor_post_id = filter_input( INPUT_POST, 'contributor_post_id', FILTER_VALIDATE_INT ); - $pledge = get_post( get_post( $contributor_post_id )->post_parent ); $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING ); + if ( empty( $contributor_post_id ) || empty( $nonce ) ) { + return ''; + } + + $message = ''; + $status = false; + $pledge = get_post( get_post( $contributor_post_id )->post_parent ); if ( filter_input( INPUT_POST, 'join_organization' ) ) { wp_verify_nonce( $nonce, 'join_decline_organization' ) || wp_nonce_ays( 'join_decline_organization' );