PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5
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/controllers/FrmUsageController.php +6 -134 6.275.5 View file →
@@ -3,49 +3,28 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 /**
7 + * @todo Show opt-in popup after plugin activation.
7 8 * @since 3.06.04
8 9 */
9 10 class FrmUsageController {
10 11
11 12 /**
12 - * Option name of flows data.
13 - *
14 - * @since 6.16.1
15 - *
16 - * @var string
17 - */
18 - const FLOWS_ACTION_NAME = 'frm_usage_tracking_flows';
19 -
20 - /**
21 13 * Randomize the first send to prevent our servers from crashing.
22 14 *
23 15 * @since 3.06.04
24 - *
25 - * @return void
26 16 */
27 17 public static function schedule_send() {
28 - $timestamp = wp_next_scheduled( 'formidable_send_usage' );
29 -
30 - if ( ! self::tracking_allowed() ) {
31 - if ( $timestamp ) {
32 - // Remove the scheduled event if it's not allowed and it's scheduled.
33 - wp_unschedule_event( $timestamp, 'formidable_send_usage' );
34 - }
35 -
18 + if ( wp_next_scheduled( 'formidable_send_usage' ) ) {
36 19 return;
37 20 }
38 21
39 - if ( $timestamp ) {
40 - return;
41 - }
42 -
43 22 $tracking = array(
44 - 'day' => random_int( 0, 6 ) * DAY_IN_SECONDS,
45 - 'hour' => random_int( 0, 23 ) * HOUR_IN_SECONDS,
46 - 'minute' => random_int( 0, 59 ) * MINUTE_IN_SECONDS,
47 - 'second' => random_int( 0, 59 ),
23 + 'day' => rand( 0, 6 ) * DAY_IN_SECONDS,
24 + 'hour' => rand( 0, 23 ) * HOUR_IN_SECONDS,
25 + 'minute' => rand( 0, 59 ) * MINUTE_IN_SECONDS,
26 + 'second' => rand( 0, 59 ),
48 27 );
49 28
50 29 $offset = array_sum( $tracking );
51 30 $init_send = strtotime( 'next sunday' ) + $offset;
@@ -56,12 +35,8 @@
56 35 /**
57 36 * Adds once weekly to the existing schedules.
58 37 *
59 38 * @since 3.06.04
60 - *
61 - * @param array $schedules Schedules.
62 - *
63 - * @return array
64 39 */
65 40 public static function add_schedules( $schedules = array() ) {
66 41 $schedules['weekly'] = array(
67 42 'interval' => DAY_IN_SECONDS * 7,
@@ -70,114 +45,11 @@
70 45 return $schedules;
71 46 }
72 47
73 48 /**
74 - * Checks if tracking is allowed.
75 - *
76 - * @since 6.16.3
77 - *
78 - * @return bool
79 - */
80 - public static function tracking_allowed() {
81 - $settings = FrmAppHelper::get_settings();
82 - return $settings->tracking;
83 - }
84 -
85 - /**
86 49 * @since 3.06.04
87 - *
88 - * @return void
89 50 */
90 51 public static function send_snapshot() {
91 52 $usage = new FrmUsage();
92 53 $usage->send_snapshot();
93 - }
94 -
95 - /**
96 - * Loads scripts.
97 - *
98 - * @since 6.16.1
99 - *
100 - * @return void
101 - */
102 - public static function load_scripts() {
103 - if ( self::is_forms_list_page() || FrmAppHelper::is_admin_page( 'formidable-form-templates' ) || FrmAppHelper::is_admin_page() ) {
104 - wp_enqueue_script( 'frm-usage-tracking', FrmAppHelper::plugin_url() . '/js/admin/usage-tracking.js', array( 'formidable_dom' ), FrmAppHelper::$plug_version, true );
105 - }
106 - }
107 -
108 - /**
109 - * Checks if is forms list page.
110 - *
111 - * @since 6.16.1
112 - *
113 - * @return bool
114 - */
115 - private static function is_forms_list_page() {
116 - if ( ! FrmAppHelper::on_form_listing_page() ) {
117 - return false;
118 - }
119 -
120 - // Exclude Trash page.
121 - $form_type = FrmAppHelper::simple_get( 'form_type' );
122 - return 'published' === $form_type;
123 - }
124 -
125 - /**
126 - * AJAX handler to track flows.
127 - *
128 - * @since 6.16.1
129 - *
130 - * @return void
131 - */
132 - public static function ajax_track_flows() {
133 - FrmAppHelper::permission_check( 'frm_view_forms' );
134 - check_ajax_referer( 'frm_ajax', 'nonce' );
135 -
136 - $key = FrmAppHelper::get_post_param( 'key', '', 'sanitize_text_field' );
137 - $value = FrmAppHelper::get_post_param( 'value', '', 'sanitize_text_field' );
138 -
139 - self::update_flows_data( $key, $value );
140 -
141 - wp_send_json_success();
142 - }
143 -
144 - /**
145 - * Updates flows data.
146 - *
147 - * @since 6.16.1
148 - *
149 - * @param string $key Flow key.
150 - * @param string $value Flow value.
151 - *
152 - * @return void
153 - */
154 - public static function update_flows_data( $key, $value ) {
155 - if ( '' === $key || '' === $value ) {
156 - return;
157 - }
158 -
159 - $flows_data = self::get_flows_data();
160 -
161 - if ( ! isset( $flows_data[ $key ] ) ) {
162 - $flows_data[ $key ] = array();
163 - }
164 -
165 - if ( ! isset( $flows_data[ $key ][ $value ] ) ) {
166 - $flows_data[ $key ][ $value ] = 0;
167 - }
168 -
169 - $flows_data[ $key ][ $value ]++;
170 - update_option( self::FLOWS_ACTION_NAME, $flows_data );
171 - }
172 -
173 - /**
174 - * Get flows data.
175 - *
176 - * @since 6.16.1
177 - *
178 - * @return array
179 - */
180 - public static function get_flows_data() {
181 - return get_option( self::FLOWS_ACTION_NAME, array() );
182 54 }
183 55 }