| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: Toggle Content |
| 5 |
* Plugin URI: https://essential-blocks.com |
| 6 |
* Description: Toggle Content block for Gutenberg |
| 7 |
* Author: WPDeveloper |
| 8 |
* Author URI: https://wpdeveloper.net |
| 9 |
* Version: 1.1.0 |
| 10 |
* License: GPL3+ |
| 11 |
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt |
| 12 |
* Text Domain: toggle-content |
| 13 |
* |
| 14 |
* @package toggle-content |
| 15 |
*/ |
| 16 |
|
| 17 |
|
| 18 |
require_once __DIR__ . '/includes/font-loader.php'; |
| 19 |
require_once __DIR__ . '/includes/post-meta.php'; |
| 20 |
require_once __DIR__ . '/lib/style-handler/style-handler.php'; |
| 21 |
|
| 22 |
|
| 23 |
function create_block_toggle_content_block_init() |
| 24 |
{ |
| 25 |
$dir = dirname(__FILE__); |
| 26 |
|
| 27 |
$script_asset_path = "$dir/build/index.asset.php"; |
| 28 |
if (!file_exists($script_asset_path)) { |
| 29 |
throw new Error( |
| 30 |
'You need to run `npm start` or `npm run build` for the "toggle-content/toggle-content" block first.' |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
$index_js = 'build/index.js'; |
| 35 |
wp_register_script( |
| 36 |
'create-block-toggle-content-block-editor', |
| 37 |
plugins_url($index_js, __FILE__), |
| 38 |
array( |
| 39 |
'wp-blocks', |
| 40 |
'wp-i18n', |
| 41 |
'wp-element', |
| 42 |
'wp-block-editor', |
| 43 |
), |
| 44 |
filemtime("$dir/$index_js") |
| 45 |
); |
| 46 |
|
| 47 |
$style_css = 'build/style-index.css'; |
| 48 |
wp_register_style( |
| 49 |
'create-block-toggle-content-block', |
| 50 |
plugins_url($style_css, __FILE__), |
| 51 |
array(), |
| 52 |
filemtime("$dir/$style_css") |
| 53 |
); |
| 54 |
|
| 55 |
$editor_css = 'build/index.css'; |
| 56 |
wp_register_style( |
| 57 |
'create-block-toggle-content-block-editor', |
| 58 |
plugins_url($editor_css, __FILE__), |
| 59 |
array(), |
| 60 |
filemtime("$dir/$editor_css") |
| 61 |
); |
| 62 |
|
| 63 |
// $frontend_js = "build/frontend.js"; |
| 64 |
// wp_enqueue_script( |
| 65 |
// 'essential-blocks-toggle-content-frontend', |
| 66 |
// plugins_url($frontend_js, __FILE__), |
| 67 |
// array(), |
| 68 |
// filemtime("$dir/$frontend_js"), |
| 69 |
// true |
| 70 |
// ); |
| 71 |
|
| 72 |
|
| 73 |
if (!is_admin()) { |
| 74 |
$frontend_js = "build/frontend.js"; |
| 75 |
wp_enqueue_script( |
| 76 |
'essential-blocks-toggle-content-frontend', |
| 77 |
plugins_url($frontend_js, __FILE__), |
| 78 |
array(), |
| 79 |
filemtime("$dir/$frontend_js"), |
| 80 |
true |
| 81 |
); |
| 82 |
} |
| 83 |
|
| 84 |
if (!WP_Block_Type_Registry::get_instance()->is_registered('essential-blocks/toggle-content')) { |
| 85 |
register_block_type('toggle-content/toggle-content', array( |
| 86 |
'editor_script' => 'create-block-toggle-content-block-editor', |
| 87 |
'editor_style' => 'create-block-toggle-content-block-editor', |
| 88 |
'style' => 'create-block-toggle-content-block', |
| 89 |
// 'render_callback' => function ($attributes, $content) { |
| 90 |
// if (!is_admin()) { |
| 91 |
// wp_enqueue_script('essential-blocks-toggle-content-frontend'); |
| 92 |
// } |
| 93 |
// return $content; |
| 94 |
// } |
| 95 |
)); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
add_action('init', 'create_block_toggle_content_block_init'); |
| 100 |
|