Admin/Connect.php 0000666 00000017322 15214133076 0007711 0 ustar 00 hooks();
}
/**
* Hooks.
*
* @since 1.5.5
*/
public function hooks() {
\add_action( 'wpforms_settings_enqueue', array( $this, 'settings_enqueues' ) );
\add_action( 'wp_ajax_wpforms_connect_url', array( $this, 'generate_url' ) );
\add_action( 'wp_ajax_nopriv_wpforms_connect_process', array( $this, 'process' ) );
}
/**
* Settings page enqueues.
*
* @since 1.5.5
*/
public function settings_enqueues() {
$min = \wpforms_get_min_suffix();
\wp_enqueue_script(
'wpforms-connect',
\WPFORMS_PLUGIN_URL . "lite/assets/js/admin/connect{$min}.js",
array( 'jquery' ),
\WPFORMS_VERSION,
true
);
}
/**
* Generate and return WPForms Connect URL.
*
* @since 1.5.5
*/
public function generate_url() {
$this->init_error_handler();
try {
// Run a security check.
\check_ajax_referer( 'wpforms-admin', 'nonce' );
// Check for permissions.
if ( ! \current_user_can( 'install_plugins' ) ) {
\wp_send_json_error(
array(
'message' => \esc_html__( 'Sorry, you do not have permission to install plugins.', 'wpforms-lite' )
)
);
}
$key = ! empty( $_POST['key'] ) ? \sanitize_text_field( \wp_unslash( $_POST['key'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
if ( empty( $key ) ) {
\wp_send_json_error(
array(
'message' => \esc_html__( 'Please enter your license key to connect.', 'wpforms-lite' )
)
);
}
if ( wpforms()->pro ) {
\wp_send_json_error(
array( 'message' => \esc_html__( 'Only the Lite version can upgrade.', 'wpforms-lite' )
)
);
}
// Verify pro version is not installed.
$active = \activate_plugin( 'wpforms/wpforms.php', false, false, true );
if ( ! \is_wp_error( $active ) ) {
// Deactivate Lite.
\deactivate_plugins( \plugin_basename( WPFORMS_PLUGIN_FILE ) );
\wp_send_json_success(
array(
'message' => \esc_html__( 'WPForms Pro was already installed and has not been activated.', 'wpforms-lite' ),
'reload' => true,
)
);
}
// Generate URL.
$oth = hash( 'sha512', \wp_rand() );
\update_option( 'wpforms_connect_token', $oth );
\update_option( 'wpforms_connect', $key );
$version = WPFORMS_VERSION;
$endpoint = \admin_url( 'admin-ajax.php' );
$redirect = \admin_url( 'admin.php?page=wpforms-settings' );
$url = \add_query_arg(
array(
'key' => $key,
'oth' => $oth,
'endpoint' => $endpoint,
'version' => $version,
'siteurl' => \admin_url(),
'homeurl' => \home_url(),
'redirect' => rawurldecode( base64_encode( $redirect ) ), // phpcs:ignore
'v' => 2,
),
'https://upgrade.wpforms.com'
);
\wp_send_json_success(
array(
'url' => $url,
'back_url' => \add_query_arg(
array(
'action' => 'wpforms_connect',
'oth' => $oth,
),
$endpoint
),
)
);
} catch ( \Exception $e ) {
\wp_send_json_error(
array( 'error' => $e->getMessage() . ' in file ' . $e->getFile() . ', line ' . $e->getLine() )
);
}
}
/**
* Process WPForms Connect.
*
* @since 1.5.5
*/
public function process() {
$this->init_error_handler();
try {
$error = esc_html__( 'Could not install upgrade. Please download from wpforms.com and install manually.', 'wpforms-lite' );
// Verify params present (oth & download link).
$post_oth = ! empty( $_REQUEST['oth'] ) ? \sanitize_text_field( \wp_unslash( $_REQUEST['oth'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
$post_url = ! empty( $_REQUEST['file'] ) ? \esc_url_raw( \wp_unslash( $_REQUEST['file'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
if ( empty( $post_oth ) || empty( $post_url ) ) {
\wp_send_json_error( $error );
}
// Verify oth.
$oth = \get_option( 'wpforms_connect_token' );
if ( empty( $oth ) || ! hash_equals( $oth, $post_oth ) ) {
\wp_send_json_error( $error );
}
// Delete so cannot replay.
\delete_option( 'wpforms_connect_token' );
// Set the current screen to avoid undefined notices.
\set_current_screen( 'wpforms_page_wpforms-settings' );
// Prepare variables.
$url = \esc_url_raw(
\add_query_arg(
array(
'page' => 'wpforms-settings',
),
\admin_url( 'admin.php' )
)
);
// Verify pro not activated.
if ( wpforms()->pro ) {
\wp_send_json_success( \esc_html__( 'Plugin installed & activated.', 'wpforms-lite' ) );
}
// Verify pro not installed.
$active = \activate_plugin( 'wpforms/wpforms.php', $url, false, true );
if ( ! \is_wp_error( $active ) ) {
\deactivate_plugins( plugin_basename( WPFORMS_PLUGIN_FILE ) );
\wp_send_json_success( esc_html__( 'Plugin installed & activated.', 'wpforms-lite' ) );
}
$creds = \request_filesystem_credentials( $url, '', false, false, null );
// Check for file system permissions.
$perm_error = \esc_html__( 'Could not install upgrade. Please check for file system permissions and try again. Also you can download plugin from wpforms.com and install manually.', 'wpforms-lite' );
if ( false === $creds || ! \WP_Filesystem( $creds ) ) {
\wp_send_json_error( $perm_error );
}
/*
* We do not need any extra credentials if we have gotten this far, so let's install the plugin.
*/
// Do not allow WordPress to search/download translations, as this will break JS output.
\remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
// Create the plugin upgrader with our custom skin.
$installer = new PluginSilentUpgrader( new ConnectSkin() );
// Error check.
if ( ! method_exists( $installer, 'install' ) ) {
\wp_send_json_error( $error );
}
// Check license key.
$key = \get_option( 'wpforms_connect', false );
if ( empty( $key ) ) {
\wp_send_json_error(
new WP_Error(
'403',
\esc_html__( 'No key provided.', 'wpforms-lite' )
)
);
}
$installer->install( $post_url ); // phpcs:ignore
// Flush the cache and return the newly installed plugin basename.
\wp_cache_flush();
$plugin_basename = $installer->plugin_info();
if ( $plugin_basename ) {
// Deactivate the lite version first.
\deactivate_plugins( \plugin_basename( WPFORMS_PLUGIN_FILE ) );
// Activate the plugin silently.
$activated = \activate_plugin( $plugin_basename, '', false, true );
if ( ! \is_wp_error( $activated ) ) {
\add_option( 'wpforms_install', 1 );
\wp_send_json_success( \esc_html__( 'Plugin installed & activated.', 'wpforms-lite' ) );
} else {
// Reactivate the lite plugin if pro activation failed.
\activate_plugin( \plugin_basename( WPFORMS_PLUGIN_FILE ), '', false, true );
\wp_send_json_error( \esc_html__( 'Pro version installed but needs to be activated from the Plugins page inside your WordPress admin.', 'wpforms-lite' ) );
}
}
\wp_send_json_error( $error );
} catch ( \Exception $e ) {
\wp_send_json_error(
array( 'error' => $e->getMessage() . ' in file ' . $e->getFile() . ', line ' . $e->getLine() )
);
}
}
/**
* Converting errors to exceptions.
*
* @since 1.5.5
*/
public function init_error_handler() {
set_error_handler( // phpcs:ignore
function ( $errno, $errstr, $errfile, $errline, array $errcontex ) {
throw new \Exception( $errstr );
}
);
}
}
Admin/ConnectSkin.php 0000666 00000001576 15214133076 0010542 0 ustar 00 \esc_html__( 'There was an error installing WPForms Pro. Please try again.', 'wpforms-lite' ),
)
);
die;
}
}
}
Admin/DashboardWidget.php 0000666 00000032767 15214133076 0011365 0 ustar 00 settings();
$this->hooks();
}
/**
* Filterable widget settings.
*
* @since 1.5.0
*/
public function settings() {
$this->settings = array(
// Number of forms to display in the forms list before "Show More" button appears.
'forms_list_number_to_display' => \apply_filters( 'wpforms_dash_widget_forms_list_number_to_display', 5 ),
// Allow results caching to reduce DB load.
'allow_data_caching' => \apply_filters( 'wpforms_dash_widget_allow_data_caching', true ),
// Transient lifetime in seconds. Defaults to the end of a current day.
'transient_lifetime' => \apply_filters( 'wpforms_dash_widget_transient_lifetime', \strtotime( 'tomorrow' ) - \time() ),
// Determine if the forms with no entries should appear in a forms list. Once switched, the effect applies after cache expiration.
'display_forms_list_empty_entries' => \apply_filters( 'wpforms_dash_widget_display_forms_list_empty_entries', true ),
);
}
/**
* Widget hooks.
*
* @since 1.5.0
*/
public function hooks() {
\add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
\add_action( 'wp_dashboard_setup', array( $this, 'widget_register' ) );
\add_action( 'admin_init', array( $this, 'hide_widget' ) );
\add_action( 'wpforms_create_form', __CLASS__ . '::clear_widget_cache' );
\add_action( 'wpforms_save_form', __CLASS__ . '::clear_widget_cache' );
\add_action( 'wpforms_delete_form', __CLASS__ . '::clear_widget_cache' );
}
/**
* Load widget-specific scripts.
*
* @since 1.5.0
*/
public function widget_scripts() {
$screen = \get_current_screen();
if ( ! isset( $screen->id ) || 'dashboard' !== $screen->id ) {
return;
}
$min = \wpforms_get_min_suffix();
\wp_enqueue_style(
'wpforms-dashboard-widget',
\WPFORMS_PLUGIN_URL . "assets/css/dashboard-widget{$min}.css",
array(),
\WPFORMS_VERSION
);
\wp_enqueue_script(
'wpforms-moment',
\WPFORMS_PLUGIN_URL . 'assets/js/moment.min.js',
array(),
'2.22.2',
true
);
\wp_enqueue_script(
'wpforms-chart',
\WPFORMS_PLUGIN_URL . 'assets/js/chart.min.js',
array( 'wpforms-moment' ),
'2.7.2',
true
);
\wp_enqueue_script(
'wpforms-dashboard-widget',
\WPFORMS_PLUGIN_URL . "lite/assets/js/admin/dashboard-widget{$min}.js",
array( 'jquery', 'wpforms-chart' ),
\WPFORMS_VERSION,
true
);
\wp_localize_script(
'wpforms-dashboard-widget',
'wpforms_dashboard_widget',
array(
'show_more_html' => \esc_html__( 'Show More', 'wpforms-lite' ) . ' ',
'show_less_html' => \esc_html__( 'Show Less', 'wpforms-lite' ) . ' ',
'i18n' => array(
'entries' => \esc_html__( 'Entries', 'wpforms-lite' ),
),
)
);
}
/**
* Register the widget.
*
* @since 1.5.0
*/
public function widget_register() {
global $wp_meta_boxes;
$widget_key = 'wpforms_reports_widget_lite';
\wp_add_dashboard_widget(
$widget_key,
\esc_html__( 'WPForms', 'wpforms-lite' ),
array( $this, 'widget_content' )
);
// Attempt to place the widget at the top.
$normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
$widget_instance = array( $widget_key => $normal_dashboard[ $widget_key ] );
unset( $normal_dashboard[ $widget_key ] );
$sorted_dashboard = \array_merge( $widget_instance, $normal_dashboard );
$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
}
/**
* Load widget content.
*
* @since 1.5.0
*/
public function widget_content() {
$forms = \wpforms()->form->get( '', array( 'fields' => 'ids' ) );
echo '
';
if ( empty( $forms ) ) {
$this->widget_content_no_forms_html();
} else {
$this->widget_content_html();
}
$plugins = \get_plugins();
if (
! \array_key_exists( 'google-analytics-for-wordpress/googleanalytics.php', $plugins ) &&
! \array_key_exists( 'google-analytics-premium/googleanalytics-premium.php', $plugins ) &&
! empty( $forms )
) {
$this->recommended_plugin_block_html();
}
echo '
';
}
/**
* Widget content HTML if a user has no forms.
*
* @since 1.5.0
*/
public function widget_content_no_forms_html() {
$create_form_url = \add_query_arg( 'page', 'wpforms-builder', \admin_url( 'admin.php' ) );
$learn_more_url = 'https://wpforms.com/docs/creating-first-form/?utm_source=WordPress&utm_medium=link&utm_campaign=liteplugin&utm_content=dashboardwidget';
?>
forms_list_block(); ?>
get_entries_count_by_form();
if ( empty( $forms ) ) {
$this->forms_list_block_empty_html();
} else {
$this->forms_list_block_html( $forms );
}
}
/**
* Empty forms list block HTML.
*
* @since 1.5.0
*/
public function forms_list_block_empty_html() {
?>
settings['forms_list_number_to_display'];
?>
$show_forms ) : ?>
settings['allow_data_caching'];
if ( $allow_caching ) {
$transient_name = 'wpforms_dash_widget_lite_entries_by_form';
$cache = \get_transient( $transient_name );
// Filter the cache to clear or alter its data.
$cache = \apply_filters( 'wpforms_dash_widget_lite_cached_data', $cache );
}
// is_array() detects cached empty searches.
if ( $allow_caching && \is_array( $cache ) ) {
return $cache;
}
$forms = \wpforms()->form->get( '', array( 'fields' => 'ids' ) );
if ( empty( $forms ) || ! \is_array( $forms ) ) {
return array();
}
$result = array();
foreach ( $forms as $form_id ) {
$count = \absint( \get_post_meta( $form_id, 'wpforms_entries_count', true ) );
if ( empty( $count ) && empty( $this->settings['display_forms_list_empty_entries'] ) ) {
continue;
}
$result[ $form_id ] = array(
'form_id' => $form_id,
'count' => $count,
'title' => \get_the_title( $form_id ),
);
}
if ( ! empty( $result ) ) {
// Sort forms by entries count (desc).
\uasort( $result, function ( $a, $b ) {
return ( $a['count'] > $b['count'] ) ? - 1 : 1;
} );
}
if ( $allow_caching ) {
// Transient lifetime in seconds. Defaults to the end of a current day.
$transient_lifetime = $this->settings['transient_lifetime'];
\set_transient( $transient_name, $result, $transient_lifetime );
}
return $result;
}
/**
* Hide dashboard widget.
* Use dashboard screen options to make it visible again.
*
* @since 1.5.0
*/
public function hide_widget() {
if ( ! \is_admin() || ! \is_user_logged_in() ) {
return;
}
if ( ! isset( $_GET['wpforms-nonce'] ) || ! \wp_verify_nonce( \sanitize_key( \wp_unslash( $_GET['wpforms-nonce'] ) ), 'wpforms_hide_dash_widget' ) ) {
return;
}
if ( ! isset( $_GET['wpforms-widget'] ) || 'hide' !== $_GET['wpforms-widget'] ) {
return;
}
$user_id = \get_current_user_id();
$metaboxhidden = \get_user_meta( $user_id, 'metaboxhidden_dashboard', true );
if ( ! \is_array( $metaboxhidden ) ) {
\update_user_meta( $user_id, 'metaboxhidden_dashboard', array( 'wpforms_reports_widget_lite' ) );
}
if ( \is_array( $metaboxhidden ) && ! \in_array( 'wpforms_reports_widget_lite', $metaboxhidden, true ) ) {
$metaboxhidden[] = 'wpforms_reports_widget_lite';
\update_user_meta( $user_id, 'metaboxhidden_dashboard', $metaboxhidden );
}
$redirect_url = \remove_query_arg( array( 'wpforms-widget', 'wpforms-nonce' ) );
\wp_safe_redirect( $redirect_url );
exit();
}
/**
* Clear dashboard widget cached data.
*
* @since 1.5.2
*/
public static function clear_widget_cache() {
delete_transient( 'wpforms_dash_widget_lite_entries_by_form' );
}
}
Admin/Education.php 0000666 00000006267 15214133076 0010241 0 ustar 00 hooks();
}
/**
* Hooks.
*
* @since 1.5.7
*/
public function hooks() {
if ( ! \wpforms_is_admin_page() && ! \wp_doing_ajax() ) {
return;
}
if ( ! \apply_filters( 'wpforms_lite_admin_education', true ) ) {
return;
}
// Admin page slug.
$this->page = str_replace( 'wpforms-', '', filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING ) );
\add_action( 'admin_init', array( $this, 'notice_bar_init' ) );
}
/**
* Notice bar init.
*
* @since 1.5.7
*/
public function notice_bar_init() {
\add_action( 'admin_enqueue_scripts', array( $this, 'enqueues' ) );
\add_action( 'wpforms_admin_header_before', array( $this, 'notice_bar_display' ) );
\add_action( 'wp_ajax_wpforms_notice_bar_dismiss', array( $this, 'notice_bar_ajax_dismiss' ) );
}
/**
* Notice bar display message.
*
* @since 1.5.7
*/
public function notice_bar_display() {
$current_user = \wp_get_current_user();
$dismissed = \get_user_meta( $current_user->ID, 'wpforms_dismissed', true );
if ( ! empty( $dismissed['lite-notice-bar'] ) ) {
return;
}
$msg = sprintf(
/* translators: %s - WPForms.com Upgrade page URL. */
__( 'You’re using WPForms Lite. To unlock more features consider upgrading to Pro .', 'wpforms-lite' ),
\wpforms_admin_upgrade_link( 'notice-bar' )
);
printf(
'
%s
',
\wp_kses(
$msg,
array(
'a' => array(
'href' => array(),
'rel' => array(),
'target' => array(),
),
)
),
\esc_attr__( 'Dismiss this message.', 'wpforms-lite' ),
\esc_attr( $this->page )
);
}
/**
* Ajax handler for dismissing DYK notices.
*
* @since 1.5.7
*/
public function notice_bar_ajax_dismiss() {
// Run a security check.
\check_ajax_referer( 'wpforms-admin', 'nonce' );
// Check for permissions.
if ( ! \wpforms_current_user_can() ) {
\wp_send_json_error(
array(
'error' => \esc_html__( 'You do not have permission to perform this action.', 'wpforms-lite' ),
)
);
}
$current_user = \wp_get_current_user();
$dismissed = \get_user_meta( $current_user->ID, 'wpforms_dismissed', true );
if ( empty( $dismissed ) ) {
$dismissed = array();
}
$dismissed['lite-notice-bar'] = time();
\update_user_meta( $current_user->ID, 'wpforms_dismissed', $dismissed );
\wp_send_json_success();
}
/**
* Load enqueues.
*
* @since 1.5.7
*/
public function enqueues() {
$min = \wpforms_get_min_suffix();
\wp_enqueue_script(
'wpforms-lite-admin-education',
\WPFORMS_PLUGIN_URL . "lite/assets/js/admin/education{$min}.js",
array( 'jquery' ),
\WPFORMS_VERSION,
false
);
}
}
Admin/Builder/Education.php 0000666 00000054461 15214133076 0011626 0 ustar 00 hooks();
}
/**
* Hooks.
*
* @since 1.5.1
*/
public function hooks() {
if ( wp_doing_ajax() ) {
add_action( 'wp_ajax_wpforms_dyk_dismiss', array( $this, 'dyk_ajax_dismiss' ) );
add_action( 'wp_ajax_wpforms_update_field_recaptcha', array( $this, 'recaptcha_field_callback' ) );
}
// Only proceed for the form builder.
if ( ! wpforms_is_admin_page( 'builder' ) ) {
return;
}
add_action( 'wpforms_field_options_after_advanced-options', array( $this, 'field_conditional_logic' ), 10, 2 );
add_filter( 'wpforms_lite_builder_strings', array( $this, 'js_strings' ) );
add_action( 'wpforms_builder_enqueues_before', array( $this, 'enqueues' ) );
add_action( 'wpforms_setup_panel_after', array( $this, 'templates' ) );
add_filter( 'wpforms_builder_fields_buttons', array( $this, 'fields' ), 50 );
add_action( 'wpforms_builder_after_panel_sidebar', array( $this, 'settings' ), 100, 2 );
add_action( 'wpforms_providers_panel_sidebar', array( $this, 'providers' ), 50 );
add_action( 'wpforms_payments_panel_sidebar', array( $this, 'payments' ), 50 );
add_action( 'wpforms_builder_settings_notifications_after', array( $this, 'dyk_notifications' ) );
add_action( 'wpforms_builder_settings_confirmations_after', array( $this, 'dyk_confirmations' ) );
}
/**
* Localize needed strings.
*
* @since 1.5.1
*
* @param array $strings JS strings.
*
* @return array
*/
public function js_strings( $strings ) {
$strings['upgrade'] = [
'pro' => [
'title' => esc_html__( 'is a PRO Feature', 'wpforms-lite' ),
'message' => '' . esc_html__( 'We\'re sorry, the %name% is not available on your plan. Please upgrade to the PRO plan to unlock all these awesome features.', 'wpforms-lite' ) . '
',
'bonus' => '' .
wp_kses(
__( 'Bonus: WPForms Lite users get 50% off regular price, automatically applied at checkout.', 'wpforms-lite' ),
[
'strong' => [],
'span' => [],
]
) .
'
',
'doc' => '' . esc_html__( 'Already purchased?', 'wpforms-lite' ) . ' ',
'button' => esc_html__( 'Upgrade to PRO', 'wpforms-lite' ),
'url' => wpforms_admin_upgrade_link( 'builder-modal', 'upgrade-pro' ),
'modal' => wpforms_get_upgrade_modal_text( 'pro' ),
],
'elite' => [
'title' => esc_html__( 'is an Elite Feature', 'wpforms-lite' ),
'message' => '' . esc_html__( 'We\'re sorry, the %name% is not available on your plan. Please upgrade to the Elite plan to unlock all these awesome features.', 'wpforms-lite' ) . '
',
'bonus' => '' .
wp_kses(
__( 'Bonus: WPForms Lite users get 50% off regular price, automatically applied at checkout.', 'wpforms-lite' ),
[
'strong' => [],
'span' => [],
]
) .
'
',
'doc' => '' . esc_html__( 'Already purchased?', 'wpforms-lite' ) . ' ',
'button' => esc_html__( 'Upgrade to Elite', 'wpforms-lite' ),
'url' => wpforms_admin_upgrade_link( 'builder-modal', 'upgrade-elite' ),
'modal' => wpforms_get_upgrade_modal_text( 'elite' ),
],
];
return $strings;
}
/**
* Load enqueues.
*
* @since 1.5.1
*/
public function enqueues() {
$min = wpforms_get_min_suffix();
wp_enqueue_script(
'wpforms-builder-education',
WPFORMS_PLUGIN_URL . "lite/assets/js/admin/builder-education{$min}.js",
array( 'jquery', 'jquery-confirm' ),
WPFORMS_VERSION,
false
);
}
/**
* Display templates.
*
* @since 1.5.1
*/
public function templates() {
$templates = array(
array(
'name' => esc_html__( 'Request A Quote Form', 'wpforms-lite' ),
'slug' => 'request-quote',
'description' => esc_html__( 'Start collecting leads with this pre-made Request a quote form. You can add and remove fields as needed.', 'wpforms-lite' ),
),
array(
'name' => esc_html__( 'Donation Form', 'wpforms-lite' ),
'slug' => 'donation',
'description' => esc_html__( 'Start collecting donation payments on your website with this ready-made Donation form. You can add and remove fields as needed.', 'wpforms-lite' ),
),
array(
'name' => esc_html__( 'Billing / Order Form', 'wpforms-lite' ),
'slug' => 'order',
'description' => esc_html__( 'Collect payments for product and service orders with this ready-made form template. You can add and remove fields as needed.', 'wpforms-lite' ),
),
);
?>
'fa-google',
'name' => esc_html__( 'reCAPTCHA', 'wpforms-lite' ),
'type' => 'recaptcha',
'order' => 180,
'class' => 'not-draggable',
);
$fields['fancy']['fields'] = array(
array(
'icon' => 'fa-phone',
'name' => esc_html__( 'Phone', 'wpforms-lite' ),
'type' => 'phone',
'order' => '1',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-map-marker',
'name' => esc_html__( 'Address', 'wpforms-lite' ),
'type' => 'address',
'order' => '2',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-calendar-o',
'name' => esc_html__( 'Date / Time', 'wpforms-lite' ),
'type' => 'date-time',
'order' => '3',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-link',
'name' => esc_html__( 'Website / URL', 'wpforms-lite' ),
'type' => 'url',
'order' => '4',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-upload',
'name' => esc_html__( 'File Upload', 'wpforms-lite' ),
'type' => 'file-upload',
'order' => '5',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-lock',
'name' => esc_html__( 'Password', 'wpforms-lite' ),
'type' => 'password',
'order' => '6',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-files-o',
'name' => esc_html__( 'Page Break', 'wpforms-lite' ),
'type' => 'pagebreak',
'order' => '7',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-arrows-h',
'name' => esc_html__( 'Section Divider', 'wpforms-lite' ),
'type' => 'divider',
'order' => '8',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-eye-slash',
'name' => esc_html__( 'Hidden Field', 'wpforms-lite' ),
'type' => 'hidden',
'order' => '9',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-code',
'name' => esc_html__( 'HTML', 'wpforms-lite' ),
'type' => 'html',
'order' => '10',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-star',
'name' => esc_html__( 'Rating', 'wpforms-lite' ),
'type' => 'rating',
'order' => '11',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-question-circle',
'name' => esc_html__( 'Captcha', 'wpforms-lite' ),
'type' => 'captcha',
'order' => '12',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-pencil',
'name' => esc_html__( 'Signature', 'wpforms-lite' ),
'type' => 'signature',
'order' => '13',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-ellipsis-h',
'name' => esc_html__( 'Likert Scale', 'wpforms-lite' ),
'type' => 'likert_scale',
'order' => '14',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-tachometer',
'name' => esc_html__( 'Net Promoter Score', 'wpforms-lite' ),
'type' => 'net_promoter_score',
'order' => '15',
'class' => 'upgrade-modal',
),
);
$fields['payment']['fields'] = array(
array(
'icon' => 'fa-file-o',
'name' => esc_html__( 'Single Item', 'wpforms-lite' ),
'type' => 'payment-single',
'order' => '1',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-list-ul',
'name' => esc_html__( 'Multiple Items', 'wpforms-lite' ),
'type' => 'payment-multiple',
'order' => '2',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-check-square-o',
'name' => esc_html__( 'Checkbox Items', 'wpforms-lite' ),
'type' => 'payment-checkbox',
'order' => '3',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-caret-square-o-down',
'name' => esc_html__( 'Dropdown Items', 'wpforms-lite' ),
'type' => 'payment-select',
'order' => '4',
'class' => 'upgrade-modal',
),
array(
'icon' => 'fa-money',
'name' => esc_html__( 'Total', 'wpforms-lite' ),
'type' => 'payment-total',
'order' => '5',
'class' => 'upgrade-modal',
),
);
return $fields;
}
/**
* Display conditional logic settings section for fields inside the form builder.
*
* @since 1.5.5
*
* @param array $field Field data.
* @param object $instance Builder instance.
*/
public function field_conditional_logic( $field, $instance ) {
// Certain fields don't support conditional logic.
if ( in_array( $field['type'], array( 'pagebreak', 'divider', 'hidden' ), true ) ) {
return;
}
?>
esc_html__( 'Conversational Forms', 'wpforms-lite' ),
'slug' => 'conversational-forms',
'plugin' => 'wpforms-conversational-forms/wpforms-conversational-forms.php',
'plugin_slug' => 'wpforms-conversational-forms',
'license' => 'pro',
),
array(
'name' => esc_html__( 'Surveys and Polls', 'wpforms-lite' ),
'slug' => 'surveys-polls',
'plugin' => 'wpforms-surveys-polls/wpforms-surveys-polls.php',
'plugin_slug' => 'wpforms-surveys-polls',
'license' => 'pro',
),
array(
'name' => esc_html__( 'Form Pages', 'wpforms-lite' ),
'slug' => 'form-pages',
'plugin' => 'wpforms-form-pages/wpforms-form-pages.php',
'plugin_slug' => 'wpforms-form-pages',
'license' => 'pro',
),
array(
'name' => esc_html__( 'Form Locker', 'wpforms-lite' ),
'slug' => 'form-locker',
'plugin' => 'wpforms-form-locker/wpforms-form-locker.php',
'plugin_slug' => 'wpforms-form-locker',
'license' => 'pro',
),
array(
'name' => esc_html__( 'Form Abandonment', 'wpforms-lite' ),
'slug' => 'form-abandonment',
'plugin' => 'wpforms-form-abandonment/wpforms-form-abandonment.php',
'plugin_slug' => 'wpforms-form-abandonment',
'license' => 'pro',
),
array(
'name' => esc_html__( 'Post Submissions', 'wpforms-lite' ),
'slug' => 'post-submissions',
'plugin' => 'wpforms-post-submissions/wpforms-post-submissions.php',
'plugin_slug' => 'wpforms-post-submissions',
'license' => 'pro',
),
);
foreach ( $settings as $setting ) {
/* translators: %s - addon name. */
$modal_name = sprintf( esc_html__( '%s addon', 'wpforms' ), $setting['name'] );
printf(
'';
}
}
/**
* Display providers.
*
* @since 1.5.1
*/
public function providers() {
$providers = wpforms_get_providers_all();
foreach ( $providers as $provider ) {
$this->display_single_addon_btn( $provider );
}
}
/**
* Display payments.
*
* @since 1.5.1
*/
public function payments() {
$payments = array(
array(
'name' => esc_html__( 'PayPal Standard', 'wpforms-lite' ),
'slug' => 'paypal_standard',
'img' => 'addon-icon-paypal.png',
'license' => 'pro',
),
array(
'name' => esc_html__( 'Stripe', 'wpforms-lite' ),
'slug' => 'stripe',
'img' => 'addon-icon-stripe.png',
'license' => 'pro',
),
);
foreach ( $payments as $payment ) {
$this->display_single_addon_btn( $payment );
}
}
/**
* Display a single addon button in a builder.
*
* @since 1.5.7
*
* @param array $addon Required keys: name, slug, img.
*/
protected function display_single_addon_btn( $addon ) {
if ( ! isset( $addon['name'], $addon['slug'], $addon['img'], $addon['license'] ) ) {
return;
}
/* translators: %s - addon name. */
$modal_name = sprintf( esc_html__( '%s addon', 'wpforms-lite' ), $addon['name'] );
?>
form->get( $form_id, array( 'content_only' => true ) );
if ( empty( $form_data ) ) {
wp_send_json_error( esc_html__( 'Something wrong. Please, try again later.', 'wpforms-lite' ) );
}
// Check that recaptcha is configured in the settings.
$site_key = wpforms_setting( 'recaptcha-site-key' );
$secret_key = wpforms_setting( 'recaptcha-secret-key' );
$recaptcha_name = $this->get_recaptcha_name();
if ( empty( $recaptcha_name ) ) {
wp_send_json_error( esc_html__( 'Something wrong. Please, try again later.', 'wpforms-lite' ) );
}
// Prepare a result array.
$data = array(
'current' => false,
'cases' => array(
'not_configured' => array(
'title' => esc_html__( 'Heads up!', 'wpforms-lite' ),
'content' => sprintf(
wp_kses( /* translators: %1$s - reCaptcha settings page URL; %2$s - WPForms.com doc URL. */
__( 'Google reCAPTCHA isn\'t configured yet. Please complete the setup in your WPForms Settings , and check out our step by step tutorial for full details.', 'wpforms-lite' ),
array(
'a' => array(
'href' => true,
'rel' => true,
'target' => true,
),
)
),
esc_url( admin_url( 'admin.php?page=wpforms-settings&view=recaptcha' ) ),
'https://wpforms.com/docs/setup-captcha-wpforms/'
),
),
'configured_not_enabled' => array(
'title' => false,
/* translators: %s - reCAPTCHA type. */
'content' => sprintf( esc_html__( '%s has been enabled for this form. Don\'t forget to save your form!', 'wpforms-lite' ), $recaptcha_name ),
),
'configured_enabled' => array(
'title' => false,
'content' => esc_html__( 'Are you sure you want to disable Google reCAPTCHA for this form?', 'wpforms-lite' ),
'cancel' => true,
),
),
);
if ( ! $site_key || ! $secret_key ) {
// If reCAPTCHA is not configured in the WPForms plugin settings.
$data['current'] = 'not_configured';
} elseif ( ! isset( $form_data['settings']['recaptcha'] ) || '1' !== $form_data['settings']['recaptcha'] ) {
// If reCAPTCHA is configured in WPForms plugin settings, but wasn't set in form settings.
$data['current'] = 'configured_not_enabled';
} else {
// If reCAPTCHA is configured in WPForms plugin and form settings.
$data['current'] = 'configured_enabled';
}
wp_send_json_success( $data );
}
/**
* Retrive a reCAPTCHA type name.
*
* @since 1.5.8
*
* @return string
*/
public function get_recaptcha_name() {
$recaptcha_type = wpforms_setting( 'recaptcha-type', 'v2' );
// Get a recaptcha name.
switch ( $recaptcha_type ) {
case 'v2':
$recaptcha_name = esc_html__( 'Google Checkbox v2 reCAPTCHA', 'wpforms-lite' );
break;
case 'invisible':
$recaptcha_name = esc_html__( 'Google Invisible v2 reCAPTCHA', 'wpforms-lite' );
break;
case 'v3':
$recaptcha_name = esc_html__( 'Google v3 reCAPTCHA', 'wpforms-lite' );
break;
default:
$recaptcha_name = '';
break;
}
return $recaptcha_name;
}
/**
* "Did You Know?" Notifications.
*
* @since 1.5.8
*/
public function dyk_notifications() {
$this->dyk_display(
'notifications',
array(
'desc' => esc_html__( 'You can have multiple notifications with conditional logic.', 'wpforms-lite' ),
)
);
}
/**
* "Did You Know?" Notifications.
*
* @since 1.5.8
*/
public function dyk_confirmations() {
$this->dyk_display(
'confirmations',
array(
'desc' => esc_html__( 'You can have multiple confirmations with conditional logic.', 'wpforms-lite' ),
)
);
}
/**
* "Did You Know?" display message.
*
* @since 1.5.8
*
* @param string $section Form builder section/area (slug).
* @param array $settings Notice settings array.
*/
public function dyk_display( $section, $settings ) {
$current_user = wp_get_current_user();
$dismissed = get_user_meta( $current_user->ID, 'wpforms_dismissed', true );
// Check if not dismissed.
if ( ! empty( $dismissed[ 'dyk-builder-' . $section ] ) ) {
return;
}
$translations = array(
'upgrade_to_pro' => __( 'Upgrade to Pro.', 'wpforms' ),
'dismiss_title' => __( 'Dismiss this message.', 'wpforms' ),
'did_you_know' => __( 'Did You Know?', 'wpforms' ),
'learn_more' => __( 'Learn More', 'wpforms' ),
);
$learn_more = ( ! empty( $settings['more'] ) ) ? '' . esc_html( $translations['learn_more'] ) . ' ' : '';
printf(
'',
esc_html( $translations['did_you_know'] ),
esc_html( $settings['desc'] ),
$learn_more, // phpcs:ignore
esc_url( wpforms_admin_upgrade_link( 'Form Builder DYK', ucfirst( $section ) ) ),
esc_html( $translations['upgrade_to_pro'] ),
esc_attr( $translations['dismiss_title'] ),
esc_attr( $section )
);
}
/**
* Ajax handler for dismissing DYK notices.
*
* @since 1.5.8
*/
public function dyk_ajax_dismiss() {
// Run a security check.
check_ajax_referer( 'wpforms-builder', 'nonce' );
// Check for permissions.
if ( ! wpforms_current_user_can() ) {
wp_send_json_error(
array(
'error' => esc_html__( 'You do not have permission to perform this action.', 'wpforms-lite' ),
)
);
}
$current_user = wp_get_current_user();
$dismissed = get_user_meta( $current_user->ID, 'wpforms_dismissed', true );
if ( empty( $dismissed ) ) {
$dismissed = array();
}
$section = ! empty( $_GET['section'] ) ? sanitize_key( wp_unslash( $_GET['section'] ) ) : '';
$dismissed[ 'dyk-builder-' . $section ] = time();
update_user_meta( $current_user->ID, 'wpforms_dismissed', $dismissed );
wp_send_json_success();
}
}
Admin/Settings/Education.php 0000666 00000011327 15214133076 0012032 0 ustar 00 hooks();
}
/**
* Hooks.
*
* @since 1.5.1
*/
public function hooks() {
// Only proceed for the Settings > Integrations tab.
if ( ! \wpforms_is_admin_page( 'settings' ) ) {
return;
}
// Integrations related hooks.
if ( \wpforms_is_admin_page( 'settings', 'integrations' ) ) {
\add_filter( 'wpforms_admin_strings', array( $this, 'js_strings' ) );
\add_action( 'admin_enqueue_scripts', array( $this, 'enqueues' ) );
\add_action( 'wpforms_settings_providers', array( $this, 'providers' ), 10000, 1 );
}
}
/**
* Localize needed strings.
*
* @since 1.5.5
*
* @param array $strings JS strings.
*
* @return array
*/
public function js_strings( $strings ) {
$strings['upgrade'] = [
'pro' => [
'title' => esc_html__( 'is a PRO Feature', 'wpforms-lite' ),
'message' => '' . esc_html__( 'We\'re sorry, the %name% is not available on your plan. Please upgrade to the PRO plan to unlock all these awesome features.', 'wpforms-lite' ) . '
',
'bonus' => '' .
wp_kses(
__( 'Bonus: WPForms Lite users get 50% off regular price, automatically applied at checkout.', 'wpforms-lite' ),
[
'strong' => [],
'span' => [],
]
) .
'
',
'doc' => '' . esc_html__( 'Already purchased?', 'wpforms-lite' ) . ' ',
'button' => esc_html__( 'Upgrade to PRO', 'wpforms-lite' ),
'url' => wpforms_admin_upgrade_link( 'settings-modal', 'upgrade-pro' ),
'modal' => wpforms_get_upgrade_modal_text( 'pro' ),
],
'elite' => [
'title' => esc_html__( 'is an Elite Feature', 'wpforms-lite' ),
'message' => '' . esc_html__( 'We\'re sorry, the %name% is not available on your plan. Please upgrade to the Elite plan to unlock all these awesome features.', 'wpforms-lite' ) . '
',
'bonus' => '' .
wp_kses(
__( 'Bonus: WPForms Lite users get 50% off regular price, automatically applied at checkout.', 'wpforms-lite' ),
[
'strong' => [],
'span' => [],
]
) .
'
',
'doc' => '' . esc_html__( 'Already purchased?', 'wpforms-lite' ) . ' ',
'button' => esc_html__( 'Upgrade to Elite', 'wpforms-lite' ),
'url' => wpforms_admin_upgrade_link( 'settings-modal', 'upgrade-elite' ),
'modal' => wpforms_get_upgrade_modal_text( 'elite' ),
],
];
return $strings;
}
/**
* Load enqueues.
*
* @since 1.5.5
*/
public function enqueues() {
$min = \wpforms_get_min_suffix();
\wp_enqueue_script(
'wpforms-settings-education',
\WPFORMS_PLUGIN_URL . "lite/assets/js/admin/settings-education{$min}.js",
array( 'jquery', 'jquery-confirm' ),
\WPFORMS_VERSION,
false
);
}
/**
* Display providers.
*
* @since 1.5.5
*/
public function providers() {
$providers = wpforms_get_providers_all();
foreach ( $providers as $provider ) {
/* translators: %s - addon name*/
$modal_name = sprintf( \__( '%s addon', 'wpforms' ), $provider['name'] );
/* translators: %s - addon name*/
$descr = sprintf( \__( 'Integrate %s with WPForms', 'wpforms' ), $provider['name'] );
printf(
'
',
\esc_attr( $provider['slug'] ),
\esc_attr( $modal_name ),
isset( $provider['url'] ) ? \esc_attr( $provider['url'] ) : '',
\esc_attr( $provider['license'] ),
' ',
\esc_html( $provider['name'] ),
\esc_html( $descr )
);
}
}
}
Admin/Settings/Access.php 0000666 00000014242 15214133076 0011317 0 ustar 00 hooks();
}
/**
* Hooks.
*
* @since 1.5.8
*/
public function hooks() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueues' ) );
add_filter( 'wpforms_settings_tabs', array( $this, 'add_tab' ) );
add_filter( 'wpforms_settings_defaults', array( $this, 'add_section' ) );
}
/**
* Enqueues.
*
* @since 1.5.8
*/
public function enqueues() {
if ( ! wpforms_is_admin_page( 'settings', self::SLUG ) ) {
return;
}
// Lity.
wp_enqueue_style(
'wpforms-lity',
WPFORMS_PLUGIN_URL . 'assets/css/lity.min.css',
null,
'3.0.0'
);
wp_enqueue_script(
'wpforms-lity',
WPFORMS_PLUGIN_URL . 'assets/js/lity.min.js',
array( 'jquery' ),
'3.0.0',
true
);
}
/**
* Add Access tab.
*
* @since 1.5.8
*
* @param array $tabs Array of tabs.
*
* @return array Array of tabs.
*/
public function add_tab( $tabs ) {
$tab = array(
self::SLUG => array(
'name' => esc_html__( 'Access', 'wpforms-lite' ),
'form' => false,
'submit' => false,
),
);
return wpforms_list_insert_after( $tabs, 'integrations', $tab );
}
/**
* Add Access settings section.
*
* @since 1.5.8
*
* @param array $settings Settings sections.
*
* @return array
*/
public function add_section( $settings ) {
$section_rows = array(
'heading',
'screenshots',
'caps',
'upgrade_to_pro',
);
foreach ( $section_rows as $section_row ) {
$settings[ self::SLUG ][ self::SLUG . '-' . $section_row ] = array(
'id' => self::SLUG . '-' . $section_row,
'content' => method_exists( $this, 'output_section_row_' . $section_row ) ? $this->{ 'output_section_row_' . $section_row }() : '',
'type' => 'content',
'no_label' => true,
'class' => array( $section_row ),
);
}
return $settings;
}
/**
* Generate and output section "Heading" row HTML.
*
* @since 1.5.8
*/
public function output_section_row_heading() {
return sprintf(
'%1$s %4$s
%5$s
',
esc_html__( 'Access Controls', 'wpforms-lite' ),
esc_url( WPFORMS_PLUGIN_URL . 'assets/images/lite-settings-access/pro-plus.svg' ),
esc_attr__( 'Pro+', 'wpforms-lite' ),
esc_html__( 'Access controls allows you to manage and customize access to WPForms functionality.', 'wpforms-lite' ),
esc_html__( 'You can easily grant or restrict access using the simple built-in controls, or use our official integrations with Members and User Role Editor plugins.', 'wpforms-lite' )
);
}
/**
* Generate and output section "Screenshots" row HTML.
*
* @since 1.5.8
*/
public function output_section_row_screenshots() {
$format = '
%5$s
';
$images_url = WPFORMS_PLUGIN_URL . 'assets/images/lite-settings-access/';
$content = sprintf(
$format,
esc_url( $images_url . 'thumbnail-access-controls.png' ),
esc_url( $images_url . 'thumbnail-access-controls@2x.png' ),
esc_url( $images_url . 'screenshot-access-controls.png' ),
esc_url( $images_url . 'screenshot-access-controls@2x.png' ),
esc_html__( 'Simple Built-in Controls', 'wpforms-lite' ),
esc_attr( esc_html__( 'Simple Built-in Controls', 'wpforms-lite' ) )
);
$content .= sprintf(
$format,
esc_url( $images_url . 'thumbnail-members.png' ),
esc_url( $images_url . 'thumbnail-members@2x.png' ),
esc_url( $images_url . 'screenshot-members.png' ),
esc_url( $images_url . 'screenshot-members@2x.png' ),
esc_html__( 'Members Integration', 'wpforms-lite' ),
esc_attr( esc_html__( 'Members Integration', 'wpforms-lite' ) )
);
$content .= sprintf(
$format,
esc_url( $images_url . 'thumbnail-user-role-editor.png' ),
esc_url( $images_url . 'thumbnail-user-role-editor@2x.png' ),
esc_url( $images_url . 'screenshot-user-role-editor.png' ),
esc_url( $images_url . 'screenshot-user-role-editor@2x.png' ),
esc_html__( 'User Role Editor Integration', 'wpforms-lite' ),
esc_attr( esc_html__( 'User Role Editor Integration', 'wpforms-lite' ) )
);
return $content;
}
/**
* Generate and output section "Capabilities" row HTML.
*
* @since 1.5.8
*/
public function output_section_row_caps() {
$caps = array(
array(
esc_html__( 'Create Forms', 'wpforms-lite' ),
esc_html__( 'Edit Forms', 'wpforms-lite' ),
esc_html__( 'Edit Others Forms', 'wpforms-lite' ),
esc_html__( 'View Forms', 'wpforms-lite' ),
esc_html__( 'View Others Forms', 'wpforms-lite' ),
),
array(
esc_html__( 'Delete Forms', 'wpforms-lite' ),
esc_html__( 'Delete Others Forms', 'wpforms-lite' ),
esc_html__( 'View Forms Entries', 'wpforms-lite' ),
esc_html__( 'View Others Forms Entries', 'wpforms-lite' ),
),
array(
esc_html__( 'Edit Forms Entries', 'wpforms-lite' ),
esc_html__( 'Edit Others Forms Entries', 'wpforms-lite' ),
esc_html__( 'Delete Forms Entries', 'wpforms-lite' ),
esc_html__( 'Delete Others Forms Entries', 'wpforms-lite' ),
),
);
$content = '' . esc_html__( 'Custom access to the following capabilities…', 'wpforms-lite' ) . '
';
foreach ( $caps as $column ) {
$content .= '';
foreach ( $column as $cap ) {
$content .= '' . $cap . ' ';
}
$content .= ' ';
}
return $content;
}
/**
* Generate and output section "Upgrade to Pro" row HTML.
*
* @since 1.5.8
*/
public function output_section_row_upgrade_to_pro() {
$content = sprintf(
'%2$s ',
esc_url( 'https://wpforms.com/lite-upgrade/?discount=LITEUPGRADE&utm_source=WordPress&utm_medium=settings-license&utm_campaign=liteplugin' ),
esc_html__( 'Upgrade to WPForms Now', 'wpforms-lite' )
);
return $content;
}
}
Reports/EntriesCount.php 0000666 00000002124 15214133076 0011342 0 ustar 00 form->get( '', array( 'fields' => 'ids' ) );
if ( empty( $forms ) || ! \is_array( $forms ) ) {
return array();
}
$result = array();
foreach ( $forms as $form_id ) {
$count = \absint( \get_post_meta( $form_id, 'wpforms_entries_count', true ) );
if ( empty( $count ) ) {
continue;
}
$result[ $form_id ] = array(
'form_id' => $form_id,
'count' => $count,
'title' => \get_the_title( $form_id ),
);
}
if ( ! empty( $result ) ) {
// Sort forms by entries count (desc).
\uasort(
$result,
function ( $a, $b ) {
return ( $a['count'] > $b['count'] ) ? -1 : 1;
}
);
}
return $result;
}
}