| 1 |
<?php |
| 2 |
/** |
| 3 |
* BPLDE Gutenberg Blocks registration class. |
| 4 |
* |
| 5 |
* @package DocumentEmbedder |
| 6 |
*/ |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
if (!class_exists('BPLDE_Block')) { |
| 13 |
class BPLDE_Block { |
| 14 |
public function __construct() { |
| 15 |
add_action('init', [$this, 'init']); |
| 16 |
add_action('enqueue_block_assets', [$this, 'bplde_block_assets']); |
| 17 |
} |
| 18 |
|
| 19 |
public function init() |
| 20 |
{ |
| 21 |
wp_register_script('ppv-blocks', BPLDE_PLUGIN_DIR . 'build/editor.js', array('wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'jquery'), BPLDE_VER, true); |
| 22 |
|
| 23 |
wp_localize_script('ppv-blocks', 'ppvBlocks', [ |
| 24 |
'siteUrl' => site_url(), |
| 25 |
'ajaxUrl' => admin_url('admin-ajax.php'), |
| 26 |
'ppv_nonce' => wp_create_nonce('ppv_secret_nonce') |
| 27 |
]); |
| 28 |
|
| 29 |
register_block_type(BPLDE_PLUGIN_PATH . 'build/blocks/document-embedder'); |
| 30 |
|
| 31 |
register_block_type('kahf-kit/kahf-banner-k27f', array( |
| 32 |
'editor_script' => 'ppv-blocks', |
| 33 |
'render_callback' => function ($attr, $content) { |
| 34 |
return wpautop($content); |
| 35 |
} |
| 36 |
)); |
| 37 |
|
| 38 |
// Document library block registration |
| 39 |
register_block_type(BPLDE_PLUGIN_PATH . 'build/blocks/document-library'); |
| 40 |
wp_set_script_translations('document-emberdder', 'document-library', plugin_dir_path(BPLDE__FILE__) . 'languages'); |
| 41 |
} |
| 42 |
|
| 43 |
public function bplde_block_assets() { |
| 44 |
wp_localize_script( |
| 45 |
'bpldl-document-library-editor-script', |
| 46 |
'bpldlData', |
| 47 |
[ |
| 48 |
'ajax_url' => admin_url('admin-ajax.php'), |
| 49 |
'nonce' => wp_create_nonce('bplde_nonce') |
| 50 |
] |
| 51 |
); |
| 52 |
wp_localize_script( |
| 53 |
'bpldl-document-library-view-script', |
| 54 |
'bpldlData', |
| 55 |
[ |
| 56 |
'ajax_url' => admin_url('admin-ajax.php'), |
| 57 |
'nonce' => wp_create_nonce('bplde_nonce') |
| 58 |
] |
| 59 |
); |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|