block-templates.php
1 year ago
class-templates-list-table.php
2 years ago
default-template-types.php
7 months ago
full-site-editing.php
1 year ago
get-block-templates.php
1 year ago
template-loader.php
1 year ago
template-parts.php
1 month ago
templates.php
1 month ago
templates.php
88 lines
| 1 | <?php |
| 2 | |
| 3 | function kubio_get_template_types() { |
| 4 | $template_types = kubio_get_template_type_slugs(); |
| 5 | $template_types = array_merge( $template_types, array( 'archive-product', 'single-product' ) ); |
| 6 | |
| 7 | return $template_types; |
| 8 | } |
| 9 | |
| 10 | function kubio_is_block_template() { |
| 11 | global $_wp_current_template_content; |
| 12 | |
| 13 | return apply_filters( 'kubio_is_block_template', ! ! $_wp_current_template_content ); |
| 14 | } |
| 15 | |
| 16 | function kubio_theme_has_kubio_block_support() { |
| 17 | return apply_filters( 'kubio/has_block_templates_support', false ); |
| 18 | } |
| 19 | |
| 20 | function kubio_theme_has_block_templates_support() { |
| 21 | $folders_to_check = array( 'full-site-editing/block-templates/index.html', 'block-templates/index.html', 'templates/index.html' ); |
| 22 | |
| 23 | $stylesheet_dir = get_stylesheet_directory(); |
| 24 | $parent_dir = get_template_directory(); |
| 25 | |
| 26 | foreach ( $folders_to_check as $folder ) { |
| 27 | $candidate = $stylesheet_dir . '/' . $folder; |
| 28 | $candidate_parent = $parent_dir . '/' . $folder; |
| 29 | if ( file_exists( $candidate ) ) { |
| 30 | return true; |
| 31 | } |
| 32 | |
| 33 | if ( $candidate_parent !== $candidate && file_exists( $candidate_parent ) ) { |
| 34 | return true; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return kubio_theme_has_kubio_block_support(); |
| 39 | } |
| 40 | |
| 41 | // skip unrelated templates to display |
| 42 | function kubio_skip_unrelated_templates( $post_templates, $theme, $post, $post_type ) { |
| 43 | |
| 44 | $exclude = array(); |
| 45 | |
| 46 | switch ( $post_type ) { |
| 47 | case 'page': |
| 48 | $exclude[] = 'page'; |
| 49 | break; |
| 50 | } |
| 51 | |
| 52 | $default_template_types = array_diff( array_keys( kubio_get_default_template_types() ), $exclude ); |
| 53 | |
| 54 | foreach ( $post_templates as $slug => $name ) { |
| 55 | if ( in_array( $slug, $default_template_types ) ) { |
| 56 | unset( $post_templates[ $slug ] ); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return $post_templates; |
| 61 | } |
| 62 | |
| 63 | add_filter( |
| 64 | 'theme_templates', |
| 65 | 'kubio_skip_unrelated_templates', |
| 66 | 100, |
| 67 | 4 |
| 68 | ); |
| 69 | |
| 70 | // view and edit the slug in quick settings |
| 71 | |
| 72 | function kubio_template_slug_editor( $column_name, $post_type ) { |
| 73 | if ( $column_name === 'slug' && $post_type === 'wp_template' ) { |
| 74 | ?> |
| 75 | <fieldset class="inline-edit-col-left"> |
| 76 | <div class="inline-edit-col"> |
| 77 | <div class="inline-edit-group wp-clearfix"> |
| 78 | <label class="inline-edit-status alignleft"> |
| 79 | <span class="title"><?php esc_html_e( 'Slug', 'kubio' ); ?></span> |
| 80 | <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span> |
| 81 | </label> |
| 82 | </div> |
| 83 | </div> |
| 84 | </fieldset> |
| 85 | <?php |
| 86 | } |
| 87 | } |
| 88 |