PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmReviews.php +34 -25 6.4.2 → trunk View file →
@@ -4,12 +4,21 @@
4 4 }
5 5
6 6 class FrmReviews {
7 7
8 + /**
9 + * @var string
10 + */
8 11 private $option_name = 'frm_reviewed';
9 12
13 + /**
14 + * @var array
15 + */
10 16 private $review_status = array();
11 17
18 + /**
19 + * @var string
20 + */
12 21 private $inbox_key = 'review';
13 22
14 23 /**
15 24 * Add admin notices as needed for reviews
@@ -18,9 +27,8 @@
18 27 *
19 28 * @return void
20 29 */
21 30 public function review_request() {
22 -
23 31 // Only show the review request to high-level users on Formidable pages
24 32 if ( ! current_user_can( 'frm_change_settings' ) || ! FrmAppHelper::is_formidable_admin() ) {
25 33 return;
26 34 }
@@ -29,15 +37,16 @@
29 37 $this->set_review_status();
30 38
31 39 // Check if it has been dismissed or if we can ask later
32 40 $dismissed = $this->review_status['dismissed'];
41 +
33 42 if ( $dismissed === 'later' && $this->review_status['asked'] < 3 ) {
34 43 $dismissed = false;
35 44 }
36 45
37 - $week_ago = ( $this->review_status['time'] + WEEK_IN_SECONDS ) <= time();
46 + $week_ago = $this->review_status['time'] + WEEK_IN_SECONDS <= time();
38 47
39 - if ( empty( $dismissed ) && $week_ago ) {
48 + if ( ! $dismissed && $week_ago ) {
40 49 $this->review();
41 50 }
42 51 }
43 52
@@ -56,9 +65,9 @@
56 65 'dismissed' => false,
57 66 'asked' => 0,
58 67 );
59 68
60 - if ( empty( $review ) ) {
69 + if ( ! $review ) {
61 70 // Set the review request to show in a week
62 71 update_user_meta( $user_id, $this->option_name, $default );
63 72 }
64 73
@@ -74,10 +83,9 @@
74 83 *
75 84 * @return void
76 85 */
77 86 private function review() {
78 -
79 - // show the review request 3 times, depending on the number of entries
87 + // Show the review request 3 times, depending on the number of entries
80 88 $show_intervals = array( 50, 200, 500 );
81 89 $asked = $this->review_status['asked'];
82 90
83 91 if ( ! isset( $show_intervals[ $asked ] ) ) {
@@ -89,9 +97,9 @@
89 97 $user = wp_get_current_user();
90 98
91 99 // Only show review request if the site has collected enough entries
92 100 if ( $entries < $count ) {
93 - // check the entry count again in a week
101 + // Check the entry count again in a week
94 102 $this->review_status['time'] = time();
95 103 update_user_meta( $user->ID, $this->option_name, $this->review_status );
96 104
97 105 return;
@@ -96,24 +104,18 @@
96 104
97 105 return;
98 106 }
99 107
100 - if ( $entries <= 100 ) {
101 - // round to the nearest 10
102 - $entries = floor( $entries / 10 ) * 10;
103 - } else {
104 - // round to the nearest 50
105 - $entries = floor( $entries / 50 ) * 50;
106 - }
107 - $name = $user->first_name;
108 - if ( ! empty( $name ) ) {
108 + $entries = $entries <= 100 ? floor( $entries / 10 ) * 10 : floor( $entries / 50 ) * 50;
109 + $name = $user->first_name;
110 +
111 + if ( $name ) {
109 112 $name = ' ' . $name;
110 113 }
111 114
112 115 $title = sprintf(
113 - /* translators: %s: User name, %2$d: number of entries */
114 - esc_html__( 'Congratulations%1$s! You have collected %2$d form submissions.', 'formidable' ),
115 - esc_html( $name ),
116 + /* translators: %1$d: number of entries */
117 + esc_html__( 'You have collected %1$d form submissions.', 'formidable' ),
116 118 absint( $entries )
117 119 );
118 120
119 121 $this->add_to_inbox( $title, $name, $asked );
@@ -118,9 +120,9 @@
118 120
119 121 $this->add_to_inbox( $title, $name, $asked );
120 122
121 123 // We have a candidate! Output a review message.
122 - include( FrmAppHelper::plugin_path() . '/classes/views/shared/review.php' );
124 + include FrmAppHelper::plugin_path() . '/classes/views/shared/review.php';
123 125 }
124 126
125 127 /**
126 128 * @param string $title
@@ -129,9 +131,9 @@
129 131 *
130 132 * @return void
131 133 */
132 134 private function add_to_inbox( $title, $name, $asked ) {
133 - $message = new FrmInbox();
135 + $message = new FrmInbox();
134 136 $requests = $message->get_messages();
135 137 $key = $this->inbox_key . ( $asked ? $asked : '' );
136 138
137 139 if ( isset( $requests[ $key ] ) ) {
@@ -141,8 +143,9 @@
141 143 // Remove previous requests.
142 144 if ( $asked > 0 ) {
143 145 $message->remove( $this->inbox_key );
144 146 }
147 +
145 148 if ( $asked > 1 ) {
146 149 $message->remove( $this->inbox_key . '1' );
147 150 }
148 151
@@ -153,13 +156,13 @@
153 156
154 157 $message->add_message(
155 158 array(
156 159 'key' => $key,
157 - 'message' => __( 'If you are enjoying Formidable, could you do me a BIG favor and give us a review to help me grow my little business and boost our motivation?', 'formidable' ) . '<br/>' .
160 + 'message' => __( 'If you are enjoying Formidable, could you do me a BIG favor and give us a review to help me grow my little business and boost our motivation?', 'formidable' ) . '<br/>' . // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
158 161 '- Steph Wells<br/>' .
159 162 '<span>' . esc_html__( 'Co-Founder and CTO of Formidable Forms', 'formidable' ) . '<span>',
160 163 'subject' => str_replace( $name, '', $title ),
161 - 'cta' => '<a href="https://wordpress.org/support/plugin/formidable/reviews/?filter=5#new-post" class="frm-dismiss-review-notice frm-review-out button frm-button-secondary" data-link="yes" target="_blank" rel="noopener noreferrer">' .
164 + 'cta' => '<a href="https://wordpress.org/support/plugin/formidable/reviews/?filter=5#new-post" class="frm-dismiss-review-notice frm-review-out button frm-button-secondary" data-link="yes" target="_blank" rel="noopener noreferrer">' . // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
162 165 esc_html__( 'Ok, you deserve it', 'formidable' ) . '</a>',
163 166 'type' => 'feedback',
164 167 )
165 168 );
@@ -169,8 +172,11 @@
169 172 * If there are already later requests, don't add it to the inbox again.
170 173 *
171 174 * @since 4.05.02
172 175 *
176 + * @param array $requests Array of requests.
177 + * @param int $asked Number of times the review has been asked.
178 + *
173 179 * @return bool
174 180 */
175 181 private function has_later_request( $requests, $asked ) {
176 182 return isset( $requests[ $this->inbox_key . ( $asked + 1 ) ] ) || isset( $requests[ $this->inbox_key . ( $asked + 2 ) ] );
@@ -195,8 +201,9 @@
195 201 * @return void
196 202 */
197 203 private function set_inbox_dismissed() {
198 204 $message = new FrmInbox();
205 +
199 206 foreach ( $this->inbox_keys() as $key ) {
200 207 $message->dismiss( $key );
201 208 }
202 209 }
@@ -207,8 +214,9 @@
207 214 * @return void
208 215 */
209 216 private function set_inbox_read() {
210 217 $message = new FrmInbox();
218 +
211 219 foreach ( $this->inbox_keys() as $key ) {
212 220 $message->mark_read( $key );
213 221 }
214 222 }
@@ -225,14 +233,15 @@
225 233 check_ajax_referer( 'frm_ajax', 'nonce' );
226 234
227 235 $user_id = get_current_user_id();
228 236 $review = get_user_meta( $user_id, $this->option_name, true );
229 - if ( empty( $review ) ) {
237 +
238 + if ( ! $review ) {
230 239 $review = array();
231 240 }
232 241
233 242 if ( isset( $review['dismissed'] ) && $review['dismissed'] === 'done' ) {
234 - // if feedback was submitted, don't update it again when the review is dismissed
243 + // If feedback was submitted, don't update it again when the review is dismissed
235 244 $this->set_inbox_dismissed();
236 245 wp_die();
237 246 }
238 247