Skip to content

Instantly share code, notes, and snippets.

@herewithme
Last active September 9, 2020 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herewithme/f1c377377cc3dcedc8388dd97196fdb6 to your computer and use it in GitHub Desktop.
Save herewithme/f1c377377cc3dcedc8388dd97196fdb6 to your computer and use it in GitHub Desktop.
Add support of Gutenberg to Sugar Calendar with minor tweaks
<?php
/**
* Plugin Name: Sugar Calendar - Gutenberg
* Description: Add support of Gutenberg to Sugar Calendar with minor tweaks
* Author: Be API Team
* Author URI: http://beapi.fr/
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*
* @see: https://gist.github.com/herewithme/f1c377377cc3dcedc8388dd97196fdb6
*/
namespace BEAPI\SugarCalendar;
add_filter( 'sc_event_supports', __NAMESPACE__ . '\\sc_event_supports' );
/**
* Gutenberg need EDITOR supports
*
* @return array
*
* @param array $supports
*/
function sc_event_supports( array $supports ) {
$supports[] = 'editor';
return $supports;
}
add_filter( 'register_post_type_args', __NAMESPACE__ . '\\register_post_type_args', 10, 2 );
/**
* Gutenberg need REST API support
*
* @return array
*
* @param $name
* @param array $args
*/
function register_post_type_args( array $args, $name ) {
if ( $name !== 'sc_event' ) {
return $args;
}
$args['show_in_rest'] = true;
$args['exclude_from_search'] = false;
return $args;
}
add_action( 'add_meta_boxes', __NAMESPACE__ . '\\add_meta_boxes', 11 );
/**
* Re-register metabox with a context compatible with Gutenberg
*/
function add_meta_boxes() {
// Sections
add_meta_box(
'sugar_calendar_event_details',
esc_html__( 'Event', 'sugar-calendar' ),
'Sugar_Calendar\\Admin\\Editor\\Meta\\box',
sugar_calendar_allowed_post_types(),
'advanced',
'high'
);
/*
No register this metabox, doublon with Gutenberg
add_meta_box(
'sugar_calendar_details',
esc_html__( 'Details', 'sugar-calendar' ),
'Sugar_Calendar\\Admin\\Editor\\Meta\\details',
sugar_calendar_get_event_post_type_id(),
'advanced',
'default'
);
*/
}
@herewithme
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment