| @@ -4,9 +4,8 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * @todo Show opt-in popup after plugin activation. |
| 8 | - * | |
| 9 | 8 | * @since 3.06.04 |
| 10 | 9 | */ |
| 11 | 10 | class FrmUsageController { |
| 12 | 11 | |
| @@ -26,27 +25,17 @@ | ||
| 26 | 25 | * |
| 27 | 26 | * @return void |
| 28 | 27 | */ |
| 29 | 28 | public static function schedule_send() { |
| 30 | - $timestamp = wp_next_scheduled( 'formidable_send_usage' ); | |
| 31 | - | |
| 32 | - if ( ! self::tracking_allowed() ) { | |
| 33 | - if ( $timestamp ) { | |
| 34 | - // Remove the scheduled event if it's not allowed and it's scheduled. | |
| 35 | - wp_unschedule_event( $timestamp, 'formidable_send_usage' ); | |
| 36 | - } | |
| 29 | + if ( wp_next_scheduled( 'formidable_send_usage' ) ) { | |
| 37 | 30 | return; |
| 38 | 31 | } |
| 39 | 32 | |
| 40 | - if ( $timestamp ) { | |
| 41 | - return; | |
| 42 | - } | |
| 43 | - | |
| 44 | 33 | $tracking = array( |
| 45 | - 'day' => random_int( 0, 6 ) * DAY_IN_SECONDS, | |
| 46 | - 'hour' => random_int( 0, 23 ) * HOUR_IN_SECONDS, | |
| 47 | - 'minute' => random_int( 0, 59 ) * MINUTE_IN_SECONDS, | |
| 48 | - '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 ), | |
| 49 | 38 | ); |
| 50 | 39 | |
| 51 | 40 | $offset = array_sum( $tracking ); |
| 52 | 41 | $init_send = strtotime( 'next sunday' ) + $offset; |
| @@ -57,12 +46,8 @@ | ||
| 57 | 46 | /** |
| 58 | 47 | * Adds once weekly to the existing schedules. |
| 59 | 48 | * |
| 60 | 49 | * @since 3.06.04 |
| 61 | - * | |
| 62 | - * @param array $schedules Schedules. | |
| 63 | - * | |
| 64 | - * @return array | |
| 65 | 50 | */ |
| 66 | 51 | public static function add_schedules( $schedules = array() ) { |
| 67 | 52 | $schedules['weekly'] = array( |
| 68 | 53 | 'interval' => DAY_IN_SECONDS * 7, |
| @@ -71,20 +56,8 @@ | ||
| 71 | 56 | return $schedules; |
| 72 | 57 | } |
| 73 | 58 | |
| 74 | 59 | /** |
| 75 | - * Checks if tracking is allowed. | |
| 76 | - * | |
| 77 | - * @since 6.16.3 | |
| 78 | - * | |
| 79 | - * @return bool | |
| 80 | - */ | |
| 81 | - public static function tracking_allowed() { | |
| 82 | - $settings = FrmAppHelper::get_settings(); | |
| 83 | - return $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 $form_type && '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' ); |