芝麻web文件管理V1.00
编辑当前文件:/home/royashxg/public_html/wp-content/plugins/chaty/includes/class-review-box.php
* @license : GPL2 * */ if (defined('ABSPATH') === false) { exit; } class Chaty_Free_Review_Box { /** * The Name of this plugin. * * @var string $pluginName The Name of this plugin. * @since 1.0.0 * @access public */ public $pluginName = "Chaty"; /** * The Slug of this plugin. * * @var string $pluginSlug The Slug of this plugin. * @since 1.0.0 * @access public */ public $pluginSlug = "chaty"; /** * The Plugin review status. * * @var string $reviewStatus The Slug of this plugin. * @since 1.0.0 * @access public */ public $reviewStatus = true; /** * The plugin slug for WordPress * * @var string $wpPluginSlug The Slug of this plugin. * @since 1.0.0 * @access public */ public $wpPluginSlug = "chaty"; /** * The plugin slug for WordPress * * @var string $isHidden Review box status * @since 1.0.0 * @access public */ public $isHidden = false; /** * Define the core functionality of the plugin. * * Set the plugin name and the plugin version that can be used throughout the plugin. * Load the dependencies, define the locale, and set the hooks for the admin area and * the public-facing side of the site. * * @since 1.0.0 */ public function __construct() { $isHidden = get_option( $this->pluginSlug . "_hide_review_box" ); if ( $isHidden !== false ) { $this->reviewStatus = false; $this->isHidden = true; } $currentCount = get_option( $this->pluginSlug . "_show_review_box_after" ); if ( $currentCount === false ) { $date = gmdate( "Y-m-d", strtotime( "+14 days" ) ); add_option( $this->pluginSlug . "_show_review_box_after", $date ); $this->reviewStatus = false; } $dateToShow = get_option( $this->pluginSlug . "_show_review_box_after" ); if ( $dateToShow !== false ) { $currentDate = gmdate( "Y-m-d" ); if ( $currentDate < $dateToShow ) { $this->reviewStatus = false; } } // $this->reviewStatus = true; $chaty_views = intval(get_option("chaty_views")); if($this->reviewStatus) { add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']); add_action('admin_notices', [$this, 'admin_notices']); } else { if(!$this->isHidden && $chaty_views == 1) { add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']); } } add_action("wp_ajax_".$this->pluginSlug."_review_box", [$this, "form_review_box"]); add_action("wp_ajax_".$this->pluginSlug."_review_box_message", [$this, "form_review_box_message"]); }//end __construct() /** * Enqueues the necessary scripts and styles for the plugin. * * This method is responsible for enqueueing the CSS and JS files * required for the plugin to function properly. It first checks if * the current user has the capability to manage options. If so, it * loads the necessary files and sets up the localization for the JS * script. * * @return void * @since 1.0.0 * */ public function enqueue_scripts() { if (current_user_can('manage_options')) { wp_enqueue_style($this->pluginSlug."-star-rating-svg", plugins_url('../admin/assets/css/star-rating-svg.css', __FILE__), [], CHT_VERSION); wp_enqueue_script($this->pluginSlug."-star-rating-svg", plugins_url('../admin/assets/js/jquery.star-rating-svg.min.js', __FILE__), ['jquery'], CHT_VERSION, true); wp_localize_script( $this->pluginSlug."-star-rating-svg", 'chaty_rating_settings', [ 'has_settings' => 1, 'review_nonce' => wp_create_nonce($this->pluginSlug."_review_box"), 'review_box_nonce' => wp_create_nonce($this->pluginSlug."_review_box_message"), 'review_link' => "https://wordpress.org/support/plugin/".$this->pluginSlug."/reviews/#new-post", 'ajax_url' => admin_url("admin-ajax.php") ] ); } } /** * Process the form submission for the review box message. * * This method is responsible for handling the submission of the form review box message. * It performs actions such as adding an option, updating an option, and making an API call * to send the feedback message. * * @return void * @since 1.0.0 * */ public function form_review_box_message() { if (current_user_can('manage_options')) { $nonce = filter_input(INPUT_POST, 'nonce'); if (!empty($nonce) && wp_verify_nonce($nonce, $this->pluginSlug."_review_box_message")) { add_option($this->pluginSlug."_hide_review_box", "1"); update_option("chaty_views", 2); $rating = filter_input(INPUT_POST, 'rating'); $message = filter_input(INPUT_POST, 'message'); global $current_user; $postMessage = []; $domain = site_url(); $user_name = $current_user->first_name." ".$current_user->last_name; $email = $current_user->user_email; $messageData = []; $messageData['key'] = "email"; $messageData['value'] = $email; $postMessage[] = $messageData; $messageData = []; $messageData['key'] = "stars"; $messageData['value'] = $rating; $postMessage[] = $messageData; $messageData = []; $messageData['key'] = "message"; $messageData['value'] = $message; $postMessage[] = $messageData; $apiParams = [ 'title' => 'Review for '.$this->pluginName.' WordPress', 'domain' => $domain, 'email' => "contact@premio.io", 'url' => site_url(), 'name' => $user_name, 'message' => $postMessage, 'plugin' => $this->pluginName, 'type' => "Review", ]; // Sending message to Crisp API $apiResponse = wp_safe_remote_post("https://premioapps.com/premio/send-feedback-api.php", ['body' => $apiParams, 'timeout' => 15, 'sslverify' => true]); if (is_wp_error($apiResponse)) { wp_safe_remote_post("https://premioapps.com/premio/send-feedback-api.php", ['body' => $apiParams, 'timeout' => 15, 'sslverify' => false]); } } die; } }//end form_review_box_message() /** * Handle the "form_review_box" AJAX request. * * This method is responsible for updating the options related to the review box based on the data received * from the client-side form. It checks if the user has the capability to manage options, verifies the nonce, * and updates the necessary options accordingly. If the "days" parameter is set to -1, the review box will be hidden, * otherwise, the review box will be displayed again after the specified number of days. * * @since 1.0.0 */ public function form_review_box() { if (current_user_can('manage_options')) { $nonce = filter_input(INPUT_POST, 'nonce'); $days = filter_input(INPUT_POST, 'days'); if (!empty($nonce) && wp_verify_nonce($nonce, $this->pluginSlug."_review_box")) { update_option("chaty_views", 2); if ($days == -1) { add_option($this->pluginSlug."_hide_review_box", "1"); } else { $date = gmdate("Y-m-d", strtotime("+".$days." days")); update_option($this->pluginSlug."_show_review_box_after", $date); } } die; } }//end form_review_box() /** * Display admin notices. * * This method is responsible for displaying admin notices in the WordPress dashboard. * It checks if the current user has the capability to manage options, and if so, it * displays a notice with HTML markup. * * @since 1.0.0 */ public function admin_notices() { if (!current_user_can('manage_options')) { return; } ?>
🙏
".esc_attr($this->pluginName)."", esc_attr($this->pluginName));?>
,
" />
" />
🙏
</textarea>