dvadf
File manager - Edit - /home/theblueo/tv/wp-includes/pomo/lib/Admin.tar
Back
Builder/Education.php 0000666 00000054461 15214176127 0010602 0 ustar 00 <?php namespace WPForms\Lite\Admin\Builder; /** * Form Builder changes and enhancements to educate Lite users on what is available in WPForms Pro. * * @since 1.5.1 */ class Education { /** * Constructor. * * @since 1.5.1 */ public function __construct() { $this->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' => '<p>' . 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' ) . '</p>', 'bonus' => '<p>' . wp_kses( __( '<strong>Bonus:</strong> WPForms Lite users get <span>50% off</span> regular price, automatically applied at checkout.', 'wpforms-lite' ), [ 'strong' => [], 'span' => [], ] ) . '</p>', 'doc' => '<a href="https://wpforms.com/docs/upgrade-wpforms-lite-paid-license/?utm_source=WordPress&utm_medium=link&utm_campaign=liteplugin&utm_content=upgrade-pro" target="_blank" rel="noopener noreferrer" class="already-purchased">' . esc_html__( 'Already purchased?', 'wpforms-lite' ) . '</a>', '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' => '<p>' . 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' ) . '</p>', 'bonus' => '<p>' . wp_kses( __( '<strong>Bonus:</strong> WPForms Lite users get <span>50% off</span> regular price, automatically applied at checkout.', 'wpforms-lite' ), [ 'strong' => [], 'span' => [], ] ) . '</p>', 'doc' => '<a href="https://wpforms.com/docs/upgrade-wpforms-lite-paid-license/?utm_source=WordPress&utm_medium=link&utm_campaign=liteplugin&utm_content=upgrade-elite" target="_blank" rel="noopener noreferrer" class="already-purchased">' . esc_html__( 'Already purchased?', 'wpforms-lite' ) . '</a>', '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' ), ), ); ?> <div class="wpforms-setup-title"> <?php esc_html_e( 'Unlock Pre-Made Form Templates', 'wpforms-lite' ); ?> <a href="<?php echo esc_url( wpforms_admin_upgrade_link( 'builder-templates' ) ); ?>" target="_blank" rel="noopener noreferrer" class="btn-green wpforms-upgrade-link wpforms-upgrade-modal" style="text-transform: uppercase;font-size: 13px;font-weight: 700;padding: 5px 10px;vertical-align: text-bottom;"> <?php esc_html_e( 'Upgrade', 'wpforms-lite' ); ?> </a> </div> <p class="wpforms-setup-desc"> <?php esc_html_e( 'While WPForms Lite allows you to create any type of form, you can speed up the process by unlocking our other pre-built form templates among other features, so you never have to start from scratch again...', 'wpforms-lite' ); ?> </p> <div class="wpforms-setup-templates wpforms-clear" style="opacity:0.5;"> <?php $x = 0; foreach ( $templates as $template ) { $class = 0 === $x % 3 ? 'first ' : ''; ?> <div class="wpforms-template upgrade-modal <?php echo sanitize_html_class( $class ); ?>" id="wpforms-template-<?php echo sanitize_html_class( $template['slug'] ); ?>"> <div class="wpforms-template-name wpforms-clear"> <?php echo esc_html( $template['name'] ); ?> </div> <div class="wpforms-template-details"> <p class="desc"><?php echo esc_html( $template['description'] ); ?></p> </div> </div> <?php $x ++; } ?> </div> <?php } /** * Display fields. * * @since 1.5.1 * * @param array $fields Form fields. * * @return array */ public function fields( $fields ) { // Add reCAPTCHA field to Standard group. $fields['standard']['fields'][] = array( 'icon' => '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; } ?> <div class="wpforms-field-option-group"> <a href="#" class="wpforms-field-option-group-toggle upgrade-modal" data-name="<?php esc_attr_e( 'Conditional Logic', 'wpforms-lite' ); ?>"> <?php esc_html_e( 'Conditionals', 'wpforms-lite' ); ?> <i class="fa fa-angle-right"></i> </a> </div> <?php } /** * Display settings panels. * * @since 1.5.1 * * @param object $form Current form. * @param string $slug Panel slug. */ public function settings( $form, $slug ) { if ( 'settings' !== $slug ) { return; } $settings = array( array( 'name' => 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( '<a href="#" class="wpforms-panel-sidebar-section wpforms-panel-sidebar-section-%s upgrade-modal" data-name="%s" data-license="%s">', esc_attr( $setting['slug'] ), esc_attr( $modal_name ), esc_attr( $setting['license'] ) ); echo esc_html( $setting['name'] ); echo '<i class="fa fa-angle-right wpforms-toggle-arrow"></i>'; echo '</a>'; } } /** * 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'] ); ?> <a href="#" class="wpforms-panel-sidebar-section icon wpforms-panel-sidebar-section-<?php echo esc_attr( $addon['slug'] ); ?> upgrade-modal" data-name="<?php echo esc_attr( $modal_name ); ?>" data-license="<?php echo esc_attr( $addon['license'] ); ?>"> <img src="<?php echo esc_attr( WPFORMS_PLUGIN_URL . 'assets/images/' . $addon['img'] ); ?>" alt=""> <?php echo esc_html( $addon['name'] ); ?> <i class="fa fa-angle-right wpforms-toggle-arrow"></i> </a> <?php } /** * Targeting on `reCAPTCHA` field button in the builder. * * TODO: Lite and Pro Education duplicate this code. * * @since 1.5.7 */ public function recaptcha_field_callback() { // Run a security check. check_ajax_referer( 'wpforms-builder', 'nonce' ); // Check for permissions. if ( ! wpforms_current_user_can() ) { die( esc_html__( 'You do not have permission.', 'wpforms-lite' ) ); } // Check for form ID. if ( ! isset( $_POST['id'] ) || empty( $_POST['id'] ) ) { die( esc_html__( 'No form ID found.', 'wpforms-lite' ) ); } // Get an actual form data. $form_id = absint( $_POST['id'] ); $form_data = wpforms()->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 <a href="%1$s" target="_blank">WPForms Settings</a>, and check out our <a href="%2$s" target="_blank" rel="noopener noreferrer">step by step tutorial</a> 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'] ) ) ? '<a href="' . esc_url( $settings['more'] ) . '" class="learn-more">' . esc_html( $translations['learn_more'] ) . '</a>' : ''; printf( '<section class="wpforms-dyk"> <div class="wpforms-dyk-fbox"> <div class="wpforms-dyk-message"><b>%s</b><br>%s</div> <div class="wpforms-dyk-buttons"> %s <a href="%s" target="_blank" rel="noopener noreferrer" class="wpforms-btn wpforms-btn-md wpforms-btn-light-grey">%s</a> <button type="button" class="dismiss" title="%s" data-section="%s"/> </div> </div> </section>', 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(); } } Connect.php 0000666 00000017322 15214176127 0006665 0 ustar 00 <?php namespace WPForms\Lite\Admin; use WP_Error; use WPForms\Helpers\PluginSilentUpgrader; /** * WPForms Connect. * * WPForms Connect is our service that makes it easy for non-techy users to * upgrade to WPForms Pro without having to manually install WPForms Pro plugin. * * @since 1.5.5 */ class Connect { /** * Constructor. * * @since 1.5.5 */ public function __construct() { $this->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 ); } ); } } Settings/Education.php 0000666 00000011327 15214176127 0011006 0 ustar 00 <?php namespace WPForms\Lite\Admin\Settings; /** * Settings changes and enhancements to educate Lite users on what is * available in WPForms Pro. * * @since 1.5.5 */ class Education { /** * Constructor. * * @since 1.5.1 */ public function __construct() { $this->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' => '<p>' . 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' ) . '</p>', 'bonus' => '<p>' . wp_kses( __( '<strong>Bonus:</strong> WPForms Lite users get <span>50% off</span> regular price, automatically applied at checkout.', 'wpforms-lite' ), [ 'strong' => [], 'span' => [], ] ) . '</p>', 'doc' => '<a href="https://wpforms.com/docs/upgrade-wpforms-lite-paid-license/?utm_source=WordPress&utm_medium=link&utm_campaign=liteplugin&utm_content=upgrade-pro" target="_blank" rel="noopener noreferrer" class="already-purchased">' . esc_html__( 'Already purchased?', 'wpforms-lite' ) . '</a>', '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' => '<p>' . 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' ) . '</p>', 'bonus' => '<p>' . wp_kses( __( '<strong>Bonus:</strong> WPForms Lite users get <span>50% off</span> regular price, automatically applied at checkout.', 'wpforms-lite' ), [ 'strong' => [], 'span' => [], ] ) . '</p>', 'doc' => '<a href="https://wpforms.com/docs/upgrade-wpforms-lite-paid-license/?utm_source=WordPress&utm_medium=link&utm_campaign=liteplugin&utm_content=upgrade-elite" target="_blank" rel="noopener noreferrer" class="already-purchased">' . esc_html__( 'Already purchased?', 'wpforms-lite' ) . '</a>', '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( '<div id="wpforms-integration-%1$s" class="wpforms-settings-provider wpforms-clear focus-out education-modal" data-name="%2$s" data-action="upgrade" data-url="%3$s" data-license="%4$s"> <div class="wpforms-settings-provider-header wpforms-clear"> <div class="wpforms-settings-provider-logo "> <i class="fa fa-chevron-right"></i> %5$s </div> <div class="wpforms-settings-provider-info"> <h3>%6$s</h3> <p>%7$s</p> </div> </div> </div>', \esc_attr( $provider['slug'] ), \esc_attr( $modal_name ), isset( $provider['url'] ) ? \esc_attr( $provider['url'] ) : '', \esc_attr( $provider['license'] ), '<img src="' . \esc_attr( WPFORMS_PLUGIN_URL ) . 'assets/images/' . \esc_attr( $provider['img'] ) . '">', \esc_html( $provider['name'] ), \esc_html( $descr ) ); } } } Settings/Access.php 0000666 00000014242 15214176127 0010273 0 ustar 00 <?php namespace WPForms\Lite\Admin\Settings; /** * Settings Access tab. * * @since 1.5.8 */ class Access { /** * View slug. * * @since 1.5.8 * * @var string */ const SLUG = 'access'; /** * Constructor. * * @since 1.5.8 */ public function __construct() { $this->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( '<h4>%1$s<img src="%2$s" alt="%3$s"></h4><p>%4$s</p><p>%5$s</p>', 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 = '<div class="cont"> <img src="%1$s" srcset="%2$s 2x" alt="%6$s"/> <a href="%3$s" class="hover" data-lity data-lity-srcset="%4$s 2x" data-lity-desc="%6$s"></a> <span>%5$s</span> </div>'; $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 = '<p>' . esc_html__( 'Custom access to the following capabilities…', 'wpforms-lite' ) . '</p>'; foreach ( $caps as $column ) { $content .= '<ul>'; foreach ( $column as $cap ) { $content .= '<li>' . $cap . '</li>'; } $content .= '</ul>'; } 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( '<a href="%1$s" target="_blank" rel="noopener noreferrer" class="wpforms-upgrade-modal wpforms-btn wpforms-btn-lg wpforms-btn-orange">%2$s</a>', 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; } } DashboardWidget.php 0000666 00000032767 15214176127 0010341 0 ustar 00 <?php namespace WPForms\Lite\Admin; /** * Dashboard Widget shows a chart and the form entries stats in WP Dashboard. * * @since 1.5.0 */ class DashboardWidget { /** * Widget settings. * * @since 1.5.0 * * @var array */ public $settings; /** * Constructor. * * @since 1.5.0 */ public function __construct() { add_action( 'admin_init', array( $this, 'init' ) ); } /** * Init class. * * @since 1.5.5 */ public function init() { // This widget should be displayed for certain high-level users only. if ( ! wpforms_current_user_can() ) { return; } if ( ! apply_filters( 'wpforms_admin_dashboardwidget', true ) ) { return; } $this->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' ) . '<span class="dashicons dashicons-arrow-down"></span>', 'show_less_html' => \esc_html__( 'Show Less', 'wpforms-lite' ) . '<span class="dashicons dashicons-arrow-up"></span>', '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 '<div class="wpforms-dash-widget wpforms-lite">'; 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 '</div><!-- .wpforms-dash-widget -->'; } /** * 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'; ?> <div class="wpforms-dash-widget-block wpforms-dash-widget-block-no-forms"> <img class="wpforms-dash-widget-block-sullie-logo" src="<?php echo \esc_url( WPFORMS_PLUGIN_URL . 'assets/images/sullie.png' ); ?>" alt="<?php \esc_attr_e( 'Sullie the WPForms mascot', 'wpforms-lite' ); ?>"> <h2><?php \esc_html_e( 'Create Your First Form to Start Collecting Leads', 'wpforms-lite' ); ?></h2> <p><?php \esc_html_e( 'You can use WPForms to build contact forms, surveys, payment forms, and more with just a few clicks.', 'wpforms-lite' ); ?></p> <a href="<?php echo \esc_url( $create_form_url ); ?>" class="button button-primary"> <?php \esc_html_e( 'Create Your Form', 'wpforms-lite' ); ?> </a> <a href="<?php echo \esc_url( $learn_more_url ); ?>" class="button" target="_blank" rel="noopener noreferrer"> <?php \esc_html_e( 'Learn More', 'wpforms-lite' ); ?> </a> </div> <?php } /** * Widget content HTML. * * @since 1.5.0 */ public function widget_content_html() { ?> <div class="wpforms-dash-widget-chart-block-container"> <div class="wpforms-dash-widget-block"> <h3 id="wpforms-dash-widget-chart-title"> <?php \esc_html_e( 'Total Entries', 'wpforms-lite' ); ?> </h3> <select class="wpforms-dash-widget-select-timespan" style="display: none;"> <option><?php \esc_html_e( 'Last 7 days', 'wpforms-lite' ); ?></option> </select> </div> <div class="wpforms-dash-widget-block wpforms-dash-widget-chart-block"> <canvas id="wpforms-dash-widget-chart" width="400" height="300"></canvas> </div> <div class="wpforms-dash-widget-block-upgrade"> <div class="wpforms-dash-widget-modal"> <h2><?php \esc_html_e( 'View all Form Entries inside WordPress Dashboard', 'wpforms-lite' ); ?></h2> <p><?php \esc_html_e( 'Form entries reports are not available.', 'wpforms-lite' ); ?></p> <p><?php \esc_html_e( 'Form entries are not stored in Lite.', 'wpforms-lite' ); ?></p> <p><?php \esc_html_e( 'Upgrade to Pro and get access to the reports.', 'wpforms-lite' ); ?></p> <p> <a href="<?php echo \esc_url( wpforms_admin_upgrade_link( 'dashboard-widget' ) ); ?>" class="wpforms-dash-widget-upgrade-btn" target="_blank" rel="noopener noreferrer"> <?php \esc_html_e( 'Upgrade to WPForms Pro', 'wpforms-lite' ); ?> </a> </p> <!-- <p> <a href="https://wpforms.com" class="wpforms-dash-widget-site-link"> <?php \esc_html_e( 'Go to WPForms.com', 'wpforms-lite' ); ?> </a> </p> --> </div> </div> </div> <div class="wpforms-dash-widget-block"> <h3><?php \esc_html_e( 'Total Entries by Form', 'wpforms-lite' ); ?></h3> </div> <div id="wpforms-dash-widget-forms-list-block" class="wpforms-dash-widget-block wpforms-dash-widget-forms-list-block"> <?php $this->forms_list_block(); ?> </div> <?php } /** * Forms list block. * * @since 1.5.0 */ public function forms_list_block() { $forms = $this->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() { ?> <p class="wpforms-error wpforms-error-no-data-forms-list"> <?php \esc_html_e( 'No entries were submitted yet.', 'wpforms-lite' ); ?> </p> <?php } /** * Forms list block HTML. * * @since 1.5.0 * * @param array $forms Forms to display in the list. */ public function forms_list_block_html( $forms ) { // Number of forms to display in the forms list before "Show More" button appears. $show_forms = $this->settings['forms_list_number_to_display']; ?> <table id="wpforms-dash-widget-forms-list-table" cellspacing="0"> <?php foreach ( \array_values( $forms ) as $key => $form ) : ?> <tr <?php echo $key >= $show_forms ? 'class="wpforms-dash-widget-forms-list-hidden-el"' : ''; ?> data-form-id="<?php echo \absint( $form['form_id'] ); ?>"> <td><span class="wpforms-dash-widget-form-title"><?php echo \esc_html( $form['title'] ); ?></span></td> <td><?php echo \absint( $form['count'] ); ?></td> </tr> <?php endforeach; ?> </table> <?php if ( \count( $forms ) > $show_forms ) : ?> <button type="button" id="wpforms-dash-widget-forms-more" class="wpforms-dash-widget-forms-more" title="<?php \esc_html_e( 'Show all forms', 'wpforms-lite' ); ?>"> <?php \esc_html_e( 'Show More', 'wpforms-lite' ); ?> <span class="dashicons dashicons-arrow-down"></span> </button> <?php endif; ?> <?php } /** * Recommended plugin block HTML. * * @since 1.5.0 */ public function recommended_plugin_block_html() { $install_mi_url = \wp_nonce_url( \self_admin_url( 'update.php?action=install-plugin&plugin=google-analytics-for-wordpress' ), 'install-plugin_google-analytics-for-wordpress' ); ?> <div class="wpforms-dash-widget-recommended-plugin-block"> <p><?php \esc_html_e( 'Recommended Plugin:', 'wpforms-lite' ); ?> <b><?php \esc_html_e( 'MonsterInsights', 'wpforms-lite' ); ?></b> - <a href="<?php echo \esc_url( $install_mi_url ); ?>"><?php \esc_html_e( 'Install', 'wpforms-lite' ); ?></a> | <a href="https://www.monsterinsights.com/?utm_source=wpformsplugin&utm_medium=link&utm_campaign=wpformsdashboardwidget"><?php \esc_html_e( 'Learn More', 'wpforms-lite' ); ?></a></p> </div> <?php } /** * Get entries count grouped by form. * Main point of entry to fetch form entry count data from DB. * Cache the result. * * @since 1.5.0 * * @return array */ public function get_entries_count_by_form() { // Allow results caching to reduce DB load. $allow_caching = $this->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' ); } } Education.php 0000666 00000006267 15214176127 0007215 0 ustar 00 <?php namespace WPForms\Lite\Admin; /** * WPForms admin pages changes and enhancements to educate Lite users on what is available in WPForms Pro. * * @since 1.5.7 */ class Education { /** * WPForms admin page slug. * * @since 1.5.7 * * @var string */ public $page; /** * Constructor. * * @since 1.5.7 */ public function __construct() { $this->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 <a href="%s" target="_blank" rel="noopener noreferrer">upgrading to Pro</a>.', 'wpforms-lite' ), \wpforms_admin_upgrade_link( 'notice-bar' ) ); printf( '<div id="wpforms-notice-bar"> <span class="wpforms-notice-bar-message">%s</span> <button type="button" class="dismiss" title="%s" data-page="%s" /> </div>', \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 ); } } ConnectSkin.php 0000666 00000001576 15214176127 0007516 0 ustar 00 <?php namespace WPForms\Lite\Admin; use WPForms\Helpers\PluginSilentUpgraderSkin; /** * WPForms Connect Skin. * * WPForms Connect is our service that makes it easy for non-techy users to * upgrade to WPForms Pro without having to manually install WPForms Pro plugin. * * @since 1.5.5 * @since 1.5.6.1 Extend PluginSilentUpgraderSkin and clean up the class. */ class ConnectSkin extends PluginSilentUpgraderSkin { /** * Instead of outputting HTML for errors, json_encode the errors and send them * back to the Ajax script for processing. * * @since 1.5.5 * * @param array $errors Array of errors with the install process. */ public function error( $errors ) { if ( ! empty( $errors ) ) { echo \wp_json_encode( array( 'error' => \esc_html__( 'There was an error installing WPForms Pro. Please try again.', 'wpforms-lite' ), ) ); die; } } } Notifications.php 0000666 00000026735 15214223200 0010076 0 ustar 00 <?php namespace WPForms\Admin; /** * Notifications. * * @since 1.6.0 */ class Notifications { /** * Source of notifications content. * * @since 1.6.0 * * @var string */ const SOURCE_URL = 'https://plugin-cdn.wpforms.com/wp-content/notifications.json'; /** * Option value. * * @since 1.6.0 * * @var bool|array */ public $option = false; /** * Initialize class. * * @since 1.6.0 */ public function init() { $this->hooks(); } /** * Register hooks. * * @since 1.6.0 */ public function hooks() { add_action( 'wpforms_overview_enqueue', [ $this, 'enqueues' ] ); add_action( 'wpforms_admin_overview_before_table', [ $this, 'output' ] ); add_action( 'wpforms_admin_notifications_update', [ $this, 'update' ] ); add_action( 'wp_ajax_wpforms_notification_dismiss', [ $this, 'dismiss' ] ); } /** * Check if user has access and is enabled. * * @since 1.6.0 * * @return bool */ public function has_access() { $access = false; if ( wpforms_current_user_can( 'view_forms' ) && ! wpforms_setting( 'hide-announcements', false ) ) { $access = true; } return apply_filters( 'wpforms_admin_notifications_has_access', $access ); } /** * Get option value. * * @since 1.6.0 * * @param bool $cache Reference property cache if available. * * @return array */ public function get_option( $cache = true ) { if ( $this->option && $cache ) { return $this->option; } $option = get_option( 'wpforms_notifications', [] ); $this->option = [ 'update' => ! empty( $option['update'] ) ? $option['update'] : 0, 'events' => ! empty( $option['events'] ) ? $option['events'] : [], 'feed' => ! empty( $option['feed'] ) ? $option['feed'] : [], 'dismissed' => ! empty( $option['dismissed'] ) ? $option['dismissed'] : [], ]; return $this->option; } /** * Fetch notifications from feed. * * @since 1.6.0 * * @return array */ public function fetch_feed() { $res = wp_remote_get( self::SOURCE_URL ); if ( is_wp_error( $res ) ) { return []; } $body = wp_remote_retrieve_body( $res ); if ( empty( $body ) ) { return []; } return $this->verify( json_decode( $body, true ) ); } /** * Verify notification data before it is saved. * * @since 1.6.0 * * @param array $notifications Array of notifications items to verify. * * @return array */ public function verify( $notifications ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh $data = []; if ( ! is_array( $notifications ) || empty( $notifications ) ) { return $data; } $option = $this->get_option(); foreach ( $notifications as $notification ) { // The message and license should never be empty, if they are, ignore. if ( empty( $notification['content'] ) || empty( $notification['type'] ) ) { continue; } // Ignore if license type does not match. $license = wpforms_get_license_type() ? wpforms_get_license_type() : 'lite'; if ( ! in_array( $license, $notification['type'], true ) ) { continue; } // Ignore if expired. if ( ! empty( $notification['end'] ) && time() > strtotime( $notification['end'] ) ) { continue; } // Ignore if notifcation has already been dismissed. if ( ! empty( $option['dismissed'] ) && in_array( $notification['id'], $option['dismissed'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict continue; } // Ignore if notification existed before installing WPForms. // Prevents bombarding the user with notifications after activation. $activated = wpforms_get_activated_timestamp(); if ( ! empty( $activated ) && ! empty( $notification['start'] ) && $activated > strtotime( $notification['start'] ) ) { continue; } $data[] = $notification; } return $data; } /** * Verify saved notification data for active notifications. * * @since 1.6.0 * * @param array $notifications Array of notifications items to verify. * * @return array */ public function verify_active( $notifications ) { if ( ! is_array( $notifications ) || empty( $notifications ) ) { return []; } // Remove notfications that are not active. foreach ( $notifications as $key => $notification ) { if ( ( ! empty( $notification['start'] ) && time() < strtotime( $notification['start'] ) ) || ( ! empty( $notification['end'] ) && time() > strtotime( $notification['end'] ) ) ) { unset( $notifications[ $key ] ); } } return $notifications; } /** * Get notification data. * * @since 1.6.0 * * @return array */ public function get() { if ( ! $this->has_access() ) { return []; } $option = $this->get_option(); // Update notifications using async task. if ( empty( $option['update'] ) || time() > $option['update'] + DAY_IN_SECONDS ) { if ( empty( wpforms()->get( 'tasks' )->is_scheduled( 'wpforms_admin_notifications_update' ) ) ) { wpforms()->get( 'tasks' ) ->create( 'wpforms_admin_notifications_update' ) ->async() ->params() ->register(); } } $events = ! empty( $option['events'] ) ? $this->verify_active( $option['events'] ) : []; $feed = ! empty( $option['feed'] ) ? $this->verify_active( $option['feed'] ) : []; return array_merge( $events, $feed ); } /** * Get notification count. * * @since 1.6.0 * * @return int */ public function get_count() { return count( $this->get() ); } /** * Add a manual notification event. * * @since 1.6.0 * * @param array $notification Notification data. */ public function add( $notification ) { if ( empty( $notification['id'] ) ) { return; } $option = $this->get_option(); if ( in_array( $notification['id'], $option['dismissed'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict return; } foreach ( $option['events'] as $item ) { if ( $item['id'] === $notification['id'] ) { return; } } $notification = $this->verify( [ $notification ] ); update_option( 'wpforms_notifications', [ 'update' => $option['update'], 'feed' => $option['feed'], 'events' => array_merge( $notification, $option['events'] ), 'dismissed' => $option['dismissed'], ] ); } /** * Update notification data from feed. * * @since 1.6.0 */ public function update() { $feed = $this->fetch_feed(); $option = $this->get_option(); update_option( 'wpforms_notifications', [ 'update' => time(), 'feed' => $feed, 'events' => $option['events'], 'dismissed' => $option['dismissed'], ] ); } /** * Admin area Form Overview enqueues. * * @since 1.6.0 */ public function enqueues() { if ( ! $this->has_access() ) { return; } $notifications = $this->get(); if ( empty( $notifications ) ) { return; } $min = wpforms_get_min_suffix(); wp_enqueue_style( 'wpforms-admin-notifications', WPFORMS_PLUGIN_URL . "assets/css/admin-notifications{$min}.css", [], WPFORMS_VERSION ); wp_enqueue_script( 'wpforms-admin-notifications', WPFORMS_PLUGIN_URL . "assets/js/admin-notifications{$min}.js", [ 'jquery' ], WPFORMS_VERSION, true ); } /** * Output notifications on Form Overview admin area. * * @since 1.6.0 */ public function output() { $notifications = $this->get(); if ( empty( $notifications ) ) { return; } $notifications_html = ''; $current_class = ' current'; $content_allowed_tags = [ 'em' => [], 'strong' => [], 'span' => [ 'style' => [], ], 'a' => [ 'href' => [], 'target' => [], 'rel' => [], ], ]; foreach ( $notifications as $notification ) { // Buttons HTML. $buttons_html = ''; if ( ! empty( $notification['btns'] ) && is_array( $notification['btns'] ) ) { foreach ( $notification['btns'] as $btn_type => $btn ) { $buttons_html .= sprintf( '<a href="%1$s" class="button button-%2$s"%3$s>%4$s</a>', ! empty( $btn['url'] ) ? esc_url( $btn['url'] ) : '', $btn_type === 'main' ? 'primary' : 'secondary', ! empty( $btn['target'] ) && $btn['target'] === '_blank' ? ' target="_blank" rel="noopener noreferrer"' : '', ! empty( $btn['text'] ) ? sanitize_text_field( $btn['text'] ) : '' ); } $buttons_html = ! empty( $buttons_html ) ? '<div class="buttons">' . $buttons_html . '</div>' : ''; } // Notification HTML. $notifications_html .= sprintf( '<div class="message%5$s" data-message-id="%4$s"> <h3 class="title">%1$s</h3> <p class="content">%2$s</p> %3$s </div>', ! empty( $notification['title'] ) ? sanitize_text_field( $notification['title'] ) : '', ! empty( $notification['content'] ) ? wp_kses( $notification['content'], $content_allowed_tags ) : '', $buttons_html, ! empty( $notification['id'] ) ? esc_attr( sanitize_text_field( $notification['id'] ) ) : 0, $current_class ); // Only first notification is current. $current_class = ''; } ?> <div id="wpforms-notifications"> <div class="bell"> <svg xmlns="http://www.w3.org/2000/svg" width="42" height="48" viewBox="0 0 42 48"><defs><style>.a{fill:#777;}.b{fill:#ca4a1f;}</style></defs><path class="a" d="M23-79a6.005,6.005,0,0,1-6-6h10.06a12.066,12.066,0,0,0,1.791,1.308,6.021,6.021,0,0,1-2.077,3.352A6.008,6.008,0,0,1,23-79Zm1.605-9H5.009a2.955,2.955,0,0,1-2.173-.923A3.088,3.088,0,0,1,2-91a2.919,2.919,0,0,1,.807-2.036c.111-.12.229-.243.351-.371a14.936,14.936,0,0,0,3.126-4.409A23.283,23.283,0,0,0,8.007-107.5a14.846,14.846,0,0,1,.906-5.145,14.5,14.5,0,0,1,2.509-4.324A15.279,15.279,0,0,1,20-122.046V-124a3,3,0,0,1,3-3,3,3,0,0,1,3,3v1.954a15.28,15.28,0,0,1,8.58,5.078,14.5,14.5,0,0,1,2.509,4.324,14.846,14.846,0,0,1,.906,5.145c0,.645.016,1.281.047,1.888A12.036,12.036,0,0,0,35-106a11.921,11.921,0,0,0-8.485,3.515A11.923,11.923,0,0,0,23-94a12,12,0,0,0,1.6,6Z" transform="translate(-2 127)"/><circle class="b" cx="9" cy="9" r="9" transform="translate(24 24)"/></svg> </div> <a class="dismiss" title="<?php echo esc_attr__( 'Dismiss this message', 'wpforms-lite' ); ?>"><i class="fa fa-times-circle" aria-hidden="true"></i></a> <div class="navigation"> <a class="prev disabled" title="<?php echo esc_attr__( 'Previous message', 'wpforms-lite' ); ?>"><i class="fa fa-chevron-left" aria-hidden="true"></i></a> <a class="next disabled" title="<?php echo esc_attr__( 'Next message', 'wpforms-lite' ); ?>"><i class="fa fa-chevron-right" aria-hidden="true"></i></a> </div> <div class="messages"> <?php echo $notifications_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> </div> </div> <?php } /** * Dismiss notification via AJAX. * * @since 1.6.0 */ public function dismiss() { // Run a security check. check_ajax_referer( 'wpforms-admin', 'nonce' ); // Check for access and required param. if ( ! $this->has_access() || empty( $_POST['id'] ) ) { wp_send_json_error(); } $id = sanitize_text_field( wp_unslash( $_POST['id'] ) ); $option = $this->get_option(); $type = is_numeric( $id ) ? 'feed' : 'events'; $option['dismissed'][] = $id; $option['dismissed'] = array_unique( $option['dismissed'] ); // Remove notification. if ( is_array( $option[ $type ] ) && ! empty( $option[ $type ] ) ) { foreach ( $option[ $type ] as $key => $notification ) { if ( $notification['id'] == $id ) { // phpcs:ignore WordPress.PHP.StrictComparisons unset( $option[ $type ][ $key ] ); break; } } } update_option( 'wpforms_notifications', $option ); wp_send_json_success(); } } Loader.php 0000666 00000003441 15214223200 0006460 0 ustar 00 <?php namespace WPForms\Admin; /** * Class Loader gives ability to track/load all admin modules. * * @since 1.5.0 */ class Loader { /** * Get the instance of a class and store it in itself. * * @since 1.5.0 */ public static function get_instance() { static $instance; if ( ! $instance ) { $instance = new self(); } return $instance; } /** * Loader constructor. * * @since 1.5.0 */ public function __construct() { $core_class_names = array( 'Connect', 'DashboardWidget', 'Challenge', 'Education', 'FlyoutMenu', 'Builder\Education', 'Builder\LicenseAlert', 'Pages\Community', 'Pages\SMTP', 'Pages\Analytics', 'Settings\Education', 'Entries\PrintPreview', 'Entries\DefaultScreen', 'Entries\Export\Export', ); $class_names = \apply_filters( 'wpforms_admin_classes_available', $core_class_names ); foreach ( $class_names as $class_name ) { $this->register_class( $class_name ); } } /** * Register a new class. * * @since 1.5.0 * * @param string $class_name Class name to register. */ public function register_class( $class_name ) { $class_name = \sanitize_text_field( $class_name ); // Load Lite class if exists. if ( ! \wpforms()->pro && \class_exists( 'WPForms\Lite\Admin\\' . $class_name ) ) { $class_name = 'WPForms\Lite\Admin\\' . $class_name; new $class_name(); return; } // Load Pro class if exists. if ( \wpforms()->pro && \class_exists( 'WPForms\Pro\Admin\\' . $class_name ) ) { $class_name = 'WPForms\Pro\Admin\\' . $class_name; new $class_name(); return; } // Load general class if neither Pro nor Lite class exists. if ( \class_exists( __NAMESPACE__ . '\\' . $class_name ) ) { $class_name = __NAMESPACE__ . '\\' . $class_name; new $class_name(); } } } Challenge.php 0000666 00000054036 15214223200 0007142 0 ustar 00 <?php namespace WPForms\Admin; /** * Challenge and guide a user to set up a first form once WPForms is installed. * * @since 1.5.0 */ class Challenge { /** * Number of minutes to complete the Challenge. * * @since 1.5.0 * * @var int */ protected $minutes = 5; /** * Constructor. * * @since 1.5.0 */ public function __construct() { if ( \current_user_can( \wpforms_get_capability_manage_options() ) ) { $this->hooks(); } } /** * Hooks. * * @since 1.5.0 */ public function hooks() { \add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); \add_action( 'wpforms_builder_init', array( $this, 'start_challenge' ) ); \add_action( 'admin_footer', array( $this, 'challenge_html' ) ); \add_action( 'wpforms_welcome_intro_after', array( $this, 'welcome_html' ) ); \add_action( 'wp_ajax_wpforms_challenge_embed_page_url', array( $this, 'get_embed_page_url_ajax' ) ); \add_action( 'wp_ajax_wpforms_challenge_save_option', array( $this, 'save_challenge_option_ajax' ) ); \add_action( 'wp_ajax_wpforms_challenge_send_contact_form', array( $this, 'send_contact_form_ajax' ) ); } /** * Check if the current page is related to Challenge. * * @since 1.5.0 */ public function is_challenge_page() { return \wpforms_is_admin_page() || $this->is_builder_page() || $this->is_form_embed_page(); } /** * Check if the current page is a forms builder page related to Challenge. * * @since 1.5.0 */ public function is_builder_page() { if ( ! \wpforms_is_admin_page( 'builder' ) ) { return false; } if ( ! $this->challenge_active() ) { return false; } $step = \absint( $this->get_challenge_option( 'step' ) ); $form_id = \absint( $this->get_challenge_option( 'form_id' ) ); if ( $form_id && $step < 2 ) { return false; } $current_form_id = isset( $_GET['form_id'] ) ? \absint( $_GET['form_id'] ) : 0; $is_new_form = isset( $_GET['newform'] ) ? \absint( $_GET['newform'] ) : 0; if ( $is_new_form && 2 !== $step ) { return false; } if ( ! $is_new_form && $form_id !== $current_form_id && $step >= 2 ) { return false; } return true; } /** * Check if the current page is a form embed page edit related to Challenge. * * @since 1.5.0 */ public function is_form_embed_page() { if ( ! \is_admin() || ! \is_user_logged_in() ) { return false; } $screen = \get_current_screen(); if ( ! isset( $screen->id ) || 'page' !== $screen->id ) { return false; } if ( ! $this->challenge_active() ) { return false; } $step = $this->get_challenge_option( 'step' ); if ( ! \in_array( $step, array( 4, 5 ), true ) ) { return false; } $embed_page = $this->get_challenge_option( 'embed_page' ); if ( isset( $screen->action ) && 'add' === $screen->action && 0 === $embed_page ) { return true; } if ( isset( $_GET['post'] ) && $embed_page === \absint( $_GET['post'] ) ) { return true; } return false; } /** * Load scripts and styles. * * @since 1.5.0 */ public function enqueue_scripts() { if ( $this->challenge_finished() ) { return; } $min = \wpforms_get_min_suffix(); if ( $this->is_challenge_page() ) { \wp_enqueue_style( 'wpforms-challenge', \WPFORMS_PLUGIN_URL . "assets/css/challenge{$min}.css", array(), \WPFORMS_VERSION ); \wp_enqueue_script( 'wpforms-challenge-admin', \WPFORMS_PLUGIN_URL . "assets/js/components/admin/challenge/challenge-admin{$min}.js", array( 'jquery' ), \WPFORMS_VERSION, true ); \wp_localize_script( 'wpforms-challenge-admin', 'wpforms_challenge_admin', array( 'nonce' => \wp_create_nonce( 'wpforms_challenge_ajax_nonce' ), 'minutes_left' => \absint( $this->minutes ), ) ); } if ( $this->is_builder_page() || $this->is_form_embed_page() ) { \wp_enqueue_style( 'tooltipster', \WPFORMS_PLUGIN_URL . 'assets/css/tooltipster.css', null, '4.2.6' ); \wp_enqueue_script( 'tooltipster', \WPFORMS_PLUGIN_URL . 'assets/js/jquery.tooltipster.min.js', array( 'jquery' ), '4.2.6', true ); \wp_enqueue_script( 'wpforms-challenge-core', \WPFORMS_PLUGIN_URL . "assets/js/components/admin/challenge/challenge-core{$min}.js", array( 'jquery', 'tooltipster', 'wpforms-challenge-admin' ), \WPFORMS_VERSION, true ); } if ( $this->is_builder_page() ) { \wp_enqueue_script( 'wpforms-challenge-builder', \WPFORMS_PLUGIN_URL . "assets/js/components/admin/challenge/challenge-builder{$min}.js", array( 'jquery', 'tooltipster', 'wpforms-challenge-core' ), \WPFORMS_VERSION, true ); } if ( $this->is_form_embed_page() ) { \wp_enqueue_style( 'wpforms-font-awesome', \WPFORMS_PLUGIN_URL . 'assets/css/font-awesome.min.css', null, '4.7.0' ); \wp_enqueue_script( 'wpforms-challenge-embed', \WPFORMS_PLUGIN_URL . "assets/js/components/admin/challenge/challenge-embed{$min}.js", array( 'jquery', 'tooltipster', 'wpforms-challenge-core' ), \WPFORMS_VERSION, true ); } } /** * Get 'wpforms_challenge' option schema. * * @since 1.5.0 */ public function get_challenge_option_schema() { return array( 'status' => '', 'step' => 0, 'user_id' => \get_current_user_id(), 'form_id' => 0, 'embed_page' => 0, 'started_date_gmt' => '', 'finished_date_gmt' => '', 'seconds_spent' => 0, 'seconds_left' => 0, 'feedback_sent' => false, 'feedback_contact_me' => false, ); } /** * Get Challenge parameter(s) from Challenge option. * * @since 1.5.0 * * @param array|string|null $query Query using 'wpforms_challenge' schema keys. * * @return array|mixed */ public function get_challenge_option( $query = null ) { if ( ! $query ) { return \get_option( 'wpforms_challenge' ); } if ( ! \is_array( $query ) ) { $return_single = true; $query = array( $query ); } $query = \array_flip( $query ); $option = \get_option( 'wpforms_challenge' ); if ( ! $option || ! \is_array( $option ) ) { return \array_intersect_key( $this->get_challenge_option_schema(), $query ); } $result = \array_intersect_key( $option, $query ); if ( $return_single ) { $result = \reset( $result ); } return $result; } /** * Set Challenge parameter(s) to Challenge option. * * @since 1.5.0 * * @param array $query Query using 'wpforms_challenge' schema keys. */ public function set_challenge_option( $query ) { if ( empty( $query ) || ! \is_array( $query ) ) { return; } $schema = $this->get_challenge_option_schema(); $replace = \array_intersect_key( $query, $schema ); if ( ! $replace ) { return; } // Validate and sanitize the data. foreach ( $replace as $key => $value ) { if ( \in_array( $key, array( 'step', 'user_id', 'form_id', 'embed_page', 'seconds_spent', 'seconds_left' ), true ) ) { $replace[ $key ] = \absint( $value ); continue; } if ( \in_array( $key, array( 'feedback_sent', 'feedback_contact_me' ), true ) ) { $replace[ $key ] = \wp_validate_boolean( $value ); continue; } $replace[ $key ] = \sanitize_text_field( $value ); } $option = \get_option( 'wpforms_challenge' ); if ( ! $option || ! \is_array( $option ) ) { \update_option( 'wpforms_challenge', \array_merge( $schema, $replace ) ); return; } \update_option( 'wpforms_challenge', \array_merge( $option, $replace ) ); } /** * Check if any forms are present on a site. * * @since 1.5.0 */ public function website_has_forms() { return (bool) \wpforms()->form->get( '', array( 'numberposts' => 1 ) ); } /** * Check if Challenge was started. * * @since 1.5.0 */ public function challenge_started() { return 'started' === $this->get_challenge_option( 'status' ); } /** * Check if Challenge was finished. * * @since 1.5.0 */ public function challenge_finished() { $status = $this->get_challenge_option( 'status' ); return \in_array( $status, array( 'completed', 'canceled', 'skipped' ), true ); } /** * Check if Challenge is in progress. * * @since 1.5.0 */ public function challenge_active() { return $this->challenge_started() && ! $this->challenge_finished(); } /** * Check if Challenge can be started. * * @since 1.5.0 */ public function challenge_can_start() { if ( $this->website_has_forms() ) { return false; } if ( $this->challenge_started() || $this->challenge_finished() ) { return false; } return true; } /** * Start the Challenge in Form Builder. * * @since 1.5.0 */ public function start_challenge() { if ( ! isset( $_GET['challenge'] ) || 'start' !== $_GET['challenge'] ) { return; } if ( ! $this->challenge_can_start() ) { return; } $this->set_challenge_option( array( 'status' => 'started', 'started_date_gmt' => \current_time( 'mysql', true ), ) ); \wp_safe_redirect( \remove_query_arg( 'challenge' ) ); } /** * Include Challenge HTML. * * @since 1.5.0 */ public function challenge_html() { if ( $this->challenge_finished() ) { return; } if ( \wpforms_is_admin_page() && ! \wpforms_is_admin_page( 'getting-started' ) && $this->challenge_can_start() ) { $this->challenge_modal_html( 'start' ); } if ( $this->is_builder_page() ) { $this->challenge_modal_html( 'progress' ); $this->challenge_builder_templates_html(); } if ( $this->is_form_embed_page() ) { $this->challenge_modal_html( 'progress' ); $this->challenge_embed_templates_html(); } } /** * Include Challenge main modal window HTML. * * @since 1.5.0 * * @param string $state State of Challenge ('start' or 'progress'). */ public function challenge_modal_html( $state ) { ?> <div class="wpforms-challenge <?php echo 'start' === $state ? \esc_attr( 'wpforms-challenge-start' ) : ''; ?>" data-wpforms-challenge-saved-step="<?php echo \absint( $this->get_challenge_option( 'step' ) ); ?>"> <div class="wpforms-challenge-list-block"> <p> <?php echo \wp_kses( \sprintf( /* translators: %1$d - Number of minutes; %2$s - Single or plural word 'minute'. */ \__( 'Complete the <b>WPForms Challenge</b> and get up and running within %1$d %2$s.', 'wpforms-lite' ), \absint( $this->minutes ), \_n( 'minute', 'minutes', \absint( $this->minutes ), 'wpforms-lite' ) ), array( 'b' => array() ) ); ?> </p> <div class="wpforms-challenge-bar"> <div></div> </div> <ul class="wpforms-challenge-list"> <li class="wpforms-challenge-step1-item"><?php \esc_html_e( 'Name Your Form', 'wpforms-lite' ); ?></li> <li class="wpforms-challenge-step2-item"><?php \esc_html_e( 'Select a Template', 'wpforms-lite' ); ?></li> <li class="wpforms-challenge-step3-item"><?php \esc_html_e( 'Add Fields to Your Form', 'wpforms-lite' ); ?></li> <li class="wpforms-challenge-step4-item"><?php \esc_html_e( 'Check Notification Settings', 'wpforms-lite' ); ?></li> <li class="wpforms-challenge-step5-item"><?php \esc_html_e( 'Embed in a Page', 'wpforms-lite' ); ?></li> </ul> <?php if ( 'start' === $state ) : ?> <a href="<?php echo \esc_url( \admin_url( 'admin.php?page=wpforms-builder&challenge=start' ) ); ?>" class="wpforms-btn wpforms-btn-md wpforms-btn-orange wpforms-challenge-start"> <?php \esc_html_e( 'Start Challenge', 'wpforms-lite' ); ?> </a> <a href="javascript:void(0);" class="wpforms-challenge-skip"><?php \esc_html_e( 'Skip Challenge', 'wpforms-lite' ); ?></a> <?php endif; ?> <?php if ( 'progress' === $state ) : ?> <a href="javascript:void(0);" class="wpforms-challenge-cancel"><?php \esc_html_e( 'Cancel Challenge', 'wpforms-lite' ); ?></a> <?php endif; ?> </div> <div class="block-timer"> <img src="<?php echo \esc_url( \WPFORMS_PLUGIN_URL . 'assets/images/challenge/sullie-circle.png' ); ?>" alt="<?php \esc_html_e( 'Sullie the WPForms mascot', 'wpforms-lite' ); ?>"> <div> <h3><?php \esc_html_e( 'WPForms Challenge', 'wpforms-lite' ); ?></h3> <p> <?php printf( /* translators: %s - minutes in 2:00 format. */ esc_html__( '%s remaining', 'wpforms-lite' ), '<span id="wpforms-challenge-timer">' . \absint( $this->minutes ) .':00</span>' ); ?> </p> </div> <div class="caret-icon"> <i class="fa fa-caret-down"></i> </div> </div> </div> <?php } /** * Include Challenge HTML templates specific to Form Builder. * * @since 1.5.0 */ public function challenge_builder_templates_html() { ?> <div class="wpforms-challenge-tooltips"> <div id="tooltip-content1"> <h3><?php \esc_html_e( 'Name Your Form', 'wpforms-lite' ); ?></h3> <p><?php \esc_html_e( 'Give your form a name so you can easily identify it.', 'wpforms-lite' ); ?></p> <button type="button" class="wpforms-challenge-step1-done wpforms-challenge-done-btn"><?php \esc_html_e( 'Done', 'wpforms-lite' ); ?></button> </div> <div id="tooltip-content2"> <h3><?php \esc_html_e( 'Select a Template', 'wpforms-lite' ); ?></h3> <p><?php \esc_html_e( 'Build your form from scratch or use one of our pre-made templates.', 'wpforms-lite' ); ?></p> </div> <div id="tooltip-content3"> <h3><?php \esc_html_e( 'Add Fields to Your Form', 'wpforms-lite' ); ?></h3> <p><?php \esc_html_e( 'You can add additional fields to your form, if you need them. This step is optional.', 'wpforms-lite' ); ?></p> <button type="button" class="wpforms-challenge-step3-done wpforms-challenge-done-btn"><?php \esc_html_e( 'Done', 'wpforms-lite' ); ?></button> </div> <div id="tooltip-content4"> <h3><?php \esc_html_e( 'Check Notification Settings', 'wpforms-lite' ); ?></h3> <p><?php \esc_html_e( 'The default notification settings might be sufficient, but double‑check to be sure.', 'wpforms-lite' ); ?></p> <button type="button" class="wpforms-challenge-step4-done wpforms-challenge-done-btn"><?php \esc_html_e( 'Done', 'wpforms-lite' ); ?></button> </div> </div> <?php } /** * Include Challenge HTML templates specific to form embed page. * * @since 1.5.0 */ public function challenge_embed_templates_html() { ?> <div class="wpforms-challenge-tooltips"> <div id="tooltip-content5"> <?php if ( \function_exists( 'register_block_type' ) ) : // Gutenberg content. ?> <h3><?php \esc_html_e( 'Add a Block', 'wpforms-lite' ); ?></h3> <p><?php \esc_html_e( 'Click the “Add Block” button, search WPForms, select block to embed.', 'wpforms-lite' ); ?></p> <?php else : ?> <h3><?php \esc_html_e( 'Embed in a Page', 'wpforms-lite' ); ?></h3> <p><?php \esc_html_e( 'Click the “Add Form” button, select your form, then add the embed code.', 'wpforms-lite' ); ?></p> <?php endif; ?> <button type="button" class="wpforms-challenge-step5-done wpforms-challenge-done-btn"><?php \esc_html_e( 'Done', 'wpforms-lite' ); ?></button> </div> </div> <div class="wpforms-challenge-popup-container"> <div id="wpforms-challenge-congrats-popup" class="wpforms-challenge-popup"> <div class="wpforms-challenge-popup-header wpforms-challenge-popup-header-congrats"> <i class="wpforms-challenge-popup-close fa fa-times-circle fa-lg"></i> </div> <div class="wpforms-challenge-popup-content"> <h3><?php \esc_html_e( 'Congrats, you did it!', 'wpforms-lite' ); ?></h3> <p> <?php echo \wp_kses( \sprintf( /* translators: %1$s - Number of minutes in HTML container; %2$s - Single or plural word 'minute'; %3$s - Number of seconds in HTML container; %4$s - Single or plural word 'second'; %5$s - 5 rating star symbols HTML. */ \__( 'You completed the WPForms Challenge in <b>%1$s %2$s %3$s %4$s</b>. Share your success story with other WPForms users and help us spread the word <b>by giving WPForms a 5-star rating (%5$s) on WordPress.org</b>. Thanks for your support and we look forward to bringing more awesome features.', 'wpforms-lite' ), '<span id="wpforms-challenge-congrats-minutes"></span>', \_n( 'minute', 'minutes', \absint( $this->minutes ), 'wpforms-lite' ), '<span id="wpforms-challenge-congrats-seconds"></span>', \_n( 'second', 'seconds', \absint( $this->minutes ), 'wpforms-lite' ), '<span class="rating-stars"><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i></span>' ), array( 'span' => array( 'id' => array(), 'class' => array(), ), 'b' => array(), 'i' => array( 'class' => array(), ), ) ); ?> </p> <a href="https://wordpress.org/support/plugin/wpforms-lite/reviews/?filter=5#new-post" class="wpforms-challenge-popup-btn wpforms-challenge-popup-rate-btn" target="_blank" rel="noopener"><?php \esc_html_e( 'Rate WPForms on WordPress.org', 'wpforms-lite' ); ?> <span class="dashicons dashicons-external"></span></a> </div> </div> <div id="wpforms-challenge-contact-popup" class="wpforms-challenge-popup"> <div class="wpforms-challenge-popup-header wpforms-challenge-popup-header-contact"> <i class="wpforms-challenge-popup-close fa fa-times-circle fa-lg"></i> </div> <div class="wpforms-challenge-popup-content"> <form id="wpforms-challenge-contact-form"> <h3><?php \esc_html_e( 'Help us improve WPForms', 'wpforms-lite' ); ?></h3> <p> <?php echo \esc_html( \sprintf( /* translators: %1$d - Number of minutes; %2$s - Single or plural word 'minute'. */ \__( 'We`re sorry that it took longer than %1$d %2$s to create a form. Our goal is to create the most beginner friendly WordPress form plugin. Please take a moment to let us know how we can improve WPForms.', 'wpforms-lite' ), \absint( $this->minutes ), \_n( 'minute', 'minutes', \absint( $this->minutes ), 'wpforms-lite' ) ) ); ?> </p> <textarea class="wpforms-challenge-contact-message"></textarea> <label> <input type="checkbox" class="wpforms-challenge-contact-permission"><?php \esc_html_e( 'Yes, I give WPForms permission to contact me for any follow up questions.', 'wpforms-lite' ); ?> </label> <button type="submit" class="wpforms-challenge-popup-btn wpforms-challenge-popup-contact-btn"><?php \esc_html_e( 'Submit Feedback', 'wpforms-lite' ); ?></button> </form> </div> </div> </div> <?php } /** * Include Challenge CTA on WPForms welcome activation screen. * * @since 1.5.0 */ public function welcome_html() { if ( $this->challenge_finished() ) { return; } ?> <div class="challenge"> <div class="block"> <h1><?php esc_html_e( 'Take the WPForms Challenge', 'wpforms-lite' ); ?></h1> <h6><?php esc_html_e( 'Create your first form with our guided setup wizard in less than 5 minutes to experience the WPForms difference.', 'wpforms-lite' ); ?></h6> <div class="button-wrap"> <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpforms-builder&challenge=start' ) ); ?>" class="wpforms-btn wpforms-btn-lg wpforms-btn-orange"> <?php esc_html_e( 'Start the WPForms Challenge', 'wpforms-lite' ); ?> </a> </div> </div> </div> <?php } /** * Get embed page URL via AJAX. * * @since 1.5.0 */ public function get_embed_page_url_ajax() { \check_admin_referer( 'wpforms_challenge_ajax_nonce' ); global $wpdb; $page_id = \absint( $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_type = 'page' AND post_name LIKE '%contact%';" ) ); if ( $page_id ) { $url = \get_edit_post_link( $page_id, '' ); $this->set_challenge_option( array( 'embed_page' => $page_id ) ); } else { $url = \add_query_arg( 'post_type', 'page', \admin_url( 'post-new.php' ) ); $this->set_challenge_option( array( 'embed_page' => 0 ) ); } \wp_send_json_success( $url ); } /** * Save Challenge data via AJAX. * * @since 1.5.0 */ public function save_challenge_option_ajax() { \check_admin_referer( 'wpforms_challenge_ajax_nonce' ); if ( empty( $_POST['option_data'] ) ) { \wp_send_json_error(); } $schema = $this->get_challenge_option_schema(); foreach ( $schema as $key => $value ) { if ( ! empty( $_POST['option_data'][ $key ] ) ) { $query[ $key ] = \sanitize_text_field( \wp_unslash( $_POST['option_data'][ $key ] ) ); } } if ( empty( $query ) ) { \wp_send_json_error(); } if ( ! empty( $query['status'] ) && \in_array( $query['status'], array( 'completed', 'canceled', 'skipped' ), true ) ) { $query['finished_date_gmt'] = \current_time( 'mysql', true ); } if ( ! empty( $query['status'] ) && 'skipped' === $query['status'] ) { $query['started_date_gmt'] = \current_time( 'mysql', true ); $query['finished_date_gmt'] = $query['started_date_gmt']; } $this->set_challenge_option( $query ); \wp_send_json_success(); } /** * Send contact form to wpforms.com via AJAX. * * @since 1.5.0 */ public function send_contact_form_ajax() { \check_admin_referer( 'wpforms_challenge_ajax_nonce' ); $url = 'https://wpforms.com/wpforms-challenge-feedback/'; $message = ! empty( $_POST['contact_data']['message'] ) ? \sanitize_textarea_field( \wp_unslash( $_POST['contact_data']['message'] ) ) : ''; $email = ''; if ( ! empty( $_POST['contact_data']['contact_me'] ) && 'true' === $_POST['contact_data']['contact_me'] ) { $current_user = \wp_get_current_user(); $email = $current_user->user_email; $this->set_challenge_option( array( 'feedback_contact_me' => true ) ); } if ( empty( $message ) && empty( $email ) ) { \wp_send_json_error(); } $data = array( 'body' => array( 'wpforms' => array( 'id' => 296355, 'submit' => 'wpforms-submit', 'fields' => array( 2 => $message, 3 => $email, ), ), ), ); $response = \wp_remote_post( $url, $data ); if ( \is_wp_error( $response ) ) { \wp_send_json_error(); } $this->set_challenge_option( array( 'feedback_sent' => true ) ); \wp_send_json_success(); } } AdminBarMenu.php 0000666 00000015134 15214223200 0007556 0 ustar 00 <?php namespace WPForms\Admin; /** * WPForms admin bar menu. * * @since 1.6.0 */ class AdminBarMenu { /** * Initialize class. * * @since 1.6.0 */ public function init() { $this->hooks(); } /** * Register hooks. * * @since 1.6.0 */ public function hooks() { add_action( 'wp_enqueue_scripts', [ $this, 'enqueues' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueues' ] ); add_action( 'admin_bar_menu', [ $this, 'register' ], 999 ); } /** * Check if current user has access to see admin bar menu. * * @since 1.6.0 * * @return bool */ public function has_access() { $access = false; if ( is_user_logged_in() && wpforms_current_user_can() && ! wpforms_setting( 'hide-admin-bar', false ) ) { $access = true; } return apply_filters( 'wpforms_admin_adminbarmenu_has_access', $access ); } /** * Check if new notifications are available. * * @since 1.6.0 * * @return bool */ public function has_notifications() { return wpforms()->get( 'notifications' )->get_count(); } /** * Enqueue styles. * * @since 1.6.0 */ public function enqueues() { if ( ! $this->has_access() ) { return; } $min = wpforms_get_min_suffix(); wp_enqueue_style( 'wpforms-admin-bar', WPFORMS_PLUGIN_URL . "assets/css/admin-bar{$min}.css", [], WPFORMS_VERSION ); } /** * Register and render admin menu bar items. * * @since 1.6.0 * * @param \WP_Admin_Bar $wp_admin_bar WordPress Admin Bar object. */ public function register( \WP_Admin_Bar $wp_admin_bar ) { if ( ! $this->has_access() ) { return; } $items = apply_filters( 'wpforms_admin_adminbarmenu_register', [ 'main_menu', 'notification_menu', 'forms_menu', 'all_forms_menu', 'add_new_menu', 'community_menu', 'support_menu', ], $wp_admin_bar ); foreach ( $items as $item ) { $this->{ $item }( $wp_admin_bar ); do_action( "wpforms_admin_adminbarmenu_register_{$item}_after", $wp_admin_bar ); } } /** * Render primary top-level admin menu bar item. * * @since 1.6.0 * * @param \WP_Admin_Bar $wp_admin_bar WordPress Admin Bar object. */ public function main_menu( \WP_Admin_Bar $wp_admin_bar ) { $indicator = ''; if ( $this->has_notifications() ) { $count = $this->has_notifications() < 10 ? $this->has_notifications() : '!'; $indicator = ' <div class="wpforms-menu-notification-counter"><span>' . $count . '</span></div>'; } $wp_admin_bar->add_menu( [ 'id' => 'wpforms-menu', 'title' => 'WPForms' . $indicator, 'href' => admin_url( 'admin.php?page=wpforms-overview' ), ] ); } /** * Render Notifications admin menu bar item. * * @since 1.6.0 * * @param \WP_Admin_Bar $wp_admin_bar WordPress Admin Bar object. */ public function notification_menu( \WP_Admin_Bar $wp_admin_bar ) { if ( ! $this->has_notifications() ) { return; } $wp_admin_bar->add_menu( [ 'parent' => 'wpforms-menu', 'id' => 'wpforms-notifications', 'title' => __( 'Notifications', 'wpforms-lite' ) . ' <div class="wpforms-menu-notification-indicator"></div>', 'href' => admin_url( 'admin.php?page=wpforms-overview' ), ] ); } /** * Render individual forms admin menu bar items and sub-items. * * @since 1.6.0 * * @param \WP_Admin_Bar $wp_admin_bar WordPress Admin Bar object. */ public function forms_menu( \WP_Admin_Bar $wp_admin_bar ) { if ( is_admin() ) { return; } $forms = wpforms()->frontend->forms; $x = 0; if ( empty( $forms ) ) { return; } foreach ( $forms as $form ) { $x++; $form_id = absint( $form['id'] ); $class = 'wpforms-menu-form'; $this->displaying_forms = true; if ( $this->has_notifications() && $x === 1 ) { $class .= ' wpforms-menu-form-notifications'; } if ( $x === count( $forms ) ) { $class .= ' wpforms-menu-form-last'; } // Shrink the long form title. $form_title = sanitize_text_field( $form['settings']['form_title'] ); $form_title = mb_strlen( $form_title ) > 99 ? mb_substr( $form_title, 0, 99 ) . '…' : $form_title; $wp_admin_bar->add_menu( [ 'parent' => 'wpforms-menu', 'id' => 'wpforms-form-id-' . $form_id, 'title' => $form_title, 'href' => '#wpforms-' . $form_id, 'meta' => [ 'class' => $class, ], ] ); $wp_admin_bar->add_menu( [ 'parent' => 'wpforms-form-id-' . $form_id, 'id' => 'wpforms-edit-form-id-' . $form_id, 'title' => __( 'Edit Form', 'wpforms-lite' ), 'href' => admin_url( 'admin.php?page=wpforms-builder&view=fields&form_id=' . $form_id ), ] ); do_action( 'wpforms_admin_adminbarmenu_forms_menu_after', $wp_admin_bar, $form ); } } /** * Render All Forms admin menu bar item. * * @since 1.6.0 * * @param \WP_Admin_Bar $wp_admin_bar WordPress Admin Bar object. */ public function all_forms_menu( \WP_Admin_Bar $wp_admin_bar ) { $wp_admin_bar->add_menu( [ 'parent' => 'wpforms-menu', 'id' => 'wpforms-forms', 'title' => __( 'All Forms', 'wpforms-lite' ), 'href' => admin_url( 'admin.php?page=wpforms-overview' ), ] ); } /** * Render Add New admin menu bar item. * * @since 1.6.0 * * @param \WP_Admin_Bar $wp_admin_bar WordPress Admin Bar object. */ public function add_new_menu( \WP_Admin_Bar $wp_admin_bar ) { $wp_admin_bar->add_menu( [ 'parent' => 'wpforms-menu', 'id' => 'wpforms-add-new', 'title' => __( 'Add New', 'wpforms-lite' ), 'href' => admin_url( 'admin.php?page=wpforms-builder' ), ] ); } /** * Render Community admin menu bar item. * * @since 1.6.0 * * @param \WP_Admin_Bar $wp_admin_bar WordPress Admin Bar object. */ public function community_menu( \WP_Admin_Bar $wp_admin_bar ) { $wp_admin_bar->add_menu( [ 'parent' => 'wpforms-menu', 'id' => 'wpforms-community', 'title' => __( 'Community', 'wpforms-lite' ), 'href' => 'https://www.facebook.com/groups/wpformsvip/', 'meta' => [ 'target' => '_blank', 'rel' => 'noopener noreferrer', ], ] ); } /** * Render Support admin menu bar item. * * @since 1.6.0 * * @param \WP_Admin_Bar $wp_admin_bar WordPress Admin Bar object. */ public function support_menu( \WP_Admin_Bar $wp_admin_bar ) { $wp_admin_bar->add_menu( [ 'parent' => 'wpforms-menu', 'id' => 'wpforms-support', 'title' => __( 'Support', 'wpforms-lite' ), 'href' => 'https://wpforms.com/docs/', 'meta' => [ 'target' => '_blank', 'rel' => 'noopener noreferrer', ], ] ); } } FlyoutMenu.php 0000666 00000007416 15214223200 0007367 0 ustar 00 <?php namespace WPForms\Admin; /** * Admin Flyout Menu. * * @since 1.5.7 */ class FlyoutMenu { /** * Constructor. * * @since 1.5.7 */ public function __construct() { if ( ! \wpforms_is_admin_page() || \wpforms_is_admin_page( 'builder' ) ) { return; } if ( ! \apply_filters( 'wpforms_admin_flyoutmenu', true ) ) { return; } // Check if WPForms Challenge is active. $challenge = \get_option( 'wpforms_challenge' ); $forms_exists = (bool) \wpforms()->form->get( '', array( 'numberposts' => 1 ) ); if ( ! $forms_exists && ( empty( $challenge ) || ( ! empty( $challenge['status'] ) && ! \in_array( $challenge['status'], array( 'completed', 'canceled', 'skipped' ), true ) ) ) ) { return; } $this->hooks(); } /** * Hooks. * * @since 1.5.7 */ public function hooks() { \add_action( 'admin_footer', array( $this, 'output' ) ); } /** * Menu items data. * * @since 1.5.7 */ public function menu_items() { $is_pro = \wpforms()->pro; $utm_campaign = $is_pro ? 'plugin' : 'liteplugin'; $items = array( array( 'title' => \esc_html__( 'Upgrade to WPForms Pro', 'wpforms-lite' ), 'url' => \wpforms_admin_upgrade_link( 'flyout-menu' ), 'icon' => 'fa-star', 'bgcolor' => '#E1772F', 'hover_bgcolor' => '#ff8931', ), array( 'title' => \esc_html__( 'Support & Docs', 'wpforms-lite' ), 'url' => 'https://wpforms.com/docs/?utm_source=WordPress&utm_medium=Flyout Menu&utm_campaign=' . $utm_campaign . '&utm_content=Support', 'icon' => 'fa-life-ring', ), array( 'title' => \esc_html__( 'Join Our Community', 'wpforms-lite' ), 'url' => 'https://www.facebook.com/groups/wpformsvip/', 'icon' => 'fa-comments', ), array( 'title' => \esc_html__( 'Suggest a Feature', 'wpforms-lite' ), 'url' => 'https://wpforms.com/features/suggest/?utm_source=WordPress&utm_medium=Flyout Menu&utm_campaign=' . $utm_campaign . '&utm_content=Feature', 'icon' => 'fa-lightbulb-o', ), ); if ( $is_pro ) { array_shift( $items ); } return \apply_filters( 'wpforms_admin_flyout_menu_items', $items ); } /** * Output menu. * * @since 1.5.7 */ public function output() { printf( '<div id="wpforms-flyout"> <div id="wpforms-flyout-items"> %1$s </div> <a href="#" class="wpforms-flyout-button wpforms-flyout-head"> <div class="wpforms-flyout-label">%2$s</div> <img src="%3$s" alt="%2$s" data-active="%4$s" /> </a> </div>', $this->get_items_html(), // phpcs:ignore \esc_attr__( 'See Quick Links', 'wpforms-lite' ), \esc_url( \WPFORMS_PLUGIN_URL . 'assets/images/admin-flyout-menu/sullie-default.svg' ), \esc_url( \WPFORMS_PLUGIN_URL . 'assets/images/admin-flyout-menu/sullie-active.svg' ) ); } /** * Generate menu items HTML. * * @since 1.5.7 * * @return string Menu items HTML. */ public function get_items_html() { $items = array_reverse( $this->menu_items() ); $items_html = ''; foreach ( $items as $item_key => $item ) { $items_html .= sprintf( '<a href="%1$s" target="_blank" rel="noopener noreferrer" class="wpforms-flyout-button wpforms-flyout-item wpforms-flyout-item-%2$d"%5$s%6$s> <div class="wpforms-flyout-label">%3$s</div> <i class="fa %4$s"></i> </a>', \esc_url( $item['url'] ), (int) $item_key, \esc_html( $item['title'] ), \sanitize_html_class( $item['icon'] ), ! empty( $item['bgcolor'] ) ? ' style="background-color: ' . \esc_attr( $item['bgcolor'] ) . '"' : '', ! empty( $item['hover_bgcolor'] ) ? ' onMouseOver="this.style.backgroundColor=\'' . \esc_attr( $item['hover_bgcolor'] ) . '\'" onMouseOut="this.style.backgroundColor=\'' . \esc_attr( $item['bgcolor'] ) . '\'"' : '' ); } return $items_html; } } Pages/Community.php 0000666 00000012733 15214223200 0010301 0 ustar 00 <?php namespace WPForms\Admin\Pages; /** * Community Sub-page. * * @since 1.5.6 */ class Community { /** * Admin menu page slug. * * @since 1.5.6 * * @var string */ const SLUG = 'wpforms-community'; /** * Constructor. * * @since 1.5.6 */ public function __construct() { if ( \wpforms_current_user_can() ) { $this->hooks(); } } /** * Hooks. * * @since 1.5.6 */ public function hooks() { // Check what page we are on. $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.CSRF.NonceVerification // Only load if we are actually on the Community page. if ( self::SLUG !== $page ) { return; } add_action( 'wpforms_admin_page', array( $this, 'output' ) ); // Hook for addons. do_action( 'wpforms_admin_community_init' ); } /** * Page data. * * @since 1.5.6 */ public function get_blocks_data() { $data = array(); $data['vip_circle'] = array( 'title' => esc_html__( 'WPForms VIP Circle Facebook Group', 'wpforms-lite' ), 'description' => esc_html__( 'Powered by the community, for the community. Anything and everything WPForms: Discussions. Questions. Tutorials. Insights and sneak peaks. Also, exclusive giveaways!', 'wpforms-lite' ), 'button_text' => esc_html__( 'Join WPForms VIP Circle', 'wpforms-lite' ), 'button_link' => 'https://www.facebook.com/groups/wpformsvip/', 'cover_bg_color' => '#E4F0F6', 'cover_img' => 'vip-circle.png', 'cover_img2x' => 'vip-circle@2x.png', ); $data['dev_docs'] = array( 'title' => esc_html__( 'WPForms Developer Documentation', 'wpforms-lite' ), 'description' => esc_html__( 'Customize and extend WPForms with code. Our comprehensive developer resources include tutorials, snippets, and documentation on core actions, filters, functions, and more.', 'wpforms-lite' ), 'button_text' => esc_html__( 'View WPForms Dev Docs', 'wpforms-lite' ), 'button_link' => 'https://wpforms.com/developers/?utm_source=WordPress&utm_medium=Community&utm_campaign=liteplugin&utm_content=Developers', 'cover_bg_color' => '#EBEBEB', 'cover_img' => 'dev-docs.png', 'cover_img2x' => 'dev-docs@2x.png', ); $data['wpbeginner'] = array( 'title' => esc_html__( 'WPBeginner Engage Facebook Group', 'wpforms-lite' ), 'description' => esc_html__( 'Hang out with other WordPress experts and like minded website owners such as yourself! Hosted by WPBeginner, the largest free WordPress site for beginners.', 'wpforms-lite' ), 'button_text' => esc_html__( 'Join WPBeginner Engage', 'wpforms-lite' ), 'button_link' => 'https://www.facebook.com/groups/wpbeginner/', 'cover_bg_color' => '#FCEBDF', 'cover_img' => 'wpbeginner.png', 'cover_img2x' => 'wpbeginner@2x.png', ); $data['translators'] = array( 'title' => esc_html__( 'WPForms Translators Community', 'wpforms-lite' ), 'description' => esc_html__( 'We\'re building a community of translators and i18n experts to translate WPForms. Sign up to our translator community newsletter to learn more and get information on how you can contribute!', 'wpforms-lite' ), 'button_text' => esc_html__( 'Join Translators Community', 'wpforms-lite' ), 'button_link' => 'https://wpforms.com/translator-community-signup/?utm_source=WordPress&utm_medium=Community&utm_campaign=liteplugin&utm_content=Translators', 'cover_bg_color' => '#F2FAED', 'cover_img' => 'translators.png', 'cover_img2x' => 'translators@2x.png', ); $data['suggest'] = array( 'title' => esc_html__( 'Suggest a Feature', 'wpforms-lite' ), 'description' => esc_html__( 'Do you have an idea or suggestion for WPForms? If you have thoughts on features, integrations, addons, or improvements - we want to hear it! We appreciate all feedback and insight from our users.', 'wpforms-lite' ), 'button_text' => esc_html__( 'Suggest a Feature', 'wpforms-lite' ), 'button_link' => 'https://wpforms.com/features/suggest/?utm_source=WordPress&utm_medium=Community&utm_campaign=liteplugin&utm_content=Feature', 'cover_bg_color' => '#FFF9EF', 'cover_img' => 'suggest.png', 'cover_img2x' => 'suggest@2x.png', ); return $data; } /** * Generate and output page HTML. * * @since 1.5.6 */ public function output() { ?> <div id="wpforms-admin-community" class="wrap wpforms-admin-wrap"> <h1 class="page-title"><?php esc_html_e( 'Community', 'wpforms-lite' ); ?></h1> <div class="items"> <?php $data = $this->get_blocks_data(); foreach ( $data as $item ) { printf( '<div class="item"> <a href="%6$s" target="_blank" rel="noopener noreferrer" class="item-cover" style="background-color: %s;" title="%4$s"><img class="item-img" src="%s" srcset="%s 2x" alt="%4$s"/></a> <h3 class="item-title">%s</h3> <p class="item-description">%s</p> <div class="item-footer"> <a class="button" href="%s" target="_blank" rel="noopener noreferrer">%s</a> </div> </div>', esc_attr( $item['cover_bg_color'] ), esc_url( WPFORMS_PLUGIN_URL . 'assets/images/community/' . $item['cover_img'] ), esc_url( WPFORMS_PLUGIN_URL . 'assets/images/community/' . $item['cover_img2x'] ), esc_html( $item['title'] ), esc_html( $item['description'] ), esc_url( $item['button_link'] ), esc_html( $item['button_text'] ) ); } ?> </div> </div> <?php } } Pages/SMTP.php 0000666 00000031542 15214223200 0007077 0 ustar 00 <?php namespace WPForms\Admin\Pages; /** * SMTP Sub-page. * * @since 1.5.7 */ class SMTP { /** * Admin menu page slug. * * @since 1.5.7 * * @var string */ const SLUG = 'wpforms-smtp'; /** * Configuration. * * @since 1.5.7 * * @var array */ private $config = array( 'lite_plugin' => 'wp-mail-smtp/wp_mail_smtp.php', 'lite_download_url' => 'https://downloads.wordpress.org/plugin/wp-mail-smtp.zip', 'pro_plugin' => 'wp-mail-smtp-pro/wp_mail_smtp.php', 'smtp_settings' => 'admin.php?page=wp-mail-smtp', ); /** * Runtime data used for generating page HTML. * * @since 1.5.7 * * @var array */ private $output_data = array(); /** * Constructor. * * @since 1.5.7 */ public function __construct() { if ( ! \wpforms_current_user_can() ) { return; } $this->hooks(); } /** * Hooks. * * @since 1.5.7 */ public function hooks() { if ( wp_doing_ajax() ) { add_action( 'wp_ajax_wpforms_smtp_page_check_plugin_status', array( $this, 'ajax_check_plugin_status' ) ); } // Check what page we are on. $page = isset( $_GET['page'] ) ? \sanitize_key( \wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.CSRF.NonceVerification // Only load if we are actually on the SMTP page. if ( self::SLUG !== $page ) { return; } add_action( 'admin_init', array( $this, 'redirect_to_smtp_settings' ) ); add_filter( 'wpforms_admin_header', '__return_false' ); add_action( 'wpforms_admin_page', array( $this, 'output' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); // Hook for addons. do_action( 'wpforms_admin_pages_smtp_hooks' ); } /** * Enqueue JS and CSS files. * * @since 1.5.7 */ public function enqueue_assets() { $min = \wpforms_get_min_suffix(); // 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 ); wp_enqueue_script( 'wpforms-admin-page-smtp', WPFORMS_PLUGIN_URL . "assets/js/components/admin/pages/smtp{$min}.js", array( 'jquery' ), WPFORMS_VERSION, true ); \wp_localize_script( 'wpforms-admin-page-smtp', 'wpforms_pluginlanding', $this->get_js_strings() ); } /** * JS Strings. * * @since 1.5.7 * * @return array Array of strings. */ protected function get_js_strings() { $error_could_not_install = sprintf( wp_kses( /* translators: %s - Lite plugin download URL. */ __( 'Could not install plugin. Please <a href="%s">download</a> and install manually.', 'wpforms-lite' ), array( 'a' => array( 'href' => true, ), ) ), esc_url( $this->config['lite_download_url'] ) ); $error_could_not_activate = sprintf( wp_kses( /* translators: %s - Lite plugin download URL. */ __( 'Could not activate plugin. Please activate from the <a href="%s">Plugins page</a>.', 'wpforms-lite' ), array( 'a' => array( 'href' => true, ), ) ), esc_url( admin_url( 'plugins.php' ) ) ); return array( 'installing' => esc_html__( 'Installing...', 'wpforms-lite' ), 'activating' => esc_html__( 'Activating...', 'wpforms-lite' ), 'activated' => esc_html__( 'WP Mail SMTP Installed & Activated', 'wpforms-lite' ), 'install_now' => esc_html__( 'Install Now', 'wpforms-lite' ), 'activate_now' => esc_html__( 'Activate Now', 'wpforms-lite' ), 'download_now' => esc_html__( 'Download Now', 'wpforms-lite' ), 'plugins_page' => esc_html__( 'Go to Plugins page', 'wpforms-lite' ), 'error_could_not_install' => $error_could_not_install, 'error_could_not_activate' => $error_could_not_activate, 'manual_install_url' => $this->config['lite_download_url'], 'manual_activate_url' => admin_url( 'plugins.php' ), 'smtp_settings_button' => esc_html__( 'Go to SMTP Settings', 'wpforms-lite' ), ); } /** * Generate and output page HTML. * * @since 1.5.7 */ public function output() { echo '<div id="wpforms-admin-smtp" class="wrap wpforms-admin-wrap wpforms-admin-plugin-landing">'; $this->output_section_heading(); $this->output_section_screenshot(); $this->output_section_step_install(); $this->output_section_step_setup(); echo '</div>'; } /** * Generate and output heading section HTML. * * @since 1.5.7 */ protected function output_section_heading() { // Heading section. printf( '<section class="top"> <img class="img-top" src="%1$s" srcset="%2$s 2x" alt="%3$s"/> <h1>%4$s</h1> <p>%5$s</p> </section>', esc_url( WPFORMS_PLUGIN_URL . 'assets/images/smtp/wpforms-wpmailsmtp.png' ), esc_url( WPFORMS_PLUGIN_URL . 'assets/images/smtp/wpforms-wpmailsmtp@2x.png' ), esc_attr__( 'WPForms ♥ WP Mail SMTP', 'wpforms-lite' ), esc_html__( 'Making Email Deliverability Easy for WordPress', 'wpforms-lite' ), esc_html__( 'WP Mail SMTP allows you to easily set up WordPress to use a trusted provider to reliably send emails, including form notifications. Built by the same folks behind WPForms.', 'wpforms-lite' ) ); } /** * Generate and output screenshot section HTML. * * @since 1.5.7 */ protected function output_section_screenshot() { // Screenshot section. printf( '<section class="screenshot"> <div class="cont"> <img src="%1$s" alt="%2$s"/> <a href="%3$s" class="hover" data-lity></a> </div> <ul> <li>%4$s</li> <li>%5$s</li> <li>%6$s</li> <li>%7$s</li> </ul> </section>', esc_url( WPFORMS_PLUGIN_URL . 'assets/images/smtp/screenshot-tnail.png' ), esc_attr__( 'WP Mail SMTP screenshot', 'wpforms-lite' ), esc_url( WPFORMS_PLUGIN_URL . 'assets/images/smtp/screenshot-full.png' ), esc_html__( 'Over 1,000,000 websites use WP Mail SMTP.', 'wpforms-lite' ), esc_html__( 'Send emails authenticated via trusted parties.', 'wpforms-lite' ), esc_html__( 'Transactional Mailers: Pepipost, SendinBlue, Mailgun, SendGrid, Amazon SES.', 'wpforms-lite' ), esc_html__( 'Web Mailers: Gmail, G Suite, Office 365, Outlook.com.', 'wpforms-lite' ) ); } /** * Generate and output step 'Install' section HTML. * * @since 1.5.7 */ protected function output_section_step_install() { $step = $this->get_data_step_install(); if ( empty( $step ) ) { return; } printf( '<section class="step step-install"> <aside class="num"> <img src="%1$s" alt="%2$s" /> <i class="loader hidden"></i> </aside> <div> <h2>%3$s</h2> <p>%4$s</p> <button class="button %5$s" data-plugin="%6$s" data-action="%7$s">%8$s</button> </div> </section>', esc_url( WPFORMS_PLUGIN_URL . 'assets/images/' . $step['icon'] ), esc_attr__( 'Step 1', 'wpforms-lite' ), esc_html__( 'Install and Activate WP Mail SMTP', 'wpforms-lite' ), esc_html__( 'Install WP Mail SMTP from the WordPress.org plugin repository.', 'wpforms-lite' ), esc_attr( $step['button_class'] ), esc_attr( $step['plugin'] ), esc_attr( $step['button_action'] ), esc_html( $step['button_text'] ) ); } /** * Generate and output step 'Setup' section HTML. * * @since 1.5.7 */ protected function output_section_step_setup() { $step = $this->get_data_step_setup(); if ( empty( $step ) ) { return; } printf( '<section class="step step-setup %1$s"> <aside class="num"> <img src="%2$s" alt="%3$s" /> <i class="loader hidden"></i> </aside> <div> <h2>%4$s</h2> <p>%5$s</p> <button class="button %6$s" data-url="%7$s">%8$s</button> </div> </section>', esc_attr( $step['section_class'] ), esc_url( WPFORMS_PLUGIN_URL . 'assets/images/' . $step['icon'] ), esc_attr__( 'Step 2', 'wpforms-lite' ), esc_html__( 'Set Up WP Mail SMTP', 'wpforms-lite' ), esc_html__( 'Select and configure your mailer.', 'wpforms-lite' ), esc_attr( $step['button_class'] ), esc_url( admin_url( $this->config['smtp_settings'] ) ), esc_html( $step['button_text'] ) ); } /** * Step 'Install' data. * * @since 1.5.7 * * @return array Step data. */ protected function get_data_step_install() { $step = array(); $this->output_data['all_plugins'] = get_plugins(); $this->output_data['plugin_installed'] = array_key_exists( $this->config['lite_plugin'], $this->output_data['all_plugins'] ); $this->output_data['pro_plugin_installed'] = array_key_exists( $this->config['pro_plugin'], $this->output_data['all_plugins'] ); $this->output_data['plugin_activated'] = false; $this->output_data['plugin_setup'] = false; if ( ! $this->output_data['plugin_installed'] && ! $this->output_data['pro_plugin_installed'] ) { $step['icon'] = 'step-1.svg'; $step['button_text'] = esc_html__( 'Install WP Mail SMTP', 'wpforms-lite' ); $step['button_class'] = ''; $step['button_action'] = 'install'; $step['plugin'] = $this->config['lite_download_url']; } else { $this->output_data['plugin_activated'] = $this->is_smtp_activated(); $this->output_data['plugin_setup'] = $this->is_smtp_configured(); $step['icon'] = $this->output_data['plugin_activated'] ? 'step-complete.svg' : 'step-1.svg'; $step['button_text'] = $this->output_data['plugin_activated'] ? esc_html__( 'WP Mail SMTP Installed & Activated', 'wpforms-lite' ) : esc_html__( 'Activate WP Mail SMTP', 'wpforms-lite' ); $step['button_class'] = $this->output_data['plugin_activated'] ? 'grey disabled' : ''; $step['button_action'] = $this->output_data['plugin_activated'] ? '' : 'activate'; $step['plugin'] = $this->output_data['pro_plugin_installed'] ? $this->config['pro_plugin'] : $this->config['lite_plugin']; } return $step; } /** * Step 'Setup' data. * * @since 1.5.7 * * @return array Step data. */ protected function get_data_step_setup() { $step = array(); $step['icon'] = 'step-2.svg'; $step['section_class'] = $this->output_data['plugin_activated'] ? '' : 'grey'; $step['button_text'] = esc_html__( 'Start Setup', 'wpforms-lite' ); $step['button_class'] = 'grey disabled'; if ( $this->output_data['plugin_setup'] ) { $step['icon'] = 'step-complete.svg'; $step['section_class'] = ''; $step['button_text'] = esc_html__( 'Go to SMTP settings', 'wpforms-lite' ); } else { $step['button_class'] = $this->output_data['plugin_activated'] ? '' : 'grey disabled'; } return $step; } /** * Ajax endpoint. Check plugin setup status. * Used to properly init step 'Setup' section after completing step 'Install'. * * @since 1.5.7 */ public function ajax_check_plugin_status() { // Security checks. if ( ! check_ajax_referer( 'wpforms-admin', 'nonce', false ) || ! wpforms_current_user_can() ) { wp_send_json_error( array( 'error' => esc_html__( 'You do not have permission.', 'wpforms-lite' ), ) ); } $result = array(); if ( ! $this->is_smtp_activated() ) { wp_send_json_error( array( 'error' => esc_html__( 'Plugin unavailable.', 'wpforms-lite' ), ) ); } $result['setup_status'] = (int) $this->is_smtp_configured(); $result['license_level'] = wp_mail_smtp()->get_license_type(); wp_send_json_success( $result ); } /** * Get $phpmailer instance. * * @since 1.5.7 * * @return \PHPMailer Instance of PHPMailer. */ protected function get_phpmailer() { global $phpmailer; if ( ! is_object( $phpmailer ) || ! is_a( $phpmailer, 'PHPMailer' ) ) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; $phpmailer = new \PHPMailer( true ); // phpcs:ignore } return $phpmailer; } /** * Whether WP Mail SMTP plugin configured or not. * * @since 1.5.7 * * @return bool True if some mailer is selected and configured properly. */ protected function is_smtp_configured() { if ( ! $this->is_smtp_activated() ) { return false; } $phpmailer = $this->get_phpmailer(); $mailer = \WPMailSMTP\Options::init()->get( 'mail', 'mailer' ); $is_mailer_complete = wp_mail_smtp()->get_providers()->get_mailer( $mailer, $phpmailer )->is_mailer_complete(); return 'mail' !== $mailer && $is_mailer_complete; } /** * Whether WP Mail SMTP plugin active or not. * * @since 1.5.7 * * @return bool True if SMTP plugin is active. */ protected function is_smtp_activated() { return function_exists( 'wp_mail_smtp' ) && ( is_plugin_active( $this->config['lite_plugin'] ) || is_plugin_active( $this->config['pro_plugin'] ) ); } /** * Redirect to SMTP settings page. * * @since 1.5.7 */ public function redirect_to_smtp_settings() { // Redirect to SMTP plugin if it is activated. if ( $this->is_smtp_configured() ) { wp_safe_redirect( admin_url( $this->config['smtp_settings'] ) ); exit; } } } Pages/Analytics.php 0000666 00000036507 15214223200 0010251 0 ustar 00 <?php namespace WPForms\Admin\Pages; /** * Analytics Sub-page. * * @since 1.5.7 */ class Analytics { /** * Admin menu page slug. * * @since 1.5.7 * * @var string */ const SLUG = 'wpforms-analytics'; /** * Configuration. * * @since 1.5.7 * * @var array */ private $config = array( 'lite_plugin' => 'google-analytics-for-wordpress/googleanalytics.php', 'lite_download_url' => 'https://downloads.wordpress.org/plugin/google-analytics-for-wordpress.zip', 'pro_plugin' => 'google-analytics-premium/googleanalytics-premium.php', 'forms_addon' => 'monsterinsights-forms/monsterinsights-forms.php', 'mi_forms_addon_page' => 'https://www.monsterinsights.com/addon/forms/?utm_source=wpformsplugin&utm_medium=link&utm_campaign=analytics-page', 'mi_onboarding' => 'admin.php?page=monsterinsights-onboarding', 'mi_addons' => 'admin.php?page=monsterinsights_settings#/addons', 'mi_forms' => 'admin.php?page=monsterinsights_reports#/forms', ); /** * Runtime data used for generating page HTML. * * @since 1.5.7 * * @var array */ private $output_data = array(); /** * Constructor. * * @since 1.5.7 */ public function __construct() { if ( ! \wpforms_current_user_can() ) { return; } $this->hooks(); } /** * Hooks. * * @since 1.5.7 */ public function hooks() { if ( wp_doing_ajax() ) { add_action( 'wp_ajax_wpforms_analytics_page_check_plugin_status', array( $this, 'ajax_check_plugin_status' ) ); } // Check what page we are on. $page = isset( $_GET['page'] ) ? \sanitize_key( \wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.CSRF.NonceVerification // Only load if we are actually on the Analytics page. if ( self::SLUG !== $page ) { return; } add_action( 'admin_init', array( $this, 'redirect_to_mi_forms' ) ); add_filter( 'wpforms_admin_header', '__return_false' ); add_action( 'wpforms_admin_page', array( $this, 'output' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); // Hook for addons. do_action( 'wpforms_admin_pages_analytics_hooks' ); } /** * Enqueue JS and CSS files. * * @since 1.5.7 */ public function enqueue_assets() { $min = \wpforms_get_min_suffix(); // 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 ); wp_enqueue_script( 'wpforms-admin-page-analytics', WPFORMS_PLUGIN_URL . "assets/js/components/admin/pages/analytics{$min}.js", array( 'jquery' ), WPFORMS_VERSION, true ); \wp_localize_script( 'wpforms-admin-page-analytics', 'wpforms_pluginlanding', $this->get_js_strings() ); } /** * JS Strings. * * @since 1.5.7 * * @return array Array of strings. */ protected function get_js_strings() { $error_could_not_install = sprintf( wp_kses( /* translators: %s - Lite plugin download URL. */ __( 'Could not install plugin. Please <a href="%s">download</a> and install manually.', 'wpforms-lite' ), array( 'a' => array( 'href' => true, ), ) ), esc_url( $this->config['lite_download_url'] ) ); $error_could_not_activate = sprintf( wp_kses( /* translators: %s - Lite plugin download URL. */ __( 'Could not activate plugin. Please activate from the <a href="%s">Plugins page</a>.', 'wpforms-lite' ), array( 'a' => array( 'href' => true, ), ) ), esc_url( admin_url( 'plugins.php' ) ) ); return array( 'installing' => esc_html__( 'Installing...', 'wpforms-lite' ), 'activating' => esc_html__( 'Activating...', 'wpforms-lite' ), 'activated' => esc_html__( 'MonsterInsights Installed & Activated', 'wpforms-lite' ), 'install_now' => esc_html__( 'Install Now', 'wpforms-lite' ), 'activate_now' => esc_html__( 'Activate Now', 'wpforms-lite' ), 'download_now' => esc_html__( 'Download Now', 'wpforms-lite' ), 'plugins_page' => esc_html__( 'Go to Plugins page', 'wpforms-lite' ), 'error_could_not_install' => $error_could_not_install, 'error_could_not_activate' => $error_could_not_activate, 'mi_manual_install_url' => $this->config['lite_download_url'], 'mi_manual_activate_url' => admin_url( 'plugins.php' ), ); } /** * Generate and output page HTML. * * @since 1.5.7 */ public function output() { echo '<div id="wpforms-admin-analytics" class="wrap wpforms-admin-wrap wpforms-admin-plugin-landing">'; $this->output_section_heading(); $this->output_section_screenshot(); $this->output_section_step_install(); $this->output_section_step_setup(); $this->output_section_step_addon(); echo '</div>'; } /** * Generate and output heading section HTML. * * @since 1.5.7 */ public function output_section_heading() { // Heading section. printf( '<section class="top"> <img class="img-top" src="%1$s" srcset="%2$s 2x" alt="%3$s"/> <h1>%4$s</h1> <p>%5$s</p> </section>', esc_url( WPFORMS_PLUGIN_URL . 'assets/images/analytics/wpforms-monsterinsights.png' ), esc_url( WPFORMS_PLUGIN_URL . 'assets/images/analytics/wpforms-monsterinsights@2x.png' ), esc_attr__( 'WPForms ♥ MonsterInsights', 'wpforms-lite' ), esc_html__( 'The Best Google Analytics Plugin for WordPress', 'wpforms-lite' ), esc_html__( 'MonsterInsights connects WPForms to Google Analytics, providing a powerful integration with their Forms addon. MonsterInsights is a sister company of WPForms.', 'wpforms-lite' ) ); } /** * Generate and output heading section HTML. * * @since 1.5.7 */ protected function output_section_screenshot() { // Screenshot section. printf( '<section class="screenshot"> <div class="cont"> <img src="%1$s" alt="%2$s"/> <a href="%3$s" class="hover" data-lity></a> </div> <ul> <li>%4$s</li> <li>%5$s</li> <li>%6$s</li> <li>%7$s</li> </ul> </section>', esc_url( WPFORMS_PLUGIN_URL . 'assets/images/analytics/screenshot-tnail.jpg' ), esc_attr__( 'Analytics screenshot', 'wpforms-lite' ), esc_url( WPFORMS_PLUGIN_URL . 'assets/images/analytics/screenshot-full.jpg' ), esc_html__( 'Track form impressions and conversions.', 'wpforms-lite' ), esc_html__( 'View form conversion rates from WordPress.', 'wpforms-lite' ), esc_html__( 'Complete UTM tracking with form entries.', 'wpforms-lite' ), esc_html__( 'Automatic integration with WPForms.', 'wpforms-lite' ) ); } /** * Generate and output step 'Install' section HTML. * * @since 1.5.7 */ protected function output_section_step_install() { $step = $this->get_data_step_install(); if ( empty( $step ) ) { return; } printf( '<section class="step step-install"> <aside class="num"> <img src="%1$s" alt="%2$s" /> <i class="loader hidden"></i> </aside> <div> <h2>%3$s</h2> <p>%4$s</p> <button class="button %5$s" data-plugin="%6$s" data-action="%7$s">%8$s</button> </div> </section>', esc_url( WPFORMS_PLUGIN_URL . 'assets/images/' . $step['icon'] ), esc_attr__( 'Step 1', 'wpforms-lite' ), esc_html__( 'Install & Activate MonsterInsights', 'wpforms-lite' ), esc_html__( 'Track form impressions and conversions.', 'wpforms-lite' ), esc_attr( $step['button_class'] ), esc_attr( $step['plugin'] ), esc_attr( $step['button_action'] ), esc_html( $step['button_text'] ) ); } /** * Generate and output step 'Setup' section HTML. * * @since 1.5.7 */ protected function output_section_step_setup() { $step = $this->get_data_step_setup(); if ( empty( $step ) ) { return; } printf( '<section class="step step-setup %1$s"> <aside class="num"> <img src="%2$s" alt="%3$s" /> <i class="loader hidden"></i> </aside> <div> <h2>%4$s</h2> <p>%5$s</p> <button class="button %6$s" data-url="%7$s">%8$s</button> </div> </section>', esc_attr( $step['section_class'] ), esc_url( WPFORMS_PLUGIN_URL . 'assets/images/' . $step['icon'] ), esc_attr__( 'Step 2', 'wpforms-lite' ), esc_html__( 'Setup MonsterInsights', 'wpforms-lite' ), esc_html__( 'MonsterInsights has an intuitive setup wizard to guide you through the setup process.', 'wpforms-lite' ), esc_attr( $step['button_class'] ), esc_url( admin_url( $this->config['mi_onboarding'] ) ), esc_html( $step['button_text'] ) ); } /** * Generate and output step 'Addon' section HTML. * * @since 1.5.7 */ protected function output_section_step_addon() { $step = $this->get_data_step_addon(); if ( empty( $step ) ) { return; } printf( '<section class="step step-addon %1$s"> <aside class="num"> <img src="%2$s" alt="%3$s" /> <i class="loader hidden"></i> </aside> <div> <h2>%4$s</h2> <p>%5$s</p> <button class="button %6$s" data-url="%7$s">%8$s</button> </div> </section>', esc_attr( $step['section_class'] ), esc_url( WPFORMS_PLUGIN_URL . 'assets/images/step-3.svg' ), esc_attr__( 'Step 3', 'wpforms-lite' ), esc_html__( 'Get Form Conversion Tracking', 'wpforms-lite' ), esc_html__( 'With the MonsterInsights Form addon you can easily track your form views, entries, conversion rates, and more.', 'wpforms-lite' ), esc_attr( $step['button_class'] ), esc_url( $step['button_url'] ), esc_html( $step['button_text'] ) ); } /** * Step 'Install' data. * * @since 1.5.7 * * @return array Step data. */ protected function get_data_step_install() { $this->output_data['all_plugins'] = get_plugins(); $this->output_data['plugin_installed'] = array_key_exists( $this->config['lite_plugin'], $this->output_data['all_plugins'] ); $this->output_data['plugin_activated'] = false; $this->output_data['pro_plugin_installed'] = array_key_exists( $this->config['pro_plugin'], $this->output_data['all_plugins'] ); $this->output_data['pro_plugin_activated'] = false; $step = array(); if ( ! $this->output_data['plugin_installed'] && ! $this->output_data['pro_plugin_installed'] ) { $step['icon'] = 'step-1.svg'; $step['button_text'] = esc_html__( 'Install MonsterInsights', 'wpforms-lite' ); $step['button_class'] = ''; $step['button_action'] = 'install'; $step['plugin'] = $this->config['lite_download_url']; } else { $this->output_data['plugin_activated'] = is_plugin_active( $this->config['lite_plugin'] ) || is_plugin_active( $this->config['pro_plugin'] ); $step['icon'] = $this->output_data['plugin_activated'] ? 'step-complete.svg' : 'step-1.svg'; $step['button_text'] = $this->output_data['plugin_activated'] ? esc_html__( 'MonsterInsights Installed & Activated', 'wpforms-lite' ) : esc_html__( 'Activate MonsterInsights', 'wpforms-lite' ); $step['button_class'] = $this->output_data['plugin_activated'] ? 'grey disabled' : ''; $step['button_action'] = $this->output_data['plugin_activated'] ? '' : 'activate'; $step['plugin'] = $this->output_data['pro_plugin_installed'] ? $this->config['pro_plugin'] : $this->config['lite_plugin']; } return $step; } /** * Step 'Setup' data. * * @since 1.5.7 * * @return array Step data. */ protected function get_data_step_setup() { $step = array(); $this->output_data['plugin_setup'] = false; if ( $this->output_data['plugin_activated'] ) { $this->output_data['plugin_setup'] = '' !== (string) \monsterinsights_get_ua(); } $step['icon'] = 'step-2.svg'; $step['section_class'] = $this->output_data['plugin_activated'] ? '' : 'grey'; $step['button_text'] = esc_html__( 'Run Setup Wizard', 'wpforms-lite' ); $step['button_class'] = 'grey disabled'; if ( $this->output_data['plugin_setup'] ) { $step['icon'] = 'step-complete.svg'; $step['section_class'] = ''; $step['button_text'] = esc_html__( 'Setup Complete', 'wpforms-lite' ); } else { $step['button_class'] = $this->output_data['plugin_activated'] ? '' : 'grey disabled'; } return $step; } /** * Step 'Addon' data. * * @since 1.5.7 * * @return array Step data. */ protected function get_data_step_addon() { $step = array(); $step['icon'] = 'step-3.svg'; $step['section_class'] = $this->output_data['plugin_setup'] ? '' : 'grey'; $step['button_text'] = esc_html__( 'Learn More', 'wpforms-lite' ); $step['button_class'] = 'grey disabled'; $step['button_url'] = ''; $plugin_license_level = false; if ( $this->output_data['plugin_activated'] ) { $mi = \MonsterInsights(); $plugin_license_level = 'lite'; if ( is_object( $mi->license ) && method_exists( $mi->license, 'license_can' ) ) { $plugin_license_level = $mi->license->license_can( 'plus' ) ? 'lite' : $plugin_license_level; $plugin_license_level = $mi->license->license_can( 'pro' ) || $mi->license->license_can( 'agency' ) ? 'pro' : $plugin_license_level; } } switch ( $plugin_license_level ) { case 'lite': $step['button_url'] = $this->config['mi_forms_addon_page']; $step['button_class'] = ''; break; case 'pro': $addon_installed = array_key_exists( $this->config['forms_addon'], $this->output_data['all_plugins'] ); $step['button_text'] = $addon_installed ? esc_html__( 'Activate Now', 'wpforms-lite' ) : esc_html__( 'Install Now', 'wpforms-lite' ); $step['button_url'] = admin_url( $this->config['mi_addons'] ); $step['button_class'] = ''; break; } return $step; } /** * Ajax endpoint. Check plugin setup status. * Used to properly init step 2 section after completing step 1. * * @since 1.5.7 */ public function ajax_check_plugin_status() { // Security checks. if ( ! check_ajax_referer( 'wpforms-admin', 'nonce', false ) || ! wpforms_current_user_can() ) { wp_send_json_error( array( 'error' => esc_html__( 'You do not have permission.', 'wpforms-lite' ), ) ); } $result = array(); if ( ! function_exists( 'MonsterInsights' ) || ! function_exists( 'monsterinsights_get_ua' ) ) { wp_send_json_error( array( 'error' => esc_html__( 'Plugin unavailable.', 'wpforms-lite' ), ) ); } $result['setup_status'] = (int) ( '' !== (string) \monsterinsights_get_ua() ); $mi = \MonsterInsights(); $result['license_level'] = 'lite'; $result['step3_button_url'] = $this->config['mi_forms_addon_page']; if ( is_object( $mi->license ) && method_exists( $mi->license, 'license_can' ) ) { $result['license_level'] = $mi->license->license_can( 'pro' ) || $mi->license->license_can( 'agency' ) ? 'pro' : $result['license_level']; $result['step3_button_url'] = admin_url( $this->config['mi_addons'] ); } $result['addon_installed'] = (int) array_key_exists( $this->config['forms_addon'], get_plugins() ); wp_send_json_success( $result ); } /** * Redirect to MI forms reporting page. * We need this function because `is_plugin_active()` available only after `admin_init` action. * * @since 1.5.7 */ public function redirect_to_mi_forms() { require_once ABSPATH . 'wp-admin/includes/plugin.php'; // Redirect to MI Forms addon if it is activated. if ( is_plugin_active( $this->config['forms_addon'] ) ) { wp_safe_redirect( admin_url( $this->config['mi_forms'] ) ); exit; } } }
dvadf
dvadf
| ver. 1.4 |
Github
|
.
| PHP 7.0.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings