Skip to content

Commit 9c2ac5b

Browse files
Merge pull request #4 from colorful-tones/feature/block-wrapper-attrs
Various enhancements
2 parents 6f3f288 + 0f40794 commit 9c2ac5b

File tree

6 files changed

+41
-29
lines changed

6 files changed

+41
-29
lines changed

blocks/phone-number/block.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
"supports": {
1313
"align": false,
1414
"anchor": true,
15-
"mode": false
15+
"mode": false,
16+
"color": {
17+
"text": true,
18+
"background": true
19+
}
1620
},
1721
"example": {
1822
"attributes": {

blocks/phone-number/template.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,15 @@
1717
$block_id = esc_attr( $block['anchor'] );
1818
}
1919

20-
// Create class attribute allowing for custom "className" and "align" values.
21-
$class_name = 'demo-acf-phone-number';
22-
if ( ! empty( $block['className'] ) ) {
23-
$class_name .= ' ' . $block['className'];
24-
}
25-
2620
$phone_number = get_field( 'demo_acf_phone_number', 'options' );
27-
2821
?>
29-
<div
30-
<?php
31-
echo wp_kses_data(
32-
get_block_wrapper_attributes(
33-
array(
34-
'id' => $block_id,
35-
'class' => esc_attr( $class_name ),
36-
)
37-
)
38-
);
39-
?>
40-
>
22+
23+
<?php if ( ! $is_preview ) : ?>
24+
<div
25+
id="<?php echo esc_attr( $block_id ); ?>"
26+
<?php echo wp_kses_data( get_block_wrapper_attributes() ); ?>
27+
>
28+
<?php endif; ?>
4129

4230
<div style="display:flex;align-items:center;gap:5px;">
4331
<svg fill="currentColor" height="18" width="18" viewBox="0 0 16 16">
@@ -47,4 +35,6 @@
4735
<?php echo esc_html( $phone_number ); ?>
4836
</div>
4937

50-
</div>
38+
<?php if ( ! $is_preview ) : ?>
39+
</div>
40+
<?php endif; ?>

demo-acf-plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
// Define our handy constants.
1717
define( 'DEMO_ACF_VERSION', '0.1.2' );
18-
define( 'DEMO_ACF_PLUGIN_DIR', dirname( __FILE__ ) );
18+
define( 'DEMO_ACF_PLUGIN_DIR', __DIR__ );
1919
define( 'DEMO_ACF_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
2020
define( 'DEMO_ACF_PLUGIN_BLOCKS', DEMO_ACF_PLUGIN_DIR . '/blocks/' );
2121

includes/acf-json.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,12 @@ function demo_acf_json_save_path_for_option_pages() {
9595
*
9696
* @param string $filename The default filename.
9797
* @param array $post The main post array for the item being saved.
98-
* @param string $load_path The path that the item was loaded from.
9998
*
10099
* @return string $filename
101100
*
102101
* @since 0.1.1
103102
*/
104-
function demo_acf_json_filename( $filename, $post, $load_path ) {
103+
function demo_acf_json_filename( $filename, $post ) {
105104
$filename = str_replace(
106105
array(
107106
' ',

includes/acf-restrict-access.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@
77
/**
88
* @link https://www.advancedcustomfields.com/resources/how-to-hide-acf-menu-from-clients/
99
*/
10-
add_filter( 'acf/settings/show_admin', 'demo_acf_show_admin' );
10+
add_filter( 'acf/settings/show_admin', 'demo_acf_show_acf_admin' );
11+
/**
12+
* Filters the settings to pass to the block editor for all editor type.
13+
* @link https://developer.wordpress.org/reference/hooks/block_editor_settings_all/
14+
*/
15+
add_filter( 'block_editor_settings_all', 'demo_acf_restrict_locking_ui', 10, 2 );
1116

1217
/**
1318
* Allow access to ACF screens by WP user role
1419
* AND a list of allowed email domains.
1520
*
1621
* @link https://developer.wordpress.org/reference/functions/current_user_can/
1722
*
18-
* @param boolean $show Whether to show the ACF admin.
1923
* @return boolean $show Whether to show the ACF admin.
2024
*
2125
* @since 0.1.2
2226
*/
23-
function demo_acf_show_admin( $show ) {
27+
function demo_acf_show_admin() {
2428
// If our user can manage site options.
2529
if ( current_user_can( 'manage_options' ) ) {
2630
$user = wp_get_current_user();
@@ -34,7 +38,9 @@ function demo_acf_show_admin( $show ) {
3438
// Make sure we have a WP_User object and email address.
3539
if ( $user && isset( $user->user_email ) ) {
3640
// Trim user email to domain only.
37-
$email_domain = strtolower( array_pop( explode( '@', trim( $user->user_email ) ) ) );
41+
$email_domain = trim( $user->user_email );
42+
$email_domain = explode( '@', $email_domain );
43+
$email_domain = strtolower( array_pop( $email_domain ) );
3844

3945
// Compare current logged in user's email with our allow list.
4046
if ( in_array( $email_domain, $allowed_email_domains, true ) ) {
@@ -43,3 +49,16 @@ function demo_acf_show_admin( $show ) {
4349
}
4450
}
4551
}
52+
53+
/**
54+
* Restrict access to the locking UI to designated email domains.
55+
*
56+
* @param array $settings Default editor settings.
57+
*
58+
* @since 0.1.3
59+
*/
60+
function example_theme_restrict_locking_ui( $settings ) {
61+
$settings['canLockBlocks'] = demo_acf_show_admin();
62+
63+
return $settings;
64+
}

includes/acf-settings-page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
add_action(
99
'acf/init',
10-
function() {
10+
function () {
1111
// Add the top-level page.
1212
acf_add_options_page(
1313
array(

0 commit comments

Comments
 (0)