';
}
/**
* Displays the popup to insert a form to a post/page.
*
* @since Unknown
* @access public
*/
public static function add_mce_popup() {
?>
' . esc_html__( 'Settings', 'gravityforms' ) . '' );
return $links;
}
/**
* Displays messages for the Gravity Forms listing on the Plugins page.
*
* Displays if the key is invalid or an update is available.
*
* @since Unknown
* @since 2.4.15 Update to improve multisite updates.
* @access public
*
* @param string $plugin_name The plugin filename. Immediately overwritten.
* @param array $plugin_data An array of plugin data.
*/
public static function plugin_row( $plugin_name, $plugin_data ) {
self::maybe_display_update_notification( $plugin_name, $plugin_data );
$add_ons = gf_upgrade()->get_min_addon_requirements();
if ( isset( $add_ons[ $plugin_name ] ) ) {
$plugin_path = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $plugin_name;
if ( ! file_exists( $plugin_path ) ) {
return;
}
$plugin_data = get_plugin_data( $plugin_path, false, false );
$current_version = $plugin_data['Version'];
$add_on = $add_ons[ $plugin_name ];
$min_version = $add_on['min_version'];
if ( version_compare( $current_version, $min_version, '<' ) ) {
$name = $add_on['name'];
/* translators: 1: The name of the add-on, 2: version number. */
$message = esc_html__( 'This version of the %1$s is not compatible with the version of Gravity Forms that is installed. Upgrade this add-on to version %2$s or greater to avoid compatibility issues and potential loss of data.', 'gravityforms' );
echo '
' . sprintf( $message, $name, $min_version ) . '
';
}
}
}
/**
* Display Gravity Forms and add-ons update notifications if needed.
*
* @since 2.4.15
*
* @param string $plugin_name The plugin filename. Immediately overwritten.
* @param array $plugin_data An array of plugin data.
* @param string $slug The add-on slug.
* @param string $version The add-on version.
*/
public static function maybe_display_update_notification( $plugin_name, $plugin_data, $slug = '', $version = '' ) {
if ( empty( $slug ) && $plugin_name !== 'gravityforms/gravityforms.php' ) {
return;
}
if ( empty( $slug ) ) {
$version_info = GFCommon::get_version_info();
$slug = 'gravityforms';
$version = GFCommon::$version;
} else {
$version_info = rgars( GFCommon::get_version_info(), 'offerings/' . $slug );
}
$valid_key = rgar( GFCommon::get_version_info(), 'is_valid_key' );
$message = '';
// Display the message only for a multisite network. A single site install doesn't need it (WP handles it).
if ( ( is_multisite() && ! is_network_admin() ) && version_compare( $version, rgar( $version_info, 'version' ), '<' ) ) {
$changelog_url = wp_nonce_url( self_admin_url( 'admin-ajax.php?action=gf_get_changelog&plugin=' . $slug . '&TB_iframe=true&width=640&height=808' ) );
if ( ! current_user_can( 'update_plugins' ) || ! $valid_key ) {
$message .= sprintf(
/* translators: 1: plugin name, 2: open tag, 3: version number, 4: close tag */
esc_html__( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s. ', 'gravityforms' ),
$plugin_data['Name'],
sprintf(
/* translators: 1: plugin name, 2: version number, 3: changelog URL */
__( '', 'gravityforms' ),
$plugin_data['Name'],
$version_info['version'],
$changelog_url
),
$version_info['version'],
''
);
} else {
$upgrade_url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin_name ) ), 'upgrade-plugin_' . $plugin_name );
$message .= sprintf(
/* translators: 1: plugin name, 2: open tag, 3: version number, 4: close tag, 5: open tag 6. close tag */
esc_html__( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s. ', 'gravityforms' ),
$plugin_data['Name'],
sprintf(
/* translators: 1: plugin name, 2: version number, 3: changelog URL */
__( '', 'gravityforms' ),
$plugin_data['Name'],
$version_info['version'],
$changelog_url
),
$version_info['version'],
'',
sprintf(
/* translators: 1: upgrade URL, 2: plugin name */
__( '', 'gravityforms' ),
$upgrade_url,
$plugin_data['Name']
),
''
);
}
}
if ( ! $valid_key ) {
$message .= sprintf( esc_html__( '%sRegister%s your copy of Gravity Forms to receive access to automatic upgrades and support. Need a license key? %sPurchase one now%s.', 'gravityforms' ), '', '', '', '' );
}
if ( ! empty( $message ) ) {
if ( is_network_admin() ) {
$active_class = is_plugin_active_for_network( $plugin_name ) ? ' active' : '';
} else {
$active_class = is_plugin_active( $plugin_name ) ? ' active' : '';
}
echo '
';
echo '
';
echo '
';
echo '
';
echo $message;
echo '
';
// Apply the class "update" to the plugin row to get rid of the ugly border.
echo "
";
}
}
/**
* Hooks into in_plugin_update_message-gravityforms/gravityforms.php and displays an update message specifically for Gravity Forms 2.3.
*
* @param $args
* @param $response
*/
public static function in_plugin_update_message( $args, $response ) {
if ( empty( $args['update'] ) ) {
return;
}
if ( version_compare( $args['new_version'], '2.3', '>=' ) && version_compare( GFForms::$version, '2.3', '<' ) ) {
$message = esc_html__( 'IMPORTANT: As this is a major update, we strongly recommend creating a backup of your site before updating.', 'gravityforms' );
require_once( GFCommon::get_base_path() . '/includes/system-status/class-gf-update.php' );
$updates = GF_Update::available_updates();
$addons_requiring_updates = array();
foreach ( $updates as $update ) {
if ( $update['slug'] == 'gravityforms' ) {
continue;
}
$update_available = version_compare( $update['installed_version'], $update['latest_version'], '<' );
if ( $update_available ) {
$addons_requiring_updates[] = $update['name'] . ' ' . $update['installed_version'];
}
}
if ( count( $addons_requiring_updates ) > 0 ) {
/* translators: %s: version number */
$message .= ' ' . sprintf( esc_html__( "The versions of the following add-ons you're running haven't been tested with Gravity Forms %s. Please update them or confirm compatibility before updating Gravity Forms, or you may experience issues:", 'gravityforms' ), $args['new_version'] );
$message .= ' ' . join( ', ', $addons_requiring_updates );
}
echo sprintf( '
%s
', $message );
}
}
/**
* Displays current version details on Plugins page
*
* @since Unknown
* @access public
*/
public static function display_changelog() {
if ( $_REQUEST['plugin'] != 'gravityforms' ) {
return;
}
$page_text = self::get_changelog();
echo $page_text;
exit;
}
/**
* Get changelog with admin-ajax.php in GFForms::maybe_display_update_notification().
*
* @since 2.4.15
*/
public static function ajax_display_changelog() {
check_admin_referer();
GFForms::display_changelog();
}
/**
* Gets the changelog for the newest version
*
* @since Unknown
* @access public
*
* @return string $page_text The changelog. Error message if there's an issue.
*/
public static function get_changelog() {
$key = GFCommon::get_key();
$body = "key=$key";
$options = array( 'method' => 'POST', 'timeout' => 3, 'body' => $body );
$options['headers'] = array(
'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ),
'Content-Length' => strlen( $body ),
'User-Agent' => 'WordPress/' . get_bloginfo( 'version' ),
'Referer' => get_bloginfo( 'url' )
);
$raw_response = GFCommon::post_to_manager( 'changelog.php', GFCommon::get_remote_request_params(), $options );
if ( is_wp_error( $raw_response ) || 200 != $raw_response['response']['code'] ) {
$page_text = sprintf( esc_html__( 'Oops!! Something went wrong. %sPlease try again or %scontact us%s.', 'gravityforms' ), ' ', "", '' );
} else {
$page_text = $raw_response['body'];
if ( substr( $page_text, 0, 10 ) != '' ) {
$page_text = '';
} else {
$page_text = '
' . $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 ) {
?>
';
}
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' => ( isset( $tab['capabilities'] ) ) ? $tab['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();
}
/**
* Display admin notice when logging is enabled.
*
* @since 2.4
* @access public
*/
public static function maybe_display_logging_notice() {
$notice_disabled = defined( 'GF_LOGGING_DISABLE_NOTICE' ) && GF_LOGGING_DISABLE_NOTICE;
$logging_enabled = get_option( 'gform_enable_logging', false ) || is_plugin_active( 'gravityformslogging/logging.php' );
// If logging is disabled, return.
if ( $notice_disabled || ! $logging_enabled || ! GFCommon::current_user_can_any( 'gravityforms_edit_settings' ) ) {
return;
}
// Prepare message.
$message = sprintf(
'
%s
%s
',
sprintf(
esc_html__( "Gravity Forms logging is currently enabled. Log files can contain sensitive information so ensure that logging is only enabled for as long as is required for troubleshooting. %sClick here to disable logging.%s", 'gravityforms' ),
'',
''
),
esc_html__( "If you're currently receiving support, do not disable logging until the issue is resolved.", 'gravityforms' )
);
// Prepare script.
$script = "";
printf( '
%s
%s', wp_create_nonce( 'gf_disable_logging_nonce' ), $message, $script );
}
/**
* 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();
if ( ! get_option( 'gform_enable_logging' ) ) {
gf_logging()->delete_log_files();
}
require_once( 'includes/class-personal-data.php' );
GF_Personal_Data::cron_task();
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 ( GFCommon::glob( '*.csv', $export_folder . DIRECTORY_SEPARATOR ) 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 ( GFCommon::glob( '*.txt', $logs_folder . DIRECTORY_SEPARATOR ) 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.
*
* @deprecated
* @since 2.0.0
* @access public
* @global $wpdb
*/
public static function delete_orphaned_entries() {
_deprecated_function( __METHOD__, '2.4.17' );
global $wpdb;
if ( version_compare( GFFormsModel::get_database_version(), '2.3-beta-1', '<' ) || GFFormsModel::has_batch_field_operations() ) {
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' );
}
/**
* Registers the Gravity Forms data exporter.
*
* @since 2.4
*
* @param array $exporters
*
* @return array
*/
public static function register_data_exporter( $exporters ) {
$exporters['gravityforms'] = array(
'exporter_friendly_name' => __( 'Gravity Forms Exporter' ),
'callback' => array( 'GFForms', 'data_exporter' ),
);
return $exporters;
}
/**
* Registers the Gravity Forms data eraser.
*
* @since 2.4
*
* @param array $erasers
*
* @return array
*/
public static function register_data_eraser( $erasers ) {
$erasers['gravityforms'] = array(
'eraser_friendly_name' => __( 'Gravity Forms Eraser' ),
'callback' => array( 'GFForms', 'data_eraser' ),
);
return $erasers;
}
/**
* Callback for the WordPress data exporter.
*
* @since 2.4
*
* @param string $email_address
* @param int $page
*
* @return array
*/
public static function data_exporter( $email_address, $page = 1 ) {
require_once( 'includes/class-personal-data.php' );
return GF_Personal_Data::data_exporter( $email_address, $page );
}
/**
* Callback for the WordPress data eraser.
*
* @since 2.4
*
* @param string $email_address
* @param int $page
*
* @return array
*/
public static function data_eraser( $email_address, $page = 1 ) {
require_once( 'includes/class-personal-data.php' );
return GF_Personal_Data::data_eraser( $email_address, $page );
}
}
/**
* 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 0.
* @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 = 0, $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 = rgblank( $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 = rgblank( $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] );
}
}
}