Skip to content

Instantly share code, notes, and snippets.

@macbookandrew
Created February 25, 2019 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macbookandrew/bb528a7de6bf922464d76515532b92c6 to your computer and use it in GitHub Desktop.
Save macbookandrew/bb528a7de6bf922464d76515532b92c6 to your computer and use it in GitHub Desktop.
Returns false if goal is disabled
<?php
/**
* Plugin Name: Give - <code>get_goal()</code> fix
* Plugin URI: https://luminfire.com
* Description: Forces <code>get_goal()</code> to return false if goal is disabled for the form.
* Version: 1.0.0
* Author: LuminFire (Andrew Minion)
* Author URI: https://luminfire.com/
*
* @package give-get-goal-fix
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Checks to see if goal is enabled and if not, returns false.
*
* @param string $goal Goal amount.
* @param int $form_id Donation form ID.
*
* @return mixed Goal amount or false.
*/
add_filter(
'give_get_set_goal',
function( $goal, $form_id ) {
$goal_enabled = get_post_meta( $form_id, '_give_goal_option', true );
if ( 'disabled' === $goal_enabled ) {
return false;
}
return $goal;
},
10,
2
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment