| @@ -258,8 +258,12 @@ | ||
| 258 | 258 | public function enqueue_scripts() { |
| 259 | 259 | if ( is_singular( 'docs' ) ) { |
| 260 | 260 | wp_enqueue_style( 'betterdocs-single' ); |
| 261 | 261 | wp_enqueue_style( 'betterdocs-article-summary' ); |
| 262 | + wp_enqueue_style( 'betterdocs-ai-actions' ); | |
| 263 | + if ( betterdocs()->listen->is_enabled() ) { | |
| 264 | + wp_enqueue_style( 'betterdocs-listen' ); | |
| 265 | + } | |
| 262 | 266 | wp_enqueue_style( 'betterdocs-encyclopedia' ); |
| 263 | 267 | wp_enqueue_style( 'betterdocs-glossaries' ); |
| 264 | 268 | wp_enqueue_script( 'clipboard' ); |
| 265 | 269 | wp_enqueue_script( 'betterdocs-glossaries' ); |
| @@ -264,8 +268,14 @@ | ||
| 264 | 268 | wp_enqueue_script( 'clipboard' ); |
| 265 | 269 | wp_enqueue_script( 'betterdocs-glossaries' ); |
| 266 | 270 | } |
| 267 | 271 | |
| 272 | + // The shortcode / block / widget can place AI Actions and Listen on any page. | |
| 273 | + // Their own dependency lists run during the_content, i.e. after wp_head has | |
| 274 | + // already printed, which would leave the controls unstyled until the footer | |
| 275 | + // stylesheet parsed — so catch those placements here instead. | |
| 276 | + $this->maybe_enqueue_meta_row(); | |
| 277 | + | |
| 268 | 278 | if ( is_post_type_archive( 'docs' ) ) { |
| 269 | 279 | wp_enqueue_style( 'betterdocs-category-grid' ); //category grid shortcode is supposed to enqueue this style, but this is called again to fix flicking of UI on Docs Page |
| 270 | 280 | wp_enqueue_style( 'betterdocs-docs' ); |
| 271 | 281 | } |
| @@ -290,8 +300,46 @@ | ||
| 290 | 300 | wp_enqueue_style( 'betterdocs-glossaries' ); |
| 291 | 301 | } |
| 292 | 302 | } |
| 293 | 303 | |
| 304 | + /** | |
| 305 | + * Enqueue the meta-row assets in wp_head when the current post embeds one of | |
| 306 | + * the shortcodes or the block, so an off-doc placement is styled on first | |
| 307 | + * paint. | |
| 308 | + * | |
| 309 | + * @since 4.8.0 | |
| 310 | + * @since 4.9.2 Listen added, and renamed from maybe_enqueue_ai_actions(). | |
| 311 | + */ | |
| 312 | + protected function maybe_enqueue_meta_row() { | |
| 313 | + if ( is_singular( 'docs' ) ) { | |
| 314 | + return; | |
| 315 | + } | |
| 316 | + | |
| 317 | + $post = get_post(); | |
| 318 | + if ( ! $post instanceof \WP_Post ) { | |
| 319 | + return; | |
| 320 | + } | |
| 321 | + | |
| 322 | + // `betterdocs/reading-time` is the merged meta-row block: it carries the AI | |
| 323 | + // Actions button and the Listen pill, and the `.betterdocs-doc-meta` wrapper | |
| 324 | + // lives in both stylesheets, so it needs a handle whichever third of it is | |
| 325 | + // switched on. Which is also why the block counts for both features here. | |
| 326 | + $block = has_block( 'betterdocs/reading-time', $post ); | |
| 327 | + | |
| 328 | + if ( betterdocs()->ai_actions->is_enabled() | |
| 329 | + && ( $block || has_shortcode( $post->post_content, 'betterdocs_ai_actions' ) ) ) { | |
| 330 | + wp_enqueue_style( 'betterdocs-ai-actions' ); | |
| 331 | + wp_enqueue_script( 'clipboard' ); | |
| 332 | + wp_enqueue_script( 'betterdocs' ); | |
| 333 | + } | |
| 334 | + | |
| 335 | + if ( betterdocs()->listen->is_enabled() | |
| 336 | + && ( $block || has_shortcode( $post->post_content, 'betterdocs_listen' ) ) ) { | |
| 337 | + wp_enqueue_style( 'betterdocs-listen' ); | |
| 338 | + wp_enqueue_script( 'betterdocs' ); | |
| 339 | + } | |
| 340 | + } | |
| 341 | + | |
| 294 | 342 | public function layout_filename( $filename, $origin_layout ) { |
| 295 | 343 | $filename = ( $origin_layout === 'layout-2' ) ? 'default' : $filename; |
| 296 | 344 | return $filename; |
| 297 | 345 | } |
| @@ -322,8 +370,9 @@ | ||
| 322 | 370 | 'betterdocs-reactions', |
| 323 | 371 | 'betterdocsReactionsConfig', |
| 324 | 372 | [ |
| 325 | 373 | 'post_id' => get_the_ID(), |
| 374 | + 'nonce' => wp_create_nonce( 'wp_rest' ), | |
| 326 | 375 | 'FEEDBACK' => [ |
| 327 | 376 | 'DISPLAY' => true, |
| 328 | 377 | 'TEXT' => esc_html__( 'How did you feel?', 'betterdocs' ), |
| 329 | 378 | 'SUCCESS' => betterdocs()->settings->get( 'reaction_feedback_text', __( 'Thanks for your feedback', 'betterdocs' ) ), |