true ], 'objects' ); $excluded = [ 'attachment' ]; if ( class_exists( Template_Manager::class ) ) { $excluded[] = Template_Manager::TEMPLATES_POST_TYPE; } foreach ( $excluded as $post_type ) { unset( $objects[ $post_type ] ); } return apply_filters( 'nyxonn_fx_supported_post_types', $objects ); } /** Existing behavior is preserved by enabling every supported type by default. */ public static function get_enabled_post_types() { $supported = array_keys( self::get_supported_post_types() ); $saved = Prefix_Migration::get_option( self::OPTION_KEY, null ); if ( ! is_array( $saved ) || ! isset( $saved['post_types'] ) || ! is_array( $saved['post_types'] ) ) { return $supported; } $selected = array_map( 'sanitize_key', $saved['post_types'] ); return array_values( array_intersect( $supported, $selected ) ); } public static function is_post_type_enabled( $post_type ) { return in_array( sanitize_key( $post_type ), self::get_enabled_post_types(), true ); } public static function sanitize_import_settings( $settings ) { $submitted = is_array( $settings ) && isset( $settings['post_types'] ) && is_array( $settings['post_types'] ) ? array_map( 'sanitize_key', $settings['post_types'] ) : []; return [ 'post_types' => array_values( array_intersect( array_keys( self::get_supported_post_types() ), $submitted ) ) ]; } /** Internal templates remain editable independently of public post-type settings. */ public static function can_edit_post( $post ) { if ( ! $post instanceof \WP_Post ) { return false; } if ( class_exists( Template_Manager::class ) && Template_Manager::TEMPLATES_POST_TYPE === $post->post_type ) { return true; } return self::is_post_type_enabled( $post->post_type ); } /** * Whether an existing post may be opened in the builder. * * Post-type settings gate new activation only. Once Nyxonn Builder owns a post, * disabling that post type must not strand its saved layout. */ public static function can_open_builder( $post ) { if ( ! $post instanceof \WP_Post ) { return false; } if ( class_exists( Template_Manager::class ) && Template_Manager::TEMPLATES_POST_TYPE === $post->post_type ) { return true; } if ( '1' === get_post_meta( $post->ID, Save::ENABLED_META, true ) ) { return true; } return self::is_post_type_enabled( $post->post_type ); } public static function handle_save() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have permission to update these settings.', 'nyxonn-builder' ), '', [ 'response' => 403 ] ); } check_admin_referer( 'nyxonn_builder_save_builder_settings' ); $supported = array_keys( self::get_supported_post_types() ); $submitted = isset( $_POST['post_types'] ) && is_array( $_POST['post_types'] ) ? array_map( 'sanitize_key', wp_unslash( $_POST['post_types'] ) ) : []; $post_types = array_values( array_intersect( $supported, $submitted ) ); update_option( self::OPTION_KEY, [ 'post_types' => $post_types ] ); $notice = 'saved'; if ( isset( $_POST['container_max_width'] ) ) { $result = Global_Settings::update_container_max_width( wp_unslash( $_POST['container_max_width'] ) ); if ( is_wp_error( $result ) ) { $notice = 'invalid_width'; } } wp_safe_redirect( add_query_arg( 'nyxonn_builder_notice', $notice, admin_url( 'admin.php?page=nyxonn_builder_settings' ) ) ); exit; } }