<commit_before><?php

/*

    Custom Post Type Class
    used to help create custom post types for Wordpress
    http://github.com/jjgrainger/wp-custom-post-type-class/

    @author     jjgrainger
    @url        http://jjgrainger.co.uk

*/

class CPT {

    /*
        @var  string  $post_type_name
        Public variable that holds the name of the post type
        assigned on __contstruct()
    */

    public $post_type_name;



    /*
        @var  string  $singular
        Public variable that holds the singular name of the post type
        This is a human friendly name, capitalized with spaces
        assigned on __contstruct()
    */

    public $singular;



    /*
        @var  string  $singular
        Public variable that holds the plural name of the post type
        This is a human friendly name, capitalized with spaces
        assigned on __contstruct()
    */

    public $plural;



    /*
        @var  string  $slug
        Public variable that holds the slug name of the post type
        This is a robot friendly name, all lowercase and uses hyphens
        assigned on __contstruct()
    */

    public $slug;



    /*
        @var  array  $options
        public variable that holds the user submited options of the post type
        assigined on __construct()
    */

    public $options;



    /*
        @var  array  $taxonomies
        public variable that holds an array of the taxonomies associated with the post type
        assigined on register_taxonomy()
    */

    public $taxonomies;



    /*
        @var  array  $filters
        use to define which filters are to appear on admin edit screen
        used in add_taxonmy_filters()
    */

    public $filters; 



    /*
        @var  array  $columns
        use to define which columns are to appear on admin edit screen
        used in add_admin_columns()
    */

    public $columns;



    /*
        @var  array  $custom_populate_columns
        an array of user defined functions to populate admin columns
    */

    public $custom_populate_columns;



    /*
        @var  array  $sortable
        use to define which columns are to sortable on admin edit screen
    */

    public $sortable;



    /*
        @function __contructor(@post_type_name, @options)
        
        @param  mixed   $post_type_names    The name(s) of the post type, accepts (post type name, slug, plural, singlualr)
        @param  array   $options            User submitted options
    */

    function __construct($post_type_names, $options = array()) {

        // check if post type names is string or array
        if(is_array($post_type_names)) {
            
            // add names to object
            $names = array(
                'singular',
                'plural',
                'slug'
            );

            // set the post type name
            $this->post_type_name = $post_type_names['post_type_name'];

            // cycle through possible names
            foreach($names as $name) {

                // if the name has been set by user
                if(isset($post_type_names[$name])) {

                    // use the user setting
                    $this->$name = $post_type_names[$name];
                
                // else generate the name
                } else {

                    // define the method to be used
                    $method = 'get_'.$name;

                    // generate the name
                    $this->$name = $this->$method();
                
                }
            
            }

        // else the post type name is only supplied
        } else {

            // apply to post type name
            $this->post_type_name = $post_type_names;

            // set the slug name
            $this->slug = $this->get_slug();

            // set the plural name label
            $this->plural = $this->get_plural();

            // set the singular name label
            $this->singular = $this->get_singular();

        }

        // set the user submitted options to the object
        $this->options = $options;      

        // register the post type
        $this->add_action('init', array(&$this, 'register_post_type'));

        // add taxonomy to admin edit columns
        $this->add_filter('manage_edit-' . $this->post_type_name . '_columns', array(&$this, 'add_admin_columns'));

        // populate the taxonomy columns with the posts terms
        $this->add_action('manage_' . $this->post_type_name . '_posts_custom_column', array(&$this, 'populate_admin_columns'), 10, 2);
    }



    /*
        helper function get
        used to get an object variable

        @param  string  $var        the variable you would like to retrieve
        @return mixed               returns the value on sucess, bool (false) when fails

    */

    function get($var) {

        // if the variable exisits
        if($this->$var) {

            // on success return the value
            return $this->$var;

        } else {

            // on fail return false
            return false;

        }
    }



    /*
        helper function set
        used to set an object variable
        can overwrite exisiting variables and create new ones
        cannot overwrite reserved variables

        @param  mixed  $var         the variable you would like to create/overwrite
        @param  mixed  $value       the value you would like to set to the variable

    */

    function set($var, $value) {

        // an array of reserved variables that cannot be overwritten
        $reserved = array(
            'config',
            'post_type_name',
            'singular',
            'plural',
            'slug',
            'options',
            'taxonomies'
        );

        // if the variable is not a reserved variable
        if(!in_array($var, $reserved)) {

            // write variable and value
            $this->$var = $value;
        
        }

    }


    /*
        helper function options_merge
        merges user submitted options array with default settings
        preserving default data if not included in user options

        @param  array  $defaults        the default option array
        @param  array  $options         user submitted options to add/override defaults

    */

    function options_merge($defaults, $options) {
        
        // set the new array as defaults
        $new_array = $defaults;
<commit_msg>options merge accepts boolean fixes #1<commit_after><?php

/*

    Custom Post Type Class
    used to help create custom post types for Wordpress
    http://github.com/jjgrainger/wp-custom-post-type-class/

    @author     jjgrainger
    @url        http://jjgrainger.co.uk

*/

class CPT {

    /*
        @var  string  $post_type_name
        Public variable that holds the name of the post type
        assigned on __contstruct()
    */

    public $post_type_name;



    /*
        @var  string  $singular
        Public variable that holds the singular name of the post type
        This is a human friendly name, capitalized with spaces
        assigned on __contstruct()
    */

    public $singular;



    /*
        @var  string  $singular
        Public variable that holds the plural name of the post type
        This is a human friendly name, capitalized with spaces
        assigned on __contstruct()
    */

    public $plural;



    /*
        @var  string  $slug
        Public variable that holds the slug name of the post type
        This is a robot friendly name, all lowercase and uses hyphens
        assigned on __contstruct()
    */

    public $slug;



    /*
        @var  array  $options
        public variable that holds the user submited options of the post type
        assigined on __construct()
    */

    public $options;



    /*
        @var  array  $taxonomies
        public variable that holds an array of the taxonomies associated with the post type
        assigined on register_taxonomy()
    */

    public $taxonomies;



    /*
        @var  array  $filters
        use to define which filters are to appear on admin edit screen
        used in add_taxonmy_filters()
    */

    public $filters; 



    /*
        @var  array  $columns
        use to define which columns are to appear on admin edit screen
        used in add_admin_columns()
    */

    public $columns;



    /*
        @var  array  $custom_populate_columns
        an array of user defined functions to populate admin columns
    */

    public $custom_populate_columns;



    /*
        @var  array  $sortable
        use to define which columns are to sortable on admin edit screen
    */

    public $sortable;



    /*
        @function __contructor(@post_type_name, @options)
        
        @param  mixed   $post_type_names    The name(s) of the post type, accepts (post type name, slug, plural, singlualr)
        @param  array   $options            User submitted options
    */

    function __construct($post_type_names, $options = array()) {

        // check if post type names is string or array
        if(is_array($post_type_names)) {
            
            // add names to object
            $names = array(
                'singular',
                'plural',
                'slug'
            );

            // set the post type name
            $this->post_type_name = $post_type_names['post_type_name'];

            // cycle through possible names
            foreach($names as $name) {

                // if the name has been set by user
                if(isset($post_type_names[$name])) {

                    // use the user setting
                    $this->$name = $post_type_names[$name];
                
                // else generate the name
                } else {

                    // define the method to be used
                    $method = 'get_'.$name;

                    // generate the name
                    $this->$name = $this->$method();
                
                }
            
            }

        // else the post type name is only supplied
        } else {

            // apply to post type name
            $this->post_type_name = $post_type_names;

            // set the slug name
            $this->slug = $this->get_slug();

            // set the plural name label
            $this->plural = $this->get_plural();

            // set the singular name label
            $this->singular = $this->get_singular();

        }

        // set the user submitted options to the object
        $this->options = $options;      

        // register the post type
        $this->add_action('init', array(&$this, 'register_post_type'));

        // add taxonomy to admin edit columns
        $this->add_filter('manage_edit-' . $this->post_type_name . '_columns', array(&$this, 'add_admin_columns'));

        // populate the taxonomy columns with the posts terms
        $this->add_action('manage_' . $this->post_type_name . '_posts_custom_column', array(&$this, 'populate_admin_columns'), 10, 2);
    }



    /*
        helper function get
        used to get an object variable

        @param  string  $var        the variable you would like to retrieve
        @return mixed               returns the value on sucess, bool (false) when fails

    */

    function get($var) {

        // if the variable exisits
        if($this->$var) {

            // on success return the value
            return $this->$var;

        } else {

            // on fail return false
            return false;

        }
    }



    /*
        helper function set
        used to set an object variable
        can overwrite exisiting variables and create new ones
        cannot overwrite reserved variables

        @param  mixed  $var         the variable you would like to create/overwrite
        @param  mixed  $value       the value you would like to set to the variable

    */

    function set($var, $value) {

        // an array of reserved variables that cannot be overwritten
        $reserved = array(
            'config',
            'post_type_name',
            'singular',
            'plural',
            'slug',
            'options',
            'taxonomies'
        );

        // if the variable is not a reserved variable
        if(!in_array($var, $reserved)) {

            // write variable and value
            $this->$var = $value;
        
        }

    }


    /*
        helper function options_merge
        merges user submitted options array with default settings
        preserving default data if not included in user options

        @param  array  $defaults        the default option array
        @param  array  $options         user submitted options to add/override defaults

    */

    function options_merge($defaults, $options) {
        
        // set the new array as defaults
        $new_array = $defaults;

        // return the value if it is false
        if($options === false) return false;

{'fraction_non_alphanumeric': 0.07833461835003855, 'fraction_numerical': 0.0005397070161912105, 'mean_word_length': 1.578727634194831, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3117116', 'n_tokens_mistral': 3472, 'n_tokens_neox': 3251, 'n_words': 1204}