builder
2 weeks ago
form-migrator
2 weeks ago
plugin-updates
8 years ago
settings
2 weeks ago
views
2 weeks ago
class-evf-admin-addons.php
4 months ago
class-evf-admin-assets.php
2 weeks ago
class-evf-admin-builder.php
2 months ago
class-evf-admin-dashboard.php
2 weeks ago
class-evf-admin-editor.php
4 years ago
class-evf-admin-embed-wizard.php
2 years ago
class-evf-admin-entries-table-list.php
2 months ago
class-evf-admin-entries.php
2 months ago
class-evf-admin-form-templates.php
2 weeks ago
class-evf-admin-forms-table-list.php
4 months ago
class-evf-admin-forms.php
4 months ago
class-evf-admin-import-export.php
2 weeks ago
class-evf-admin-menus.php
2 weeks ago
class-evf-admin-notices.php
4 months ago
class-evf-admin-preview-confirmation.php
11 months ago
class-evf-admin-settings.php
2 weeks ago
class-evf-admin-tools.php
2 months ago
class-evf-admin-welcome.php
2 years ago
class-evf-admin.php
1 month ago
class-evf-base-list-table.php
4 months ago
evf-admin-functions.php
2 weeks ago
class-evf-admin.php
265 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Admin |
| 4 | * |
| 5 | * @package EverestForms\Admin |
| 6 | * @version 1.0.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * EVF_Admin class. |
| 13 | */ |
| 14 | class EVF_Admin { |
| 15 | |
| 16 | /** |
| 17 | * Constructor. |
| 18 | */ |
| 19 | public function __construct() { |
| 20 | add_action( 'init', array( $this, 'includes' ) ); |
| 21 | add_action( 'current_screen', array( $this, 'maybe_load_integrations' ) ); |
| 22 | add_action( 'admin_init', array( $this, 'buffer' ), 1 ); |
| 23 | add_action( 'admin_init', array( $this, 'addon_actions' ) ); |
| 24 | add_action( 'admin_init', array( $this, 'template_actions' ) ); |
| 25 | add_action( 'admin_init', array( $this, 'admin_redirects' ) ); |
| 26 | add_action( 'admin_footer', 'evf_print_js', 25 ); |
| 27 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 28 | add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Output buffering allows admin screens to make redirects later on. |
| 33 | */ |
| 34 | public function buffer() { |
| 35 | ob_start(); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Include any classes we need within admin. |
| 40 | */ |
| 41 | public function includes() { |
| 42 | include_once __DIR__ . '/evf-admin-functions.php'; |
| 43 | include_once __DIR__ . '/class-evf-admin-menus.php'; |
| 44 | include_once __DIR__ . '/class-evf-admin-notices.php'; |
| 45 | include_once __DIR__ . '/class-evf-admin-assets.php'; |
| 46 | include_once __DIR__ . '/class-evf-admin-editor.php'; |
| 47 | include_once __DIR__ . '/class-evf-admin-forms.php'; |
| 48 | include_once __DIR__ . '/class-evf-admin-entries.php'; |
| 49 | include_once __DIR__ . '/class-evf-admin-import-export.php'; |
| 50 | |
| 51 | // Setup/welcome. |
| 52 | if ( ! empty( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 53 | switch ( $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 54 | case 'evf-dashboard': |
| 55 | include_once __DIR__ . '/class-evf-admin-dashboard.php'; |
| 56 | break; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | include_once __DIR__ . '/form-migrator/abstract-evf-form-migrator.php'; |
| 61 | include_once __DIR__ . '/form-migrator/class-evf-fm-contactform7.php'; |
| 62 | include_once __DIR__ . '/form-migrator/class-evf-fm-wpforms.php'; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Handle redirects after addon activate/deactivate. |
| 67 | */ |
| 68 | public function addon_actions() { |
| 69 | if ( isset( $_GET['page'], $_REQUEST['action'] ) && 'evf-addons' === $_GET['page'] ) { |
| 70 | $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); |
| 71 | $plugin = isset( $_REQUEST['plugin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['plugin'] ) ) : false; |
| 72 | |
| 73 | if ( 'evf-addons-refresh' === $action ) { |
| 74 | if ( empty( $_GET['evf-addons-nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['evf-addons-nonce'] ) ), 'refresh' ) ) { |
| 75 | wp_die( esc_html_e( 'Could not verify nonce', 'everest-forms' ) ); |
| 76 | } |
| 77 | foreach ( array( 'evf_pro_license_plan', 'evf_addons_sections_list', 'evf_extensions_section_list' ) as $transient ) { |
| 78 | delete_transient( $transient ); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if ( $plugin && in_array( $action, array( 'activate', 'deactivate' ), true ) ) { |
| 83 | |
| 84 | if ( 'activate' === $action ) { |
| 85 | if ( ! current_user_can( 'activate_plugin', $plugin ) ) { |
| 86 | wp_die( esc_html__( 'Sorry, you are not allowed to activate this plugin.', 'everest-forms' ) ); |
| 87 | } |
| 88 | |
| 89 | check_admin_referer( 'activate-plugin_' . $plugin ); |
| 90 | |
| 91 | activate_plugin( $plugin ); |
| 92 | } elseif ( 'deactivate' === $action ) { |
| 93 | if ( ! current_user_can( 'deactivate_plugins' ) ) { |
| 94 | wp_die( esc_html__( 'Sorry, you are not allowed to deactivate plugins for this site.', 'everest-forms' ) ); |
| 95 | } |
| 96 | |
| 97 | check_admin_referer( 'deactivate-plugin_' . $plugin ); |
| 98 | |
| 99 | deactivate_plugins( $plugin ); |
| 100 | $evf_stats_report_cron = new EVF_Report_Cron(); |
| 101 | $evf_stats_report_cron->deactivate(); |
| 102 | |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // Redirect to the add-ons page. |
| 107 | wp_safe_redirect( admin_url( 'admin.php?page=evf-addons' ) ); |
| 108 | exit; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Handle redirects after template refresh. |
| 114 | */ |
| 115 | public function template_actions() { |
| 116 | if ( isset( $_GET['page'], $_REQUEST['action'] ) && 'evf-builder' === $_GET['page'] ) { |
| 117 | $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); |
| 118 | $templates = EVF_Admin_Form_Templates::get_template_data(); |
| 119 | $templates = is_array( $templates ) ? $templates : array(); |
| 120 | if ( 'evf-template-refresh' === $action ) { |
| 121 | if ( empty( $_GET['evf-template-nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['evf-template-nonce'] ) ), 'refresh' ) ) { |
| 122 | wp_die( esc_html_e( 'Could not verify nonce', 'everest-forms' ) ); |
| 123 | } |
| 124 | |
| 125 | foreach ( array( 'evf_pro_license_plan', 'evf_template_sections', 'evf_template_section', 'evf_template_section_list' ) as $transient ) { |
| 126 | delete_transient( $transient ); |
| 127 | } |
| 128 | |
| 129 | // Redirect to the builder page normally. |
| 130 | wp_safe_redirect( admin_url( 'admin.php?page=evf-builder&create-form=1' ) ); |
| 131 | exit; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Handle redirects to setup/dashboard page after install and updates. |
| 138 | * |
| 139 | * For setup wizard, transient must be present, the user must have access rights, and we must ignore the network/bulk plugin updaters. |
| 140 | */ |
| 141 | public function admin_redirects() { |
| 142 | // Nonced plugin install redirects (whitelisted). |
| 143 | if ( ! empty( $_GET['evf-install-plugin-redirect'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 144 | $plugin_slug = evf_clean( esc_url_raw( wp_unslash( $_GET['evf-install-plugin-redirect'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification. |
| 145 | |
| 146 | $url = admin_url( 'plugin-install.php?tab=search&type=term&s=' . $plugin_slug ); |
| 147 | wp_safe_redirect( $url ); |
| 148 | exit; |
| 149 | } |
| 150 | |
| 151 | // Setup wizard redirect. |
| 152 | if ( get_transient( '_evf_activation_redirect' ) && apply_filters( 'everest_forms_show_dashboard_page', true ) ) { |
| 153 | $do_redirect = true; |
| 154 | $current_page = isset( $_GET['page'] ) ? evf_clean( sanitize_text_field( wp_unslash( $_GET['page'] ) ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification |
| 155 | |
| 156 | // On these pages, or during these events, postpone the redirect. |
| 157 | if ( wp_doing_ajax() || is_network_admin() || ! current_user_can( 'manage_everest_forms' ) ) { |
| 158 | $do_redirect = false; |
| 159 | } |
| 160 | |
| 161 | // On these pages, or during these events, disable the redirect. |
| 162 | if ( 'evf-dashboard' === $current_page || EVF_Admin_Notices::has_notice( 'install' ) || apply_filters( 'everest_forms_prevent_automatic_wizard_redirect', false ) || isset( $_GET['activate-multi'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 163 | delete_transient( '_evf_activation_redirect' ); |
| 164 | $do_redirect = false; |
| 165 | } |
| 166 | |
| 167 | if ( $do_redirect ) { |
| 168 | delete_transient( '_evf_activation_redirect' ); |
| 169 | wp_safe_redirect( admin_url( 'admin.php?page=evf-dashboard' ) ); |
| 170 | exit; |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Change the admin footer text on EverestForms admin pages. |
| 177 | * |
| 178 | * @since 1.0.0 |
| 179 | * @param string $footer_text Footer text. |
| 180 | * @return string |
| 181 | */ |
| 182 | public function admin_footer_text( $footer_text ) { |
| 183 | if ( ! current_user_can( 'manage_everest_forms' ) || ! function_exists( 'evf_get_screen_ids' ) ) { |
| 184 | return $footer_text; |
| 185 | } |
| 186 | $current_screen = get_current_screen(); |
| 187 | |
| 188 | // Removing footer text from builder page. |
| 189 | if ( 'everest-forms_page_evf-builder' === $current_screen->id && isset( $_GET['form_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 190 | add_filter( |
| 191 | 'update_footer', |
| 192 | function () { |
| 193 | return ''; |
| 194 | } |
| 195 | ); |
| 196 | return ''; |
| 197 | } |
| 198 | |
| 199 | $evf_pages = evf_get_screen_ids(); |
| 200 | // Check to make sure we're on a EverestForms admin page. |
| 201 | if ( isset( $current_screen->id ) && apply_filters( 'everest_forms_display_admin_footer_text', in_array( $current_screen->id, $evf_pages, true ) ) ) { |
| 202 | // Change the footer text. |
| 203 | if ( ! get_option( 'everest_forms_admin_footer_text_rated' ) ) { |
| 204 | $footer_text = sprintf( |
| 205 | /* translators: 1: EverestForms 2:: five stars */ |
| 206 | esc_html__( 'If you like %1$s please leave us a %2$s rating. A huge thanks in advance!', 'everest-forms' ), |
| 207 | sprintf( '<strong>%s</strong>', esc_html__( 'Everest Forms', 'everest-forms' ) ), |
| 208 | '<a href="https://wordpress.org/support/plugin/everest-forms/reviews?rate=5#new-post" target="_blank" class="evf-rating-link" data-rated="' . esc_attr__( 'Thanks :)', 'everest-forms' ) . '">★★★★★</a>' |
| 209 | ); |
| 210 | evf_enqueue_js( |
| 211 | " |
| 212 | jQuery( 'a.evf-rating-link' ).on( 'click', function() { |
| 213 | jQuery.post( '" . evf()->ajax_url() . "', { |
| 214 | action: 'everest_forms_rated', |
| 215 | security: '" . wp_create_nonce( 'everest_forms_rated' ) . "' |
| 216 | } ); |
| 217 | jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) ); |
| 218 | }); |
| 219 | " |
| 220 | ); |
| 221 | } else { |
| 222 | $footer_text = esc_html__( 'Thank you for creating with Everest Forms.', 'everest-forms' ); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | return $footer_text; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Add body classes for Everest builder. |
| 231 | * |
| 232 | * @param array $classes Admin body classes. |
| 233 | * @return array |
| 234 | */ |
| 235 | public function admin_body_class( $classes ) { |
| 236 | $screen = get_current_screen(); |
| 237 | $screen_id = $screen ? $screen->id : ''; |
| 238 | |
| 239 | // Check to make sure we're on a EverestForms builder page. |
| 240 | if ( ( isset( $_GET['form_id'] ) || isset( $_GET['create-form'] ) ) && in_array( $screen_id, array( 'everest-forms_page_evf-builder' ), true ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 241 | $classes = isset( $_GET['form_id'] ) ? 'everest-forms-builder' : 'everest-forms-builder-setup'; // phpcs:ignore WordPress.Security.NonceVerification |
| 242 | } |
| 243 | |
| 244 | return $classes; |
| 245 | } |
| 246 | |
| 247 | public function maybe_load_integrations( $screen ) { |
| 248 | if ( ! $screen ) { |
| 249 | return; |
| 250 | } |
| 251 | |
| 252 | if ( ! in_array( $screen->id, evf_get_screen_ids(), true ) ) { |
| 253 | return; |
| 254 | } |
| 255 | |
| 256 | if ( EVF()->integrations ) { |
| 257 | return; |
| 258 | } |
| 259 | |
| 260 | EVF()->integrations = new EVF_Integrations(); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | return new EVF_Admin(); |
| 265 |