| 1 |
<?php |
| 2 |
if(!defined('ABSPATH')) { |
| 3 |
return; |
| 4 |
} |
| 5 |
|
| 6 |
if(!class_exists('PPV_Block')){ |
| 7 |
class PPV_Block{ |
| 8 |
function __construct(){ |
| 9 |
// add_action('init', [$this, 'enqueue_block_css_js']); |
| 10 |
add_action('init', [$this, 'enqueue_script']); |
| 11 |
} |
| 12 |
|
| 13 |
function enqueue_script(){ |
| 14 |
wp_register_script( 'ppv-blocks', plugin_dir_url( __FILE__ ).'dist/editor.js', array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'jquery' ), PPV_VER, true ); |
| 15 |
|
| 16 |
// wp_register_style( 'ppv-blocks', plugin_dir_url( __FILE__ ). 'dist/editor.css' , array(), PPV_VER ); |
| 17 |
|
| 18 |
wp_localize_script('ppv-blocks', 'ppvBlocks', [ |
| 19 |
'siteUrl' => site_url(), |
| 20 |
'ajaxUrl' => admin_url('admin-ajax.php'), |
| 21 |
'ppv_nonce' => wp_create_nonce( 'ppv_secret_nonce' ) |
| 22 |
]); |
| 23 |
|
| 24 |
register_block_type('meta-box/document-embedder', array( |
| 25 |
'editor_script' => 'ppv-blocks', |
| 26 |
// 'style' => 'ppv-blocks', |
| 27 |
'render_callback' => function($attr, $content){ |
| 28 |
ob_start(); |
| 29 |
|
| 30 |
if(isset($attr['selected'])){ |
| 31 |
echo do_shortcode("[doc id=".esc_attr($attr['selected'])."]"); |
| 32 |
}else if(isset($attr['data']['tringle_text'])){ |
| 33 |
echo do_shortcode("[doc id=".esc_attr($attr['data']['tringle_text'])."]"); |
| 34 |
} |
| 35 |
return ob_get_clean(); |
| 36 |
} |
| 37 |
)); |
| 38 |
|
| 39 |
register_block_type('kahf-kit/kahf-banner-k27f', array( |
| 40 |
'editor_script' => 'ppv-blocks', |
| 41 |
// 'style' => 'ppv-blocks', |
| 42 |
'render_callback' => function($attr, $content){ |
| 43 |
return wpautop( $content ); |
| 44 |
} |
| 45 |
)); |
| 46 |
|
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
new PPV_Block(); |
| 53 |
} |
| 54 |
|
| 55 |
|