public function custom_template_locator($post_templates, $wp_theme, $post, $post_type)
    {
        // Path to  templates folder.
        $path = \get_stylesheet_directory() . '/' . Config::get('theme.templates_directory') . '/views/post-templates/';

        $templates = \scandir($path);

        if (! empty($templates)) {
            foreach ($templates as $tpl) {
                $full_path = $path . $tpl;

                if ($tpl === '.' || $tpl === '..' || \is_dir($full_path) || $tpl === '_example.php') {
                    continue;
                }

                if (! \preg_match('|Template Name:(.*)$|mi', \file_get_contents($full_path), $header)) {
                    continue;
                }

                $types = ['page'];

                if (\preg_match('|Template Post Type:(.*)$|mi', \file_get_contents($full_path), $type)) {
                    $types = \explode(',', \_cleanup_header_comment(\str_replace(' ', '', $type[1])));
                }

                if (\in_array($post_type, $types)) {
                    $post_templates[ Config::get('theme.templates_directory') . '/views/post-templates/' . $tpl ] = \trim($header[1]);
                }
            }
        }

        return $post_templates;
    }
public function custom_template_locator($post_templates, $wp_theme, $post, $post_type)
    {
        // Path to  templates folder.
        $path = \get_stylesheet_directory() . '/' . Config::get('theme.templates_directory') . '/views/post-templates/';

        $templates = \scandir($path);

        if (! empty($templates)) {
            foreach ($templates as $tpl) {
                $full_path = $path . $tpl;

                if ($tpl === '.' || $tpl === '..' || \is_dir($full_path) || $tpl === '_example.php') {
                    continue;
                }

                if (! \preg_match('|Template Name:(.*)$|mi', \file_get_contents($full_path), $header)) {
                    continue;
                }

                $types = ['page'];

                if (\preg_match('|Template Post Type:(.*)$|mi', \file_get_contents($full_path), $type)) {
                    $types = \explode(',', \_cleanup_header_comment(\str_replace(' ', '', $type[1])));
                }

                if (\in_array($post_type, $types)) {
                    $post_templates[ Config::get('theme.templates_directory') . '/views/post-templates/' . $tpl ] = \trim($header[1]);
                }
            }
        }

        return $post_templates;
    }
public function custom_template_locator ( $ post_templates , $ wp_theme , $ post , $ post_type ) { // Path to  templates folder. $ path = \ get_stylesheet_directory ( ) . '/' . Config :: get ( 'theme.templates_directory' ) . '/views/post-templates/' ; $ templates = \ scandir ( $ path ) ; if ( ! empty ( $ templates ) ) { foreach ( $ templates as $ tpl ) { $ full_path = $ path . $ tpl ; if ( $ tpl === '.' || $ tpl === '..' || \ is_dir ( $ full_path ) || $ tpl === '_example.php' ) { continue ; } if ( ! \ preg_match ( '|Template Name:(.*)$|mi' , \ file_get_contents ( $ full_path ) , $ header ) ) { continue ; } $ types = [ 'page' ] ; if ( \ preg_match ( '|Template Post Type:(.*)$|mi' , \ file_get_contents ( $ full_path ) , $ type ) ) { $ types = \ explode ( ',' , \ _cleanup_header_comment ( \ str_replace ( ' ' , '' , $ type [ 1 ] ) ) ) ; } if ( \ in_array ( $ post_type , $ types ) ) { $ post_templates [ Config :: get ( 'theme.templates_directory' ) . '/views/post-templates/' . $ tpl ] = \ trim ( $ header [ 1 ] ) ; } } } return $ post_templates ; }
Scans the templates folder and adds any templates found to the global template array.

@since  1.0.0

@param array         $post_templates Array of page templates. Keys are filenames,
values are translated names.
@param \WP_Theme     $wp_theme       The theme object.
@param \WP_Post|null $post           The post being edited, provided for context, or null.
@param string        $post_type      Post type to get the templates for.
@return array                        Modified array of page templates
Scans the templates folder and adds any templates found to the global template array .