blocks
2 days ago
build
2 days ago
content-guidelines-ai
2 days ago
fonts
1 year ago
genericons
4 months ago
lib
2 days ago
accessible-focus.js
5 years ago
blogging-prompts.php
1 week ago
class.jetpack-provision.php
7 months ago
content-guidelines-ai.js
1 week ago
content-guidelines-ai.php
1 week ago
crowdsignal-shortcode.js
1 year ago
crowdsignal-survey.js
5 years ago
deprecate.js
7 months ago
facebook-embed.js
4 years ago
gallery-settings.js
5 years ago
genericons.php
1 year ago
jetpack-admin.js
3 years ago
jetpack-deactivate-dialog.js
1 year ago
jetpack-modules.js
1 year ago
jetpack-modules.models.js
7 months ago
jetpack-modules.views.js
7 months ago
polldaddy-shortcode.js
3 months ago
site-switcher-endpoint.php
5 months ago
site-switcher.js
5 months ago
site-switcher.php
5 months ago
social-logos.php
3 months ago
twitter-timeline.js
1 month ago
content-guidelines-ai.php
103 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Content Guidelines AI — Jetpack AI integration. |
| 4 | * |
| 5 | * Enqueues a standalone JS bundle on the Content Guidelines admin page |
| 6 | * that adds AI-powered guideline generation via Jetpack. |
| 7 | * |
| 8 | * @package automattic/jetpack |
| 9 | */ |
| 10 | |
| 11 | use Automattic\Jetpack\Assets; |
| 12 | use Automattic\Jetpack\Status\Visitor; |
| 13 | use Automattic\Jetpack\Tracking; |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit( 0 ); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Check if the current user is an Automattician. |
| 21 | * |
| 22 | * - Simple sites: wpcom_is_proxied_request() + is_automattician() |
| 23 | * - Atomic sites: Visitor::is_automattician_feature_flags_only() |
| 24 | * |
| 25 | * @return bool |
| 26 | */ |
| 27 | function jetpack_content_guidelines_ai_is_automattician() { |
| 28 | // Simple sites. |
| 29 | if ( function_exists( 'wpcom_is_proxied_request' ) |
| 30 | && wpcom_is_proxied_request() |
| 31 | && function_exists( 'is_automattician' ) |
| 32 | && is_automattician() |
| 33 | ) { |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | // Atomic sites. |
| 38 | return ( new Visitor() )->is_automattician_feature_flags_only(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Enqueue content-guidelines-ai script on the Content Guidelines admin page. |
| 43 | * |
| 44 | * @since 16.0 |
| 45 | * |
| 46 | * @param string $hook_suffix The current admin page hook suffix. |
| 47 | */ |
| 48 | function jetpack_content_guidelines_ai_enqueue_scripts( $hook_suffix ) { |
| 49 | if ( 'settings_page_guidelines-wp-admin' !== $hook_suffix ) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | // Temporarily gate to Automatticians only during internal rollout. |
| 54 | if ( ! jetpack_content_guidelines_ai_is_automattician() ) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | // Bail when build artifacts are missing rather than enqueueing a script |
| 59 | // with guessed (and likely wrong) dependencies. |
| 60 | if ( ! file_exists( JETPACK__PLUGIN_DIR . '_inc/build/content-guidelines-ai.min.asset.php' ) ) { |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | // The bundle records Tracks events via @automattic/jetpack-analytics, |
| 65 | // which only queues into window._tkq. Enqueue the Tracks client (w.js) |
| 66 | // so events send without relying on whichever platform widgets happen |
| 67 | // to load it. |
| 68 | Tracking::register_tracks_functions_scripts( true ); |
| 69 | |
| 70 | // Handles dependencies/version from the asset file, JS translations for |
| 71 | // the text domain, the CSS (including the .rtl.css variant), and style |
| 72 | // dependencies derived from the script's. |
| 73 | Assets::register_script( |
| 74 | 'jetpack-content-guidelines-ai', |
| 75 | '_inc/build/content-guidelines-ai.min.js', |
| 76 | JETPACK__PLUGIN_FILE, |
| 77 | array( |
| 78 | 'in_footer' => true, |
| 79 | 'textdomain' => 'jetpack', |
| 80 | 'css_path' => '_inc/build/content-guidelines-ai.css', |
| 81 | 'enqueue' => true, |
| 82 | ) |
| 83 | ); |
| 84 | |
| 85 | // Preload the per-user "banner dismissed" flag so the empty-state banner |
| 86 | // doesn't flash before an async read. Persisted via the |
| 87 | // guidelines-banner-dismissed REST endpoint. Defaults to dismissed so a |
| 88 | // load error hides the banner rather than showing it on every visit. |
| 89 | $banner_dismissed = class_exists( 'WPCOM_REST_API_V2_Endpoint_Guidelines_Banner_Dismissed' ) |
| 90 | ? WPCOM_REST_API_V2_Endpoint_Guidelines_Banner_Dismissed::is_dismissed() |
| 91 | : true; |
| 92 | wp_add_inline_script( |
| 93 | 'jetpack-content-guidelines-ai', |
| 94 | 'window.jetpackContentGuidelinesAi = ' . wp_json_encode( |
| 95 | array( 'bannerDismissed' => $banner_dismissed ), |
| 96 | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT |
| 97 | ) . ';', |
| 98 | 'before' |
| 99 | ); |
| 100 | } |
| 101 | |
| 102 | add_action( 'admin_enqueue_scripts', 'jetpack_content_guidelines_ai_enqueue_scripts' ); |
| 103 |