public function init()
    {
        // Update slug
        $slug = Helpers::urlize($this->getModel()->getSlug());
        $this->getModel()->setSlug($slug);

        // Check forbidden slugs
        if (in_array($slug, $this->forbidden_slugs)) {
            throw new PosttypeException(Translate::t('posttype.errors.slug_is_forbidden'));
        }

        // Update args on post types except reserved ones
        if (!in_array($slug, $this->reserved_slugs)) {
            // Check if post type already exists
            if (post_type_exists($slug)) {
                throw new PosttypeException(Translate::t('posttype.errors.slug_already_exists'));
            }

            $args = $this->getModel()->getArgs();
            $labels = $this->getModel()->getLabels();

            // Initialize plural and singular vars
            $labels['name'] = isset($labels['name']) ? $labels['name'] : '';
            $labels['singular_name'] = isset($labels['singular_name']) ? $labels['singular_name'] : '';

            // Check label for all except reserved ones
            if (empty($labels['name']) || empty($labels['singular_name'])) {
                throw new PosttypeException(Translate::t('posttype.errors.term_is_not_defined'));
            }

            $args = array_merge($this->defaultArgs(), $args);
            $args['labels'] = array_merge(
                $this->defaultLabels($labels['name'], $labels['singular_name']),
                $labels
            );

            // Update PosttypeModel args
            $this->getModel()->setArgs($args);
            $this->getModel()->setLabels($labels);
        }

        // Register post type
        $this->register();
    }
public function init()
    {
        // Update slug
        $slug = Helpers::urlize($this->getModel()->getSlug());
        $this->getModel()->setSlug($slug);

        // Check forbidden slugs
        if (in_array($slug, $this->forbidden_slugs)) {
            throw new PosttypeException(Translate::t('posttype.errors.slug_is_forbidden'));
        }

        // Update args on post types except reserved ones
        if (!in_array($slug, $this->reserved_slugs)) {
            // Check if post type already exists
            if (post_type_exists($slug)) {
                throw new PosttypeException(Translate::t('posttype.errors.slug_already_exists'));
            }

            $args = $this->getModel()->getArgs();
            $labels = $this->getModel()->getLabels();

            // Initialize plural and singular vars
            $labels['name'] = isset($labels['name']) ? $labels['name'] : '';
            $labels['singular_name'] = isset($labels['singular_name']) ? $labels['singular_name'] : '';

            // Check label for all except reserved ones
            if (empty($labels['name']) || empty($labels['singular_name'])) {
                throw new PosttypeException(Translate::t('posttype.errors.term_is_not_defined'));
            }

            $args = array_merge($this->defaultArgs(), $args);
            $args['labels'] = array_merge(
                $this->defaultLabels($labels['name'], $labels['singular_name']),
                $labels
            );

            // Update PosttypeModel args
            $this->getModel()->setArgs($args);
            $this->getModel()->setLabels($labels);
        }

        // Register post type
        $this->register();
    }
public function init ( ) { // Update slug $ slug = Helpers :: urlize ( $ this -> getModel ( ) -> getSlug ( ) ) ; $ this -> getModel ( ) -> setSlug ( $ slug ) ; // Check forbidden slugs if ( in_array ( $ slug , $ this -> forbidden_slugs ) ) { throw new PosttypeException ( Translate :: t ( 'posttype.errors.slug_is_forbidden' ) ) ; } // Update args on post types except reserved ones if ( ! in_array ( $ slug , $ this -> reserved_slugs ) ) { // Check if post type already exists if ( post_type_exists ( $ slug ) ) { throw new PosttypeException ( Translate :: t ( 'posttype.errors.slug_already_exists' ) ) ; } $ args = $ this -> getModel ( ) -> getArgs ( ) ; $ labels = $ this -> getModel ( ) -> getLabels ( ) ; // Initialize plural and singular vars $ labels [ 'name' ] = isset ( $ labels [ 'name' ] ) ? $ labels [ 'name' ] : '' ; $ labels [ 'singular_name' ] = isset ( $ labels [ 'singular_name' ] ) ? $ labels [ 'singular_name' ] : '' ; // Check label for all except reserved ones if ( empty ( $ labels [ 'name' ] ) || empty ( $ labels [ 'singular_name' ] ) ) { throw new PosttypeException ( Translate :: t ( 'posttype.errors.term_is_not_defined' ) ) ; } $ args = array_merge ( $ this -> defaultArgs ( ) , $ args ) ; $ args [ 'labels' ] = array_merge ( $ this -> defaultLabels ( $ labels [ 'name' ] , $ labels [ 'singular_name' ] ) , $ labels ) ; // Update PosttypeModel args $ this -> getModel ( ) -> setArgs ( $ args ) ; $ this -> getModel ( ) -> setLabels ( $ labels ) ; } // Register post type $ this -> register ( ) ; }
Build PosttypeModel and initialize hook.
Build PosttypeModel and initialize hook .