| @@ -32,8 +32,13 @@ | ||
| 32 | 32 | { |
| 33 | 33 | return; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | + if ( current_user_can( 'manage_propertyhive' ) ) | |
| 37 | + { | |
| 38 | + return; | |
| 39 | + } | |
| 40 | + | |
| 36 | 41 | if ( |
| 37 | 42 | !is_post_type_archive( 'property' ) && |
| 38 | 43 | !is_page( ph_get_page_id( 'search_results' ) ) |
| 39 | 44 | ) |
| @@ -40,8 +45,13 @@ | ||
| 40 | 45 | { |
| 41 | 46 | return; |
| 42 | 47 | } |
| 43 | 48 | |
| 49 | + if ( apply_filters( 'propertyhive_enable_search_analytics', true ) === false ) | |
| 50 | + { | |
| 51 | + return; | |
| 52 | + } | |
| 53 | + | |
| 44 | 54 | // Ignore page 2 onwards |
| 45 | 55 | if ( is_paged() ) |
| 46 | 56 | { |
| 47 | 57 | return; |
| @@ -60,8 +70,9 @@ | ||
| 60 | 70 | } |
| 61 | 71 | |
| 62 | 72 | $this->recorded = true; |
| 63 | 73 | |
| 74 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Append a UTC timestamp to the plugin's custom analytics table using wpdb field formats. | |
| 64 | 75 | $result = $wpdb->insert( |
| 65 | 76 | $wpdb->prefix . 'ph_search_log', |
| 66 | 77 | array( |
| 67 | 78 | 'searched_at' => current_time( 'mysql', true ), |
| @@ -80,16 +91,16 @@ | ||
| 80 | 91 | public function clear_old_searches() |
| 81 | 92 | { |
| 82 | 93 | global $wpdb; |
| 83 | 94 | |
| 84 | - $table_name = $wpdb->prefix . 'ph_search_log'; | |
| 85 | 95 | $cutoff = gmdate( 'Y-m-d H:i:s', strtotime( '-90 days' ) ); |
| 86 | 96 | |
| 87 | 97 | do |
| 88 | 98 | { |
| 99 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Retention deletes batches from the custom analytics table; its counts are read live and have no object-cache entries. | |
| 89 | 100 | $deleted = $wpdb->query( |
| 90 | 101 | $wpdb->prepare( |
| 91 | - "DELETE FROM {$table_name} | |
| 102 | + "DELETE FROM {$wpdb->prefix}ph_search_log | |
| 92 | 103 | WHERE searched_at < %s |
| 93 | 104 | ORDER BY searched_at ASC |
| 94 | 105 | LIMIT 500", |
| 95 | 106 | $cutoff |