PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.2
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / settings / index.php

index.php in Block Animations, Motion & Scroll Effects – Ghost Kit 3.7.2, at settings/index.php

236 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Additional PHP for blocks.
4 *
5 * @package ghostkit
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * GhostKit_Settings
14 */
15 class GhostKit_Settings {
16 /**
17 * GhostKit_Settings constructor.
18 */
19 public function __construct() {
20 // Load admin style sheet and JavaScript.
21 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
22
23 // Sometimes redirect is not working on page opens. Admin Init is a solution.
24 add_action( 'admin_init', array( $this, 'go_pro_redirect' ) );
25
26 // Add the options page and menu item.
27 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
28 }
29
30 /**
31 * Register and enqueue admin-specific style sheet.
32 */
33 public function admin_enqueue_scripts() {
34 $screen = get_current_screen();
35
36 GhostKit_Assets::enqueue_style(
37 'ghostkit-admin',
38 'build/assets/admin/css/admin',
39 array(),
40 filemtime( ghostkit()->plugin_path . 'build/assets/admin/css/admin.css' )
41 );
42 wp_style_add_data( 'ghostkit-admin', 'rtl', 'replace' );
43
44 GhostKit_Assets::enqueue_style(
45 'ghostkit-settings',
46 'build/settings/style',
47 array(),
48 filemtime( ghostkit()->plugin_path . 'build/settings/style.css' )
49 );
50 wp_style_add_data( 'ghostkit-settings', 'rtl', 'replace' );
51
52 if ( 'toplevel_page_ghostkit' !== $screen->id ) {
53 return;
54 }
55
56 $block_editor_context = new WP_Block_Editor_Context();
57
58 // Preload server-registered block schemas.
59 wp_add_inline_script(
60 'wp-blocks',
61 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
62 );
63
64 wp_add_inline_script(
65 'wp-blocks',
66 sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $block_editor_context ) ) ),
67 'after'
68 );
69
70 // The settings page is not a block editor screen, but it boots the block editor
71 // scripts, so callbacks that check this flag have to see the editor context.
72 add_filter( 'should_load_block_editor_scripts_and_styles', '__return_true' );
73
74 // phpcs:ignore
75 do_action( 'enqueue_block_editor_assets' );
76
77 // phpcs:ignore
78 do_action( 'enqueue_block_assets' );
79
80 remove_filter( 'should_load_block_editor_scripts_and_styles', '__return_true' );
81
82 // Ghost Kit Settings.
83 GhostKit_Assets::enqueue_script(
84 'ghostkit-settings',
85 'build/settings/index',
86 array( 'ghostkit-helper' )
87 );
88
89 wp_localize_script(
90 'ghostkit-settings',
91 'ghostkitSettingsData',
92 array(
93 'api_nonce' => wp_create_nonce( 'wp_rest' ),
94 'api_url' => rest_url( 'ghostkit/v1/' ),
95 )
96 );
97
98 wp_enqueue_style( 'wp-components' );
99
100 if ( function_exists( 'wp_enqueue_media' ) ) {
101 wp_enqueue_media();
102 }
103 }
104
105 /**
106 * Go Pro.
107 * Redirect to the Pro purchase page.
108 */
109 public function go_pro_redirect() {
110 // phpcs:ignore
111 if ( ! isset( $_GET['page'] ) || empty( $_GET['page'] ) ) {
112 return;
113 }
114
115 // phpcs:ignore
116 if ( 'ghostkit_go_pro' === $_GET['page'] ) {
117 $medium = 'admin_menu';
118
119 // phpcs:ignore
120 if ( isset( $_GET['utm_medium'] ) ) {
121 // phpcs:ignore
122 $medium = $_GET['utm_medium'];
123 }
124
125 // phpcs:ignore
126 wp_redirect( ghostkit()->go_pro_link() . '?utm_source=plugin&utm_medium=' . esc_attr( $medium ) . '&utm_campaign=go_pro&utm_content=' . GHOSTKIT_VERSION );
127 exit();
128 }
129 }
130
131 /**
132 * Add admin menu.
133 */
134 public function admin_menu() {
135 add_menu_page(
136 esc_html__( 'Ghost Kit', 'ghostkit' ),
137 esc_html__( 'Ghost Kit', 'ghostkit' ),
138 'manage_options',
139 'ghostkit',
140 array( $this, 'display_admin_page' ),
141 // phpcs:ignore
142 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( ghostkit()->plugin_path . 'assets/images/admin-icon.svg' ) ),
143 56.9
144 );
145
146 add_submenu_page(
147 'ghostkit',
148 '',
149 esc_html__( 'Blocks', 'ghostkit' ),
150 'manage_options',
151 'ghostkit'
152 );
153 add_submenu_page(
154 'ghostkit',
155 '',
156 esc_html__( 'Icons', 'ghostkit' ),
157 'manage_options',
158 'admin.php?page=ghostkit&sub_page=icons'
159 );
160 add_submenu_page(
161 'ghostkit',
162 '',
163 esc_html__( 'Typography', 'ghostkit' ),
164 'manage_options',
165 'admin.php?page=ghostkit&sub_page=typography'
166 );
167 add_submenu_page(
168 'ghostkit',
169 '',
170 esc_html__( 'Fonts', 'ghostkit' ),
171 'manage_options',
172 'admin.php?page=ghostkit&sub_page=fonts'
173 );
174 add_submenu_page(
175 'ghostkit',
176 '',
177 esc_html__( 'Breakpoints', 'ghostkit' ),
178 'manage_options',
179 'admin.php?page=ghostkit&sub_page=breakpoints'
180 );
181 add_submenu_page(
182 'ghostkit',
183 '',
184 esc_html__( 'CSS & JavaScript', 'ghostkit' ),
185 'manage_options',
186 'admin.php?page=ghostkit&sub_page=css_js'
187 );
188
189 if ( GhostKit_Templates::is_allowed() ) {
190 add_submenu_page(
191 'ghostkit',
192 '',
193 esc_html__( 'Templates', 'ghostkit' ),
194 'manage_options',
195 'edit.php?post_type=ghostkit_template'
196 );
197 }
198
199 add_submenu_page(
200 'ghostkit',
201 '',
202 '<span class="dashicons dashicons-star-filled" style="font-size: 17px"></span> ' . esc_html__( 'Go Pro', 'ghostkit' ),
203 'manage_options',
204 'ghostkit_go_pro',
205 array( $this, 'go_pro_redirect' )
206 );
207
208 global $wp_version;
209
210 // Since WP 6.3 user have an ability to open the reusable blocks page
211 // From the Appearance -> Editor -> Patterns.
212 if ( ! version_compare( $wp_version, '6.3', '>=' ) ) {
213 add_menu_page(
214 esc_html__( 'Reusable Blocks', 'ghostkit' ),
215 esc_html__( 'Reusable Blocks', 'ghostkit' ),
216 'read',
217 'edit.php?post_type=wp_block',
218 '',
219 'dashicons-editor-table',
220 57
221 );
222 }
223 }
224
225 /**
226 * Render the admin page.
227 */
228 public function display_admin_page() {
229 ?>
230 <div class="ghostkit-admin-page"></div>
231 <?php
232 }
233 }
234
235 new GhostKit_Settings();
236