PluginProbe
Easy Hotel – Powerful Hotel Booking / 2.0.2
Easy Hotel – Powerful Hotel Booking v2.0.2
2.0.8 2.0.7 2.0.6 2.0.5 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.9.9 1.9.8 1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 All 110 releases
easy-hotel / admin / includes / compat-bogo.php

compat-bogo.php in Easy Hotel – Powerful Hotel Booking 2.0.2, at admin/includes/compat-bogo.php

91 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Bogo compatibility shim.
4 *
5 * Bogo's bogo_option_sticky_posts() (bogo/includes/query.php) hooks the
6 * `option_sticky_posts` filter and calls is_home() with no guard. The
7 * `option_sticky_posts` option is read whenever any query touches sticky
8 * posts, which can happen before the main query is set up (e.g. while the
9 * block editor is loading on post-new.php). Calling is_home() that early
10 * triggers WordPress's `_doing_it_wrong( 'is_home', ... )` notice.
11 *
12 * With WP_DEBUG_DISPLAY enabled that notice is echoed into the response
13 * before headers are sent ("headers already sent" / output started in
14 * functions.php). On the block editor that corrupts the editor bootstrap,
15 * so Gutenberg cannot load the freshly created accommodation auto-draft and
16 * shows: "You attempted to edit an item that doesn't exist. Perhaps it was
17 * deleted?"
18 *
19 * This replaces Bogo's callback with a version that only evaluates is_home()
20 * after the `wp` action has fired (i.e. once the main query exists), which is
21 * exactly when is_home() is reliable. Behaviour is otherwise unchanged.
22 *
23 * @package easy-hotel
24 */
25
26 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
27
28 add_action( 'plugins_loaded', 'eshb_fix_bogo_sticky_is_home', 1 );
29
30 function eshb_fix_bogo_sticky_is_home() {
31 if ( ! function_exists( 'bogo_option_sticky_posts' ) ) {
32 return; // Bogo not active – nothing to do.
33 }
34
35 remove_filter( 'option_sticky_posts', 'bogo_option_sticky_posts', 10 );
36
37 add_filter( 'option_sticky_posts', 'eshb_bogo_option_sticky_posts', 10, 1 );
38 }
39
40 function eshb_bogo_option_sticky_posts( $posts ) {
41 // Only let Bogo run its is_home()-based filtering once the main query is
42 // available; before that, is_home() is meaningless and noisy.
43 if ( did_action( 'wp' ) ) {
44 return bogo_option_sticky_posts( $posts );
45 }
46
47 return $posts;
48 }
49
50 /**
51 * Stop Bogo's block-editor script from breaking the editor for our CPTs.
52 *
53 * Bogo's `bogo-block-editor` script registers a GLOBAL apiFetch middleware that
54 * appends `lang=<slug>` to every block-editor REST request, with no check for
55 * whether the post type is localizable. For a non-localizable CPT such as
56 * eshb_accomodation, Gutenberg's post fetch then becomes
57 * /wp/v2/eshb_accomodation/<id>?context=edit&lang=<slug>
58 * When that slug is a bare language (e.g. "en", which Bogo emits when the
59 * locale is "alone"), the request triggers a _doing_it_wrong notice. With
60 * WP_DEBUG_DISPLAY on, that notice HTML is dumped into the REST response, so the
61 * JSON is no longer parseable. Gutenberg's getEntityRecord then resolves empty
62 * and renders: "You attempted to edit an item that doesn't exist."
63 *
64 * Bogo's own Language panel renders nothing for non-localizable post types, so
65 * the script has no purpose on these screens. Dequeue it there.
66 */
67 add_action( 'admin_enqueue_scripts', 'eshb_dequeue_bogo_block_editor', 999 );
68
69 function eshb_dequeue_bogo_block_editor( $hook_suffix ) {
70 if ( ! in_array( $hook_suffix, array( 'post.php', 'post-new.php' ), true ) ) {
71 return;
72 }
73
74 if ( ! function_exists( 'bogo_is_localizable_post_type' ) ) {
75 return; // Bogo not active.
76 }
77
78 $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
79
80 if ( ! $screen || empty( $screen->post_type ) ) {
81 return;
82 }
83
84 // Leave Bogo alone for post types it actually localizes (post, page, ...).
85 if ( bogo_is_localizable_post_type( $screen->post_type ) ) {
86 return;
87 }
88
89 wp_dequeue_script( 'bogo-block-editor' );
90 }
91