<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
<?php
/**
 * The Class.
 */
class Beruco_Meta_Box {

    private static $_instance = null;
 
    /**
     * Hook into the appropriate actions when the class is constructed.
     */
    public function __construct() {
        add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
        add_action( 'save_post',      array( $this, 'save'         ) );

        add_action( 'admin_enqueue_scripts', array( $this, 'beruco_post_options_admin_scripts' ) );
    }

    public function beruco_post_options_admin_scripts(){
        wp_register_style( 'beruco-theme-options', BERUCO_ADDON_URL . 'admin/extension/theme-options/assets/css/theme-options.css', array(), '1.0', 'all' );			
        wp_register_style( 'beruco_theme_options_css', BERUCO_ADDON_URL . 'admin/extension/theme-options/assets/css/theme-options.css' );
        wp_register_script( 'wp-color-picker-alpha', BERUCO_ADDON_URL . 'admin/extension/theme-options/assets/js/wp-color-picker-alpha.min.js', array( 'jquery', 'wp-color-picker' ), '3.0.0' );
        wp_register_script( 'beruco_theme_options_js', BERUCO_ADDON_URL . 'admin/extension/theme-options/assets/js/theme-options.js' );
    }
 
    /**
     * Adds the meta box container.
     */
    public function add_meta_box( $post_type ) {
        // Limit meta box to certain post types.
        $post_types = array( 'post', 'page' );
 
        if ( in_array( $post_type, $post_types ) ) {
            add_meta_box(
                'beruco_metabox',
                esc_html__( 'Beruco Options', 'textdomain' ),
                array( $this, 'render_meta_box_content' ),
                $post_type,
                'advanced',
                'high'
            );
        }
    }
 
    /**
     * Save the meta when the post is saved.
     *
     * @param int $post_id The ID of the post being saved.
     */
    public function save( $post_id ) {
 
        /*
         * We need to verify this came from the our screen and with proper authorization,
         * because save_post can be triggered at other times.
         */
 
        // Check if our nonce is set.
        if ( ! isset( $_POST['beruco_metabox_security'] ) ) {
            return $post_id;
        }
 
        $nonce = $_POST['beruco_metabox_security'];
 
        // Verify that the nonce is valid.
        if ( ! wp_verify_nonce( $nonce, 'beruco_metabox_nonce_*&%$' ) ) {
            return $post_id;
        }
 
        /*
         * If this is an autosave, our form has not been submitted,
         * so we don't want to do anything.
         */
        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
            return $post_id;
        }
 
        // Check the user's permissions.
        //if ( 'page' == $_POST['post_type'] ) {
            if ( ! current_user_can( 'edit_page', $post_id ) ) {
                return $post_id;
            }
 
        /* OK, it's safe for us to save the data now. */
 
        // Sanitize the user input.
        $post_data = $_POST['beruco_options']? $_POST['beruco_options'] : '';
 
        // Update the meta field.
        update_post_meta( $post_id, 'beruco_post_meta', $post_data );
    }
 
 
    /**
     * Render Meta Box content.
     *
     * @param WP_Post $post The post object.
     */
    public function render_meta_box_content( $post ) {

        wp_enqueue_style( 'beruco-theme-options' );
        wp_enqueue_media();
        wp_enqueue_style( 'beruco_theme_options_css' );
        wp_enqueue_style( 'wp-color-picker' );
        wp_enqueue_script( 'wp-color-picker-alpha' );
        wp_enqueue_script( 'beruco_theme_options_js' );
 
        // Add an nonce field so we can check for it later.
        wp_nonce_field( 'beruco_metabox_nonce_*&%$', 'beruco_metabox_security' );
        
        /*
        // Use get_post_meta to retrieve an existing value from the database.
        $value = get_post_meta( $post->ID, 'beruco_post_meta_value', true );
 
        // Display the form, using the current value.
        ?>
        <label for="myplugin_new_field">
            <?php _e( 'Description for this field', 'textdomain' ); ?>
        </label>
        <input type="text" id="myplugin_new_field" name="beruco_post_meta_value" value="<?php echo esc_attr( $value ); ?>" size="25" />
        <?php
        */

        if( !class_exists( 'Beruco_Options' ) ) require_once( BERUCO_ADDON_DIR . 'admin/extension/theme-options/framework.php' );
        require_once( BERUCO_ADDON_DIR . 'admin/extension/metabox/meta-config.php' );

        ?>
        <div class="beruco-settings-wrap">
        <div class="beruco-inner-wrap">
        <div class="beruco-admin-content-wrap">
                <?php wp_nonce_field( 'beruco_theme_options*&^&*$', 'save_beruco_theme_options' ); ?>
                <div class="beruco-tab">
                    <div class="beruco-tab-list">
                        <ul class="tablinks-list">
                            <?php Beruco_Options::beruco_put_section(); ?>
                        </ul>
                    </div><!-- .beruco-tab-list -->
                    
                    <?php Beruco_Options::beruco_put_field(); ?>
                    
                </div><!-- .beruco-tab -->							
        </div><!-- .beruco-admin-content-wrap -->
        </div>
        </div>
    <?php
    }

    public static function get_instance() {
		if ( is_null( self::$_instance ) ) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}

}
Beruco_Meta_Box::get_instance();