PluginProbe ʕ •ᴥ•ʔ
Smart Custom 404 Error Page / trunk
Smart Custom 404 Error Page vtrunk
trunk 11.4.6 11.4.7 11.4.8
404page / inc / class-404page-block-editor.php
404page / inc Last commit date
admin 1 year ago ppf 1 year ago class-404page-admin.php 1 year ago class-404page-block-editor.php 1 year ago class-404page-classic-editor.php 1 year ago class-404page-deprecated.php 1 year ago class-404page-settings.php 1 year ago class-404page.php 1 year ago index.php 9 years ago
class-404page-block-editor.php
102 lines
1 <?php
2
3 /**
4 * The 404page block editor plugin class
5 *
6 * @since 9
7 * partially rewritten in 11.4.0, because it stopped working
8 */
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly
12 }
13
14 /**
15 * The block editor plugin class
16 */
17 if ( !class_exists( 'PP_404Page_BlockEditor' ) ) {
18
19 class PP_404Page_BlockEditor extends PPF09_SubClass {
20
21 /**
22 * Do Init
23 *
24 * @since 9
25 * @access public
26 */
27 public function init() {
28
29 add_action( 'admin_head', array( $this, 'admin_style' ) );
30
31 }
32
33
34 /**
35 * Add Block Editor Style to Header if currently edited page is a custom 404 error page
36 *
37 * @since 9
38 * @access public
39 */
40 public function admin_style() {
41
42 if ( $this->is_gutenberg_editing() ) {
43
44 ?>
45 <style type="text/css">
46 .edit-post-layout__content:before { content: "<?php esc_html_e( 'You are currently editing your custom 404 error page', '404page'); ?>"; background-color: #333; color: #FFF; padding: 8px; font-size: 16px; display: block };
47 </style>
48 <?php /* since 11.4.0 */ ?>
49 <script type="text/javascript">
50 jQuery( document ).ready( function( $ ) {
51 var checkExist = setInterval( function() {
52 if ( $( '.edit-post-header-toolbar' ).length ) {
53 $( '.edit-post-header-toolbar' ).prepend( '<div style="margin-<?php echo ( is_rtl() ? 'right' : 'left' ); ?>: 24px; height: 32px; line-height: 32px; padding: 0 12px; background-color: #000; color: #fff">404</div>' );
54 clearInterval(checkExist);
55 }
56 }, 100);
57
58 } );
59 </script>
60 <?php
61
62 }
63
64 }
65
66
67 /**
68 * Is the 404 page edited in gutenberg editor?
69 *
70 * @since 9
71 * @access private
72 */
73 private function is_gutenberg_editing() {
74
75 // Is the current screen the page edit screen and is a custom 404 error page defined?
76 if ( get_current_screen()->id == 'page' && $this->settings()->get( 'page_id' ) > 0 ) {
77
78 // Is the block editor active for pages and is the classic editor not loaded?
79 if ( function_exists( 'use_block_editor_for_post_type' ) && use_block_editor_for_post_type( 'page' ) && ! isset( $_GET['classic-editor'] ) ) {
80
81 global $post;
82
83 $all404pages = $this->core()->get_all_page_ids();
84
85 // Is the currently edited page a custom 404 error page?
86 if ( in_array( $post->ID, $all404pages ) ) {
87
88 return true;
89
90 }
91
92 }
93
94 }
95
96 return false;
97
98 }
99
100 }
101
102 }