post_templates ) && isset( $omega->post_templates[ $post_type ] ) ) return $omega->post_templates[ $post_type ]; /* Else, set up an empty array to house the templates. */ else $omega->post_templates = array(); /* Set up an empty post templates array. */ $post_templates = array(); /* Get the post type object. */ $post_type_object = get_post_type_object( $post_type ); /* Get the theme (parent theme if using a child theme) object. */ $theme = wp_get_theme( get_template() ); /* Get the theme PHP files one level deep. */ $files = (array) $theme->get_files( 'php', 1 ); /* If a child theme is active, get its files and merge with the parent theme files. */ if ( is_child_theme() ) { $child = wp_get_theme(); $child_files = (array) $child->get_files( 'php', 1 ); $files = array_merge( $files, $child_files ); } /* Loop through each of the PHP files and check if they are post templates. */ foreach ( $files as $file => $path ) { /* Get file data based on the post type singular name (e.g., "Post Template", "Book Template", etc.). */ $headers = get_file_data( $path, array( "{$post_type_object->name} Template" => "{$post_type_object->name} Template", ) ); /* Continue loop if the header is empty. */ if ( empty( $headers["{$post_type_object->name} Template"] ) ) continue; /* Add the PHP filename and template name to the array. */ $post_templates[ $file ] = $headers["{$post_type_object->name} Template"]; } /* Add the templates to the global $omega object. */ $omega->post_templates[ $post_type ] = array_flip( $post_templates ); /* Return array of post templates. */ return $omega->post_templates[ $post_type ]; } ?>