Skip to content

Commit

Permalink
Add options in Settings > Writing screen to allow admin disable Edit …
Browse files Browse the repository at this point in the history
…and Convert reusable blocks buttons in block overlay.
  • Loading branch information
MarieComet committed Jun 5, 2022
1 parent d713cf3 commit bb0d9cb
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 27 deletions.
Binary file added .wordpress-org/screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wp-element', 'wp-reusable-blocks'), 'version' => '8238108c0206a600fe2b306650629ffe');
<?php return array('dependencies' => array('wp-element', 'wp-reusable-blocks'), 'version' => '0db53a080c593b7091ea139c202ab14b');
17 changes: 15 additions & 2 deletions build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/index.js.map

Large diffs are not rendered by default.

Binary file modified languages/lock-reusable-blocks-fr_FR.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion languages/lock-reusable-blocks-fr_FR.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2022-03-19T08:57:45+01:00\n"
"PO-Revision-Date: 2022-03-19 08:58+0100\n"
"PO-Revision-Date: 2022-06-05 20:20+0100\n"
"Language: fr_FR\n"
"X-Generator: Poedit 2.3\n"
"X-Domain: lock-reusable-blocks\n"
Expand Down
66 changes: 65 additions & 1 deletion lock-reusable-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Description: Lock Reusable Blocks in the editor to avoid unintentional global changes.
* Requires at least: 5.8
* Requires PHP: 7.0
* Version: 0.3.0
* Version: 0.4.0
* Author: Marie Comet
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand All @@ -29,6 +29,66 @@ function lrb_include_files() {
load_plugin_textdomain( 'lock-reusable-blocks', false, basename( dirname( __FILE__ ) ) . '/languages/' );
}

/**
* Add custom settings in Writing admin screen
*/
add_action( 'admin_init', 'lrb_admin_settings' );
function lrb_admin_settings() {
add_settings_section(
'lrb_options_section',
__( 'Lock Reusable Blocks', 'lrb' ),
'lrb_options_section_cb',
'writing'
);
register_setting( 'writing', 'hide_convert_reusable_block_button' );
register_setting( 'writing', 'hide_edit_reusable_block_button' );
add_settings_field(
'hide_convert_reusable_block_button',
__( 'Hide "Convert to regular blocks" button', 'lrb' ),
'lrb_options_hide_convert_button_cb',
'writing',
'lrb_options_section',
);
add_settings_field(
'hide_edit_reusable_block_button',
__( 'Hide "Edit reusable block" button', 'lrb' ),
'lrb_options_hide_edit_button_cb',
'writing',
'lrb_options_section',
);
}

/**
* Render custom section in Writing admin screen
*/
function lrb_options_section_cb() {
printf(
'<p>%s</p>',
__( 'Settings related to Lock Reusable Blocks feature', 'lrb' )
);
}

/**
* Render checkbox setting in Writing admin screen
*/
function lrb_options_hide_convert_button_cb() {
printf(
'<input type="checkbox" id="hide_convert_reusable_block_button" name="hide_convert_reusable_block_button" value="1" %s />',
get_option('hide_convert_reusable_block_button') == '1' ? 'checked="checked"' : ''
);
}

function lrb_options_hide_edit_button_cb() {
printf(
'<input type="checkbox" id="hide_edit_reusable_block_button" name="hide_edit_reusable_block_button" value="1" %s />',
get_option('hide_edit_reusable_block_button') == '1' ? 'checked="checked"' : ''
);
}


/**
* Enqueue admin scripts
*/
function lrb_gutenberg_editor_scripts() {
wp_enqueue_style(
'lrb-gutenberg',
Expand All @@ -42,6 +102,10 @@ function lrb_gutenberg_editor_scripts() {
LRB_VERSION
);
wp_enqueue_script( 'lrb-editor-script' );
wp_localize_script( 'lrb-editor-script', 'lrb', [
'hide_convert_button' => get_option( 'hide_convert_reusable_block_button', '' ),
'hide_edit_button' => get_option( 'hide_edit_reusable_block_button', '' )
] );
wp_set_script_translations( 'lrb-editor-script', 'lock-reusable-blocks', LRB_PATH . '/languages/' );
}
add_action( 'enqueue_block_editor_assets', 'lrb_gutenberg_editor_scripts' );
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ Editing reusable blocks in posts is locked, and you have access to two actions w
- Edit the reusable block (opens the block editing page in a new tab)
- Convert to regular blocks (native action)

Options are availables in Settings > Writing screen to hide Edit and Convert reusable blocks buttons in block overlay.

![image](https://user-images.githubusercontent.com/7976501/168146661-c48f4f25-f83b-41f9-99a4-cf397539d3eb.png)
22 changes: 20 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: chaton666
Tags: lock, reusable, block
Requires at least: 5.0
Tested up to: 6.0
Stable tag: 0.3.0
Stable tag: 0.4.0
License: GPL v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.txt

Expand All @@ -16,6 +16,24 @@ Editing reusable blocks in posts is locked, and you have access to two actions w
- Edit the reusable block (opens the block editing page in a new tab)
- Convert to regular blocks (native action)

Options are availables in Settings > Writing screen to hide Edit and Convert reusable blocks buttons in block overlay.

== Screenshots ==

1. Reusable Block locked in the editor.
1. Reusable Block locked in the editor.
2. Settings screen.

== Changelog ==

= 0.4.0 =
* Add options in Settings > Writing screen to allow admin disable Edit and Convert reusable blocks buttons in block overlay.
Props to @btxtiger for the idea.

= 0.3.0 =
* Convert to regular blocks button: switch to primary style

= 0.2.0 =
* Add button to convert reusable block to regular blocks

= 0.1.0 =
* First release
52 changes: 33 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,46 @@ import './style.scss';

if ( props.isSelected && isReusableBlock( props ) && attributes.ref ) {

let showConvert = true, showEdit = true;
if ( typeof lrb !== 'undefined' ) {
if ( lrb.hide_convert_button && '1' === lrb.hide_convert_button ) {
showConvert = false;
}
if ( lrb.hide_edit_button && '1' === lrb.hide_edit_button ) {
showEdit = false;
}
}

const {
__experimentalConvertBlockToStatic: convertBlockToStatic,
} = useDispatch( reusableBlocksStore );

return (
<div className="wp-block wp-reusable-block-locked">
<div className="wp-reusable-block-locked__wrapper">
<Button
variant="primary"
className="wp-reusable-block-locked__edit-link"
href={ addQueryArgs( 'post.php', {
post: attributes.ref,
action: 'edit'
} ) }
target="_blank"
rel="noopener noreferrer"
>
{ __( 'Edit reusable block', 'lock-reusable-blocks' ) }
</Button>
<Button
onClick={ () => convertBlockToStatic( clientId ) }
variant="primary"
className="wp-reusable-block-locked__convert-link"
>
{ __( 'Convert to regular blocks', 'lock-reusable-blocks' ) }
</Button>
{ showConvert &&
<Button
variant="primary"
className="wp-reusable-block-locked__edit-link"
href={ addQueryArgs( 'post.php', {
post: attributes.ref,
action: 'edit'
} ) }
target="_blank"
rel="noopener noreferrer"
>
{ __( 'Edit reusable block', 'lock-reusable-blocks' ) }
</Button>
}
{ showEdit &&
<Button
onClick={ () => convertBlockToStatic( clientId ) }
variant="primary"
className="wp-reusable-block-locked__convert-link"
>
{ __( 'Convert to regular blocks', 'lock-reusable-blocks' ) }
</Button>
}
</div>
<BlockEdit { ...props } />
</div>
Expand Down

0 comments on commit bb0d9cb

Please sign in to comment.