cookie fallback -> normalized). * * Used by the admin shell (RT_WA_Analytics_Admin), the reports controller and * the leads controller so every screen renders against the same resolved range. */ trait RT_WA_Analytics_Date_Range { private $date_from = ''; private $date_to = ''; private $date_label = ''; private $has_explicit_range = false; private function resolve_date_range() { $date_from = isset( $_GET['date_from'] ) ? sanitize_text_field( wp_unslash( $_GET['date_from'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $date_to = isset( $_GET['date_to'] ) ? sanitize_text_field( wp_unslash( $_GET['date_to'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! preg_match( '/^\d{4}-\d{2}-\d{2}$/', $date_from ) ) { $date_from = ''; } if ( ! preg_match( '/^\d{4}-\d{2}-\d{2}$/', $date_to ) ) { $date_to = ''; } if ( empty( $date_from ) || empty( $date_to ) ) { $cookie = isset( $_COOKIE['rt_wa_admin_date_range'] ) ? sanitize_text_field( wp_unslash( $_COOKIE['rt_wa_admin_date_range'] ) ) : ''; $decoded = $cookie ? json_decode( $cookie, true ) : null; if ( is_array( $decoded ) && ! empty( $decoded['from'] ) && ! empty( $decoded['to'] ) ) { if ( preg_match( '/^\d{4}-\d{2}-\d{2}$/', $decoded['from'] ) && preg_match( '/^\d{4}-\d{2}-\d{2}$/', $decoded['to'] ) ) { if ( empty( $date_from ) ) { $date_from = $decoded['from']; } if ( empty( $date_to ) ) { $date_to = $decoded['to']; } } } } list($date_from, $date_to) = RT_WA_Analytics_DB::normalize_date_range( $date_from, $date_to ); $this->date_from = $date_from; $this->date_to = $date_to; $this->date_label = $date_from === $date_to ? date_i18n( 'M j, Y', strtotime( $date_from ) ) : date_i18n( 'M j', strtotime( $date_from ) ) . ' — ' . date_i18n( 'M j, Y', strtotime( $date_to ) ); $this->has_explicit_range = isset( $_GET['date_from'] ) || isset( $_GET['date_to'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended } }