Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Replicastore often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Replicastore, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class Replicastore implements Replicastore_Interface { |
||
17 | /** |
||
18 | * Empty and reset the replicastore. |
||
19 | * |
||
20 | * @access public |
||
21 | */ |
||
22 | public function reset() { |
||
23 | global $wpdb; |
||
24 | |||
25 | $wpdb->query( "DELETE FROM $wpdb->posts" ); |
||
26 | |||
27 | // Delete comments from cache. |
||
28 | $comment_ids = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments" ); |
||
29 | if ( ! empty( $comment_ids ) ) { |
||
30 | clean_comment_cache( $comment_ids ); |
||
31 | } |
||
32 | $wpdb->query( "DELETE FROM $wpdb->comments" ); |
||
33 | |||
34 | // Also need to delete terms from cache. |
||
35 | $term_ids = $wpdb->get_col( "SELECT term_id FROM $wpdb->terms" ); |
||
36 | foreach ( $term_ids as $term_id ) { |
||
37 | wp_cache_delete( $term_id, 'terms' ); |
||
38 | } |
||
39 | |||
40 | $wpdb->query( "DELETE FROM $wpdb->terms" ); |
||
41 | |||
42 | $wpdb->query( "DELETE FROM $wpdb->term_taxonomy" ); |
||
43 | $wpdb->query( "DELETE FROM $wpdb->term_relationships" ); |
||
44 | |||
45 | // Callables and constants. |
||
46 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'jetpack_%'" ); |
||
47 | $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key NOT LIKE '\_%'" ); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Ran when full sync has just started. |
||
52 | * |
||
53 | * @access public |
||
54 | * |
||
55 | * @param array $config Full sync configuration for this sync module. |
||
56 | */ |
||
57 | public function full_sync_start( $config ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
58 | $this->reset(); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Ran when full sync has just finished. |
||
63 | * |
||
64 | * @access public |
||
65 | * |
||
66 | * @param string $checksum Deprecated since 7.3.0. |
||
67 | */ |
||
68 | public function full_sync_end( $checksum ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
69 | // Noop right now. |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Retrieve the number of terms. |
||
74 | * |
||
75 | * @access public |
||
76 | * |
||
77 | * @return int Number of terms. |
||
78 | */ |
||
79 | public function term_count() { |
||
80 | global $wpdb; |
||
81 | return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->terms" ); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Retrieve the number of rows in the `term_taxonomy` table. |
||
86 | * |
||
87 | * @access public |
||
88 | * |
||
89 | * @return int Number of terms. |
||
90 | */ |
||
91 | public function term_taxonomy_count() { |
||
92 | global $wpdb; |
||
93 | return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->term_taxonomy" ); |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Retrieve the number of term relationships. |
||
98 | * |
||
99 | * @access public |
||
100 | * |
||
101 | * @return int Number of rows in the term relationships table. |
||
102 | */ |
||
103 | public function term_relationship_count() { |
||
104 | global $wpdb; |
||
105 | return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->term_relationships" ); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Retrieve the number of posts with a particular post status within a certain range. |
||
110 | * |
||
111 | * @access public |
||
112 | * |
||
113 | * @todo Prepare the SQL query before executing it. |
||
114 | * |
||
115 | * @param string $status Post status. |
||
|
|||
116 | * @param int $min_id Minimum post ID. |
||
117 | * @param int $max_id Maximum post ID. |
||
118 | * @return int Number of posts. |
||
119 | */ |
||
120 | View Code Duplication | public function post_count( $status = null, $min_id = null, $max_id = null ) { |
|
121 | global $wpdb; |
||
122 | |||
123 | $where = ''; |
||
124 | |||
125 | if ( $status ) { |
||
126 | $where = "post_status = '" . esc_sql( $status ) . "'"; |
||
127 | } else { |
||
128 | $where = '1=1'; |
||
129 | } |
||
130 | |||
131 | if ( ! empty( $min_id ) ) { |
||
132 | $where .= ' AND ID >= ' . (int) $min_id; |
||
133 | } |
||
134 | |||
135 | if ( ! empty( $max_id ) ) { |
||
136 | $where .= ' AND ID <= ' . (int) $max_id; |
||
137 | } |
||
138 | |||
139 | // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
||
140 | return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE $where" ); |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Retrieve the posts with a particular post status. |
||
145 | * |
||
146 | * @access public |
||
147 | * |
||
148 | * @todo Implement range and actually use max_id/min_id arguments. |
||
149 | * |
||
150 | * @param string $status Post status. |
||
151 | * @param int $min_id Minimum post ID. |
||
152 | * @param int $max_id Maximum post ID. |
||
153 | * @return array Array of posts. |
||
154 | */ |
||
155 | public function get_posts( $status = null, $min_id = null, $max_id = null ) { |
||
156 | $args = array( |
||
157 | 'orderby' => 'ID', |
||
158 | 'posts_per_page' => -1, |
||
159 | ); |
||
160 | |||
161 | if ( $status ) { |
||
162 | $args['post_status'] = $status; |
||
163 | } else { |
||
164 | $args['post_status'] = 'any'; |
||
165 | } |
||
166 | |||
167 | return get_posts( $args ); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * Retrieve a post object by the post ID. |
||
172 | * |
||
173 | * @access public |
||
174 | * |
||
175 | * @param int $id Post ID. |
||
176 | * @return \WP_Post Post object. |
||
177 | */ |
||
178 | public function get_post( $id ) { |
||
179 | return get_post( $id ); |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * Update or insert a post. |
||
184 | * |
||
185 | * @access public |
||
186 | * |
||
187 | * @param \WP_Post $post Post object. |
||
188 | * @param bool $silent Whether to perform a silent action. Not used in this implementation. |
||
189 | */ |
||
190 | public function upsert_post( $post, $silent = false ) { |
||
191 | global $wpdb; |
||
192 | |||
193 | // Reject the post if it's not a \WP_Post. |
||
194 | if ( ! $post instanceof \WP_Post ) { |
||
195 | return; |
||
196 | } |
||
197 | |||
198 | $post = $post->to_array(); |
||
199 | |||
200 | // Reject posts without an ID. |
||
201 | if ( ! isset( $post['ID'] ) ) { |
||
202 | return; |
||
203 | } |
||
204 | |||
205 | $now = current_time( 'mysql' ); |
||
206 | $now_gmt = get_gmt_from_date( $now ); |
||
207 | |||
208 | $defaults = array( |
||
209 | 'ID' => 0, |
||
210 | 'post_author' => '0', |
||
211 | 'post_content' => '', |
||
212 | 'post_content_filtered' => '', |
||
213 | 'post_title' => '', |
||
214 | 'post_name' => '', |
||
215 | 'post_excerpt' => '', |
||
216 | 'post_status' => 'draft', |
||
217 | 'post_type' => 'post', |
||
218 | 'comment_status' => 'closed', |
||
219 | 'comment_count' => '0', |
||
220 | 'ping_status' => '', |
||
221 | 'post_password' => '', |
||
222 | 'to_ping' => '', |
||
223 | 'pinged' => '', |
||
224 | 'post_parent' => 0, |
||
225 | 'menu_order' => 0, |
||
226 | 'guid' => '', |
||
227 | 'post_date' => $now, |
||
228 | 'post_date_gmt' => $now_gmt, |
||
229 | 'post_modified' => $now, |
||
230 | 'post_modified_gmt' => $now_gmt, |
||
231 | ); |
||
232 | |||
233 | $post = array_intersect_key( $post, $defaults ); |
||
234 | |||
235 | $post = sanitize_post( $post, 'db' ); |
||
236 | |||
237 | unset( $post['filter'] ); |
||
238 | |||
239 | $exists = $wpdb->get_var( $wpdb->prepare( "SELECT EXISTS( SELECT 1 FROM $wpdb->posts WHERE ID = %d )", $post['ID'] ) ); |
||
240 | |||
241 | if ( $exists ) { |
||
242 | $wpdb->update( $wpdb->posts, $post, array( 'ID' => $post['ID'] ) ); |
||
243 | } else { |
||
244 | $wpdb->insert( $wpdb->posts, $post ); |
||
245 | } |
||
246 | |||
247 | clean_post_cache( $post['ID'] ); |
||
248 | } |
||
249 | |||
250 | /** |
||
251 | * Delete a post by the post ID. |
||
252 | * |
||
253 | * @access public |
||
254 | * |
||
255 | * @param int $post_id Post ID. |
||
256 | */ |
||
257 | public function delete_post( $post_id ) { |
||
258 | wp_delete_post( $post_id, true ); |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Retrieve the checksum for posts within a range. |
||
263 | * |
||
264 | * @access public |
||
265 | * |
||
266 | * @param int $min_id Minimum post ID. |
||
267 | * @param int $max_id Maximum post ID. |
||
268 | * @return int The checksum. |
||
269 | */ |
||
270 | public function posts_checksum( $min_id = null, $max_id = null ) { |
||
271 | return $this->summarize_checksum_histogram( $this->checksum_histogram( 'posts', $this->calculate_buckets( 'posts', $min_id, $max_id ), $min_id, $max_id ) ); |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * Retrieve the checksum for post meta within a range. |
||
276 | * |
||
277 | * @access public |
||
278 | * |
||
279 | * @param int $min_id Minimum post meta ID. |
||
280 | * @param int $max_id Maximum post meta ID. |
||
281 | * @return int The checksum. |
||
282 | */ |
||
283 | public function post_meta_checksum( $min_id = null, $max_id = null ) { |
||
284 | return $this->summarize_checksum_histogram( $this->checksum_histogram( 'postmeta', $this->calculate_buckets( 'postmeta', $min_id, $max_id ), $min_id, $max_id ) ); |
||
285 | } |
||
286 | |||
287 | /** |
||
288 | * Retrieve the number of comments with a particular comment status within a certain range. |
||
289 | * |
||
290 | * @access public |
||
291 | * |
||
292 | * @todo Prepare the SQL query before executing it. |
||
293 | * |
||
294 | * @param string $status Comment status. |
||
295 | * @param int $min_id Minimum comment ID. |
||
296 | * @param int $max_id Maximum comment ID. |
||
297 | * @return int Number of comments. |
||
298 | */ |
||
299 | View Code Duplication | public function comment_count( $status = null, $min_id = null, $max_id = null ) { |
|
321 | |||
322 | /** |
||
323 | * Translate a comment status to a value of the comment_approved field. |
||
324 | * |
||
325 | * @access private |
||
326 | * |
||
327 | * @param string $status Comment status. |
||
328 | * @return string|bool New comment_approved value, false if the status doesn't affect it. |
||
329 | */ |
||
330 | private function comment_status_to_approval_value( $status ) { |
||
348 | |||
349 | /** |
||
350 | * Retrieve the comments with a particular comment status. |
||
351 | * |
||
352 | * @access public |
||
353 | * |
||
354 | * @todo Implement range and actually use max_id/min_id arguments. |
||
355 | * |
||
356 | * @param string $status Comment status. |
||
357 | * @param int $min_id Minimum comment ID. |
||
358 | * @param int $max_id Maximum comment ID. |
||
359 | * @return array Array of comments. |
||
360 | */ |
||
361 | public function get_comments( $status = null, $min_id = null, $max_id = null ) { |
||
373 | |||
374 | /** |
||
375 | * Retrieve a comment object by the comment ID. |
||
376 | * |
||
377 | * @access public |
||
378 | * |
||
379 | * @param int $id Comment ID. |
||
380 | * @return \WP_Comment Comment object. |
||
381 | */ |
||
382 | public function get_comment( $id ) { |
||
385 | |||
386 | /** |
||
387 | * Update or insert a comment. |
||
388 | * |
||
389 | * @access public |
||
390 | * |
||
391 | * @param \WP_Comment $comment Comment object. |
||
392 | */ |
||
393 | public function upsert_comment( $comment ) { |
||
440 | |||
441 | /** |
||
442 | * Trash a comment by the comment ID. |
||
443 | * |
||
444 | * @access public |
||
445 | * |
||
446 | * @param int $comment_id Comment ID. |
||
447 | */ |
||
448 | public function trash_comment( $comment_id ) { |
||
451 | |||
452 | /** |
||
453 | * Delete a comment by the comment ID. |
||
454 | * |
||
455 | * @access public |
||
456 | * |
||
457 | * @param int $comment_id Comment ID. |
||
458 | */ |
||
459 | public function delete_comment( $comment_id ) { |
||
462 | |||
463 | /** |
||
464 | * Mark a comment by the comment ID as spam. |
||
465 | * |
||
466 | * @access public |
||
467 | * |
||
468 | * @param int $comment_id Comment ID. |
||
469 | */ |
||
470 | public function spam_comment( $comment_id ) { |
||
473 | |||
474 | /** |
||
475 | * Trash the comments of a post. |
||
476 | * |
||
477 | * @access public |
||
478 | * |
||
479 | * @param int $post_id Post ID. |
||
480 | * @param array $statuses Post statuses. Not used in this implementation. |
||
481 | */ |
||
482 | public function trashed_post_comments( $post_id, $statuses ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
485 | |||
486 | /** |
||
487 | * Untrash the comments of a post. |
||
488 | * |
||
489 | * @access public |
||
490 | * |
||
491 | * @param int $post_id Post ID. |
||
492 | */ |
||
493 | public function untrashed_post_comments( $post_id ) { |
||
496 | |||
497 | /** |
||
498 | * Retrieve the checksum for comments within a range. |
||
499 | * |
||
500 | * @access public |
||
501 | * |
||
502 | * @param int $min_id Minimum comment ID. |
||
503 | * @param int $max_id Maximum comment ID. |
||
504 | * @return int The checksum. |
||
505 | */ |
||
506 | public function comments_checksum( $min_id = null, $max_id = null ) { |
||
507 | return $this->summarize_checksum_histogram( $this->checksum_histogram( 'comments', $this->calculate_buckets( 'comments', $min_id, $max_id ), $min_id, $max_id ) ); |
||
508 | } |
||
509 | |||
510 | /** |
||
511 | * Retrieve the checksum for comment meta within a range. |
||
512 | * |
||
513 | * @access public |
||
514 | * |
||
515 | * @param int $min_id Minimum comment meta ID. |
||
516 | * @param int $max_id Maximum comment meta ID. |
||
517 | * @return int The checksum. |
||
518 | */ |
||
519 | public function comment_meta_checksum( $min_id = null, $max_id = null ) { |
||
522 | |||
523 | /** |
||
524 | * Update the value of an option. |
||
525 | * |
||
526 | * @access public |
||
527 | * |
||
528 | * @param string $option Option name. |
||
529 | * @param mixed $value Option value. |
||
530 | * @return bool False if value was not updated and true if value was updated. |
||
531 | */ |
||
532 | public function update_option( $option, $value ) { |
||
535 | |||
536 | /** |
||
537 | * Retrieve an option value based on an option name. |
||
538 | * |
||
539 | * @access public |
||
540 | * |
||
541 | * @param string $option Name of option to retrieve. |
||
542 | * @param mixed $default Optional. Default value to return if the option does not exist. |
||
543 | * @return mixed Value set for the option. |
||
544 | */ |
||
545 | public function get_option( $option, $default = false ) { |
||
548 | |||
549 | /** |
||
550 | * Remove an option by name. |
||
551 | * |
||
552 | * @access public |
||
553 | * |
||
554 | * @param string $option Name of option to remove. |
||
555 | * @return bool True, if option is successfully deleted. False on failure. |
||
556 | */ |
||
557 | public function delete_option( $option ) { |
||
560 | |||
561 | /** |
||
562 | * Change the features that the current theme supports. |
||
563 | * Intentionally not implemented in this replicastore. |
||
564 | * |
||
565 | * @access public |
||
566 | * |
||
567 | * @param array $theme_support Features that the theme supports. |
||
568 | */ |
||
569 | public function set_theme_support( $theme_support ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
572 | |||
573 | /** |
||
574 | * Whether the current theme supports a certain feature. |
||
575 | * |
||
576 | * @access public |
||
577 | * |
||
578 | * @param string $feature Name of the feature. |
||
579 | */ |
||
580 | public function current_theme_supports( $feature ) { |
||
583 | |||
584 | /** |
||
585 | * Retrieve metadata for the specified object. |
||
586 | * |
||
587 | * @access public |
||
588 | * |
||
589 | * @param string $type Meta type. |
||
590 | * @param int $object_id ID of the object. |
||
591 | * @param string $meta_key Meta key. |
||
592 | * @param bool $single If true, return only the first value of the specified meta_key. |
||
593 | * |
||
594 | * @return mixed Single metadata value, or array of values. |
||
595 | */ |
||
596 | public function get_metadata( $type, $object_id, $meta_key = '', $single = false ) { |
||
599 | |||
600 | /** |
||
601 | * Stores remote meta key/values alongside an ID mapping key. |
||
602 | * |
||
603 | * @access public |
||
604 | * |
||
605 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
606 | * |
||
607 | * @param string $type Meta type. |
||
608 | * @param int $object_id ID of the object. |
||
609 | * @param string $meta_key Meta key. |
||
610 | * @param mixed $meta_value Meta value. |
||
611 | * @param int $meta_id ID of the meta. |
||
612 | * |
||
613 | * @return bool False if meta table does not exist, true otherwise. |
||
614 | */ |
||
615 | public function upsert_metadata( $type, $object_id, $meta_key, $meta_value, $meta_id ) { |
||
657 | |||
658 | /** |
||
659 | * Delete metadata for the specified object. |
||
660 | * |
||
661 | * @access public |
||
662 | * |
||
663 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
664 | * |
||
665 | * @param string $type Meta type. |
||
666 | * @param int $object_id ID of the object. |
||
667 | * @param array $meta_ids IDs of the meta objects to delete. |
||
668 | */ |
||
669 | public function delete_metadata( $type, $object_id, $meta_ids ) { |
||
687 | |||
688 | /** |
||
689 | * Delete metadata with a certain key for the specified objects. |
||
690 | * |
||
691 | * @access public |
||
692 | * |
||
693 | * @todo Test this out to make sure it works as expected. |
||
694 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
695 | * |
||
696 | * @param string $type Meta type. |
||
697 | * @param array $object_ids IDs of the objects. |
||
698 | * @param string $meta_key Meta key. |
||
699 | */ |
||
700 | public function delete_batch_metadata( $type, $object_ids, $meta_key ) { |
||
716 | |||
717 | /** |
||
718 | * Retrieve value of a constant based on the constant name. |
||
719 | * |
||
720 | * @access public |
||
721 | * |
||
722 | * @param string $constant Name of constant to retrieve. |
||
723 | * @return mixed Value set for the constant. |
||
724 | */ |
||
725 | public function get_constant( $constant ) { |
||
734 | |||
735 | /** |
||
736 | * Set the value of a constant. |
||
737 | * |
||
738 | * @access public |
||
739 | * |
||
740 | * @param string $constant Name of constant to retrieve. |
||
741 | * @param mixed $value Value set for the constant. |
||
742 | */ |
||
743 | public function set_constant( $constant, $value ) { |
||
746 | |||
747 | /** |
||
748 | * Retrieve the number of the available updates of a certain type. |
||
749 | * Type is one of: `plugins`, `themes`, `wordpress`, `translations`, `total`, `wp_update_version`. |
||
750 | * |
||
751 | * @access public |
||
752 | * |
||
753 | * @param string $type Type of updates to retrieve. |
||
754 | * @return int|null Number of updates available, `null` if type is invalid or missing. |
||
755 | */ |
||
756 | public function get_updates( $type ) { |
||
765 | |||
766 | /** |
||
767 | * Set the available updates of a certain type. |
||
768 | * Type is one of: `plugins`, `themes`, `wordpress`, `translations`, `total`, `wp_update_version`. |
||
769 | * |
||
770 | * @access public |
||
771 | * |
||
772 | * @param string $type Type of updates to set. |
||
773 | * @param int $updates Total number of updates. |
||
774 | */ |
||
775 | public function set_updates( $type, $updates ) { |
||
780 | |||
781 | /** |
||
782 | * Retrieve a callable value based on its name. |
||
783 | * |
||
784 | * @access public |
||
785 | * |
||
786 | * @param string $name Name of the callable to retrieve. |
||
787 | * @return mixed Value of the callable. |
||
788 | */ |
||
789 | public function get_callable( $name ) { |
||
798 | |||
799 | /** |
||
800 | * Update the value of a callable. |
||
801 | * |
||
802 | * @access public |
||
803 | * |
||
804 | * @param string $name Callable name. |
||
805 | * @param mixed $value Callable value. |
||
806 | */ |
||
807 | public function set_callable( $name, $value ) { |
||
810 | |||
811 | /** |
||
812 | * Retrieve a network option value based on a network option name. |
||
813 | * |
||
814 | * @access public |
||
815 | * |
||
816 | * @param string $option Name of network option to retrieve. |
||
817 | * @return mixed Value set for the network option. |
||
818 | */ |
||
819 | public function get_site_option( $option ) { |
||
822 | |||
823 | /** |
||
824 | * Update the value of a network option. |
||
825 | * |
||
826 | * @access public |
||
827 | * |
||
828 | * @param string $option Network option name. |
||
829 | * @param mixed $value Network option value. |
||
830 | * @return bool False if value was not updated and true if value was updated. |
||
831 | */ |
||
832 | public function update_site_option( $option, $value ) { |
||
835 | |||
836 | /** |
||
837 | * Remove a network option by name. |
||
838 | * |
||
839 | * @access public |
||
840 | * |
||
841 | * @param string $option Name of option to remove. |
||
842 | * @return bool True, if option is successfully deleted. False on failure. |
||
843 | */ |
||
844 | public function delete_site_option( $option ) { |
||
847 | |||
848 | /** |
||
849 | * Retrieve the terms from a particular taxonomy. |
||
850 | * |
||
851 | * @access public |
||
852 | * |
||
853 | * @param string $taxonomy Taxonomy slug. |
||
854 | * @return array Array of terms. |
||
855 | */ |
||
856 | public function get_terms( $taxonomy ) { |
||
859 | |||
860 | /** |
||
861 | * Retrieve a particular term. |
||
862 | * |
||
863 | * @access public |
||
864 | * |
||
865 | * @param string $taxonomy Taxonomy slug. |
||
866 | * @param int $term_id ID of the term. |
||
867 | * @param bool $is_term_id Whether this is a `term_id` or a `term_taxonomy_id`. |
||
868 | * @return \WP_Term|\WP_Error Term object on success, \WP_Error object on failure. |
||
869 | */ |
||
870 | public function get_term( $taxonomy, $term_id, $is_term_id = true ) { |
||
878 | |||
879 | /** |
||
880 | * Verify a taxonomy is legitimate and register it if necessary. |
||
881 | * |
||
882 | * @access private |
||
883 | * |
||
884 | * @param string $taxonomy Taxonomy slug. |
||
885 | * @return bool|void|\WP_Error True if already exists; void if it was registered; \WP_Error on error. |
||
886 | */ |
||
887 | private function ensure_taxonomy( $taxonomy ) { |
||
906 | |||
907 | /** |
||
908 | * Retrieve all terms from a taxonomy that are related to an object with a particular ID. |
||
909 | * |
||
910 | * @access public |
||
911 | * |
||
912 | * @param int $object_id Object ID. |
||
913 | * @param string $taxonomy Taxonomy slug. |
||
914 | * @return array|bool|\WP_Error Array of terms on success, `false` if no terms or post doesn't exist, \WP_Error on failure. |
||
915 | */ |
||
916 | public function get_the_terms( $object_id, $taxonomy ) { |
||
919 | |||
920 | /** |
||
921 | * Insert or update a term. |
||
922 | * |
||
923 | * @access public |
||
924 | * |
||
925 | * @param \WP_Term $term_object Term object. |
||
926 | * @return array|bool|\WP_Error Array of term_id and term_taxonomy_id if updated, true if inserted, \WP_Error on failure. |
||
927 | */ |
||
928 | public function update_term( $term_object ) { |
||
961 | |||
962 | /** |
||
963 | * Delete a term by the term ID and its corresponding taxonomy. |
||
964 | * |
||
965 | * @access public |
||
966 | * |
||
967 | * @param int $term_id Term ID. |
||
968 | * @param string $taxonomy Taxonomy slug. |
||
969 | * @return bool|int|\WP_Error True on success, false if term doesn't exist. Zero if trying with default category. \WP_Error on invalid taxonomy. |
||
970 | */ |
||
971 | public function delete_term( $term_id, $taxonomy ) { |
||
974 | |||
975 | /** |
||
976 | * Add/update terms of a particular taxonomy of an object with the specified ID. |
||
977 | * |
||
978 | * @access public |
||
979 | * |
||
980 | * @param int $object_id The object to relate to. |
||
981 | * @param string $taxonomy The context in which to relate the term to the object. |
||
982 | * @param string|int|array $terms A single term slug, single term id, or array of either term slugs or ids. |
||
983 | * @param bool $append Optional. If false will delete difference of terms. Default false. |
||
984 | */ |
||
985 | public function update_object_terms( $object_id, $taxonomy, $terms, $append ) { |
||
988 | |||
989 | /** |
||
990 | * Remove certain term relationships from the specified object. |
||
991 | * |
||
992 | * @access public |
||
993 | * |
||
994 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
995 | * |
||
996 | * @param int $object_id ID of the object. |
||
997 | * @param array $tt_ids Term taxonomy IDs. |
||
998 | * @return bool True on success, false on failure. |
||
999 | */ |
||
1000 | public function delete_object_terms( $object_id, $tt_ids ) { |
||
1045 | |||
1046 | /** |
||
1047 | * Retrieve the number of users. |
||
1048 | * Not supported in this replicastore. |
||
1049 | * |
||
1050 | * @access public |
||
1051 | */ |
||
1052 | public function user_count() { |
||
1055 | |||
1056 | /** |
||
1057 | * Retrieve a user object by the user ID. |
||
1058 | * |
||
1059 | * @access public |
||
1060 | * |
||
1061 | * @param int $user_id User ID. |
||
1062 | * @return \WP_User User object. |
||
1063 | */ |
||
1064 | public function get_user( $user_id ) { |
||
1067 | |||
1068 | /** |
||
1069 | * Insert or update a user. |
||
1070 | * Not supported in this replicastore. |
||
1071 | * |
||
1072 | * @access public |
||
1073 | * @throws \Exception If this method is invoked. |
||
1074 | * |
||
1075 | * @param \WP_User $user User object. |
||
1076 | */ |
||
1077 | public function upsert_user( $user ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1080 | |||
1081 | /** |
||
1082 | * Delete a user. |
||
1083 | * Not supported in this replicastore. |
||
1084 | * |
||
1085 | * @access public |
||
1086 | * @throws \Exception If this method is invoked. |
||
1087 | * |
||
1088 | * @param int $user_id User ID. |
||
1089 | */ |
||
1090 | public function delete_user( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1093 | |||
1094 | /** |
||
1095 | * Update/insert user locale. |
||
1096 | * Not supported in this replicastore. |
||
1097 | * |
||
1098 | * @access public |
||
1099 | * @throws \Exception If this method is invoked. |
||
1100 | * |
||
1101 | * @param int $user_id User ID. |
||
1102 | * @param string $local The user locale. |
||
1103 | */ |
||
1104 | public function upsert_user_locale( $user_id, $local ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1107 | |||
1108 | /** |
||
1109 | * Delete user locale. |
||
1110 | * Not supported in this replicastore. |
||
1111 | * |
||
1112 | * @access public |
||
1113 | * @throws \Exception If this method is invoked. |
||
1114 | * |
||
1115 | * @param int $user_id User ID. |
||
1116 | */ |
||
1117 | public function delete_user_locale( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1120 | |||
1121 | /** |
||
1122 | * Retrieve the user locale. |
||
1123 | * |
||
1124 | * @access public |
||
1125 | * |
||
1126 | * @param int $user_id User ID. |
||
1127 | * @return string The user locale. |
||
1128 | */ |
||
1129 | public function get_user_locale( $user_id ) { |
||
1132 | |||
1133 | /** |
||
1134 | * Retrieve the allowed mime types for the user. |
||
1135 | * Not supported in this replicastore. |
||
1136 | * |
||
1137 | * @access public |
||
1138 | * |
||
1139 | * @param int $user_id User ID. |
||
1140 | */ |
||
1141 | public function get_allowed_mime_types( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1144 | |||
1145 | /** |
||
1146 | * Retrieve all the checksums we are interested in. |
||
1147 | * Currently that is posts, comments, post meta and comment meta. |
||
1148 | * |
||
1149 | * @access public |
||
1150 | * |
||
1151 | * @return array Checksums. |
||
1152 | */ |
||
1153 | public function checksum_all() { |
||
1172 | |||
1173 | /** |
||
1174 | * Return the summarized checksum from buckets or the WP_Error. |
||
1175 | * |
||
1176 | * @param array $histogram checksum_histogram result. |
||
1177 | * |
||
1178 | * @return int|WP_Error checksum or Error. |
||
1179 | */ |
||
1180 | protected function summarize_checksum_histogram( $histogram ) { |
||
1187 | |||
1188 | /** |
||
1189 | * Grabs the minimum and maximum object ids for the given parameters. |
||
1190 | * |
||
1191 | * @access public |
||
1192 | * |
||
1193 | * @param string $id_field The id column in the table to query. |
||
1194 | * @param string $object_table The table to query. |
||
1195 | * @param string $where A sql where clause without 'WHERE'. |
||
1196 | * @param int $bucket_size The maximum amount of objects to include in the query. |
||
1197 | * For `term_relationships` table, the bucket size will refer to the amount |
||
1198 | * of distinct object ids. This will likely include more database rows than |
||
1199 | * the bucket size implies. |
||
1200 | * |
||
1201 | * @return object An object with min_id and max_id properties. |
||
1202 | */ |
||
1203 | public function get_min_max_object_id( $id_field, $object_table, $where, $bucket_size ) { |
||
1222 | |||
1223 | /** |
||
1224 | * Retrieve the checksum histogram for a specific object type. |
||
1225 | * |
||
1226 | * @access public |
||
1227 | * |
||
1228 | * @param string $table Object type. |
||
1229 | * @param int $buckets Number of buckets to split the objects to. |
||
1230 | * @param int $start_id Minimum object ID. |
||
1231 | * @param int $end_id Maximum object ID. |
||
1232 | * @param array $columns Table columns to calculate the checksum from. |
||
1233 | * @param bool $strip_non_ascii Whether to strip non-ASCII characters. |
||
1234 | * @param string $salt Salt, used for $wpdb->prepare()'s args. |
||
1235 | * |
||
1236 | * @return array The checksum histogram. |
||
1237 | */ |
||
1238 | public function checksum_histogram( $table, $buckets, $start_id = null, $end_id = null, $columns = null, $strip_non_ascii = true, $salt = '' ) { |
||
1282 | |||
1283 | /** |
||
1284 | * Retrieve the type of the checksum. |
||
1285 | * |
||
1286 | * @access public |
||
1287 | * |
||
1288 | * @return string Type of the checksum. |
||
1289 | */ |
||
1290 | public function get_checksum_type() { |
||
1293 | |||
1294 | /** |
||
1295 | * Used in methods that are not implemented and shouldn't be invoked. |
||
1296 | * |
||
1297 | * @access private |
||
1298 | * @throws \Exception If this method is invoked. |
||
1299 | */ |
||
1300 | private function invalid_call() { |
||
1306 | |||
1307 | /** |
||
1308 | * Determine number of buckets to use in full table checksum. |
||
1309 | * |
||
1310 | * @param string $table Object Type. |
||
1311 | * @param int $start_id Min Object ID. |
||
1312 | * @param int $end_id Max Object ID. |
||
1313 | * @return int Number of Buckets to use. |
||
1314 | */ |
||
1315 | private function calculate_buckets( $table, $start_id = null, $end_id = null ) { |
||
1336 | } |
||
1337 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.