Created
January 17, 2024 21:09
-
-
Save MadtownLems/2f66b6937105f69e810b12870cfa4a18 to your computer and use it in GitHub Desktop.
Block Visibility Modifier (Modifier Plugin Proof of Concept)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Block Visibility Modifier | |
Description: Modifies the behavior of the WP Block Visibility plugin: Removes settings page and overrides actual settings | |
Version: 1 | |
Author: Jason LeMahieu | |
Author URI: https://jasonlemahieu.com | |
*/ | |
/* Options Diagram | |
option_name = block_visibility_settings | |
- Raw from Database | |
a:3:{s:19:"visibility_controls";a:16:{s:14:"browser_device";a:1:{s:6:"enable";b:0;}s:6:"cookie";a:1:{s:6:"enable";b:0;}s:9:"date_time";a:4:{s:6:"enable";b:1;s:18:"enable_day_of_week";b:1;s:18:"enable_time_of_day";b:1;s:17:"enable_scheduling";b:1;}s:10:"hide_block";a:1:{s:6:"enable";b:1;}s:8:"location";a:1:{s:6:"enable";b:0;}s:8:"metadata";a:1:{s:6:"enable";b:0;}s:12:"query_string";a:1:{s:6:"enable";b:0;}s:15:"referral_source";a:1:{s:6:"enable";b:0;}s:11:"screen_size";a:5:{s:6:"enable";b:1;s:11:"breakpoints";a:4:{s:11:"extra_large";s:6:"1200px";s:5:"large";s:6:"1100px";s:6:"medium";s:5:"800px";s:5:"small";s:5:"576px";}s:8:"controls";a:5:{s:11:"extra_large";b:0;s:5:"large";b:1;s:6:"medium";b:1;s:5:"small";b:1;s:11:"extra_small";b:1;}s:24:"enable_advanced_controls";b:0;s:19:"enable_frontend_css";b:1;}s:8:"url_path";a:1:{s:6:"enable";b:0;}s:18:"visibility_by_role";a:4:{s:6:"enable";b:1;s:17:"enable_user_roles";b:0;s:12:"enable_users";b:0;s:21:"enable_user_rule_sets";b:0;}s:18:"visibility_presets";a:1:{s:6:"enable";b:1;}s:3:"acf";a:1:{s:6:"enable";b:0;}s:11:"woocommerce";a:2:{s:6:"enable";b:1;s:23:"enable_variable_pricing";b:1;}s:3:"edd";a:2:{s:6:"enable";b:1;s:23:"enable_variable_pricing";b:1;}s:9:"wp_fusion";a:1:{s:6:"enable";b:1;}}s:15:"disabled_blocks";a:65:{i:0;s:14:"core/paragraph";i:1;s:12:"core/heading";i:2;s:9:"core/list";i:3;s:10:"core/quote";i:4;s:9:"core/code";i:5;s:12:"core/details";i:6;s:17:"core/preformatted";i:7;s:14:"core/pullquote";i:8;s:10:"core/table";i:9;s:10:"core/verse";i:10;s:14:"core/footnotes";i:11;s:10:"core/image";i:12;s:12:"core/gallery";i:13;s:10:"core/audio";i:14;s:10:"core/cover";i:15;s:9:"core/file";i:16;s:15:"core/media-text";i:17;s:10:"core/video";i:18;s:12:"core/buttons";i:19;s:12:"core/columns";i:20;s:9:"core/more";i:21;s:14:"core/separator";i:22;s:11:"core/spacer";i:23;s:13:"core/archives";i:24;s:13:"core/calendar";i:25;s:15:"core/categories";i:26;s:9:"core/html";i:27;s:20:"core/latest-comments";i:28;s:17:"core/latest-posts";i:29;s:14:"core/page-list";i:30;s:8:"core/rss";i:31;s:11:"core/search";i:32;s:14:"core/shortcode";i:33;s:17:"core/social-links";i:34;s:14:"core/tag-cloud";i:35;s:15:"core/navigation";i:36;s:14:"core/site-logo";i:37;s:15:"core/site-title";i:38;s:17:"core/site-tagline";i:39;s:10:"core/query";i:40;s:18:"core/template-part";i:41;s:11:"core/avatar";i:42;s:15:"core/post-title";i:43;s:17:"core/post-excerpt";i:44;s:24:"core/post-featured-image";i:45;s:17:"core/post-content";i:46;s:16:"core/post-author";i:47;s:21:"core/post-author-name";i:48;s:14:"core/post-date";i:49;s:15:"core/post-terms";i:50;s:25:"core/post-navigation-link";i:51;s:14:"core/read-more";i:52;s:13:"core/comments";i:53;s:24:"core/comment-author-name";i:54;s:20:"core/comment-content";i:55;s:17:"core/comment-date";i:56;s:22:"core/comment-edit-link";i:57;s:23:"core/comment-reply-link";i:58;s:19:"core/comments-title";i:59;s:23:"core/post-comments-form";i:60;s:13:"core/loginout";i:61;s:21:"core/term-description";i:62;s:16:"core/query-title";i:63;s:26:"core/post-author-biography";i:64;s:10:"core/embed";}s:15:"plugin_settings";a:12:{s:16:"default_controls";a:0:{}s:28:"enable_contextual_indicators";b:1;s:26:"contextual_indicator_color";s:0:"";s:20:"enable_block_opacity";b:1;s:13:"block_opacity";i:80;s:23:"enable_toolbar_controls";b:0;s:21:"enable_editor_notices";b:1;s:29:"enable_user_role_restrictions";b:0;s:18:"enabled_user_roles";a:0:{}s:24:"enable_full_control_mode";b:0;s:19:"remove_on_uninstall";b:0;s:28:"enable_control_set_utilities";b:1;}} | |
https://wtools.io/unserialize-to-php-array | |
*/ | |
class EXT_Block_Visibility_Pro_Modifier { | |
function __construct() { | |
// filter the option set by Settings->Block Visibility and uses our own set of options instead | |
add_filter( 'pre_option_block_visibility_settings', array( &$this, 'filter_option_block_visibility_settings' ), 10, 2 ); | |
// remove Settings->Block Visibility administration menu | |
add_action( 'admin_menu', array( &$this, 'action_admin_menu' ), 11 ); | |
} | |
// Filter the block_visibility_settings option to use our set values instead | |
function filter_option_block_visibility_settings( $value, $option ) { | |
// set our forced site-wide defaults | |
$my_option = array ( | |
'visibility_controls' => | |
array ( | |
'browser_device' => | |
array ( | |
'enable' => false, | |
), | |
'cookie' => | |
array ( | |
'enable' => false, | |
), | |
'date_time' => | |
array ( | |
'enable' => true, | |
'enable_day_of_week' => true, | |
'enable_time_of_day' => true, | |
'enable_scheduling' => true, | |
), | |
'hide_block' => | |
array ( | |
'enable' => true, | |
), | |
'location' => | |
array ( | |
'enable' => false, | |
), | |
'metadata' => | |
array ( | |
'enable' => false, | |
), | |
'query_string' => | |
array ( | |
'enable' => false, | |
), | |
'referral_source' => | |
array ( | |
'enable' => false, | |
), | |
'screen_size' => | |
array ( | |
'enable' => true, | |
'breakpoints' => | |
array ( | |
'extra_large' => '1200px', | |
'large' => '1100px', | |
'medium' => '800px', | |
'small' => '576px', | |
), | |
'controls' => | |
array ( | |
'extra_large' => false, | |
'large' => true, | |
'medium' => true, | |
'small' => true, | |
'extra_small' => true, | |
), | |
'enable_advanced_controls' => false, | |
'enable_frontend_css' => true, | |
), | |
'url_path' => | |
array ( | |
'enable' => false, | |
), | |
'visibility_by_role' => | |
array ( | |
'enable' => true, | |
'enable_user_roles' => false, | |
'enable_users' => false, | |
'enable_user_rule_sets' => false, | |
), | |
'visibility_presets' => | |
array ( | |
'enable' => true, | |
), | |
'acf' => | |
array ( | |
'enable' => false, | |
), | |
'woocommerce' => | |
array ( | |
'enable' => true, | |
'enable_variable_pricing' => true, | |
), | |
'edd' => | |
array ( | |
'enable' => true, | |
'enable_variable_pricing' => true, | |
), | |
'wp_fusion' => | |
array ( | |
'enable' => true, | |
), | |
), | |
'disabled_blocks' => | |
array ( | |
0 => 'core/paragraph', | |
1 => 'core/heading', | |
2 => 'core/list', | |
3 => 'core/quote', | |
4 => 'core/code', | |
5 => 'core/details', | |
6 => 'core/preformatted', | |
7 => 'core/pullquote', | |
8 => 'core/table', | |
9 => 'core/verse', | |
10 => 'core/footnotes', | |
11 => 'core/image', | |
12 => 'core/gallery', | |
13 => 'core/audio', | |
14 => 'core/cover', | |
15 => 'core/file', | |
16 => 'core/media-text', | |
17 => 'core/video', | |
18 => 'core/buttons', | |
19 => 'core/columns', | |
20 => 'core/more', | |
21 => 'core/separator', | |
22 => 'core/spacer', | |
23 => 'core/archives', | |
24 => 'core/calendar', | |
25 => 'core/categories', | |
26 => 'core/html', | |
27 => 'core/latest-comments', | |
28 => 'core/latest-posts', | |
29 => 'core/page-list', | |
30 => 'core/rss', | |
31 => 'core/search', | |
32 => 'core/shortcode', | |
33 => 'core/social-links', | |
34 => 'core/tag-cloud', | |
35 => 'core/navigation', | |
36 => 'core/site-logo', | |
37 => 'core/site-title', | |
38 => 'core/site-tagline', | |
39 => 'core/query', | |
40 => 'core/template-part', | |
41 => 'core/avatar', | |
42 => 'core/post-title', | |
43 => 'core/post-excerpt', | |
44 => 'core/post-featured-image', | |
45 => 'core/post-content', | |
46 => 'core/post-author', | |
47 => 'core/post-author-name', | |
48 => 'core/post-date', | |
49 => 'core/post-terms', | |
50 => 'core/post-navigation-link', | |
51 => 'core/read-more', | |
52 => 'core/comments', | |
53 => 'core/comment-author-name', | |
54 => 'core/comment-content', | |
55 => 'core/comment-date', | |
56 => 'core/comment-edit-link', | |
57 => 'core/comment-reply-link', | |
58 => 'core/comments-title', | |
59 => 'core/post-comments-form', | |
60 => 'core/loginout', | |
61 => 'core/term-description', | |
62 => 'core/query-title', | |
63 => 'core/post-author-biography', | |
64 => 'core/embed', | |
), | |
'plugin_settings' => | |
array ( | |
'default_controls' => | |
array ( | |
), | |
'enable_contextual_indicators' => true, | |
'contextual_indicator_color' => '', | |
'enable_block_opacity' => true, | |
'block_opacity' => 80, | |
'enable_toolbar_controls' => false, | |
'enable_editor_notices' => true, | |
'enable_user_role_restrictions' => false, | |
'enabled_user_roles' => | |
array ( | |
), | |
'enable_full_control_mode' => false, | |
'remove_on_uninstall' => false, | |
'enable_control_set_utilities' => true, | |
), | |
); | |
return $my_option; | |
} | |
// Remove Settings->Block Visibility | |
function action_admin_menu() { | |
remove_submenu_page( 'options-general.php', 'block-visibility-settings' ); | |
} | |
} // end class | |
$instance = new EXT_Block_Visibility_Pro_Modifier; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment