[ad_1]
class GFAPI {
// FORMS —————————————————-
/**
* Returns the shape object for a given Kind ID
*
* @since 1.8
* @entry public
* @static
*
* @param int $form_id The ID of the Kind
*
* @return combined The shape meta array or false
*/
public static perform get_form( $form_id ) {
$form_id = absint( $form_id );
$kind = GFFormsModel::get_form_meta( $form_id );
if ( ! $kind ) {
return false;
}
//loading kind columns into meta
$form_info = GFFormsModel::get_form( $form_id, true );
$kind[‘is_active’] = $form_info->is_active;
$kind[‘date_created’] = $form_info->date_created;
$kind[‘is_trash’] = $form_info->is_trash;
return $kind;
}
/**
* Returns all the shape objects
*
* @since 1.8.11.5
* @entry public
* @static
*
* @param bool $lively
* @param bool $trash
*
* @return combined The array of Varieties
*/
public static perform get_forms( $lively = true, $trash = false ) {
$form_ids = GFFormsModel::get_form_ids( $lively, $trash );
if ( empty( $form_ids ) ) {
return array();
}
$kinds = array();
foreach ( $form_ids as $form_id ) {
$kinds[] = GFAPI::get_form( $form_id );
}
return $kinds;
}
/**
* Deletes the kinds with the given Kind IDs
*
* @since 1.8
* @entry public
* @static
*
* @param array $form_ids An array of kind IDs to delete
*/
public static perform delete_forms( $form_ids ) {
GFFormsModel::delete_forms( $form_ids );
}
/**
* Deletes the shape with the given Kind ID
*
* @since 1.8
* @entry public
* @static
*
* @param int $form_id The ID of the Kind to delete
*
* @return combined True for achievement, or a WP_Error occasion
*/
public static perform delete_form( $form_id ) {
$kind = self::get_form( $form_id );
if ( empty( $kind ) ) {
return new WP_Error( ‘not_found’, sprintf( __( ‘Kind with id: %s not discovered’, ‘gravityforms’ ), $form_id ), $form_id );
}
self::delete_forms( array( $form_id ) );
return true;
}
/**
* Updates the kinds with an array of kind objects
*
* @since 1.8
* @entry public
* @static
*
* @param array $kinds The Kind objects
*
* @return combined True for achievement, or a WP_Error occasion
*/
public static perform update_forms( $kinds ) {
foreach ( $kinds as $kind ) {
$end result = self::update_form( $kind );
if ( is_wp_error( $end result ) ) {
return $end result;
}
}
return true;
}
/**
* Updates the shape with a given kind object.
*
* @since 1.8
* @entry public
* @static
*
* @param array $kind The Kind object
* @param int $form_id Optionally available. If specified, then the ID within the Kind object will probably be ignored
*
* @return combined True for achievement, or a WP_Error occasion
*/
public static perform update_form( $kind, $form_id = null ) {
world $wpdb;
if ( ! $kind ) {
return new WP_Error( ‘invalid’, __( ‘Invalid kind object’, ‘gravityforms’ ) );
}
$form_table_name = $wpdb->prefix . ‘rg_form’;
if ( empty( $form_id ) ) {
$form_id = $kind[‘id’];
} else {
// be certain that the shape object has the best kind id
$kind[‘id’] = $form_id;
if ( isset( $kind[‘fields’] ) ) {
foreach ( $kind[‘fields’] as &$subject ) {
if ( $subject instanceof GF_Field ) {
$field->formId = $form_id;
} else {
$subject[‘formId’] = $form_id;
}
}
}
}
if ( empty( $form_id ) ) {
return new WP_Error( ‘missing_form_id’, __( ‘Lacking kind id’, ‘gravityforms’ ) );
}
$meta_table_name = GFFormsModel::get_meta_table_name();
if ( intval( $wpdb->get_var( $wpdb->put together( “SELECT rely(0) FROM {$meta_table_name} WHERE form_id=%d”, $form_id ) ) ) == 0 ) {
return new WP_Error( ‘not_found’, __( ‘Kind not discovered’, ‘gravityforms’ ) );
}
// Strip confirmations and notifications
$form_display_meta = $kind;
unset( $form_display_meta[‘confirmations’] );
unset( $form_display_meta[‘notifications’] );
$end result = GFFormsModel::update_form_meta( $form_id, $form_display_meta );
if ( false === $end result ) {
return new WP_Error( ‘error_updating_form’, __( ‘Error updating kind’, ‘gravityforms’ ), $wpdb->last_error );
}
if ( isset( $kind[‘confirmations’] ) && is_array( $kind[‘confirmations’] ) ) {
$end result = GFFormsModel::update_form_meta( $form_id, $kind[‘confirmations’], ‘confirmations’ );
if ( false === $end result ) {
return new WP_Error( ‘error_updating_confirmations’, __( ‘Error updating kind confirmations’, ‘gravityforms’ ), $wpdb->last_error );
}
}
if ( isset( $kind[‘notifications’] ) && is_array( $kind[‘notifications’] ) ) {
$end result = GFFormsModel::update_form_meta( $form_id, $kind[‘notifications’], ‘notifications’ );
if ( false === $end result ) {
return new WP_Error( ‘error_updating_notifications’, __( ‘Error updating kind notifications’, ‘gravityforms’ ), $wpdb->last_error );
}
}
//updating kind title and is_active flag
$is_active = rgar( $kind, ‘is_active’ ) ? ‘1’ : ‘0’;
$end result = $wpdb->question( $wpdb->put together( “UPDATE {$form_table_name} SET title=%s, is_active=%s WHERE id=%d”, $kind[‘title’], $is_active, $kind[‘id’] ) );
if ( false === $end result ) {
return new WP_Error( ‘error_updating_title’, __( ‘Error updating title’, ‘gravityforms’ ), $wpdb->last_error );
}
return true;
}
/**
* Updates a kind property – a column in the principle kinds desk. e.g. is_trash, is_active, title
*
* @since 1.8.3.15
* @entry public
* @static
*
* @param array $form_ids The IDs of the kinds to replace
* @param array $property_key The title of the column within the database e.g. is_trash, is_active, title
* @param array $worth The brand new worth
*
* @return combined Both a WP_Error occasion or the results of the question
*/
public static perform update_forms_property( $form_ids, $property_key, $worth ) {
world $wpdb;
$desk = GFFormsModel::get_form_table_name();
$db_columns = GFFormsModel::get_form_db_columns();
if ( ! in_array( strtolower( $property_key ), $db_columns ) ) {
return new WP_Error( ‘property_key_incorrect’, __( ‘Property key incorrect’, ‘gravityforms’ ) );
}
$worth = esc_sql( $worth );
if ( ! is_numeric( $worth ) ) {
$worth = sprintf( “‘%s'”, $worth );
}
$in_str_arr = array_fill( 0, rely( $form_ids ), ‘%d’ );
$in_str = be a part of( $in_str_arr, ‘, ‘ );
$end result = $wpdb->question(
$wpdb->put together(
”
UPDATE $desk
SET {$property_key} = {$worth}
WHERE id IN ($in_str)
“, $form_ids
)
);
return $end result;
}
/**
* Updates the property of 1 kind – columns in the principle kinds desk. e.g. is_trash, is_active, title
*
* @since 1.8.3.15
* @entry public
* @static
*
* @param array|int $form_id The ID of the kinds to replace
* @param string $property_key The title of the column within the database e.g. is_trash, is_active, title
* @param string $worth The brand new worth
*
* @return combined Both a WP_Error occasion or the results of the question
*/
public static perform update_form_property( $form_id, $property_key, $worth ) {
return self::update_forms_property( array( $form_id ), $property_key, $worth );
}
/**
* Provides a number of kind objects.
*
* @since 1.8
* @entry public
* @static
*
* @param array $kinds The Kind objects
*
* @return combined Both an array of recent kind IDs or a WP_Error occasion
*/
public static perform add_forms( $kinds ) {
if ( ! $kinds || ! is_array( $kinds ) ) {
return new WP_Error( ‘invalid’, __( ‘Invalid kind objects’, ‘gravityforms’ ) );
}
$form_ids = array();
foreach ( $kinds as $kind ) {
$end result = self::add_form( $kind );
if ( is_wp_error( $end result ) ) {
return $end result;
}
$form_ids[] = $end result;
}
return $form_ids;
}
/**
* Provides a brand new kind utilizing the given Kind object. Warning, little checking is completed to ensure it is a legitimate Kind object.
*
* @since 1.8
* @entry public
* @static
*
* @param array $form_meta The Kind object
*
* @return combined Both the brand new Kind ID or a WP_Error occasion
*/
public static perform add_form( $form_meta ) {
world $wpdb;
if ( ! $form_meta || ! is_array( $form_meta ) ) {
return new WP_Error( ‘invalid’, __( ‘Invalid kind object’, ‘gravityforms’ ) );
}
if ( rgar( $form_meta, ‘title’ ) == ” ) {
return new WP_Error( ‘missing_title’, __( ‘The shape title is lacking’, ‘gravityforms’ ) );
}
//Ensuring title isn’t duplicate
$title = $form_meta[‘title’];
$rely = 2;
whereas ( ! RGFormsModel::is_unique_title( $title ) ) {
$title = $form_meta[‘title’] . “($rely)”;
$rely ++;
}
//inserting kind
$form_id = RGFormsModel::insert_form( $title );
//updating kind meta
$form_meta[‘title’] = $title;
//updating object’s id property
$form_meta[‘id’] = $form_id;
if ( isset( $form_meta[‘confirmations’] ) ) {
$form_meta[‘confirmations’] = self::set_property_as_key( $form_meta[‘confirmations’], ‘id’ );
GFFormsModel::update_form_meta( $form_id, $form_meta[‘confirmations’], ‘confirmations’ );
unset( $form_meta[‘confirmations’] );
}
if ( isset( $form_meta[‘notifications’] ) ) {
$form_meta[‘notifications’] = self::set_property_as_key( $form_meta[‘notifications’], ‘id’ );
GFFormsModel::update_form_meta( $form_id, $form_meta[‘notifications’], ‘notifications’ );
unset( $form_meta[‘notifications’] );
}
//updating kind meta
$end result = GFFormsModel::update_form_meta( $form_id, $form_meta );
if ( false === $end result ) {
return new WP_Error( ‘insert_form_error’, __( ‘There was an issue whereas inserting the shape’, ‘gravityforms’ ), $wpdb->last_error );
}
return $form_id;
}
/**
* Personal.
*
* @since 1.8
* @entry personal
* @static
* @ignore
*/
personal static perform set_property_as_key( $array, $property ) {
$new_array = array();
foreach ( $array as $merchandise ) {
$new_array[ $item[ $property ] ] = $merchandise;
}
return $new_array;
}
// ENTRIES —————————————————-
/**
* Returns an array of Entry objects for the given search standards. The search standards array is constructed as follows:
*
* Filter by standing
* $search_criteria[‘status’] = ‘lively’;
*
* Filter by date vary
* $search_criteria[‘start_date’] = $start_date;
* $search_criteria[‘end_date’] = $end_date;
*
* Filter by any column in the principle desk
* $search_criteria[‘field_filters’][] = array(“key” => ‘foreign money’, worth => ‘USD’);
* $search_criteria[‘field_filters’][] = array(“key” => ‘is_read’, worth => true);
*
* Filter by Area Values
* $search_criteria[‘field_filters’][] = array(‘key’ => ‘1’, ‘worth’ => ‘gquiz159982170’);
*
* Filter Operators
* Supported operators for scalar values: is/=, isnot/<>, incorporates
* $search_criteria[‘field_filters’][] = array(‘key’ => ‘1’, ‘operator’ => ‘incorporates’, worth’ => ‘Steve’);
* Supported operators for array values: in/=, not in/<>/!=
* $search_criteria[‘field_filters’][] = array(‘key’ => ‘1’, ‘operator’ => ‘not in’, worth’ => array( ‘Alex’, ‘David’, ‘Dana’ );
*
* Filter by a checkbox worth (not really helpful)
* $search_criteria[‘field_filters’][] = array(‘key’ => ‘2.2’, ‘worth’ => ‘gquiz246fec995’);
* be aware: this may work for checkboxes however it will not work if the checkboxes have been re-ordered – greatest to make use of the next examples beneath
*
* Filter by a checkbox worth (really helpful)
* $search_criteria[‘field_filters’][] = array(‘key’ => ‘2’, ‘worth’ => ‘gquiz246fec995’);
* $search_criteria[‘field_filters’][] = array(‘key’ => ‘2’, ‘operator’ => ‘not in’, worth’ => array( ‘First Selection’, ‘Third Selection’ );
*
* Filter by a world search of values of any kind subject
* $search_criteria[‘field_filters’][] = array(‘worth’ => $search_value);
* OR
* $search_criteria[‘field_filters’][] = array(‘key’ => 0, ‘worth’ => $search_value);
*
* Filter entries by Entry meta (added utilizing the gform_entry_meta hook)
* $search_criteria[‘field_filters’][] = array(‘key’ => ‘gquiz_score’, ‘worth’ => ‘1’);
* $search_criteria[‘field_filters’][] = array(‘key’ => ‘gquiz_is_pass’, ‘worth’ => ‘1’);
*
* Filter by ALL / ANY of the sphere filters
* $search_criteria[‘field_filters’][‘mode’] = ‘all’; // default
* $search_criteria[‘field_filters’][‘mode’] = ‘any’;
*
* Sorting: column, subject or entry meta
* $sorting = array(‘key’ => $sort_field, ‘course’ => ‘ASC’ );
*
* Paging
* $paging = array(‘offset’ => 0, ‘page_size’ => 20 );
*
*
*
* @since 1.8
* @entry public
* @static
*
* @param int|array $form_ids The ID of the shape or an array IDs of the Varieties. Zero for all kinds.
* @param array $search_criteria Optionally available. An array containing the search standards
* @param array $sorting Optionally available. An array containing the sorting standards
* @param array $paging Optionally available. An array containing the paging standards
* @param int $total_count Optionally available. An output parameter containing the entire variety of entries. Go a non-null worth to get the entire rely.
*
* @return combined Both an array of the Entry objects or a WP_Error occasion
*/
public static perform get_entries( $form_ids, $search_criteria = array(), $sorting = null, $paging = null, &$total_count = null ) {
if ( empty( $sorting ) ) {
$sorting = array( ‘key’ => ‘id’, ‘course’ => ‘DESC’, ‘is_numeric’ => true );
}
$entries = GFFormsModel::search_leads( $form_ids, $search_criteria, $sorting, $paging );
if ( ! is_null( $total_count ) ) {
$total_count = self::count_entries( $form_ids, $search_criteria );
}
return $entries;
}
/**
* Returns the entire variety of entries for the given search standards. See get_entries() for examples of the search standards.
*
* @since 1.8
* @entry public
* @static
*
* @param int|array $form_ids The ID of the Kind or an array of Kind IDs
* @param array $search_criteria Optionally available. An array containing the search standards
*
* @return int The entire rely
*/
public static perform count_entries( $form_ids, $search_criteria = array() ) {
return GFFormsModel::count_search_leads( $form_ids, $search_criteria );
}
/**
* Returns the Entry object for a given Entry ID
*
* @since 1.8
* @entry public
* @static
*
* @param int $entry_id The ID of the Entry
*
* @return combined The Entry object or a WP_Error occasion
*/
public static perform get_entry( $entry_id ) {
$search_criteria[‘field_filters’][] = array( ‘key’ => ‘id’, ‘worth’ => $entry_id );
$paging = array( ‘offset’ => 0, ‘page_size’ => 1 );
$entries = self::get_entries( 0, $search_criteria, null, $paging );
if ( empty( $entries ) ) {
return new WP_Error( ‘not_found’, sprintf( __( ‘Entry with id %s not discovered’, ‘gravityforms’ ), $entry_id ), $entry_id );
}
return $entries[0];
}
/**
* Provides a number of Entry objects.
*
* @since 1.8
* @entry public
* @static
*
* @param array $entries The Entry objects
* @param int $form_id Optionally available. If specified, the form_id within the Entry objects will probably be ignored
*
* @return combined Both an array of recent Entry IDs or a WP_Error occasion
*/
public static perform add_entries( $entries, $form_id = null ) {
$entry_ids = array();
foreach ( $entries as $entry ) {
if ( $form_id ) {
$entry[‘form_id’] = $form_id;
}
$end result = self::add_entry( $entry );
if ( is_wp_error( $end result ) ) {
return $end result;
}
$entry_ids[] = $end result;
}
return $entry_ids;
}
/**
* Updates a number of Entry objects.
*
* @since 1.8
* @entry public
* @static
*
* @param array $entries The Entry objects
*
* @return combined Both True for achievement, or a WP_Error occasion
*/
public static perform update_entries( $entries ) {
foreach ( $entries as $entry ) {
$entry_id = rgar( $entry, ‘id’ );
GFCommon::log_debug( ‘Updating entry ‘ . $entry_id );
$end result = self::update_entry( $entry, $entry_id );
if ( is_wp_error( $end result ) ) {
return $end result;
}
}
return true;
}
/**
* Updates a single Entry object.
*
* @since 1.8
* @entry public
* @static
*
* @param array $entry The Entry object
* @param int $entry_id Optionally available. If specified, the ID within the Entry object will probably be ignored
*
* @return combined Both True or a WP_Error occasion
*/
public static perform update_entry( $entry, $entry_id = null ) {
world $wpdb;
if ( empty( $entry_id ) ) {
if ( rgar( $entry, ‘id’ ) ) {
$entry_id = absint( $entry[‘id’] );
}
} else {
$entry[‘id’] = absint( $entry_id );
}
if ( empty( $entry_id ) ) {
return new WP_Error( ‘missing_entry_id’, __( ‘Lacking entry id’, ‘gravityforms’ ) );
}
$current_entry = $original_entry = self::get_entry( $entry_id );
if ( ! $current_entry ) {
return new WP_Error( ‘not_found’, __( ‘Entry not discovered’, ‘gravityforms’ ), $entry_id );
}
if ( is_wp_error( $current_entry ) ) {
return $current_entry;
}
// be certain that the shape id exists
$form_id = rgar( $entry, ‘form_id’ );
if ( empty( $form_id ) ) {
$form_id = rgar( $current_entry, ‘form_id’ );
}
if ( false === self::form_id_exists( $form_id ) ) {
return new WP_Error( ‘invalid_form_id’, __( ‘The shape for this entry doesn’t exist’, ‘gravityforms’ ) );
}
$entry = apply_filters( ‘gform_entry_pre_update’, $entry, $original_entry );
// use values within the entry object if current
$post_id = isset( $entry[‘post_id’] ) ? intval( $entry[‘post_id’] ) : ‘NULL’;
$date_created = isset( $entry[‘date_created’] ) ? sprintf( “‘%s'”, esc_sql( $entry[‘date_created’] ) ) : ‘utc_timestamp()’;
$is_starred = isset( $entry[‘is_starred’] ) ? $entry[‘is_starred’] : 0;
$is_read = isset( $entry[‘is_read’] ) ? $entry[‘is_read’] : 0;
$ip = isset( $entry[‘ip’] ) ? $entry[‘ip’] : GFFormsModel::get_ip();
$source_url = isset( $entry[‘source_url’] ) ? $entry[‘source_url’] : GFFormsModel::get_current_page_url();
$user_agent = isset( $entry[‘user_agent’] ) ? $entry[‘user_agent’] : ‘API’;
$foreign money = isset( $entry[‘currency’] ) ? $entry[‘currency’] : GFCommon::get_currency();
$payment_status = isset( $entry[‘payment_status’] ) ? sprintf( “‘%s'”, esc_sql( $entry[‘payment_status’] ) ) : ‘NULL’;
$payment_date = strtotime( rgar( $entry, ‘payment_date’ ) ) ? “‘” . gmdate( ‘Y-m-d H:i:s’, strtotime( “{$entry[‘payment_date’]}” ) ) . “‘” : ‘NULL’;
$payment_amount = isset( $entry[‘payment_amount’] ) ? (float) $entry[‘payment_amount’] : ‘NULL’;
$payment_method = isset( $entry[‘payment_method’] ) ? $entry[‘payment_method’] : ”;
$transaction_id = isset( $entry[‘transaction_id’] ) ? sprintf( “‘%s'”, esc_sql( $entry[‘transaction_id’] ) ) : ‘NULL’;
$is_fulfilled = isset( $entry[‘is_fulfilled’] ) ? intval( $entry[‘is_fulfilled’] ) : ‘NULL’;
$standing = isset( $entry[‘status’] ) ? $entry[‘status’] : ‘lively’;
world $current_user;
$user_id = isset( $entry[‘created_by’] ) ? absint( $entry[‘created_by’] ) : ”;
if ( empty( $user_id ) ) {
$user_id = $current_user && $current_user->ID ? absint( $current_user->ID ) : ‘NULL’;
}
$transaction_type = isset( $entry[‘transaction_type’] ) ? intval( $entry[‘transaction_type’] ) : ‘NULL’;
$lead_table = GFFormsModel::get_lead_table_name();
$sql = $wpdb->put together(
”
UPDATE $lead_table
SET
form_id = %d,
post_id = {$post_id},
date_created = {$date_created},
is_starred = %d,
is_read = %d,
ip = %s,
source_url = %s,
user_agent = %s,
foreign money = %s,
payment_status = {$payment_status},
payment_date = {$payment_date},
payment_amount = {$payment_amount},
transaction_id = {$transaction_id},
is_fulfilled = {$is_fulfilled},
created_by = {$user_id},
transaction_type = {$transaction_type},
standing = %s,
payment_method = %s
WHERE
id = %d
“, $form_id, $is_starred, $is_read, $ip, $source_url, $user_agent, $foreign money, $standing, $payment_method, $entry_id
);
$end result = $wpdb->question( $sql );
if ( false === $end result ) {
return new WP_Error( ‘update_entry_properties_failed’, __( ‘There was an issue whereas updating the entry properties’, ‘gravityforms’ ), $wpdb->last_error );
}
// solely save subject values for fields that at present exist within the kind. The remaining in $entry will probably be ignored. The remaining in $current_entry will get deleted.
$lead_detail_table = GFFormsModel::get_lead_details_table_name();
$current_fields = $wpdb->get_results( $wpdb->put together( “SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d”, $entry_id ) );
$kind = GFFormsModel::get_form_meta( $form_id );
$kind = gf_apply_filters( array( ‘gform_form_pre_update_entry’, $form_id ), $kind, $entry, $entry_id );
foreach ( $kind[‘fields’] as $subject ) {
/** @var GF_Field $subject */
$kind = GFFormsModel::get_input_type( $subject );
if ( in_array( $kind, array( ‘html’, ‘web page’, ‘part’ ) ) ) {
proceed;
}
$inputs = $field->get_entry_inputs();
if ( is_array( $inputs ) ) {
foreach ( $field->inputs as $enter ) {
$input_id = (string) $enter[‘id’];
if ( isset( $entry[ $input_id ] ) ) {
if ( $entry[ $input_id ] != $current_entry[ $input_id ] ) {
$lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id );
$end result = GFFormsModel::update_lead_field_value( $kind, $entry, $subject, $lead_detail_id, $input_id, $entry[ $input_id ] );
if ( false === $end result ) {
return new WP_Error( ‘update_input_value_failed’, __( ‘There was an issue whereas updating one of many enter values for the entry’, ‘gravityforms’ ), $wpdb->last_error );
}
}
unset( $current_entry[ $input_id ] );
}
}
} else {
$field_id = $field->id;
$field_value = isset( $entry[ (string) $field_id ] ) ? $entry[ (string) $field_id ] : ”;
if ( $field_value != $current_entry[ $field_id ] ) {
$lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $field_id );
$end result = GFFormsModel::update_lead_field_value( $kind, $entry, $subject, $lead_detail_id, $field_id, $field_value );
if ( false === $end result ) {
return new WP_Error( ‘update_field_values_failed’, __( ‘There was an issue whereas updating the sphere values’, ‘gravityforms’ ), $wpdb->last_error );
}
}
unset( $current_entry[ $field_id ] );
}
}
// save the entry meta values – just for the entry meta at present obtainable for the shape, ignore the remainder
$entry_meta = GFFormsModel::get_entry_meta( $form_id );
if ( is_array( $entry_meta ) ) {
foreach ( array_keys( $entry_meta ) as $key ) {
if ( isset( $entry[ $key ] ) ) {
if ( $entry[ $key ] != $current_entry[ $key ] ) {
gform_update_meta( $entry_id, $key, $entry[ $key ] );
}
unset( $current_entry[ $key ] );
}
}
}
// now delete remaining values from the outdated entry
if ( is_array( $entry_meta ) ) {
foreach ( array_keys( $entry_meta ) as $meta_key ) {
if ( isset( $current_entry[ $meta_key ] ) ) {
gform_delete_meta( $entry_id, $meta_key );
unset( $current_entry[ $meta_key ] );
}
}
}
foreach ( $current_entry as $okay => $v ) {
$lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $okay );
$subject = GFFormsModel::get_field( $kind, $okay );
$end result = GFFormsModel::update_lead_field_value( $kind, $entry, $subject, $lead_detail_id, $okay, ” );
if ( false === $end result ) {
return new WP_Error( ‘update_field_values_failed’, __( ‘There was an issue whereas updating the sphere values’, ‘gravityforms’ ), $wpdb->last_error );
}
}
/**
* Fires after the Entry is up to date.
*
* @param array $lead The entry object after being up to date.
* @param array $original_entry The entry object earlier than being up to date.
*/
gf_do_action( array( ‘gform_post_update_entry’, $form_id ), $entry, $original_entry );
return true;
}
/**
* Provides a single Entry object.
*
* Supposed for use for importing an entry object. The same old hooks which are triggered whereas saving entries are usually not fired right here.
* Checks that the shape id, subject ids and entry meta exist and ignores legacy values (i.e. values for fields that now not exist).
*
* @since 1.8
* @entry public
* @static
*
* @param array $entry The Entry object
*
* @return combined Both the brand new Entry ID or a WP_Error occasion
*/
public static perform add_entry( $entry ) {
world $wpdb;
if ( ! is_array( $entry ) ) {
return new WP_Error( ‘invalid_entry_object’, __( ‘The entry object should be an array’, ‘gravityforms’ ) );
}
// be certain that the shape id exists
$form_id = rgar( $entry, ‘form_id’ );
if ( empty( $form_id ) ) {
return new WP_Error( ’empty_form_id’, __( ‘The shape id should be specified’, ‘gravityforms’ ) );
}
if ( false === self::form_id_exists( $form_id ) ) {
return new WP_Error( ‘invalid_form_id’, __( ‘The shape for this entry doesn’t exist’, ‘gravityforms’ ) );
}
// use values within the entry object if current
$post_id = isset( $entry[‘post_id’] ) ? intval( $entry[‘post_id’] ) : ‘NULL’;
$date_created = isset( $entry[‘date_created’] ) && $entry[‘date_created’] != ” ? sprintf( “‘%s'”, esc_sql( $entry[‘date_created’] ) ) : ‘utc_timestamp()’;
$is_starred = isset( $entry[‘is_starred’] ) ? $entry[‘is_starred’] : 0;
$is_read = isset( $entry[‘is_read’] ) ? $entry[‘is_read’] : 0;
$ip = isset( $entry[‘ip’] ) ? $entry[‘ip’] : GFFormsModel::get_ip();
$source_url = isset( $entry[‘source_url’] ) ? $entry[‘source_url’] : esc_url_raw( GFFormsModel::get_current_page_url() );
$user_agent = isset( $entry[‘user_agent’] ) ? $entry[‘user_agent’] : ‘API’;
$foreign money = isset( $entry[‘currency’] ) ? $entry[‘currency’] : GFCommon::get_currency();
$payment_status = isset( $entry[‘payment_status’] ) ? sprintf( “‘%s'”, esc_sql( $entry[‘payment_status’] ) ) : ‘NULL’;
$payment_date = strtotime( rgar( $entry, ‘payment_date’ ) ) ? sprintf( “‘%s'”, gmdate( ‘Y-m-d H:i:s’, strtotime( “{$entry[‘payment_date’]}” ) ) ) : ‘NULL’;
$payment_amount = isset( $entry[‘payment_amount’] ) ? (float) $entry[‘payment_amount’] : ‘NULL’;
$payment_method = isset( $entry[‘payment_method’] ) ? $entry[‘payment_method’] : ”;
$transaction_id = isset( $entry[‘transaction_id’] ) ? sprintf( “‘%s'”, esc_sql( $entry[‘transaction_id’] ) ) : ‘NULL’;
$is_fulfilled = isset( $entry[‘is_fulfilled’] ) ? intval( $entry[‘is_fulfilled’] ) : ‘NULL’;
$standing = isset( $entry[‘status’] ) ? $entry[‘status’] : ‘lively’;
world $current_user;
$user_id = isset( $entry[‘created_by’] ) ? absint( $entry[‘created_by’] ) : ”;
if ( empty( $user_id ) ) {
$user_id = $current_user && $current_user->ID ? absint( $current_user->ID ) : ‘NULL’;
}
$transaction_type = isset( $entry[‘transaction_type’] ) ? intval( $entry[‘transaction_type’] ) : ‘NULL’;
$lead_table = GFFormsModel::get_lead_table_name();
$end result = $wpdb->question(
$wpdb->put together(
”
INSERT INTO $lead_table
(form_id, post_id, date_created, is_starred, is_read, ip, source_url, user_agent, foreign money, payment_status, payment_date, payment_amount, transaction_id, is_fulfilled, created_by, transaction_type, standing, payment_method)
VALUES
(%d, {$post_id}, {$date_created}, %d, %d, %s, %s, %s, %s, {$payment_status}, {$payment_date}, {$payment_amount}, {$transaction_id}, {$is_fulfilled}, {$user_id}, {$transaction_type}, %s, %s)
“, $form_id, $is_starred, $is_read, $ip, $source_url, $user_agent, $foreign money, $standing, $payment_method
)
);
if ( false === $end result ) {
return new WP_Error( ‘insert_entry_properties_failed’, __( ‘There was an issue whereas inserting the entry properties’, ‘gravityforms’ ), $wpdb->last_error );
}
// studying newly created lead id
$entry_id = $wpdb->insert_id;
$entry[‘id’] = $entry_id;
// solely save subject values for fields that at present exist within the kind
$kind = GFFormsModel::get_form_meta( $form_id );
foreach ( $kind[‘fields’] as $subject ) {
/** @var GF_Field $subject */
if ( in_array( $field->kind, array( ‘html’, ‘web page’, ‘part’ ) ) ) {
proceed;
}
$inputs = $field->get_entry_inputs();
if ( is_array( $inputs ) ) {
foreach ( $inputs as $enter ) {
$input_id = (string) $enter[‘id’];
if ( isset( $entry[ $input_id ] ) ) {
$end result = GFFormsModel::update_lead_field_value( $kind, $entry, $subject, 0, $input_id, $entry[ $input_id ] );
if ( false === $end result ) {
return new WP_Error( ‘insert_input_value_failed’, __( ‘There was an issue whereas inserting one of many enter values for the entry’, ‘gravityforms’ ), $wpdb->last_error );
}
}
}
} else {
$field_id = $field->id;
$field_value = isset( $entry[ (string) $field_id ] ) ? $entry[ (string) $field_id ] : ”;
$end result = GFFormsModel::update_lead_field_value( $kind, $entry, $subject, 0, $field_id, $field_value );
if ( false === $end result ) {
return new WP_Error( ‘insert_field_values_failed’, __( ‘There was an issue whereas inserting the sphere values’, ‘gravityforms’ ), $wpdb->last_error );
}
}
}
// add save the entry meta values – just for the entry meta at present obtainable for the shape, ignore the remainder
$entry_meta = GFFormsModel::get_entry_meta( $form_id );
if ( is_array( $entry_meta ) ) {
foreach ( array_keys( $entry_meta ) as $key ) {
if ( isset( $entry[ $key ] ) ) {
gform_update_meta( $entry_id, $key, $entry[ $key ], $kind[‘id’] );
}
}
}
return $entry_id;
}
/**
* Deletes a single Entry.
*
* @since 1.8
* @entry public
* @static
*
* @param int $entry_id The ID of the Entry object
*
* @return combined Both true for achievement or a WP_Error occasion
*/
public static perform delete_entry( $entry_id ) {
$entry = GFFormsModel::get_lead( $entry_id );
if ( empty( $entry ) ) {
return new WP_Error( ‘invalid_entry_id’, sprintf( __( ‘Invalid entry id: %s’, ‘gravityforms’ ), $entry_id ), $entry_id );
}
GFFormsModel::delete_lead( $entry_id );
return true;
}
/**
* Updates a single property of an entry.
*
* @since 1.8.3.1
* @entry public
* @static
*
* @param int $entry_id The ID of the Entry object
* @param string $property The property of the Entry object to be up to date
* @param combined $worth The worth to which the property needs to be set
*
* @return bool Whether or not the entry property was up to date efficiently
*/
public static perform update_entry_property( $entry_id, $property, $worth ) {
return GFFormsModel::update_lead_property( $entry_id, $property, $worth );
}
/**
* Updates a single subject of an entry.
*
* @since 1.9
* @entry public
* @static
*
* @param int $entry_id The ID of the Entry object
* @param string $input_id The id of the enter to be up to date. For single enter fields corresponding to textual content, paragraph, web site, drop down and so forth… this would be the similar as the sphere ID.
* For multi enter fields corresponding to title, deal with, checkboxes, and so forth… the enter id will probably be within the format {FIELD_ID}.{INPUT NUMBER}. ( i.e. “1.3” )
* The $input_id could be obtained by inspecting the important thing for the desired subject within the $entry object.
*
* @param combined $worth The worth to which the sphere needs to be set
*
* @return bool Whether or not the entry property was up to date efficiently
*/
public static perform update_entry_field( $entry_id, $input_id, $worth ) {
world $wpdb;
$entry = self::get_entry( $entry_id );
if ( is_wp_error( $entry ) ) {
return $entry;
}
$kind = self::get_form( $entry[‘form_id’] );
if ( ! $kind ) {
return false;
}
$subject = GFFormsModel::get_field( $kind, $input_id );
$input_id_min = (float) $input_id – 0.0001;
$input_id_max = (float) $input_id + 0.0001;
$lead_details_table_name = GFFormsModel::get_lead_details_table_name();
$lead_detail_id = $wpdb->get_var( $wpdb->put together( “SELECT id FROM {$lead_details_table_name} WHERE lead_id=%d AND field_number BETWEEN %s AND %s”, $entry_id, $input_id_min, $input_id_max ) );
$end result = true;
if ( ! isset( $entry[ $input_id ] ) || $entry[ $input_id ] != $worth ) {
$end result = GFFormsModel::update_lead_field_value( $kind, $entry, $subject, $lead_detail_id, $input_id, $worth );
}
return $end result;
}
// FORM SUBMISSIONS ——————————————-
/**
* Submits a kind. Use this perform to ship enter values by the whole kind submission course of.
* Helps subject validation, notifications, confirmations, multiple-pages and save & proceed.
*
* Instance utilization:
* $input_values[‘input_1’] = ‘Single line textual content’;
* $input_values[‘input_2_3’] = ‘First title’;
* $input_values[‘input_2_6’] = ‘Final title’;
* $input_values[‘input_5’] = ‘A paragraph of textual content.’;
* //$input_values[‘gform_save’] = true; // help for save and proceed
*
* $end result = GFAPI::submit_form( 52, $input_values );
*
* Instance output for a profitable submission:
* ‘is_valid’ => boolean true
* ‘page_number’ => int 0
* ‘source_page_number’ => int 1
* ‘confirmation_message’ => string ‘affirmation message [snip]’
*
* Instance output for failed validation:
* ‘is_valid’ => boolean false
* ‘validation_messages’ =>
* array (measurement=1)
* 2 => string ‘This subject is required. Please enter the primary and final title.’
* ‘page_number’ => int 1
* ‘source_page_number’ => int 1
* ‘confirmation_message’ => string ”
*
*
* Instance output for save and proceed:
* ‘is_valid’ => boolean true
* ‘page_number’ => int 1
* ‘source_page_number’ => int 1
* ‘confirmation_message’ => string ‘Please use the next hyperlink to return to your kind from any laptop. [snip]’
* ‘resume_token’ => string ‘045f941cc4c04d479556bab1db6d3495’
*
*
* @param int $form_id The Kind ID
* @param array $input_values An array of values.
* @param array $field_values Optionally available.
* @param int $target_page Optionally available.
* @param int $source_page Optionally available.
*
* @return array An array containing the results of the submission.
*/
public static perform submit_form( $form_id, $input_values, $field_values = array(), $target_page = 0, $source_page = 1 ) {
$form_id = absint( $form_id );
$kind = GFAPI::get_form( $form_id );
if ( empty( $kind ) || ! $kind[‘is_active’] || $kind[‘is_trash’] ) {
return new WP_Error( ‘form_not_found’, __( ‘Your kind couldn’t be discovered’, ‘gravityforms’ ) );
}
$input_values[ ‘is_submit_’ . $form_id ] = true;
$input_values[‘gform_submit’] = $form_id;
$input_values[ ‘gform_target_page_number_’ . $form_id ] = absint( $target_page );
$input_values[ ‘gform_source_page_number_’ . $form_id ] = absint( $source_page );
$input_values[‘gform_field_values’] = $field_values;
require_once(GFCommon::get_base_path() . ‘/form_display.php’);
if ( ! isset( $_POST ) ) {
$_POST = array();
}
$_POST = array_merge_recursive( $_POST, $input_values );
strive {
GFFormDisplay::process_form( $form_id );
} catch ( Exception $ex ) {
return new WP_Error( ‘error_processing_form’, __( ‘There was an error whereas processing the shape:’, ‘gravityforms’ ) . ‘ ‘ . $ex->getCode() . ‘ ‘ . $ex->getMessage() );
}
if ( empty( GFFormDisplay::$submission ) ) {
return new WP_Error( ‘error_processing_form’, __( ‘There was an error whereas processing the shape:’, ‘gravityforms’ ) );
}
$submissions_array = GFFormDisplay::$submission;
$submission_details = $submissions_array[ $form_id ];
$end result = array();
$end result[‘is_valid’] = $submission_details[‘is_valid’];
if ( $end result[‘is_valid’] == false ) {
$validation_messages = array();
foreach ( $submission_details[‘form’][‘fields’] as $subject ) {
if ( $field->failed_validation ) {
$validation_messages[ $field->id ] = $field->validation_message;
}
}
$end result[‘validation_messages’] = $validation_messages;
}
$end result[‘page_number’] = $submission_details[‘page_number’];
$end result[‘source_page_number’] = $submission_details[‘source_page_number’];
$end result[‘confirmation_message’] = $submission_details[‘confirmation_message’];
if ( isset( $submission_details[‘resume_token’] ) ) {
$end result[‘resume_token’] = $submission_details[‘resume_token’];
$kind = self::get_form( $form_id );
$end result[‘confirmation_message’] = GFFormDisplay::replace_save_variables( $end result[‘confirmation_message’], $kind, $end result[‘resume_token’] );
}
return $end result;
}
// FEEDS ——————————————————
/**
* Returns all of the feeds for the given standards.
*
* @since 1.8
* @entry public
* @static
*
* @param combined $feed_ids The ID of the Feed or an array of Feed IDs
* @param int $form_id The ID of the Kind to which the Feeds belong
* @param string $addon_slug The slug of the add-on to which the Feeds belong
* @param bool $is_active
*
* @return combined Both an array of Feed objects or a WP_Error occasion
*/
public static perform get_feeds( $feed_ids = null, $form_id = null, $addon_slug = null, $is_active = true ) {
world $wpdb;
$desk = $wpdb->prefix . ‘gf_addon_feed’;
$where_arr = array();
$where_arr[] = $wpdb->put together( ‘is_active=%d’, $is_active );
if ( false === empty( $form_id ) ) {
$where_arr[] = $wpdb->put together( ‘form_id=%d’, $form_id );
}
if ( false === empty( $addon_slug ) ) {
$where_arr[] = $wpdb->put together( ‘addon_slug=%s’, $addon_slug );
}
if ( false === empty( $feed_ids ) ) {
if ( ! is_array( $feed_ids ) ) {
$feed_ids = array( $feed_ids );
}
$in_str_arr = array_fill( 0, rely( $feed_ids ), ‘%d’ );
$in_str = be a part of( $in_str_arr, ‘, ‘ );
$where_arr[] = $wpdb->put together( “id IN ($in_str)”, $feed_ids );
}
$the place = be a part of( ‘ AND ‘, $where_arr );
$sql = “SELECT id, form_id, addon_slug, meta FROM {$desk} WHERE $the place”;
$outcomes = $wpdb->get_results( $sql, ARRAY_A );
if ( empty( $outcomes ) ) {
return new WP_Error( ‘not_found’, __( ‘Feed not discovered’, ‘gravityforms’ ) );
}
foreach ( $outcomes as &$end result ) {
$end result[‘meta’] = json_decode( $end result[‘meta’], true );
}
return $outcomes;
}
/**
* Deletes a single Feed
*
* @since 1.8
* @entry public
* @static
*
* @param int $feed_id The ID of the Feed to delete
*
* @return combined Both an array of Feed objects or a WP_Error occasion
*/
public static perform delete_feed( $feed_id ) {
world $wpdb;
$desk = $wpdb->prefix . ‘gf_addon_feed’;
$sql = $wpdb->put together( “DELETE FROM {$desk} WHERE id=%d”, $feed_id );
$outcomes = $wpdb->question( $sql );
if ( false === $outcomes ) {
return new WP_Error( ‘error_deleting’, sprintf( __( ‘There was an an error whereas deleting feed id %s’, ‘gravityforms’ ), $feed_id ), $wpdb->last_error );
}
if ( 0 === $outcomes ) {
return new WP_Error( ‘not_found’, sprintf( __( ‘Feed id %s not discovered’, ‘gravityforms’ ), $feed_id ) );
}
return true;
}
public static perform update_feed( $feed_id, $feed_meta, $form_id = null ) {
world $wpdb;
$feed_meta_json = json_encode( $feed_meta );
$desk = $wpdb->prefix . ‘gf_addon_feed’;
if ( empty( $form_id ) ) {
$sql = $wpdb->put together( “UPDATE {$desk} SET meta= %s WHERE id=%d”, $feed_meta_json, $feed_id );
} else {
$sql = $wpdb->put together( “UPDATE {$desk} SET form_id = %d, meta= %s WHERE id=%d”, $form_id, $feed_meta_json, $feed_id );
}
$outcomes = $wpdb->question( $sql );
if ( false === $outcomes ) {
return new WP_Error( ‘error_updating’, sprintf( __( ‘There was an an error whereas updating feed id %s’, ‘gravityforms’ ), $feed_id ), $wpdb->last_error );
}
if ( 0 === $outcomes ) {
return new WP_Error( ‘not_found’, sprintf( __( ‘Feed id %s not discovered’, ‘gravityforms’ ), $feed_id ) );
}
return $outcomes;
}
/**
* Provides a feed with the given Feed object.
*
* @since 1.8
* @entry public
* @static
*
* @param int $form_id The ID of the Kind to which the Feed belongs
* @param array $feed_meta The Feed object
* @param string $addon_slug The slug of the add-on to which the Feeds belong
*
* @return combined Both the ID of the newly created Feed or a WP_Error occasion
*/
public static perform add_feed( $form_id, $feed_meta, $addon_slug ) {
world $wpdb;
$desk = $wpdb->prefix . ‘gf_addon_feed’;
$feed_meta_json = json_encode( $feed_meta );
$sql = $wpdb->put together( “INSERT INTO {$desk} (form_id, meta, addon_slug) VALUES (%d, %s, %s)”, $form_id, $feed_meta_json, $addon_slug );
$outcomes = $wpdb->question( $sql );
if ( false === $outcomes ) {
return new WP_Error( ‘error_inserting’, __( ‘There was an an error whereas inserting a feed’, ‘gravityforms’ ), $wpdb->last_error );
}
return $wpdb->insert_id;
}
// NOTIFICATIONS ———————————————-
/**
* Sends all lively notifications for a kind given an entry object and an occasion.
*
* @param $kind
* @param $entry
* @param string $occasion Default=”form_submission”
*
* @return array
*/
public static perform send_notifications( $kind, $entry, $occasion=”form_submission” ) {
if ( rgempty( ‘notifications’, $kind ) || ! is_array( $kind[‘notifications’] ) ) {
return array();
}
$entry_id = rgar( $entry, ‘id’ );
GFCommon::log_debug( “GFAPI::send_notifications(): Gathering notifications for {$occasion} occasion for entry #{$entry_id}.” );
$notifications_to_send = array();
//operating by filters that disable kind submission notifications
foreach ( $kind[‘notifications’] as $notification ) {
if ( rgar( $notification, ‘occasion’ ) != $occasion ) {
proceed;
}
if ( $occasion == ‘form_submission’ ) {
if ( rgar( $notification, ‘kind’ ) == ‘consumer’ && gf_apply_filters( array( ‘gform_disable_user_notification’, $kind[‘id’] ), false, $kind, $entry ) ) {
GFCommon::log_debug( “GFAPI::send_notifications(): Notification is disabled by gform_disable_user_notification hook, not together with notification (#{$notification[‘id’]} – {$notification[‘name’]}).” );
//skip consumer notification if it has been disabled by a hook
proceed;
} elseif ( rgar( $notification, ‘kind’ ) == ‘admin’ && gf_apply_filters( array( ‘gform_disable_admin_notification’, $kind[‘id’] ), false, $kind, $entry ) ) {
GFCommon::log_debug( “GFAPI::send_notifications(): Notification is disabled by gform_disable_admin_notification hook, not together with notification (#{$notification[‘id’]} – {$notification[‘name’]}).” );
//skip admin notification if it has been disabled by a hook
proceed;
}
}
if ( gf_apply_filters( array( ‘gform_disable_notification’, $kind[‘id’] ), false, $notification, $kind, $entry ) ) {
GFCommon::log_debug( “GFAPI::send_notifications(): Notification is disabled by gform_disable_notification hook, not together with notification (#{$notification[‘id’]} – {$notification[‘name’]}).” );
//skip notifications if it has been disabled by a hook
proceed;
}
$notifications_to_send[] = $notification[‘id’];
}
GFCommon::send_notifications( $notifications_to_send, $kind, $entry, true, $occasion );
}
// PERMISSIONS ————————————————
/**
* Checks the permissions for the present consumer. Returns true if the present consumer has any of the desired capabilities.
* IMPORTANT: Name this earlier than calling any of the opposite API Capabilities as permission checks are usually not carried out at decrease ranges.
*
* @since 1.8.5.10
* @entry public
* @static
*
* @param array|string $capabilities An array of capabilities, or a single functionality
*
* @return bool Returns true if the present consumer has any of the desired capabilities
*/
public static perform current_user_can_any( $capabilities ) {
return GFCommon::current_user_can_any( $capabilities );
}
// FIELDS —————————————————–
/**
* Returns an array containing the shape fields of the desired kind or sorts.
*
* @since 1.9.9.8
*
* @param array $kind
* @param array|string $sorts
* @param bool $use_input_type
*
* @return GF_Field[]
*/
public static perform get_fields_by_type( $kind, $sorts, $use_input_type = false ) {
return GFFormsModel::get_fields_by_type( $kind, $sorts, $use_input_type );
}
// HELPERS —————————————————-
/**
* Personal.
*
* @since 1.8
* @entry personal
* @static
* @ignore
*/
public static perform form_id_exists( $form_id ) {
world $wpdb;
$form_table_name = GFFormsModel::get_form_table_name();
$form_id = intval( $form_id );
$end result = $wpdb->get_var(
$wpdb->put together(
” SELECT rely(id) FROM {$form_table_name}
WHERE id=%d”, $form_id
)
);
$end result = intval( $end result );
return $end result > 0;
}
}
[ad_2]