PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
← All changes | includes/Assets.php +67 -76 0.3.21.1.5 View file →
@@ -1,82 +1,73 @@
1 1 <?php
2 2
3 -/**
4 - * The file register assets for the plugin
5 - *
6 - * @package Tableberg
7 - */
3 +namespace Tableberg;
8 4
9 -namespace Tableberg;
5 +use Tableberg\Patterns\RegisterPatterns;
10 6
11 -/**
12 - * Handle plugin assets
13 - */
14 7 class Assets {
15 - /**
16 - * Register blocks assets
17 - */
18 - public function register_blocks_assets() {
19 - wp_register_script(
20 - 'tableberg-script',
21 - TABLEBERG_URL . 'build/tableberg.build.js',
22 - array(
23 - 'lodash',
24 - 'react',
25 - 'wp-block-editor',
26 - 'wp-blocks',
27 - 'wp-components',
28 - 'wp-data',
29 - 'wp-element',
30 - 'wp-i18n',
31 - 'wp-primitives',
32 - ),
33 - Constants::plugin_version(),
34 - false
35 - );
36 - wp_register_style(
37 - 'tableberg-editor-style',
38 - TABLEBERG_URL . 'build/tableberg-editor-style.css',
39 - array(),
40 - Constants::plugin_version(),
41 - false
42 - );
43 - wp_register_style(
44 - 'tableberg-style',
45 - TABLEBERG_URL . 'build/tableberg-frontend-style.css',
46 - array(),
47 - Constants::plugin_version(),
48 - false
49 - );
50 - }
51 - /**
52 - * Enqueue Admin assets
53 - */
54 - public function register_admin_assets() {
55 - wp_enqueue_script(
56 - 'tableberg-admin-script',
57 - TABLEBERG_URL . 'build/tableberg-admin.build.js',
58 - array(
59 - 'lodash',
60 - 'react',
61 - 'wp-block-editor',
62 - 'wp-blocks',
63 - 'wp-components',
64 - 'wp-data',
65 - 'wp-element',
66 - 'wp-i18n',
67 - 'wp-primitives',
68 - ),
69 - Constants::plugin_version(),
70 - true
71 - );
72 - $frontend_script_data = apply_filters('tableberg/filter/admin_settings_menu_data', array());
73 - wp_localize_script('tableberg-admin-script', 'tablebergAdminMenuData', $frontend_script_data);
74 - wp_enqueue_style(
75 - 'tableberg-admin-style',
76 - TABLEBERG_URL . 'build/tableberg-admin-style.css',
77 - array(),
78 - Constants::plugin_version(),
79 - 'all'
80 - );
81 - }
8 + /**
9 + * The frontend view script gates pro features (sorting/search/pagination)
10 + * on TABLEBERG_CFG.IS_PRO, so the config must exist on the frontend too.
11 + */
12 + public function register_frontend_assets() {
13 + self::pass_data_to_js('tableberg-table-view-script');
14 + }
15 +
16 + public function register_blocks_assets() {
17 + self::pass_data_to_js('tableberg-table-editor-script');
18 +
19 + $tableberg_patterns = RegisterPatterns::get_all_registered_tableberg_patterns();
20 + $tableberg_pattern_categories = RegisterPatterns::get_all_registered_tableberg_pattern_categories();
21 +
22 + wp_localize_script('tableberg-table-editor-script', 'tablebergPatterns', $tableberg_patterns);
23 + wp_localize_script('tableberg-table-editor-script', 'tablebergPatternCategories', $tableberg_pattern_categories);
24 +
25 + }
26 +
27 + public function register_admin_assets() {
28 + wp_enqueue_script(
29 + 'tableberg-admin-script',
30 + TABLEBERG_URL . 'includes/Admin/assets/tableberg-admin.build.js',
31 + [
32 + 'lodash',
33 + 'react',
34 + 'wp-block-editor',
35 + 'wp-blocks',
36 + 'wp-components',
37 + 'wp-data',
38 + 'wp-element',
39 + 'wp-i18n',
40 + 'wp-primitives',
41 + ],
42 + TABLEBERG_VERSION,
43 + true
44 + );
45 +
46 + self::pass_data_to_js('tableberg-admin-script');
47 +
48 + $frontend_script_data = apply_filters('tableberg/filter/admin_settings_menu_data', []);
49 + wp_localize_script('tableberg-admin-script', 'tablebergAdminMenuData', $frontend_script_data);
50 + wp_enqueue_style(
51 + 'tableberg-admin-style',
52 + TABLEBERG_URL . 'includes/Admin/assets/tableberg-admin-style.css',
53 + [],
54 + TABLEBERG_VERSION,
55 + 'all'
56 + );
57 + }
58 +
59 +
60 + private static function pass_data_to_js(string $handle) {
61 + $data = [
62 + 'plugin_url' => TABLEBERG_URL,
63 + // Pro marks this true only after its licence check succeeds and
64 + // its runtime extensions actually boot. The version constant only
65 + // proves that the add-on PHP file was loaded.
66 + 'IS_PRO' => (bool) apply_filters(
67 + 'tableberg/is_pro_runtime_active',
68 + false
69 + ),
70 + ];
71 + wp_localize_script($handle, 'TABLEBERG_CFG', $data);
72 + }
82 73 }