get_option( 'dgb_disabled_blocks', array() ),
'nonce' => wp_create_nonce( 'dgb_nonce' ),
);
$block_registry = WP_Block_Type_Registry::get_instance();
foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
// Front-end script.
if ( ! empty( $block_type->editor_script ) ) {
wp_enqueue_script( $block_type->editor_script );
}
}
wp_enqueue_script( 'dgb-admin', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery', 'wp-blocks', 'wp-element', 'wp-data', 'wp-components', 'wp-block-library' ), '1.1.0' );
wp_localize_script( 'dgb-admin', 'dgb_object', $local_arr );
wp_localize_script(
'dgb-admin',
'dgb_strings',
array(
'enable' => __( 'Enabled', 'disable_affiliate_booster_blocks' ),
'disable' => __( 'Disabled', 'disable_affiliate_booster_blocks' ),
)
);
}
/**
* [disable_gutenberg_blocks_add_menu description]
*/
public function register_sub_menu() {
add_submenu_page(
'options-general.php',
esc_html__( 'Enable/Disable Affiliate Booster Blocks', 'disable_affiliate_booster_blocks' ),
esc_html__( 'Enable/Disable Affiliate Booster Blocks', 'disable_affiliate_booster_blocks' ),
'activate_plugins',
'affiliate_booster_blocks',
array( $this, 'submenu_page_callback' )
);
}
/**
* [admin description]
*/
public function submenu_page_callback() {
$table = new ABDGB_List_Table();
$table->prepare_items();
?>
Buy Now
Enable & Disable Blocks
We have more than 25 blocks in AffiliateBooster. The good news is, you can disable the blocks which you do not want. This will improve the speed of your blog and you will have less clutter.
Note: If you have added the block previously, and disable the block here, you previously added block will stop working; so please enable/disable carefully.
$value) {
$this->disable_block( $value );
}
}
if(isset($_POST['enable']) && $_POST['enable'] == 'Enabled All'){
foreach ($allblocks as $key => $value) {
$this->enable_block( $value );
}
}
wp_safe_redirect( admin_url( 'options-general.php?page=affiliate_booster_blocks' ) );
exit();
}
// Detect when a bulk action is being triggered...
if ( isset( $_GET['action'] ) && 'disable' === $_GET['action'] ) {
// In our file that handles the request, verify the nonce.
$nonce = ( isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '' );
$block = ( isset( $_GET['block'] ) ? sanitize_text_field( wp_unslash( $_GET['block'] ) ) : '' );
if ( ! wp_verify_nonce( $nonce, 'dgb_nonce' ) ) {
die( 'Not today.' );
} else {
$this->disable_block( $block );
wp_safe_redirect( admin_url( 'options-general.php?page=affiliate_booster_blocks' ) );
exit();
}
}
// Detect when a bulk action is being triggered...
if ( isset( $_GET['action'] ) && 'enable' === $_GET['action'] ) {
// In our file that handles the request, verify the nonce.
$nonce = ( isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '' );
$block = ( isset( $_GET['block'] ) ? sanitize_text_field( wp_unslash( $_GET['block'] ) ) : '' );
if ( ! wp_verify_nonce( $nonce, 'dgb_nonce' ) ) {
die( 'Not today.' );
} else {
$this->enable_block( $block );
}
wp_safe_redirect( admin_url( 'options-general.php?page=affiliate_booster_blocks' ) );
exit();
}
// If the disable enable action is triggered.
if ( ( isset( $_POST['action'] ) && 'bulk-enable' === $_POST['action'] )
|| ( isset( $_POST['action2'] ) && 'bulk-enable' === $_POST['action2'] )
) {
$bulk_change_ids = ( isset( $_POST['bulk-change'] ) ? $_POST['bulk-change'] : array() );
// loop over the array of record IDs and enable them.
foreach ( $bulk_change_ids as $id ) {
$this->enable_block( $id );
}
}
// If the disable bulk action is triggered.
if ( ( isset( $_POST['action'] ) && 'bulk-disable' === $_POST['action'] )
|| ( isset( $_POST['action2'] ) && 'bulk-disable' === $_POST['action2'] )
) {
$bulk_change_ids = ( isset( $_POST['bulk-change'] ) ? $_POST['bulk-change'] : array() );
// loop over the array of record IDs and disable them.
foreach ( $bulk_change_ids as $id ) {
$this->disable_block( $id );
}
}
}
/**
* [disable_block description]
*
* @param string $name Name of block to disable.
*/
public function disable_block( $name ) {
$blocks = (array) get_option( 'dgb_disabled_blocks', array() );
$name = sanitize_text_field( $name );
if ( ! in_array( $name, $blocks, true ) ) {
array_push( $blocks, $name );
}
update_option( 'dgb_disabled_blocks', $blocks );
}
/**
* [disable_block description]
*
* @param string $name Name of block to enable.
*/
public function enable_block( $name ) {
$blocks = (array) get_option( 'dgb_disabled_blocks', array() );
$new_blocks = array();
$name = sanitize_text_field( $name );
if ( in_array( $name, $blocks, true ) ) {
$new_blocks = array_diff( $blocks, array( $name ) );
}
update_option( 'dgb_disabled_blocks', $new_blocks );
}
}
new ABDGB_Admin_Page();