menu
3 years ago
notices
2 years ago
ui
3 years ago
admin-notices.php
2 years ago
admin.php
2 years ago
canary-deployment.php
3 years ago
feedback.php
2 years ago
feedback.php
190 lines
| 1 | <?php |
| 2 | namespace Elementor\Core\Admin; |
| 3 | |
| 4 | use Elementor\Api; |
| 5 | use Elementor\Core\Base\Module; |
| 6 | use Elementor\Plugin; |
| 7 | use Elementor\Tracker; |
| 8 | use Elementor\Utils; |
| 9 | |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | exit; // Exit if accessed directly. |
| 12 | } |
| 13 | |
| 14 | class Feedback extends Module { |
| 15 | |
| 16 | /** |
| 17 | * @since 2.2.0 |
| 18 | * @access public |
| 19 | */ |
| 20 | public function __construct() { |
| 21 | add_action( 'current_screen', function () { |
| 22 | if ( ! $this->is_plugins_screen() ) { |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_feedback_dialog_scripts' ] ); |
| 27 | } ); |
| 28 | |
| 29 | // Ajax. |
| 30 | add_action( 'wp_ajax_elementor_deactivate_feedback', [ $this, 'ajax_elementor_deactivate_feedback' ] ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Get module name. |
| 35 | * |
| 36 | * Retrieve the module name. |
| 37 | * |
| 38 | * @since 1.7.0 |
| 39 | * @access public |
| 40 | * |
| 41 | * @return string Module name. |
| 42 | */ |
| 43 | public function get_name() { |
| 44 | return 'feedback'; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Enqueue feedback dialog scripts. |
| 49 | * |
| 50 | * Registers the feedback dialog scripts and enqueues them. |
| 51 | * |
| 52 | * @since 1.0.0 |
| 53 | * @access public |
| 54 | */ |
| 55 | public function enqueue_feedback_dialog_scripts() { |
| 56 | add_action( 'admin_footer', [ $this, 'print_deactivate_feedback_dialog' ] ); |
| 57 | |
| 58 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 59 | |
| 60 | wp_register_script( |
| 61 | 'elementor-admin-feedback', |
| 62 | ELEMENTOR_ASSETS_URL . 'js/admin-feedback' . $suffix . '.js', |
| 63 | [ |
| 64 | 'elementor-common', |
| 65 | ], |
| 66 | ELEMENTOR_VERSION, |
| 67 | true |
| 68 | ); |
| 69 | |
| 70 | wp_enqueue_script( 'elementor-admin-feedback' ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @since 2.3.0 |
| 75 | * @deprecated 3.1.0 |
| 76 | */ |
| 77 | public function localize_feedback_dialog_settings() { |
| 78 | Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0' ); |
| 79 | |
| 80 | return []; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Print deactivate feedback dialog. |
| 85 | * |
| 86 | * Display a dialog box to ask the user why he deactivated Elementor. |
| 87 | * |
| 88 | * Fired by `admin_footer` filter. |
| 89 | * |
| 90 | * @since 1.0.0 |
| 91 | * @access public |
| 92 | */ |
| 93 | public function print_deactivate_feedback_dialog() { |
| 94 | $deactivate_reasons = [ |
| 95 | 'no_longer_needed' => [ |
| 96 | 'title' => esc_html__( 'I no longer need the plugin', 'elementor' ), |
| 97 | 'input_placeholder' => '', |
| 98 | ], |
| 99 | 'found_a_better_plugin' => [ |
| 100 | 'title' => esc_html__( 'I found a better plugin', 'elementor' ), |
| 101 | 'input_placeholder' => esc_html__( 'Please share which plugin', 'elementor' ), |
| 102 | ], |
| 103 | 'couldnt_get_the_plugin_to_work' => [ |
| 104 | 'title' => esc_html__( 'I couldn\'t get the plugin to work', 'elementor' ), |
| 105 | 'input_placeholder' => '', |
| 106 | ], |
| 107 | 'temporary_deactivation' => [ |
| 108 | 'title' => esc_html__( 'It\'s a temporary deactivation', 'elementor' ), |
| 109 | 'input_placeholder' => '', |
| 110 | ], |
| 111 | 'elementor_pro' => [ |
| 112 | 'title' => esc_html__( 'I have Elementor Pro', 'elementor' ), |
| 113 | 'input_placeholder' => '', |
| 114 | 'alert' => esc_html__( 'Wait! Don\'t deactivate Elementor. You have to activate both Elementor and Elementor Pro in order for the plugin to work.', 'elementor' ), |
| 115 | ], |
| 116 | 'other' => [ |
| 117 | 'title' => esc_html__( 'Other', 'elementor' ), |
| 118 | 'input_placeholder' => esc_html__( 'Please share the reason', 'elementor' ), |
| 119 | ], |
| 120 | ]; |
| 121 | |
| 122 | ?> |
| 123 | <div id="elementor-deactivate-feedback-dialog-wrapper"> |
| 124 | <div id="elementor-deactivate-feedback-dialog-header"> |
| 125 | <i class="eicon-elementor-square" aria-hidden="true"></i> |
| 126 | <span id="elementor-deactivate-feedback-dialog-header-title"><?php echo esc_html__( 'Quick Feedback', 'elementor' ); ?></span> |
| 127 | </div> |
| 128 | <form id="elementor-deactivate-feedback-dialog-form" method="post"> |
| 129 | <?php |
| 130 | wp_nonce_field( '_elementor_deactivate_feedback_nonce' ); |
| 131 | ?> |
| 132 | <input type="hidden" name="action" value="elementor_deactivate_feedback" /> |
| 133 | |
| 134 | <div id="elementor-deactivate-feedback-dialog-form-caption"><?php echo esc_html__( 'If you have a moment, please share why you are deactivating Elementor:', 'elementor' ); ?></div> |
| 135 | <div id="elementor-deactivate-feedback-dialog-form-body"> |
| 136 | <?php foreach ( $deactivate_reasons as $reason_key => $reason ) : ?> |
| 137 | <div class="elementor-deactivate-feedback-dialog-input-wrapper"> |
| 138 | <input id="elementor-deactivate-feedback-<?php echo esc_attr( $reason_key ); ?>" class="elementor-deactivate-feedback-dialog-input" type="radio" name="reason_key" value="<?php echo esc_attr( $reason_key ); ?>" /> |
| 139 | <label for="elementor-deactivate-feedback-<?php echo esc_attr( $reason_key ); ?>" class="elementor-deactivate-feedback-dialog-label"><?php echo esc_html( $reason['title'] ); ?></label> |
| 140 | <?php if ( ! empty( $reason['input_placeholder'] ) ) : ?> |
| 141 | <input class="elementor-feedback-text" type="text" name="reason_<?php echo esc_attr( $reason_key ); ?>" placeholder="<?php echo esc_attr( $reason['input_placeholder'] ); ?>" /> |
| 142 | <?php endif; ?> |
| 143 | <?php if ( ! empty( $reason['alert'] ) ) : ?> |
| 144 | <div class="elementor-feedback-text"><?php echo esc_html( $reason['alert'] ); ?></div> |
| 145 | <?php endif; ?> |
| 146 | </div> |
| 147 | <?php endforeach; ?> |
| 148 | </div> |
| 149 | </form> |
| 150 | </div> |
| 151 | <?php |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Ajax elementor deactivate feedback. |
| 156 | * |
| 157 | * Send the user feedback when Elementor is deactivated. |
| 158 | * |
| 159 | * Fired by `wp_ajax_elementor_deactivate_feedback` action. |
| 160 | * |
| 161 | * @since 1.0.0 |
| 162 | * @access public |
| 163 | */ |
| 164 | public function ajax_elementor_deactivate_feedback() { |
| 165 | $wpnonce = Utils::get_super_global_value( $_POST, '_wpnonce' ); // phpcs:ignore -- Nonce verification is made in `wp_verify_nonce()`. |
| 166 | if ( ! wp_verify_nonce( $wpnonce, '_elementor_deactivate_feedback_nonce' ) ) { |
| 167 | wp_send_json_error(); |
| 168 | } |
| 169 | |
| 170 | if ( ! current_user_can( 'activate_plugins' ) ) { |
| 171 | wp_send_json_error( 'Permission denied' ); |
| 172 | } |
| 173 | |
| 174 | $reason_key = Utils::get_super_global_value( $_POST, 'reason_key' ) ?? ''; |
| 175 | $reason_text = Utils::get_super_global_value( $_POST, "reason_{$reason_key}" ) ?? ''; |
| 176 | |
| 177 | Api::send_feedback( $reason_key, $reason_text ); |
| 178 | |
| 179 | wp_send_json_success(); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * @since 2.3.0 |
| 184 | * @access private |
| 185 | */ |
| 186 | private function is_plugins_screen() { |
| 187 | return in_array( get_current_screen()->id, [ 'plugins', 'plugins-network' ] ); |
| 188 | } |
| 189 | } |
| 190 |