<commit_before><?php
/**
 * Created by PhpStorm.
 * User: sergiovilar
 * Date: 03/05/14
 * Time: 10:55 AM
 */

class RegisterMetabox {

    private $boxes = array();

    /**
     * Add a post type and his fields
     *
     * @param $post_type
     * @param $fields
     */
    public function add($post_type, $fields){

        $this->boxes[$post_type] = $fields;

    }

    public function register(){

        add_filter( 'rwmb_meta_boxes', array($this, 'doRegister') );

    }

    public function doRegister(){

        $meta_boxes = array();

        foreach($this->boxes as $post_type => $fields){

            $box = array(
                'id' => $post_type . '_metabox',
                'title' => 'fields',
                'pages' => array($post_type),
                'context' => 'normal',
                'priority' => 'high',
                'autosave' => true,

                // List of meta fields
                'fields' => array()
            );

            foreach($fields as $key => $content){

                if($key != 'title' && $key != 'editor' && $key != 'thumbnail'){

                    switch($content['type']){

                        case 'int':

                            array_push($box['fields'], array(
                                'name' => $content['label'],
                                'id'   => $key,
                                'type' => 'number',
                            ));

                            break;

                        case 'text':

                            array_push($box['fields'], array(
                                'name' => $content['label'],
                                'id'   => $key,
                                'type' => 'text',
                            ));

                            break;

                        case 'long_text':

                            array_push($box['fields'], array(
                                'name' => $content['label'],
                                'id'   => $key,
                                'type' => 'textarea',
                            ));

                            break;

                        case 'float':

                            array_push($box['fields'], array(
                                'name' => $content['label'],
                                'id'   => $key,
                                'type' => 'text',
                            ));

                            break;

                        case 'boolean':

                            array_push($box['fields'], array(
                                'name' => $content['label'],
                                'id'   => $key,
                                'type' => 'checkbox',
                            ));

                            break;

                        case 'file':

                            array_push($box['fields'], array(
                                'name' => $content['label'],
                                'id'   => $key,
                                'type' => 'file',
                            ));

                            break;

                        case 'image':

                            if(!$content['multiple']){

                                array_push($box['fields'], array(
                                    'name' => $content['label'],
                                    'id'   => $key,
                                    'type' => 'image',
                                ));

                            }else{

                                array_push($box['fields'], array(
                                    'name' => $content['label'],
                                    'id'   => $key,
                                    'type' => 'plupload_image',
                                ));

                            }

                            break;

                    }

                }

            }

            array_push($meta_boxes, $box);

        }

        if(count($meta_boxes) > 0){
            return $meta_boxes;
        }else{
            return [];
        }

    }

} <commit_msg>Fixed problem registering metaboxes without fields<commit_after><?php
/**
 * Created by PhpStorm.
 * User: sergiovilar
 * Date: 03/05/14
 * Time: 10:55 AM
 */

class RegisterMetabox {

    private $boxes = array();

    /**
     * Add a post type and his fields
     *
     * @param $post_type
     * @param $fields
     */
    public function add($post_type, $fields){

        $this->boxes[$post_type] = $fields;

    }

    public function register(){

        add_filter( 'rwmb_meta_boxes', array($this, 'doRegister') );

    }

    public function doRegister(){

        $meta_boxes = array();

        foreach($this->boxes as $post_type => $fields){

            $box = array(
                'id' => $post_type . '_metabox',
                'title' => 'fields',
                'pages' => array($post_type),
                'context' => 'normal',
                'priority' => 'high',
                'autosave' => true,

                // List of meta fields
                'fields' => array()
            );

            foreach($fields as $key => $content){

                if($key != 'title' && $key != 'editor' && $key != 'thumbnail'){

                    switch($content['type']){

                        case 'int':

                            array_push($box['fields'], array(
                                'name' => $content['label'],
                                'id'   => $key,
                                'type' => 'number',
                            ));

                            break;

                        case 'text':

                            array_push($box['fields'], array(
                                'name' => $content['label'],
                                'id'   => $key,
                                'type' => 'text',
                            ));

                            break;

                        case 'long_text':

                            array_push($box['fields'], array(
                                'name' => $content['label'],
                                'id'   => $key,
                                'type' => 'textarea',
                            ));

                            break;

                        case 'float':

                            array_push($box['fields'], array(
                                'name' => $content['label'],
                                'id'   => $key,
                                'type' => 'text',
                            ));

                            break;

                        case 'boolean':

                            array_push($box['fields'], array(
                                'name' => $content['label'],
                                'id'   => $key,
                                'type' => 'checkbox',
                            ));

                            break;

                        case 'file':

                            array_push($box['fields'], array(
                                'name' => $content['label'],
                                'id'   => $key,
                                'type' => 'file',
                            ));

                            break;

                        case 'image':

                            if(!$content['multiple']){

                                array_push($box['fields'], array(
                                    'name' => $content['label'],
                                    'id'   => $key,
                                    'type' => 'image',
                                ));

                            }else{

                                array_push($box['fields'], array(
                                    'name' => $content['label'],
                                    'id'   => $key,
                                    'type' => 'plupload_image',
                                ));

                            }

                            break;

                    }

                }

            }

            if(count($box['fields']) > 0){
                array_push($meta_boxes, $box);
            }

        }

        if(count($meta_boxes) > 0){
            return $meta_boxes;
        }else{
            return [];
        }

    }

} 
{'fraction_non_alphanumeric': 0.12619274809160305, 'fraction_numerical': 0.0027433206106870227, 'mean_word_length': 0.7008113590263692, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6511580', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1818, 'n_words': 359}