|
21 | 21 | */
|
22 | 22 | function plsr_is_speculative_loading_enabled(): bool {
|
23 | 23 | $option = plsr_get_stored_setting_value();
|
24 |
| - return ( |
25 |
| - ( |
26 |
| - ! is_user_logged_in() |
27 |
| - || |
28 |
| - 'any' === $option['authentication'] |
29 |
| - || |
30 |
| - ( current_user_can( 'manage_options' ) && 'logged_out_and_admins' === $option['authentication'] ) |
31 |
| - ) |
| 24 | + |
| 25 | + // Disabled if the user is logged in, unless the setting explicitly allows the current user's role. |
| 26 | + if ( |
| 27 | + ( is_user_logged_in() ) |
| 28 | + && |
| 29 | + 'any' !== $option['authentication'] |
32 | 30 | &&
|
33 |
| - ( |
34 |
| - (bool) get_option( 'permalink_structure' ) |
35 |
| - || |
36 |
| - /** |
37 |
| - * Filters whether speculative loading should be enabled even though the site does not use pretty permalinks. |
38 |
| - * |
39 |
| - * Since query parameters are commonly used by plugins for dynamic behavior that can change state, ideally any |
40 |
| - * such URLs are excluded from speculative loading. If the site does not use pretty permalinks though, they are |
41 |
| - * impossible to recognize. Therefore, speculative loading is disabled by default for those sites. |
42 |
| - * |
43 |
| - * For site owners of sites without pretty permalinks that are certain their site is not using such a pattern, |
44 |
| - * this filter can be used to still enable speculative loading at their own risk. |
45 |
| - * |
46 |
| - * @since 1.4.0 |
47 |
| - * |
48 |
| - * @param bool $enabled Whether speculative loading is enabled even without pretty permalinks. |
49 |
| - */ |
50 |
| - (bool) apply_filters( 'plsr_enabled_without_pretty_permalinks', false ) |
51 |
| - ) |
52 |
| - ); |
| 31 | + ( ! current_user_can( 'manage_options' ) || 'logged_out_and_admins' !== $option['authentication'] ) |
| 32 | + ) { |
| 33 | + return false; |
| 34 | + } |
| 35 | + |
| 36 | + // Disable if pretty permalinks are not enabled, unless explicitly overridden by the filter. |
| 37 | + if ( |
| 38 | + ! (bool) get_option( 'permalink_structure' ) |
| 39 | + && |
| 40 | + /** |
| 41 | + * Filters whether speculative loading should be enabled even though the site does not use pretty permalinks. |
| 42 | + * |
| 43 | + * Since query parameters are commonly used by plugins for dynamic behavior that can change state, ideally any |
| 44 | + * such URLs are excluded from speculative loading. If the site does not use pretty permalinks though, they are |
| 45 | + * impossible to recognize. Therefore, speculative loading is disabled by default for those sites. |
| 46 | + * |
| 47 | + * For site owners of sites without pretty permalinks that are certain their site is not using such a pattern, |
| 48 | + * this filter can be used to still enable speculative loading at their own risk. |
| 49 | + * |
| 50 | + * @since 1.4.0 |
| 51 | + * |
| 52 | + * @param bool $enabled Whether speculative loading is enabled even without pretty permalinks. |
| 53 | + */ |
| 54 | + ! apply_filters( 'plsr_enabled_without_pretty_permalinks', false ) |
| 55 | + ) { |
| 56 | + return false; |
| 57 | + } |
| 58 | + |
| 59 | + return true; |
53 | 60 | }
|
54 | 61 |
|
55 | 62 | // Conditionally use either the WordPress Core API, or load the plugin's API implementation otherwise.
|
|
0 commit comments