PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
← All changes | includes/classes/Command.php +219 -97 4.6.05.3.5 View file →
@@ -9,15 +9,16 @@
9 9 */
10 10
11 11 namespace ElasticPress;
12 12
13 -use \WP_CLI_Command;
14 -use \WP_CLI;
13 +use WP_CLI_Command;
14 +use WP_CLI;
15 +use ElasticPress\Command\Utility;
16 +use ElasticPress\Elasticsearch;
17 +use ElasticPress\FeatureRequirementsStatus;
15 18 use ElasticPress\Features;
19 +use ElasticPress\Indexables;
16 20 use ElasticPress\Utils;
17 -use ElasticPress\Elasticsearch;
18 -use ElasticPress\Indexables;
19 -use ElasticPress\Command\Utility;
20 21
21 22 if ( ! defined( 'ABSPATH' ) ) {
22 23 // @codeCoverageIgnoreStart
23 24 exit; // Exit if accessed directly.
@@ -104,14 +105,14 @@
104 105 }
105 106
106 107 $status = $feature->requirements_status();
107 108
108 - if ( 2 === $status->code ) {
109 + if ( FeatureRequirementsStatus::FORCE_DISABLED === $status->get_code() ) {
109 110 /* translators: Error message */
110 - WP_CLI::error( sprintf( esc_html__( 'Feature requirements are not met: %s', 'elasticpress' ), implode( "\n\n", (array) $status->message ) ) );
111 - } elseif ( 1 === $status->code ) {
111 + WP_CLI::error( sprintf( esc_html__( 'Feature requirements are not met: %s', 'elasticpress' ), implode( "\n\n", (array) $status->get_message() ) ) );
112 + } elseif ( FeatureRequirementsStatus::MANUALLY_ENABLED === $status->get_code() && ! empty( $status->get_message() ) ) {
112 113 /* translators: Warning message */
113 - WP_CLI::warning( sprintf( esc_html__( 'Feature is usable but there are warnings: %s', 'elasticpress' ), implode( "\n\n", (array) $status->message ) ) );
114 + WP_CLI::warning( sprintf( esc_html__( 'Feature is usable but there are warnings: %s', 'elasticpress' ), implode( "\n\n", (array) $status->get_message() ) ) );
114 115 }
115 116
116 117 Features::factory()->activate_feature( $feature->slug );
117 118
@@ -143,13 +144,18 @@
143 144 if ( empty( $feature ) ) {
144 145 WP_CLI::error( esc_html__( 'No feature with that slug is registered', 'elasticpress' ) );
145 146 }
146 147
147 - $active_features = Utils\get_option( 'ep_feature_settings', [] );
148 + $active_features = (array) Features::factory()->get_feature_settings();
149 + $active_features_draft = (array) Features::factory()->get_feature_settings_draft();
148 150
149 - $key = array_search( $feature->slug, array_keys( $active_features ), true );
151 + $key_current = array_search( $feature->slug, array_keys( $active_features ), true );
152 + $key_draft = array_search( $feature->slug, array_keys( $active_features_draft ), true );
150 153
151 - if ( false === $key || empty( $active_features[ $feature->slug ]['active'] ) ) {
154 + $in_current = false !== $key_current && ! empty( $active_features[ $feature->slug ]['active'] );
155 + $in_draft = false !== $key_draft && ! empty( $active_features_draft[ $feature->slug ]['active'] );
156 +
157 + if ( ! $in_current && ! $in_draft ) {
152 158 WP_CLI::error( esc_html__( 'Feature is not active', 'elasticpress' ) );
153 159 }
154 160
155 161 Features::factory()->deactivate_feature( $feature->slug );
@@ -173,9 +179,9 @@
173 179 public function list_features( $args, $assoc_args ) {
174 180 $list_all = \WP_CLI\Utils\get_flag_value( $assoc_args, 'all', null );
175 181
176 182 if ( empty( $list_all ) ) {
177 - $features = Utils\get_option( 'ep_feature_settings', [] );
183 + $features = Features::factory()->get_feature_settings();
178 184
179 185 WP_CLI::line( esc_html__( 'Active features:', 'elasticpress' ) );
180 186
181 187 foreach ( array_keys( $features ) as $feature_slug ) {
@@ -249,15 +255,11 @@
249 255 if ( ! is_numeric( $assoc_args['network-wide'] ) ) {
250 256 $assoc_args['network-wide'] = 0;
251 257 }
252 258
253 - $sites = Utils\get_sites( $assoc_args['network-wide'] );
259 + $sites = Utils\get_sites( $assoc_args['network-wide'], true );
254 260
255 261 foreach ( $sites as $site ) {
256 - if ( ! Utils\is_site_indexable( $site['blog_id'] ) ) {
257 - continue;
258 - }
259 -
260 262 switch_to_blog( $site['blog_id'] );
261 263
262 264 foreach ( $non_global_indexable_objects as $indexable ) {
263 265 /**
@@ -512,9 +514,9 @@
512 514 if ( isset( $assoc_args['network-wide'] ) && defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
513 515 if ( ! is_numeric( $assoc_args['network-wide'] ) ) {
514 516 $assoc_args['network-wide'] = 0;
515 517 }
516 - $sites = Utils\get_sites( $assoc_args['network-wide'] );
518 + $sites = Utils\get_sites( $assoc_args['network-wide'], false );
517 519
518 520 foreach ( $sites as $site ) {
519 521 switch_to_blog( $site['blog_id'] );
520 522
@@ -620,8 +622,20 @@
620 622 WP_CLI::success( esc_html__( 'Done.', 'elasticpress' ) );
621 623 }
622 624
623 625 /**
626 + * A WP-CLI wrapper to run `Autosuggest::post_deactivation()`.
627 + *
628 + * @subcommand epio-reset-autosuggest
629 + * @since 5.3.2
630 + */
631 + public function epio_reset_autosuggest() {
632 + Features::factory()->get_registered_feature( 'autosuggest' )->post_deactivation();
633 +
634 + WP_CLI::success( esc_html__( 'Done.', 'elasticpress' ) );
635 + }
636 +
637 + /**
624 638 * Helper method for creating the network alias for an indexable
625 639 *
626 640 * @param Indexable $indexable Instance of indexable.
627 641 * @since 0.9
@@ -627,16 +641,12 @@
627 641 * @since 0.9
628 642 * @return array|bool
629 643 */
630 644 private function create_network_alias_helper( Indexable $indexable ) {
631 - $sites = Utils\get_sites();
645 + $sites = Utils\get_sites( 0, true );
632 646 $indexes = [];
633 647
634 648 foreach ( $sites as $site ) {
635 - if ( ! Utils\is_site_indexable( $site['blog_id'] ) ) {
636 - continue;
637 - }
638 -
639 649 switch_to_blog( $site['blog_id'] );
640 650
641 651 $indexes[] = $indexable->get_index_name();
642 652
@@ -688,8 +698,11 @@
688 698 *
689 699 * [--show-nobulk-errors]
690 700 * : Display the error message returned from Elasticsearch when a post fails to index while not using the /_bulk endpoint
691 701 *
702 + * [--stop-on-error]
703 + * : Stop indexing if an error is encountered and display the error.
704 + *
692 705 * [--offset=<offset_number>]
693 706 * : Skip the first n posts (don't forget to remove the `--setup` flag when resuming or the index will be emptied before starting again).
694 707 *
695 708 * [--indexables=<indexables>]
@@ -799,9 +812,16 @@
799 812 'offset' => ( ! empty( $assoc_args['offset'] ) ) ? absint( $assoc_args['offset'] ) : 0,
800 813 'static_bulk' => $static_bulk,
801 814 ];
802 815
803 - if ( isset( $assoc_args['show-errors'] ) || ( isset( $assoc_args['show-bulk-errors'] ) && ! $no_bulk ) || ( isset( $assoc_args['show-nobulk-errors'] ) && $no_bulk ) ) {
816 + $index_args['stop_on_error'] = WP_CLI\Utils\get_flag_value( $assoc_args, 'stop-on-error', false );
817 +
818 + $show_errors = $index_args['stop_on_error'] ||
819 + WP_CLI\Utils\get_flag_value( $assoc_args, 'show-errors', false ) ||
820 + ( WP_CLI\Utils\get_flag_value( $assoc_args, 'show-bulk-errors', false ) && ! $no_bulk ) ||
821 + ( WP_CLI\Utils\get_flag_value( $assoc_args, 'show-nobulk-errors', false ) && $no_bulk );
822 +
823 + if ( $show_errors ) {
804 824 $index_args['show_errors'] = true;
805 825 }
806 826
807 827 if ( ! empty( $assoc_args['post-ids'] ) ) {
@@ -866,10 +886,8 @@
866 886 */
867 887 public function status() {
868 888 $this->connect_check();
869 889
870 - $request_args = [ 'headers' => Elasticsearch::factory()->format_request_headers() ];
871 -
872 890 $registered_index_names = $this->get_index_names();
873 891
874 892 $response_cat_indices = Elasticsearch::factory()->remote_request( '_cat/indices?format=json' );
875 893
@@ -888,9 +906,9 @@
888 906 }
889 907
890 908 $index_names_imploded = implode( ',', $index_names );
891 909
892 - $request = wp_remote_get( trailingslashit( Utils\get_host( true ) ) . $index_names_imploded . '/_recovery/?pretty', $request_args );
910 + $request = Elasticsearch::factory()->remote_request( $index_names_imploded . '/_recovery/?pretty' );
893 911
894 912 if ( is_wp_error( $request ) ) {
895 913 WP_CLI::error( implode( "\n", $request->get_error_messages() ) );
896 914 }
@@ -911,10 +929,8 @@
911 929 */
912 930 public function stats() {
913 931 $this->connect_check();
914 932
915 - $request_args = array( 'headers' => Elasticsearch::factory()->format_request_headers() );
916 -
917 933 $registered_index_names = $this->get_index_names();
918 934
919 935 $response_cat_indices = Elasticsearch::factory()->remote_request( '_cat/indices?format=json' );
920 936
@@ -933,9 +949,10 @@
933 949 }
934 950
935 951 $index_names_imploded = implode( ',', $index_names );
936 952
937 - $request = wp_remote_get( trailingslashit( Utils\get_host( true ) ) . $index_names_imploded . '/_stats/', $request_args );
953 + Elasticsearch::factory()->refresh_indices();
954 + $request = Elasticsearch::factory()->remote_request( $index_names_imploded . '/_stats/' );
938 955
939 956 if ( is_wp_error( $request ) ) {
940 957 WP_CLI::error( implode( "\n", $request->get_error_messages() ) );
941 958 }
@@ -1065,9 +1082,9 @@
1065 1082 * @param array $assoc_args Associative CLI args.
1066 1083 */
1067 1084 public function get_last_sync( $args, $assoc_args ) {
1068 1085 $pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' );
1069 - $last_sync = \ElasticPress\IndexHelper::factory()->get_last_index();
1086 + $last_sync = \ElasticPress\IndexHelper::factory()->get_last_sync();
1070 1087
1071 1088 $this->pretty_json_encode( $last_sync, $pretty );
1072 1089 }
1073 1090
@@ -1109,9 +1126,9 @@
1109 1126 private function maybe_change_host( $assoc_args ) {
1110 1127 if ( isset( $assoc_args['ep-host'] ) ) {
1111 1128 add_filter(
1112 1129 'ep_host',
1113 - function ( $host ) use ( $assoc_args ) {
1130 + function () use ( $assoc_args ) {
1114 1131 return $assoc_args['ep-host'];
1115 1132 }
1116 1133 );
1117 1134 }
@@ -1116,9 +1133,8 @@
1116 1133 );
1117 1134 }
1118 1135 }
1119 1136
1120 -
1121 1137 /**
1122 1138 * maybe change index prefix on the fly
1123 1139 *
1124 1140 * @param array $assoc_args Associative CLI args.
@@ -1128,9 +1144,9 @@
1128 1144 private function maybe_change_index_prefix( $assoc_args ) {
1129 1145 if ( isset( $assoc_args['ep-prefix'] ) ) {
1130 1146 add_filter(
1131 1147 'ep_index_prefix',
1132 - function ( $prefix ) use ( $assoc_args ) {
1148 + function ( $prefix ) use ( $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
1133 1149 return $assoc_args['ep-prefix'];
1134 1150 }
1135 1151 );
1136 1152 }
@@ -1270,9 +1286,9 @@
1270 1286 return Utility::custom_get_transient( $pre_transient, $transient );
1271 1287 }
1272 1288
1273 1289 /**
1274 - * Utilitary function to render Stats for a given index.
1290 + * Utility function to render Stats for a given index.
1275 1291 *
1276 1292 * @since 3.5.6
1277 1293 * @param string $current_index The index name.
1278 1294 * @param array $body The response body.
@@ -1309,8 +1325,9 @@
1309 1325 case 'warning':
1310 1326 if ( empty( $args['show_errors'] ) ) {
1311 1327 return;
1312 1328 }
1329 +
1313 1330 WP_CLI::warning( $message['message'] );
1314 1331 break;
1315 1332
1316 1333 case 'error':
@@ -1323,17 +1340,19 @@
1323 1340 break;
1324 1341 }
1325 1342
1326 1343 if ( 'index_next_batch' === $context ) {
1327 - $counter++;
1344 + ++$counter;
1328 1345 if ( ( $counter % 10 ) === 0 ) {
1329 1346 $time_elapsed_diff = $time_elapsed > 0 ? ' (+' . (string) ( Utility::timer_stop() - $time_elapsed ) . ')' : '';
1330 1347 $time_elapsed = Utility::timer_stop( 2 );
1331 1348 WP_CLI::log( WP_CLI::colorize( '%Y' . esc_html__( 'Time elapsed: ', 'elasticpress' ) . '%N' . Utility::timer_format( $time_elapsed ) . $time_elapsed_diff ) );
1332 1349
1333 - $current_memory = round( memory_get_usage() / 1024 / 1024, 2 ) . 'mb';
1334 - $peak_memory = ' (Peak: ' . round( memory_get_peak_usage() / 1024 / 1024, 2 ) . 'mb)';
1335 - WP_CLI::log( WP_CLI::colorize( '%Y' . esc_html__( 'Memory Usage: ', 'elasticpress' ) . '%N' . $current_memory . $peak_memory ) );
1350 + $current_memory = memory_get_usage() / 1024 / 1024;
1351 + $current_memory = ( $current_memory > 1000 ) ? round( $current_memory / 1024, 2 ) . 'gb' : round( $current_memory, 2 ) . 'mb';
1352 + $peak_memory = memory_get_peak_usage() / 1024 / 1024;
1353 + $peak_memory = ( $peak_memory > 1000 ) ? round( $peak_memory / 1024, 2 ) . 'gb' : round( $peak_memory, 2 ) . 'mb';
1354 + WP_CLI::log( WP_CLI::colorize( '%Y' . esc_html__( 'Memory Usage: ', 'elasticpress' ) . '%N' . $current_memory . ' (Peak: ' . $peak_memory . ')' ) );
1336 1355 }
1337 1356 }
1338 1357 }
1339 1358
@@ -1390,14 +1409,13 @@
1390 1409 * @param array $args Positional CLI args.
1391 1410 * @param array $assoc_args Associative CLI args.
1392 1411 */
1393 1412 public function request( $args, $assoc_args ) {
1394 - $pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' );
1395 - $debug_http_request = \WP_CLI\Utils\get_flag_value( $assoc_args, 'debug-http-request' );
1396 - $path = $args[0];
1397 - $method = isset( $assoc_args['method'] ) ? $assoc_args['method'] : 'GET';
1398 - $body = isset( $assoc_args['body'] ) ? $assoc_args['body'] : '';
1399 - $request_args = [
1413 + $pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' );
1414 + $path = $args[0];
1415 + $method = isset( $assoc_args['method'] ) ? $assoc_args['method'] : 'GET';
1416 + $body = isset( $assoc_args['body'] ) ? $assoc_args['body'] : '';
1417 + $request_args = [
1400 1418 'method' => $method,
1401 1419 ];
1402 1420 if ( 'GET' !== $method && ! empty( $body ) ) {
1403 1421 $request_args['body'] = $body;
@@ -1402,54 +1420,9 @@
1402 1420 if ( 'GET' !== $method && ! empty( $body ) ) {
1403 1421 $request_args['body'] = $body;
1404 1422 }
1405 1423
1406 - if ( ! empty( $debug_http_request ) ) {
1407 - add_filter(
1408 - 'http_api_debug',
1409 - function ( $response, $context, $transport, $request_args, $url ) {
1410 - // phpcs:disable WordPress.PHP.DevelopmentFunctions
1411 - WP_CLI::line(
1412 - sprintf(
1413 - /* translators: URL of the request */
1414 - esc_html__( 'URL: %s', 'elasticpress' ),
1415 - $url
1416 - )
1417 - );
1418 - WP_CLI::line(
1419 - sprintf(
1420 - /* translators: Request arguments (outputted with print_r()) */
1421 - esc_html__( 'Request Args: %s', 'elasticpress' ),
1422 - print_r( $request_args, true )
1423 - )
1424 - );
1425 - WP_CLI::line(
1426 - sprintf(
1427 - /* translators: HTTP transport used */
1428 - esc_html__( 'Transport: %s', 'elasticpress' ),
1429 - $transport
1430 - )
1431 - );
1432 - WP_CLI::line(
1433 - sprintf(
1434 - /* translators: Context under which the http_api_debug hook is fired */
1435 - esc_html__( 'Context: %s', 'elasticpress' ),
1436 - $context
1437 - )
1438 - );
1439 - WP_CLI::line(
1440 - sprintf(
1441 - /* translators: HTTP response (outputted with print_r()) */
1442 - esc_html__( 'Response: %s', 'elasticpress' ),
1443 - print_r( $response, true )
1444 - )
1445 - );
1446 - // phpcs:enable WordPress.PHP.DevelopmentFunctions
1447 - },
1448 - 10,
1449 - 5
1450 - );
1451 - }
1424 + $this->maybe_add_http_api_debug_filter( $assoc_args );
1452 1425 $response = Elasticsearch::factory()->remote_request( $path, $request_args, [], 'wp_cli_request' );
1453 1426
1454 1427 if ( is_wp_error( $response ) ) {
1455 1428 WP_CLI::error( $response->get_error_message() );
@@ -1515,9 +1488,9 @@
1515 1488 * @param array $json_obj The JSON object or array.
1516 1489 * @param boolean $pretty_print_flag Whether it should or not be formatted.
1517 1490 */
1518 1491 protected function pretty_json_encode( $json_obj, $pretty_print_flag ) {
1519 - $flag = $pretty_print_flag ? JSON_PRETTY_PRINT : null;
1492 + $flag = $pretty_print_flag ? JSON_PRETTY_PRINT : 0;
1520 1493 WP_CLI::line( wp_json_encode( $json_obj, $flag ) );
1521 1494 }
1522 1495
1523 1496 /**
@@ -1544,14 +1517,24 @@
1544 1517
1545 1518 /**
1546 1519 * Saves the Instant Results search template to EPIO.
1547 1520 *
1521 + * ## OPTIONS
1522 + *
1523 + * [--network-wide]
1524 + * : Save the template for all sites in the network if plugin is network activated. Otherwise, save the template for the current site only.
1525 + *
1548 1526 * @since 4.5.0
1527 + * @param array $args Positional CLI args.
1528 + * @param array $assoc_args Associative CLI args.
1549 1529 * @subcommand put-search-template
1550 1530 */
1551 - public function put_search_template() {
1531 + public function put_search_template( $args, $assoc_args ) {
1532 + $network_wide = \WP_CLI\Utils\get_flag_value( $assoc_args, 'network-wide', false );
1552 1533 $instant_results = Features::factory()->get_registered_feature( 'instant-results' );
1553 - $instant_results->epio_save_search_template();
1534 +
1535 + $instant_results->epio_save_site_search_template( $network_wide );
1536 +
1554 1537 WP_CLI::success( esc_html__( 'Done.', 'elasticpress' ) );
1555 1538 }
1556 1539
1557 1540 /**
@@ -1556,13 +1539,152 @@
1556 1539
1557 1540 /**
1558 1541 * Deletes the Instant Results search template.
1559 1542 *
1543 + * ## OPTIONS
1544 + *
1545 + * [--network-wide]
1546 + * : Delete the template for all sites in the network if plugin is network activated. Otherwise, delete the template for the current site only.
1547 + *
1560 1548 * @since 4.5.0
1549 + * @param array $args Positional CLI args.
1550 + * @param array $assoc_args Associative CLI args.
1561 1551 * @subcommand delete-search-template
1562 1552 */
1563 - public function delete_search_template() {
1553 + public function delete_search_template( $args, $assoc_args ) {
1554 + $network_wide = \WP_CLI\Utils\get_flag_value( $assoc_args, 'network-wide', false );
1564 1555 $instant_results = Features::factory()->get_registered_feature( 'instant-results' );
1565 - $instant_results->epio_delete_search_template();
1556 +
1557 + $instant_results->epio_delete_site_search_template( $network_wide );
1558 +
1566 1559 WP_CLI::success( esc_html__( 'Done.', 'elasticpress' ) );
1560 + }
1561 +
1562 + /**
1563 + * Get an index settings
1564 + *
1565 + * ## OPTIONS
1566 + *
1567 + * <index_name>
1568 + * : Index name
1569 + *
1570 + * [--pretty]
1571 + * : Use this flag to render a pretty-printed version of the JSON response.
1572 + *
1573 + * @subcommand get-index-settings
1574 + *
1575 + * @since 4.7.0
1576 + *
1577 + * @param array $args Positional CLI args.
1578 + * @param array $assoc_args Associative CLI args.
1579 + */
1580 + public function get_index_settings( $args, $assoc_args ) {
1581 + $response = Elasticsearch::factory()->get_index_settings( $args[0], true );
1582 + $pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' );
1583 +
1584 + $this->pretty_json_encode( $response, $pretty );
1585 + }
1586 +
1587 + /**
1588 + * Get a specific content in Elasticsearch
1589 + *
1590 + * ## OPTIONS
1591 + *
1592 + * <indexable>
1593 + * : Indexable slug. Example: `post`
1594 + *
1595 + * <ID>
1596 + * : Content ID
1597 + *
1598 + * [--debug-http-request]
1599 + * : Enable debugging
1600 + *
1601 + * [--pretty]
1602 + * : Use this flag to render a pretty-printed version of the JSON response.
1603 + *
1604 + * @since 4.7.0
1605 + *
1606 + * @param array $args Positional CLI args.
1607 + * @param array $assoc_args Associative CLI args.
1608 + */
1609 + public function get( $args, $assoc_args ) {
1610 + $indexables = Indexables::factory();
1611 +
1612 + $indexable = $indexables->get( $args[0] );
1613 + if ( ! $indexable || ! $indexables->is_active( $args[0] ) ) {
1614 + $message = wp_sprintf(
1615 + /* translators: list of active indexables slugs */
1616 + esc_html__( 'Indexable not found or inactive. Active indexables are: %l', 'elasticpress' ),
1617 + $indexables->get_all( null, true )
1618 + );
1619 + WP_CLI::error( $message );
1620 + }
1621 +
1622 + $this->maybe_add_http_api_debug_filter( $assoc_args );
1623 +
1624 + $object = $indexable->get( $args[1] );
1625 + if ( ! $object ) {
1626 + WP_CLI::error( esc_html__( 'Not found', 'elasticpress' ) );
1627 + }
1628 +
1629 + $pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' );
1630 +
1631 + $this->pretty_json_encode( $object, $pretty );
1632 + }
1633 +
1634 + /**
1635 + * Given associative CLI args, conditionally displays HTTP debug info
1636 + *
1637 + * @since 4.7.0
1638 + * @param array $assoc_args Associative CLI args.
1639 + */
1640 + protected function maybe_add_http_api_debug_filter( $assoc_args ) {
1641 + $debug_http_request = \WP_CLI\Utils\get_flag_value( $assoc_args, 'debug-http-request' );
1642 +
1643 + if ( ! empty( $debug_http_request ) ) {
1644 + add_filter(
1645 + 'http_api_debug',
1646 + function ( $response, $context, $transport, $request_args, $url ) {
1647 + // phpcs:disable WordPress.PHP.DevelopmentFunctions
1648 + WP_CLI::line(
1649 + sprintf(
1650 + /* translators: URL of the request */
1651 + esc_html__( 'URL: %s', 'elasticpress' ),
1652 + $url
1653 + )
1654 + );
1655 + WP_CLI::line(
1656 + sprintf(
1657 + /* translators: Request arguments (outputted with print_r()) */
1658 + esc_html__( 'Request Args: %s', 'elasticpress' ),
1659 + print_r( $request_args, true )
1660 + )
1661 + );
1662 + WP_CLI::line(
1663 + sprintf(
1664 + /* translators: HTTP transport used */
1665 + esc_html__( 'Transport: %s', 'elasticpress' ),
1666 + $transport
1667 + )
1668 + );
1669 + WP_CLI::line(
1670 + sprintf(
1671 + /* translators: Context under which the http_api_debug hook is fired */
1672 + esc_html__( 'Context: %s', 'elasticpress' ),
1673 + $context
1674 + )
1675 + );
1676 + WP_CLI::line(
1677 + sprintf(
1678 + /* translators: HTTP response (outputted with print_r()) */
1679 + esc_html__( 'Response: %s', 'elasticpress' ),
1680 + print_r( $response, true )
1681 + )
1682 + );
1683 + // phpcs:enable WordPress.PHP.DevelopmentFunctions
1684 + },
1685 + 10,
1686 + 5
1687 + );
1688 + }
1567 1689 }
1568 1690 }