Skip to content

Instantly share code, notes, and snippets.

@stirtingale
Last active August 24, 2022 20:34
Show Gist options
  • Save stirtingale/e6008d230335790ffd8d5b310780e383 to your computer and use it in GitHub Desktop.
Save stirtingale/e6008d230335790ffd8d5b310780e383 to your computer and use it in GitHub Desktop.
Limit ACF field to edit only
<?php
if (isset($block['data']['preview_image_help'])):
$image = get_template_directory_uri() . '/blocks/previews/' . basename(__FILE__, '.php') . '.png';
echo '<img src="' . $image . '" style="width:100%; height:auto;">';
else:
?>
Front End Content
<?php
endif; // preview_image_help
?>
add_action('acf/init', 'block_blockname');
function block_blockname() {
// check function exists.
if( function_exists('acf_register_block_type') ) {
acf_register_block_type(array(
'name' => 'blockname',
'title' => __('Block Name'),
'icon' => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M22 0h-20v6h1.999c0-1.174.397-3 2.001-3h4v16.874c0 1.174-.825 2.126-2 2.126h-1v2h9.999v-2h-.999c-1.174 0-2-.952-2-2.126v-16.874h4c1.649 0 2.02 1.826 2.02 3h1.98v-6z"/></svg>',
'render_template' => 'blocks/block-file.php',
'category' => 'XYZ',
'mode' => 'edit',
'supports' => array(
'align' => false,
'multiple' => true,
),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'preview_image_help' => true,
)
)
)
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment