connect('post'); } public static function getSinceDate(string $date):string { return match ($date) { 'week' => '-1 week', 'month' => '-1 month', default => '-1 day', }; } public static function forUser(int $userID, ?string $sinceDate = null, bool $modified = false):array { $date = self::getSinceDate($sinceDate); $posts = new WP_Query([ 'posts_per_page' => -1, 'post_status' => 'publish', 'post_author' => $userID, 'date_query' => [ [ 'after' => $date, 'inclusive' => true, 'column' => $modified ? 'post_modified' : 'post_date' ] ], 'fields' => 'ids', ]); wp_reset_postdata(); return $posts->posts; } public static function forTerm(int $termID, string $taxonomy, ?string $sinceDate = null, bool $modified = false):array { if (!in_array($taxonomy, ['category', 'tag'])){ $taxonomy = jvbCheckBase($taxonomy); } $date = self::getSinceDate($sinceDate); $posts = new WP_Query([ 'posts_per_page' => -1, 'post_status' => 'publish', 'date_query' => [ [ 'after' => $date, 'inclusive' => true, 'column' => $modified ? 'post_modified' : 'post_date' ] ], 'tax_query' => [ [ 'taxonomy' => $taxonomy, 'terms' => $termID, ] ], 'fields' => 'ids', ]); wp_reset_postdata(); return $posts->posts; } public static function formatForNotification(array $IDs, string $type):array { $posts = []; foreach ($IDs as $ID) { $posts[] = self::$cache->remember( $ID, function() use ($ID) { $meta = Meta::forPost($ID); $img = $meta->get('post_thumbnail'); $registrar = Registrar::getInstance(get_post_type($ID)); return array_merge([ 'url' => get_the_permalink($ID), 'content' => $registrar->getType(), 'icon' => $registrar->getIcon(), 'image' => (!empty($img) ? jvbImageData($img) : []) ], $meta->getAll([ 'post_date', 'post_modified', 'post_title', 'post_excerpt', ]) ); } ); } return $posts; } }