| @@ -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 | |
| @@ -24,28 +25,17 @@ | ||
| 24 | 25 | * |
| 25 | 26 | * @return void |
| 26 | 27 | */ |
| 27 | 28 | 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 | - | |
| 29 | + if ( wp_next_scheduled( 'formidable_send_usage' ) ) { | |
| 36 | 30 | return; |
| 37 | 31 | } |
| 38 | 32 | |
| 39 | - if ( $timestamp ) { | |
| 40 | - return; | |
| 41 | - } | |
| 42 | - | |
| 43 | 33 | $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 ), | |
| 34 | + 'day' => rand( 0, 6 ) * DAY_IN_SECONDS, | |
| 35 | + 'hour' => rand( 0, 23 ) * HOUR_IN_SECONDS, | |
| 36 | + 'minute' => rand( 0, 59 ) * MINUTE_IN_SECONDS, | |
| 37 | + 'second' => rand( 0, 59 ), | |
| 48 | 38 | ); |
| 49 | 39 | |
| 50 | 40 | $offset = array_sum( $tracking ); |
| 51 | 41 | $init_send = strtotime( 'next sunday' ) + $offset; |
| @@ -55,36 +45,19 @@ | ||
| 55 | 45 | |
| 56 | 46 | /** |
| 57 | 47 | * Adds once weekly to the existing schedules. |
| 58 | 48 | * |
| 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 | 49 | * @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 | 50 | */ |
| 70 | 51 | public static function add_schedules( $schedules = array() ) { |
| 71 | - _deprecated_function( __METHOD__, '6.35' ); | |
| 52 | + $schedules['weekly'] = array( | |
| 53 | + 'interval' => DAY_IN_SECONDS * 7, | |
| 54 | + 'display' => __( 'Once Weekly', 'formidable' ), | |
| 55 | + ); | |
| 72 | 56 | return $schedules; |
| 73 | 57 | } |
| 74 | 58 | |
| 75 | 59 | /** |
| 76 | - * Checks if tracking is allowed. | |
| 77 | - * | |
| 78 | - * @since 6.16.3 | |
| 79 | - * | |
| 80 | - * @return bool | |
| 81 | - */ | |
| 82 | - public static function tracking_allowed() { | |
| 83 | - return (bool) FrmAppHelper::get_settings()->tracking; | |
| 84 | - } | |
| 85 | - | |
| 86 | - /** | |
| 87 | 60 | * @since 3.06.04 |
| 88 | 61 | * |
| 89 | 62 | * @return void |
| 90 | 63 | */ |
| @@ -96,13 +69,11 @@ | ||
| 96 | 69 | /** |
| 97 | 70 | * Loads scripts. |
| 98 | 71 | * |
| 99 | 72 | * @since 6.16.1 |
| 100 | - * | |
| 101 | - * @return void | |
| 102 | 73 | */ |
| 103 | 74 | public static function load_scripts() { |
| 104 | - if ( self::is_forms_list_page() || FrmAppHelper::is_admin_page( 'formidable-form-templates' ) || FrmAppHelper::is_admin_page() ) { | |
| 75 | + if ( self::is_forms_list_page() || FrmAppHelper::is_admin_page( 'formidable-form-templates' ) ) { | |
| 105 | 76 | wp_enqueue_script( 'frm-usage-tracking', FrmAppHelper::plugin_url() . '/js/admin/usage-tracking.js', array( 'formidable_dom' ), FrmAppHelper::$plug_version, true ); |
| 106 | 77 | } |
| 107 | 78 | } |
| 108 | 79 | |
| @@ -113,15 +84,20 @@ | ||
| 113 | 84 | * |
| 114 | 85 | * @return bool |
| 115 | 86 | */ |
| 116 | 87 | private static function is_forms_list_page() { |
| 117 | - if ( ! FrmAppHelper::on_form_listing_page() ) { | |
| 88 | + if ( ! FrmAppHelper::is_admin_page() ) { | |
| 118 | 89 | return false; |
| 119 | 90 | } |
| 120 | 91 | |
| 121 | - // Exclude Trash page. | |
| 92 | + // Check Trash page. | |
| 122 | 93 | $form_type = FrmAppHelper::simple_get( 'form_type' ); |
| 123 | - return 'published' === $form_type; | |
| 94 | + if ( $form_type && 'published' !== $form_type ) { | |
| 95 | + return false; | |
| 96 | + } | |
| 97 | + | |
| 98 | + // Check edit or settings page. | |
| 99 | + return ! FrmAppHelper::simple_get( 'frm_action' ); | |
| 124 | 100 | } |
| 125 | 101 | |
| 126 | 102 | /** |
| 127 | 103 | * AJAX handler to track flows. |
| @@ -126,10 +102,8 @@ | ||
| 126 | 102 | /** |
| 127 | 103 | * AJAX handler to track flows. |
| 128 | 104 | * |
| 129 | 105 | * @since 6.16.1 |
| 130 | - * | |
| 131 | - * @return void | |
| 132 | 106 | */ |
| 133 | 107 | public static function ajax_track_flows() { |
| 134 | 108 | FrmAppHelper::permission_check( 'frm_view_forms' ); |
| 135 | 109 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| @@ -142,9 +116,9 @@ | ||
| 142 | 116 | wp_send_json_success(); |
| 143 | 117 | } |
| 144 | 118 | |
| 145 | 119 | /** |
| 146 | - * Updates flows data. This increases the count of flow_data[ $key ][ $value ]. | |
| 120 | + * Updates flows data. | |
| 147 | 121 | * |
| 148 | 122 | * @since 6.16.1 |
| 149 | 123 | * |
| 150 | 124 | * @param string $key Flow key. |
| @@ -152,13 +126,13 @@ | ||
| 152 | 126 | * |
| 153 | 127 | * @return void |
| 154 | 128 | */ |
| 155 | 129 | public static function update_flows_data( $key, $value ) { |
| 130 | + $flows_data = self::get_flows_data(); | |
| 131 | + | |
| 156 | 132 | if ( '' === $key || '' === $value ) { |
| 157 | 133 | return; |
| 158 | 134 | } |
| 159 | - | |
| 160 | - $flows_data = self::get_flows_data(); | |
| 161 | 135 | |
| 162 | 136 | if ( ! isset( $flows_data[ $key ] ) ) { |
| 163 | 137 | $flows_data[ $key ] = array(); |
| 164 | 138 | } |