cp-feedback.php
92 lines
| 1 | <?php |
| 2 | if ( ! class_exists( 'WCMP_FEEDBACK' ) ) { |
| 3 | class WCMP_FEEDBACK { |
| 4 | |
| 5 | private $feedback_url = 'https://wordpress.dwbooster.com/licensesystem/debug-data.php'; |
| 6 | private $plugin_slug; |
| 7 | private $plugin_file; |
| 8 | private $support_link; |
| 9 | private $full_support_link; |
| 10 | |
| 11 | public function __construct( $plugin_slug, $plugin_file, $support_link ) { |
| 12 | $this->plugin_slug = $plugin_slug; |
| 13 | $this->plugin_file = $plugin_file; |
| 14 | $this->support_link = $support_link; |
| 15 | $this->full_support_link = $support_link . ( ( strpos( $support_link, '?' ) === false ) ? '?' : '&' ) . 'priority-support=yes'; |
| 16 | |
| 17 | // To know when the plugin was installed |
| 18 | if ( ! get_option( 'installed_' . $this->plugin_slug, false ) ) { |
| 19 | update_option( 'installed_' . $this->plugin_slug, time() ); |
| 20 | } |
| 21 | // Actions and filters |
| 22 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
| 23 | add_action( 'wp_ajax_wcmp_feedback', array( $this, 'feedback_action' ) ); |
| 24 | } // End __construct |
| 25 | |
| 26 | public function enqueue_scripts( $hook ) { |
| 27 | if ( 'plugins.php' == $hook ) { |
| 28 | wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
| 29 | wp_enqueue_script( 'jquery' ); |
| 30 | wp_enqueue_script( 'jquery-ui-dialog' ); |
| 31 | |
| 32 | add_action( 'admin_footer', array( $this, 'feedback_interface' ) ); |
| 33 | } |
| 34 | } // End insert_admin_scripts |
| 35 | |
| 36 | public function feedback_interface() { |
| 37 | // Varibles to use into the feedback interface |
| 38 | $plugin_slug = $this->plugin_slug; |
| 39 | $support_link = $this->support_link; |
| 40 | $full_support_link = $this->full_support_link; |
| 41 | |
| 42 | include_once dirname( $this->plugin_file ) . '/feedback/feedback.html'; |
| 43 | } // End feedback_interface |
| 44 | |
| 45 | // This function is used only if explicitly accepted (opt-in) by the user |
| 46 | public function feedback_action() { |
| 47 | if ( |
| 48 | isset( $_POST['_wpnonce'] ) && |
| 49 | wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'woocommerce-music-player-feedback' ) && |
| 50 | isset( $_POST['feedback_plugin'] ) && |
| 51 | $_POST['feedback_plugin'] == $this->plugin_slug |
| 52 | ) { |
| 53 | $plugin_data = get_plugin_data( $this->plugin_file ); |
| 54 | $plugin_version = $plugin_data['Version']; |
| 55 | $time = time() - get_option( 'installed_' . $this->plugin_slug, 0 ); |
| 56 | |
| 57 | $data = array( |
| 58 | 'plugin' => $plugin_data['Name'], |
| 59 | 'pluginv' => $plugin_version, |
| 60 | 'wordpress' => get_bloginfo( 'version' ), |
| 61 | 'itime' => $time, |
| 62 | 'phpversion' => phpversion(), |
| 63 | ); |
| 64 | |
| 65 | foreach ( $_POST as $parameter => $value ) { |
| 66 | $data[ $parameter ] = $value; |
| 67 | } |
| 68 | |
| 69 | if ( ! isset( $_POST['wcmp_feedback_anonymous'] ) ) { |
| 70 | $current_user = wp_get_current_user(); |
| 71 | $data['email'] = $current_user->user_email; |
| 72 | $data['website'] = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : ''; |
| 73 | $data['url'] = get_site_url(); |
| 74 | } |
| 75 | |
| 76 | // Send data |
| 77 | $response = wp_remote_post( |
| 78 | $this->feedback_url, |
| 79 | array( |
| 80 | 'body' => $data, |
| 81 | 'sslverify' => false, |
| 82 | ) |
| 83 | ); |
| 84 | |
| 85 | wp_die(); // this is required to terminate immediately and return a proper response |
| 86 | } |
| 87 | |
| 88 | } // End feedback_action |
| 89 | |
| 90 | } // End class |
| 91 | } |
| 92 |