ID ) ) { return $use_block_editor; } if ( $post && $this->is_template_post( $post ) ) { return false; } if ( $post && $this->is_nyxonn_builder_enabled( $post->ID ) ) { return false; } return $use_block_editor; } public function render_nx_screen( $post ) { if ( ! $post ) { return; } if ( ! class_exists( '\NyxonnBuilder\Role_Manager' ) || ! \NyxonnBuilder\Role_Manager::can_use_builder( $post->ID ) ) { return; } if ( $this->is_template_post( $post ) ) { $edit_url = admin_url( 'admin.php?page=nyxonn-builder-editor&post_id=' . $post->ID ); echo '
'; echo '

Nyxonn Builder Template Builder

'; echo '

Edit this template in Nyxonn Builder.

'; echo '

Edit with Nyxonn Builder

'; echo '
'; return; } $builder_available = class_exists( '\NyxonnBuilder\Builder_Settings' ) && \NyxonnBuilder\Builder_Settings::is_post_type_enabled( $post->post_type ); $is_enabled = '1' === \NyxonnBuilder\Prefix_Migration::get_post_meta( $post->ID, self::META_KEY, true ); if ( ! $builder_available ) { if ( $is_enabled ) { echo '
'; echo '

' . esc_html__( 'This page is built with Nyxonn Builder.', 'nyxonn-builder' ) . '

'; echo '

' . esc_html__( 'Nyxonn Builder is disabled for new content of this post type, but this existing layout can still be edited.', 'nyxonn-builder' ) . '

'; echo '

' . esc_html__( 'Edit with Nyxonn Builder', 'nyxonn-builder' ) . '

'; echo '
'; } return; } $edit_url = $this->get_nyxonn_builder_enable_url( $post->ID ); if ( $is_enabled ) { $edit_url = admin_url( 'admin.php?page=nyxonn-builder-editor&post_id=' . $post->ID ); } echo '
'; if ( $is_enabled ) { echo '

Nyxonn Builder Enabled

'; echo '

This page is built with Nyxonn Builder. Default editor is disabled.

'; } else { echo '

Use Nyxonn Builder

'; echo '

Open this page in Nyxonn Builder to edit layout.

'; } echo '

Edit with Nyxonn Builder

'; echo '
'; } public function enqueue_editor_screen_assets( $hook ) { if ( ! in_array( $hook, [ 'post.php', 'post-new.php' ], true ) ) { return; } $post = $this->get_current_post(); if ( ! $post ) { return; } if ( ! class_exists( '\NyxonnBuilder\Role_Manager' ) || ! \NyxonnBuilder\Role_Manager::can_use_builder( $post->ID ) ) { return; } if ( ! $this->is_nyxonn_builder_enabled( $post->ID ) && ! $this->is_template_post( $post ) ) { return; } wp_enqueue_style( 'nx-editor-screen', NYXONN_BUILDER_ASSETS_URL . 'css/editor-screen.css', [], filemtime( NYXONN_BUILDER_PLUGIN_DIR . 'assets/css/editor-screen.css' ) ); } public function handle_disable_request() { if ( ! isset( $_GET['nyxonn_builder_disable'], $_GET['post_id'], $_GET['_wpnonce'] ) ) { return; } $post_id = isset( $_GET['post_id'] ) ? intval( wp_unslash( $_GET['post_id'] ) ) : 0; $nonce = isset( $_GET['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) : ''; if ( ! $post_id || ! current_user_can( 'edit_post', $post_id ) ) { return; } if ( ! wp_verify_nonce( $nonce, 'nyxonn_builder_disable_' . $post_id ) ) { return; } delete_post_meta( $post_id, self::META_KEY ); wp_safe_redirect( admin_url( 'post.php?post=' . $post_id . '&action=edit' ) ); exit; } public function handle_enable_request() { if ( ! isset( $_GET['nyxonn_builder_enable'], $_GET['post_id'], $_GET['_wpnonce'] ) ) { return; } $post_id = intval( wp_unslash( $_GET['post_id'] ) ); if ( ! $post_id || ! class_exists( '\NyxonnBuilder\Role_Manager' ) || ! \NyxonnBuilder\Role_Manager::can_use_builder( $post_id ) ) { return; } if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'nyxonn_builder_enable' ) ) { return; } $post = get_post( $post_id ); if ( ! $post || ! class_exists( '\NyxonnBuilder\Builder_Settings' ) || ! \NyxonnBuilder\Builder_Settings::can_edit_post( $post ) ) { wp_safe_redirect( admin_url( 'post.php?post=' . $post_id . '&action=edit&nyxonn_builder_editor_unavailable=1' ) ); exit; } update_post_meta( $post_id, self::META_KEY, '1' ); wp_safe_redirect( admin_url( 'admin.php?page=nyxonn-builder-editor&post_id=' . $post_id ) ); exit; } public function nyxonn_builder_notice() { $post = $this->get_current_post(); if ( ! $post || ! $this->is_nyxonn_builder_enabled( $post->ID ) ) { return; } echo '

This page is built with Nyxonn Builder. Default editor is disabled.

'; } public function add_nx_column( $columns ) { $columns['nyxonn_builder_enabled'] = 'Nyxonn Builder Enabled'; return $columns; } public function render_nx_column( $column, $post_id ) { if ( 'nyxonn_builder_enabled' !== $column ) { return; } echo $this->is_nyxonn_builder_enabled( $post_id ) ? '✅' : '—'; } private function is_nyxonn_builder_enabled( $post_id ) { return class_exists( '\NyxonnBuilder\Save' ) ? \NyxonnBuilder\Save::is_enabled( $post_id ) : \NyxonnBuilder\Prefix_Migration::get_post_meta( $post_id, self::META_KEY, true ) === '1'; } private function is_template_post( $post ) { if ( ! $post ) { return false; } if ( class_exists( '\NyxonnBuilder\Template_Manager' ) ) { return $post->post_type === \NyxonnBuilder\Template_Manager::TEMPLATES_POST_TYPE; } return false; } private function get_current_post() { global $post; if ( $post instanceof WP_Post ) { return $post; } if ( isset( $_GET['post'] ) ) { return get_post( intval( wp_unslash( $_GET['post'] ) ) ); } return null; } private function get_nyxonn_builder_enable_url( $post_id ) { return add_query_arg( [ 'page' => 'nyxonn-builder-editor', 'nyxonn_builder_enable' => 1, 'post_id' => $post_id, '_wpnonce' => wp_create_nonce( 'nyxonn_builder_enable' ), ], admin_url( 'admin.php' ) ); } } new Nyxonn_Builder_Init();