@@ -10,47 +10,47 @@ |
||
10 | 10 | */ |
11 | 11 | class Videoobject_Duplicate_Remover { |
12 | 12 | |
13 | - public function __construct() { |
|
14 | - add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10 ); |
|
15 | - } |
|
16 | - |
|
17 | - /** |
|
18 | - * @param $jsonld array The final jsonld. |
|
19 | - * @return array Filtered jsonld. |
|
20 | - */ |
|
21 | - public function wl_after_get_jsonld( $jsonld ) { |
|
22 | - |
|
23 | - if ( ! is_array( $jsonld ) |
|
24 | - || ! count( $jsonld ) > 1 |
|
25 | - || ! array_key_exists( 0, $jsonld ) ) { |
|
26 | - // Return early if there are no referenced entities. |
|
27 | - return $jsonld; |
|
28 | - } |
|
29 | - |
|
30 | - $post_jsonld = array_shift( $jsonld ); |
|
31 | - |
|
32 | - // we need to loop through all the items and remove the faq markup. |
|
33 | - foreach ( $jsonld as $key => &$value ) { |
|
34 | - if ( ! array_key_exists( '@type', $value ) ) { |
|
35 | - continue; |
|
36 | - } |
|
37 | - $type = $value['@type']; |
|
38 | - |
|
39 | - if ( ( is_string( $type ) && 'Article' !== $type ) |
|
40 | - || ( is_array( $type ) && ! in_array( 'Article', $type, true ) ) ) { |
|
41 | - continue; |
|
42 | - } |
|
43 | - // Video doesnt exist, dont try to remove it. |
|
44 | - if ( ! array_key_exists( 'video', $value ) ) { |
|
45 | - continue; |
|
46 | - } |
|
47 | - unset( $jsonld[ $key ]['video'] ); |
|
48 | - } |
|
49 | - |
|
50 | - // Add the post jsonld to front of jsonld array. |
|
51 | - array_unshift( $jsonld, $post_jsonld ); |
|
52 | - |
|
53 | - return $jsonld; |
|
54 | - } |
|
13 | + public function __construct() { |
|
14 | + add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10 ); |
|
15 | + } |
|
16 | + |
|
17 | + /** |
|
18 | + * @param $jsonld array The final jsonld. |
|
19 | + * @return array Filtered jsonld. |
|
20 | + */ |
|
21 | + public function wl_after_get_jsonld( $jsonld ) { |
|
22 | + |
|
23 | + if ( ! is_array( $jsonld ) |
|
24 | + || ! count( $jsonld ) > 1 |
|
25 | + || ! array_key_exists( 0, $jsonld ) ) { |
|
26 | + // Return early if there are no referenced entities. |
|
27 | + return $jsonld; |
|
28 | + } |
|
29 | + |
|
30 | + $post_jsonld = array_shift( $jsonld ); |
|
31 | + |
|
32 | + // we need to loop through all the items and remove the faq markup. |
|
33 | + foreach ( $jsonld as $key => &$value ) { |
|
34 | + if ( ! array_key_exists( '@type', $value ) ) { |
|
35 | + continue; |
|
36 | + } |
|
37 | + $type = $value['@type']; |
|
38 | + |
|
39 | + if ( ( is_string( $type ) && 'Article' !== $type ) |
|
40 | + || ( is_array( $type ) && ! in_array( 'Article', $type, true ) ) ) { |
|
41 | + continue; |
|
42 | + } |
|
43 | + // Video doesnt exist, dont try to remove it. |
|
44 | + if ( ! array_key_exists( 'video', $value ) ) { |
|
45 | + continue; |
|
46 | + } |
|
47 | + unset( $jsonld[ $key ]['video'] ); |
|
48 | + } |
|
49 | + |
|
50 | + // Add the post jsonld to front of jsonld array. |
|
51 | + array_unshift( $jsonld, $post_jsonld ); |
|
52 | + |
|
53 | + return $jsonld; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | } |
@@ -11,44 +11,44 @@ |
||
11 | 11 | class Videoobject_Duplicate_Remover { |
12 | 12 | |
13 | 13 | public function __construct() { |
14 | - add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10 ); |
|
14 | + add_filter('wl_after_get_jsonld', array($this, 'wl_after_get_jsonld'), 10); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @param $jsonld array The final jsonld. |
19 | 19 | * @return array Filtered jsonld. |
20 | 20 | */ |
21 | - public function wl_after_get_jsonld( $jsonld ) { |
|
21 | + public function wl_after_get_jsonld($jsonld) { |
|
22 | 22 | |
23 | - if ( ! is_array( $jsonld ) |
|
24 | - || ! count( $jsonld ) > 1 |
|
25 | - || ! array_key_exists( 0, $jsonld ) ) { |
|
23 | + if ( ! is_array($jsonld) |
|
24 | + || ! count($jsonld) > 1 |
|
25 | + || ! array_key_exists(0, $jsonld)) { |
|
26 | 26 | // Return early if there are no referenced entities. |
27 | 27 | return $jsonld; |
28 | 28 | } |
29 | 29 | |
30 | - $post_jsonld = array_shift( $jsonld ); |
|
30 | + $post_jsonld = array_shift($jsonld); |
|
31 | 31 | |
32 | 32 | // we need to loop through all the items and remove the faq markup. |
33 | - foreach ( $jsonld as $key => &$value ) { |
|
34 | - if ( ! array_key_exists( '@type', $value ) ) { |
|
33 | + foreach ($jsonld as $key => &$value) { |
|
34 | + if ( ! array_key_exists('@type', $value)) { |
|
35 | 35 | continue; |
36 | 36 | } |
37 | 37 | $type = $value['@type']; |
38 | 38 | |
39 | - if ( ( is_string( $type ) && 'Article' !== $type ) |
|
40 | - || ( is_array( $type ) && ! in_array( 'Article', $type, true ) ) ) { |
|
39 | + if ((is_string($type) && 'Article' !== $type) |
|
40 | + || (is_array($type) && ! in_array('Article', $type, true))) { |
|
41 | 41 | continue; |
42 | 42 | } |
43 | 43 | // Video doesnt exist, dont try to remove it. |
44 | - if ( ! array_key_exists( 'video', $value ) ) { |
|
44 | + if ( ! array_key_exists('video', $value)) { |
|
45 | 45 | continue; |
46 | 46 | } |
47 | - unset( $jsonld[ $key ]['video'] ); |
|
47 | + unset($jsonld[$key]['video']); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | // Add the post jsonld to front of jsonld array. |
51 | - array_unshift( $jsonld, $post_jsonld ); |
|
51 | + array_unshift($jsonld, $post_jsonld); |
|
52 | 52 | |
53 | 53 | return $jsonld; |
54 | 54 | } |
@@ -9,65 +9,65 @@ discard block |
||
9 | 9 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
10 | 10 | class Wordpress_Permalink_Content_Service implements Content_Service { |
11 | 11 | |
12 | - private static $instance = null; |
|
13 | - |
|
14 | - protected function __construct() { |
|
15 | - } |
|
16 | - |
|
17 | - /** |
|
18 | - * The singleton instance. |
|
19 | - * |
|
20 | - * @return Content_Service |
|
21 | - */ |
|
22 | - public static function get_instance() { |
|
23 | - if ( ! isset( self::$instance ) ) { |
|
24 | - self::$instance = new self(); |
|
25 | - } |
|
26 | - |
|
27 | - return self::$instance; |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * @param $uri string In the form https://example.org/path/post#post/1 |
|
32 | - * |
|
33 | - * @return Wordpress_Content|null |
|
34 | - */ |
|
35 | - public function get_by_entity_id( $uri ) { |
|
36 | - if ( ! preg_match( '@.*#(\w+)/(\d+)@', $uri, $matches ) ) { |
|
37 | - return null; |
|
38 | - } |
|
39 | - |
|
40 | - $type_name = $matches[1]; |
|
41 | - $id = $matches[2]; |
|
42 | - switch ( Object_Type_Enum::from_string( $type_name ) ) { |
|
43 | - case Object_Type_Enum::POST: |
|
44 | - return new Wordpress_Content( get_post( $id ) ); |
|
45 | - case Object_Type_Enum::TERM: |
|
46 | - return new Wordpress_Content( get_term( $id ) ); |
|
47 | - case Object_Type_Enum::USER: |
|
48 | - return new Wordpress_Content( get_user_by( 'ID', $id ) ); |
|
49 | - } |
|
50 | - |
|
51 | - return null; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Get a |
|
56 | - * |
|
57 | - * @throws Exception in case of error. |
|
58 | - */ |
|
59 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
60 | - // If the URL is in the local site URL, then try to find a corresponding post. |
|
61 | - if ( 0 === strpos( $uri, site_url() ) ) { |
|
62 | - return $this->get_by_entity_id( $uri ); |
|
63 | - } |
|
64 | - |
|
65 | - // Otherwise look in sameAs. |
|
66 | - global $wpdb; |
|
67 | - |
|
68 | - $row = $wpdb->get_row( |
|
69 | - $wpdb->prepare( |
|
70 | - " |
|
12 | + private static $instance = null; |
|
13 | + |
|
14 | + protected function __construct() { |
|
15 | + } |
|
16 | + |
|
17 | + /** |
|
18 | + * The singleton instance. |
|
19 | + * |
|
20 | + * @return Content_Service |
|
21 | + */ |
|
22 | + public static function get_instance() { |
|
23 | + if ( ! isset( self::$instance ) ) { |
|
24 | + self::$instance = new self(); |
|
25 | + } |
|
26 | + |
|
27 | + return self::$instance; |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * @param $uri string In the form https://example.org/path/post#post/1 |
|
32 | + * |
|
33 | + * @return Wordpress_Content|null |
|
34 | + */ |
|
35 | + public function get_by_entity_id( $uri ) { |
|
36 | + if ( ! preg_match( '@.*#(\w+)/(\d+)@', $uri, $matches ) ) { |
|
37 | + return null; |
|
38 | + } |
|
39 | + |
|
40 | + $type_name = $matches[1]; |
|
41 | + $id = $matches[2]; |
|
42 | + switch ( Object_Type_Enum::from_string( $type_name ) ) { |
|
43 | + case Object_Type_Enum::POST: |
|
44 | + return new Wordpress_Content( get_post( $id ) ); |
|
45 | + case Object_Type_Enum::TERM: |
|
46 | + return new Wordpress_Content( get_term( $id ) ); |
|
47 | + case Object_Type_Enum::USER: |
|
48 | + return new Wordpress_Content( get_user_by( 'ID', $id ) ); |
|
49 | + } |
|
50 | + |
|
51 | + return null; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Get a |
|
56 | + * |
|
57 | + * @throws Exception in case of error. |
|
58 | + */ |
|
59 | + public function get_by_entity_id_or_same_as( $uri ) { |
|
60 | + // If the URL is in the local site URL, then try to find a corresponding post. |
|
61 | + if ( 0 === strpos( $uri, site_url() ) ) { |
|
62 | + return $this->get_by_entity_id( $uri ); |
|
63 | + } |
|
64 | + |
|
65 | + // Otherwise look in sameAs. |
|
66 | + global $wpdb; |
|
67 | + |
|
68 | + $row = $wpdb->get_row( |
|
69 | + $wpdb->prepare( |
|
70 | + " |
|
71 | 71 | SELECT content_type, content_id |
72 | 72 | FROM ( |
73 | 73 | SELECT %d AS content_type, post_id AS content_id |
@@ -84,84 +84,84 @@ discard block |
||
84 | 84 | ) _tmp_same_as |
85 | 85 | LIMIT 1 |
86 | 86 | ", |
87 | - Object_Type_Enum::POST, |
|
88 | - $uri, |
|
89 | - Object_Type_Enum::TERM, |
|
90 | - $uri, |
|
91 | - Object_Type_Enum::USER, |
|
92 | - $uri |
|
93 | - ) |
|
94 | - ); |
|
95 | - |
|
96 | - if ( ! isset( $row ) ) { |
|
97 | - return null; |
|
98 | - } |
|
99 | - |
|
100 | - switch ( (int) $row->content_type ) { |
|
101 | - case Object_Type_Enum::POST: |
|
102 | - return new Wordpress_Content( get_post( $row->content_id ) ); |
|
103 | - case Object_Type_Enum::TERM: |
|
104 | - return new Wordpress_Content( get_term( $row->content_id ) ); |
|
105 | - case Object_Type_Enum::USER: |
|
106 | - return new Wordpress_Content( get_user_by( 'ID', $row->content_id ) ); |
|
107 | - default: |
|
108 | - return null; |
|
109 | - } |
|
110 | - |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @param Wordpress_Content_Id $content_id |
|
115 | - * |
|
116 | - * @return string|void|null |
|
117 | - */ |
|
118 | - public function get_entity_id( $content_id ) { |
|
119 | - $type = $content_id->get_type(); |
|
120 | - $id = $content_id->get_id(); |
|
121 | - |
|
122 | - switch ( $type ) { |
|
123 | - case Object_Type_Enum::POST: |
|
124 | - $base_uri = get_permalink( $id ); |
|
125 | - break; |
|
126 | - case Object_Type_Enum::TERM: |
|
127 | - $base_uri = get_term_link( $id ); |
|
128 | - break; |
|
129 | - case Object_Type_Enum::USER: |
|
130 | - $base_uri = get_author_posts_url( $id ); |
|
131 | - break; |
|
132 | - default: |
|
133 | - return null; |
|
134 | - } |
|
135 | - |
|
136 | - $type_name = Object_Type_Enum::to_string( $type ); |
|
137 | - |
|
138 | - return "$base_uri#$type_name/$id"; |
|
139 | - } |
|
140 | - |
|
141 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
142 | - public function set_entity_id( $content_id, $uri ) { |
|
143 | - // do nothing. |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @param Wordpress_Content_Id $content_id |
|
148 | - * |
|
149 | - * @return bool|void |
|
150 | - */ |
|
151 | - public function supports( $content_id ) { |
|
152 | - return in_array( |
|
153 | - $content_id->get_type(), |
|
154 | - array( |
|
155 | - Object_Type_Enum::POST, |
|
156 | - Object_Type_Enum::TERM, |
|
157 | - Object_Type_Enum::USER, |
|
158 | - ), |
|
159 | - true |
|
160 | - ); |
|
161 | - } |
|
162 | - |
|
163 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
164 | - public function delete( $content_id ) { |
|
165 | - // Ignore, we don't store any data. |
|
166 | - } |
|
87 | + Object_Type_Enum::POST, |
|
88 | + $uri, |
|
89 | + Object_Type_Enum::TERM, |
|
90 | + $uri, |
|
91 | + Object_Type_Enum::USER, |
|
92 | + $uri |
|
93 | + ) |
|
94 | + ); |
|
95 | + |
|
96 | + if ( ! isset( $row ) ) { |
|
97 | + return null; |
|
98 | + } |
|
99 | + |
|
100 | + switch ( (int) $row->content_type ) { |
|
101 | + case Object_Type_Enum::POST: |
|
102 | + return new Wordpress_Content( get_post( $row->content_id ) ); |
|
103 | + case Object_Type_Enum::TERM: |
|
104 | + return new Wordpress_Content( get_term( $row->content_id ) ); |
|
105 | + case Object_Type_Enum::USER: |
|
106 | + return new Wordpress_Content( get_user_by( 'ID', $row->content_id ) ); |
|
107 | + default: |
|
108 | + return null; |
|
109 | + } |
|
110 | + |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @param Wordpress_Content_Id $content_id |
|
115 | + * |
|
116 | + * @return string|void|null |
|
117 | + */ |
|
118 | + public function get_entity_id( $content_id ) { |
|
119 | + $type = $content_id->get_type(); |
|
120 | + $id = $content_id->get_id(); |
|
121 | + |
|
122 | + switch ( $type ) { |
|
123 | + case Object_Type_Enum::POST: |
|
124 | + $base_uri = get_permalink( $id ); |
|
125 | + break; |
|
126 | + case Object_Type_Enum::TERM: |
|
127 | + $base_uri = get_term_link( $id ); |
|
128 | + break; |
|
129 | + case Object_Type_Enum::USER: |
|
130 | + $base_uri = get_author_posts_url( $id ); |
|
131 | + break; |
|
132 | + default: |
|
133 | + return null; |
|
134 | + } |
|
135 | + |
|
136 | + $type_name = Object_Type_Enum::to_string( $type ); |
|
137 | + |
|
138 | + return "$base_uri#$type_name/$id"; |
|
139 | + } |
|
140 | + |
|
141 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
142 | + public function set_entity_id( $content_id, $uri ) { |
|
143 | + // do nothing. |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @param Wordpress_Content_Id $content_id |
|
148 | + * |
|
149 | + * @return bool|void |
|
150 | + */ |
|
151 | + public function supports( $content_id ) { |
|
152 | + return in_array( |
|
153 | + $content_id->get_type(), |
|
154 | + array( |
|
155 | + Object_Type_Enum::POST, |
|
156 | + Object_Type_Enum::TERM, |
|
157 | + Object_Type_Enum::USER, |
|
158 | + ), |
|
159 | + true |
|
160 | + ); |
|
161 | + } |
|
162 | + |
|
163 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
164 | + public function delete( $content_id ) { |
|
165 | + // Ignore, we don't store any data. |
|
166 | + } |
|
167 | 167 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @return Content_Service |
21 | 21 | */ |
22 | 22 | public static function get_instance() { |
23 | - if ( ! isset( self::$instance ) ) { |
|
23 | + if ( ! isset(self::$instance)) { |
|
24 | 24 | self::$instance = new self(); |
25 | 25 | } |
26 | 26 | |
@@ -32,20 +32,20 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return Wordpress_Content|null |
34 | 34 | */ |
35 | - public function get_by_entity_id( $uri ) { |
|
36 | - if ( ! preg_match( '@.*#(\w+)/(\d+)@', $uri, $matches ) ) { |
|
35 | + public function get_by_entity_id($uri) { |
|
36 | + if ( ! preg_match('@.*#(\w+)/(\d+)@', $uri, $matches)) { |
|
37 | 37 | return null; |
38 | 38 | } |
39 | 39 | |
40 | 40 | $type_name = $matches[1]; |
41 | 41 | $id = $matches[2]; |
42 | - switch ( Object_Type_Enum::from_string( $type_name ) ) { |
|
42 | + switch (Object_Type_Enum::from_string($type_name)) { |
|
43 | 43 | case Object_Type_Enum::POST: |
44 | - return new Wordpress_Content( get_post( $id ) ); |
|
44 | + return new Wordpress_Content(get_post($id)); |
|
45 | 45 | case Object_Type_Enum::TERM: |
46 | - return new Wordpress_Content( get_term( $id ) ); |
|
46 | + return new Wordpress_Content(get_term($id)); |
|
47 | 47 | case Object_Type_Enum::USER: |
48 | - return new Wordpress_Content( get_user_by( 'ID', $id ) ); |
|
48 | + return new Wordpress_Content(get_user_by('ID', $id)); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | return null; |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @throws Exception in case of error. |
58 | 58 | */ |
59 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
59 | + public function get_by_entity_id_or_same_as($uri) { |
|
60 | 60 | // If the URL is in the local site URL, then try to find a corresponding post. |
61 | - if ( 0 === strpos( $uri, site_url() ) ) { |
|
62 | - return $this->get_by_entity_id( $uri ); |
|
61 | + if (0 === strpos($uri, site_url())) { |
|
62 | + return $this->get_by_entity_id($uri); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | // Otherwise look in sameAs. |
@@ -93,17 +93,17 @@ discard block |
||
93 | 93 | ) |
94 | 94 | ); |
95 | 95 | |
96 | - if ( ! isset( $row ) ) { |
|
96 | + if ( ! isset($row)) { |
|
97 | 97 | return null; |
98 | 98 | } |
99 | 99 | |
100 | - switch ( (int) $row->content_type ) { |
|
100 | + switch ((int) $row->content_type) { |
|
101 | 101 | case Object_Type_Enum::POST: |
102 | - return new Wordpress_Content( get_post( $row->content_id ) ); |
|
102 | + return new Wordpress_Content(get_post($row->content_id)); |
|
103 | 103 | case Object_Type_Enum::TERM: |
104 | - return new Wordpress_Content( get_term( $row->content_id ) ); |
|
104 | + return new Wordpress_Content(get_term($row->content_id)); |
|
105 | 105 | case Object_Type_Enum::USER: |
106 | - return new Wordpress_Content( get_user_by( 'ID', $row->content_id ) ); |
|
106 | + return new Wordpress_Content(get_user_by('ID', $row->content_id)); |
|
107 | 107 | default: |
108 | 108 | return null; |
109 | 109 | } |
@@ -115,31 +115,31 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @return string|void|null |
117 | 117 | */ |
118 | - public function get_entity_id( $content_id ) { |
|
118 | + public function get_entity_id($content_id) { |
|
119 | 119 | $type = $content_id->get_type(); |
120 | 120 | $id = $content_id->get_id(); |
121 | 121 | |
122 | - switch ( $type ) { |
|
122 | + switch ($type) { |
|
123 | 123 | case Object_Type_Enum::POST: |
124 | - $base_uri = get_permalink( $id ); |
|
124 | + $base_uri = get_permalink($id); |
|
125 | 125 | break; |
126 | 126 | case Object_Type_Enum::TERM: |
127 | - $base_uri = get_term_link( $id ); |
|
127 | + $base_uri = get_term_link($id); |
|
128 | 128 | break; |
129 | 129 | case Object_Type_Enum::USER: |
130 | - $base_uri = get_author_posts_url( $id ); |
|
130 | + $base_uri = get_author_posts_url($id); |
|
131 | 131 | break; |
132 | 132 | default: |
133 | 133 | return null; |
134 | 134 | } |
135 | 135 | |
136 | - $type_name = Object_Type_Enum::to_string( $type ); |
|
136 | + $type_name = Object_Type_Enum::to_string($type); |
|
137 | 137 | |
138 | 138 | return "$base_uri#$type_name/$id"; |
139 | 139 | } |
140 | 140 | |
141 | 141 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
142 | - public function set_entity_id( $content_id, $uri ) { |
|
142 | + public function set_entity_id($content_id, $uri) { |
|
143 | 143 | // do nothing. |
144 | 144 | } |
145 | 145 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @return bool|void |
150 | 150 | */ |
151 | - public function supports( $content_id ) { |
|
151 | + public function supports($content_id) { |
|
152 | 152 | return in_array( |
153 | 153 | $content_id->get_type(), |
154 | 154 | array( |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | } |
162 | 162 | |
163 | 163 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
164 | - public function delete( $content_id ) { |
|
164 | + public function delete($content_id) { |
|
165 | 165 | // Ignore, we don't store any data. |
166 | 166 | } |
167 | 167 | } |
@@ -11,89 +11,89 @@ |
||
11 | 11 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
12 | 12 | class Wordpress_Content implements Content { |
13 | 13 | |
14 | - /** |
|
15 | - * The actual content. |
|
16 | - * |
|
17 | - * @var WP_Post|WP_Term|WP_User $bag |
|
18 | - */ |
|
19 | - private $bag; |
|
20 | - |
|
21 | - /** |
|
22 | - * Creates a WordPress content instance. |
|
23 | - * |
|
24 | - * @param WP_Post|WP_Term|WP_User $bag |
|
25 | - */ |
|
26 | - public function __construct( $bag ) { |
|
27 | - $this->bag = $bag; |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * The actual content. |
|
32 | - * |
|
33 | - * @return WP_Post|WP_Term|WP_User |
|
34 | - */ |
|
35 | - public function get_bag() { |
|
36 | - return $this->bag; |
|
37 | - } |
|
38 | - |
|
39 | - public function get_id() { |
|
40 | - if ( ! is_object( $this->bag ) ) { |
|
41 | - return null; |
|
42 | - } |
|
43 | - |
|
44 | - switch ( get_class( $this->bag ) ) { |
|
45 | - case 'WP_Post': |
|
46 | - case 'WP_User': |
|
47 | - return $this->bag->ID; |
|
48 | - case 'WP_Term': |
|
49 | - return $this->bag->term_id; |
|
50 | - } |
|
51 | - |
|
52 | - return null; |
|
53 | - } |
|
54 | - |
|
55 | - public function get_object_type_enum() { |
|
56 | - if ( ! is_object( $this->bag ) ) { |
|
57 | - return null; |
|
58 | - } |
|
59 | - |
|
60 | - return Object_Type_Enum::from_wordpress_instance( $this->bag ); |
|
61 | - } |
|
62 | - |
|
63 | - public function get_permalink() { |
|
64 | - if ( ! is_object( $this->bag ) ) { |
|
65 | - return null; |
|
66 | - } |
|
67 | - |
|
68 | - switch ( get_class( $this->bag ) ) { |
|
69 | - case 'WP_Post': |
|
70 | - return get_permalink( $this->get_bag()->ID ); |
|
71 | - case 'WP_User': |
|
72 | - return get_author_posts_url( $this->get_bag()->ID ); |
|
73 | - case 'WP_Term': |
|
74 | - return get_term_link( $this->bag->term_id ); |
|
75 | - } |
|
76 | - |
|
77 | - return null; |
|
78 | - } |
|
79 | - |
|
80 | - public function get_edit_link() { |
|
81 | - if ( ! is_object( $this->bag ) ) { |
|
82 | - return null; |
|
83 | - } |
|
84 | - |
|
85 | - switch ( get_class( $this->bag ) ) { |
|
86 | - case 'WP_Post': |
|
87 | - // We need to return & character as &, by default context is set to display. |
|
88 | - // so & will be returned as & breaking header location redirects. |
|
89 | - // By setting context to none we prevent this issue. |
|
90 | - return get_edit_post_link( $this->get_bag()->ID, 'none' ); |
|
91 | - case 'WP_User': |
|
92 | - return get_edit_user_link( $this->get_bag()->ID ); |
|
93 | - case 'WP_Term': |
|
94 | - return get_edit_term_link( $this->bag->term_id ); |
|
95 | - } |
|
96 | - |
|
97 | - return null; |
|
98 | - } |
|
14 | + /** |
|
15 | + * The actual content. |
|
16 | + * |
|
17 | + * @var WP_Post|WP_Term|WP_User $bag |
|
18 | + */ |
|
19 | + private $bag; |
|
20 | + |
|
21 | + /** |
|
22 | + * Creates a WordPress content instance. |
|
23 | + * |
|
24 | + * @param WP_Post|WP_Term|WP_User $bag |
|
25 | + */ |
|
26 | + public function __construct( $bag ) { |
|
27 | + $this->bag = $bag; |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * The actual content. |
|
32 | + * |
|
33 | + * @return WP_Post|WP_Term|WP_User |
|
34 | + */ |
|
35 | + public function get_bag() { |
|
36 | + return $this->bag; |
|
37 | + } |
|
38 | + |
|
39 | + public function get_id() { |
|
40 | + if ( ! is_object( $this->bag ) ) { |
|
41 | + return null; |
|
42 | + } |
|
43 | + |
|
44 | + switch ( get_class( $this->bag ) ) { |
|
45 | + case 'WP_Post': |
|
46 | + case 'WP_User': |
|
47 | + return $this->bag->ID; |
|
48 | + case 'WP_Term': |
|
49 | + return $this->bag->term_id; |
|
50 | + } |
|
51 | + |
|
52 | + return null; |
|
53 | + } |
|
54 | + |
|
55 | + public function get_object_type_enum() { |
|
56 | + if ( ! is_object( $this->bag ) ) { |
|
57 | + return null; |
|
58 | + } |
|
59 | + |
|
60 | + return Object_Type_Enum::from_wordpress_instance( $this->bag ); |
|
61 | + } |
|
62 | + |
|
63 | + public function get_permalink() { |
|
64 | + if ( ! is_object( $this->bag ) ) { |
|
65 | + return null; |
|
66 | + } |
|
67 | + |
|
68 | + switch ( get_class( $this->bag ) ) { |
|
69 | + case 'WP_Post': |
|
70 | + return get_permalink( $this->get_bag()->ID ); |
|
71 | + case 'WP_User': |
|
72 | + return get_author_posts_url( $this->get_bag()->ID ); |
|
73 | + case 'WP_Term': |
|
74 | + return get_term_link( $this->bag->term_id ); |
|
75 | + } |
|
76 | + |
|
77 | + return null; |
|
78 | + } |
|
79 | + |
|
80 | + public function get_edit_link() { |
|
81 | + if ( ! is_object( $this->bag ) ) { |
|
82 | + return null; |
|
83 | + } |
|
84 | + |
|
85 | + switch ( get_class( $this->bag ) ) { |
|
86 | + case 'WP_Post': |
|
87 | + // We need to return & character as &, by default context is set to display. |
|
88 | + // so & will be returned as & breaking header location redirects. |
|
89 | + // By setting context to none we prevent this issue. |
|
90 | + return get_edit_post_link( $this->get_bag()->ID, 'none' ); |
|
91 | + case 'WP_User': |
|
92 | + return get_edit_user_link( $this->get_bag()->ID ); |
|
93 | + case 'WP_Term': |
|
94 | + return get_edit_term_link( $this->bag->term_id ); |
|
95 | + } |
|
96 | + |
|
97 | + return null; |
|
98 | + } |
|
99 | 99 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param WP_Post|WP_Term|WP_User $bag |
25 | 25 | */ |
26 | - public function __construct( $bag ) { |
|
26 | + public function __construct($bag) { |
|
27 | 27 | $this->bag = $bag; |
28 | 28 | } |
29 | 29 | |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | } |
38 | 38 | |
39 | 39 | public function get_id() { |
40 | - if ( ! is_object( $this->bag ) ) { |
|
40 | + if ( ! is_object($this->bag)) { |
|
41 | 41 | return null; |
42 | 42 | } |
43 | 43 | |
44 | - switch ( get_class( $this->bag ) ) { |
|
44 | + switch (get_class($this->bag)) { |
|
45 | 45 | case 'WP_Post': |
46 | 46 | case 'WP_User': |
47 | 47 | return $this->bag->ID; |
@@ -53,45 +53,45 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | public function get_object_type_enum() { |
56 | - if ( ! is_object( $this->bag ) ) { |
|
56 | + if ( ! is_object($this->bag)) { |
|
57 | 57 | return null; |
58 | 58 | } |
59 | 59 | |
60 | - return Object_Type_Enum::from_wordpress_instance( $this->bag ); |
|
60 | + return Object_Type_Enum::from_wordpress_instance($this->bag); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | public function get_permalink() { |
64 | - if ( ! is_object( $this->bag ) ) { |
|
64 | + if ( ! is_object($this->bag)) { |
|
65 | 65 | return null; |
66 | 66 | } |
67 | 67 | |
68 | - switch ( get_class( $this->bag ) ) { |
|
68 | + switch (get_class($this->bag)) { |
|
69 | 69 | case 'WP_Post': |
70 | - return get_permalink( $this->get_bag()->ID ); |
|
70 | + return get_permalink($this->get_bag()->ID); |
|
71 | 71 | case 'WP_User': |
72 | - return get_author_posts_url( $this->get_bag()->ID ); |
|
72 | + return get_author_posts_url($this->get_bag()->ID); |
|
73 | 73 | case 'WP_Term': |
74 | - return get_term_link( $this->bag->term_id ); |
|
74 | + return get_term_link($this->bag->term_id); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | return null; |
78 | 78 | } |
79 | 79 | |
80 | 80 | public function get_edit_link() { |
81 | - if ( ! is_object( $this->bag ) ) { |
|
81 | + if ( ! is_object($this->bag)) { |
|
82 | 82 | return null; |
83 | 83 | } |
84 | 84 | |
85 | - switch ( get_class( $this->bag ) ) { |
|
85 | + switch (get_class($this->bag)) { |
|
86 | 86 | case 'WP_Post': |
87 | 87 | // We need to return & character as &, by default context is set to display. |
88 | 88 | // so & will be returned as & breaking header location redirects. |
89 | 89 | // By setting context to none we prevent this issue. |
90 | - return get_edit_post_link( $this->get_bag()->ID, 'none' ); |
|
90 | + return get_edit_post_link($this->get_bag()->ID, 'none'); |
|
91 | 91 | case 'WP_User': |
92 | - return get_edit_user_link( $this->get_bag()->ID ); |
|
92 | + return get_edit_user_link($this->get_bag()->ID); |
|
93 | 93 | case 'WP_Term': |
94 | - return get_edit_term_link( $this->bag->term_id ); |
|
94 | + return get_edit_term_link($this->bag->term_id); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | return null; |
@@ -8,29 +8,29 @@ |
||
8 | 8 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
9 | 9 | abstract class Abstract_Wordpress_Content_Legacy_Service extends Abstract_Wordpress_Content_Service { |
10 | 10 | |
11 | - private $expected_object_type; |
|
12 | - private $get_meta_fn; |
|
13 | - |
|
14 | - protected function __construct( $expected_object_type, $get_meta_fn ) { |
|
15 | - parent::__construct(); |
|
16 | - |
|
17 | - $this->expected_object_type = $expected_object_type; |
|
18 | - $this->get_meta_fn = $get_meta_fn; |
|
19 | - } |
|
20 | - |
|
21 | - public function get_entity_id( $content_id ) { |
|
22 | - Assertions::equals( |
|
23 | - $content_id->get_type(), |
|
24 | - $this->expected_object_type, |
|
25 | - sprintf( '`content_id` must be of type `%s`.', Object_Type_Enum::to_string( $this->expected_object_type ) ) |
|
26 | - ); |
|
27 | - |
|
28 | - $result = call_user_func( $this->get_meta_fn, $content_id->get_id(), 'entity_url', true ); |
|
29 | - return $result ? $result : null; |
|
30 | - } |
|
31 | - |
|
32 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
33 | - public function delete( $content_id ) { |
|
34 | - // do nothing, WP deletes the post meta for us. |
|
35 | - } |
|
11 | + private $expected_object_type; |
|
12 | + private $get_meta_fn; |
|
13 | + |
|
14 | + protected function __construct( $expected_object_type, $get_meta_fn ) { |
|
15 | + parent::__construct(); |
|
16 | + |
|
17 | + $this->expected_object_type = $expected_object_type; |
|
18 | + $this->get_meta_fn = $get_meta_fn; |
|
19 | + } |
|
20 | + |
|
21 | + public function get_entity_id( $content_id ) { |
|
22 | + Assertions::equals( |
|
23 | + $content_id->get_type(), |
|
24 | + $this->expected_object_type, |
|
25 | + sprintf( '`content_id` must be of type `%s`.', Object_Type_Enum::to_string( $this->expected_object_type ) ) |
|
26 | + ); |
|
27 | + |
|
28 | + $result = call_user_func( $this->get_meta_fn, $content_id->get_id(), 'entity_url', true ); |
|
29 | + return $result ? $result : null; |
|
30 | + } |
|
31 | + |
|
32 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
33 | + public function delete( $content_id ) { |
|
34 | + // do nothing, WP deletes the post meta for us. |
|
35 | + } |
|
36 | 36 | } |
@@ -11,26 +11,26 @@ |
||
11 | 11 | private $expected_object_type; |
12 | 12 | private $get_meta_fn; |
13 | 13 | |
14 | - protected function __construct( $expected_object_type, $get_meta_fn ) { |
|
14 | + protected function __construct($expected_object_type, $get_meta_fn) { |
|
15 | 15 | parent::__construct(); |
16 | 16 | |
17 | 17 | $this->expected_object_type = $expected_object_type; |
18 | 18 | $this->get_meta_fn = $get_meta_fn; |
19 | 19 | } |
20 | 20 | |
21 | - public function get_entity_id( $content_id ) { |
|
21 | + public function get_entity_id($content_id) { |
|
22 | 22 | Assertions::equals( |
23 | 23 | $content_id->get_type(), |
24 | 24 | $this->expected_object_type, |
25 | - sprintf( '`content_id` must be of type `%s`.', Object_Type_Enum::to_string( $this->expected_object_type ) ) |
|
25 | + sprintf('`content_id` must be of type `%s`.', Object_Type_Enum::to_string($this->expected_object_type)) |
|
26 | 26 | ); |
27 | 27 | |
28 | - $result = call_user_func( $this->get_meta_fn, $content_id->get_id(), 'entity_url', true ); |
|
28 | + $result = call_user_func($this->get_meta_fn, $content_id->get_id(), 'entity_url', true); |
|
29 | 29 | return $result ? $result : null; |
30 | 30 | } |
31 | 31 | |
32 | 32 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
33 | - public function delete( $content_id ) { |
|
33 | + public function delete($content_id) { |
|
34 | 34 | // do nothing, WP deletes the post meta for us. |
35 | 35 | } |
36 | 36 | } |
@@ -8,73 +8,73 @@ |
||
8 | 8 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
9 | 9 | class Wordpress_Dataset_Content_Service_Hooks { |
10 | 10 | |
11 | - public static function register() { |
|
12 | - add_action( 'wp_insert_post', array( get_called_class(), 'insert_post' ) ); |
|
13 | - add_action( 'after_delete_post', array( get_called_class(), 'after_delete_post' ) ); |
|
14 | - add_action( 'created_term', array( get_called_class(), 'created_term' ) ); |
|
15 | - add_action( 'delete_term', array( get_called_class(), 'delete_term' ) ); |
|
16 | - add_action( 'user_register', array( get_called_class(), 'user_register' ) ); |
|
17 | - add_action( 'deleted_user', array( get_called_class(), 'deleted_user' ) ); |
|
18 | - } |
|
11 | + public static function register() { |
|
12 | + add_action( 'wp_insert_post', array( get_called_class(), 'insert_post' ) ); |
|
13 | + add_action( 'after_delete_post', array( get_called_class(), 'after_delete_post' ) ); |
|
14 | + add_action( 'created_term', array( get_called_class(), 'created_term' ) ); |
|
15 | + add_action( 'delete_term', array( get_called_class(), 'delete_term' ) ); |
|
16 | + add_action( 'user_register', array( get_called_class(), 'user_register' ) ); |
|
17 | + add_action( 'deleted_user', array( get_called_class(), 'deleted_user' ) ); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @throws Exception in case of error. |
|
22 | - */ |
|
23 | - public static function insert_post( $post_id ) { |
|
24 | - if ( ! wp_is_post_revision( $post_id ) ) { |
|
25 | - self::set_entity_id( Wordpress_Content_Id::create_post( $post_id ) ); |
|
26 | - } |
|
27 | - } |
|
20 | + /** |
|
21 | + * @throws Exception in case of error. |
|
22 | + */ |
|
23 | + public static function insert_post( $post_id ) { |
|
24 | + if ( ! wp_is_post_revision( $post_id ) ) { |
|
25 | + self::set_entity_id( Wordpress_Content_Id::create_post( $post_id ) ); |
|
26 | + } |
|
27 | + } |
|
28 | 28 | |
29 | - public static function after_delete_post( $post_id ) { |
|
30 | - self::delete( Wordpress_Content_Id::create_post( $post_id ) ); |
|
31 | - } |
|
29 | + public static function after_delete_post( $post_id ) { |
|
30 | + self::delete( Wordpress_Content_Id::create_post( $post_id ) ); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @throws Exception in case of error. |
|
35 | - */ |
|
36 | - public static function created_term( $term_id ) { |
|
37 | - self::set_entity_id( Wordpress_Content_Id::create_term( $term_id ) ); |
|
38 | - } |
|
33 | + /** |
|
34 | + * @throws Exception in case of error. |
|
35 | + */ |
|
36 | + public static function created_term( $term_id ) { |
|
37 | + self::set_entity_id( Wordpress_Content_Id::create_term( $term_id ) ); |
|
38 | + } |
|
39 | 39 | |
40 | - public static function delete_term( $term_id ) { |
|
41 | - self::delete( Wordpress_Content_Id::create_term( $term_id ) ); |
|
42 | - } |
|
40 | + public static function delete_term( $term_id ) { |
|
41 | + self::delete( Wordpress_Content_Id::create_term( $term_id ) ); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @throws Exception in case of error. |
|
46 | - */ |
|
47 | - public static function user_register( $user_id ) { |
|
48 | - self::set_entity_id( Wordpress_Content_Id::create_user( $user_id ) ); |
|
49 | - } |
|
44 | + /** |
|
45 | + * @throws Exception in case of error. |
|
46 | + */ |
|
47 | + public static function user_register( $user_id ) { |
|
48 | + self::set_entity_id( Wordpress_Content_Id::create_user( $user_id ) ); |
|
49 | + } |
|
50 | 50 | |
51 | - public static function deleted_user( $user_id ) { |
|
52 | - self::delete( Wordpress_Content_Id::create_user( $user_id ) ); |
|
53 | - } |
|
51 | + public static function deleted_user( $user_id ) { |
|
52 | + self::delete( Wordpress_Content_Id::create_user( $user_id ) ); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param Wordpress_Content_Id $content_id |
|
57 | - * |
|
58 | - * @return void |
|
59 | - * @throws Exception in case of error. |
|
60 | - */ |
|
61 | - private static function set_entity_id( $content_id ) { |
|
62 | - $content_service = Wordpress_Content_Service::get_instance(); |
|
63 | - try { |
|
64 | - $existing_id = $content_service->get_entity_id( $content_id ); |
|
65 | - if ( empty( $existing_id ) ) { |
|
66 | - $rel_uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() ); |
|
67 | - $content_service->set_entity_id( $content_id, $rel_uri ); |
|
68 | - } |
|
69 | - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
70 | - } catch ( Exception $e ) { |
|
71 | - // Don't report. |
|
72 | - } |
|
73 | - } |
|
55 | + /** |
|
56 | + * @param Wordpress_Content_Id $content_id |
|
57 | + * |
|
58 | + * @return void |
|
59 | + * @throws Exception in case of error. |
|
60 | + */ |
|
61 | + private static function set_entity_id( $content_id ) { |
|
62 | + $content_service = Wordpress_Content_Service::get_instance(); |
|
63 | + try { |
|
64 | + $existing_id = $content_service->get_entity_id( $content_id ); |
|
65 | + if ( empty( $existing_id ) ) { |
|
66 | + $rel_uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() ); |
|
67 | + $content_service->set_entity_id( $content_id, $rel_uri ); |
|
68 | + } |
|
69 | + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
70 | + } catch ( Exception $e ) { |
|
71 | + // Don't report. |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - private static function delete( $content_id ) { |
|
76 | - $content_service = Wordpress_Content_Service::get_instance(); |
|
77 | - $content_service->delete( $content_id ); |
|
78 | - } |
|
75 | + private static function delete( $content_id ) { |
|
76 | + $content_service = Wordpress_Content_Service::get_instance(); |
|
77 | + $content_service->delete( $content_id ); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | } |
@@ -9,47 +9,47 @@ discard block |
||
9 | 9 | class Wordpress_Dataset_Content_Service_Hooks { |
10 | 10 | |
11 | 11 | public static function register() { |
12 | - add_action( 'wp_insert_post', array( get_called_class(), 'insert_post' ) ); |
|
13 | - add_action( 'after_delete_post', array( get_called_class(), 'after_delete_post' ) ); |
|
14 | - add_action( 'created_term', array( get_called_class(), 'created_term' ) ); |
|
15 | - add_action( 'delete_term', array( get_called_class(), 'delete_term' ) ); |
|
16 | - add_action( 'user_register', array( get_called_class(), 'user_register' ) ); |
|
17 | - add_action( 'deleted_user', array( get_called_class(), 'deleted_user' ) ); |
|
12 | + add_action('wp_insert_post', array(get_called_class(), 'insert_post')); |
|
13 | + add_action('after_delete_post', array(get_called_class(), 'after_delete_post')); |
|
14 | + add_action('created_term', array(get_called_class(), 'created_term')); |
|
15 | + add_action('delete_term', array(get_called_class(), 'delete_term')); |
|
16 | + add_action('user_register', array(get_called_class(), 'user_register')); |
|
17 | + add_action('deleted_user', array(get_called_class(), 'deleted_user')); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @throws Exception in case of error. |
22 | 22 | */ |
23 | - public static function insert_post( $post_id ) { |
|
24 | - if ( ! wp_is_post_revision( $post_id ) ) { |
|
25 | - self::set_entity_id( Wordpress_Content_Id::create_post( $post_id ) ); |
|
23 | + public static function insert_post($post_id) { |
|
24 | + if ( ! wp_is_post_revision($post_id)) { |
|
25 | + self::set_entity_id(Wordpress_Content_Id::create_post($post_id)); |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
29 | - public static function after_delete_post( $post_id ) { |
|
30 | - self::delete( Wordpress_Content_Id::create_post( $post_id ) ); |
|
29 | + public static function after_delete_post($post_id) { |
|
30 | + self::delete(Wordpress_Content_Id::create_post($post_id)); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @throws Exception in case of error. |
35 | 35 | */ |
36 | - public static function created_term( $term_id ) { |
|
37 | - self::set_entity_id( Wordpress_Content_Id::create_term( $term_id ) ); |
|
36 | + public static function created_term($term_id) { |
|
37 | + self::set_entity_id(Wordpress_Content_Id::create_term($term_id)); |
|
38 | 38 | } |
39 | 39 | |
40 | - public static function delete_term( $term_id ) { |
|
41 | - self::delete( Wordpress_Content_Id::create_term( $term_id ) ); |
|
40 | + public static function delete_term($term_id) { |
|
41 | + self::delete(Wordpress_Content_Id::create_term($term_id)); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @throws Exception in case of error. |
46 | 46 | */ |
47 | - public static function user_register( $user_id ) { |
|
48 | - self::set_entity_id( Wordpress_Content_Id::create_user( $user_id ) ); |
|
47 | + public static function user_register($user_id) { |
|
48 | + self::set_entity_id(Wordpress_Content_Id::create_user($user_id)); |
|
49 | 49 | } |
50 | 50 | |
51 | - public static function deleted_user( $user_id ) { |
|
52 | - self::delete( Wordpress_Content_Id::create_user( $user_id ) ); |
|
51 | + public static function deleted_user($user_id) { |
|
52 | + self::delete(Wordpress_Content_Id::create_user($user_id)); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -58,23 +58,23 @@ discard block |
||
58 | 58 | * @return void |
59 | 59 | * @throws Exception in case of error. |
60 | 60 | */ |
61 | - private static function set_entity_id( $content_id ) { |
|
61 | + private static function set_entity_id($content_id) { |
|
62 | 62 | $content_service = Wordpress_Content_Service::get_instance(); |
63 | 63 | try { |
64 | - $existing_id = $content_service->get_entity_id( $content_id ); |
|
65 | - if ( empty( $existing_id ) ) { |
|
66 | - $rel_uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() ); |
|
67 | - $content_service->set_entity_id( $content_id, $rel_uri ); |
|
64 | + $existing_id = $content_service->get_entity_id($content_id); |
|
65 | + if (empty($existing_id)) { |
|
66 | + $rel_uri = Entity_Uri_Generator::create_uri($content_id->get_type(), $content_id->get_id()); |
|
67 | + $content_service->set_entity_id($content_id, $rel_uri); |
|
68 | 68 | } |
69 | 69 | // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
70 | - } catch ( Exception $e ) { |
|
70 | + } catch (Exception $e) { |
|
71 | 71 | // Don't report. |
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | - private static function delete( $content_id ) { |
|
75 | + private static function delete($content_id) { |
|
76 | 76 | $content_service = Wordpress_Content_Service::get_instance(); |
77 | - $content_service->delete( $content_id ); |
|
77 | + $content_service->delete($content_id); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | } |
@@ -9,111 +9,111 @@ |
||
9 | 9 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
10 | 10 | class Wordpress_Dataset_Content_Service implements Content_Service { |
11 | 11 | |
12 | - /** |
|
13 | - * @var Content_Service[] |
|
14 | - */ |
|
15 | - private $delegates = array(); |
|
16 | - |
|
17 | - protected function __construct() { |
|
18 | - |
|
19 | - } |
|
20 | - |
|
21 | - private static $instance = null; |
|
22 | - |
|
23 | - /** |
|
24 | - * The singleton instance. |
|
25 | - * |
|
26 | - * @return Content_Service |
|
27 | - */ |
|
28 | - public static function get_instance() { |
|
29 | - if ( ! isset( self::$instance ) ) { |
|
30 | - self::$instance = new self(); |
|
31 | - |
|
32 | - self::$instance->register_delegate( Wordpress_Post_Content_Service::get_instance() ); |
|
33 | - self::$instance->register_delegate( Wordpress_Term_Content_Legacy_Service::get_instance() ); |
|
34 | - self::$instance->register_delegate( Wordpress_User_Content_Legacy_Service::get_instance() ); |
|
35 | - |
|
36 | - Wordpress_Dataset_Content_Service_Hooks::register(); |
|
37 | - } |
|
38 | - |
|
39 | - return self::$instance; |
|
40 | - } |
|
41 | - |
|
42 | - public function register_delegate( $delegate ) { |
|
43 | - Assertions::is_a( $delegate, 'Wordlift\Content\Content_Service', 'A `delegate` must implement the `Wordlift\Content\Content_Service` interface.' ); |
|
44 | - |
|
45 | - $this->delegates[] = $delegate; |
|
46 | - } |
|
47 | - |
|
48 | - public function get_by_entity_id( $uri ) { |
|
49 | - foreach ( $this->delegates as $delegate ) { |
|
50 | - $content = $delegate->get_by_entity_id_or_same_as( $uri ); |
|
51 | - if ( isset( $content ) ) { |
|
52 | - return $content; |
|
53 | - } |
|
54 | - } |
|
55 | - |
|
56 | - return null; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Get a |
|
61 | - * |
|
62 | - * @throws Exception in case of error. |
|
63 | - */ |
|
64 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
65 | - foreach ( $this->delegates as $delegate ) { |
|
66 | - $content = $delegate->get_by_entity_id_or_same_as( $uri ); |
|
67 | - if ( isset( $content ) ) { |
|
68 | - return $content; |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - return null; |
|
73 | - } |
|
74 | - |
|
75 | - public function get_entity_id( $content_id ) { |
|
76 | - foreach ( $this->delegates as $delegate ) { |
|
77 | - if ( ! $delegate->supports( $content_id ) ) { |
|
78 | - continue; |
|
79 | - } |
|
80 | - $uri = $delegate->get_entity_id( $content_id ); |
|
81 | - if ( $uri ) { |
|
82 | - return $uri; |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - return null; |
|
87 | - } |
|
88 | - |
|
89 | - public function set_entity_id( $content_id, $uri ) { |
|
90 | - foreach ( $this->delegates as $delegate ) { |
|
91 | - if ( $delegate->supports( $content_id ) ) { |
|
92 | - $delegate->set_entity_id( $content_id, $uri ); |
|
93 | - |
|
94 | - return; |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - throw new Exception( 'Not supported' ); |
|
99 | - } |
|
100 | - |
|
101 | - public function supports( $content_id ) { |
|
102 | - foreach ( $this->delegates as $delegate ) { |
|
103 | - if ( $delegate->supports( $content_id ) ) { |
|
104 | - return true; |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - return false; |
|
109 | - } |
|
110 | - |
|
111 | - public function delete( $content_id ) { |
|
112 | - foreach ( $this->delegates as $delegate ) { |
|
113 | - if ( $delegate->supports( $content_id ) ) { |
|
114 | - $delegate->delete( $content_id ); |
|
115 | - break; |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
12 | + /** |
|
13 | + * @var Content_Service[] |
|
14 | + */ |
|
15 | + private $delegates = array(); |
|
16 | + |
|
17 | + protected function __construct() { |
|
18 | + |
|
19 | + } |
|
20 | + |
|
21 | + private static $instance = null; |
|
22 | + |
|
23 | + /** |
|
24 | + * The singleton instance. |
|
25 | + * |
|
26 | + * @return Content_Service |
|
27 | + */ |
|
28 | + public static function get_instance() { |
|
29 | + if ( ! isset( self::$instance ) ) { |
|
30 | + self::$instance = new self(); |
|
31 | + |
|
32 | + self::$instance->register_delegate( Wordpress_Post_Content_Service::get_instance() ); |
|
33 | + self::$instance->register_delegate( Wordpress_Term_Content_Legacy_Service::get_instance() ); |
|
34 | + self::$instance->register_delegate( Wordpress_User_Content_Legacy_Service::get_instance() ); |
|
35 | + |
|
36 | + Wordpress_Dataset_Content_Service_Hooks::register(); |
|
37 | + } |
|
38 | + |
|
39 | + return self::$instance; |
|
40 | + } |
|
41 | + |
|
42 | + public function register_delegate( $delegate ) { |
|
43 | + Assertions::is_a( $delegate, 'Wordlift\Content\Content_Service', 'A `delegate` must implement the `Wordlift\Content\Content_Service` interface.' ); |
|
44 | + |
|
45 | + $this->delegates[] = $delegate; |
|
46 | + } |
|
47 | + |
|
48 | + public function get_by_entity_id( $uri ) { |
|
49 | + foreach ( $this->delegates as $delegate ) { |
|
50 | + $content = $delegate->get_by_entity_id_or_same_as( $uri ); |
|
51 | + if ( isset( $content ) ) { |
|
52 | + return $content; |
|
53 | + } |
|
54 | + } |
|
55 | + |
|
56 | + return null; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Get a |
|
61 | + * |
|
62 | + * @throws Exception in case of error. |
|
63 | + */ |
|
64 | + public function get_by_entity_id_or_same_as( $uri ) { |
|
65 | + foreach ( $this->delegates as $delegate ) { |
|
66 | + $content = $delegate->get_by_entity_id_or_same_as( $uri ); |
|
67 | + if ( isset( $content ) ) { |
|
68 | + return $content; |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + return null; |
|
73 | + } |
|
74 | + |
|
75 | + public function get_entity_id( $content_id ) { |
|
76 | + foreach ( $this->delegates as $delegate ) { |
|
77 | + if ( ! $delegate->supports( $content_id ) ) { |
|
78 | + continue; |
|
79 | + } |
|
80 | + $uri = $delegate->get_entity_id( $content_id ); |
|
81 | + if ( $uri ) { |
|
82 | + return $uri; |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + return null; |
|
87 | + } |
|
88 | + |
|
89 | + public function set_entity_id( $content_id, $uri ) { |
|
90 | + foreach ( $this->delegates as $delegate ) { |
|
91 | + if ( $delegate->supports( $content_id ) ) { |
|
92 | + $delegate->set_entity_id( $content_id, $uri ); |
|
93 | + |
|
94 | + return; |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + throw new Exception( 'Not supported' ); |
|
99 | + } |
|
100 | + |
|
101 | + public function supports( $content_id ) { |
|
102 | + foreach ( $this->delegates as $delegate ) { |
|
103 | + if ( $delegate->supports( $content_id ) ) { |
|
104 | + return true; |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + return false; |
|
109 | + } |
|
110 | + |
|
111 | + public function delete( $content_id ) { |
|
112 | + foreach ( $this->delegates as $delegate ) { |
|
113 | + if ( $delegate->supports( $content_id ) ) { |
|
114 | + $delegate->delete( $content_id ); |
|
115 | + break; |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | 119 | } |
@@ -26,12 +26,12 @@ discard block |
||
26 | 26 | * @return Content_Service |
27 | 27 | */ |
28 | 28 | public static function get_instance() { |
29 | - if ( ! isset( self::$instance ) ) { |
|
29 | + if ( ! isset(self::$instance)) { |
|
30 | 30 | self::$instance = new self(); |
31 | 31 | |
32 | - self::$instance->register_delegate( Wordpress_Post_Content_Service::get_instance() ); |
|
33 | - self::$instance->register_delegate( Wordpress_Term_Content_Legacy_Service::get_instance() ); |
|
34 | - self::$instance->register_delegate( Wordpress_User_Content_Legacy_Service::get_instance() ); |
|
32 | + self::$instance->register_delegate(Wordpress_Post_Content_Service::get_instance()); |
|
33 | + self::$instance->register_delegate(Wordpress_Term_Content_Legacy_Service::get_instance()); |
|
34 | + self::$instance->register_delegate(Wordpress_User_Content_Legacy_Service::get_instance()); |
|
35 | 35 | |
36 | 36 | Wordpress_Dataset_Content_Service_Hooks::register(); |
37 | 37 | } |
@@ -39,16 +39,16 @@ discard block |
||
39 | 39 | return self::$instance; |
40 | 40 | } |
41 | 41 | |
42 | - public function register_delegate( $delegate ) { |
|
43 | - Assertions::is_a( $delegate, 'Wordlift\Content\Content_Service', 'A `delegate` must implement the `Wordlift\Content\Content_Service` interface.' ); |
|
42 | + public function register_delegate($delegate) { |
|
43 | + Assertions::is_a($delegate, 'Wordlift\Content\Content_Service', 'A `delegate` must implement the `Wordlift\Content\Content_Service` interface.'); |
|
44 | 44 | |
45 | 45 | $this->delegates[] = $delegate; |
46 | 46 | } |
47 | 47 | |
48 | - public function get_by_entity_id( $uri ) { |
|
49 | - foreach ( $this->delegates as $delegate ) { |
|
50 | - $content = $delegate->get_by_entity_id_or_same_as( $uri ); |
|
51 | - if ( isset( $content ) ) { |
|
48 | + public function get_by_entity_id($uri) { |
|
49 | + foreach ($this->delegates as $delegate) { |
|
50 | + $content = $delegate->get_by_entity_id_or_same_as($uri); |
|
51 | + if (isset($content)) { |
|
52 | 52 | return $content; |
53 | 53 | } |
54 | 54 | } |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @throws Exception in case of error. |
63 | 63 | */ |
64 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
65 | - foreach ( $this->delegates as $delegate ) { |
|
66 | - $content = $delegate->get_by_entity_id_or_same_as( $uri ); |
|
67 | - if ( isset( $content ) ) { |
|
64 | + public function get_by_entity_id_or_same_as($uri) { |
|
65 | + foreach ($this->delegates as $delegate) { |
|
66 | + $content = $delegate->get_by_entity_id_or_same_as($uri); |
|
67 | + if (isset($content)) { |
|
68 | 68 | return $content; |
69 | 69 | } |
70 | 70 | } |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | return null; |
73 | 73 | } |
74 | 74 | |
75 | - public function get_entity_id( $content_id ) { |
|
76 | - foreach ( $this->delegates as $delegate ) { |
|
77 | - if ( ! $delegate->supports( $content_id ) ) { |
|
75 | + public function get_entity_id($content_id) { |
|
76 | + foreach ($this->delegates as $delegate) { |
|
77 | + if ( ! $delegate->supports($content_id)) { |
|
78 | 78 | continue; |
79 | 79 | } |
80 | - $uri = $delegate->get_entity_id( $content_id ); |
|
81 | - if ( $uri ) { |
|
80 | + $uri = $delegate->get_entity_id($content_id); |
|
81 | + if ($uri) { |
|
82 | 82 | return $uri; |
83 | 83 | } |
84 | 84 | } |
@@ -86,21 +86,21 @@ discard block |
||
86 | 86 | return null; |
87 | 87 | } |
88 | 88 | |
89 | - public function set_entity_id( $content_id, $uri ) { |
|
90 | - foreach ( $this->delegates as $delegate ) { |
|
91 | - if ( $delegate->supports( $content_id ) ) { |
|
92 | - $delegate->set_entity_id( $content_id, $uri ); |
|
89 | + public function set_entity_id($content_id, $uri) { |
|
90 | + foreach ($this->delegates as $delegate) { |
|
91 | + if ($delegate->supports($content_id)) { |
|
92 | + $delegate->set_entity_id($content_id, $uri); |
|
93 | 93 | |
94 | 94 | return; |
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | - throw new Exception( 'Not supported' ); |
|
98 | + throw new Exception('Not supported'); |
|
99 | 99 | } |
100 | 100 | |
101 | - public function supports( $content_id ) { |
|
102 | - foreach ( $this->delegates as $delegate ) { |
|
103 | - if ( $delegate->supports( $content_id ) ) { |
|
101 | + public function supports($content_id) { |
|
102 | + foreach ($this->delegates as $delegate) { |
|
103 | + if ($delegate->supports($content_id)) { |
|
104 | 104 | return true; |
105 | 105 | } |
106 | 106 | } |
@@ -108,10 +108,10 @@ discard block |
||
108 | 108 | return false; |
109 | 109 | } |
110 | 110 | |
111 | - public function delete( $content_id ) { |
|
112 | - foreach ( $this->delegates as $delegate ) { |
|
113 | - if ( $delegate->supports( $content_id ) ) { |
|
114 | - $delegate->delete( $content_id ); |
|
111 | + public function delete($content_id) { |
|
112 | + foreach ($this->delegates as $delegate) { |
|
113 | + if ($delegate->supports($content_id)) { |
|
114 | + $delegate->delete($content_id); |
|
115 | 115 | break; |
116 | 116 | } |
117 | 117 | } |
@@ -13,32 +13,32 @@ |
||
13 | 13 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
14 | 14 | class Wordpress_Post_Content_Service { |
15 | 15 | |
16 | - private static $instance = null; |
|
17 | - |
|
18 | - /** |
|
19 | - * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
20 | - * the constructor. |
|
21 | - * |
|
22 | - * @return Content_Service |
|
23 | - */ |
|
24 | - public static function get_instance() { |
|
25 | - |
|
26 | - if ( ! isset( self::$instance ) ) { |
|
27 | - |
|
28 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
29 | - if ( ! apply_filters( 'wl_feature__enable__rel-item-id', false ) ) { |
|
30 | - self::$instance = Wordpress_Post_Content_Legacy_Service::get_instance(); |
|
31 | - } else { |
|
32 | - // Migrate `entity_url` from post-meta to wl_entities. |
|
33 | - $content_migration = new Content_Migration(); |
|
34 | - $content_migration->migrate(); |
|
35 | - |
|
36 | - // Create the post content service that uses wl_entities. |
|
37 | - self::$instance = Wordpress_Post_Content_Table_Service::get_instance(); |
|
38 | - } |
|
39 | - } |
|
40 | - |
|
41 | - return self::$instance; |
|
42 | - } |
|
16 | + private static $instance = null; |
|
17 | + |
|
18 | + /** |
|
19 | + * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
20 | + * the constructor. |
|
21 | + * |
|
22 | + * @return Content_Service |
|
23 | + */ |
|
24 | + public static function get_instance() { |
|
25 | + |
|
26 | + if ( ! isset( self::$instance ) ) { |
|
27 | + |
|
28 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
29 | + if ( ! apply_filters( 'wl_feature__enable__rel-item-id', false ) ) { |
|
30 | + self::$instance = Wordpress_Post_Content_Legacy_Service::get_instance(); |
|
31 | + } else { |
|
32 | + // Migrate `entity_url` from post-meta to wl_entities. |
|
33 | + $content_migration = new Content_Migration(); |
|
34 | + $content_migration->migrate(); |
|
35 | + |
|
36 | + // Create the post content service that uses wl_entities. |
|
37 | + self::$instance = Wordpress_Post_Content_Table_Service::get_instance(); |
|
38 | + } |
|
39 | + } |
|
40 | + |
|
41 | + return self::$instance; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | } |
@@ -23,10 +23,10 @@ |
||
23 | 23 | */ |
24 | 24 | public static function get_instance() { |
25 | 25 | |
26 | - if ( ! isset( self::$instance ) ) { |
|
26 | + if ( ! isset(self::$instance)) { |
|
27 | 27 | |
28 | 28 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
29 | - if ( ! apply_filters( 'wl_feature__enable__rel-item-id', false ) ) { |
|
29 | + if ( ! apply_filters('wl_feature__enable__rel-item-id', false)) { |
|
30 | 30 | self::$instance = Wordpress_Post_Content_Legacy_Service::get_instance(); |
31 | 31 | } else { |
32 | 32 | // Migrate `entity_url` from post-meta to wl_entities. |
@@ -9,47 +9,47 @@ discard block |
||
9 | 9 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
10 | 10 | class Wordpress_Term_Content_Legacy_Service extends Abstract_Wordpress_Content_Legacy_Service { |
11 | 11 | |
12 | - private static $instance = null; |
|
13 | - |
|
14 | - /** |
|
15 | - * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
16 | - * the constructor. |
|
17 | - * |
|
18 | - * @return Wordpress_Term_Content_Legacy_Service |
|
19 | - */ |
|
20 | - public static function get_instance() { |
|
21 | - |
|
22 | - if ( ! isset( self::$instance ) ) { |
|
23 | - self::$instance = new self( Object_Type_Enum::TERM, 'get_term_meta' ); |
|
24 | - } |
|
25 | - |
|
26 | - return self::$instance; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * @param string $uri The entity id, relative or absolute. |
|
31 | - * |
|
32 | - * @return Wordpress_Content|null The term encapsulate within a {@link Wordpress_Content} structure or null. |
|
33 | - * @throws Exception in case of error. when the uri is not within the dataset URI scope. |
|
34 | - */ |
|
35 | - public function get_by_entity_id( $uri ) { |
|
36 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
37 | - Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
38 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
39 | - |
|
40 | - $abs_uri = $this->make_absolute( $uri ); |
|
41 | - |
|
42 | - Assertions::starts_with( |
|
43 | - $abs_uri, |
|
44 | - $this->get_dataset_uri(), |
|
45 | - sprintf( 'URI `%s` must be within the dataset URI scope, `%s` provided.', $abs_uri, $this->get_dataset_uri() ) |
|
46 | - ); |
|
47 | - |
|
48 | - global $wpdb; |
|
49 | - |
|
50 | - $term_id = $wpdb->get_var( |
|
51 | - $wpdb->prepare( |
|
52 | - " |
|
12 | + private static $instance = null; |
|
13 | + |
|
14 | + /** |
|
15 | + * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
16 | + * the constructor. |
|
17 | + * |
|
18 | + * @return Wordpress_Term_Content_Legacy_Service |
|
19 | + */ |
|
20 | + public static function get_instance() { |
|
21 | + |
|
22 | + if ( ! isset( self::$instance ) ) { |
|
23 | + self::$instance = new self( Object_Type_Enum::TERM, 'get_term_meta' ); |
|
24 | + } |
|
25 | + |
|
26 | + return self::$instance; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * @param string $uri The entity id, relative or absolute. |
|
31 | + * |
|
32 | + * @return Wordpress_Content|null The term encapsulate within a {@link Wordpress_Content} structure or null. |
|
33 | + * @throws Exception in case of error. when the uri is not within the dataset URI scope. |
|
34 | + */ |
|
35 | + public function get_by_entity_id( $uri ) { |
|
36 | + Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
37 | + Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
38 | + Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
39 | + |
|
40 | + $abs_uri = $this->make_absolute( $uri ); |
|
41 | + |
|
42 | + Assertions::starts_with( |
|
43 | + $abs_uri, |
|
44 | + $this->get_dataset_uri(), |
|
45 | + sprintf( 'URI `%s` must be within the dataset URI scope, `%s` provided.', $abs_uri, $this->get_dataset_uri() ) |
|
46 | + ); |
|
47 | + |
|
48 | + global $wpdb; |
|
49 | + |
|
50 | + $term_id = $wpdb->get_var( |
|
51 | + $wpdb->prepare( |
|
52 | + " |
|
53 | 53 | SELECT t.term_id |
54 | 54 | FROM $wpdb->terms AS t |
55 | 55 | INNER JOIN $wpdb->termmeta AS tm |
@@ -57,70 +57,70 @@ discard block |
||
57 | 57 | WHERE tm.meta_key = 'entity_url' AND tm.meta_value = %s |
58 | 58 | LIMIT 1 |
59 | 59 | ", |
60 | - $abs_uri |
|
61 | - ) |
|
62 | - ); |
|
63 | - |
|
64 | - if ( isset( $term_id ) ) { |
|
65 | - return new Wordpress_Content( get_term( $term_id ) ); |
|
66 | - } |
|
67 | - |
|
68 | - return null; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @throws Exception in case of error. when `$uri` is not a string. |
|
73 | - */ |
|
74 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
75 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
76 | - Assertions::not_empty( '`uri` cannot be empty.' ); |
|
77 | - |
|
78 | - // If it's a relative URI, or it's an internal URI, look in entity ID. |
|
79 | - if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
80 | - return $this->get_by_entity_id( $uri ); |
|
81 | - } |
|
82 | - |
|
83 | - global $wpdb; |
|
84 | - |
|
85 | - $term_id = $wpdb->get_var( |
|
86 | - $wpdb->prepare( |
|
87 | - " |
|
60 | + $abs_uri |
|
61 | + ) |
|
62 | + ); |
|
63 | + |
|
64 | + if ( isset( $term_id ) ) { |
|
65 | + return new Wordpress_Content( get_term( $term_id ) ); |
|
66 | + } |
|
67 | + |
|
68 | + return null; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @throws Exception in case of error. when `$uri` is not a string. |
|
73 | + */ |
|
74 | + public function get_by_entity_id_or_same_as( $uri ) { |
|
75 | + Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
76 | + Assertions::not_empty( '`uri` cannot be empty.' ); |
|
77 | + |
|
78 | + // If it's a relative URI, or it's an internal URI, look in entity ID. |
|
79 | + if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
80 | + return $this->get_by_entity_id( $uri ); |
|
81 | + } |
|
82 | + |
|
83 | + global $wpdb; |
|
84 | + |
|
85 | + $term_id = $wpdb->get_var( |
|
86 | + $wpdb->prepare( |
|
87 | + " |
|
88 | 88 | SELECT tm.term_id |
89 | 89 | FROM $wpdb->termmeta tm |
90 | 90 | WHERE tm.meta_key IN ( 'entity_url', 'entity_same_as' ) AND tm.meta_value = %s |
91 | 91 | LIMIT 1 |
92 | 92 | ", |
93 | - $uri |
|
94 | - ) |
|
95 | - ); |
|
96 | - |
|
97 | - if ( isset( $term_id ) ) { |
|
98 | - return new Wordpress_Content( get_term( $term_id ) ); |
|
99 | - } |
|
100 | - |
|
101 | - return null; |
|
102 | - } |
|
103 | - |
|
104 | - public function set_entity_id( $content_id, $uri ) { |
|
105 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::TERM, 'Content must be of `term` type.' ); |
|
106 | - Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
107 | - |
|
108 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
109 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
110 | - } |
|
111 | - |
|
112 | - $abs_url = $this->make_absolute( $uri ); |
|
113 | - |
|
114 | - update_term_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param Wordpress_Content_Id $content_id |
|
119 | - * |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function supports( $content_id ) { |
|
123 | - return $content_id->get_type() === Object_Type_Enum::TERM; |
|
124 | - } |
|
93 | + $uri |
|
94 | + ) |
|
95 | + ); |
|
96 | + |
|
97 | + if ( isset( $term_id ) ) { |
|
98 | + return new Wordpress_Content( get_term( $term_id ) ); |
|
99 | + } |
|
100 | + |
|
101 | + return null; |
|
102 | + } |
|
103 | + |
|
104 | + public function set_entity_id( $content_id, $uri ) { |
|
105 | + Assertions::equals( $content_id->get_type(), Object_Type_Enum::TERM, 'Content must be of `term` type.' ); |
|
106 | + Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
107 | + |
|
108 | + if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
109 | + throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
110 | + } |
|
111 | + |
|
112 | + $abs_url = $this->make_absolute( $uri ); |
|
113 | + |
|
114 | + update_term_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param Wordpress_Content_Id $content_id |
|
119 | + * |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function supports( $content_id ) { |
|
123 | + return $content_id->get_type() === Object_Type_Enum::TERM; |
|
124 | + } |
|
125 | 125 | |
126 | 126 | } |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public static function get_instance() { |
21 | 21 | |
22 | - if ( ! isset( self::$instance ) ) { |
|
23 | - self::$instance = new self( Object_Type_Enum::TERM, 'get_term_meta' ); |
|
22 | + if ( ! isset(self::$instance)) { |
|
23 | + self::$instance = new self(Object_Type_Enum::TERM, 'get_term_meta'); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | return self::$instance; |
@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | * @return Wordpress_Content|null The term encapsulate within a {@link Wordpress_Content} structure or null. |
33 | 33 | * @throws Exception in case of error. when the uri is not within the dataset URI scope. |
34 | 34 | */ |
35 | - public function get_by_entity_id( $uri ) { |
|
36 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
37 | - Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
38 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
35 | + public function get_by_entity_id($uri) { |
|
36 | + Assertions::is_string($uri, '`uri` must be a string.'); |
|
37 | + Assertions::not_empty($uri, '`uri` cannot be empty.'); |
|
38 | + Assertions::not_empty($this->get_dataset_uri(), '`dataset_uri` cannot be empty.'); |
|
39 | 39 | |
40 | - $abs_uri = $this->make_absolute( $uri ); |
|
40 | + $abs_uri = $this->make_absolute($uri); |
|
41 | 41 | |
42 | 42 | Assertions::starts_with( |
43 | 43 | $abs_uri, |
44 | 44 | $this->get_dataset_uri(), |
45 | - sprintf( 'URI `%s` must be within the dataset URI scope, `%s` provided.', $abs_uri, $this->get_dataset_uri() ) |
|
45 | + sprintf('URI `%s` must be within the dataset URI scope, `%s` provided.', $abs_uri, $this->get_dataset_uri()) |
|
46 | 46 | ); |
47 | 47 | |
48 | 48 | global $wpdb; |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | ) |
62 | 62 | ); |
63 | 63 | |
64 | - if ( isset( $term_id ) ) { |
|
65 | - return new Wordpress_Content( get_term( $term_id ) ); |
|
64 | + if (isset($term_id)) { |
|
65 | + return new Wordpress_Content(get_term($term_id)); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | return null; |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | /** |
72 | 72 | * @throws Exception in case of error. when `$uri` is not a string. |
73 | 73 | */ |
74 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
75 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
76 | - Assertions::not_empty( '`uri` cannot be empty.' ); |
|
74 | + public function get_by_entity_id_or_same_as($uri) { |
|
75 | + Assertions::is_string($uri, '`uri` must be a string.'); |
|
76 | + Assertions::not_empty('`uri` cannot be empty.'); |
|
77 | 77 | |
78 | 78 | // If it's a relative URI, or it's an internal URI, look in entity ID. |
79 | - if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
80 | - return $this->get_by_entity_id( $uri ); |
|
79 | + if ( ! $this->is_absolute($uri) || $this->is_internal($uri)) { |
|
80 | + return $this->get_by_entity_id($uri); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | global $wpdb; |
@@ -94,24 +94,24 @@ discard block |
||
94 | 94 | ) |
95 | 95 | ); |
96 | 96 | |
97 | - if ( isset( $term_id ) ) { |
|
98 | - return new Wordpress_Content( get_term( $term_id ) ); |
|
97 | + if (isset($term_id)) { |
|
98 | + return new Wordpress_Content(get_term($term_id)); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | return null; |
102 | 102 | } |
103 | 103 | |
104 | - public function set_entity_id( $content_id, $uri ) { |
|
105 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::TERM, 'Content must be of `term` type.' ); |
|
106 | - Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
104 | + public function set_entity_id($content_id, $uri) { |
|
105 | + Assertions::equals($content_id->get_type(), Object_Type_Enum::TERM, 'Content must be of `term` type.'); |
|
106 | + Assertions::not_empty($uri, "`uri` can't be empty"); |
|
107 | 107 | |
108 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
109 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
108 | + if ($this->is_absolute($uri) && ! $this->is_internal($uri)) { |
|
109 | + throw new Exception('`uri` must be within the dataset URI scope.'); |
|
110 | 110 | } |
111 | 111 | |
112 | - $abs_url = $this->make_absolute( $uri ); |
|
112 | + $abs_url = $this->make_absolute($uri); |
|
113 | 113 | |
114 | - update_term_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
114 | + update_term_meta($content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return bool |
121 | 121 | */ |
122 | - public function supports( $content_id ) { |
|
122 | + public function supports($content_id) { |
|
123 | 123 | return $content_id->get_type() === Object_Type_Enum::TERM; |
124 | 124 | } |
125 | 125 |
@@ -9,37 +9,37 @@ discard block |
||
9 | 9 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
10 | 10 | class Wordpress_User_Content_Legacy_Service extends Abstract_Wordpress_Content_Legacy_Service { |
11 | 11 | |
12 | - private static $instance = null; |
|
12 | + private static $instance = null; |
|
13 | 13 | |
14 | - /** |
|
15 | - * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
16 | - * the constructor. |
|
17 | - * |
|
18 | - * @return Wordpress_User_Content_Legacy_Service |
|
19 | - */ |
|
20 | - public static function get_instance() { |
|
14 | + /** |
|
15 | + * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
16 | + * the constructor. |
|
17 | + * |
|
18 | + * @return Wordpress_User_Content_Legacy_Service |
|
19 | + */ |
|
20 | + public static function get_instance() { |
|
21 | 21 | |
22 | - if ( ! isset( self::$instance ) ) { |
|
23 | - self::$instance = new self( Object_Type_Enum::USER, 'get_user_meta' ); |
|
24 | - } |
|
22 | + if ( ! isset( self::$instance ) ) { |
|
23 | + self::$instance = new self( Object_Type_Enum::USER, 'get_user_meta' ); |
|
24 | + } |
|
25 | 25 | |
26 | - return self::$instance; |
|
27 | - } |
|
26 | + return self::$instance; |
|
27 | + } |
|
28 | 28 | |
29 | - public function get_by_entity_id( $uri ) { |
|
30 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
31 | - Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
32 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
29 | + public function get_by_entity_id( $uri ) { |
|
30 | + Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
31 | + Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
32 | + Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
33 | 33 | |
34 | - $abs_uri = $this->make_absolute( $uri ); |
|
34 | + $abs_uri = $this->make_absolute( $uri ); |
|
35 | 35 | |
36 | - Assertions::starts_with( $abs_uri, $this->get_dataset_uri(), '`uri` must be within the dataset URI scope.' ); |
|
36 | + Assertions::starts_with( $abs_uri, $this->get_dataset_uri(), '`uri` must be within the dataset URI scope.' ); |
|
37 | 37 | |
38 | - global $wpdb; |
|
38 | + global $wpdb; |
|
39 | 39 | |
40 | - $user_id = $wpdb->get_var( |
|
41 | - $wpdb->prepare( |
|
42 | - " |
|
40 | + $user_id = $wpdb->get_var( |
|
41 | + $wpdb->prepare( |
|
42 | + " |
|
43 | 43 | SELECT u.ID |
44 | 44 | FROM $wpdb->users AS u |
45 | 45 | INNER JOIN $wpdb->usermeta AS um |
@@ -47,34 +47,34 @@ discard block |
||
47 | 47 | WHERE um.meta_key = 'entity_url' AND um.meta_value = %s |
48 | 48 | LIMIT 1 |
49 | 49 | ", |
50 | - $abs_uri |
|
51 | - ) |
|
52 | - ); |
|
53 | - |
|
54 | - if ( isset( $user_id ) ) { |
|
55 | - return new Wordpress_Content( get_userdata( $user_id ) ); |
|
56 | - } |
|
57 | - |
|
58 | - return null; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @throws Exception in case of error. when `$uri` is not a string. |
|
63 | - */ |
|
64 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
65 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
66 | - Assertions::not_empty( '`uri` cannot be empty.' ); |
|
67 | - |
|
68 | - // If it's a relative URI, or it's an internal URI, look in entity ID. |
|
69 | - if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
70 | - return $this->get_by_entity_id( $uri ); |
|
71 | - } |
|
72 | - |
|
73 | - global $wpdb; |
|
74 | - |
|
75 | - $user_id = $wpdb->get_var( |
|
76 | - $wpdb->prepare( |
|
77 | - " |
|
50 | + $abs_uri |
|
51 | + ) |
|
52 | + ); |
|
53 | + |
|
54 | + if ( isset( $user_id ) ) { |
|
55 | + return new Wordpress_Content( get_userdata( $user_id ) ); |
|
56 | + } |
|
57 | + |
|
58 | + return null; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @throws Exception in case of error. when `$uri` is not a string. |
|
63 | + */ |
|
64 | + public function get_by_entity_id_or_same_as( $uri ) { |
|
65 | + Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
66 | + Assertions::not_empty( '`uri` cannot be empty.' ); |
|
67 | + |
|
68 | + // If it's a relative URI, or it's an internal URI, look in entity ID. |
|
69 | + if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
70 | + return $this->get_by_entity_id( $uri ); |
|
71 | + } |
|
72 | + |
|
73 | + global $wpdb; |
|
74 | + |
|
75 | + $user_id = $wpdb->get_var( |
|
76 | + $wpdb->prepare( |
|
77 | + " |
|
78 | 78 | SELECT u.ID |
79 | 79 | FROM $wpdb->users AS u |
80 | 80 | INNER JOIN $wpdb->usermeta AS um |
@@ -82,38 +82,38 @@ discard block |
||
82 | 82 | WHERE um.meta_key IN ( 'entity_url', 'entity_same_as' ) AND um.meta_value = %s |
83 | 83 | LIMIT 1 |
84 | 84 | ", |
85 | - $uri |
|
86 | - ) |
|
87 | - ); |
|
85 | + $uri |
|
86 | + ) |
|
87 | + ); |
|
88 | 88 | |
89 | - if ( isset( $user_id ) ) { |
|
90 | - return new Wordpress_Content( get_userdata( $user_id ) ); |
|
91 | - } |
|
89 | + if ( isset( $user_id ) ) { |
|
90 | + return new Wordpress_Content( get_userdata( $user_id ) ); |
|
91 | + } |
|
92 | 92 | |
93 | - return null; |
|
94 | - } |
|
93 | + return null; |
|
94 | + } |
|
95 | 95 | |
96 | - public function set_entity_id( $content_id, $uri ) { |
|
97 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::USER, '`content_id` must be of type user.' ); |
|
98 | - Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
96 | + public function set_entity_id( $content_id, $uri ) { |
|
97 | + Assertions::equals( $content_id->get_type(), Object_Type_Enum::USER, '`content_id` must be of type user.' ); |
|
98 | + Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
99 | 99 | |
100 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
100 | + if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
101 | 101 | |
102 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
103 | - } |
|
102 | + throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
103 | + } |
|
104 | 104 | |
105 | - $abs_url = $this->make_absolute( $uri ); |
|
105 | + $abs_url = $this->make_absolute( $uri ); |
|
106 | 106 | |
107 | - update_user_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
108 | - } |
|
107 | + update_user_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * @param Wordpress_Content_Id $content_id |
|
112 | - * |
|
113 | - * @return bool |
|
114 | - */ |
|
115 | - public function supports( $content_id ) { |
|
116 | - return $content_id->get_type() === Object_Type_Enum::USER; |
|
117 | - } |
|
110 | + /** |
|
111 | + * @param Wordpress_Content_Id $content_id |
|
112 | + * |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | + public function supports( $content_id ) { |
|
116 | + return $content_id->get_type() === Object_Type_Enum::USER; |
|
117 | + } |
|
118 | 118 | |
119 | 119 | } |
@@ -19,21 +19,21 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public static function get_instance() { |
21 | 21 | |
22 | - if ( ! isset( self::$instance ) ) { |
|
23 | - self::$instance = new self( Object_Type_Enum::USER, 'get_user_meta' ); |
|
22 | + if ( ! isset(self::$instance)) { |
|
23 | + self::$instance = new self(Object_Type_Enum::USER, 'get_user_meta'); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | return self::$instance; |
27 | 27 | } |
28 | 28 | |
29 | - public function get_by_entity_id( $uri ) { |
|
30 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
31 | - Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
32 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
29 | + public function get_by_entity_id($uri) { |
|
30 | + Assertions::is_string($uri, '`uri` must be a string.'); |
|
31 | + Assertions::not_empty($uri, '`uri` cannot be empty.'); |
|
32 | + Assertions::not_empty($this->get_dataset_uri(), '`dataset_uri` cannot be empty.'); |
|
33 | 33 | |
34 | - $abs_uri = $this->make_absolute( $uri ); |
|
34 | + $abs_uri = $this->make_absolute($uri); |
|
35 | 35 | |
36 | - Assertions::starts_with( $abs_uri, $this->get_dataset_uri(), '`uri` must be within the dataset URI scope.' ); |
|
36 | + Assertions::starts_with($abs_uri, $this->get_dataset_uri(), '`uri` must be within the dataset URI scope.'); |
|
37 | 37 | |
38 | 38 | global $wpdb; |
39 | 39 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | ) |
52 | 52 | ); |
53 | 53 | |
54 | - if ( isset( $user_id ) ) { |
|
55 | - return new Wordpress_Content( get_userdata( $user_id ) ); |
|
54 | + if (isset($user_id)) { |
|
55 | + return new Wordpress_Content(get_userdata($user_id)); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | return null; |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * @throws Exception in case of error. when `$uri` is not a string. |
63 | 63 | */ |
64 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
65 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
66 | - Assertions::not_empty( '`uri` cannot be empty.' ); |
|
64 | + public function get_by_entity_id_or_same_as($uri) { |
|
65 | + Assertions::is_string($uri, '`uri` must be a string.'); |
|
66 | + Assertions::not_empty('`uri` cannot be empty.'); |
|
67 | 67 | |
68 | 68 | // If it's a relative URI, or it's an internal URI, look in entity ID. |
69 | - if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
70 | - return $this->get_by_entity_id( $uri ); |
|
69 | + if ( ! $this->is_absolute($uri) || $this->is_internal($uri)) { |
|
70 | + return $this->get_by_entity_id($uri); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | global $wpdb; |
@@ -86,25 +86,25 @@ discard block |
||
86 | 86 | ) |
87 | 87 | ); |
88 | 88 | |
89 | - if ( isset( $user_id ) ) { |
|
90 | - return new Wordpress_Content( get_userdata( $user_id ) ); |
|
89 | + if (isset($user_id)) { |
|
90 | + return new Wordpress_Content(get_userdata($user_id)); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return null; |
94 | 94 | } |
95 | 95 | |
96 | - public function set_entity_id( $content_id, $uri ) { |
|
97 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::USER, '`content_id` must be of type user.' ); |
|
98 | - Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
96 | + public function set_entity_id($content_id, $uri) { |
|
97 | + Assertions::equals($content_id->get_type(), Object_Type_Enum::USER, '`content_id` must be of type user.'); |
|
98 | + Assertions::not_empty($uri, "`uri` can't be empty"); |
|
99 | 99 | |
100 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
100 | + if ($this->is_absolute($uri) && ! $this->is_internal($uri)) { |
|
101 | 101 | |
102 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
102 | + throw new Exception('`uri` must be within the dataset URI scope.'); |
|
103 | 103 | } |
104 | 104 | |
105 | - $abs_url = $this->make_absolute( $uri ); |
|
105 | + $abs_url = $this->make_absolute($uri); |
|
106 | 106 | |
107 | - update_user_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
107 | + update_user_meta($content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return bool |
114 | 114 | */ |
115 | - public function supports( $content_id ) { |
|
115 | + public function supports($content_id) { |
|
116 | 116 | return $content_id->get_type() === Object_Type_Enum::USER; |
117 | 117 | } |
118 | 118 |