PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.2
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.2
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / user-meta / application / custom-meta-collector.php

custom-meta-collector.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.2, at src/user-meta/application/custom-meta-collector.php

73 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\User_Meta\Application;
4
5 use Yoast\WP\SEO\User_Meta\Domain\Custom_Meta_Interface;
6
7 /**
8 * The collector to get custom user meta.
9 *
10 * @makePublic
11 */
12 class Custom_Meta_Collector {
13
14 /**
15 * All custom meta.
16 *
17 * @var array<Custom_Meta_Interface>
18 */
19 private $custom_meta;
20
21 /**
22 * The constructor.
23 *
24 * @param Custom_Meta_Interface ...$custom_meta All custom meta.
25 */
26 public function __construct( Custom_Meta_Interface ...$custom_meta ) {
27 $this->custom_meta = $custom_meta;
28 }
29
30 /**
31 * Returns all the custom meta.
32 *
33 * @return array<Custom_Meta_Interface> All the custom meta.
34 */
35 public function get_custom_meta(): array {
36 return $this->custom_meta;
37 }
38
39 /**
40 * Returns all the custom meta, sorted by rendering priority.
41 *
42 * @return array<Custom_Meta_Interface> All the custom meta, sorted by rendering priority.
43 */
44 public function get_sorted_custom_meta(): array {
45 $custom_meta = $this->get_custom_meta();
46
47 \usort(
48 $custom_meta,
49 static function ( Custom_Meta_Interface $a, Custom_Meta_Interface $b ) {
50 return ( $a->get_render_priority() <=> $b->get_render_priority() );
51 },
52 );
53
54 return $custom_meta;
55 }
56
57 /**
58 * Returns the custom meta that can't be empty.
59 *
60 * @return array<string> The custom meta that can't be empty.
61 */
62 public function get_non_empty_custom_meta(): array {
63 $non_empty_custom_meta = [];
64 foreach ( $this->custom_meta as $custom_meta ) {
65 if ( ! $custom_meta->is_empty_allowed() ) {
66 $non_empty_custom_meta[] = $custom_meta->get_key();
67 }
68 }
69
70 return $non_empty_custom_meta;
71 }
72 }
73