PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow / 2.7.1
WDesignKit – AI Templates, Widget Builder & MCP Workflow v2.7.1
2.7.1 2.7.0 2.6.6 2.6.5 2.6.4 2.6.3 2.6.2 2.6.1 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 2.5.1 2.5.0 2.4.0 2.3.3 2.3.2 2.3.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 All 130 releases
wdesignkit / includes / admin / notices / class-wdkit-review-form.php

class-wdkit-review-form.php in WDesignKit – AI Templates, Widget Builder & MCP Workflow 2.7.1, at includes/admin/notices/class-wdkit-review-form.php

209 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The file that defines the core plugin class
4 *
5 * A class definition that includes attributes and functions used across both the
6 * public-facing side of the site and the admin area.
7 *
8 * @link https://posimyth.com/
9 * @since 1.2.5
10 *
11 * @package Wdesignkit
12 * @subpackage Wdesignkit/includes
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 if ( ! class_exists( 'Wdkit_Review_Form' ) ) {
20
21 /**
22 * Wdkit_Review_Form
23 *
24 * @since 1.2.5
25 */
26 class Wdkit_Review_Form {
27
28 /**
29 * Singleton instance variable.
30 *
31 * @var instance|null The single instance of the class.
32 */
33 private static $instance;
34
35 /**
36 * Singleton instance getter method.
37 *
38 * @since 1.2.5
39 * @return self The single instance of the class.
40 */
41 public static function get_instance() {
42 if ( ! isset( self::$instance ) ) {
43 self::$instance = new self();
44 }
45
46 return self::$instance;
47 }
48
49 /**
50 * Constructor for the core functionality of the plugin.
51 *
52 * @since 1.2.5
53 */
54 public function __construct() {
55
56 add_action( 'admin_footer', array( $this, 'wdkit_review_form' ), 10, 1 );
57
58 add_action( 'admin_enqueue_scripts', array( $this, 'wdkit_review_form_scripts' ) );
59
60 add_action( 'wp_ajax_wdkit_submit_review', array( $this, 'wdkit_handle_review_submission' ) );
61 }
62
63 /**
64 * Loads the file for setting plugin page notices.
65 *
66 * @since 1.2.5
67 */
68 public function wdkit_review_form() {
69 ?>
70 <div class="wkit-plugin-review-popup-container">
71 </div>
72 <?php
73 }
74
75 /**
76 * Load review form scripts
77 *
78 * @since 1.2.5
79 */
80 public function wdkit_review_form_scripts() {
81
82 wp_enqueue_style( 'wdkit-review-form-plugin', WDKIT_URL . 'assets/css/review-form/review-plugin-form.css', [], WDKIT_VERSION, 'all' );
83 wp_enqueue_script( 'wdkit-review-form-plugin', WDKIT_URL . 'assets/js/main/review-form/review-plugin-form.js', [], WDKIT_VERSION, true );
84
85 wp_localize_script(
86 'wdkit-review-form-plugin',
87 'wdkitPluginReview',
88 array(
89 'ajax_url' => admin_url( 'admin-ajax.php' ),
90 'nonce' => wp_create_nonce( 'wdkit_review_nonce' ),
91 )
92 );
93 }
94
95 /**
96 * Handle review submission
97 *
98 * @since 1.2.5
99 */
100 public function wdkit_handle_review_submission() {
101
102 check_ajax_referer( 'wdkit_review_nonce', 'nonce' );
103
104 // Check if user is logged in
105 if ( ! is_user_logged_in() ) {
106 wp_send_json([
107 'message' => __( 'You must be logged in to submit a review.', 'wdesignkit' ),
108 'error' => 'You must be logged in to submit a review.',
109 'success' => false,
110 ]);
111 }
112
113 // Check if the user is logged in and has manage_options capability
114 if ( ! current_user_can( 'manage_options' ) ) {
115 wp_send_json([
116 'message' => __( 'Unauthorized', 'wdesignkit' ),
117 'error' => 'Unauthorized',
118 'success' => false,
119 ]);
120 }
121
122 $active_plugins = get_plugins();
123 $active_plugins_list = [];
124
125 foreach ($active_plugins as $plugin) {
126 if (!in_array($plugin['Title'], $active_plugins_list)) {
127 $active_plugins_list[] = $plugin['Title'];
128 }
129 }
130
131 global $wpdb;
132 $allow_email = !empty( $_POST['allow_email'] ) ? sanitize_text_field( $_POST['allow_email'] ) : false;
133 $rating = !empty( $_POST['rating'] ) ? sanitize_text_field( $_POST['rating'] ) : '0';
134 $email = !empty( wp_get_current_user()->user_email ) ? wp_get_current_user()->user_email : '';
135 $description = !empty( $_POST['description'] ) ? sanitize_textarea_field( $_POST['description'] ) : '';
136 $plugins = !empty( $active_plugins_list ) ? implode(', ', $active_plugins_list) : '';
137 $page_url = !empty( $_POST['page_url'] ) ? sanitize_text_field( $_POST['page_url'] ) : '';
138 $screen_resolution = !empty( $_POST['screen_resolution'] ) ? sanitize_text_field( $_POST['screen_resolution'] ) : '';
139 $active_theme = get_option( 'current_theme' );
140 $wp_version = get_bloginfo( 'version' );
141 $db_version = $wpdb->db_version();
142 $php_version = phpversion();
143 $max_execution_time = ini_get( 'max_execution_time' );
144 $memory_limit = ini_get( 'memory_limit' );
145 $language = get_bloginfo( 'language' );
146 $server = ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '';
147
148 $detail = [
149 'rating' => $rating,
150 'description' => $description,
151 // 'plugins' => $plugins,
152 // 'themes' => $active_theme,
153 // 'wp_version' => $wp_version,
154 // 'page_url' => $page_url,
155 // 'wdkit_version' => WDKIT_VERSION,
156 // 'db_version' => $db_version,
157 // 'php_version' => $php_version,
158 // 'server' => $server,
159 // 'memory_limit' => $memory_limit,
160 // 'language' => $language,
161 'screen_resolution' => 1,
162 // 'max_execution_time' => $max_execution_time,
163 ];
164
165 if( !empty($allow_email) && $allow_email === 'true' ){
166 $detail['email'] = $email;
167 }
168
169 $response = wp_remote_post('https://api.wdesignkit.com/api/wp/userreview', [
170 'method' => 'POST',
171 'timeout' => 30,
172 'headers' => [
173 'Content-Type' => 'application/json',
174 ],
175 'body' => json_encode($detail),
176 ]);
177
178 if (is_wp_error($response)) {
179 wp_send_json([
180 'message' => __( 'API Request Failed', 'wdesignkit' ),
181 'error' => $response->get_error_message(),
182 'success' => false,
183 ]);
184 }
185
186 $response_code = wp_remote_retrieve_response_code($response);
187 $response_body = wp_remote_retrieve_body($response);
188 $response_json = json_decode($response_body, true);
189
190 if ($response_code >= 200 && $response_code < 300) {
191 wp_send_json([
192 'message' => __( 'API responded successfully.', 'wdesignkit' ),
193 'data' => $response_json,
194 'success' => true,
195 ]);
196 } else {
197 wp_send_json([
198 'message' => __( 'API returned error', 'wdesignkit' ),
199 'code' => $response_code,
200 'data' => $response_json,
201 'success' => false,
202 ]);
203 }
204 }
205
206 }
207
208 Wdkit_Review_Form::get_instance();
209 }