| @@ -1,8 +1,10 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | /** |
| 3 | - * Adds the PSH functionality to Jetpack. | |
| 3 | + * Plugin Search Hints, aka Feature Suggestions. | |
| 4 | 4 | * |
| 5 | + * @since 7.1.0 | |
| 6 | + * | |
| 5 | 7 | * @package automattic/jetpack |
| 6 | 8 | */ |
| 7 | 9 | |
| 8 | 10 | // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. |
| @@ -13,9 +15,9 @@ | ||
| 13 | 15 | use Automattic\Jetpack\Tracking; |
| 14 | 16 | |
| 15 | 17 | // Disable direct access and execution. |
| 16 | 18 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | - exit; | |
| 19 | + exit( 0 ); | |
| 18 | 20 | } |
| 19 | 21 | |
| 20 | 22 | if ( |
| 21 | 23 | is_admin() && |
| @@ -237,9 +239,8 @@ | ||
| 237 | 239 | 'jetpackPluginSearch', |
| 238 | 240 | array( |
| 239 | 241 | 'nonce' => wp_create_nonce( 'wp_rest' ), |
| 240 | 242 | 'base_rest_url' => rest_url( '/jetpack/v4' ), |
| 241 | - 'poweredBy' => esc_html__( 'by Jetpack (installed)', 'jetpack' ), | |
| 242 | 243 | 'manageSettings' => esc_html__( 'Configure', 'jetpack' ), |
| 243 | 244 | 'activateModule' => esc_html__( 'Activate Module', 'jetpack' ), |
| 244 | 245 | 'getStarted' => esc_html__( 'Get started', 'jetpack' ), |
| 245 | 246 | 'activated' => esc_html__( 'Activated', 'jetpack' ), |
| @@ -311,20 +312,31 @@ | ||
| 311 | 312 | 'configure_url' => admin_url( 'admin.php?page=akismet-key-config' ), |
| 312 | 313 | ), |
| 313 | 314 | 'sharing-block' => array( |
| 314 | 315 | 'name' => esc_html__( 'Sharing buttons block', 'jetpack' ), |
| 315 | - 'search_terms' => 'share, sharing, sharing block, sharing button, social buttons, buttons, share facebook, share twitter, social share, icons, email, facebook, twitter, x, linkedin, pinterest, pocket, social media', | |
| 316 | + 'search_terms' => 'share, sharing, sharing block, sharing button, social buttons, buttons, share facebook, share twitter, social share, icons, email, facebook, twitter, x, linkedin, pinterest, social media', | |
| 316 | 317 | 'short_description' => esc_html__( 'Add sharing buttons blocks anywhere on your website to help your visitors share your content.', 'jetpack' ), |
| 317 | 318 | 'requires_connection' => false, |
| 318 | 319 | 'module' => 'sharing-block', |
| 319 | 320 | 'sort' => '13', |
| 320 | 321 | 'learn_more_button' => Redirect::get_url( 'jetpack-support-sharing-block' ), |
| 321 | - 'configure_url' => admin_url( 'site-editor.php?path=%2Fwp_template' ), | |
| 322 | + 'configure_url' => $this->get_sharing_block_editor_url(), | |
| 322 | 323 | ), |
| 323 | 324 | ); |
| 324 | 325 | } |
| 325 | 326 | |
| 326 | 327 | /** |
| 328 | + * Site Editor URL for the template the Sharing Buttons block goes in. | |
| 329 | + * | |
| 330 | + * @return string | |
| 331 | + */ | |
| 332 | + private function get_sharing_block_editor_url() { | |
| 333 | + return admin_url( | |
| 334 | + 'site-editor.php?p=' . rawurlencode( '/wp_template/' . get_stylesheet() . '//single' ) . '&canvas=edit' | |
| 335 | + ); | |
| 336 | + } | |
| 337 | + | |
| 338 | + /** | |
| 327 | 339 | * Intercept the plugins API response and add in an appropriate card for Jetpack |
| 328 | 340 | * |
| 329 | 341 | * @param object $result Plugin search results. |
| 330 | 342 | * @param string $action unused. |
| @@ -365,8 +377,19 @@ | ||
| 365 | 377 | } else { |
| 366 | 378 | $searchable_modules[] = 'sharedaddy'; |
| 367 | 379 | } |
| 368 | 380 | |
| 381 | + /* | |
| 382 | + * Only surface the SEO Tools hint when the new Jetpack SEO admin page is | |
| 383 | + * available and registered, so its CTA never points to a missing page. | |
| 384 | + */ | |
| 385 | + if ( | |
| 386 | + \Automattic\Jetpack\SEO\Initializer::is_available() | |
| 387 | + && \Automattic\Jetpack\SEO\Initializer::is_seo_surface_visible() | |
| 388 | + ) { | |
| 389 | + $searchable_modules[] = 'seo-tools'; | |
| 390 | + } | |
| 391 | + | |
| 369 | 392 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-admin.php'; |
| 370 | 393 | $tracking = new Tracking(); |
| 371 | 394 | $jetpack_modules_list = array_intersect_key( |
| 372 | 395 | array_merge( $this->get_extra_features(), Jetpack_Admin::init()->get_modules() ), |
| @@ -417,8 +440,9 @@ | ||
| 417 | 440 | esc_html_x( 'Jetpack: %s', 'Jetpack: Module Name', 'jetpack' ), |
| 418 | 441 | $jetpack_modules_list[ $matching_module ]['name'] |
| 419 | 442 | ), |
| 420 | 443 | 'short_description' => $jetpack_modules_list[ $matching_module ]['short_description'], |
| 444 | + 'author' => esc_attr__( 'Jetpack (installed)', 'jetpack' ), | |
| 421 | 445 | 'requires_connection' => (bool) $jetpack_modules_list[ $matching_module ]['requires_connection'], |
| 422 | 446 | 'slug' => self::$slug, |
| 423 | 447 | 'version' => JETPACK__VERSION, |
| 424 | 448 | 'icons' => array( |
| @@ -514,14 +538,11 @@ | ||
| 514 | 538 | case 'publicize': |
| 515 | 539 | $configure_url = Redirect::get_url( 'calypso-marketing-connections' ); |
| 516 | 540 | break; |
| 517 | 541 | case 'seo-tools': |
| 518 | - $configure_url = Redirect::get_url( | |
| 519 | - 'calypso-marketing-traffic', | |
| 520 | - array( | |
| 521 | - 'anchor' => 'seo', | |
| 522 | - ) | |
| 523 | - ); | |
| 542 | + // Jetpack SEO has its own wp-admin page (the new SEO home base); | |
| 543 | + // send users there rather than the legacy Traffic page. | |
| 544 | + $configure_url = admin_url( 'admin.php?page=jetpack-seo' ); | |
| 524 | 545 | break; |
| 525 | 546 | case 'google-analytics': |
| 526 | 547 | $configure_url = Redirect::get_url( |
| 527 | 548 | 'calypso-marketing-traffic', |
| @@ -556,9 +577,9 @@ | ||
| 556 | 577 | if ( 'sharing-block' === $plugin['module'] ) { |
| 557 | 578 | $links['jp_get_started'] = '<a |
| 558 | 579 | id="plugin-select-settings" |
| 559 | 580 | class="jetpack-plugin-search__primary jetpack-plugin-search__get-started button" |
| 560 | - href="' . esc_url( admin_url( 'site-editor.php?path=%2Fwp_template' ) ) . '" | |
| 581 | + href="' . esc_url( $this->get_sharing_block_editor_url() ) . '" | |
| 561 | 582 | data-module="' . esc_attr( $plugin['module'] ) . '" |
| 562 | 583 | data-track="get_started" |
| 563 | 584 | >' . esc_html__( 'Add block', 'jetpack' ) . '</a>'; |
| 564 | 585 | } elseif ( 'akismet' === $plugin['module'] || 'vaultpress' === $plugin['module'] ) { |
| @@ -565,8 +586,9 @@ | ||
| 565 | 586 | $links['jp_get_started'] = '<a |
| 566 | 587 | id="plugin-select-settings" |
| 567 | 588 | class="jetpack-plugin-search__primary jetpack-plugin-search__get-started button" |
| 568 | 589 | href="' . esc_url( Redirect::get_url( 'plugin-hint-learn-' . $plugin['module'] ) ) . '" |
| 590 | + target="_blank" | |
| 569 | 591 | data-module="' . esc_attr( $plugin['module'] ) . '" |
| 570 | 592 | data-track="get_started" |
| 571 | 593 | >' . esc_html__( 'Get started', 'jetpack' ) . '</a>'; |
| 572 | 594 | // Jetpack installed, active, feature not enabled; prompt to enable. |
| @@ -597,13 +619,26 @@ | ||
| 597 | 619 | data-module="' . esc_attr( $plugin['module'] ) . '" |
| 598 | 620 | data-track="configure" |
| 599 | 621 | >' . esc_html__( 'Configure', 'jetpack' ) . '</a>'; |
| 600 | 622 | // Module is active, doesn't have options to configure. |
| 623 | + } elseif ( 'seo-tools' === $plugin['module'] && Jetpack::is_module_active( $plugin['module'] ) ) { | |
| 624 | + // Jetpack SEO has its own wp-admin page; send users there (same tab) | |
| 625 | + // rather than a jetpack.com doc redirect, which isn't registered for | |
| 626 | + // this module. Reuse get_configure_url() so the destination stays in | |
| 627 | + // one place. | |
| 628 | + $links['jp_get_started'] = '<a | |
| 629 | + id="plugin-select-settings" | |
| 630 | + class="jetpack-plugin-search__primary jetpack-plugin-search__get-started button" | |
| 631 | + href="' . esc_url( $this->get_configure_url( $plugin['module'], $plugin['configure_url'] ) ) . '" | |
| 632 | + data-module="' . esc_attr( $plugin['module'] ) . '" | |
| 633 | + data-track="get_started" | |
| 634 | + >' . esc_html__( 'Get started', 'jetpack' ) . '</a>'; | |
| 601 | 635 | } elseif ( Jetpack::is_module_active( $plugin['module'] ) ) { |
| 602 | 636 | $links['jp_get_started'] = '<a |
| 603 | 637 | id="plugin-select-settings" |
| 604 | 638 | class="jetpack-plugin-search__primary jetpack-plugin-search__get-started button" |
| 605 | 639 | href="' . esc_url( Redirect::get_url( 'plugin-hint-learn-' . $plugin['module'] ) ) . '" |
| 640 | + target="_blank" | |
| 606 | 641 | data-module="' . esc_attr( $plugin['module'] ) . '" |
| 607 | 642 | data-track="get_started" |
| 608 | 643 | >' . esc_html__( 'Get started', 'jetpack' ) . '</a>'; |
| 609 | 644 | } |