generator-chisel 2.0.0-alpha.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/bin/chisel.js +6 -0
- package/lib/commands/create/Creator.js +6 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/.gitignore.chisel-tpl +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/.nvmrc +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/404.php +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/README.md +37 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/acf-json/group_6772609e3c28c.json +83 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/acf-json/group_6772615562fb4.json +49 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/archive.php +2 -4
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/block.json +31 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/edit.js +35 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/editor.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/index.js +45 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/save.js +20 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/script.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/style.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/view.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/view.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/block.json +32 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/edit.js +33 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/editor.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/index.js +45 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/render.php +12 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/render.twig +5 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/save.js +6 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/script.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/style.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/view.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/view.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/block.json +36 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/critical.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/editor.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/example.twig +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/index.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/init.php +0 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/script.js +8 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/style.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/view.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/view.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/arrow-left.svg +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/arrow-right.svg +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/chisel-icon.svg +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/chisel-logo.svg +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/close-line.svg +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/color/chisel-icon.svg +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/color/chisel-logo.svg +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/color/facebook-logo.svg +10 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/color/instagram-logo.svg +14 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/x-logo.svg +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/author.php +3 -4
- package/lib/commands/create/creators/app/chisel-starter-theme/composer.json +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/footer.php +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/functions.php +18 -24
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Factory/RegisterAcfOptionsPage.php +62 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/Factory}/RegisterBlocks.php +53 -22
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Factory/RegisterCustomPostType.php +211 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Factory/RegisterCustomTaxonomy.php +174 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/AcfHelpers.php +46 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/AjaxHelpers.php +33 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/AssetsHelpers.php +28 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/BlocksHelpers.php +118 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/CacheHelpers.php +41 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/CommentsHelpers.php +26 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/DataHelpers.php +35 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/GravityFormsHelpers.php +65 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/ImageHelpers.php +102 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes/Helpers.php → inc/Helper/ThemeHelpers.php} +53 -93
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/WoocommerceHelpers.php +72 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/YoastHelpers.php +37 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes/interfaces/Instance.php → inc/Interfaces/HooksInterface.php} +3 -8
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Interfaces/InstanceInterface.php +16 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/Module}/AcfSync.php +13 -20
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/Module}/Ajax.php +16 -41
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/Plugin}/GravityForms.php +15 -72
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/Plugin}/Woocommerce.php +26 -80
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Plugin/Yoast.php +46 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Traits/PageBlocks.php +92 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Traits/Singleton.php +23 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Acf.php +118 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/AcfBlocks.php +62 -61
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/AjaxEnpoints.php +6 -6
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Assets.php +258 -119
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Blocks.php +63 -51
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Cache.php +103 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes/ExtendedImage.php → inc/WP/ChiselImage.php} +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes/ExtendedPost.php → inc/WP/ChiselPost.php} +4 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes/ExtendedProduct.php → inc/WP/ChiselProduct.php} +4 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes/ExtendedTerm.php → inc/WP/ChiselTerm.php} +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Comments.php +10 -32
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Components.php +61 -36
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/CustomPostTypes.php +124 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/CustomTaxonomies.php +129 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Sidebars.php +11 -17
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Site.php +15 -21
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Theme.php +22 -15
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Twig.php +34 -21
- package/lib/commands/create/creators/app/chisel-starter-theme/index.php +2 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/package.chisel-tpl.json +5 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/page.php +3 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/phpcs.xml +5 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/search.php +3 -4
- package/lib/commands/create/creators/app/chisel-starter-theme/single.php +3 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/src/blocks/accordion/accordion-item.js +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/src/blocks/accordion/style.scss +12 -5
- package/lib/commands/create/creators/app/chisel-starter-theme/src/blocks-acf/slider/acf-json/group_66462c70b851f.json +107 -105
- package/lib/commands/create/creators/app/chisel-starter-theme/src/blocks-acf/slider/block.json +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/src/blocks-acf/slider/slider.twig +4 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/src/design/settings/_index.scss +2 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/src/design/tools/_buttons.scss +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/src/design/tools/_icon.scss +39 -7
- package/lib/commands/create/creators/app/chisel-starter-theme/src/design/tools/_index.scss +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/design/tools/_layout.scss +11 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/admin/acf.js +65 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/app.js +2 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/editor/blocks.js +10 -4
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/editor/mods/core-button.js +13 -9
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/editor/utils.js +0 -12
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/modules/loaded.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/admin.scss +2 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/blocks/_core-button.scss +14 -13
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/components/_buttons.scss +14 -13
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/components/_icons-preview.scss +97 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/components/_main-nav.scss +19 -9
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/components/_posts-items.scss +6 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/objects/_icon.scss +51 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/objects/_layout.scss +0 -13
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/wp-admin/_acf.scss +29 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/wp-admin/_index.scss +4 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/style.chisel-tpl.css +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/base.twig +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/components/header.twig +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/{partials → components}/logo.twig +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/views/components/main-nav-item.twig +2 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/components/main-nav.twig +5 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/views/components/pagination.twig +70 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/views/components/slider.twig +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/views/{partials → components}/the-title.twig +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/index.twig +10 -5
- package/lib/commands/create/creators/app/chisel-starter-theme/views/objects/icon.twig +37 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/views/partials/icons-preview.twig +81 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/views/sidebar-blog.twig +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/sidebar-woocommerce.twig +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/single.twig +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/views/woocommerce/archive-product.twig +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/views/woocommerce/linked-products.twig +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/views/woocommerce/single-product.twig +4 -4
- package/lib/commands/create/creators/app/chisel-starter-theme/woocommerce.php +6 -6
- package/lib/commands/create/creators/app/index.js +74 -20
- package/lib/commands/create/creators/app/template/.devcontainer/Dockerfile +21 -0
- package/lib/commands/create/creators/app/template/.devcontainer/compose.chisel-tpl +3 -0
- package/lib/commands/create/creators/app/template/.devcontainer/devcontainer.json.chisel-tpl +31 -0
- package/lib/commands/create/creators/app/template/.devcontainer/docker-compose.yml.chisel-tpl +40 -0
- package/lib/commands/create/creators/app/template/.devcontainer/exec +8 -0
- package/lib/commands/create/creators/app/template/.devcontainer/post-create-command.sh.chisel-tpl +24 -0
- package/lib/commands/create/creators/devcontainer.js +62 -0
- package/lib/commands/create/creators/utils.js +58 -0
- package/lib/commands/create/creators/wp/index.js +24 -3
- package/lib/commands/create/creators/wp-plugins/plugins.json +1 -1
- package/lib/commands/create/index.js +9 -2
- package/lib/commands/create/packages-versions.js +3 -3
- package/package.json +3 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/classes/Acf.php +0 -188
- package/lib/commands/create/creators/app/chisel-starter-theme/classes/ChiselCache.php +0 -87
- package/lib/commands/create/creators/app/chisel-starter-theme/classes/CustomPostTypes.php +0 -444
- package/lib/commands/create/creators/app/chisel-starter-theme/classes/Yoast.php +0 -78
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/components/_icon.scss +0 -19
- package/lib/commands/create/creators/app/chisel-starter-theme/views/components/icon.twig +0 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/partials/pagination.twig +0 -70
- /package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons/{loader.svg → animated/loader.svg} +0 -0
- /package/lib/commands/create/creators/app/chisel-starter-theme/assets/{icons → icons-source}/minus.svg +0 -0
- /package/lib/commands/create/creators/app/chisel-starter-theme/assets/{icons → icons-source}/plus.svg +0 -0
package/lib/commands/create/creators/app/chisel-starter-theme/inc/Factory/RegisterCustomPostType.php
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Chisel\Factory;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Custom post types wrapper class.
|
|
7
|
+
*
|
|
8
|
+
* @package Chisel
|
|
9
|
+
*/
|
|
10
|
+
class RegisterCustomPostType {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Post type.
|
|
14
|
+
*
|
|
15
|
+
* @var array
|
|
16
|
+
*/
|
|
17
|
+
private $post_type;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Arguments.
|
|
21
|
+
*
|
|
22
|
+
* @var array
|
|
23
|
+
*/
|
|
24
|
+
private $args;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Default arguments.
|
|
28
|
+
*
|
|
29
|
+
* @var array
|
|
30
|
+
*/
|
|
31
|
+
private $defaults;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Class constructor.
|
|
35
|
+
*
|
|
36
|
+
* @param string $post_type Post type.
|
|
37
|
+
* @param array $args Arguments.
|
|
38
|
+
* @param array $defaults Default arguments.
|
|
39
|
+
*/
|
|
40
|
+
public function __construct( $post_type, $args, $defaults = array() ) {
|
|
41
|
+
$this->post_type = $post_type;
|
|
42
|
+
$this->args = $args;
|
|
43
|
+
$this->defaults = $defaults;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Register custom post type.
|
|
48
|
+
*/
|
|
49
|
+
public function register_post_type() {
|
|
50
|
+
$post_type = $this->post_type;
|
|
51
|
+
$post_type_args = $this->args;
|
|
52
|
+
$defaults = $this->defaults;
|
|
53
|
+
|
|
54
|
+
$default_supports = isset( $defaults['supports'] ) ? apply_filters( 'chisel_default_post_type_supports_' . $post_type, $defaults['supports'] ) : array();
|
|
55
|
+
$default_rewrite = isset( $defaults['rewrite_args'] ) ? apply_filters( 'chisel_default_post_type_rewrite_args_' . $post_type, $defaults['rewrite_args'] ) : array();
|
|
56
|
+
|
|
57
|
+
$labels = $this->get_post_type_labels();
|
|
58
|
+
|
|
59
|
+
$default_rewrite['slug'] = $post_type;
|
|
60
|
+
|
|
61
|
+
$description = isset( $post_type_args['description'] ) ? $post_type_args['description'] : '';
|
|
62
|
+
$public = isset( $post_type_args['public'] ) ? $post_type_args['public'] : true;
|
|
63
|
+
$hierarchical = isset( $post_type_args['hierarchical'] ) ? $post_type_args['hierarchical'] : false; // true for pages like post type.
|
|
64
|
+
$exclude_from_search = isset( $post_type_args['exclude_from_search'] ) ? $post_type_args['exclude_from_search'] : ! $public;
|
|
65
|
+
$publicly_queryable = isset( $post_type_args['publicly_queryable'] ) ? $post_type_args['publicly_queryable'] : $public;
|
|
66
|
+
$show_ui = isset( $post_type_args['show_ui'] ) ? $post_type_args['show_ui'] : $public; // show in admin.
|
|
67
|
+
$show_in_menu = isset( $post_type_args['show_in_menu'] ) ? $post_type_args['show_in_menu'] : $public; // if or where to show in admin menu - show_ui must be true. If a string of an existing top level menu ('tools.php' or 'edit.php?post_type=page', for example), the post type will be placed as a sub-menu of that.
|
|
68
|
+
$show_in_nav_menus = isset( $post_type_args['show_in_nav_menus'] ) ? $post_type_args['show_in_nav_menus'] : $public;
|
|
69
|
+
$show_in_admin_bar = isset( $post_type_args['show_in_admin_bar'] ) ? $post_type_args['show_in_admin_bar'] : $show_in_menu;
|
|
70
|
+
$show_in_rest = isset( $post_type_args['show_in_rest'] ) ? $post_type_args['show_in_rest'] : true; // set to false to disable block editor. Supports array must also include 'editor'.
|
|
71
|
+
$menu_position = isset( $post_type_args['menu_position'] ) ? $post_type_args['menu_position'] : null;
|
|
72
|
+
$menu_icon = isset( $post_type_args['menu_icon'] ) ? $post_type_args['menu_icon'] : 'dashicons-admin-post';
|
|
73
|
+
$capability_type = isset( $post_type_args['capability_type'] ) ? $post_type_args['capability_type'] : 'post';
|
|
74
|
+
$capabilities = isset( $post_type_args['capabilities'] ) ? $post_type_args['capabilities'] : array();
|
|
75
|
+
$supports = isset( $post_type_args['supports'] ) ? wp_parse_args( $post_type_args['supports'], $default_supports ) : $default_supports;
|
|
76
|
+
$has_archive = isset( $post_type_args['has_archive'] ) ? $post_type_args['has_archive'] : true;
|
|
77
|
+
$rewrite = isset( $post_type_args['rewrite'] ) ? wp_parse_args( $post_type_args['rewrite'], $default_rewrite ) : $default_rewrite;
|
|
78
|
+
$query_var = isset( $post_type_args['query_var'] ) ? $post_type_args['query_var'] : $post_type;
|
|
79
|
+
$can_export = isset( $post_type_args['can_export'] ) ? $post_type_args['can_export'] : true;
|
|
80
|
+
|
|
81
|
+
if ( in_array( 'thumbnail', $supports, true ) ) {
|
|
82
|
+
add_filter(
|
|
83
|
+
'chisel_post_thumbnails_post_types',
|
|
84
|
+
function ( $pts ) use ( $post_type ) {
|
|
85
|
+
$pts[] = $post_type;
|
|
86
|
+
return $pts;
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
$args = array(
|
|
92
|
+
'label' => $post_type_args['plural'],
|
|
93
|
+
'labels' => $labels,
|
|
94
|
+
'description' => $description,
|
|
95
|
+
'public' => $public,
|
|
96
|
+
'hierarchical' => $hierarchical,
|
|
97
|
+
'exclude_from_search' => $exclude_from_search,
|
|
98
|
+
'publicly_queryable' => $publicly_queryable,
|
|
99
|
+
'show_ui' => $show_ui,
|
|
100
|
+
'show_in_menu' => $show_in_menu,
|
|
101
|
+
'show_in_nav_menus' => $show_in_nav_menus,
|
|
102
|
+
'show_in_admin_bar' => $show_in_admin_bar,
|
|
103
|
+
'show_in_rest' => $show_in_rest,
|
|
104
|
+
'menu_position' => $menu_position,
|
|
105
|
+
'menu_icon' => $menu_icon,
|
|
106
|
+
'capability_type' => $capability_type,
|
|
107
|
+
'capabilities' => $capabilities,
|
|
108
|
+
'supports' => $supports,
|
|
109
|
+
'has_archive' => $has_archive,
|
|
110
|
+
'rewrite' => $rewrite,
|
|
111
|
+
'query_var' => $query_var,
|
|
112
|
+
'can_export' => $can_export,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
$other_args = array(
|
|
116
|
+
'rest_base',
|
|
117
|
+
'rest_namespace',
|
|
118
|
+
'rest_controller_class',
|
|
119
|
+
'autosave_rest_controller_class',
|
|
120
|
+
'revisions_rest_controller_class',
|
|
121
|
+
'late_route_registration',
|
|
122
|
+
'map_meta_cap',
|
|
123
|
+
'register_meta_box_cb',
|
|
124
|
+
'taxonomies',
|
|
125
|
+
'template',
|
|
126
|
+
'template_lock',
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
foreach ( $other_args as $arg ) {
|
|
130
|
+
if ( isset( $post_type_args[$arg] ) ) {
|
|
131
|
+
$args[$arg] = $post_type_args[$arg];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
register_post_type( $post_type, $args );
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Get post type labels.
|
|
140
|
+
*
|
|
141
|
+
* @return array
|
|
142
|
+
*/
|
|
143
|
+
private function get_post_type_labels() {
|
|
144
|
+
$post_type_args = $this->args;
|
|
145
|
+
|
|
146
|
+
$labels = array(
|
|
147
|
+
'name' => $post_type_args['plural'],
|
|
148
|
+
'singular_name' => $post_type_args['singular'],
|
|
149
|
+
'add_new' => __( 'Add New', 'chisel' ),
|
|
150
|
+
// translators: %s is the singular name of the post type.
|
|
151
|
+
'add_new_item' => sprintf( __( 'Add New %s', 'chisel' ), $post_type_args['singular'] ),
|
|
152
|
+
// translators: %s is the singular name of the post type.
|
|
153
|
+
'edit_item' => sprintf( __( 'Edit %s', 'chisel' ), $post_type_args['singular'] ),
|
|
154
|
+
// translators: %s is the singular name of the post type.
|
|
155
|
+
'new_item' => sprintf( __( 'New %s', 'chisel' ), $post_type_args['singular'] ),
|
|
156
|
+
// translators: %s is the plural name of the post type.
|
|
157
|
+
'all_items' => sprintf( __( 'All %s', 'chisel' ), $post_type_args['plural'] ),
|
|
158
|
+
// translators: %s is the singular name of the post type.
|
|
159
|
+
'view_item' => sprintf( __( 'View %s', 'chisel' ), $post_type_args['singular'] ),
|
|
160
|
+
// translators: %s is the plural name of the post type.
|
|
161
|
+
'search_items' => sprintf( __( 'Search %s', 'chisel' ), $post_type_args['plural'] ),
|
|
162
|
+
// translators: %s is the plural name of the post type.
|
|
163
|
+
'not_found' => sprintf( __( 'No %s found', 'chisel' ), $post_type_args['plural'] ),
|
|
164
|
+
// translators: %s is the plural name of the post type.
|
|
165
|
+
'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'chisel' ), $post_type_args['plural'] ),
|
|
166
|
+
'parent_item_colon' => '',
|
|
167
|
+
'menu_name' => $post_type_args['plural'],
|
|
168
|
+
// translators: %s is the singular name of the post type.
|
|
169
|
+
'archives' => sprintf( __( '%s Archives', 'chisel' ), $post_type_args['singular'] ),
|
|
170
|
+
// translators: %s is the singular name of the post type.
|
|
171
|
+
'attributes' => sprintf( __( '%s Attributes', 'chisel' ), $post_type_args['singular'] ),
|
|
172
|
+
// translators: %s is the singular name of the post type.
|
|
173
|
+
'insert_into_item' => sprintf( __( 'Insert into %s', 'chisel' ), $post_type_args['singular'] ),
|
|
174
|
+
// translators: %s is the singular name of the post type.
|
|
175
|
+
'uploaded_to_this_item' => sprintf( __( 'Uploaded to this %s', 'chisel' ), $post_type_args['singular'] ),
|
|
176
|
+
'featured_image' => __( 'Featured Image', 'chisel' ),
|
|
177
|
+
'set_featured_image' => __( 'Set featured image', 'chisel' ),
|
|
178
|
+
'remove_featured_image' => __( 'Remove featured image', 'chisel' ),
|
|
179
|
+
'use_featured_image' => __( 'Use as featured image', 'chisel' ),
|
|
180
|
+
// translators: %s is the plural name of the post type.
|
|
181
|
+
'filter_items_list' => sprintf( __( 'Filter %s list', 'chisel' ), $post_type_args['plural'] ),
|
|
182
|
+
'filter_by_date' => __( 'Filter by date', 'chisel' ),
|
|
183
|
+
// translators: %s is the plural name of the post type.
|
|
184
|
+
'items_list_navigation' => sprintf( __( '%s list navigation', 'chisel' ), $post_type_args['plural'] ),
|
|
185
|
+
// translators: %s is the plural name of the post type.
|
|
186
|
+
'items_list' => sprintf( __( '%s list', 'chisel' ), $post_type_args['plural'] ),
|
|
187
|
+
// translators: %s is the singular name of the post type.
|
|
188
|
+
'item_published' => sprintf( __( '%s published', 'chisel' ), $post_type_args['singular'] ),
|
|
189
|
+
// translators: %s is the singular name of the post type.
|
|
190
|
+
'item_published_privately' => sprintf( __( '%s published privately', 'chisel' ), $post_type_args['singular'] ),
|
|
191
|
+
// translators: %s is the singular name of the post type.
|
|
192
|
+
'item_reverted_to_draft' => sprintf( __( '%s reverted to draft', 'chisel' ), $post_type_args['singular'] ),
|
|
193
|
+
// translators: %s is the singular name of the post type.
|
|
194
|
+
'item_scheduled' => sprintf( __( '%s scheduled', 'chisel' ), $post_type_args['singular'] ),
|
|
195
|
+
// translators: %s is the singular name of the post type.
|
|
196
|
+
'item_updated' => sprintf( __( '%s updated', 'chisel' ), $post_type_args['singular'] ),
|
|
197
|
+
// translators: %s is the singular name of the post type.
|
|
198
|
+
'item_trashed' => sprintf( __( '%s trashed', 'chisel' ), $post_type_args['singular'] ),
|
|
199
|
+
// translators: %s is the singular name of the post type.
|
|
200
|
+
'item_untrashed' => sprintf( __( '%s untrashed', 'chisel' ), $post_type_args['singular'] ),
|
|
201
|
+
// translators: %s is the singular name of the post type.
|
|
202
|
+
'item_link' => sprintf( __( '%s link', 'chisel' ), $post_type_args['singular'] ),
|
|
203
|
+
// translators: %s is the singular name of the post type.
|
|
204
|
+
'item_link_description' => sprintf( __( 'A link to a %s', 'chisel' ), $post_type_args['singular'] ),
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
$custom_labels = isset( $post_type_args['labels'] ) ? $post_type_args['labels'] : array();
|
|
208
|
+
|
|
209
|
+
return wp_parse_args( $custom_labels, $labels );
|
|
210
|
+
}
|
|
211
|
+
}
|
package/lib/commands/create/creators/app/chisel-starter-theme/inc/Factory/RegisterCustomTaxonomy.php
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Chisel\Factory;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Custom axonomies wrapper class.
|
|
7
|
+
*
|
|
8
|
+
* @package Chisel
|
|
9
|
+
*/
|
|
10
|
+
class RegisterCustomTaxonomy {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Taxonomy.
|
|
14
|
+
*
|
|
15
|
+
* @var array
|
|
16
|
+
*/
|
|
17
|
+
private $taxonomy;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Arguments.
|
|
21
|
+
*
|
|
22
|
+
* @var array
|
|
23
|
+
*/
|
|
24
|
+
private $args;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Default arguments.
|
|
28
|
+
*
|
|
29
|
+
* @var array
|
|
30
|
+
*/
|
|
31
|
+
private $defaults;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Class constructor.
|
|
35
|
+
*
|
|
36
|
+
* @param string $taxonomy Taxonomy.
|
|
37
|
+
* @param array $args Arguments.
|
|
38
|
+
* @param array $defaults Default arguments.
|
|
39
|
+
*/
|
|
40
|
+
public function __construct( $taxonomy, $args, $defaults = array() ) {
|
|
41
|
+
$this->taxonomy = $taxonomy;
|
|
42
|
+
$this->args = $args;
|
|
43
|
+
$this->defaults = $defaults;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Register custom taxonomy.
|
|
48
|
+
*/
|
|
49
|
+
public function register_taxonomy() {
|
|
50
|
+
$taxonomy = $this->taxonomy;
|
|
51
|
+
$taxonomy_args = $this->args;
|
|
52
|
+
$defaults = $this->defaults;
|
|
53
|
+
|
|
54
|
+
$default_capabilities = isset( $defaults['capabilities'] ) ? apply_filters( 'chisel_default_taxonomy_capabilities_' . $taxonomy, $defaults['capabilities'] ) : array();
|
|
55
|
+
$default_rewrite = isset( $defaults['rewrite_args'] ) ? apply_filters( 'chisel_default_taxonomy_rewrite_args_' . $taxonomy, $defaults['rewrite_args'] ) : array();
|
|
56
|
+
|
|
57
|
+
$labels = $this->get_taxonomy_labels();
|
|
58
|
+
|
|
59
|
+
$default_rewrite['slug'] = $taxonomy;
|
|
60
|
+
|
|
61
|
+
$description = isset( $taxonomy_args['description'] ) ? $taxonomy_args['description'] : '';
|
|
62
|
+
$public = isset( $taxonomy_args['public'] ) ? $taxonomy_args['public'] : true;
|
|
63
|
+
$publicly_queryable = isset( $taxonomy_args['publicly_queryable'] ) ? $taxonomy_args['publicly_queryable'] : $public;
|
|
64
|
+
$hierarchical = isset( $taxonomy_args['hierarchical'] ) ? $taxonomy_args['hierarchical'] : false; // true for a taxonomy like categories.
|
|
65
|
+
$show_ui = isset( $taxonomy_args['show_ui'] ) ? $taxonomy_args['show_ui'] : $public; // show in admin.
|
|
66
|
+
$show_in_menu = isset( $taxonomy_args['show_in_menu'] ) ? $taxonomy_args['show_in_menu'] : $show_ui; // Show in admin menu (as a submenu of post type).
|
|
67
|
+
$show_in_nav_menus = isset( $taxonomy_args['show_in_nav_menus'] ) ? $taxonomy_args['show_in_nav_menus'] : $public;
|
|
68
|
+
$show_in_rest = isset( $taxonomy_args['show_in_rest'] ) ? $taxonomy_args['show_in_rest'] : true; // set to false to hide in block editor.
|
|
69
|
+
$show_tagcloud = isset( $taxonomy_args['show_tagcloud'] ) ? $taxonomy_args['show_tagcloud'] : $show_ui;
|
|
70
|
+
$show_in_quick_edit = isset( $taxonomy_args['show_in_quick_edit'] ) ? $taxonomy_args['show_in_quick_edit'] : $show_ui;
|
|
71
|
+
$show_admin_column = isset( $taxonomy_args['show_admin_column'] ) ? $taxonomy_args['show_admin_column'] : $public;
|
|
72
|
+
$capabilities = isset( $taxonomy_args['capabilities'] ) ? wp_parse_args( $taxonomy_args['capabilities'], $default_capabilities ) : $default_capabilities;
|
|
73
|
+
$rewrite = isset( $taxonomy_args['rewrite'] ) ? wp_parse_args( $taxonomy_args['rewrite'], $default_rewrite ) : $default_rewrite;
|
|
74
|
+
$query_var = isset( $taxonomy_args['query_var'] ) ? $taxonomy_args['query_var'] : $taxonomy;
|
|
75
|
+
$rest_base = isset( $taxonomy_args['rest_base'] ) ? $taxonomy_args['rest_base'] : $taxonomy;
|
|
76
|
+
|
|
77
|
+
$args = array(
|
|
78
|
+
'labels' => $labels,
|
|
79
|
+
'description' => $description,
|
|
80
|
+
'public' => $public,
|
|
81
|
+
'publicly_queryable' => $publicly_queryable,
|
|
82
|
+
'hierarchical' => $hierarchical,
|
|
83
|
+
'show_ui' => $show_ui,
|
|
84
|
+
'show_in_menu' => $show_in_menu,
|
|
85
|
+
'show_in_nav_menus' => $show_in_nav_menus,
|
|
86
|
+
'show_tagcloud' => $show_tagcloud,
|
|
87
|
+
'show_in_quick_edit' => $show_in_quick_edit,
|
|
88
|
+
'show_admin_column' => $show_admin_column,
|
|
89
|
+
'capabilities' => $capabilities,
|
|
90
|
+
'rewrite' => $rewrite,
|
|
91
|
+
'query_var' => $query_var,
|
|
92
|
+
'show_in_rest' => $show_in_rest,
|
|
93
|
+
'rest_base' => $rest_base,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
$other_args = array(
|
|
97
|
+
'rest_base',
|
|
98
|
+
'rest_namespace',
|
|
99
|
+
'rest_controller_class',
|
|
100
|
+
'meta_box_cb',
|
|
101
|
+
'default_term',
|
|
102
|
+
'sort',
|
|
103
|
+
'args',
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
foreach ( $other_args as $arg ) {
|
|
107
|
+
if ( isset( $taxonomy_args[$arg] ) ) {
|
|
108
|
+
$args[$arg] = $taxonomy_args[$arg];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
register_taxonomy( $taxonomy, $taxonomy_args['post_types'], $args );
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Get taxonomy labels.
|
|
117
|
+
*
|
|
118
|
+
* @return array
|
|
119
|
+
*/
|
|
120
|
+
private function get_taxonomy_labels() {
|
|
121
|
+
$taxonomy_args = $this->args;
|
|
122
|
+
|
|
123
|
+
$labels = array(
|
|
124
|
+
'name' => $taxonomy_args['plural'],
|
|
125
|
+
'singular_name' => $taxonomy_args['singular'],
|
|
126
|
+
// translators: %s is the plural name of the taxonomy.
|
|
127
|
+
'search_items' => sprintf( __( 'Search %s', 'chisel' ), $taxonomy_args['plural'] ),
|
|
128
|
+
// translators: %s is the plural name of the taxonomy.
|
|
129
|
+
'popular_items' => sprintf( __( 'Popular %s', 'chisel' ), $taxonomy_args['plural'] ),
|
|
130
|
+
// translators: %s is the plural name of the taxonomy.
|
|
131
|
+
'all_items' => sprintf( __( 'All %s', 'chisel' ), $taxonomy_args['plural'] ),
|
|
132
|
+
// translators: %s is the singular name of the taxonomy.
|
|
133
|
+
'parent_item' => sprintf( __( 'Parent %s', 'chisel' ), $taxonomy_args['singular'] ),
|
|
134
|
+
// translators: %s is the singular name of the taxonomy.
|
|
135
|
+
'parent_item_colon' => sprintf( __( 'Parent %s:', 'chisel' ), $taxonomy_args['singular'] ),
|
|
136
|
+
// translators: %s is the singular name of the taxonomy.
|
|
137
|
+
'edit_item' => sprintf( __( 'Edit %s', 'chisel' ), $taxonomy_args['singular'] ),
|
|
138
|
+
// translators: %s is the singular name of the taxonomy.
|
|
139
|
+
'view_item' => sprintf( __( 'View %s', 'chisel' ), $taxonomy_args['singular'] ),
|
|
140
|
+
// translators: %s is the singular name of the taxonomy.
|
|
141
|
+
'update_item' => sprintf( __( 'Update %s', 'chisel' ), $taxonomy_args['singular'] ),
|
|
142
|
+
// translators: %s is the singular name of the taxonomy.
|
|
143
|
+
'add_new_item' => sprintf( __( 'Add New %s', 'chisel' ), $taxonomy_args['singular'] ),
|
|
144
|
+
// translators: %s is the singular name of the taxonomy.
|
|
145
|
+
'new_item_name' => sprintf( __( 'New %s Name', 'chisel' ), $taxonomy_args['singular'] ),
|
|
146
|
+
// translators: %s is the plural name of the taxonomy.
|
|
147
|
+
'separate_items_with_commas' => sprintf( __( 'Separate %s with commas', 'chisel' ), $taxonomy_args['plural'] ),
|
|
148
|
+
// translators: %s is the plural name of the taxonomy.
|
|
149
|
+
'add_or_remove_items' => sprintf( __( 'Add or remove %s', 'chisel' ), $taxonomy_args['plural'] ),
|
|
150
|
+
// translators: %s is the plural name of the taxonomy.
|
|
151
|
+
'choose_from_most_used' => sprintf( __( 'Choose from the most used %s', 'chisel' ), $taxonomy_args['plural'] ),
|
|
152
|
+
// translators: %s is the plural name of the taxonomy.
|
|
153
|
+
'not_found' => sprintf( __( 'No %s found', 'chisel' ), $taxonomy_args['plural'] ),
|
|
154
|
+
'no_terms' => __( 'No terms', 'chisel' ),
|
|
155
|
+
// translators: %s is the singular name of the taxonomy.
|
|
156
|
+
'filter_by_item' => sprintf( __( 'Filter by %s', 'chisel' ), $taxonomy_args['singular'] ),
|
|
157
|
+
// translators: %s is the plural name of the taxonomy.
|
|
158
|
+
'items_list_navigation' => sprintf( __( '%s list navigation', 'chisel' ), $taxonomy_args['plural'] ),
|
|
159
|
+
// translators: %s is the plural name of the taxonomy.
|
|
160
|
+
'items_list' => sprintf( __( '%s list', 'chisel' ), $taxonomy_args['plural'] ),
|
|
161
|
+
'most_used' => _x( 'Most Used', 'taxonomy', 'chisel' ),
|
|
162
|
+
// translators: %s is the plural name of the taxonomy.
|
|
163
|
+
'back_to_items' => sprintf( __( '← Back to %s', 'chisel' ), $taxonomy_args['plural'] ),
|
|
164
|
+
// translators: %s is the singular name of the taxonomy.
|
|
165
|
+
'item_link' => sprintf( __( '%s link', 'chisel' ), $taxonomy_args['singular'] ),
|
|
166
|
+
// translators: %s is the singular name of the taxonomy.
|
|
167
|
+
'item_link_description' => sprintf( __( 'A link to a %s', 'chisel' ), $taxonomy_args['singular'] ),
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
$custom_labels = isset( $taxonomy_args['labels'] ) ? $taxonomy_args['labels'] : array();
|
|
171
|
+
|
|
172
|
+
return wp_parse_args( $custom_labels, $labels );
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Chisel\Helper;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Helper functions.
|
|
7
|
+
*
|
|
8
|
+
* @package Chisel
|
|
9
|
+
*/
|
|
10
|
+
class AcfHelpers {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Get the acf field value. Acf get_field() wrapper. If ACF plugin is not active, returns false.
|
|
14
|
+
*
|
|
15
|
+
* @param string $selector
|
|
16
|
+
* @param int|bool $post_id
|
|
17
|
+
* @param bool $format_value
|
|
18
|
+
* @param bool $escape_html
|
|
19
|
+
*
|
|
20
|
+
* @return mixed
|
|
21
|
+
*/
|
|
22
|
+
public static function get_field( $selector, $post_id = false, $format_value = true, $escape_html = false ) {
|
|
23
|
+
if ( function_exists( 'get_field' ) ) {
|
|
24
|
+
return get_field( $selector, $post_id, $format_value, $escape_html );
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Update the acf field value. Acf update_field() wrapper. If ACF plugin is not active, returns false.
|
|
32
|
+
*
|
|
33
|
+
* @param string $selector
|
|
34
|
+
* @param mixed $value
|
|
35
|
+
* @param int|bool $post_id
|
|
36
|
+
*
|
|
37
|
+
* @return int|bool
|
|
38
|
+
*/
|
|
39
|
+
public static function update_field( $selector, $value, $post_id = false ) {
|
|
40
|
+
if ( function_exists( 'update_field' ) ) {
|
|
41
|
+
return update_field( $selector, $value, $post_id );
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Chisel\Helper;
|
|
4
|
+
|
|
5
|
+
use Chisel\Module\Ajax;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Helper functions.
|
|
9
|
+
*
|
|
10
|
+
* @package Chisel
|
|
11
|
+
*/
|
|
12
|
+
class AjaxHelpers {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Get custom ajax endpint
|
|
16
|
+
*
|
|
17
|
+
* @return string
|
|
18
|
+
*/
|
|
19
|
+
public static function get_ajax_endpoint_url() {
|
|
20
|
+
return sprintf( '%s/wp-json/%s/%s', esc_url( get_bloginfo( 'url' ) ), Ajax::ROUTE_NAMESPACE, Ajax::ROUTE_BASE );
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Decode json string from ajax request
|
|
25
|
+
*
|
|
26
|
+
* @param string $value
|
|
27
|
+
*
|
|
28
|
+
* @return array
|
|
29
|
+
*/
|
|
30
|
+
public static function ajax_json_decode( $value ) {
|
|
31
|
+
return (array) json_decode( stripslashes( $value ) );
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Chisel\Helper;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Helper functions.
|
|
7
|
+
*
|
|
8
|
+
* @package Chisel
|
|
9
|
+
*/
|
|
10
|
+
class AssetsHelpers {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Get the final handle for the asset.
|
|
14
|
+
*
|
|
15
|
+
* @param string $handle
|
|
16
|
+
*
|
|
17
|
+
* @return string
|
|
18
|
+
*/
|
|
19
|
+
public static function get_final_handle( $handle ) {
|
|
20
|
+
$handle = 'chisel-' . $handle;
|
|
21
|
+
|
|
22
|
+
if ( ThemeHelpers::is_fast_refresh() ) {
|
|
23
|
+
$handle .= '-fast-refresh';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return $handle;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Chisel\Helper;
|
|
4
|
+
|
|
5
|
+
use Timber\Timber;
|
|
6
|
+
use Chisel\WP\AcfBlocks;
|
|
7
|
+
use Chisel\Helper\CacheHelpers;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Helper functions.
|
|
11
|
+
*
|
|
12
|
+
* @package Chisel
|
|
13
|
+
*/
|
|
14
|
+
class BlocksHelpers {
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get block object classnames
|
|
18
|
+
*
|
|
19
|
+
* @param string $block_name
|
|
20
|
+
*
|
|
21
|
+
* @return string
|
|
22
|
+
*/
|
|
23
|
+
public static function get_block_object_classnames( $block_name ) {
|
|
24
|
+
if ( ! $block_name ) {
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
$block_name_parts = explode( '/', $block_name );
|
|
29
|
+
|
|
30
|
+
if ( empty( $block_name_parts ) || ! isset( $block_name_parts[1] ) ) {
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return 'c-block c-block--' . $block_name_parts[0] . ' c-block--' . $block_name_parts[1];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Render twig file for a block
|
|
39
|
+
*
|
|
40
|
+
* @param string $block_name
|
|
41
|
+
* @param array $context
|
|
42
|
+
*
|
|
43
|
+
* @return void
|
|
44
|
+
*/
|
|
45
|
+
public static function render_twig_file( $block_name, $context ) {
|
|
46
|
+
$block_name = explode( '/', $block_name );
|
|
47
|
+
$block_name = end( $block_name );
|
|
48
|
+
|
|
49
|
+
$twig_file = self::get_instance()->blocks_twig_base_path . $block_name . '/render.twig';
|
|
50
|
+
Timber::render( $twig_file, $context );
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Render ACF block.
|
|
55
|
+
*
|
|
56
|
+
* @param array $block The block.
|
|
57
|
+
* @param string $content The content.
|
|
58
|
+
* @param bool $is_preview Is preview.
|
|
59
|
+
* @param int $post_id The post ID.
|
|
60
|
+
*
|
|
61
|
+
* @return void
|
|
62
|
+
*/
|
|
63
|
+
public static function acf_block_render( $block, $content = '', $is_preview = false, $post_id = 0 ) {
|
|
64
|
+
$context = Timber::context();
|
|
65
|
+
|
|
66
|
+
$block_slug = str_replace( 'chisel/', '', $block['name'] );
|
|
67
|
+
|
|
68
|
+
$slug = 'b-' . $block_slug;
|
|
69
|
+
$context['block'] = $block;
|
|
70
|
+
$context['post_id'] = $post_id;
|
|
71
|
+
$context['slug'] = $slug;
|
|
72
|
+
$context['is_preview'] = $is_preview;
|
|
73
|
+
$context['fields'] = get_fields();
|
|
74
|
+
$classes = array_merge(
|
|
75
|
+
array( $slug ),
|
|
76
|
+
isset( $block['className'] ) ? array( $block['className'] ) : array(),
|
|
77
|
+
$is_preview ? array( 'is-preview' ) : array(),
|
|
78
|
+
$block['supports']['align'] ? array( 'align' . $context['block']['align'] ) : array(),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
$context['block']['class_names'] = $classes;
|
|
82
|
+
$context['block']['block_id'] = isset( $block['anchor'] ) ? $block['anchor'] : $block['id'];
|
|
83
|
+
|
|
84
|
+
// allow to use filters to manipulate the output.
|
|
85
|
+
$context = apply_filters( 'chisel_timber_acf_blocks_data', $context );
|
|
86
|
+
$context = apply_filters( 'chisel_timber_acf_blocks_data_' . $block_slug, $context );
|
|
87
|
+
$context = apply_filters( 'chisel_timber_acf_blocks_data_' . $block['id'], $context );
|
|
88
|
+
|
|
89
|
+
$context['wrapper_attributes'] = get_block_wrapper_attributes(
|
|
90
|
+
array(
|
|
91
|
+
'id' => $context['block']['block_id'],
|
|
92
|
+
'class' => implode( ' ', $context['block']['class_names'] ),
|
|
93
|
+
)
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
Timber::render( AcfBlocks::get_instance()->blocks_twig_base_path . $block_slug . '/' . $block_slug . '.twig', $context, CacheHelpers::expiry() );
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get block inline css from url. The critical.scss imported into script.js will be built into script.css.
|
|
101
|
+
*
|
|
102
|
+
* @param string $blocks_url
|
|
103
|
+
* @param string $block_name
|
|
104
|
+
*
|
|
105
|
+
* @return string
|
|
106
|
+
*/
|
|
107
|
+
public static function get_block_inline_css( $blocks_url, $block_name ) {
|
|
108
|
+
$css_url = $blocks_url . '/' . $block_name . '/script.css';
|
|
109
|
+
$response = wp_remote_get( $css_url );
|
|
110
|
+
$css = '';
|
|
111
|
+
|
|
112
|
+
if ( is_array( $response ) && ! is_wp_error( $response ) ) {
|
|
113
|
+
$css = wp_remote_retrieve_body( $response );
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return $css;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Chisel\Helper;
|
|
4
|
+
|
|
5
|
+
use Timber\Timber;
|
|
6
|
+
use Timber\Loader;
|
|
7
|
+
|
|
8
|
+
use Chisel\WP\Cache;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Image Helper functions.
|
|
12
|
+
*
|
|
13
|
+
* @package Chisel
|
|
14
|
+
*/
|
|
15
|
+
class CacheHelpers {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get the cache expiry time.
|
|
19
|
+
*
|
|
20
|
+
* @param int $custom_expiry The custom expiry time.
|
|
21
|
+
*
|
|
22
|
+
* @return int
|
|
23
|
+
*/
|
|
24
|
+
public static function expiry( $custom_expiry = null ) {
|
|
25
|
+
if ( ! Cache::get_instance()->cache_everything ) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return $custom_expiry ? $custom_expiry : Cache::get_instance()->cache_expiry;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Clear twig environment cache.
|
|
34
|
+
*
|
|
35
|
+
* @return void
|
|
36
|
+
*/
|
|
37
|
+
public static function clear_environment_cache() {
|
|
38
|
+
$loader = new Loader();
|
|
39
|
+
$loader->clear_cache_twig();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Chisel\Helper;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Helper functions.
|
|
7
|
+
*
|
|
8
|
+
* @package Chisel
|
|
9
|
+
*/
|
|
10
|
+
class CommentsHelpers {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Display comments template - the comments and the form.
|
|
14
|
+
*
|
|
15
|
+
* @return void
|
|
16
|
+
*/
|
|
17
|
+
public static function comments_template() {
|
|
18
|
+
if ( ! post_type_supports( get_post_type(), 'comments' ) ) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if ( comments_open() ) {
|
|
23
|
+
return apply_filters( 'the_content', '<!-- wp:pattern {"slug":"chisel/comments"} /-->' );
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|