<commit_before><?php

if (!class_exists('CM_WP_Element_PostType')) {

    class CM_WP_Element_PostType extends CM_WP_Element {

        /***************************************
         * Static factory properties & methods *
         ***************************************/

        /**
         * Array of registered post
         * @var array
         */
        static protected $registered_post_types = array();

        /**
         * Flag to indicate whether the action hook to register the posts has been
         * added
         * @var boolean
         */
        static protected $hook_registered = false;

        
        /**
         * Returns a constructed CM_WP_Element_PostType object
         *
         * @param CM_WP_Base $owner The the plugin/theme object that this belongs to
         * @param string     $name  Slug for the post being registered (will be
         *                          pre-fixed by the plugin prefix)
         *                          Name should be the plural term
         * @param array      $args  (optional) Array of additional arguments
         *                          Possible arguments are...
         *                          - $post_class - Name of class to use for post
         *                          objects
         *                          - $slug - The slug for the post.  Will be prefixed
         *                          by the plugin/theme prefix.
         *                          If not provided, will be created from the $name
         *                          value
         *
         * @return CM_WP_Element_PostType
         */
        static public function register( $owner, $name, $args = array() ) {

            // Fill gaps in $args with defaults
            $defaults = array(
                'slug'       => null,
            );
            $args = wp_parse_args( $args, $defaults );

            $slug = $args['slug'];
            unset( $args['slug'] );

            // If slug is not provided, build it from the $name value
            if ( empty( $slug ) ) {
                $slug = str_replace( '-', '_', sanitize_title( $name ) );
            }

            // Add the plugin/theme prefix to the slug
            $prefixed_slug = "{$owner->get_prefix()}_{$slug}";

            if ( isset( self::$registered_post_types[$prefixed_slug] ) ) {
                throw new
                    CM_WP_Exception_Element_PostType_AlreadyRegisteredException(
                        $slug
                    );
                
            }

            $class = get_called_class();

            // Now build the new object
            self::$registered_post_types[$prefixed_slug] = 
                new $class( $owner, $prefixed_slug, $name, $args );

            if ( ! self::$hook_registered ) {
                add_action( 'init', array( __CLASS__, 'register_post_types') );
                self::$hook_registered = true;
            }

            return self::$registered_post_types[$prefixed_slug];
        }



        /************************
         * Other static methods *
         ************************/

        public function register_post_types() {
            foreach ( self::$registered_post_types as $post_type ) {
                $post_type->register_with_wp();
            }
        }


        /*******************************
         * Object properties & methods *
         *******************************/

        /**
         * Slug to use when registering the post_type
         * @var string
         */
        protected $slug;


        /**
         * Labels for the post type
         * @var array
         */
        protected $labels = array();


        /**
         * Default register_post_type arguments
         * @var array
         */
        protected $post_args = array(
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true, 
            'show_in_menu' => true, 
            'query_var' => true,
            'rewrite' => array( 'slug' => 'book' ),
            'capability_type' => 'post',
            'has_archive' => true, 
            'hierarchical' => false,
            'menu_position' => null,
            'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
        );


        /**
         * The name of the class used to build post objects
         * @var string
         */
        protected $post_class = 'CM_WP_Element_PostType_Post';

        /**
         * Sets the object slug & name (label)
         *
         * @param CM_WP_Base $owner Plugin/theme that registered this post type
         * @param string $slug Slug used to register post with.  WIll be prefixes by
         *                     the plugin/theme prefix
         * @param string $name Name to use for the label for the plugin
         * @param array $args  Array of additional arguments
         */
        protected function __construct(
            CM_WP_Base $owner,
            $slug,
            $name,
            array $args = array()
        ) {

            parent::__construct( $owner );
            $this->slug   = $slug;

            // Build the labels array from the $name
            $this->set_labels( $name );
           
            // If we've been passed a post_class, override the default class
            if ( ! empty( $args['post_class'] ) ) {
                $this->post_class = $args['post_class'];
            }
        }


        protected function set_labels( $plural_label, $single_label = null ) {

            if ( is_null( $single_label ) ) {
                $single_label = preg_replace('/s$/', '', $plural_label);
            }

            $this->labels = array(
                'name'               => $plural_label,
                'singular_name'      => $single_label,
                'add_new'            => "Add New {$single_label}",
                'add_new_item'       => "Add New {$single_label}",
                'edit_item'          => "Edit {$single_label}",<commit_msg>Corrected post types to use the non-prefixed slug for the permalink slug for posts<commit_after><?php

if (!class_exists('CM_WP_Element_PostType')) {

    class CM_WP_Element_PostType extends CM_WP_Element {

        /***************************************
         * Static factory properties & methods *
         ***************************************/

        /**
         * Array of registered post
         * @var array
         */
        static protected $registered_post_types = array();

        /**
         * Flag to indicate whether the action hook to register the posts has been
         * added
         * @var boolean
         */
        static protected $hook_registered = false;

        
        /**
         * Returns a constructed CM_WP_Element_PostType object
         *
         * @param CM_WP_Base $owner The the plugin/theme object that this belongs to
         * @param string     $name  Slug for the post being registered (will be
         *                          pre-fixed by the plugin prefix)
         *                          Name should be the plural term
         * @param array      $args  (optional) Array of additional arguments
         *                          Possible arguments are...
         *                          - $post_class - Name of class to use for post
         *                          objects
         *                          - $slug - The slug for the post.  Will be prefixed
         *                          by the plugin/theme prefix.
         *                          If not provided, will be created from the $name
         *                          value
         *
         * @return CM_WP_Element_PostType
         */
        static public function register( $owner, $name, $args = array() ) {

            // Fill gaps in $args with defaults
            $defaults = array(
                'slug'       => null,
            );
            $args = wp_parse_args( $args, $defaults );

            $slug = $args['slug'];
            unset( $args['slug'] );

            // If slug is not provided, build it from the $name value
            if ( empty( $slug ) ) {
                $slug = str_replace( '-', '_', sanitize_title( $name ) );
            }

            // Add the plugin/theme prefix to the slug
            $prefixed_slug = "{$owner->get_prefix()}_{$slug}";

            if ( isset( self::$registered_post_types[$prefixed_slug] ) ) {
                throw new
                    CM_WP_Exception_Element_PostType_AlreadyRegisteredException(
                        $slug
                    );
                
            }

            $class = get_called_class();

            // Now build the new object
            self::$registered_post_types[$prefixed_slug] = 
                new $class( $owner, $prefixed_slug, $name, $args );

            if ( ! self::$hook_registered ) {
                add_action( 'init', array( __CLASS__, 'register_post_types') );
                self::$hook_registered = true;
            }

            return self::$registered_post_types[$prefixed_slug];
        }



        /************************
         * Other static methods *
         ************************/

        public function register_post_types() {
            foreach ( self::$registered_post_types as $post_type ) {
                $post_type->register_with_wp();
            }
        }


        /*******************************
         * Object properties & methods *
         *******************************/

        /**
         * Slug to use when registering the post_type
         * @var string
         */
        protected $slug;


        /**
         * Labels for the post type
         * @var array
         */
        protected $labels = array();


        /**
         * Default register_post_type arguments
         * @var array
         */
        protected $post_args = array(
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true, 
            'show_in_menu' => true, 
            'query_var' => true,
            'rewrite' => array( 'slug' => 'change_me' ),
            'capability_type' => 'post',
            'has_archive' => true, 
            'hierarchical' => false,
            'menu_position' => null,
            'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
        );


        /**
         * The name of the class used to build post objects
         * @var string
         */
        protected $post_class = 'CM_WP_Element_PostType_Post';

        /**
         * Sets the object slug & name (label)
         *
         * @param CM_WP_Base $owner Plugin/theme that registered this post type
         * @param string $slug Slug used to register post with.  WIll be prefixes by
         *                     the plugin/theme prefix
         * @param string $name Name to use for the label for the plugin
         * @param array $args  Array of additional arguments
         */
        protected function __construct(
            CM_WP_Base $owner,
            $slug,
            $name,
            array $args = array()
        ) {

            parent::__construct( $owner );
            $this->slug = $slug;

            // Build the labels array from the $name
            $this->set_labels( $name );

            // Change the post slug from 'change_me'
            $this->post_args['rewrite']['slug'] = preg_replace(
                '/^' . $owner->get_prefix() . '_/',
                '',
                $this->slug
            );
           
            // If we've been passed a post_class, override the default class
            if ( ! empty( $args['post_class'] ) ) {
                $this->post_class = $args['post_class'];
            }
        }


        protected function set_labels( $plural_label, $single_label = null ) {

            if ( is_null( $single_label ) ) {
                $single_label = preg_replace('/s$/', '', $plural_label);
            }

            $this->labels = array(
                'name'               => $plural_label,
                'singular_name'      => $single_label,
                'add_new'            => "Add New {$single_label}",
                'add_new_item'       => "Add New {$single_label}",
                'edit_item'          => "Edit {$single_label}",
{'fraction_non_alphanumeric': 0.12749615975422426, 'fraction_numerical': 0.0, 'mean_word_length': 1.3802193573215316, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2338264', 'n_tokens_mistral': 3168, 'n_tokens_neox': 3060, 'n_words': 850}