-
Notifications
You must be signed in to change notification settings - Fork 1
/
useful-block-styles.php
99 lines (85 loc) · 2.55 KB
/
useful-block-styles.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
<?php
/**
* Plugin Name: Useful Block Styles
* Description: A simple plugin to register Block Styles that you'd want on any site with the WordPress block editor. Includes Multicolumn and marker-less lists and Button-only File block.
* Author: Mark Root-Wiley, Ryan Tvenge
* Plugin URI: https://github.com/mrwweb/useful-block-styles
* Text Domain: useful-block-styles
* Version: 0.3.1
*
* @package Useful_Block_Styles
*/
namespace WPSea\BlockStyles;
/**
* Get the full list of block styles registered by the plugin. Enables filtering the list (to hide one or more styles) with `wpsea_block_styles` filter
*
* @return array nested array where value keys are block slugs and values are an array of user-readable style names
*/
function get_block_styles()
{
$block_styles = array(
'core/heading' => array(
'Screen Reader Text'
),
'core/list' => array(
'No Markers',
'Multicolumn',
'Multicolumn No Markers'
),
'core/file' => array(
'Button Only',
),
'core/gallery' => array(
'Not Stretched',
'Centered Not Stretched',
'Small Logos',
'Small Grayscale Logos',
),
);
return apply_filters('wpsea_block_styles', $block_styles);
}
add_action('init', 'WPSea\BlockStyles\register_block_styles');
/**
* Registers all block styles with the block editor
*/
function register_block_styles()
{
$block_styles = get_block_styles();
foreach ($block_styles as $block => $styles) {
foreach ($styles as $style) {
register_block_style(
$block,
array(
'name' => 'useful-' . sanitize_title_with_dashes($style, null, 'save'),
'label' => esc_html($style),
)
);
}
}
}
add_action('wp_enqueue_scripts', 'WPSea\BlockStyles\front_end_assets', 9);
/**
* Enqueue front-end block stylesheet. Registered with priority 9 so it will generally come before theme stylesheets.
*/
function front_end_assets()
{
wp_enqueue_style(
'useful-block-styles',
plugin_dir_url(__FILE__) . 'css/useful-block-styles.css',
array('wp-block-library'),
filemtime(plugin_dir_path(__FILE__) . 'css/useful-block-styles.css'),
);
}
add_action('enqueue_block_editor_assets', 'WPSea\BlockStyles\block_editor_assets', 9);
/**
* Enqueue block editor stylesheet. Registered with priority 9 so it will generally come before theme stylesheets.
*/
function block_editor_assets()
{
wp_enqueue_style(
'useful-block-styles-editor-styles',
plugin_dir_url(__FILE__) . 'css/useful-block-styles-editor-styles.css',
array(),
filemtime(plugin_dir_path(__FILE__) . 'css/useful-block-styles-editor-styles.css')
);
}