| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: GutenBee |
| 4 |
* Plugin URI: https://www.cssigniter.com/plugins/gutenbee/ |
| 5 |
* Description: Premium Blocks for WordPress |
| 6 |
* Author: The CSSIgniter Team |
| 7 |
* Author URI: https://www.cssigniter.com |
| 8 |
* Version: 2.9.0 |
| 9 |
* Text Domain: gutenbee |
| 10 |
* Domain Path: languages |
| 11 |
* |
| 12 |
* GutenBee is free software: you can redistribute it and/or modify |
| 13 |
* it under the terms of the GNU General Public License as published by |
| 14 |
* the Free Software Foundation, either version 2 of the License, or |
| 15 |
* any later version. |
| 16 |
* |
| 17 |
* GutenBee is distributed in the hope that it will be useful, |
| 18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
* GNU General Public License for more details. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU General Public License |
| 23 |
* along with GutenBee. If not, see <http://www.gnu.org/licenses/>. |
| 24 |
* |
| 25 |
*/ |
| 26 |
|
| 27 |
if ( ! defined( 'GUTENBEE_PLUGIN_VERSION' ) ) { |
| 28 |
define( 'GUTENBEE_PLUGIN_VERSION', '2.9.0' ); |
| 29 |
} |
| 30 |
|
| 31 |
if ( ! defined( 'GUTENBEE_PLUGIN_DIR' ) ) { |
| 32 |
define( 'GUTENBEE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 33 |
} |
| 34 |
|
| 35 |
if ( ! defined( 'GUTENBEE_PLUGIN_DIR_URL' ) ) { |
| 36 |
define( 'GUTENBEE_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) ); |
| 37 |
} |
| 38 |
|
| 39 |
add_action( 'init', 'gutenbee_init' ); |
| 40 |
function gutenbee_init() { |
| 41 |
load_plugin_textdomain( 'gutenbee', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); |
| 42 |
} |
| 43 |
|
| 44 |
add_action( 'enqueue_block_editor_assets', 'gutenbee_enqueue_editor_assets' ); |
| 45 |
function gutenbee_enqueue_editor_assets() { |
| 46 |
wp_enqueue_script( 'gutenbee', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/build/gutenbee.build.js', array( |
| 47 |
'wp-components', |
| 48 |
'wp-blocks', |
| 49 |
'wp-element', |
| 50 |
'wp-editor', |
| 51 |
'wp-block-editor', |
| 52 |
'wp-data', |
| 53 |
'wp-date', |
| 54 |
'wp-i18n', |
| 55 |
'wp-compose', |
| 56 |
'wp-keycodes', |
| 57 |
'wp-html-entities', |
| 58 |
'wp-server-side-render', |
| 59 |
), GUTENBEE_PLUGIN_VERSION, true ); |
| 60 |
|
| 61 |
wp_localize_script( 'gutenbee', '__GUTENBEE_SETTINGS__', gutenbee_get_settings() ); |
| 62 |
|
| 63 |
wp_enqueue_style( 'gutenbee-editor', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/build/gutenbee.build.css', array( |
| 64 |
'wp-edit-blocks', |
| 65 |
), GUTENBEE_PLUGIN_VERSION ); |
| 66 |
} |
| 67 |
|
| 68 |
add_action( 'wp_enqueue_scripts', 'gutenbee_enqueue_frontend_block_assets' ); |
| 69 |
function gutenbee_enqueue_frontend_block_assets() { |
| 70 |
$gutenbee_settings = gutenbee_get_settings(); |
| 71 |
$maps_api_key = $gutenbee_settings['google_maps_api_key']; |
| 72 |
|
| 73 |
if ( $maps_api_key && has_block( 'gutenbee/google-maps' ) ) { |
| 74 |
wp_enqueue_script( 'gutenbee-google-maps', 'https://maps.googleapis.com/maps/api/js?key=' . $maps_api_key, array(), GUTENBEE_PLUGIN_VERSION, true ); |
| 75 |
} |
| 76 |
|
| 77 |
$enqueue_css = false; |
| 78 |
$enqueue_js = false; |
| 79 |
foreach ( gutenbee_get_blocks_info() as $block_name => $block_info ) { |
| 80 |
if ( has_block( $block_name ) || gutenbee_has_block_in_reusable( $block_name ) ) { |
| 81 |
if ( ! $enqueue_css && $block_info['enqueue_css'] ) { |
| 82 |
$enqueue_css = true; |
| 83 |
} |
| 84 |
if ( ! $enqueue_js && $block_info['enqueue_js'] ) { |
| 85 |
$enqueue_js = true; |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
if ( apply_filters( 'gutenbee_enqueue_frontend_styles', $enqueue_css ) ) { |
| 91 |
wp_enqueue_style( 'gutenbee', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/build/gutenbee.scripts.css', array(), GUTENBEE_PLUGIN_VERSION ); |
| 92 |
} |
| 93 |
|
| 94 |
if ( apply_filters( 'gutenbee_enqueue_frontend_scripts', $enqueue_js ) ) { |
| 95 |
wp_enqueue_script( 'gutenbee-scripts', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/build/gutenbee.scripts.js', array( |
| 96 |
'jquery', |
| 97 |
), GUTENBEE_PLUGIN_VERSION, true ); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
add_action( 'admin_enqueue_scripts', 'gutenbee_admin_assets' ); |
| 102 |
|
| 103 |
function gutenbee_admin_assets() { |
| 104 |
wp_enqueue_style( 'gutenbee-admin-styles', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/assets/css/admin.css', array( |
| 105 |
'wp-color-picker', |
| 106 |
), GUTENBEE_PLUGIN_VERSION ); |
| 107 |
wp_enqueue_script( 'gutenbee-admin-scripts', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/assets/js/admin.js', array( |
| 108 |
'wp-color-picker', |
| 109 |
), GUTENBEE_PLUGIN_VERSION, true ); |
| 110 |
} |
| 111 |
|
| 112 |
// GutenBee's block category |
| 113 |
add_filter( 'block_categories', 'gutenbee_block_categories', 10, 2 ); |
| 114 |
function gutenbee_block_categories( $categories, $post ) { |
| 115 |
return array_merge( $categories, array( |
| 116 |
array( |
| 117 |
'slug' => 'gutenbee', |
| 118 |
'title' => __( 'GutenBee', 'gutenbee' ), |
| 119 |
), |
| 120 |
) ); |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Returns a list of settings names and their corresponding labels. |
| 125 |
* Note that the list may not contain all blocks. E.g. google-maps |
| 126 |
* |
| 127 |
* @return array |
| 128 |
*/ |
| 129 |
function gutenbee_get_setting_block_names() { |
| 130 |
// Setting keys here for each block MUST be the same slugs |
| 131 |
// used in the block's registration definition (check each block's |
| 132 |
// index.js file, after `gutenbee/XYZ`, XYZ is the block's key). |
| 133 |
return array( |
| 134 |
'accordion' => __( 'Accordion Block', 'gutenbee' ), |
| 135 |
'banner' => __( 'Banner Block', 'gutenbee' ), |
| 136 |
'buttons' => __( 'Button Block', 'gutenbee' ), |
| 137 |
'container' => __( 'Container Block', 'gutenbee' ), |
| 138 |
'countdown' => __( 'Countdown Block', 'gutenbee' ), |
| 139 |
'countup' => __( 'Countup Block', 'gutenbee' ), |
| 140 |
'divider' => __( 'Divider Block', 'gutenbee' ), |
| 141 |
'food-menu' => __( 'Food Menu Block', 'gutenbee' ), |
| 142 |
'heading' => __( 'Heading Block', 'gutenbee' ), |
| 143 |
'icon' => __( 'Icon Block', 'gutenbee' ), |
| 144 |
'iconbox' => __( 'Icon Box Block', 'gutenbee' ), |
| 145 |
'icon-list' => __( 'Icon List Block', 'gutenbee' ), |
| 146 |
'image' => __( 'Image Block', 'gutenbee' ), |
| 147 |
'imagebox' => __( 'Image Box Block', 'gutenbee' ), |
| 148 |
'image-comparison' => __( 'Image Comparison Block', 'gutenbee' ), |
| 149 |
'justified-gallery' => __( 'Justified Gallery Block', 'gutenbee' ), |
| 150 |
'paragraph' => __( 'Paragraph Block', 'gutenbee' ), |
| 151 |
'post-types' => __( 'Post Types Block', 'gutenbee' ), |
| 152 |
'progress-bar' => __( 'Progress Bar Block', 'gutenbee' ), |
| 153 |
'review' => __( 'Review Block', 'gutenbee' ), |
| 154 |
'spacer' => __( 'Spacer Block', 'gutenbee' ), |
| 155 |
'slideshow' => __( 'Slideshow Block', 'gutenbee' ), |
| 156 |
'tab-slider' => __( 'Tab Slider Block', 'gutenbee' ), |
| 157 |
'tabs' => __( 'Tabs Block', 'gutenbee' ), |
| 158 |
'testimonial' => __( 'Testimonial Block', 'gutenbee' ), |
| 159 |
'video' => __( 'Video Block', 'gutenbee' ), |
| 160 |
'video-embed' => __( 'Video Embed Block', 'gutenbee' ), |
| 161 |
// 'lottie' => __( 'Lottie Player Block', 'gutenbee' ), |
| 162 |
); |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Returns a list of blocks and information about them. |
| 167 |
* |
| 168 |
* @return array |
| 169 |
*/ |
| 170 |
function gutenbee_get_blocks_info() { |
| 171 |
return array( |
| 172 |
'gutenbee/accordion' => array( |
| 173 |
'label' => __( 'Accordion Block', 'gutenbee' ), |
| 174 |
'enqueue_js' => true, |
| 175 |
'enqueue_css' => true, |
| 176 |
), |
| 177 |
'gutenbee/banner' => array( |
| 178 |
'label' => __( 'Banner Block', 'gutenbee' ), |
| 179 |
'enqueue_js' => true, |
| 180 |
'enqueue_css' => true, |
| 181 |
), |
| 182 |
'gutenbee/button' => array( |
| 183 |
'label' => __( 'Button Block', 'gutenbee' ), |
| 184 |
'enqueue_js' => false, |
| 185 |
'enqueue_css' => true, |
| 186 |
), |
| 187 |
'gutenbee/buttons' => array( |
| 188 |
'label' => __( 'Buttons Block', 'gutenbee' ), |
| 189 |
'enqueue_js' => false, |
| 190 |
'enqueue_css' => true, |
| 191 |
), |
| 192 |
'gutenbee/container' => array( |
| 193 |
'label' => __( 'Container Block', 'gutenbee' ), |
| 194 |
'enqueue_js' => true, |
| 195 |
'enqueue_css' => true, |
| 196 |
), |
| 197 |
'gutenbee/column' => array( |
| 198 |
'label' => __( 'Column Block', 'gutenbee' ), |
| 199 |
'enqueue_js' => false, |
| 200 |
'enqueue_css' => true, |
| 201 |
), |
| 202 |
'gutenbee/countdown' => array( |
| 203 |
'label' => __( 'Countdown Block', 'gutenbee' ), |
| 204 |
'enqueue_js' => true, |
| 205 |
'enqueue_css' => true, |
| 206 |
), |
| 207 |
'gutenbee/countup' => array( |
| 208 |
'label' => __( 'Countup Block', 'gutenbee' ), |
| 209 |
'enqueue_js' => true, |
| 210 |
'enqueue_css' => true, |
| 211 |
), |
| 212 |
'gutenbee/divider' => array( |
| 213 |
'label' => __( 'Divider Block', 'gutenbee' ), |
| 214 |
'enqueue_js' => true, |
| 215 |
'enqueue_css' => true, |
| 216 |
), |
| 217 |
'gutenbee/google-maps' => array( |
| 218 |
'label' => __( 'Google Map Block', 'gutenbee' ), |
| 219 |
'enqueue_js' => true, |
| 220 |
'enqueue_css' => true, |
| 221 |
), |
| 222 |
'gutenbee/heading' => array( |
| 223 |
'label' => __( 'Heading Block', 'gutenbee' ), |
| 224 |
'enqueue_js' => false, |
| 225 |
'enqueue_css' => true, |
| 226 |
), |
| 227 |
'gutenbee/icon' => array( |
| 228 |
'label' => __( 'Icon Block', 'gutenbee' ), |
| 229 |
'enqueue_js' => false, |
| 230 |
'enqueue_css' => true, |
| 231 |
), |
| 232 |
'gutenbee/iconbox' => array( |
| 233 |
'label' => __( 'Icon Box Block', 'gutenbee' ), |
| 234 |
'enqueue_js' => false, |
| 235 |
'enqueue_css' => true, |
| 236 |
), |
| 237 |
'gutenbee/icon-list' => array( |
| 238 |
'label' => __( 'Icon List Block', 'gutenbee' ), |
| 239 |
'enqueue_js' => false, |
| 240 |
'enqueue_css' => true, |
| 241 |
), |
| 242 |
'gutenbee/image' => array( |
| 243 |
'label' => __( 'Image Block', 'gutenbee' ), |
| 244 |
'enqueue_js' => false, |
| 245 |
'enqueue_css' => true, |
| 246 |
), |
| 247 |
'gutenbee/imagebox' => array( |
| 248 |
'label' => __( 'Image Box Block', 'gutenbee' ), |
| 249 |
'enqueue_js' => false, |
| 250 |
'enqueue_css' => true, |
| 251 |
), |
| 252 |
'gutenbee/image-comparison' => array( |
| 253 |
'label' => __( 'Image Comparison Block', 'gutenbee' ), |
| 254 |
'enqueue_js' => true, |
| 255 |
'enqueue_css' => true, |
| 256 |
), |
| 257 |
'gutenbee/justified-gallery' => array( |
| 258 |
'label' => __( 'Justified Gallery Block', 'gutenbee' ), |
| 259 |
'enqueue_js' => true, |
| 260 |
'enqueue_css' => true, |
| 261 |
), |
| 262 |
// 'gutenbee/lottie' => array( |
| 263 |
// 'label' => __( 'Lottie Player Block', 'gutenbee' ), |
| 264 |
// 'enqueue_js' => false, |
| 265 |
// 'enqueue_css' => false, |
| 266 |
// ), |
| 267 |
'gutenbee/paragraph' => array( |
| 268 |
'label' => __( 'Paragraph Block', 'gutenbee' ), |
| 269 |
'enqueue_js' => false, |
| 270 |
'enqueue_css' => true, |
| 271 |
), |
| 272 |
'gutenbee/post-types' => array( |
| 273 |
'label' => __( 'Post Types Block', 'gutenbee' ), |
| 274 |
'enqueue_js' => false, |
| 275 |
'enqueue_css' => true, |
| 276 |
), |
| 277 |
'gutenbee/progress-bar' => array( |
| 278 |
'label' => __( 'Progress Block', 'gutenbee' ), |
| 279 |
'enqueue_js' => false, |
| 280 |
'enqueue_css' => true, |
| 281 |
), |
| 282 |
'gutenbee/review' => array( |
| 283 |
'label' => __( 'Review Block', 'gutenbee' ), |
| 284 |
'enqueue_js' => false, |
| 285 |
'enqueue_css' => true, |
| 286 |
), |
| 287 |
'gutenbee/slideshow' => array( |
| 288 |
'label' => __( 'Slideshow Block', 'gutenbee' ), |
| 289 |
'enqueue_js' => true, |
| 290 |
'enqueue_css' => true, |
| 291 |
), |
| 292 |
'gutenbee/spacer' => array( |
| 293 |
'label' => __( 'Spacer Block', 'gutenbee' ), |
| 294 |
'enqueue_js' => true, |
| 295 |
'enqueue_css' => true, |
| 296 |
), |
| 297 |
'gutenbee/tab-slider' => array( |
| 298 |
'label' => __( 'Tab Slider Block', 'gutenbee' ), |
| 299 |
'enqueue_js' => true, |
| 300 |
'enqueue_css' => true, |
| 301 |
), |
| 302 |
'gutenbee/tabs' => array( |
| 303 |
'label' => __( 'Tabs Block', 'gutenbee' ), |
| 304 |
'enqueue_js' => true, |
| 305 |
'enqueue_css' => true, |
| 306 |
), |
| 307 |
'gutenbee/testimonial' => array( |
| 308 |
'label' => __( 'Testimonial Block', 'gutenbee' ), |
| 309 |
'enqueue_js' => false, |
| 310 |
'enqueue_css' => true, |
| 311 |
), |
| 312 |
'gutenbee/video' => array( |
| 313 |
'label' => __( 'Video Block', 'gutenbee' ), |
| 314 |
'enqueue_js' => false, |
| 315 |
'enqueue_css' => true, |
| 316 |
), |
| 317 |
'gutenbee/video-embed' => array( |
| 318 |
'label' => __( 'Video Embed Block', 'gutenbee' ), |
| 319 |
'enqueue_js' => true, |
| 320 |
'enqueue_css' => true, |
| 321 |
), |
| 322 |
'gutenbee/food-menu' => array( |
| 323 |
'label' => __( 'Food Menu', 'gutenbee' ), |
| 324 |
'enqueue_js' => false, |
| 325 |
'enqueue_css' => true, |
| 326 |
), |
| 327 |
); |
| 328 |
} |
| 329 |
|
| 330 |
/** |
| 331 |
* Returns the plugin's settings array. |
| 332 |
* |
| 333 |
* @return array |
| 334 |
*/ |
| 335 |
function gutenbee_get_settings() { |
| 336 |
$settings = get_option( 'gutenbee_settings' ); |
| 337 |
$general_settings = get_option( 'gutenbee_general_settings' ); |
| 338 |
|
| 339 |
if ( $settings && $general_settings ) { |
| 340 |
$settings = array_merge( $settings, $general_settings ); |
| 341 |
} elseif ( $general_settings ) { |
| 342 |
$settings = $general_settings; |
| 343 |
} |
| 344 |
|
| 345 |
$settings = gutenbee_validate_settings( $settings ); |
| 346 |
|
| 347 |
/** |
| 348 |
* Filters the plugin's settings values. |
| 349 |
* |
| 350 |
* @since 2.6.2 |
| 351 |
* |
| 352 |
* @param array $settings |
| 353 |
* |
| 354 |
* @hooked ignition_module_accommodation_add_cpt_to_array - 10 |
| 355 |
*/ |
| 356 |
$settings = apply_filters( 'gutenbee_settings', $settings ); |
| 357 |
|
| 358 |
return $settings; |
| 359 |
} |
| 360 |
|
| 361 |
/** |
| 362 |
* Makes sure there are no undefined indexes in the settings array. |
| 363 |
* Use before using a setting value. Eleminates the need for isset() before using. |
| 364 |
* |
| 365 |
* @param $settings |
| 366 |
* |
| 367 |
* @return array |
| 368 |
*/ |
| 369 |
function gutenbee_validate_settings( $settings ) { |
| 370 |
$defaults = array( |
| 371 |
'active_google-maps' => 1, |
| 372 |
'google_maps_api_key' => '', |
| 373 |
'active_high-contrast' => 0, |
| 374 |
'high-contrast-color' => '#ffff00', |
| 375 |
'active_editor-width' => 0, |
| 376 |
'editor-width-value' => 680, |
| 377 |
); |
| 378 |
foreach ( gutenbee_get_setting_block_names() as $id => $name ) { |
| 379 |
$defaults[ 'active_' . $id ] = 1; |
| 380 |
} |
| 381 |
|
| 382 |
$settings = wp_parse_args( $settings, $defaults ); |
| 383 |
|
| 384 |
$settings['theme_supports']['post-types'] = gutenbee_block_post_types_get_theme_support(); |
| 385 |
$settings['theme_supports']['container'] = gutenbee_block_container_get_theme_support(); |
| 386 |
|
| 387 |
return $settings; |
| 388 |
} |
| 389 |
|
| 390 |
/** |
| 391 |
* Returns the appropriate page(d) query variable to use in custom loops (needed for pagination). |
| 392 |
* |
| 393 |
* @uses get_query_var() |
| 394 |
* |
| 395 |
* @param int $default_return The default page number to return, if no query vars are set. |
| 396 |
* |
| 397 |
* @return int The appropriate paged value if found, else 0. |
| 398 |
*/ |
| 399 |
function gutenbee_get_page_var( $default_return = 0 ) { |
| 400 |
$paged = get_query_var( 'paged', false ); |
| 401 |
$page = get_query_var( 'page', false ); |
| 402 |
|
| 403 |
if ( false === $paged && false === $page ) { |
| 404 |
return $default_return; |
| 405 |
} |
| 406 |
|
| 407 |
return max( $paged, $page ); |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
function gutenbee_get_columns_classes( $columns ) { |
| 412 |
switch ( intval( $columns ) ) { |
| 413 |
case 1: |
| 414 |
$classes = 'columns-1'; |
| 415 |
break; |
| 416 |
case 2: |
| 417 |
$classes = 'columns-2'; |
| 418 |
break; |
| 419 |
case 3: |
| 420 |
$classes = 'columns-3'; |
| 421 |
break; |
| 422 |
case 4: |
| 423 |
default: |
| 424 |
$classes = 'columns-4'; |
| 425 |
break; |
| 426 |
} |
| 427 |
|
| 428 |
return apply_filters( 'gutenbee_get_columns_classes', $classes, $columns ); |
| 429 |
} |
| 430 |
|
| 431 |
function gutenbee_get_template_part( $block, $slug, $name = '', $args = array() ) { |
| 432 |
$templates = array(); |
| 433 |
$name = (string) $name; |
| 434 |
if ( '' !== $name ) { |
| 435 |
$templates[] = "{$slug}-{$name}.php"; |
| 436 |
} |
| 437 |
|
| 438 |
$templates[] = "{$slug}.php"; |
| 439 |
|
| 440 |
$located = gutenbee_locate_template( $block, $templates, $args ); |
| 441 |
|
| 442 |
if ( ! empty( $located ) ) { |
| 443 |
include $located; |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
function gutenbee_locate_template( $block, $templates, $args ) { |
| 448 |
$plugin_path = plugin_dir_path( __FILE__ ); |
| 449 |
|
| 450 |
// The templates path in the plugin, i.e. defaults/fallback. E.g. src/blocks/post-types/templates/ |
| 451 |
$default_path = trailingslashit( trailingslashit( $plugin_path ) . "src/blocks/{$block}/templates" ); |
| 452 |
|
| 453 |
// The templates path in the theme. E.g. gutenbee/ |
| 454 |
$theme_path = apply_filters( 'gutenbee_locate_template_theme_path', "gutenbee/{$block}", $block ); |
| 455 |
$theme_path = trailingslashit( $theme_path ); |
| 456 |
|
| 457 |
$theme_templates = array(); |
| 458 |
foreach ( $templates as $template ) { |
| 459 |
$theme_templates[] = $theme_path . $template; |
| 460 |
} |
| 461 |
|
| 462 |
// Try to find a theme-overridden template. |
| 463 |
$located = locate_template( $theme_templates, false ); |
| 464 |
|
| 465 |
$located = apply_filters( 'gutenbee_locate_template', $located, $block, $theme_templates, $templates, $theme_path, $default_path, $args ); |
| 466 |
|
| 467 |
if ( empty( $located ) ) { |
| 468 |
// Nope. Try the plugin templates instead. |
| 469 |
foreach ( $templates as $template ) { |
| 470 |
if ( file_exists( $default_path . $template ) ) { |
| 471 |
$located = $default_path . $template; |
| 472 |
break; |
| 473 |
} |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
return $located; |
| 478 |
} |
| 479 |
|
| 480 |
/** |
| 481 |
* Checks the content for existence of blocks by $block_name inside reusable blocks. |
| 482 |
* |
| 483 |
* @link https://github.com/WordPress/gutenberg/issues/18272#issuecomment-566179633 |
| 484 |
* |
| 485 |
* @param string $block_name |
| 486 |
* @param int|false $id Optional. Post ID. Defaults to the ID of the global $post object. |
| 487 |
* |
| 488 |
* @return bool |
| 489 |
*/ |
| 490 |
function gutenbee_has_block_in_reusable( $block_name, $id = false ) { |
| 491 |
$id = ( ! $id ) ? get_the_ID() : $id; |
| 492 |
if ( $id ) { |
| 493 |
if ( has_block( 'core/block', $id ) ) { |
| 494 |
// Check for reusable blocks |
| 495 |
$content = get_post_field( 'post_content', $id ); |
| 496 |
$blocks = parse_blocks( $content ); |
| 497 |
|
| 498 |
if ( ! is_array( $blocks ) || empty( $blocks ) ) { |
| 499 |
return false; |
| 500 |
} |
| 501 |
|
| 502 |
foreach ( $blocks as $block ) { |
| 503 |
if ( 'core/block' === $block['blockName'] && ! empty( $block['attrs']['ref'] ) ) { |
| 504 |
if ( has_block( $block_name, $block['attrs']['ref'] ) ) { |
| 505 |
return true; |
| 506 |
} |
| 507 |
} |
| 508 |
} |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
return false; |
| 513 |
} |
| 514 |
|
| 515 |
// TODO think what to do here enabling JSON uploads |
| 516 |
add_filter( 'wp_check_filetype_and_ext', 'gutenbee_file_and_ext_json', 10, 4 ); |
| 517 |
function gutenbee_file_and_ext_json( $types, $file, $filename, $mimes ) { |
| 518 |
if ( false !== strpos( $filename, '.json' ) ) { |
| 519 |
$types['ext'] = 'json'; |
| 520 |
$types['type'] = 'application/json'; |
| 521 |
} |
| 522 |
return $types; |
| 523 |
} |
| 524 |
|
| 525 |
add_filter( 'upload_mimes', 'gutenbee_mime_types' ); |
| 526 |
function gutenbee_mime_types( $mimes ) { |
| 527 |
$mimes['json'] = 'application/json'; |
| 528 |
return $mimes; |
| 529 |
} |
| 530 |
|
| 531 |
add_filter( 'plugin_action_links_gutenbee/gutenbee.php', 'gutenbee_settings_link' ); |
| 532 |
function gutenbee_settings_link( $links ) { |
| 533 |
$action_links = array( |
| 534 |
'settings' => '<a href="' . admin_url( 'admin.php?page=gutenbee' ) . '" aria-label="' . esc_attr__( 'View GutenBee settings', 'gutenbee' ) . '">' . esc_html__( 'Settings', 'gutenbee' ) . '</a>', |
| 535 |
); |
| 536 |
|
| 537 |
return array_merge( $action_links, $links ); |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
require_once untrailingslashit( dirname( __FILE__ ) ) . '/inc/options.php'; |
| 542 |
require_once untrailingslashit( dirname( __FILE__ ) ) . '/src/blocks/container/block.php'; |
| 543 |
require_once untrailingslashit( dirname( __FILE__ ) ) . '/src/blocks/post-types/block.php'; |
| 544 |
|