| 1 |
<?php |
| 2 |
/** |
| 3 |
* Loads dynamic blocks for server-side rendering. |
| 4 |
* |
| 5 |
* @package Gutenify |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
// Register server-side code for individual blocks. |
| 14 |
foreach ( glob( dirname( dirname( __FILE__ ) ) . '/src/blocks/*/index.php' ) as $gutenify_block_logic ) { |
| 15 |
require_once $gutenify_block_logic; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Register meta field. |
| 20 |
* |
| 21 |
* @return void |
| 22 |
*/ |
| 23 |
function gutenify_register_meta_fields() { |
| 24 |
$post_types = apply_filters( 'gutenify_active_post_types', array( 'post', 'page' ) ); |
| 25 |
if ( ! empty( $post_types ) ) { |
| 26 |
$meta_fields['gutenify_custom_css'] = array( |
| 27 |
'show_in_rest' => true, |
| 28 |
'single' => true, |
| 29 |
'type' => 'string', |
| 30 |
'auth_callback' => function () { |
| 31 |
return current_user_can( 'edit_posts' ); |
| 32 |
}, |
| 33 |
); |
| 34 |
|
| 35 |
$meta_fields['gutenify_custom_css_data'] = array( |
| 36 |
'show_in_rest' => true, |
| 37 |
'single' => true, |
| 38 |
'type' => 'string', |
| 39 |
'auth_callback' => function () { |
| 40 |
return current_user_can( 'edit_posts' ); |
| 41 |
}, |
| 42 |
); |
| 43 |
|
| 44 |
foreach ( $post_types as $post_type ) { |
| 45 |
if ( ! empty( $meta_fields ) ) { |
| 46 |
foreach ( $meta_fields as $meta_key => $meta_args ) { |
| 47 |
register_post_meta( $post_type, $meta_key, $meta_args ); |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
add_action( 'init', 'gutenify_register_meta_fields' ); |
| 54 |
|