-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathjsforwp-how-to-gutenberg.php
109 lines (90 loc) · 2.86 KB
/
jsforwp-how-to-gutenberg.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* Plugin Name: Gutenberg - How to Register a Block
* Plugin URI: https://gutenberg.courses
* Description: An plugin for learing how Gutenberg blocks work. From <a href="https://gutenberg.courses">Zac Gordon's Gutenberg Course</a>.
* Text Domain: jsforwphowto
* Domain Path: /languages
* Author: Zac Gordon
* Author URI: https://zacgordon.com
* Version: 2.1.0
* License: GPL2+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*
* @package jsforwphowto
*/
// Exit if accessed directly.
defined('ABSPATH') || exit;
// Only load if Gutenberg is available.
if ( ! function_exists( 'register_block_type' ) ) {
return;
}
function jsforwphowto_templates( $args, $post_type ) {
if ( $post_type == 'post' ) {
$args['template_lock'] = true;
$args['template'] = [
[
'core/image', [
'align' => 'left',
]
],
[
'core/paragraph', [
'placeholder' => 'The only thing you can add',
]
]
];
}
return $args;
}
//add_filter( 'register_post_type_args', 'jsforwphowto_templates', 20, 2 );
/**
* Enqueue block editor only JavaScript and CSS
*/
function jsforwphowto_editor_scripts()
{
// Make paths variables so we don't write em twice ;)
$blockPath = '/assets/js/editor.blocks.js';
$editorStylePath = '/assets/css/blocks.editor.css';
// Enqueue the bundled block JS file
wp_enqueue_script(
'jsforwphowto-blocks-js',
plugins_url( $blockPath, __FILE__ ),
[ 'wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-editor' ],
filemtime( plugin_dir_path(__FILE__) . $blockPath )
);
// Enqueue optional editor only styles
wp_enqueue_style(
'jsforwphowto-blocks-editor-css',
plugins_url( $editorStylePath, __FILE__),
[],
filemtime( plugin_dir_path( __FILE__ ) . $editorStylePath )
);
}
// Hook scripts function into block editor hook
add_action( 'enqueue_block_editor_assets', 'jsforwphowto_editor_scripts' );
/**
* Enqueue front end and editor JavaScript and CSS
*/
function jsforwphowto_scripts()
{
$blockPath = '/assets/js/frontend.blocks.js';
// Make paths variables so we don't write em twice ;)
$stylePath = '/assets/css/blocks.style.css';
// Enqueue the bundled block JS file
wp_enqueue_script(
'jsforwphowto-blocks-frontend-js',
plugins_url( $blockPath, __FILE__ ),
[ 'wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-api', 'wp-editor' ],
filemtime( plugin_dir_path(__FILE__) . $blockPath )
);
// Enqueue frontend and editor block styles
wp_enqueue_style(
'jsforwphowto-blocks-css',
plugins_url($stylePath, __FILE__),
null,
filemtime(plugin_dir_path(__FILE__) . $stylePath )
);
}
// Hook scripts function into block editor hook
add_action('enqueue_block_assets', 'jsforwphowto_scripts');