PluginProbe
Toggle Content / 1.2.1
Toggle Content v1.2.1
trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.8 1.3.0
toggle-content / toggle-content.php

toggle-content.php in Toggle Content 1.2.1, at toggle-content.php

129 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.2.1
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 /**
19 * Registers all block assets so that they can be enqueued through the block editor
20 * in the corresponding context.
21 *
22 * @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/
23 */
24
25
26 define('TOGGLE_CONTENT_VERSION', "1.2.1");
27 define('TOGGLE_CONTENT_ADMIN_URL', plugin_dir_url(__FILE__));
28 define('TOGGLE_CONTENT_ADMIN_PATH', dirname(__FILE__));
29
30 require_once __DIR__ . '/includes/font-loader.php';
31 require_once __DIR__ . '/includes/post-meta.php';
32 require_once __DIR__ . '/includes/helpers.php';
33 require_once __DIR__ . '/lib/style-handler/style-handler.php';
34
35 function create_block_toggle_content_block_init()
36 {
37
38 $script_asset_path = TOGGLE_CONTENT_ADMIN_PATH . "/dist/index.asset.php";
39 if (!file_exists($script_asset_path)) {
40 throw new Error(
41 'You need to run `npm start` or `npm run build` for the "toggle-content/toggle-content" block first.'
42 );
43 }
44 $script_asset = require($script_asset_path);
45 $all_dependencies = array_merge($script_asset['dependencies'], array(
46 'wp-blocks',
47 'wp-i18n',
48 'wp-element',
49 'wp-block-editor',
50 'toggle-content-controls-util',
51 ));
52
53 $index_js = TOGGLE_CONTENT_ADMIN_URL . 'dist/index.js';
54 wp_register_script(
55 'create-block-toggle-content-block-editor',
56 $index_js,
57 $all_dependencies,
58 $script_asset['version'],
59 true
60 );
61
62 $style_css = TOGGLE_CONTENT_ADMIN_URL . 'dist/style.css';
63 wp_register_style(
64 'create-block-toggle-content-block-editor',
65 $style_css,
66 array(),
67 TOGGLE_CONTENT_VERSION,
68 "all"
69 );
70
71
72 $frontend_js = TOGGLE_CONTENT_ADMIN_URL . 'dist/frontend/index.js';
73 wp_register_script(
74 'essential-blocks-toggle-content-frontend',
75 $frontend_js,
76 array(),
77 TOGGLE_CONTENT_VERSION,
78 true
79 );
80
81
82 //
83 //
84 //
85 $controls_dependencies = require TOGGLE_CONTENT_ADMIN_PATH . '/dist/controls.asset.php';
86
87 wp_register_script(
88 "toggle-content-controls-util",
89 TOGGLE_CONTENT_ADMIN_URL . '/dist/controls.js',
90 array_merge($controls_dependencies['dependencies'], array("essential-blocks-edit-post")),
91 $controls_dependencies['version'],
92 true
93 );
94
95 wp_localize_script('toggle-content-controls-util', 'EssentialBlocksLocalize', array(
96 'eb_wp_version' => (float) get_bloginfo('version'),
97 'rest_rootURL' => get_rest_url(),
98 ));
99
100 wp_register_style(
101 'toggle-content-editor-css',
102 TOGGLE_CONTENT_ADMIN_URL . '/dist/controls.css',
103 array(
104 "create-block-toggle-content-block-editor"
105 ),
106 $controls_dependencies['version'],
107 'all'
108 );
109
110 if (!WP_Block_Type_Registry::get_instance()->is_registered('essential-blocks/countdown')) {
111 register_block_type(
112 Countdown_Helper::get_block_register_path("toggle-content/toggle-content", TOGGLE_CONTENT_ADMIN_PATH),
113 array(
114 'editor_script' => 'create-block-toggle-content-block-editor',
115 'editor_style' => 'toggle-content-editor-css',
116 'render_callback' => function ($attributes, $content) {
117 if (!is_admin()) {
118 wp_enqueue_script('essential-blocks-toggle-content-frontend');
119 wp_enqueue_style('create-block-toggle-content-block-editor');
120 }
121 return $content;
122 }
123 )
124 );
125 }
126 }
127
128 add_action('init', 'create_block_toggle_content_block_init');
129