Changeset 3481598
- Timestamp:
- 03/13/2026 12:37:50 AM (3 weeks ago)
- Location:
- dropinblog/trunk
- Files:
-
- 4 edited
-
classes/api.php (modified) (2 diffs)
-
classes/rendering.php (modified) (5 diffs)
-
dropinblog.php (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dropinblog/trunk/classes/api.php
r3426487 r3481598 55 55 public function get_rendered_head(){ 56 56 if( $this->is_api_error ){ 57 return ''; 57 return ''; 58 58 } 59 59 if( !$this->response_body->success ){ … … 61 61 } 62 62 return $this->response_body->data->head_html; 63 } 64 65 public function get_head_data() { 66 if ( $this->is_api_error ) { 67 return null; 68 } 69 if ( ! $this->response_body->success ) { 70 return null; 71 } 72 return $this->response_body->data->head_data; 63 73 } 64 74 -
dropinblog/trunk/classes/rendering.php
r3481565 r3481598 11 11 var $current_url_parts; 12 12 var $is_full_type = false; 13 private array $async_handles = []; 13 14 14 15 function __construct() … … 62 63 add_action('wp', [$this, 'cleanup']); 63 64 add_filter('wp_head', [$this, 'render_head'], 1000); 65 add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts']); 66 add_filter('script_loader_tag', [$this, 'add_async_attribute'], 10, 2); 64 67 add_filter('the_content', [$this, 'render_content']); 65 68 add_filter('template_redirect', [$this, 'render_redirect']); … … 94 97 $html = (string) $this->api_content->get_rendered_head(); 95 98 99 // Strip external script tags (they're enqueued via wp_enqueue_script now). 100 // Keep inline scripts (JSON-LD schema, etc.) in the output. 101 $html = preg_replace( '#<script\b[^>]*\bsrc\b[^>]*>.*?</script>#is', '', $html ); 102 96 103 $allowed['title'] = []; 97 $allowed['link'] = ['rel' => true, 'href' => true, 'type' => true];98 $allowed['meta'] = ['charset' => true, 'name' => true, 'content' => true, 'property' => true];99 $allowed['script'] = ['type' => true , 'async' => true, 'src' => true, 'data-jetpack-boost' => true, 'defer' => true];104 $allowed['link'] = ['rel' => true, 'href' => true, 'type' => true]; 105 $allowed['meta'] = ['charset' => true, 'name' => true, 'content' => true, 'property' => true]; 106 $allowed['script'] = ['type' => true]; 100 107 $allowed['style'] = ['id' => true]; 101 108 $allowed_protocols = wp_allowed_protocols(); … … 255 262 switch ($path) { 256 263 case "main": 257 $this->api_content = new DropInBlog_Api( "/blog/{$this->blog_id}/rendered/list");264 $this->api_content = new DropInBlog_Api($this->api_endpoint("/blog/{$this->blog_id}/rendered/list")); 258 265 break; 259 266 case "main_pagination": 260 $this->api_content = new DropInBlog_Api( "/blog/{$this->blog_id}/rendered/list?page={$this->current_url_parts[1]}");267 $this->api_content = new DropInBlog_Api($this->api_endpoint("/blog/{$this->blog_id}/rendered/list?page={$this->current_url_parts[1]}")); 261 268 break; 262 269 case "single_post": 263 $this->api_content = new DropInBlog_Api( "/blog/{$this->blog_id}/rendered/post/{$this->current_url_parts[0]}");270 $this->api_content = new DropInBlog_Api($this->api_endpoint("/blog/{$this->blog_id}/rendered/post/{$this->current_url_parts[0]}")); 264 271 break; 265 272 case "category": 266 $this->api_content = new DropInBlog_Api( "/blog/{$this->blog_id}/rendered/list/category/{$this->current_url_parts[1]}");273 $this->api_content = new DropInBlog_Api($this->api_endpoint("/blog/{$this->blog_id}/rendered/list/category/{$this->current_url_parts[1]}")); 267 274 break; 268 275 case "category_pagination": 269 $this->api_content = new DropInBlog_Api( "/blog/{$this->blog_id}/rendered/list/category/{$this->current_url_parts[1]}?page={$this->current_url_parts[3]}");276 $this->api_content = new DropInBlog_Api($this->api_endpoint("/blog/{$this->blog_id}/rendered/list/category/{$this->current_url_parts[1]}?page={$this->current_url_parts[3]}")); 270 277 break; 271 278 case "author": 272 $this->api_content = new DropInBlog_Api( "/blog/{$this->blog_id}/rendered/list/author/{$this->current_url_parts[1]}");279 $this->api_content = new DropInBlog_Api($this->api_endpoint("/blog/{$this->blog_id}/rendered/list/author/{$this->current_url_parts[1]}")); 273 280 break; 274 281 case "author_pagination": 275 $this->api_content = new DropInBlog_Api( "/blog/{$this->blog_id}/rendered/list/author/{$this->current_url_parts[1]}?page={$this->current_url_parts[3]}");282 $this->api_content = new DropInBlog_Api($this->api_endpoint("/blog/{$this->blog_id}/rendered/list/author/{$this->current_url_parts[1]}?page={$this->current_url_parts[3]}")); 276 283 break; 277 284 case "feed": … … 299 306 } 300 307 308 private function api_endpoint( string $path ): string { 309 $fields = 'fields=head_html,body_html,head_data'; 310 $separator = str_contains( $path, '?' ) ? '&' : '?'; 311 return $path . $separator . $fields; 312 } 313 314 public function enqueue_scripts() { 315 if ( ! $this->api_content ) { 316 return; 317 } 318 319 $head_data = $this->api_content->get_head_data(); 320 321 $index = 0; 322 323 if ( ! empty( $head_data->js ) ) { 324 $this->enqueue_head_item_scripts( $head_data->js, 'dib-js', $index ); 325 } 326 327 if ( ! empty( $head_data->js_search ) ) { 328 $this->enqueue_head_item_scripts( $head_data->js_search, 'dib-js-search', $index ); 329 } 330 } 331 332 private function enqueue_head_item_scripts( $items, string $prefix, int &$index ): void { 333 if ( ! is_array( $items ) ) { 334 $items = [ $items ]; 335 } 336 337 foreach ( $items as $item ) { 338 $handle = $prefix . '-' . $index; 339 $index++; 340 341 $src = is_string( $item ) ? $item : ( $item->src ?? '' ); 342 $async = is_object( $item ) && ! empty( $item->async ); 343 344 if ( empty( $src ) ) { 345 continue; 346 } 347 348 wp_enqueue_script( $handle, $src, [], null, false ); 349 350 if ( $async ) { 351 $this->async_handles[] = $handle; 352 } 353 } 354 } 355 356 public function add_async_attribute( string $tag, string $handle ): string { 357 if ( in_array( $handle, $this->async_handles, true ) ) { 358 return str_replace( ' src=', ' async src=', $tag ); 359 } 360 return $tag; 361 } 362 301 363 public function get_url_subsegments($base_slug = '') 302 364 { -
dropinblog/trunk/dropinblog.php
r3481565 r3481598 4 4 Plugin URI: https://dropinblog.com 5 5 Description: Embed and display your DropInBlog seamlessly within WordPress with full SEO support. 6 Version: 1.0. 26 Version: 1.0.3 7 7 License: GPL v2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
dropinblog/trunk/readme.txt
r3481565 r3481598 4 4 Tested up to: 6.9 5 5 Requires at least PHP: 8.0 6 Stable tag: 1.0. 26 Stable tag: 1.0.3 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 43 43 == Changelog == 44 44 45 = 1.0.3 = 46 * Enqueue external scripts via wp_enqueue_script for better compatibility with caching and optimization plugins 47 45 48 = 1.0.2 = 46 49 * Fixed conflict with Jetpack … … 53 56 54 57 == Upgrade Notice == 58 59 = 1.0.3 = 60 Improved compatibility with caching and optimization plugins. 55 61 56 62 = 1.0.2 =
Note: See TracChangeset
for help on using the changeset viewer.