$get, 'path' => $path, 'post' => $post, ); try { return $render(); } finally { self::$simulated = $previous; } } public static function simulation(): ?array { return self::$simulated; } public static function get( string $key ): mixed { if ( null !== self::$simulated ) { $value = self::$simulated['get'][ $key ] ?? null; return null === $value ? null : map_deep( $value, 'sanitize_text_field' ); } return is_admin() && ! wp_doing_ajax() ? self::admin_get( $key ) : self::public_get( $key ); } private static function admin_get( string $key ): mixed { if ( ! isset( $_GET['rooster_view'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['rooster_view'] ) ), 'rooster_admin_view' ) ) { return null; } return isset( $_GET[ $key ] ) ? map_deep( wp_unslash( $_GET[ $key ] ), 'sanitize_text_field' ) : null; } private static function public_get( string $key ): mixed { return isset( $_GET[ $key ] ) ? map_deep( wp_unslash( $_GET[ $key ] ), 'sanitize_text_field' ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- a public page's read-only argument (see the docblock). } public static function args( TableDefinition $d ): array { $names = TableQuery::arg_names( $d ); $keys = array_merge( array( $names['page'], $names['per_page'], $names['orderby'], $names['order'], $names['after'] ), array_values( $names['filters'] ) ); if ( 'post' !== $d->search_transport() ) { $keys[] = $names['search']; } $out = array(); foreach ( $keys as $key ) { $value = self::get( $key ); if ( is_scalar( $value ) || is_array( $value ) ) { $out[ $key ] = $value; } } return $out; } public static function posted_search( TableDefinition $d ): array { $name = TableQuery::arg_names( $d )['search']; if ( null !== self::$simulated ) { $term = self::$simulated['post'][ $name ] ?? ''; return 'post' === $d->search_transport() && is_string( $term ) && '' !== $term ? array( $name => sanitize_text_field( $term ) ) : array(); } if ( 'post' !== $d->search_transport() || ! \RoosterLMS\Admin\Request::posted_nonce_valid( TableQuery::SEARCH_NONCE, TableQuery::SEARCH_ACTION ) ) { return array(); } $term = \RoosterLMS\Admin\Request::posted_value( $name ); return is_string( $term ) ? array( $name => $term ) : array(); } }