@@ -10,6 +10,8 @@ class Otter_Blocks {
1010 /**
1111 * Otter_Blocks class instance.
1212 *
13+ * @since 1.0.0
14+ * @access public
1315 * @var Otter_Blocks
1416 */
1517 public static $ instance = null ;
@@ -34,23 +36,175 @@ public function __construct() {
3436 public function init () {
3537 add_action ( 'enqueue_block_assets ' , array ( $ this , 'enqueue_block_assets ' ) );
3638 add_action ( 'init ' , array ( $ this , 'load_gutenberg_blocks ' ) );
39+ add_action ( 'admin_menu ' , array ( $ this , 'register_menu_page ' ) );
40+ add_action ( 'init ' , array ( $ this , 'register_settings ' ), 99 );
41+ add_action ( 'admin_init ' , array ( $ this , 'maybe_redirect ' ) );
3742 }
3843
3944 /**
4045 * Load assets for our blocks.
46+ *
47+ * @since 1.0.0
48+ * @access public
4149 */
42- function enqueue_block_assets () {
43- wp_enqueue_style ( 'font-awesome-5 ' , plugins_url ( 'assets/fontawesome/css/all.min.css ' , __FILE__ ) );
44- wp_enqueue_style ( 'font-awesome-4-shims ' , plugins_url ( 'assets/fontawesome/css/v4-shims.min.css ' , __FILE__ ) );
50+ public function enqueue_block_assets () {
51+ if ( is_admin () || has_block ( 'themeisle-blocks/button-group ' ) || has_block ( 'themeisle-blocks/font-awesome-icons ' ) || has_block ( 'themeisle-blocks/sharing-icons ' ) || has_block ( 'themeisle-blocks/plugin-cards ' ) || has_block ( 'block ' ) ) {
52+ wp_enqueue_style ( 'font-awesome-5 ' , plugins_url ( 'assets/fontawesome/css/all.min.css ' , __FILE__ ) );
53+ wp_enqueue_style ( 'font-awesome-4-shims ' , plugins_url ( 'assets/fontawesome/css/v4-shims.min.css ' , __FILE__ ) );
54+ }
4555 }
4656
4757 /**
4858 * Load Gutenberg Blocks
59+ *
60+ * @since 1.0.0
61+ * @access public
4962 */
50- function load_gutenberg_blocks () {
63+ public function load_gutenberg_blocks () {
64+ load_plugin_textdomain ( 'otter-blocks ' , false , basename ( dirname ( __FILE__ ) ) . '/languages ' );
65+
5166 if ( class_exists ( '\ThemeIsle\GutenbergBlocks ' ) ) {
5267 \ThemeIsle \GutenbergBlocks::instance ( $ this ->name );
5368 }
69+
70+ if ( class_exists ( '\ThemeIsle\GutenbergCSS ' ) && get_option ( 'themeisle_blocks_settings_css_module ' , true ) ) {
71+ \ThemeIsle \GutenbergCSS::instance ();
72+ }
73+ }
74+
75+ /**
76+ * Register Admin Page
77+ *
78+ * @since 1.2.0
79+ * @access public
80+ */
81+ public function register_menu_page () {
82+ $ page_hook_suffix = add_options_page (
83+ __ ( 'Otter ' , 'otter-blocks ' ),
84+ __ ( 'Otter ' , 'otter-blocks ' ),
85+ 'manage_options ' ,
86+ 'otter ' ,
87+ array ( $ this , 'menu_callback ' )
88+ );
89+
90+ add_action ( "admin_print_scripts- {$ page_hook_suffix }" , array ( $ this , 'enqueue_options_assets ' ) );
91+ }
92+
93+ /**
94+ * Register Settings
95+ *
96+ * @since 1.2.0
97+ * @access public
98+ */
99+ public function register_settings () {
100+ register_setting (
101+ 'themeisle_blocks_settings ' ,
102+ 'themeisle_blocks_settings_redirect ' ,
103+ array (
104+ 'type ' => 'boolean ' ,
105+ 'description ' => __ ( 'Redirect on new install. ' , 'otter-blocks ' ),
106+ 'show_in_rest ' => true ,
107+ 'default ' => true ,
108+ )
109+ );
110+
111+ register_setting (
112+ 'themeisle_blocks_settings ' ,
113+ 'themeisle_blocks_settings_tour ' ,
114+ array (
115+ 'type ' => 'boolean ' ,
116+ 'description ' => __ ( 'Show tour for Otter. ' , 'otter-blocks ' ),
117+ 'show_in_rest ' => true ,
118+ 'default ' => true ,
119+ )
120+ );
121+
122+ register_setting (
123+ 'themeisle_blocks_settings ' ,
124+ 'themeisle_blocks_settings_css_module ' ,
125+ array (
126+ 'type ' => 'boolean ' ,
127+ 'description ' => __ ( 'Custom CSS module allows to add custom CSS to each block in Block Editor. ' , 'otter-blocks ' ),
128+ 'show_in_rest ' => true ,
129+ 'default ' => true ,
130+ )
131+ );
132+ }
133+
134+ /**
135+ * Load assets for option page.
136+ *
137+ * @since 1.2.0
138+ * @access public
139+ */
140+ public function enqueue_options_assets () {
141+ if ( OTTER_BLOCKS_DEV ) {
142+ $ version = time ();
143+ } else {
144+ $ version = OTTER_BLOCKS_VERSION ;
145+ }
146+
147+ $ tour = get_option ( 'themeisle_blocks_settings_tour ' );
148+
149+ wp_enqueue_style (
150+ 'otter-blocks-styles ' ,
151+ plugins_url ( 'build/build.css ' , __FILE__ ),
152+ array ( 'wp-components ' )
153+ );
154+
155+ wp_enqueue_script (
156+ 'otter-blocks-scripts ' ,
157+ plugins_url ( 'build/build.js ' , __FILE__ ),
158+ array ( 'react ' , 'react-dom ' , 'wp-i18n ' , 'wp-api ' , 'wp-components ' , 'wp-element ' ),
159+ $ version ,
160+ true
161+ );
162+
163+ wp_localize_script (
164+ 'otter-blocks-scripts ' , 'otterObj ' , array (
165+ 'version ' => OTTER_BLOCKS_VERSION ,
166+ 'assetsPath ' => plugins_url ( 'assets/ ' , __FILE__ ),
167+ 'showTour ' => $ tour ,
168+ )
169+ );
170+ }
171+
172+ /**
173+ * Register Admin Page
174+ *
175+ * @since 1.2.0
176+ * @access public
177+ */
178+ public function menu_callback () {
179+ echo '<div id="otter"></div> ' ;
180+ }
181+
182+ /**
183+ * Maybe redirect to dashboard page.
184+ *
185+ * @since 1.2.0
186+ * @access public
187+ */
188+ public function maybe_redirect () {
189+ if ( ! get_option ( 'themeisle_blocks_settings_redirect ' ) ) {
190+ return ;
191+ }
192+
193+ if ( defined ( 'DOING_AJAX ' ) && DOING_AJAX ) {
194+ return ;
195+ }
196+
197+ if ( is_network_admin () || isset ( $ _GET ['activate-multi ' ] ) ) {
198+ return ;
199+ }
200+
201+ if ( ! get_option ( 'themeisle_blocks_settings_tour ' ) ) {
202+ return ;
203+ }
204+
205+ update_option ( 'themeisle_blocks_settings_redirect ' , false );
206+ wp_safe_redirect ( admin_url ( 'options-general.php?page=otter ' ) );
207+ exit ;
54208 }
55209
56210 /**
0 commit comments