Scafford custom post type.

## OPTIONS

<classname>
: Name of the post type class.

[--slug=<slug>]
: Specify post type slug. If this option is not provided it will slugify post type name.

## EXAMPLE

wp assely:make posttype Movies
761978
public function posttype()
    {
        $this->setClassname($this->getArgument(0));

        $name = Str::snake($this->getClassname());

        $this->generateClass('Posttypes', 'posttype.stub', [
            'classname' => $this->getClassname(),
            'slug' => $this->getOption('slug', $name),
            'rewrite_slug' => $this->getOption('slug', Str::slug($name)),
        ]);
    }
739300
public function init() {
		if ( ! post_type_exists( $this->post_type ) ) {
			$post_type = register_post_type( $this->post_type, $this->args );
			if ( is_wp_error( $post_type ) ) {
				return $post_type;
			}
		}
		if ( '' !== $this->title_placeholder ) {
			add_filter( 'enter_title_here', array( $this, 'update_placeholder' ) );
		}
	}
339774
public function presentPostType()
	{
		global $wp_rewrite;

		$postType = get_post_type_object(get_post_type($this->ID));

		if(! $postType)
		{
			return null;
		}

		if (get_option('permalink_structure') && is_array($postType->rewrite))
		{

			$slug = $postType->rewrite['slug'];

			if ($postType->rewrite['with_front'])
			{
				$structure = $wp_rewrite->front . $slug;
			}
			else
			{
				$structure = $wp_rewrite->root . $slug;
			}

			$link = url(user_trailingslashit($structure, 'post_type_archive'));

		}
		else
		{
			$slug = (isset($postType->slug) && $postType->slug) ? $postType->slug : $postType->name;
			$link = url('?post_type=' . $slug);
		}

		$postType->permalink = $link;

		return $postType;
	}
117747
public function getPostTypeObject($post_type)
    {
        if ( ! isset($this->postTypes[ $post_type ])) {
            return false;
        }

        return $this->postTypes[ $post_type ];
    }
1127820
def process(cls, post, render=True):
        
        post["slug"] = cls.create_slug(post["title"])
        post["editable"] = cls.is_author(post, current_user)
        post["url"] = cls.construct_url(post)
        post["priority"] = 0.8
        if render:
            cls.render_text(post)
            post["meta"]["images"] = cls.extract_images(post)
1281786
private function createPostTypes()
    {
        if(!$this->option('posts') && ($this->option('post_types') || $this->option('all'))) {
            $this->comment('Creating dummy Post Types...');
            $output = (new \PostTypeSeeder())
                ->setCommand($this)
                ->run($this->getDefaultOption('post_types'));
            $this->info($output);
        }
        return $this;
    }
908120
function rule_match_post_format( $match, $rule, $options )
	{
		// vars
		$post_format = $options['post_format'];
		if( !$post_format )
		{	
			// validate
			if( !$options['post_id'] )
			{
				return false;
			}
			
			
			// post type
			if( !$options['post_type'] )
			{
				$options['post_type'] = get_post_type( $options['post_id'] );
			}
			
		
			// does post_type support 'post-format'
			if( post_type_supports( $options['post_type'], 'post-formats' ) )
			{
				$post_format = get_post_format( $options['post_id'] );
				
				if( $post_format === false )
				{
					$post_format = 'standard';
				}
			}
		}

       	
       	if($rule['operator'] == "==")
        {
        	$match = ( $post_format === $rule['value'] );
        	 
        }
        elseif($rule['operator'] == "!=")
        {
        	$match = ( $post_format !== $rule['value'] );
        }
        
        
        
        return $match;
        
    }
511661
public function getPostType()
    {
        global $wp_query;

        // If taxonomy or category page and post type not isset then it's the "post" post type
        if (is_home() || ((is_tax() || is_category() || is_tag()) && is_a(get_queried_object(),
                    'WP_Term') && !get_post_type())) {
            return 'post';
        }

        $postType = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : false;
        if (!$postType && isset($wp_query->query['category_name']) && !empty($wp_query->query['category_name'])) {
            $postType = 'post';
        }

        if (is_array($postType)) {
            $postType = end($postType);
        }

        return $postType;
    }
51680
public static function get_post_type_date_archive_support( $post_type ) {
		if ( is_string( $post_type ) ) {
			$post_type = get_post_type_object( $post_type );
		}

		if ( ! empty( $post_type->cptp ) && isset( $post_type->cptp['date_archive'] ) ) {
			return ! ! $post_type->cptp['date_archive'];
		}

		return true;
	}
69154
public static function get_unique_custom_fields_by_post_type($post_type = "post") {
    global $wpdb;

    $query = "SELECT DISTINCT(type) FROM ".MF_TABLE_CUSTOM_FIELDS. " WHERE post_type = '".$post_type."'";

    $fields = $wpdb->get_col($query);
    return $fields;
  }
442158
protected function get_post_type() {
		global $wp_query;

		$post_type = get_post_type();

		if ( $post_type ) {
			return $post_type;
		}

		if ( isset( $wp_query->query['post_type'] ) ) {
			return $wp_query->query['post_type'];
		}

		return $post_type;
	}
922317
protected function preload($post_type = 'post')
    {
        $args = array(
            'fields'           => 'ids',
            'orderby'          => 'post_date',
            'order'            => 'DESC',
            'post_status'      => 'publish',
            'post_type'        => $post_type,
            'showposts'        => -1,
            'suppress_filters' => true,
        );
        $query = new WP_Query($args);

        if ($query->have_posts()) {
            $posts = apply_filters('staticwp_preload_' . $post_type . '_posts', $query->posts);
            foreach ($posts as $post_id) {
                $this->updateHtml($post_id);
            }
        }
    }
1023186
public function metaBoxPostTypes()
    {
	global $modularityOptions;
	$enabled = isset($modularityOptions['enabled-post-types']) && is_array($modularityOptions['enabled-post-types']) ? $modularityOptions['enabled-post-types'] : array();

	$postTypes = array_filter(get_post_types(), function ($item) {
	    $disallowed = array_merge(
		array_keys(\Modularity\ModuleManager::$available),
		array(
		    'attachment',
		    'revision',
		    'nav_menu_item',
		    'custom_css',
		    'customize_changeset'
		)
	    );

	    if (in_array($item, $disallowed)) {
		return false;
	    }

	    if (substr($item, 0, 4) == 'acf-') {
		return false;
	    }

	    return true;
	});

	include MODULARITY_TEMPLATE_PATH . 'options/partials/modularity-post-types.php';
    }
724814
public static function get_post_class( $post_type, $post_class = '\Timber\Post' ) {
		$post_class = apply_filters('Timber\PostClassMap', $post_class);
		$post_class_use = '\Timber\Post';

		if ( is_array($post_class) ) {
			if ( isset($post_class[$post_type]) ) {
				$post_class_use = $post_class[$post_type];
			} else {
				Helper::error_log($post_type.' not found in '.print_r($post_class, true));
			}
		} elseif ( is_string($post_class) ) {
			$post_class_use = $post_class;
		} else {
			Helper::error_log('Unexpeted value for PostClass: '.print_r($post_class, true));
		}

		if ( $post_class_use === '\Timber\Post' || $post_class_use === 'Timber\Post' ) {
			return $post_class_use;
		}

		if ( !class_exists($post_class_use) || !is_subclass_of($post_class_use, '\Timber\Post') ) {
			Helper::error_log('Class '.$post_class_use.' either does not exist or implement \Timber\Post');
			return '\Timber\Post';
		}

		return $post_class_use;
	}
261184
function add_taxonomy_filters() {

        global $typenow;
        global $wp_query;

        // Must set this to the post type you want the filter(s) displayed on.
        if ( $typenow == $this->post_type_name ) {

            // if custom filters are defined use those
            if ( is_array( $this->filters ) ) {

                $filters = $this->filters;

            // else default to use all taxonomies associated with the post
            } else {

                $filters = $this->taxonomies;
            }

            if ( ! empty( $filters ) ) {

                // Foreach of the taxonomies we want to create filters for...
                foreach ( $filters as $tax_slug ) {

                    // ...object for taxonomy, doesn't contain the terms.
                    $tax = get_taxonomy( $tax_slug );

                    // Get taxonomy terms and order by name.
                    $args = array(
                        'orderby' => 'name',
                        'hide_empty' => false
                    );

                    // Get taxonomy terms.
                    $terms = get_terms( $tax_slug, $args );

                    // If we have terms.
                    if ( $terms ) {

                        // Set up select box.
                        printf( ' &nbsp;<select name="%s" class="postform">', $tax_slug );

                        // Default show all.
                        printf( '<option value="0">%s</option>', sprintf( __( 'Show all %s', $this->textdomain ), $tax->label ) );

                        // Foreach term create an option field...
                        foreach ( $terms as $term ) {

                            // ...if filtered by this term make it selected.
                            if ( isset( $_GET[ $tax_slug ] ) && $_GET[ $tax_slug ] === $term->slug ) {

                                printf( '<option value="%s" selected="selected">%s (%s)</option>', $term->slug, $term->name, $term->count );

                            // ...create option for taxonomy.
                            } else {

                                printf( '<option value="%s">%s (%s)</option>', $term->slug, $term->name, $term->count );
                            }
                        }
                        // End the select field.
                        print( '</select>&nbsp;' );
                    }
                }
            }
        }
    }
189711
private function _get_post_types(){
    global $wpdb;

    $query = sprintf('SELECT * FROM %s ORDER BY id',MF_TABLE_POSTTYPES);
    $posttypes = $wpdb->get_results( $query, ARRAY_A );
    return $posttypes;
  }
654621
function rule_match_page_type( $match, $rule, $options )
	{
		// validation
		if( !$options['post_id'] )
		{
			return false;
		}

		$post = get_post( $options['post_id'] );
		        
        if( $rule['value'] == 'front_page')
        {
        	
	        $front_page = (int) get_option('page_on_front');
	        
	        
	        if($rule['operator'] == "==")
	        {
	        	$match = ( $front_page == $post->ID );
	        }
	        elseif($rule['operator'] == "!=")
	        {
	        	$match = ( $front_page != $post->ID );
	        }
	        
        }
        elseif( $rule['value'] == 'posts_page')
        {
        
	        $posts_page = (int) get_option('page_for_posts');
	        
	        
	        if($rule['operator'] == "==")
	        {
	        	$match = ( $posts_page == $post->ID );
	        }
	        elseif($rule['operator'] == "!=")
	        {
	        	$match = ( $posts_page != $post->ID );
	        }
	        
        }
        elseif( $rule['value'] == 'top_level')
        {
        	$post_parent = $post->post_parent;
        	if( $options['page_parent'] )
        	{
	        	$post_parent = $options['page_parent'];
        	}
        	
        	
	        if($rule['operator'] == "==")
	        {
	        	$match = ( $post_parent == 0 );
	        }
	        elseif($rule['operator'] == "!=")
	        {
	        	$match = ( $post_parent != 0 );
	        }
	        
        }
        elseif( $rule['value'] == 'parent')
        {
        
        	$children = get_pages(array(
        		'post_type' => $post->post_type,
        		'child_of' =>  $post->ID,
        	));
        	
	        
	        if($rule['operator'] == "==")
	        {
	        	$match = ( count($children) > 0 );
	        }
	        elseif($rule['operator'] == "!=")
	        {
	        	$match = ( count($children) == 0 );
	        }
	        
        }
        elseif( $rule['value'] == 'child')
        {
        
        	$post_parent = $post->post_parent;
        	if( $options['page_parent'] )
        	{
	        	$post_parent = $options['page_parent'];
        	}
	        
	        
	        if($rule['operator'] == "==")
	        {
	        	$match = ( $post_parent != 0 );
	        }
	        elseif($rule['operator'] == "!=")
	        {
	        	$match = ( $post_parent == 0 );
	        }
	        
        }
        
        return $match;

	}