PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | jetpack_vendor/automattic/jetpack-search/src/class-cli.php +57 -0 13.6.2 → 16.3-a.7 View file →
@@ -10,8 +10,12 @@
10 10 use WP_CLI;
11 11 use WP_CLI_Command;
12 12 use WP_Error;
13 13
14 +if ( ! defined( 'ABSPATH' ) ) {
15 + exit( 0 );
16 +}
17 +
14 18 if ( ! class_exists( 'WP_CLI_Command' ) ) {
15 19 return;
16 20 }
17 21
@@ -45,8 +49,61 @@
45 49 WP_CLI::line( 'Running as user ' . $ret->user_login . '…' );
46 50 $blog_id = Helper::get_wpcom_site_id();
47 51 Instant_Search::instance( $blog_id )->auto_config_search();
48 52 WP_CLI::success( 'Auto config success!' );
53 + } catch ( \Exception $e ) {
54 + WP_CLI::error( $e->getMessage() );
55 + }
56 + }
57 +
58 + /**
59 + * Backfill the reserved-slot taxonomy projection for any user-facing
60 + * taxonomies declared in `jetpack_search_custom_taxonomy_map`.
61 + *
62 + * Wraps `Custom_Taxonomy_Slot_Mapping::backfill()` so operators don't have
63 + * to reach for `wp eval` and a fully-qualified static call. The auto-mirror
64 + * on `set_object_terms` / `deleted_term_relationships` / `delete_term`
65 + * keeps the slot in sync from the moment the mapping is declared — this
66 + * subcommand only needs to run once after the mapping is first turned on,
67 + * or after a gap during which the auto-mirror was inactive.
68 + *
69 + * ## OPTIONS
70 + *
71 + * [--mode=<mode>]
72 + * : Backfill mode.
73 + * ---
74 + * default: mirror
75 + * options:
76 + * - mirror
77 + * - rebuild
78 + * ---
79 + *
80 + * ## EXAMPLES
81 + *
82 + * # Per-post mirror — cheap, idempotent, safe to re-run.
83 + * wp jetpack-search backfill_taxonomy_slot_mapping
84 + *
85 + * # Full sweep — wipes the slot taxonomy first, then re-projects.
86 + * wp jetpack-search backfill_taxonomy_slot_mapping --mode=rebuild
87 + *
88 + * @param array $args Positional args (unused).
89 + * @param array $assoc_args Associative args. Supports `mode`.
90 + */
91 + public function backfill_taxonomy_slot_mapping( $args, $assoc_args ) {
92 + $mode = isset( $assoc_args['mode'] ) ? (string) $assoc_args['mode'] : 'mirror';
93 + if ( ! in_array( $mode, Custom_Taxonomy_Slot_Mapping::BACKFILL_MODES, true ) ) {
94 + WP_CLI::error( sprintf( 'Unknown mode "%s"; expected one of: %s.', $mode, implode( ', ', Custom_Taxonomy_Slot_Mapping::BACKFILL_MODES ) ) );
95 + }
96 +
97 + if ( empty( Custom_Taxonomy_Slot_Mapping::get_map() ) ) {
98 + WP_CLI::warning( 'jetpack_search_custom_taxonomy_map is empty; nothing to backfill.' );
99 + return;
100 + }
101 +
102 + WP_CLI::line( sprintf( 'Running backfill in %s mode…', $mode ) );
103 + try {
104 + $count = Custom_Taxonomy_Slot_Mapping::backfill( $mode );
105 + WP_CLI::success( sprintf( 'Backfilled %d (post, taxonomy) pair(s).', $count ) );
49 106 } catch ( \Exception $e ) {
50 107 WP_CLI::error( $e->getMessage() );
51 108 }
52 109 }