PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.1.0
Forumax – AI Powered Advanced Community Forum Plugin v2.1.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 2.0.0 2.1.0 All 29 releases
bbp-core / includes / admin / notices / asking-for-review.php

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

166 lines 5.8 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 $forums = get_pages( [
33 'post_type' => 'forum',
34 'post_status' => 'publish'
35 ] );
36 $forums = is_array( $forums ) ? $forums : [];
37
38 $topics = get_pages( [
39 'post_type' => 'topic',
40 'post_status' => 'publish'
41 ] );
42 $topics = is_array( $topics ) ? $topics : [];
43 ?>
44 <div class="notice notice-success is-dismissible" id="bbpc_notify_review">
45 <div>
46 <img src="<?php echo esc_url( FORUMAX_ASSETS . 'img/logo.svg' ); ?>">
47 </div>
48 <div>
49 <h3><?php esc_html_e( 'Give Forumax a review', 'forumax' ); ?></h3>
50 <p style="margin-top: 10px;">
51 <?php
52 if ( count( $forums ) <= 0 ) {
53 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' );
54 } else {
55 $topics_count = count( $topics );
56 $topics_text = $topics_count > 0 ? " and <b>" . $topics_count . "</b> topics" : '';
57 echo wp_kses(
58 sprintf(
59 /* translators: 1: number of forums created, 2: additional topics text */
60 __( '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' ),
61 count( $forums ),
62 $topics_text
63 ),
64 array(
65 'b' => array(), // Allow <b> tag
66 'strong' => array(), // If needed, allow <strong> tag
67 'br' => array(), // If needed, allow <br> tag
68 )
69 );
70 }
71 ?>
72 </p>
73 <p class="bbpc_notify_review_subheading" style="margin-bottom: 12px;">
74 <?php esc_html_e( 'We will be forever grateful. Thank you in advance.', 'forumax' ); ?>
75 </p>
76 <div class="action_links">
77 <a href="javascript:;" data="rateNow" class="button button-primary" style="margin-right: 5px">
78 <?php esc_html_e( 'Ok, you deserve', 'forumax' ) ?>
79 <span class='icon_star'></span>
80 <span class='icon_star'></span>
81 <span class='icon_star'></span>
82 <span class='icon_star'></span>
83 <span class='icon_star'></span>
84 </a>
85 <a href="javascript:;" class="btn" data="later" style="margin-right: 5px">
86 <span class='icon_clock_alt'></span>
87 <?php esc_html_e( 'Nope, maybe later', 'forumax' ) ?>
88 </a>
89 <a href="javascript:;" class="btn red" data="alreadyDid">
90 <span class='icon_close_alt2'></span>
91 <?php esc_html_e( 'Never show again', 'forumax' ) ?>
92 </a>
93 </div>
94 </div>
95 </div>
96
97 <script>
98 jQuery(document).ready(function () {
99 // Show review popup
100 jQuery("#bbpc_notify_review a").on("click", function () {
101 const thisElement = this;
102 const fieldValue = jQuery(thisElement).attr("data");
103 const freeLink = "https://wordpress.org/support/plugin/bbp-core/reviews/#new-post";
104 let hidePopup = false;
105 if ( fieldValue === "rateNow" ) {
106 window.open(freeLink, "_blank");
107 } else {
108 hidePopup = true;
109 }
110
111 jQuery
112 .ajax({
113 dataType: 'json',
114 url: forumax_local_object.ajaxurl,
115 type: "post",
116 data: {
117 action: "bbpc_notify_save_review",
118 field: fieldValue,
119 nonce: forumax_local_object.nonce,
120 },
121 })
122 .done(function (result) {
123 if (hidePopup == true) {
124 jQuery("#bbpc_notify_review .notice-dismiss").trigger("click");
125 }
126 })
127 .fail(function (res) {
128 if (hidePopup == true) {
129 console.log(res.responseText);
130 jQuery("#bbpc_notify_review .notice-dismiss").trigger("click");
131 }
132 });
133 })
134 })
135 </script>
136 <?php
137 }
138
139 /**
140 ** Save Notice
141 **/
142 function forumax_notify_save_review() {
143 if ( isset( $_POST ) ) {
144 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : null;
145 $field = isset( $_POST['field'] ) ? sanitize_text_field( wp_unslash( $_POST['field'] ) ) : null;
146
147 if ( ! wp_verify_nonce( $nonce, 'bbpc-admin-nonce' ) ) {
148 wp_send_json_error( array( 'status' => 'Wrong nonce validate!' ) );
149 exit();
150 }
151
152 if ( ! current_user_can( 'manage_options' ) ) {
153 wp_send_json_error( array( 'message' => 'Unauthorized user' ) );
154 exit();
155 }
156
157 if ( $field == 'later' ) {
158 update_option( 'bbpc_notify_review', time() + 3 * 60 * 60 * 24 ); //After 3 days show
159 } else if ( $field == 'alreadyDid' ) {
160 update_option( 'bbpc_notify_review', 0 );
161 }
162 wp_send_json_success();
163 }
164 wp_send_json_error( array( 'message' => 'Update fail!' ) );
165 }
166