PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.1
Forumax – AI Powered Advanced Community Forum Plugin v2.5.1
2.5.1 2.5.0 2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 All 31 releases
bbp-core / includes / admin / notices / asking-for-review.php

asking-for-review.php in Forumax – AI Powered Advanced Community Forum Plugin 2.5.1, at includes/admin/notices/asking-for-review.php

158 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 $optionReview = get_option('bbpc_notify_review');
3 if ( is_admin() && time() >= (int) $optionReview && $optionReview !== '0') {
4 add_action('admin_enqueue_scripts', 'forumax_notify_enqueue_script'); // Hook to admin_enqueue_scripts
5
6 $bbpc_installed = get_option('bbpc_installed');
7 // Check if timestamp exists
8 if ( $bbpc_installed ) {
9 // Add 7days to the timestamp
10 $show_notice = $bbpc_installed + (7 * 24 * 60 * 60);
11
12 // Get the current time
13 $current_time = current_time('timestamp');
14
15 // Compare current time with timestamp + 7 days
16 if ( $current_time >= $show_notice ) {
17 add_action('admin_notices', 'forumax_notify_give_review');
18 }
19 }
20 }
21
22 function forumax_notify_enqueue_script() {
23 wp_enqueue_script( 'bbpc-notify-review' );
24 }
25
26 add_action('wp_ajax_bbpc_notify_save_review', 'forumax_notify_save_review');
27
28 /**
29 ** Give Notice
30 **/
31 function forumax_notify_give_review() {
32 // Counts only: this notice shows on every admin screen, and loading every
33 // forum/topic object here made wp-admin crawl on large communities.
34 $forums_count = (int) wp_count_posts( 'forum' )->publish;
35 $topics_count = (int) wp_count_posts( 'topic' )->publish;
36 ?>
37 <div class="notice notice-success is-dismissible" id="bbpc_notify_review">
38 <div>
39 <img src="<?php echo esc_url( FORUMAX_ASSETS . 'img/logo.svg' ); ?>">
40 </div>
41 <div>
42 <h3><?php esc_html_e( 'Give Forumax a review', 'forumax' ); ?></h3>
43 <p style="margin-top: 10px;">
44 <?php
45 if ( $forums_count <= 0 ) {
46 esc_html_e( 'Thank you for choosing Forumax. We hope you love it. Could you take a couple of seconds posting a nice review to share your happy experience?', 'forumax' );
47 } else {
48 $topics_text = $topics_count > 0 ? " and <b>" . $topics_count . "</b> topics" : '';
49 echo wp_kses(
50 sprintf(
51 /* translators: 1: number of forums created, 2: additional topics text */
52 __( 'You have created <b>%1$d</b> forums%2$s with Forumax. That\'s awesome! May we ask you to give it a 5-Star rating on WordPress? <br> It will help us spread the word and boost our motivation.', 'forumax' ),
53 $forums_count,
54 $topics_text
55 ),
56 array(
57 'b' => array(), // Allow <b> tag
58 'strong' => array(), // If needed, allow <strong> tag
59 'br' => array(), // If needed, allow <br> tag
60 )
61 );
62 }
63 ?>
64 </p>
65 <p class="bbpc_notify_review_subheading" style="margin-bottom: 12px;">
66 <?php esc_html_e( 'We will be forever grateful. Thank you in advance.', 'forumax' ); ?>
67 </p>
68 <div class="action_links">
69 <a href="javascript:;" data="rateNow" class="button button-primary" style="margin-right: 5px">
70 <?php esc_html_e( 'Ok, you deserve', 'forumax' ) ?>
71 <span class='icon_star'></span>
72 <span class='icon_star'></span>
73 <span class='icon_star'></span>
74 <span class='icon_star'></span>
75 <span class='icon_star'></span>
76 </a>
77 <a href="javascript:;" class="btn" data="later" style="margin-right: 5px">
78 <span class='icon_clock_alt'></span>
79 <?php esc_html_e( 'Nope, maybe later', 'forumax' ) ?>
80 </a>
81 <a href="javascript:;" class="btn red" data="alreadyDid">
82 <span class='icon_close_alt2'></span>
83 <?php esc_html_e( 'Never show again', 'forumax' ) ?>
84 </a>
85 </div>
86 </div>
87 </div>
88
89 <script>
90 jQuery(document).ready(function () {
91 // Show review popup
92 jQuery("#bbpc_notify_review a").on("click", function () {
93 const thisElement = this;
94 const fieldValue = jQuery(thisElement).attr("data");
95 const freeLink = "https://wordpress.org/support/plugin/bbp-core/reviews/#new-post";
96 let hidePopup = false;
97 if ( fieldValue === "rateNow" ) {
98 window.open(freeLink, "_blank");
99 } else {
100 hidePopup = true;
101 }
102
103 jQuery
104 .ajax({
105 dataType: 'json',
106 url: forumax_local_object.ajaxurl,
107 type: "post",
108 data: {
109 action: "bbpc_notify_save_review",
110 field: fieldValue,
111 nonce: forumax_local_object.nonce,
112 },
113 })
114 .done(function (result) {
115 if (hidePopup == true) {
116 jQuery("#bbpc_notify_review .notice-dismiss").trigger("click");
117 }
118 })
119 .fail(function (res) {
120 if (hidePopup == true) {
121 console.log(res.responseText);
122 jQuery("#bbpc_notify_review .notice-dismiss").trigger("click");
123 }
124 });
125 })
126 })
127 </script>
128 <?php
129 }
130
131 /**
132 ** Save Notice
133 **/
134 function forumax_notify_save_review() {
135 if ( isset( $_POST ) ) {
136 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : null;
137 $field = isset( $_POST['field'] ) ? sanitize_text_field( wp_unslash( $_POST['field'] ) ) : null;
138
139 if ( ! wp_verify_nonce( $nonce, 'bbpc-admin-nonce' ) ) {
140 wp_send_json_error( array( 'status' => 'Wrong nonce validate!' ) );
141 exit();
142 }
143
144 if ( ! current_user_can( 'manage_options' ) ) {
145 wp_send_json_error( array( 'message' => 'Unauthorized user' ) );
146 exit();
147 }
148
149 if ( $field == 'later' ) {
150 update_option( 'bbpc_notify_review', time() + 3 * 60 * 60 * 24 ); //After 3 days show
151 } else if ( $field == 'alreadyDid' ) {
152 update_option( 'bbpc_notify_review', 0 );
153 }
154 wp_send_json_success();
155 }
156 wp_send_json_error( array( 'message' => 'Update fail!' ) );
157 }
158