Get permalink structure front for date archive.

@since 1.0.0

@param string $post_type post type name.

@return string
6340
public static function get_date_front( $post_type ) {
		$structure = CPTP_Util::get_permalink_structure( $post_type );

		$front = '';

		preg_match_all( '/%.+?%/', $structure, $tokens );
		$tok_index = 1;
		foreach ( (array) $tokens[0] as $token ) {
			if ( '%post_id%' === $token && ( $tok_index <= 3 ) ) {
				$front = '/date';
				break;
			}
			$tok_index ++;
		}

		return apply_filters( 'CPTP_date_front', $front, $post_type, $structure );
	}
1294805
public function rebuildRewriteRules($postType, $args)
    {
        global $wp_post_types, $wp_rewrite;

        if (!is_admin() && empty(get_option('permalink_structure'))) {
            return;
        }

        if ($args->has_archive) {
            $archiveSlug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive;

            // Maybe append blogfront
            if ($args->rewrite['with_front']) {
                $archiveSlug = substr($wp_rewrite->front, 1) . $archiveSlug;
            } else {
                $archiveSlug = $wp_rewrite->root . $archiveSlug;
            }

            // Add rewrite rule for the archive
            add_rewrite_rule("{$archiveSlug}/?$", "index.php?post_type=$postType", 'top');

            // Add rewrite rules for feeds
            if ($args->rewrite['feeds'] && $wp_rewrite->feeds) {
                $feeds = '(' . trim(implode('|', $wp_rewrite->feeds)) . ')';

                add_rewrite_rule(
                    "{$archiveSlug}/feed/$feeds/?$",
                    "index.php?post_type=$postType" . '&feed=$matches[1]',
                    'top'
                );

                add_rewrite_rule(
                    "{$archiveSlug}/$feeds/?$",
                    "index.php?post_type=$postType" . '&feed=$matches[1]',
                    'top'
                );
            }

            // Add rewrite rules for pagination
            if ($args->rewrite['pages']) {
                add_rewrite_rule(
                    "{$archiveSlug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$",
                    "index.php?post_type=$postType" . '&paged=$matches[1]',
                    'top'
                );
            }
        }

        $permastructArgs = $args->rewrite;
        $permastructArgs['feed'] = $permastructArgs['feeds'];

        // Support plugins that enable 'permastruct' option
        if (isset($args->rewrite['permastruct'])) {
            $permastruct = str_replace($oldRewrite, $slug, $args->rewrite['permastruct']);
        } else {
            $permastruct = "{$args->rewrite['slug']}/%$postType%";
        }

        add_permastruct($postType, $permastruct, $permastructArgs);

        return true;
    }
265077
public function get_custom_post_type( $post_type ) {
		if ( ! $this->is_valid_custom_post_type( $post_type ) ) {
			return null;
		}

		$custom_posts = $this->get_custom_posts();

		return $custom_posts[ $post_type ];
	}
220385
public function register_post_type_rules( $post_type, $args ) {

		/**
		 * WP_Rewrite.
		 *
		 * @var WP_Rewrite $wp_rewrite
		 */
		global $wp_rewrite;

		if ( $args->_builtin ) {
			return;
		}

		if ( false === $args->rewrite ) {
			return;
		}

		if ( ! in_array( $post_type, CPTP_Util::get_post_types(), true ) ) {
			return;
		}

		$permalink = CPTP_Util::get_permalink_structure( $post_type );

		if ( ! $permalink ) {
			$permalink = CPTP_DEFAULT_PERMALINK;
		}

		$permalink = '%' . $post_type . '_slug%' . $permalink;
		$permalink = str_replace( '%postname%', '%' . $post_type . '%', $permalink );

		add_rewrite_tag( '%' . $post_type . '_slug%', '(' . $args->rewrite['slug'] . ')', 'post_type=' . $post_type . '&slug=' );

		$taxonomies = CPTP_Util::get_taxonomies( true );
		foreach ( $taxonomies as $taxonomy => $objects ) :
			$wp_rewrite->add_rewrite_tag( "%$taxonomy%", '(.+?)', "$taxonomy=" );
		endforeach;

		$rewrite_args = $args->rewrite;
		if ( ! is_array( $rewrite_args ) ) {
			$rewrite_args = array(
				'with_front' => $args->rewrite,
			);
		}

		$slug = $args->rewrite['slug'];
		if ( $args->has_archive ) {
			if ( is_string( $args->has_archive ) ) {
				$slug = $args->has_archive;
			};

			if ( $args->rewrite['with_front'] ) {
				$slug = substr( $wp_rewrite->front, 1 ) . $slug;
			}

			if ( CPTP_Util::get_post_type_date_archive_support( $post_type ) ) {
				$date_front = CPTP_Util::get_date_front( $post_type );
				add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type=' . $post_type, 'top' );
				add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type=' . $post_type, 'top' );
				add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]&post_type=' . $post_type, 'top' );
				add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&post_type=' . $post_type, 'top' );
				add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type=' . $post_type, 'top' );
				add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type=' . $post_type, 'top' );
				add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]&post_type=' . $post_type, 'top' );
				add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&post_type=' . $post_type, 'top' );
				add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&feed=$matches[2]&post_type=' . $post_type, 'top' );
				add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&feed=$matches[2]&post_type=' . $post_type, 'top' );
				add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top' );
				add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/?$', 'index.php?year=$matches[1]&post_type=' . $post_type, 'top' );
			}

			if ( CPTP_Util::get_post_type_author_archive_support( $post_type ) ) {

				add_rewrite_rule( $slug . '/author/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?author_name=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top' );
				add_rewrite_rule( $slug . '/author/([^/]+)/?$', 'index.php?author_name=$matches[1]&post_type=' . $post_type, 'top' );
			}

			if ( in_array( 'category', $args->taxonomies, true ) ) {

				$category_base = get_option( 'category_base', 'category' );

				add_rewrite_rule( $slug . '/' . $category_base . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?category_name=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top' );
				add_rewrite_rule( $slug . '/' . $category_base . '/([^/]+)/?$', 'index.php?category_name=$matches[1]&post_type=' . $post_type, 'top' );

			}

			do_action( 'CPTP_registered_' . $post_type . '_rules', $args, $slug );
		}

		$rewrite_args['walk_dirs'] = false;
		add_permastruct( $post_type, $permalink, $rewrite_args );

	}
724243
private static function is_rewrite_supported_by( $post_type ) {
		$post_type_object = get_post_type_object( $post_type );
		if ( false === $post_type_object->rewrite ) {
			$support = false;
		} else {
			$support = true;
		}

		/**
		 * Filters support CPTP for custom post type.
		 *
		 * @since 3.2.0
		 *
		 * @param bool $support support CPTP.
		 */
		$support = apply_filters( "CPTP_is_rewrite_supported_by_${post_type}", $support );

		/**
		 * Filters support CPTP for custom post type.
		 *
		 * @since 3.2.0
		 *
		 * @param bool $support support CPTP.
		 * @param string $post_type post type name.
		 */
		return apply_filters( 'CPTP_is_rewrite_supported', $support, $post_type );
	}
1256200
public function getRequestedPostTypeArchivePermalink()
    {
        $requested_post_type = $this->getRequestedPostType();

        if (!is_null($requested_post_type)) {
            $this->data['post_type_permalink']  = get_post_type_archive_link($requested_post_type);
        } else {
            $this->data['post_type_permalink'] = false;
        }

        return;
    }
888836
public function currentPostType(): string
    {
        if (!$this->Wp->is_admin) {
            return ''; // Not applicable.
        }
        return !empty($_GET['post_type'])
            ? $this->c::unslash((string) $_GET['post_type'])
            : $this->postTypeNow(); // Fallback on `$typenow`.
    }
486018
public static function getArchiveSlug()
    {
        global $wp_query;

        if ($wp_query && !is_tax() && (is_post_type_archive() || is_archive() || is_home() || is_search() || is_404())) {
            $postType = get_post_type();

            if (isset($wp_query->query_vars['post_type']) && !empty($wp_query->query_vars['post_type'])) {
                $postType = $wp_query->query_vars['post_type'];
            }

            if (is_home()) {
                $archiveSlug = 'archive-post';
            } elseif (is_post_type_archive() && is_search()) {
                $archiveSlug = 'archive-' . get_post_type_object($postType)->name;
            } elseif (is_search()) {
                $archiveSlug = 'search';
            } elseif (is_404()) {
                $archiveSlug = 'e404';
            } elseif (is_author()) {
                $archiveSlug = 'author';
            } else {
                $archiveSlug = 'archive-' . get_post_type_object($postType)->name;
            }

            return $archiveSlug;
        }

        return false;
    }
392322
public function get_default_custom_group($post_type){
    global $wpdb;

    $query = sprintf("SELECT id FROM %s WHERE name = '__default' AND post_type = '%s' ",MF_TABLE_CUSTOM_GROUPS,$post_type);
    $group = $wpdb->get_col($query);

    //exists default group?
    if(!$group){
      $wpdb->insert(
        MF_TABLE_CUSTOM_GROUPS,
        array(
          'name' => '__default',
          'label' => 'Magic Fields',
          'post_type' => $post_type
        ),
        array(
          '%s',
          '%s',
          '%s'
        )
      );
      $custom_group_id = $wpdb->insert_id;
    }else{
      $custom_group_id = $group[0];
    }

    return $custom_group_id;

  }
1338099
def obtain_the_permalink(check = nil, render_inline = true)
      site_url = Setting.get('site_url')
      post = obtain_record(check)

      return '' if post.blank?

      article_url = Setting.get('articles_slug')

      url =
        if post.post_type == 'post'
           site_url("#{article_url}#{post.structured_url}")
        else
          site_url("#{post.structured_url}")
        end

      if render_inline
        render :inline => url
      else
        url
      end

    end
1222435
public function current_post_type() {

		// start by getting current post or stdClass object
		global $wp_query;
		$obj = $wp_query->get_queried_object();

		// see if we are on a post type and if so, set $current_post_type to post type
		if ( isset( $obj->post_type ) ) {
			$current_post_type = $obj->post_type;

		} elseif ( isset( $obj->taxonomy ) ) {
			$current_post_type = $obj->taxonomy;
		} elseif ( isset( $obj->name ) ) {
			$current_post_type = $obj->name;
		} elseif ( is_home() ) {
			$current_post_type = 'post';
		} else {
			$current_post_type = false;
		}

		return $current_post_type;
	}
431186
public function scan_post_type() {
		$flg = false;
		foreach ( $this->namespaces as $ns => $dir ) {
			$dir = $dir . '/' . $ns . '/ThePost';
			if ( is_dir( $dir ) ) {
				foreach ( scandir( $dir ) as $file ) {
					if ( ! preg_match( '/^\./u', $file ) ) {
						$base_class = str_replace( '.php', '', $file );
						$class_name = $ns . '\\ThePost\\' . $base_class;
						if ( class_exists( $class_name ) && $this->is_sub_class_of( $class_name, PostHelper::class ) ) {
							$this->post_type_to_override[ $this->str->camel_to_hyphen( $base_class ) ] = $class_name;
							$flg                                                                       = true;
						}
					}
				}
			}
		}
		if ( $flg ) {
			add_action( 'the_post', [ $this, 'the_post' ] );
		}
	}
1310826
public static function getArchiveTemplateSlugs()
    {
        $archives = get_post_types(array(
            'has_archive' => true
        ), 'names');

        $templates = array();

        foreach ($archives as $archive) {
            $template = \Modularity\Helper\Wp::findCoreTemplates(array(
                'archive-' . $archive
            ));

            if ($template) {
                $templates[] = $template;
            } else {
                $templates[] = 'archive';
            }
        }

        array_unique($templates);
        return $templates;
    }
1194412
public function pre_get_posts( $query ) {
		global $typenow;

		/**
		 * Check if we should modify the query.
		 *
		 * As a hint for for future condition updates: We can’t use $query->is_post_type_archive(),
		 * because some post_types have 'has_archive' set to false.
		 */
		if ( ! is_admin() ) {
			if (
				// Special case for post in a page_for_posts setting.
				( 'post' === $this->post_type && ! $query->is_home() )
				// All other post types.
				|| ( 'post' !== $this->post_type && $this->post_type !== $query->get( 'post_type' ) )
			) {
				return;
			}
		} elseif ( ! $query->is_main_query() || $typenow !== $this->post_type ) {
			return;
		}

		// Differ between frontend and backend queries.
		$query_args = $this->query_args[ is_admin() ? 'backend' : 'frontend' ];

		if ( empty( $query_args ) ) {
			return;
		}

		// Set query args.
		foreach ( $query_args as $key => $arg ) {
			$query->set( $key, $arg );
		}
	}
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;
	}
845378
public function mf_register_post_types(){
    global $mf_pt_register,$mf_pt_unique;

    $post_types = $this->_get_post_types();
    
    foreach($post_types as $p){
      $p = unserialize($p['arguments']);

      $name = $p['core']['type'];
      $option = $p['option'];

      $option['show_in_menu'] = ($option['show_in_menu']) ? true : false;
      $option['query_var'] = ($option['query_var']) ? true : false;
      $option['exclude_from_search'] = ($option['exclude_from_search']) ? true : false;
      $option['labels'] = $p['label'];
      $option['with_front'] = (isset($option['with_front'])) ? $option['with_front'] : true;


      if( isset($p['support']) ){
        foreach($p['support'] as $k => $v){
          $option['supports'][] = $k;
        }
      }

      //always add support for the editor
      $option['supports'][] = 'editor';
      $option['supports'] = array_unique($option['supports']);

      if( isset($p['taxonomy']) ){
        foreach($p['taxonomy'] as $k => $v){
          //register_taxonomy_for_object_type($k, $name);
          $option['taxonomies'][] = $k;
        }
      }
			if(isset($option['has_archive']) && $option['has_archive'] && isset($option['has_archive_slug']) && $option['has_archive_slug'])	
				$option['has_archive'] = $option['has_archive_slug'];
			
			
      if($option['rewrite'] && $option['rewrite_slug'])
        $option['rewrite'] = array( 'slug' => $option['rewrite_slug'],'with_front' => $option['with_front']);

      unset($option['rewrite_slug']);
      unset($option['with_front']);
      array_push($mf_pt_register,$name);

      if($option['menu_position']){
        $option['menu_position'] = (int)$option['menu_position'];
      }

      //check Capability type
      trim($option['capability_type']);
      if(empty($option['capability_type'])){
        $option['capability_type'] = 'post';
      }elseif( !in_array($option['capability_type'],array('post','page')) ){
        $option['capabilities'] = $this->_get_cap($option['capability_type']);
      }
      
      //classic pin image for the menu
      if ( isset($option['menu_icon']) && empty($option['menu_icon']) )  {
        unset($option['menu_icon']);
      }
       
      


      //description
      $option['description'] = $p['core']['description'];
      register_post_type($name,$option);

      //add unique post type
      if (isset($p['core']['quantity']) && $p['core']['quantity'] == 1) {
        array_push($mf_pt_unique, "edit.php?post_type=".$name);
      }
     
     
    }
  
  }
1241174
protected function set_post_type_archive( $post_type_object ) {
		$label = $post_type_object->label;
		$this->set( $label, $this->get_post_type_archive_link( $post_type_object->name ) );
	}