| 1 |
<?php |
| 2 |
|
| 3 |
namespace Tableberg; |
| 4 |
|
| 5 |
use Tableberg\Patterns\RegisterPatterns; |
| 6 |
|
| 7 |
class Assets { |
| 8 |
public function register_blocks_assets() { |
| 9 |
self::pass_data_to_js('tableberg-script'); |
| 10 |
|
| 11 |
$tableberg_patterns = RegisterPatterns::get_all_registered_tableberg_patterns(); |
| 12 |
$tableberg_pattern_categories = RegisterPatterns::get_all_registered_tableberg_pattern_categories(); |
| 13 |
|
| 14 |
wp_localize_script('tableberg-script', 'tablebergPatterns', $tableberg_patterns); |
| 15 |
wp_localize_script('tableberg-script', 'tablebergPatternCategories', $tableberg_pattern_categories); |
| 16 |
|
| 17 |
} |
| 18 |
|
| 19 |
public function register_admin_assets() { |
| 20 |
wp_enqueue_script( |
| 21 |
'tableberg-admin-script', |
| 22 |
TABLEBERG_URL . 'includes/Admin/assets/tableberg-admin.build.js', |
| 23 |
[ |
| 24 |
'lodash', |
| 25 |
'react', |
| 26 |
'wp-block-editor', |
| 27 |
'wp-blocks', |
| 28 |
'wp-components', |
| 29 |
'wp-data', |
| 30 |
'wp-element', |
| 31 |
'wp-i18n', |
| 32 |
'wp-primitives', |
| 33 |
], |
| 34 |
TABLEBERG_VERSION, |
| 35 |
true |
| 36 |
); |
| 37 |
|
| 38 |
self::pass_data_to_js('tableberg-admin-script'); |
| 39 |
|
| 40 |
$frontend_script_data = apply_filters('tableberg/filter/admin_settings_menu_data', []); |
| 41 |
wp_localize_script('tableberg-admin-script', 'tablebergAdminMenuData', $frontend_script_data); |
| 42 |
wp_enqueue_style( |
| 43 |
'tableberg-admin-style', |
| 44 |
TABLEBERG_URL . 'includes/Admin/assets/tableberg-admin-style.css', |
| 45 |
[], |
| 46 |
TABLEBERG_VERSION, |
| 47 |
'all' |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
private static function pass_data_to_js(string $handle) { |
| 53 |
$data = [ |
| 54 |
'plugin_url' => TABLEBERG_URL, |
| 55 |
]; |
| 56 |
global $tp_fs; |
| 57 |
if (isset($tp_fs)) { |
| 58 |
$data['IS_PRO'] = $tp_fs->is__premium_only() |
| 59 |
&& $tp_fs->can_use_premium_code(); |
| 60 |
} else { |
| 61 |
$data['IS_PRO'] = false; |
| 62 |
} |
| 63 |
wp_localize_script($handle, 'TABLEBERG_CFG', $data); |
| 64 |
} |
| 65 |
} |
| 66 |
|