| @@ -3,8 +3,9 @@ | ||
| 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 | |
| @@ -25,15 +26,13 @@ | ||
| 25 | 26 | * @return void |
| 26 | 27 | */ |
| 27 | 28 | public static function schedule_send() { |
| 28 | 29 | $timestamp = wp_next_scheduled( 'formidable_send_usage' ); |
| 29 | - | |
| 30 | 30 | if ( ! self::tracking_allowed() ) { |
| 31 | 31 | if ( $timestamp ) { |
| 32 | 32 | // Remove the scheduled event if it's not allowed and it's scheduled. |
| 33 | 33 | wp_unschedule_event( $timestamp, 'formidable_send_usage' ); |
| 34 | 34 | } |
| 35 | - | |
| 36 | 35 | return; |
| 37 | 36 | } |
| 38 | 37 | |
| 39 | 38 | if ( $timestamp ) { |
| @@ -40,12 +39,12 @@ | ||
| 40 | 39 | return; |
| 41 | 40 | } |
| 42 | 41 | |
| 43 | 42 | $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 ), | |
| 43 | + 'day' => rand( 0, 6 ) * DAY_IN_SECONDS, | |
| 44 | + 'hour' => rand( 0, 23 ) * HOUR_IN_SECONDS, | |
| 45 | + 'minute' => rand( 0, 59 ) * MINUTE_IN_SECONDS, | |
| 46 | + 'second' => rand( 0, 59 ), | |
| 48 | 47 | ); |
| 49 | 48 | |
| 50 | 49 | $offset = array_sum( $tracking ); |
| 51 | 50 | $init_send = strtotime( 'next sunday' ) + $offset; |
| @@ -55,21 +54,15 @@ | ||
| 55 | 54 | |
| 56 | 55 | /** |
| 57 | 56 | * Adds once weekly to the existing schedules. |
| 58 | 57 | * |
| 59 | - * WordPress core registers an identical 'weekly' schedule of its own, so this adds nothing. | |
| 60 | - * The 'cron_schedules' registration is gone, and with it the translated label that made | |
| 61 | - * this run before the text domain loaded. | |
| 62 | - * | |
| 63 | 58 | * @since 3.06.04 |
| 64 | - * @deprecated 6.35 | |
| 65 | - * | |
| 66 | - * @param array $schedules Unused. The registered cron schedules, keyed by schedule name. | |
| 67 | - * | |
| 68 | - * @return array | |
| 69 | 59 | */ |
| 70 | 60 | public static function add_schedules( $schedules = array() ) { |
| 71 | - _deprecated_function( __METHOD__, '6.35' ); | |
| 61 | + $schedules['weekly'] = array( | |
| 62 | + 'interval' => DAY_IN_SECONDS * 7, | |
| 63 | + 'display' => __( 'Once Weekly', 'formidable' ), | |
| 64 | + ); | |
| 72 | 65 | return $schedules; |
| 73 | 66 | } |
| 74 | 67 | |
| 75 | 68 | /** |
| @@ -79,9 +72,10 @@ | ||
| 79 | 72 | * |
| 80 | 73 | * @return bool |
| 81 | 74 | */ |
| 82 | 75 | public static function tracking_allowed() { |
| 83 | - return (bool) FrmAppHelper::get_settings()->tracking; | |
| 76 | + $settings = FrmAppHelper::get_settings(); | |
| 77 | + return $settings->tracking; | |
| 84 | 78 | } |
| 85 | 79 | |
| 86 | 80 | /** |
| 87 | 81 | * @since 3.06.04 |
| @@ -96,13 +90,11 @@ | ||
| 96 | 90 | /** |
| 97 | 91 | * Loads scripts. |
| 98 | 92 | * |
| 99 | 93 | * @since 6.16.1 |
| 100 | - * | |
| 101 | - * @return void | |
| 102 | 94 | */ |
| 103 | 95 | public static function load_scripts() { |
| 104 | - if ( self::is_forms_list_page() || FrmAppHelper::is_admin_page( 'formidable-form-templates' ) || FrmAppHelper::is_admin_page() ) { | |
| 96 | + if ( self::is_forms_list_page() || FrmAppHelper::is_admin_page( 'formidable-form-templates' ) ) { | |
| 105 | 97 | wp_enqueue_script( 'frm-usage-tracking', FrmAppHelper::plugin_url() . '/js/admin/usage-tracking.js', array( 'formidable_dom' ), FrmAppHelper::$plug_version, true ); |
| 106 | 98 | } |
| 107 | 99 | } |
| 108 | 100 | |
| @@ -119,9 +111,9 @@ | ||
| 119 | 111 | } |
| 120 | 112 | |
| 121 | 113 | // Exclude Trash page. |
| 122 | 114 | $form_type = FrmAppHelper::simple_get( 'form_type' ); |
| 123 | - return 'published' === $form_type; | |
| 115 | + return $form_type && 'published' === $form_type; | |
| 124 | 116 | } |
| 125 | 117 | |
| 126 | 118 | /** |
| 127 | 119 | * AJAX handler to track flows. |
| @@ -126,10 +118,8 @@ | ||
| 126 | 118 | /** |
| 127 | 119 | * AJAX handler to track flows. |
| 128 | 120 | * |
| 129 | 121 | * @since 6.16.1 |
| 130 | - * | |
| 131 | - * @return void | |
| 132 | 122 | */ |
| 133 | 123 | public static function ajax_track_flows() { |
| 134 | 124 | FrmAppHelper::permission_check( 'frm_view_forms' ); |
| 135 | 125 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| @@ -142,9 +132,9 @@ | ||
| 142 | 132 | wp_send_json_success(); |
| 143 | 133 | } |
| 144 | 134 | |
| 145 | 135 | /** |
| 146 | - * Updates flows data. This increases the count of flow_data[ $key ][ $value ]. | |
| 136 | + * Updates flows data. | |
| 147 | 137 | * |
| 148 | 138 | * @since 6.16.1 |
| 149 | 139 | * |
| 150 | 140 | * @param string $key Flow key. |
| @@ -152,13 +142,13 @@ | ||
| 152 | 142 | * |
| 153 | 143 | * @return void |
| 154 | 144 | */ |
| 155 | 145 | public static function update_flows_data( $key, $value ) { |
| 146 | + $flows_data = self::get_flows_data(); | |
| 147 | + | |
| 156 | 148 | if ( '' === $key || '' === $value ) { |
| 157 | 149 | return; |
| 158 | 150 | } |
| 159 | - | |
| 160 | - $flows_data = self::get_flows_data(); | |
| 161 | 151 | |
| 162 | 152 | if ( ! isset( $flows_data[ $key ] ) ) { |
| 163 | 153 | $flows_data[ $key ] = array(); |
| 164 | 154 | } |