' . $page_text . '
';
}
}
return stripslashes( $page_text );
}
//------------------------------------------------------
//-------------- DASHBOARD PAGE -------------------------
/**
* Registers the dashboard widget.
*
* @since Unknown
* @access public
*/
public static function dashboard_setup() {
/**
* Changes the dashboard widget title
*
* @param string $dashboard_title The dashboard widget title.
*/
$dashboard_title = apply_filters( 'gform_dashboard_title', __( 'Forms', 'gravityforms' ) );
wp_add_dashboard_widget( 'rg_forms_dashboard', $dashboard_title, array( 'GFForms', 'dashboard' ) );
}
/**
* Displays the dashboard UI.
*
* @since Unknown
* @access public
*/
public static function dashboard() {
$forms = RGFormsModel::get_form_summary();
if ( sizeof( $forms ) > 0 ) {
?>
', '' ); ?>
", '' );
?>
self::get_shortcodes(),
'previewNonce' => wp_create_nonce( 'gf-shortcode-ui-preview' ),
/**
* Allows the enabling (false) or disabling (true) of a shortcode preview of a form
*
* @param bool $preview_disabled Defaults to true. False to enable.
*/
'previewDisabled' => apply_filters( 'gform_shortcode_preview_disabled', true ),
'strings' => array(
'pleaseSelectAForm' => esc_html__( 'Please select a form.', 'gravityforms' ),
'errorLoadingPreview' => esc_html__( 'Failed to load the preview for this form.', 'gravityforms' ),
)
) );
}
if ( empty( $scripts ) ) {
return;
}
foreach ( $scripts as $script ) {
wp_enqueue_script( $script );
}
GFCommon::localize_gform_gravityforms_multifile();
}
/**
* Gets current page name.
*
* @since Unknown
* @access public
*
* @return bool|string Page name or false.
* Page names:
*
* new_form
* form_list
* form_editor
* form_settings
* confirmation
* notification_list
* notification_new
* notification_edit
* entry_list
* entry_detail
* entry_detail_edit
* settings
* addons
* export_entry
* export_form
* import_form
* updates
*/
public static function get_page() {
if ( rgget( 'page' ) == 'gf_new_form' ) {
return 'new_form';
}
if ( rgget( 'page' ) == 'gf_edit_forms' && ! rgget( 'id' ) ) {
return 'form_list';
}
if ( rgget( 'page' ) == 'gf_edit_forms' && ! rgget( 'view' ) ) {
return 'form_editor';
}
if ( rgget( 'page' ) == 'gf_edit_forms' && rgget( 'view' ) == 'settings' && ( ! rgget( 'subview' ) || rgget( 'subview' ) == 'settings' ) ) {
return 'form_settings';
}
if ( rgget( 'page' ) == 'gf_edit_forms' && rgget( 'view' ) == 'settings' && rgget( 'subview' ) == 'confirmation' ) {
return 'confirmation';
}
if ( rgget( 'page' ) == 'gf_edit_forms' && rgget( 'view' ) == 'settings' && rgget( 'subview' ) == 'notification' && rgget( 'nid' ) ) {
return 'notification_edit';
}
if ( rgget( 'page' ) == 'gf_edit_forms' && rgget( 'view' ) == 'settings' && rgget( 'subview' ) == 'notification' && isset( $_GET['nid'] ) ) {
return 'notification_edit';
}
if ( rgget( 'page' ) == 'gf_edit_forms' && rgget( 'view' ) == 'settings' && rgget( 'subview' ) == 'notification' ) {
return 'notification_list';
}
if ( rgget( 'page' ) == 'gf_edit_forms' && rgget( 'view' ) == 'settings' && rgget( 'subview' ) ) {
return 'form_settings_' . rgget( 'subview' );
}
if ( rgget( 'page' ) == 'gf_entries' && ( ! rgget( 'view' ) || rgget( 'view' ) == 'entries' ) ) {
return 'entry_list';
}
if ( rgget( 'page' ) == 'gf_entries' && rgget( 'view' ) == 'entry' && isset( $_POST['screen_mode'] ) && $_POST['screen_mode'] == 'edit' ) {
return 'entry_detail_edit';
}
if ( rgget( 'page' ) == 'gf_entries' && rgget( 'view' ) == 'entry' ) {
return 'entry_detail';
}
if ( rgget( 'page' ) == 'gf_settings' ) {
return 'settings';
}
if ( rgget( 'page' ) == 'gf_addons' ) {
return 'addons';
}
if ( rgget( 'page' ) == 'gf_export' && ( rgget( 'view' ) == 'export_entry' || ! isset( $_GET['view'] ) ) ) {
return 'export_entry';
}
if ( rgget( 'page' ) == 'gf_export' && rgget( 'view' ) == 'export_form' ) {
return 'export_form';
}
if ( rgget( 'page' ) == 'gf_export' && rgget( 'view' ) == 'import_form' ) {
return 'import_form';
}
if ( rgget( 'page' ) == 'gf_system_status' ) {
return rgget( 'subview' ) === 'updates' ? 'updates' : 'system_status';
}
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && ( ( isset( $_POST['form_id'] ) && rgpost( 'action' ) === 'rg_select_export_form' ) || ( isset( $_POST['export_form'] ) && rgpost( 'action' ) === 'gf_process_export' ) ) ) {
return 'export_entry_ajax';
}
return false;
}
/**
* Gets the form.
*
* @since Unknown
* @access public
*
* @uses GFFormDisplay::get_form()
* @uses GFCommon::get_base_path()
*/
public static function get_form( $form_id, $display_title = true, $display_description = true, $force_display = false, $field_values = null, $ajax = false, $tabindex = 0 ) {
require_once( GFCommon::get_base_path() . '/form_display.php' );
return GFFormDisplay::get_form( $form_id, $display_title, $display_description, $force_display, $field_values, $ajax, $tabindex );
}
/**
* Runs when the Forms menu item is clicked.
*
* Checks to see if the installation wizard should be displayed instead.
*
* @since Unknown
* @access public
*/
public static function new_form() {
if ( self::maybe_display_wizard() ) {
return;
};
self::form_list_page();
}
/**
* Enqueues scripts
*
* @since Unknown
* @access public
*
* @uses GFFormDisplay::enqueue_scripts()
*/
public static function enqueue_scripts() {
require_once( GFCommon::get_base_path() . '/form_display.php' );
GFFormDisplay::enqueue_scripts();
}
/**
* Prints form scripts.
*
* @since Unknown
* @access public
*
* @uses GFFormDisplay::print_form_scripts()
*/
public static function print_form_scripts( $form, $ajax ) {
require_once( GFCommon::get_base_path() . '/form_display.php' );
GFFormDisplay::print_form_scripts( $form, $ajax );
}
/**
* Displays the Forms page
*
* Passes everything off to GFFormDetail::forms_page
*
* @since Unknown
* @access public
*
* @uses GFFormDetail::forms_page()
*/
public static function forms_page( $form_id ) {
require_once( GFCommon::get_base_path() . '/form_detail.php' );
GFFormDetail::forms_page( $form_id );
}
/**
* Runs the Gravity Forms settings page.
*
* Checks to see if the installation wizard should be displayed.
*
* @since Unknown
* @access public
*
* @uses GFSettings::settings_page()
*/
public static function settings_page() {
if ( self::maybe_display_wizard() ) {
return;
};
require_once( GFCommon::get_base_path() . '/settings.php' );
GFSettings::settings_page();
}
/**
* Runs the Gravity Forms system status page.
*
* @since 2.2
* @access public
*
* @uses GFSystemStatus::system_status_page()
*/
public static function system_status() {
require_once( GFCommon::get_base_path() . '/includes/system-status/class-gf-system-status.php' );
require_once( GFCommon::get_base_path() . '/includes/system-status/class-gf-system-report.php' );
require_once( GFCommon::get_base_path() . '/includes/system-status/class-gf-update.php' );
GF_System_Status::system_status_page();
}
/**
* Adds pages to the Gravity Forms Settings page
*
* @since Unknown
* @access public
*
* @used-by GFSettings::add_settings_page()
*/
public static function add_settings_page( $name, $handle = '', $icon_path = '' ) {
require_once( GFCommon::get_base_path() . '/settings.php' );
GFSettings::add_settings_page( $name, $handle, $icon_path );
}
/**
* Displays the help page
*
* @since Unknown
* @access public
*
* @uses GFHelp::help_page()
*/
public static function help_page() {
require_once( GFCommon::get_base_path() . '/help.php' );
GFHelp::help_page();
}
/**
* Displays the Gravity Forms Export page
*
* @since Unknown
* @access public
*
* @uses GFForms::maybe_display_wizard()
* @uses GFExport::export_page()
*/
public static function export_page() {
if ( self::maybe_display_wizard() ) {
return;
};
require_once( GFCommon::get_base_path() . '/export.php' );
GFExport::export_page();
}
/**
* Target for the wp_ajax_gf_process_export ajax action requested from the export entries page.
*
* @since 2.0.0
* @access public
*
* @uses GFCommon::get_base_path()
* @uses GFExport::ajax_process_export()
*/
public static function ajax_process_export() {
require_once( GFCommon::get_base_path() . '/export.php' );
GFExport::ajax_process_export();
}
/**
* Target for the wp_ajax_gf_download_export ajax action requested from the export entries page.
*
* @since 2.0.0
* @access public
*
* @uses GFCommon::get_base_path()
* @uses GFExport::ajax_download_export()
*/
public static function ajax_download_export() {
require_once( GFCommon::get_base_path() . '/export.php' );
GFExport::ajax_download_export();
}
/**
* Target for the wp_ajax_gf_dismiss_message ajax action requested from the Gravity Forms admin pages.
*
* @since 2.0.0
* @access public
*
* @uses GFCommon::dismiss_message()
*/
public static function ajax_dismiss_message() {
check_admin_referer( 'gf_dismissible_nonce', 'nonce' );
$key = rgget( 'message_key' );
$key = sanitize_key( $key );
GFCommon::dismiss_message( $key );
}
/**
* Target for the wp_ajax_gf_force_upgrade ajax action requested from the System Status page.
*
* Outputs a JSON string with the status and then triggers the background upgrader usually handled byt the cron healthcheck.
*
* @since 2.3.0.4
*/
public static function ajax_force_upgrade() {
check_ajax_referer( 'gf_force_upgrade', 'nonce' );
$status_label = get_option( 'gform_upgrade_status' );
if ( empty( $status_label ) ) {
$status = 'complete';
$status_label = __( 'Finished', 'gravityforms' );
$percent_complete = 100;
} else {
$status = 'in_progress';
require_once( GFCommon::get_base_path() . '/includes/system-status/class-gf-system-report.php' );
$percent_complete = GF_System_Report::get_upgrade_percent_complete();
}
$response = json_encode(
array(
'status' => $status,
'status_label' => $status_label,
'percent' => (string) $percent_complete,
)
);
echo $response;
ob_end_flush();
// Simuate the healthcheck cron.
GFForms::$background_upgrader->handle_cron_healthcheck();
// The healthcheck task will terminate anyway but exit just in case.
exit;
}
/**
* Runs the add-ons page
*
* If the display wizard needs to be displayed, do that instead.
*
* @since Unknown
* @access public
*/
public static function addons_page() {
if ( self::maybe_display_wizard() ) {
return;
};
wp_print_styles( array( 'thickbox' ) );
$plugins = get_plugins();
$installed_plugins = array();
foreach ( $plugins as $key => $plugin ) {
$is_active = is_plugin_active( $key );
$installed_plugin = array(
'plugin' => $key,
'name' => $plugin['Name'],
'is_active' => $is_active
);
$installed_plugin['activation_url'] = $is_active ? '' : wp_nonce_url( "plugins.php?action=activate&plugin={$key}", "activate-plugin_{$key}" );
$installed_plugin['deactivation_url'] = ! $is_active ? '' : wp_nonce_url( "plugins.php?action=deactivate&plugin={$key}", "deactivate-plugin_{$key}" );
$installed_plugins[] = $installed_plugin;
}
$nonces = self::get_addon_nonces();
$body = array(
'plugins' => urlencode( serialize( $installed_plugins ) ),
'nonces' => urlencode( serialize( $nonces ) ),
'key' => GFCommon::get_key()
);
$options = array( 'body' => $body, 'headers' => array( 'Referer' => get_bloginfo( 'url' ) ), 'timeout' => 15 );
$raw_response = GFCommon::post_to_manager( 'api.php', "op=plugin_browser&{$_SERVER['QUERY_STRING']}", $options );
if ( is_wp_error( $raw_response ) || $raw_response['response']['code'] != 200 ) {
echo "
" . esc_html__( 'Add-On browser is currently unavailable. Please try again later.', 'gravityforms' ) . '
';
} else {
echo GFCommon::get_remote_message();
echo $raw_response['body'];
}
}
/**
* Gets all add-on information.
*
* @since Unknown
* @access public
*
* @param string $api The API URL.
* @param string $action The action needed. Determines the view.
* @param object $args Additional arguments sent to the API
*
* @return bool|object API object if successful. False if error.
*/
public static function get_addon_info( $api, $action, $args ) {
if ( $action == 'plugin_information' && empty( $api ) && ( ! rgempty( 'rg', $_GET ) || $args->slug == 'gravityforms' ) ) {
$key = GFCommon::get_key();
$raw_response = GFCommon::post_to_manager( 'api.php', "op=get_plugin&slug={$args->slug}&key={$key}", array() );
if ( is_wp_error( $raw_response ) || $raw_response['response']['code'] != 200 ) {
return false;
}
$plugin = unserialize( $raw_response['body'] );
$api = new stdClass();
$api->name = $plugin['title'];
$api->version = $plugin['version'];
$api->download_link = $plugin['download_url'];
$api->tested = '10.0';
}
return $api;
}
/**
* Creates nonces for add-on installation pages.
*
* @since Unknown
* @access public
*
* @return array|bool $nonces The nonces if the API response is fine. Otherwise, false.
*/
public static function get_addon_nonces() {
$raw_response = GFCommon::post_to_manager( 'api.php', 'op=get_plugins', array() );
if ( is_wp_error( $raw_response ) || $raw_response['response']['code'] != 200 ) {
return false;
}
$addons = unserialize( $raw_response['body'] );
$nonces = array();
foreach ( $addons as $addon ) {
$nonces[ $addon['key'] ] = wp_create_nonce( "install-plugin_{$addon['key']}" );
}
return $nonces;
}
/**
* Begins exports.
*
* @since Unknown
* @access public
*
* @uses GFExport::start_export()
*/
public static function start_export() {
require_once( GFCommon::get_base_path() . '/export.php' );
GFExport::start_export();
}
/**
* Gets the post categories.
*
* @since Unknown
* @access public
*
* @uses GFFormDetail::get_post_category_values()
*/
public static function get_post_category_values() {
require_once( GFCommon::get_base_path() . '/form_detail.php' );
GFFormDetail::get_post_category_values();
}
/**
* Gets and displays the rules for an address field, depending on the address type.
*
* @since Unknown
* @access public
*/
public static function get_address_rule_values_select() {
$address_type = rgpost( 'address_type' );
$value = rgpost( 'value' );
$id = sanitize_text_field( rgpost( 'id' ) );
$form_id = absint( rgpost( 'form_id' ) );
$address_field = new GF_Field_Address();
$address_types = $address_field->get_address_types( $form_id );
$markup = '';
$type_obj = $address_type && isset( $address_types[ $address_type ] ) ? $address_types[ $address_type ] : 'international';
switch ( $address_type ) {
case 'international':
$items = $address_field->get_countries();
break;
default:
$items = $type_obj['states'];
}
$markup = sprintf( '
%2$s ', esc_attr( $id ), $address_field->get_state_dropdown( $items, $value ) );
echo $markup;
die();
}
/**
* Gets post categories for display in Notifications.
*
* @since Unknown
* @access public
*
* @uses GFNotification::get_post_category_values()
*/
public static function get_notification_post_category_values() {
require_once( GFCommon::get_base_path() . '/notification.php' );
GFNotification::get_post_category_values();
}
/**
* Fires off the entries page.
*
* Checks if the installation wizard is needed. If so, does that instead.
*
* @since Unknown
* @access public
*
* @uses GFForms::maybe_display_wizard()
* @uses GFEntryDetail::lead_detail_page()
* @uses GFEntryList::all_entries_page()
*/
public static function all_leads_page() {
if ( self::maybe_display_wizard() ) {
return;
};
$view = rgget( 'view' );
$lead_id = rgget( 'lid' );
if ( $view == 'entry' && ( rgget( 'lid' ) || ! rgblank( rgget( 'pos' ) ) ) ) {
require_once( GFCommon::get_base_path() . '/entry_detail.php' );
GFEntryDetail::lead_detail_page();
} else if ( $view == 'entries' || empty( $view ) ) {
require_once( GFCommon::get_base_path() . '/entry_list.php' );
GFEntryList::all_entries_page();
} else {
$form_id = rgget( 'id' );
$form_id = absint( $form_id );
/**
* Fires when viewing entries of a certain form
*
* @since Unknown
*
* @param string $view The current view/entry type
* @param string $form_id The current form ID
* @param string $lead_id The current entry ID
*/
do_action( 'gform_entries_view', $view, $form_id, $lead_id );
}
}
/**
* Gets the Form List page.
*
* @since Unknown
* @access public
*
* @uses GFFormList::form_list_page()
*/
public static function form_list_page() {
require_once( GFCommon::get_base_path() . '/form_list.php' );
GFFormList::form_list_page();
}
/**
* Handles the view when accessing specific forms
*
* If needed, displays the installation wizard instead.
*
* @since Unknown
* @access public
*
* @uses GFForms::maybe_display_wizard()
* @uses GFCommon::ensure_wp_version()
* @uses GFForms::get()
* @uses GFEntryList::leads_page()
* @uses GFEntryDetail::lead_detail_page()
* @uses GFFormSettings::form_settings_page()
* @uses GFForms::forms_page()
* @uses GFForms::form_list_page()
*/
public static function forms() {
if ( ! GFCommon::ensure_wp_version() ) {
return;
}
if ( self::maybe_display_wizard() ) {
return;
};
$id = RGForms::get( 'id' );
$view = RGForms::get( 'view' );
if ( $view == 'entries' ) {
require_once( GFCommon::get_base_path() . '/entry_list.php' );
GFEntryList::leads_page( $id );
} else if ( $view == 'entry' ) {
require_once( GFCommon::get_base_path() . '/entry_detail.php' );
GFEntryDetail::lead_detail_page();
} else if ( $view == 'notification' ) {
require_once( GFCommon::get_base_path() . '/notification.php' );
//GFNotification::notification_page($id);
} else if ( $view == 'settings' ) {
require_once( GFCommon::get_base_path() . '/form_settings.php' );
GFFormSettings::form_settings_page( $id );
} else if ( empty( $view ) ) {
if ( is_numeric( $id ) ) {
self::forms_page( $id );
} else {
self::form_list_page();
}
}
/**
* Fires an action based on the form view
*
* @since Unknown
*
* @param string $view The current view
* @param string $id The form ID
*/
do_action( 'gform_view', $view, $id );
}
/**
* Obtains $_GET values or values from an array.
*
* @since Unknown
* @access public
*
* @param string $name The ID of a specific value.
* @param array $array An optional array to search through. Defaults to null.
*
* @return string The value. Empty if not found.
*/
public static function get( $name, $array = null ) {
if ( ! isset( $array ) ) {
$array = $_GET;
}
if ( isset( $array[ $name ] ) ) {
return $array[ $name ];
}
return '';
}
/**
* Obtains $_POST values.
*
* @since Unknown
* @access public
*
* @param string $name The ID of the value to obtain
* @param bool $do_stripslashes If stripslashes_deep should be run on the result. Defaults to true.
*
* @return string The value. Empty if not found.
*/
public static function post( $name, $do_stripslashes = true ) {
if ( isset( $_POST[ $name ] ) ) {
return $do_stripslashes ? stripslashes_deep( $_POST[ $name ] ) : $_POST[ $name ];
}
return '';
}
/**
* Resends failed notifications
*
* @since Unknown
* @access public
*
* @uses GFCommon::send_notification()
*/
public static function resend_notifications() {
check_admin_referer( 'gf_resend_notifications', 'gf_resend_notifications' );
$form_id = absint( rgpost( 'formId' ) );
$leads = rgpost( 'leadIds' ); // may be a single ID or an array of IDs
if ( 0 == $leads ) {
// get all the lead ids for the current filter / search
$filter = rgpost( 'filter' );
$search = rgpost( 'search' );
$star = $filter == 'star' ? 1 : null;
$read = $filter == 'unread' ? 0 : null;
$status = in_array( $filter, array( 'trash', 'spam' ) ) ? $filter : 'active';
$search_criteria['status'] = $status;
if ( $star ) {
$search_criteria['field_filters'][] = array( 'key' => 'is_starred', 'value' => (bool) $star );
}
if ( ! is_null( $read ) ) {
$search_criteria['field_filters'][] = array( 'key' => 'is_read', 'value' => (bool) $read );
}
$search_field_id = rgpost( 'fieldId' );
if ( isset( $_POST['fieldId'] ) && $_POST['fieldId'] !== '' ) {
$key = $search_field_id;
$val = $search;
$strpos_row_key = strpos( $search_field_id, '|' );
if ( $strpos_row_key !== false ) { //multi-row
$key_array = explode( '|', $search_field_id );
$key = $key_array[0];
$val = $key_array[1] . ':' . $val;
}
$search_criteria['field_filters'][] = array(
'key' => $key,
'operator' => rgempty( 'operator', $_POST ) ? 'is' : rgpost( 'operator' ),
'value' => $val,
);
}
$leads = GFFormsModel::search_lead_ids( $form_id, $search_criteria );
} else {
$leads = ! is_array( $leads ) ? array( $leads ) : $leads;
}
/**
* Filters the notifications to be re-sent
*
* @since Unknown
*
* @param array $form_meta The Form Object
* @param array $leads The entry IDs
*/
$form = gf_apply_filters( array(
'gform_before_resend_notifications',
$form_id
), RGFormsModel::get_form_meta( $form_id ), $leads );
if ( empty( $leads ) || empty( $form ) ) {
esc_html_e( 'There was an error while resending the notifications.', 'gravityforms' );
die();
};
$notifications = json_decode( rgpost( 'notifications' ) );
if ( ! is_array( $notifications ) ) {
die( esc_html__( 'No notifications have been selected. Please select a notification to be sent.', 'gravityforms' ) );
}
if ( ! rgempty( 'sendTo', $_POST ) && ! GFCommon::is_valid_email_list( rgpost( 'sendTo' ) ) ) {
die( sprintf( esc_html__( 'The %sSend To%s email address provided is not valid.', 'gravityforms' ), '
', ' ' ) );
}
foreach ( $leads as $lead_id ) {
$lead = RGFormsModel::get_lead( $lead_id );
foreach ( $notifications as $notification_id ) {
$notification = $form['notifications'][ $notification_id ];
if ( ! $notification ) {
continue;
}
//overriding To email if one was specified
if ( rgpost( 'sendTo' ) ) {
$notification['to'] = rgpost( 'sendTo' );
$notification['toType'] = 'email';
}
/**
* Allow the resend notification email to be skipped
*
* @since 2.3
*
* @param bool $abort_email Should we prevent this email being sent?
* @param array $notification The current notification object.
* @param array $form The current form object.
* @param array $lead The current entry object.
*/
$abort_email = apply_filters( 'gform_disable_resend_notification', false, $notification, $form, $lead );
if ( ! $abort_email ) {
GFCommon::send_notification( $notification, $form, $lead );
}
/**
* Fires after the current notification processing is finished
*
* @since 2.3
*
* @param array $notification The current notification object.
* @param array $form The current form object.
* @param array $lead The current entry object.
*/
do_action( 'gform_post_resend_notification', $notification, $form, $lead );
}
}
/**
* Fires after the resend notifications processing is finished
*
* @since 2.3
*
* @param array $form The current form object.
* @param array $lead The current entry object.
*/
do_action( 'gform_post_resend_all_notifications', $form, $lead );
die();
}
//-------------------------------------------------
//----------- AJAX CALLS --------------------------
/**
* Gets the CAPTCHA image for the form editor and displays it.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*/
public static function captcha_image() {
$field_properties = array(
'type' => 'captcha',
'simpleCaptchaSize' => $_GET['size'],
'simpleCaptchaFontColor' => $_GET['fg'],
'simpleCaptchaBackgroundColor' => $_GET['bg']
);
/* @var GF_Field_CAPTCHA $field */
$field = GF_Fields::create( $field_properties );
if ( $_GET['type'] == 'math' ) {
$captcha = $field->get_math_captcha( $_GET['pos'] );
} else {
$captcha = $field->get_captcha();
}
@ini_set( 'memory_limit', '256M' );
$image = imagecreatefrompng( $captcha['path'] );
include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
wp_stream_image( $image, 'image/png', 0 );
imagedestroy( $image );
die();
}
/**
* Updates the form status (active/inactive).
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormsModel::update_form_active()
*/
public static function update_form_active() {
check_ajax_referer( 'rg_update_form_active', 'rg_update_form_active' );
RGFormsModel::update_form_active( $_POST['form_id'], $_POST['is_active'] );
}
/**
* Updates the notification status (active/inactive).
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormsModel::update_notification_active()
*/
public static function update_notification_active() {
check_ajax_referer( 'rg_update_notification_active', 'rg_update_notification_active' );
RGFormsModel::update_notification_active( $_POST['form_id'], $_POST['notification_id'], $_POST['is_active'] );
}
/**
* Updates the confirmation status (active/inactive).
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @since GFFormsModel::update_confirmation_active()
*/
public static function update_confirmation_active() {
check_ajax_referer( 'rg_update_confirmation_active', 'rg_update_confirmation_active' );
RGFormsModel::update_confirmation_active( $_POST['form_id'], $_POST['confirmation_id'], $_POST['is_active'] );
}
/**
* Updates the entry properties.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormsModel::update_entry_property()
*/
public static function update_lead_property() {
check_ajax_referer( 'rg_update_lead_property', 'rg_update_lead_property' );
GFFormsModel::update_entry_property( $_POST['lead_id'], $_POST['name'], $_POST['value'] );
}
/**
* Updates the entry status.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormsModel::update_lead_property()
* @uses GFFormsModel::delete_lead()
*/
public static function update_lead_status() {
check_ajax_referer( 'gf_delete_entry' );
$status = rgpost( 'status' );
$lead_id = rgpost( 'entry' );
$entry = GFAPI::get_entry( $lead_id );
$form = GFAPI::get_form( $entry['form_id'] );
switch ( $status ) {
case 'unspam' :
GFFormsModel::update_entry_property( $lead_id, 'status', 'active' );
break;
case 'delete' :
if ( GFCommon::current_user_can_any( 'gravityforms_delete_entries' ) ) {
RGFormsModel::delete_entry( $lead_id );
}
break;
default :
RGFormsModel::update_entry_property( $lead_id, 'status', $status );
break;
}
require_once( 'entry_list.php' );
$filter_links = GFEntryList::get_filter_links( $form );
$counts = array();
foreach ( $filter_links as $filter_link ) {
$id = $filter_link['id'] == '' ? 'all' : $filter_link['id'];
$counts[ $id . '_count' ] = $filter_link['count'];
}
$x = new WP_Ajax_Response();
$x->add( array(
'what' => 'gf_entry',
'id' => $lead_id,
'supplemental' => $counts,
) );
$x->send();
}
// Settings
/**
* Runs the license upgrade.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFSettings::upgrade_license()
*/
public static function upgrade_license() {
require_once( GFCommon::get_base_path() . '/settings.php' );
GFSettings::upgrade_license();
}
// Form detail
/**
* Saves the form in the form editor.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormDetail::save_form()
*/
public static function save_form() {
require_once( GFCommon::get_base_path() . '/form_detail.php' );
GFFormDetail::save_form();
}
/**
* Adds fields in the form editor.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormDetail::add_field()
*/
public static function add_field() {
require_once( GFCommon::get_base_path() . '/form_detail.php' );
GFFormDetail::add_field();
}
/**
* Duplicates fields in the form editor.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormDetail::duplicate_field()
*/
public static function duplicate_field() {
require_once( GFCommon::get_base_path() . '/form_detail.php' );
GFFormDetail::duplicate_field();
}
/**
* Deletes fields in the form editor.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses \GFFormDetail::delete_field()
*/
public static function delete_field() {
require_once( GFCommon::get_base_path() . '/form_detail.php' );
GFFormDetail::delete_field();
}
/**
* Changes the input type in the form editor.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormDetail::change_input_type()
*/
public static function change_input_type() {
require_once( GFCommon::get_base_path() . '/form_detail.php' );
GFFormDetail::change_input_type();
}
/**
* Refreshes the field preview.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses \GFFormDetail::refresh_field_preview
*/
public static function refresh_field_preview() {
require_once( GFCommon::get_base_path() . '/form_detail.php' );
GFFormDetail::refresh_field_preview();
}
/**
* Deletes custom choices from radio/checkbox/select/etc fields.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormDetail::delete_custom_choice()
*/
public static function delete_custom_choice() {
require_once( GFCommon::get_base_path() . '/form_detail.php' );
GFFormDetail::delete_custom_choice();
}
/**
* Saves custom choices from radio/checkbox/select/etc fields.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormDetail::save_custom_choice()
*/
public static function save_custom_choice() {
require_once( GFCommon::get_base_path() . '/form_detail.php' );
GFFormDetail::save_custom_choice();
}
/**
* Deletes a file from the entry detail view.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormsModel::delete_file()
*/
public static function delete_file() {
check_ajax_referer( 'rg_delete_file', 'rg_delete_file' );
$lead_id = intval( $_POST['lead_id'] );
$field_id = intval( $_POST['field_id'] );
$file_index = intval( $_POST['file_index'] );
RGFormsModel::delete_file( $lead_id, $field_id, $file_index );
die( "EndDeleteFile($field_id, $file_index);" );
}
/**
* Gets the form export data.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormsModel::get_form_meta()
*/
public static function select_export_form() {
check_ajax_referer( 'rg_select_export_form', 'rg_select_export_form' );
$form_id = intval( $_POST['form_id'] );
$form = RGFormsModel::get_form_meta( $form_id );
/**
* Filters through the Form Export Page
*
* @since Unknown
*
* @param int $form The Form Object of the form to export
*/
$form = gf_apply_filters( array( 'gform_form_export_page', $form_id ), $form );
$filter_settings = GFCommon::get_field_filter_settings( $form );
$filter_settings_json = json_encode( $filter_settings );
$fields = array();
$form = GFExport::add_default_export_fields( $form );
if ( is_array( $form['fields'] ) ) {
/* @var GF_Field $field */
foreach ( $form['fields'] as $field ) {
$inputs = $field->get_entry_inputs();
if ( is_array( $inputs ) ) {
foreach ( $inputs as $input ) {
$fields[] = array( $input['id'], GFCommon::get_label( $field, $input['id'] ) );
}
} else if ( ! $field->displayOnly ) {
$fields[] = array( $field->id, GFCommon::get_label( $field ) );
}
}
}
$field_json = GFCommon::json_encode( $fields );
die( "EndSelectExportForm($field_json, $filter_settings_json);" );
}
/**
* Saves a form confirmation.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormSettings::save_confirmation()
*/
// public static function save_confirmation() {
// require_once( GFCommon::get_base_path() . '/form_settings.php' );
// GFFormSettings::save_confirmation();
// }
/**
* Saves the form title.
*
* Called via AJAX.
*
* @since 2.0.2.5
* @access public
*
* @uses GFFormSettings::save_form_title()
*/
public static function save_form_title() {
require_once( GFCommon::get_base_path() . '/form_settings.php' );
GFFormSettings::save_form_title();
}
/**
* Deletes a form confirmation.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormSettings::delete_confirmation()
*/
public static function delete_confirmation() {
require_once( GFCommon::get_base_path() . '/form_settings.php' );
GFFormSettings::delete_confirmation();
}
// Form list
/**
* Saves a new form.
*
* Called via AJAX.
*
* @since Unknown
* @access public
*
* @uses GFFormList::save_new_form()
*/
public static function save_new_form() {
require_once( GFCommon::get_base_path() . '/form_list.php' );
GFFormList::save_new_form();
}
/**
* Used to check that background tasks are working.
*
* @since 2.3
*/
public static function check_background_tasks() {
check_ajax_referer( 'gf_check_background_tasks', 'nonce' );
echo 'ok';
die();
}
/**
* Displays the edit title popup.
*
* @since Unknown
* @access public
*
* @param array $form The Form Object.
*/
public static function edit_form_title( $form ) {
//Only allow users with form edit permissions to edit forms
if ( ! GFCommon::current_user_can_any( 'gravityforms_edit_forms' ) ) {
return;
}
?>
array(), 'inactive' => array(), );
foreach ( $all_forms as $form ) {
if ( '1' === $form->is_active ) {
$forms['active'][] = $form;
} else if ( '0' === $form->is_active ) {
$forms['inactive'][] = $form;
}
}
// Enqueuing Chosen script and styling.
wp_enqueue_script( 'gform_chosen', false, array( 'jquery' ), GFCommon::$version, true );
wp_enqueue_style( 'gform_chosen' );
?>
title;
?>
0 ? $forms[0]->id : '0' : rgget( 'id' );
?>
$menu_item ) {
$priorities[ $k ] = rgar( $menu_item, 'priority' );
}
array_multisort( $priorities, SORT_DESC, $menu_items );
$keys = array_keys( $menu_items );
$last_key = array_pop( $keys ); // array_pop(array_keys($menu_items)) causes a Strict Standards warning in WP 3.6 on PHP 5.4
foreach ( $menu_items as $key => $menu_item ) {
if ( is_array( $menu_item ) ) {
if ( GFCommon::current_user_can_any( rgar( $menu_item, 'capabilities' ) ) ) {
$sub_menu_str = '';
$count_sub_menu_items = 0;
$sub_menu_items = rgar( $menu_item, 'sub_menu_items' );
if ( is_array( $sub_menu_items ) ) {
foreach ( $sub_menu_items as $k => $val ) {
if ( false === GFCommon::current_user_can_any( rgar( $sub_menu_items[ $k ], 'capabilities' ) ) ) {
unset( $sub_menu_items[ $k ] );
}
}
$sub_menu_items = array_values( $sub_menu_items ); //reset numeric keys
$count_sub_menu_items = count( $sub_menu_items );
}
$menu_class = rgar( $menu_item, 'menu_class' );
if ( $count_sub_menu_items == 1 ) {
$label = $compact ? rgar( $menu_item, 'label' ) : rgar( $sub_menu_items[0], 'label' );
$menu_item = $sub_menu_items[0];
} else {
$label = rgar( $menu_item, 'label' );
$sub_menu_str = self::toolbar_sub_menu_items( $sub_menu_items, $compact );
}
$link_class = esc_attr( rgar( $menu_item, 'link_class' ) );
$icon = rgar( $menu_item, 'icon' );
$url = esc_url( rgar( $menu_item, 'url' ) );
$title = esc_attr( rgar( $menu_item, 'title' ) );
$onclick = esc_attr( rgar( $menu_item, 'onclick' ) );
$label = esc_html( $label );
$target = rgar( $menu_item, 'target' );
$link = "
{$icon} {$label} " . $sub_menu_str;
if ( $compact ) {
if ( $key == 'delete' ) {
/**
* A filter to allow the modification of the HTML link to delete a form
*
* @since Unknown
*
* @param string $link The HTML "Delete Form" Link
*/
$link = apply_filters( 'gform_form_delete_link', $link );
}
$divider = $key == $last_key ? '' : ' | ';
if ( $count_sub_menu_items > 0 ) {
$menu_class .= ' gf_form_action_has_submenu';
}
$output .= '';
} else {
$output .= "";
}
}
} elseif ( $compact ) {
//for backwards compatibility <1.7: form actions only
$divider = $key == $last_key ? '' : ' | ';
$output .= '
' . $menu_item . $divider . ' ';
}
}
return $output;
}
/**
* Gets the menu items to be displayed within the toolbar.
*
* @since Unknown
* @access public
*
* @used-by GFForms::top_toolbar()
* @uses GFForms::toolbar_class()
*
* @param string $form_id The form ID.
* @param bool $compact True if the compact label should be used. Defaults to false.
*
* @return array $menu_items The menu items to be displayed.
*/
public static function get_toolbar_menu_items( $form_id, $compact = false ) {
$menu_items = array();
$is_mobile = wp_is_mobile();
$form_id = absint( $form_id );
// ---- Form Editor ----
$edit_capabilities = array( 'gravityforms_edit_forms' );
$menu_items['edit'] = array(
'label' => __( 'Edit', 'gravityforms' ),
'short_label' => esc_html__( 'Editor', 'gravityforms' ),
'icon' => '
',
'title' => __( 'Edit this form', 'gravityforms' ),
'url' => '?page=gf_edit_forms&id=' . $form_id,
'menu_class' => 'gf_form_toolbar_editor',
'link_class' => self::toolbar_class( 'editor' ),
'capabilities' => $edit_capabilities,
'priority' => 1000,
);
// ---- Form Settings ----
$sub_menu_items = self::get_form_settings_sub_menu_items( $form_id );
$menu_items['settings'] = array(
'label' => __( 'Settings', 'gravityforms' ),
'icon' => '
',
'title' => __( 'Edit settings for this form', 'gravityforms' ),
'url' => $is_mobile ? '#' : '?page=gf_edit_forms&view=settings&id=' . $form_id,
'menu_class' => 'gf_form_toolbar_settings',
'link_class' => self::toolbar_class( 'settings' ),
'sub_menu_items' => $sub_menu_items,
'capabilities' => $edit_capabilities,
'priority' => 900,
);
// ---- Entries ----
$entries_capabilities = array(
'gravityforms_view_entries',
'gravityforms_edit_entries',
'gravityforms_delete_entries'
);
$menu_items['entries'] = array(
'label' => __( 'Entries', 'gravityforms' ),
'icon' => '',
'title' => __( 'View entries generated by this form', 'gravityforms' ),
'url' => '?page=gf_entries&id=' . $form_id,
'menu_class' => 'gf_form_toolbar_entries',
'link_class' => self::toolbar_class( 'entries' ),
'capabilities' => $entries_capabilities,
'priority' => 800,
);
// ---- Preview ----
$preview_capabilities = array(
'gravityforms_edit_forms',
'gravityforms_create_form',
'gravityforms_preview_forms'
);
$menu_items['preview'] = array(
'label' => __( 'Preview', 'gravityforms' ),
'icon' => '
',
'title' => __( 'Preview this form', 'gravityforms' ),
'url' => trailingslashit( site_url() ) . '?gf_page=preview&id=' . $form_id,
'menu_class' => 'gf_form_toolbar_preview',
'link_class' => self::toolbar_class( 'preview' ),
'target' => '_blank',
'capabilities' => $preview_capabilities,
'priority' => 700,
);
/*
// ---- Duplicate ----
$duplicate_capabilities = array( 'gravityforms_edit_forms', 'gravityforms_create_form' );
$menu_items['duplicate'] = array(
'label' => __( 'Duplicate', 'gravityforms' ),
'icon' => '
',
'title' => __( 'Duplicate this form', 'gravityforms' ),
'url' => wp_nonce_url( "?page=gf_edit_forms&action=duplicate&arg={$form_id}", "gf_duplicate_form_{$form_id}" ),
'menu_class' => 'gf_form_toolbar_duplicate',
'link_class' => self::toolbar_class( 'duplicate' ),
'capabilities' => $duplicate_capabilities,
'priority' => 600,
);
//---- Trash ----
$trash_capabilities = array( 'gravityforms_delete_forms' );
$menu_items['trash'] = array(
'label' => __( 'Trash', 'gravityforms' ),
'icon' => '
',
'title' => __( 'Trash this form', 'gravityforms' ),
'url' => wp_nonce_url( "?page=gf_edit_forms&action=trash&arg={$form_id}", "gf_delete_form_{$form_id}" ),
'menu_class' => 'gf_form_toolbar_trash',
'link_class' => self::toolbar_class( 'trash' ),
'capabilities' => $trash_capabilities,
'priority' => 500,
);
*/
return $menu_items;
}
/**
* Builds the sub-menu items within the Gravity Forms toolbar.
*
* @since Unknown
* @access public
*
* @used-by GFForms::format_toolbar_menu_items()
*
* @param array $menu_items The menu items to be built
* @param bool $compact True if the compact label should be used. False otherwise.
*
* @return string $sub_menu_items_string The menu item HTML
*/
public static function toolbar_sub_menu_items( $menu_items, $compact = false ) {
if ( empty( $menu_items ) ) {
return '';
}
$sub_menu_items_string = '';
foreach ( $menu_items as $menu_item ) {
if ( GFCommon::current_user_can_any( rgar( $menu_item, 'capabilities' ) ) ) {
$menu_class = esc_attr( rgar( $menu_item, 'menu_class' ) );
$link_class = esc_attr( rgar( $menu_item, 'link_class' ) );
$url = esc_url( rgar( $menu_item, 'url' ) );
$label = esc_html( rgar( $menu_item, 'label' ) );
$target = esc_attr( rgar( $menu_item, 'target' ) );
$sub_menu_items_string .= "";
}
}
if ( $compact ) {
$sub_menu_items_string = '';
} else {
$sub_menu_items_string = '';
}
return $sub_menu_items_string;
}
/**
* Gets the form settings sub-menu items.
*
* @since Unknown
* @access public
*
* @used-by GFForms::get_toolbar_menu_items()
* @uses GFFormSettings::get_tabs()
*
* @param string $form_id The form ID.
*
* @return array $sub_menu_items The sub-menu items.
*/
public static function get_form_settings_sub_menu_items( $form_id ) {
require_once( GFCommon::get_base_path() . '/form_settings.php' );
$sub_menu_items = array();
$tabs = GFFormSettings::get_tabs( $form_id );
foreach ( $tabs as $tab ) {
if ( $tab['name'] == 'settings' ) {
$form_setting_menu_item['label'] = 'Settings';
}
$sub_menu_items[] = array(
'url' => admin_url( "admin.php?page=gf_edit_forms&view=settings&subview={$tab['name']}&id={$form_id}" ),
'label' => $tab['label'],
'capabilities' => array( 'gravityforms_edit_forms' )
);
}
return $sub_menu_items;
}
/**
* Gets the CSS class to be used for the toolbar.
*
* @since Unknown
* @access private
*
* @used-by GFForms::get_toolbar_menu_items()
*
* @param string $item The Gravity Forms view (current page).
*
* @return string The class name. Empty string if the view isn't found.
*/
private static function toolbar_class( $item ) {
switch ( $item ) {
case 'editor':
if ( in_array( rgget( 'page' ), array(
'gf_edit_forms',
'gf_new_form'
) ) && rgempty( 'view', $_GET )
) {
return 'gf_toolbar_active';
}
break;
case 'settings':
if ( rgget( 'view' ) == 'settings' ) {
return 'gf_toolbar_active';
}
break;
case 'notifications' :
if ( rgget( 'page' ) == 'gf_new_form' ) {
return 'gf_toolbar_disabled';
} else if ( rgget( 'page' ) == 'gf_edit_forms' && rgget( 'view' ) == 'notification' ) {
return 'gf_toolbar_active';
}
break;
case 'entries' :
if ( rgget( 'page' ) == 'gf_new_form' ) {
return 'gf_toolbar_disabled';
} else if ( rgget( 'page' ) == 'gf_entries' && rgempty( 'view', $_GET ) ) {
return 'gf_toolbar_active';
}
break;
case 'preview' :
if ( rgget( 'page' ) == 'gf_new_form' ) {
return 'gf_toolbar_disabled';
}
break;
}
return '';
}
/**
* Modifies the top WordPress toolbar to add Gravity Forms menu items.
*
* @since Unknown
* @access public
* @global $wp_admin_bar
*
* @used-by GFForms::init()
*/
public static function admin_bar() {
/**
* @var WP_Admin_Bar $wp_admin_bar
*/
global $wp_admin_bar;
if ( GFCommon::current_user_can_any( 'gravityforms_create_form' ) ) {
$wp_admin_bar->add_node(
array(
'id' => 'gravityforms-new-form',
'parent' => 'new-content',
'title' => esc_attr__( 'Form', 'gravityforms' ),
'href' => admin_url( 'admin.php?page="gf_new_form' ),
)
);
}
if ( ! get_option( 'gform_enable_toolbar_menu' ) ) {
return;
}
if ( ! GFCommon::current_user_can_any( array(
'gravityforms_edit_forms',
'gravityforms_create_form',
'gravityforms_preview_forms',
'gravityforms_view_entries'
) )
) {
// The current user can't use anything on the menu so bail.
return;
}
$args = array(
'id' => 'gform-forms',
'title' => '
' . esc_html__( 'Forms', 'gravityforms' ) . ' ',
'href' => admin_url( 'admin.php?page=gf_edit_forms' ),
);
$wp_admin_bar->add_node( $args );
$recent_form_ids = GFFormsModel::get_recent_forms();
if ( $recent_form_ids ) {
$forms = GFFormsModel::get_form_meta_by_id( $recent_form_ids );
$wp_admin_bar->add_node(
array(
'id' => 'gform-form-recent-forms',
'parent' => 'gform-forms',
'title' => esc_html__( 'Recent', 'gravityforms' ),
'group' => true,
)
);
foreach ( $recent_form_ids as $recent_form_id ) {
foreach ( $forms as $form ) {
if ( $form['id'] == $recent_form_id ) {
$wp_admin_bar->add_node(
array(
'id' => 'gform-form-' . $recent_form_id,
'parent' => 'gform-form-recent-forms',
'title' => $form['title'],
'href' => GFCommon::current_user_can_any( 'gravityforms_edit_forms' ) ? admin_url( 'admin.php?page=gf_edit_forms&id=' . $recent_form_id ) : '',
)
);
if ( GFCommon::current_user_can_any( 'gravityforms_edit_forms' ) ) {
$wp_admin_bar->add_node(
array(
'id' => 'gform-form-' . $recent_form_id . '-edit',
'parent' => 'gform-form-' . $recent_form_id,
'title' => esc_html__( 'Edit', 'gravityforms' ),
'href' => admin_url( 'admin.php?page=gf_edit_forms&id=' . $recent_form_id ),
)
);
}
if ( GFCommon::current_user_can_any( 'gravityforms_view_entries' ) ) {
$wp_admin_bar->add_node(
array(
'id' => 'gform-form-' . $recent_form_id . '-entries',
'parent' => 'gform-form-' . $recent_form_id,
'title' => esc_html__( 'Entries', 'gravityforms' ),
'href' => admin_url( 'admin.php?page=gf_entries&id=' . $recent_form_id ),
)
);
}
if ( GFCommon::current_user_can_any( 'gravityforms_edit_forms' ) ) {
$wp_admin_bar->add_node(
array(
'id' => 'gform-form-' . $recent_form_id . '-settings',
'parent' => 'gform-form-' . $recent_form_id,
'title' => esc_html__( 'Settings', 'gravityforms' ),
'href' => admin_url( 'admin.php?page=gf_edit_forms&view=settings&subview=settings&id=' . $recent_form_id ),
)
);
}
if ( GFCommon::current_user_can_any( array(
'gravityforms_edit_forms',
'gravityforms_create_form',
'gravityforms_preview_forms'
) )
) {
$wp_admin_bar->add_node(
array(
'id' => 'gform-form-' . $recent_form_id . '-preview',
'parent' => 'gform-form-' . $recent_form_id,
'title' => esc_html__( 'Preview', 'gravityforms' ),
'href' => trailingslashit( site_url() ) . '?gf_page=preview&id=' . $recent_form_id,
)
);
}
}
}
}
}
if ( GFCommon::current_user_can_any( 'gravityforms_edit_forms' ) ) {
$wp_admin_bar->add_node(
array(
'id' => 'gform-forms-view-all',
'parent' => 'gform-forms',
'title' => esc_attr__( 'All Forms', 'gravityforms' ),
'href' => admin_url( 'admin.php?page=gf_edit_forms' ),
)
);
}
if ( GFCommon::current_user_can_any( 'gravityforms_create_form' ) ) {
$wp_admin_bar->add_node(
array(
'id' => 'gform-forms-new-form',
'parent' => 'gform-forms',
'title' => esc_attr__( 'New Form', 'gravityforms' ),
'href' => admin_url( 'admin.php?page=gf_new_form' ),
)
);
}
}
/**
* Determines if automatic updating should be processed.
*
* @since Unknown
* @access public
*
* @used-by WP_Automatic_Updater::should_update()
* @uses GFForms::is_auto_update_disabled()
*
* @param bool $update Whether or not to update.
* @param object $item The update offer object.
*
* @return bool True if update should be processed. False otherwise.
*/
public static function maybe_auto_update( $update, $item ) {
if ( isset( $item->slug ) && $item->slug == 'gravityforms' ) {
GFCommon::log_debug( 'GFForms::maybe_auto_update() - Starting auto-update for gravityforms.' );
$auto_update_disabled = self::is_auto_update_disabled();
GFCommon::log_debug( 'GFForms::maybe_auto_update() - $auto_update_disabled: ' . var_export( $auto_update_disabled, true ) );
if ( $auto_update_disabled || version_compare( GFForms::$version, $item->new_version, '=>' ) ) {
GFCommon::log_debug( 'GFForms::maybe_auto_update() - Aborting update.' );
return false;
}
$current_major = implode( '.', array_slice( preg_split( '/[.-]/', GFForms::$version ), 0, 1 ) );
$new_major = implode( '.', array_slice( preg_split( '/[.-]/', $item->new_version ), 0, 1 ) );
$current_branch = implode( '.', array_slice( preg_split( '/[.-]/', GFForms::$version ), 0, 2 ) );
$new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $item->new_version ), 0, 2 ) );
if ( $current_major == $new_major && $current_branch == $new_branch ) {
GFCommon::log_debug( __METHOD__ . '() - OK to update.' );
return true;
} else {
GFCommon::log_debug( __METHOD__ . '() - Aborting update. Not on the same major version.' );
return false;
}
}
return $update;
}
/**
* Checks if automatic updates are disabled.
*
* @since Unknown
* @access public
*
* @used-by GFForms::maybe_auto_update()
* @used DISALLOW_FILE_MODS
* @used WP_INSTALLING
* @used AUTOMATIC_UPDATER_DISABLED
* @used GFORM_DISABLE_AUTO_UPDATE
*
* @return bool True if auto update is disabled. False otherwise.
*/
public static function is_auto_update_disabled() {
// Currently WordPress won't ask Gravity Forms to update if background updates are disabled.
// Let's double check anyway.
// WordPress background updates are disabled if you don't want file changes.
if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) {
return true;
}
if ( defined( 'WP_INSTALLING' ) ) {
return true;
}
$wp_updates_disabled = defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED;
/**
* Overrides the WordPress AUTOMATIC_UPDATER_DISABLED constant.
*
* @since Unknown
*
* @param bool $wp_updates_disabled True if disables. False otherwise.
*/
$wp_updates_disabled = apply_filters( 'automatic_updater_disabled', $wp_updates_disabled );
if ( $wp_updates_disabled ) {
GFCommon::log_debug( __METHOD__ . '() - Background updates are disabled in WordPress.' );
return true;
}
// Now check Gravity Forms Background Update Settings
$enabled = get_option( 'gform_enable_background_updates' );
GFCommon::log_debug( 'GFForms::is_auto_update_disabled() - $enabled: ' . var_export( $enabled, true ) );
/**
* Filter to disable Gravity Forms Automatic updates
*
* @param bool $enabled Check if automatic updates are enabled, and then disable it
*/
$disabled = apply_filters( 'gform_disable_auto_update', ! $enabled );
GFCommon::log_debug( 'GFForms::is_auto_update_disabled() - $disabled: ' . var_export( $disabled, true ) );
if ( ! $disabled ) {
$disabled = defined( 'GFORM_DISABLE_AUTO_UPDATE' ) && GFORM_DISABLE_AUTO_UPDATE;
GFCommon::log_debug( 'GFForms::is_auto_update_disabled() - GFORM_DISABLE_AUTO_UPDATE: ' . var_export( $disabled, true ) );
}
return $disabled;
}
public static function deprecate_add_on_methods() {
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ( defined( 'DOING_CRON' ) && DOING_CRON ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) ) {
return;
}
$deprecated = GFAddOn::get_all_deprecated_protected_methods();
if ( ! empty( $deprecated ) ) {
foreach ( $deprecated as $method ) {
_deprecated_function( $method, '1.9', 'public access level' );
}
}
}
/**
* Shortcode UI
*/
/**
* Output a shortcode.
*
* Called via AJAX.
* Used for displaying the shortcode in the TinyMCE editor.
*
* @since Unknown
* @access public
* @global $post
*/
public static function handle_ajax_do_shortcode() {
$shortcode = ! empty( $_POST['shortcode'] ) ? sanitize_text_field( stripslashes( $_POST['shortcode'] ) ) : null;
$post_id = ! empty( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : null;
if ( ! current_user_can( 'edit_post', $post_id ) || ! wp_verify_nonce( $_POST['nonce'], 'gf-shortcode-ui-preview' ) ) {
echo esc_html__( 'Error', 'gravityforms' );
exit;
}
$form_id = ! empty( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : null;
global $post;
$post = get_post( $post_id );
setup_postdata( $post );
self::enqueue_form_scripts( $form_id, true );
wp_print_scripts();
wp_print_styles();
echo do_shortcode( $shortcode );
// Disable the elements on the form
?>
id ) ] = $form->title;
}
$default_attrs = array(
array(
'label' => __( 'Select a form below to add it to your post or page.', 'gravityforms' ),
'tooltip' => __( 'Select a form from the list to add it to your post or page.', 'gravityforms' ),
'attr' => 'id',
'type' => 'select',
'section' => 'required',
'description' => __( "Can't find your form? Make sure it is active.", 'gravityforms' ),
'options' => $forms_options,
),
array(
'label' => __( 'Display form title', 'gravityforms' ),
'attr' => 'title',
'default' => 'true',
'section' => 'standard',
'type' => 'checkbox',
'tooltip' => __( 'Whether or not to display the form title.', 'gravityforms' )
),
array(
'label' => __( 'Display form description', 'gravityforms' ),
'attr' => 'description',
'default' => 'true',
'section' => 'standard',
'type' => 'checkbox',
'tooltip' => __( 'Whether or not to display the form description.', 'gravityforms' )
),
array(
'label' => __( 'Enable Ajax', 'gravityforms' ),
'attr' => 'ajax',
'section' => 'standard',
'type' => 'checkbox',
'tooltip' => __( 'Specify whether or not to use Ajax to submit the form.', 'gravityforms' )
),
array(
'label' => 'Tabindex',
'attr' => 'tabindex',
'type' => 'number',
'tooltip' => __( 'Specify the starting tab index for the fields of this form.', 'gravityforms' )
),
);
/**
* Filters through the shortcode builder actions (ajax, tabindex, form title) for adding a new form to a post, page, etc.
*
* @since Unknown
*
* @param array() Array of additional shortcode builder actions. Empty by default.
*/
$add_on_actions = apply_filters( 'gform_shortcode_builder_actions', array() );
if ( ! empty( $add_on_actions ) ) {
$action_options = array( '' => __( 'Select an action', 'gravityforms' ) );
foreach ( $add_on_actions as $add_on_action ) {
foreach ( $add_on_action as $key => $array ) {
$action_options[ $key ] = $array['label'];
}
}
$default_attrs[] = array(
'label' => 'Action',
'attr' => 'action',
'type' => 'select',
'options' => $action_options,
'tooltip' => __( 'Select an action for this shortcode. Actions are added by some add-ons.', 'gravityforms' )
);
}
$shortcode = array(
'shortcode_tag' => 'gravityform',
'action_tag' => '',
'label' => 'Gravity Forms',
'attrs' => $default_attrs,
);
$shortcodes[] = $shortcode;
if ( ! empty( $add_on_actions ) ) {
foreach ( $add_on_actions as $add_on_action ) {
foreach ( $add_on_action as $key => $array ) {
$attrs = array_merge( $default_attrs, $array['attrs'] );
$shortcode = array(
'shortcode_tag' => 'gravityform',
'action_tag' => $key,
'label' => rgar( $array, 'label' ),
'attrs' => $attrs,
);
}
}
$shortcodes[] = $shortcode;
}
return $shortcodes;
}
/**
* Enqueues scripts needed to display the form.
*
* @since Unknown
* @access public
*
* @used GFFormDisplay::enqueue_form_scripts()
* @used GFAddOn::get_registered_addons()
*
* @param string $form_id The displayed form ID.
* @param bool $is_ajax True if form uses AJAX. False otherwise.
*/
public static function enqueue_form_scripts( $form_id, $is_ajax = false ) {
require_once( GFCommon::get_base_path() . '/form_display.php' );
$form = RGFormsModel::get_form_meta( $form_id );
GFFormDisplay::enqueue_form_scripts( $form, $is_ajax );
$addons = GFAddOn::get_registered_addons();
foreach ( $addons as $addon ) {
$a = call_user_func( array( $addon, 'get_instance' ) );
$a->enqueue_scripts( $form, $is_ajax );
}
}
/**
* Displays the installation wizard or upgrade wizard when appropriate.
*
* @since 2.2
* @access public
*
* @return bool Was a wizard displayed?
*/
public static function maybe_display_wizard() {
return gf_upgrade()->maybe_display_wizard();
}
/**
* Sets the screen options for the entry list.
*
* @since 2.0
* @access public
*
* @used-by Filter: set-screen-option
*
* @param bool|int $status Screen option value. Not used. Defaults to false.
* @param string $option The option to check.
* @param int $value The number of rows to display per page.
*
* @return array $return The filtered data
*/
public static function set_screen_options( $status, $option, $value ) {
$return = false;
if ( $option == 'gform_entries_screen_options' ) {
$return = array();
$return['default_filter'] = sanitize_key( rgpost( 'gform_default_filter' ) );
$return['per_page'] = sanitize_key( rgpost( 'gform_per_page' ) );
} elseif ( $option = 'gform_forms_per_page' ) {
$return = $value;
}
return $return;
}
/**
* Returns the markup for the screen options for the entry list.
*
* @since 2.0
* @access public
*
* @used-by Filter: screen_settings
* @used GFEntryList::get_screen_options_markup()
*
* @param string $status The current screen settings
* @param WP_Screen $args WP_Screen object
*
* @return string $return The filtered screen settings
*/
public static function show_screen_options( $status, $args ) {
$return = $status;
if ( self::get_page() == 'entry_list' ) {
require_once( GFCommon::get_base_path() . '/entry_list.php' );
$return = GFEntryList::get_screen_options_markup( $status, $args );
}
return $return;
}
/**
* Loads the screen options for the entry detail page.
*
* @since 2.0
* @access public
*
* @used GFEntryDetail::add_meta_boxes()
*/
public static function load_screen_options() {
$screen = get_current_screen();
if ( ! is_object( $screen ) ) {
return;
}
$page = GFForms::get_page();
if ( $page == 'form_list' ) {
$args = array(
'label' => __( 'Forms per page', 'gravityforms' ),
'default' => 20,
'option' => 'gform_forms_per_page',
);
add_screen_option( 'per_page', $args );
} elseif ( in_array( $page, array( 'entry_detail', 'entry_detail_edit' ) ) ) {
require_once( GFCommon::get_base_path() . '/entry_detail.php' );
GFEntryDetail::add_meta_boxes();
}
}
/**
* Daily cron task. Target for the gravityforms_cron action.
*
* - Performs self-healing
* - Adds empty index files
* - Deletes unclaimed export files.
* - Deleted old log files.
* - Deletes orphaned entry rows from the lead table.
*
* @since 2.0.0
* @access public
*
* @used-by Action: gravityforms_cron
* @used GFForms::add_security_files()
* @used GFForms::delete_old_export_files()
* @used GFForms::delete_old_log_files()
* @used GFForms::do_self_healing()
* @used GFForms::delete_orphaned_entries()
*/
public static function cron() {
GFCommon::log_debug( __METHOD__ . '(): Starting cron.' );
self::add_security_files();
self::delete_old_export_files();
self::delete_old_log_files();
self::do_self_healing();
self::delete_orphaned_entries();
GFCommon::log_debug( __METHOD__ . '(): Done.' );
}
/**
* Deletes all entry export files from the server that haven't been claimed within 24 hours.
*
* @since 2.0.0
* @access public
*/
public static function delete_old_export_files() {
GFCommon::log_debug( __METHOD__ . '(): Starting.' );
$uploads_folder = RGFormsModel::get_upload_root();
if ( ! is_dir( $uploads_folder ) || is_link( $uploads_folder ) ) {
GFCommon::log_debug( __METHOD__ . '(): No upload root - bailing.' );
return;
}
$export_folder = $uploads_folder . 'export';
if ( ! is_dir( $export_folder ) || is_link( $export_folder ) ) {
GFCommon::log_debug( __METHOD__ . '(): No export root - bailing.' );
return;
}
GFCommon::log_debug( __METHOD__ . '(): Start deleting old export files' );
foreach ( glob( $export_folder . DIRECTORY_SEPARATOR . '*.csv', GLOB_BRACE ) as $filename ) {
$timestamp = filemtime( $filename );
if ( $timestamp < time() - DAY_IN_SECONDS ) {
// Delete files over a day old
GFCommon::log_debug( __METHOD__ . '(): Proceeding to delete ' . $filename );
$success = unlink( $filename );
GFCommon::log_debug( __METHOD__ . '(): Delete successful: ' . ( $success ? 'yes' : 'no' ) );
}
}
}
/**
* Deletes any log files that are older than one month.
*
* @since 2.0.0
* @access public
*/
public static function delete_old_log_files() {
GFCommon::log_debug( __METHOD__ . '(): Starting.' );
$uploads_folder = RGFormsModel::get_upload_root();
if ( ! is_dir( $uploads_folder ) || is_link( $uploads_folder ) ) {
GFCommon::log_debug( __METHOD__ . '(): No upload root - bailing.' );
return;
}
$logs_folder = $uploads_folder . 'logs';
if ( ! is_dir( $logs_folder ) || is_link( $logs_folder ) ) {
GFCommon::log_debug( __METHOD__ . '(): No logs folder - bailing.' );
return;
}
GFCommon::log_debug( __METHOD__ . '(): Start deleting old log files' );
foreach ( glob( $logs_folder . DIRECTORY_SEPARATOR . '*.txt', GLOB_BRACE ) as $filename ) {
$timestamp = filemtime( $filename );
if ( $timestamp < time() - MONTH_IN_SECONDS ) {
// Delete files over one month old
GFCommon::log_debug( __METHOD__ . '(): Proceeding to delete ' . $filename );
$success = unlink( $filename );
GFCommon::log_debug( __METHOD__ . '(): Delete successful: ' . ( $success ? 'yes' : 'no' ) );
}
}
}
/**
* Deletes all rows in the lead table that don't have corresponding rows in the details table.
*
* @since 2.0.0
* @access public
* @global $wpdb
*/
public static function delete_orphaned_entries() {
global $wpdb;
if ( version_compare( GFFormsModel::get_database_version(), '2.3-beta-1', '<' ) ) {
return;
}
GFCommon::log_debug( __METHOD__ . '(): Starting to delete orphaned entries' );
$entry_table = GFFormsModel::get_entry_table_name();
$entry_meta_table = GFFormsModel::get_entry_meta_table_name();
$sql = "DELETE FROM {$entry_table} WHERE id NOT IN( SELECT entry_id FROM {$entry_meta_table} )";
$result = $wpdb->query( $sql );
GFCommon::log_debug( __METHOD__ . '(): Delete result: ' . print_r( $result, true ) );
}
/**
* Hooked into the 'admin_head' action.
*
* Outputs the styles for the Forms Toolbar menu.
* Outputs gf vars if required.
*
* @since 2.0.1.2
* @access public
*/
public static function load_admin_bar_styles() {
if ( ! get_option( 'gform_enable_toolbar_menu' ) ) {
return;
}
if ( ! GFCommon::current_user_can_any( array(
'gravityforms_edit_forms',
'gravityforms_create_form',
'gravityforms_preview_forms',
'gravityforms_view_entries'
) )
) {
// The current user can't use anything on the menu so bail.
return;
}
?>
drop_index() instead
*/
public static function drop_index( $table, $index ) {
_deprecated_function( 'This function has been deprecated. Use gf_upgrade()->drop_index() instead', '2.2', 'gf_upgrade()->drop_index()' );
gf_upgrade()->drop_index( $table, $index );
}
/**
* Fixes case for database queries.
*
* @deprecated 2.2
*
* @since Unknown
* @access public
*
* @param array $cqueries Queries to be fixed.
*
* @return array $queries Queries after processing.
*/
public static function dbdelta_fix_case( $cqueries ) {
_deprecated_function( 'dbdelta_fix_case', '2.2', 'gf_upgrade()->dbdelta_fix_case()' );
return gf_upgrade()->dbdelta_fix_case( $cqueries );
}
public static function setup( $force_setup = false ) {
_deprecated_function( 'This function has been deprecated. Use gf_upgrade()->maybe_upgrade() or gf_upgrade()->upgrade() instead', '2.2', 'gf_upgrade()->upgrade() or gf_upgrade()->maybe_upgrade()' );
if ( $force_setup ) {
$current_version = get_option( 'rg_form_version' );
gf_upgrade()->upgrade( $current_version, true );
} else {
gf_upgrade()->maybe_upgrade();
}
}
public static function setup_database() {
_deprecated_function( 'This function has been deprecated. Use gf_upgrade()->upgrade_schema()', '2.2', 'gf_upgrade()->upgrade_schema()' );
gf_upgrade()->upgrade_schema();
}
/**
* Creates an instance of GF_Background_Upgrader and stores it in GFForms::$background_upgrader
*
* @since 2.3
*/
public static function init_background_upgrader() {
if ( empty( self::$background_upgrader ) ) {
require_once( plugin_dir_path( __FILE__ ) . 'includes/class-gf-background-upgrader.php' );
self::$background_upgrader = new GF_Background_Upgrader();
}
}
/**
* Target for the WordPress 'query' filter. Triggers an PHP Notice if an outdated add-on or custom code attempts to
* access tables that are not valid for this version of Gravity Forms.
*
* @since 2.3
*
* @param $query
*
* @return string
*/
public static function filter_query( $query ) {
global $wpdb;
if ( preg_match( "/$wpdb->prefix(rg_lead_detail|rg_lead_meta|rg_lead_notes|rg_lead|rg_form_meta|rg_form_view|rg_form|rg_incomplete_submissions)/", $query, $matches ) ) {
if ( version_compare( GFFormsModel::get_database_version(), '2.3-dev-1', '>' ) ) {
$table_name = $matches[0];
$url = 'https://docs.gravityforms.com/database-storage-structure-reference/#changes-from-gravity-forms-2-2';
/* translators: 1: The table name 2: the URL with further details */
$message = esc_html__( 'An outdated add-on or custom code is attempting to access the %1$s table which is not valid in this version of Gravity Forms. Update your add-ons and custom code to prevent loss of form data. Further details: %2$s', 'gravityforms' );
$notice = sprintf( $message, $table_name, $url );
trigger_error( $notice );
}
}
return $query;
}
/**
* Target for the admin_notices action.
*
* @since 2.3
*
* Displays site-side dismissible notices.
*/
public static function action_admin_notices() {
GFCommon::display_dismissible_message( false, 'site-wide' );
}
}
/**
* Class RGForms
*
* @deprecated
* Exists only for backwards compatibility. Used GFForms instead.
*/
class RGForms extends GFForms {
}
/**
* Main Gravity Forms function call.
*
* Should be used to insert a Gravity Form from code.
*
* @param string $id The form ID
* @param bool $display_title If the form title should be displayed in the form. Defaults to true.
* @param bool $display_description If the form description should be displayed in the form. Defaults to true.
* @param bool $display_inactive If the form should be displayed if marked as inactive. Defaults to false.
* @param array|null $field_values Default field values. Defaults to null.
* @param bool $ajax If submission should be processed via AJAX. Defaults to false.
* @param int $tabindex Starting tabindex. Defaults to 1.
* @param bool $echo If the field should be echoed. Defaults to true.
*
* @return string|void
*/
function gravity_form( $id, $display_title = true, $display_description = true, $display_inactive = false, $field_values = null, $ajax = false, $tabindex = 1, $echo = true ) {
if ( ! $echo ) {
return GFForms::get_form( $id, $display_title, $display_description, $display_inactive, $field_values, $ajax, $tabindex );
}
echo GFForms::get_form( $id, $display_title, $display_description, $display_inactive, $field_values, $ajax, $tabindex );
}
/**
* @return GF_Upgrade
*/
function gf_upgrade() {
require_once( GFCommon::get_base_path() . '/includes/class-gf-upgrade.php' );
return GF_Upgrade::get_instance();
}
/**
* Enqueues form scripts for the specified form.
*
* @uses GFForms::enqueue_form_scripts()
*
* @param string $form_id The form ID.
* @param bool $is_ajax If the form is submitted via AJAX. Defaults to false.
*/
function gravity_form_enqueue_scripts( $form_id, $is_ajax = false ) {
GFForms::enqueue_form_scripts( $form_id, $is_ajax );
}
if ( ! function_exists( 'rgget' ) ) {
/**
* Helper function for getting values from query strings or arrays
*
* @param string $name The key
* @param array $array The array to search through. If null, checks query strings. Defaults to null.
*
* @return string The value. If none found, empty string.
*/
function rgget( $name, $array = null ) {
if ( ! isset( $array ) ) {
$array = $_GET;
}
if ( ! is_array( $array ) ) {
return '';
}
if ( isset( $array[ $name ] ) ) {
return $array[ $name ];
}
return '';
}
}
if ( ! function_exists( 'rgpost' ) ) {
/**
* Helper function to obtain POST values.
*
* @param string $name The key
* @param bool $do_stripslashes Optional. Performs stripslashes_deep. Defaults to true.
*
* @return string The value. If none found, empty string.
*/
function rgpost( $name, $do_stripslashes = true ) {
if ( isset( $_POST[ $name ] ) ) {
return $do_stripslashes ? stripslashes_deep( $_POST[ $name ] ) : $_POST[ $name ];
}
return '';
}
}
if ( ! function_exists( 'rgar' ) ) {
/**
* Get a specific property of an array without needing to check if that property exists.
*
* Provide a default value if you want to return a specific value if the property is not set.
*
* @since Unknown
* @access public
*
* @param array $array Array from which the property's value should be retrieved.
* @param string $prop Name of the property to be retrieved.
* @param string $default Optional. Value that should be returned if the property is not set or empty. Defaults to null.
*
* @return null|string|mixed The value
*/
function rgar( $array, $prop, $default = null ) {
if ( ! is_array( $array ) && ! ( is_object( $array ) && $array instanceof ArrayAccess ) ) {
return $default;
}
if ( isset( $array[ $prop ] ) ) {
$value = $array[ $prop ];
} else {
$value = '';
}
return empty( $value ) && $default !== null ? $default : $value;
}
}
if ( ! function_exists( 'rgars' ) ) {
/**
* Gets a specific property within a multidimensional array.
*
* @since Unknown
* @access public
*
* @param array $array The array to search in.
* @param string $name The name of the property to find.
* @param string $default Optional. Value that should be returned if the property is not set or empty. Defaults to null.
*
* @return null|string|mixed The value
*/
function rgars( $array, $name, $default = null ) {
if ( ! is_array( $array ) && ! ( is_object( $array ) && $array instanceof ArrayAccess ) ) {
return $default;
}
$names = explode( '/', $name );
$val = $array;
foreach ( $names as $current_name ) {
$val = rgar( $val, $current_name, $default );
}
return $val;
}
}
if ( ! function_exists( 'rgempty' ) ) {
/**
* Determines if a value is empty.
*
* @since Unknown
* @access public
*
* @param string $name The property name to check.
* @param array $array Optional. An array to check through. Otherwise, checks for POST variables.
*
* @return bool True if empty. False otherwise.
*/
function rgempty( $name, $array = null ) {
if ( is_array( $name ) ) {
return empty( $name );
}
if ( ! $array ) {
$array = $_POST;
}
$val = rgar( $array, $name );
return empty( $val );
}
}
if ( ! function_exists( 'rgblank' ) ) {
/**
* Checks if the string is empty
*
* @since Unknown
* @access public
*
* @param string $text The string to check.
*
* @return bool True if empty. False otherwise.
*/
function rgblank( $text ) {
return empty( $text ) && ! is_array( $text ) && strval( $text ) != '0';
}
}
if ( ! function_exists( 'rgobj' ) ) {
/**
* Gets a property value from an object
*
* @since Unknown
* @access public
*
* @param object $obj The object to check
* @param string $name The property name to check for
*
* @return string The property value
*/
function rgobj( $obj, $name ) {
if ( isset( $obj->$name ) ) {
return $obj->$name;
}
return '';
}
}
if ( ! function_exists( 'rgexplode' ) ) {
/**
* Converts a delimiter separated string to an array.
*
* @since Unknown
* @access public
*
* @param string $sep The delimiter between values
* @param string $string The string to convert
* @param int $count The expected number of items in the resulting array
*
* @return array $ary The exploded array
*/
function rgexplode( $sep, $string, $count ) {
$ary = explode( $sep, $string );
while ( count( $ary ) < $count ) {
$ary[] = '';
}
return $ary;
}
}
if ( ! function_exists( 'gf_apply_filters' ) ) {
//function gf_apply_filters( $filter, $modifiers, $value ) {
/**
* Gravity Forms pre-processing for apply_filters
*
* Allows additional filters based on form and field ID to be defined easily.
*
* @since Unknown
* @access public
*
* @param string|array $filter The name of the filter.
* @param mixed $value The value to filter.
*
* @return mixed The filtered value.
*/
function gf_apply_filters( $filter, $value ) {
$args = func_get_args();
if ( is_array( $filter ) ) {
// func parameters are: $filter, $value
$modifiers = array_splice( $filter, 1, count( $filter ) );
$filter = $filter[0];
$args = array_slice( $args, 2 );
} else {
//_deprecated_argument( 'gf_apply_filters', '1.9.14.20', "Modifiers should no longer be passed as a separate parameter. Combine the filter name and modifier(s) into an array and pass that array as the first parameter of the function. Example: gf_apply_filters( array( 'action_name', 'mod1', 'mod2' ), \$value, \$arg1, \$arg2 );" );
// func parameters are: $filter, $modifier, $value
$modifiers = ! is_array( $value ) ? array( $value ) : $value;
$value = $args[2];
$args = array_slice( $args, 3 );
}
// Add an empty modifier so the base filter will be applied as well
array_unshift( $modifiers, '' );
$args = array_pad( $args, 10, null );
// Apply modified versions of filter
foreach ( $modifiers as $modifier ) {
$modifier = empty( $modifier ) ? '' : sprintf( '_%s', $modifier );
$filter .= $modifier;
$value = apply_filters( $filter, $value, $args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8], $args[9] );
}
return $value;
}
}
if ( ! function_exists( 'gf_do_action' ) ) {
/**
* Gravity Forms pre-processing for do_action.
*
* Allows additional actions based on form and field ID to be defined easily.
*
* @since 1.9.14.20 Modifiers should no longer be passed as a separate parameter.
* @since 1.9.12
* @access public
*
* @param string|array $action The action.
*/
function gf_do_action( $action ) {
$args = func_get_args();
if ( is_array( $action ) ) {
// Func parameters are: $action, $value
$modifiers = array_splice( $action, 1, count( $action ) );
$action = $action[0];
$args = array_slice( $args, 1 );
} else {
//_deprecated_argument( 'gf_do_action', '1.9.14.20', "Modifiers should no longer be passed as a separate parameter. Combine the action name and modifier(s) into an array and pass that array as the first parameter of the function. Example: gf_do_action( array( 'action_name', 'mod1', 'mod2' ), \$arg1, \$arg2 );" );
// Func parameters are: $action, $modifier, $value
$modifiers = ! is_array( $args[1] ) ? array( $args[1] ) : $args[1];
$args = array_slice( $args, 2 );
}
// Add an empty modifier so the base filter will be applied as well
array_unshift( $modifiers, '' );
$args = array_pad( $args, 10, null );
// Apply modified versions of filter
foreach ( $modifiers as $modifier ) {
$modifier = empty( $modifier ) ? '' : sprintf( '_%s', $modifier );
$action .= $modifier;
do_action( $action, $args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8], $args[9] );
}
}
}