| 1 |
<?php |
| 2 |
/** |
| 3 |
* Templates |
| 4 |
* |
| 5 |
* @deprecated since v3.1.0 |
| 6 |
* |
| 7 |
* @package ghostkit |
| 8 |
*/ |
| 9 |
|
| 10 |
/** |
| 11 |
* GhostKit_Templates |
| 12 |
*/ |
| 13 |
class GhostKit_Templates { |
| 14 |
/** |
| 15 |
* Is templates feature allowed to display in UI. |
| 16 |
* |
| 17 |
* @var boolean |
| 18 |
*/ |
| 19 |
public static $is_allowed = null; |
| 20 |
|
| 21 |
/** |
| 22 |
* GhostKit_Templates constructor. |
| 23 |
*/ |
| 24 |
public static function init() { |
| 25 |
add_action( 'init', 'GhostKit_Templates::add_custom_post_type' ); |
| 26 |
add_filter( 'admin_notices', 'GhostKit_Templates::add_templates_page_notice' ); |
| 27 |
|
| 28 |
add_action( |
| 29 |
'wp_loaded', |
| 30 |
function () { |
| 31 |
if ( ! is_admin() ) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
$allow_templates = GhostKit_Templates::is_allowed() ? 'true' : 'false'; |
| 36 |
|
| 37 |
// Disable customizer settings from GhostKit. |
| 38 |
wp_add_inline_script( 'ghostkit-helper', 'if (ghostkitVariables) { ghostkitVariables.allowTemplates = ' . $allow_templates . '; }', 'before' ); |
| 39 |
}, |
| 40 |
9 |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Check if displaying Templates allowed. |
| 46 |
* |
| 47 |
* @return boolean |
| 48 |
*/ |
| 49 |
public static function is_allowed() { |
| 50 |
if ( null !== self::$is_allowed ) { |
| 51 |
return self::$is_allowed; |
| 52 |
} |
| 53 |
|
| 54 |
self::$is_allowed = false; |
| 55 |
|
| 56 |
/* |
| 57 |
* Check theme templates. |
| 58 |
*/ |
| 59 |
if ( count( glob( get_template_directory() . '/ghostkit/templates/*/content.php' ) ) ) { |
| 60 |
self::$is_allowed = true; |
| 61 |
} |
| 62 |
|
| 63 |
/* |
| 64 |
* Check child theme templates. |
| 65 |
*/ |
| 66 |
if ( ! self::$is_allowed && get_stylesheet_directory() !== get_template_directory() && count( glob( get_stylesheet_directory() . '/ghostkit/templates/*/content.php' ) ) ) { |
| 67 |
self::$is_allowed = true; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Check Templates posts. |
| 72 |
*/ |
| 73 |
if ( ! self::$is_allowed ) { |
| 74 |
$db_templates = new WP_Query( |
| 75 |
array( |
| 76 |
'post_type' => 'ghostkit_template', |
| 77 |
'posts_per_page' => 1, |
| 78 |
'showposts' => 1, |
| 79 |
) |
| 80 |
); |
| 81 |
|
| 82 |
self::$is_allowed = $db_templates->have_posts(); |
| 83 |
} |
| 84 |
|
| 85 |
return self::$is_allowed; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Register custom post type. |
| 90 |
*/ |
| 91 |
public static function add_custom_post_type() { |
| 92 |
register_post_type( |
| 93 |
'ghostkit_template', |
| 94 |
array( |
| 95 |
'labels' => array( |
| 96 |
'name' => _x( 'Templates', 'Post Type General Name', 'ghostkit' ), |
| 97 |
'singular_name' => _x( 'Template', 'Post Type Singular Name', 'ghostkit' ), |
| 98 |
'menu_name' => __( 'Templates', 'ghostkit' ), |
| 99 |
'parent_item_colon' => __( 'Parent Template', 'ghostkit' ), |
| 100 |
'all_items' => __( 'Templates', 'ghostkit' ), |
| 101 |
'view_item' => __( 'View Template', 'ghostkit' ), |
| 102 |
'add_new_item' => __( 'Add New Template', 'ghostkit' ), |
| 103 |
'add_new' => __( 'Add New', 'ghostkit' ), |
| 104 |
'edit_item' => __( 'Edit Template', 'ghostkit' ), |
| 105 |
'update_item' => __( 'Update Template', 'ghostkit' ), |
| 106 |
'search_items' => __( 'Search Template', 'ghostkit' ), |
| 107 |
'not_found' => __( 'Not Found', 'ghostkit' ), |
| 108 |
'not_found_in_trash' => __( 'Not found in Trash', 'ghostkit' ), |
| 109 |
), |
| 110 |
'public' => false, // true? |
| 111 |
'publicly_queryable' => false, // true? |
| 112 |
'has_archive' => false, |
| 113 |
'show_ui' => true, |
| 114 |
'exclude_from_search' => true, |
| 115 |
'show_in_nav_menus' => false, |
| 116 |
'rewrite' => false, |
| 117 |
'hierarchical' => false, |
| 118 |
'show_in_menu' => false, |
| 119 |
'show_in_admin_bar' => true, |
| 120 |
'show_in_rest' => true, |
| 121 |
'taxonomies' => array( |
| 122 |
'ghostkit_template_category', |
| 123 |
), |
| 124 |
'capability_type' => 'post', |
| 125 |
'supports' => array( |
| 126 |
'title', |
| 127 |
'editor', |
| 128 |
'thumbnail', |
| 129 |
), |
| 130 |
) |
| 131 |
); |
| 132 |
|
| 133 |
register_taxonomy( |
| 134 |
'ghostkit_template_category', |
| 135 |
'ghostkit_template', |
| 136 |
array( |
| 137 |
'label' => esc_html__( 'Categories', 'ghostkit' ), |
| 138 |
'labels' => array( |
| 139 |
'menu_name' => esc_html__( 'Categories', 'ghostkit' ), |
| 140 |
), |
| 141 |
'rewrite' => false, |
| 142 |
'hierarchical' => false, |
| 143 |
'publicly_queryable' => false, |
| 144 |
'show_in_nav_menus' => false, |
| 145 |
'show_in_rest' => true, |
| 146 |
'show_admin_column' => true, |
| 147 |
) |
| 148 |
); |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Show notice in templates list admin page. |
| 153 |
*/ |
| 154 |
public static function add_templates_page_notice() { |
| 155 |
$current_screen = get_current_screen(); |
| 156 |
|
| 157 |
if ( ! isset( $current_screen->post_type ) || 'ghostkit_template' !== $current_screen->post_type ) { |
| 158 |
return; |
| 159 |
} |
| 160 |
|
| 161 |
?> |
| 162 |
<div class="notice notice-error"> |
| 163 |
<h3> |
| 164 |
<?php echo esc_html__( 'Templates Deprecated', 'ghostkit' ); ?> |
| 165 |
</h3> |
| 166 |
<p> |
| 167 |
<?php |
| 168 |
echo esc_html__( 'Please avoid using the Templates feature. It has been deprecated since Ghost Kit v3.1.0 and will be removed in future updates.', 'ghostkit' ); |
| 169 |
?> |
| 170 |
<br /> |
| 171 |
<?php |
| 172 |
echo wp_kses_post( sprintf( __( 'To create a block template, you can use the built-in WordPress feature named Patterns.', 'ghostkit' ), 'https://wordpress.org/documentation/article/site-editor-patterns/' ) ); |
| 173 |
?> |
| 174 |
</p> |
| 175 |
<p> |
| 176 |
<a href="https://wordpress.org/documentation/article/site-editor-patterns/" target="_blank" class="button button-primary"><?php echo esc_html__( 'Read About Patterns', 'ghostkit' ); ?></a> |
| 177 |
</p> |
| 178 |
</div> |
| 179 |
<?php |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
GhostKit_Templates::init(); |
| 184 |
|