(Advanced) How to update entry approval status using PHP

If you want to update the approval status of an entry using PHP, you should use the GravityView_Entry_Approval::update_approved method:

// Check to make sure GravityView is loaded
if ( ! class_exists( 'GravityView_Entry_Approval' ) ) {
	return;	
}

/**
 * There are three options that should be used when updating entry approval statuses:
 *   GravityView_Entry_Approval_Status::APPROVED - Approved/Accepted entries
 *   GravityView_Entry_Approval_Status::DISAPPROVED - Disapproved/Rejected entries
 *   GravityView_Entry_Approval_Status::UNAPPROVED - Unapproved/Not Reviewed entries
 */
$updated = GravityView_Entry_Approval::update_approved( $entry_id, GravityView_Entry_Approval_Status::APPROVED );

if ( ! $updated ) {
  echo 'There are a few reasons this might not have worked. GFAPI class isn\'t found, invalid approval status, entry not found for that ID, or updating the entry in the database failed.';
} else {
  echo 'Thanks for reading!';	
}

Read here how to add these code samples to your website: Where to put code samples.

By default, this will add a note to the entry that the approval status has been updated by the current user. If you want to disable this entry note, you can do so with the gravityview/approve_entries/add-note filter:

add_filter( 'gravityview/approve_entries/add-note', '__return_false' );
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us