Files
2025-01-01 18:09:33 -08:00

64 lines
1.9 KiB
PHP

<?php
/**
* Plugin Name: Lcp Viewport
* Description: Example block scaffolded with Create Block tool.
* Requires at least: 6.6
* Requires PHP: 7.2
* Version: 0.1.0
* Author: The WordPress Contributors
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: lcp-viewport
*
* @package CreateBlock
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function lcp_header_container_block_init() {
register_block_type( __DIR__ . '/build' , array(
//'parent' => array( 'lcp/viewport', 'lcp/main-area' ), // Only allow this block to be inserted inside the 'lcp/viewport' block
)
);
}
add_action( 'init', 'lcp_header_container_block_init' );
/* REST API TO UPDATE OPTIONS */
// Register custom REST API endpoint
function lcp_register_rest_route() {
register_rest_route('lcp/v1', '/set-header-height', array(
'methods' => 'POST',
'callback' => 'lcp_set_header_height',
'permission_callback' => function () {
return current_user_can('manage_options'); // Ensure the user has permission
},
));
}
add_action('rest_api_init', 'lcp_register_rest_route');
// Callback to save the height to wp_options
function lcp_set_header_height(WP_REST_Request $request) {
$height = $request->get_param('height');
if (is_numeric($height)) {
update_option('lcp_header_height', $height);
return new WP_REST_Response(array('message' => 'Height saved successfully'), 200);
}
return new WP_REST_Response(array('message' => 'Invalid height value'), 400);
}