mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 08:32:23 +01:00
65 lines
2.2 KiB
PHP
65 lines
2.2 KiB
PHP
<?php
|
|
defined( 'ABSPATH' ) or die( 'Nope, not accessing this' );
|
|
|
|
|
|
/**
|
|
* ADD gancio-event / gancio-events as allowed tags in post and tinymce-editor
|
|
*/
|
|
function add_gancio_events_to_kses_allowed($the_allowed_tags)
|
|
{
|
|
$the_allowed_tags['gancio-events'] = array('tags' => true, 'places' => true, 'theme' => true, 'id' => true, 'baseurl' => true, 'collection' => true, 'maxlength' => true);
|
|
$the_allowed_tags['gancio-event'] = array('id' => true, 'url' => true);
|
|
return $the_allowed_tags;
|
|
}
|
|
add_filter('wp_kses_allowed_html', 'add_gancio_events_to_kses_allowed', 10, 1);
|
|
|
|
function tinymce_init( $init ) {
|
|
$ext = 'gancio-event[id,url],gancio-events[baseurl,places,tags,theme,maxlength,collection]';
|
|
if ( isset( $init['extended_valid_elements'] ) ) {
|
|
$init['extended_valid_elements'] .= ',' . $ext;
|
|
} else {
|
|
$init['extended_valid_elements'] = $ext;
|
|
}
|
|
return $init;
|
|
}
|
|
add_filter('tiny_mce_before_init', 'tinymce_init');
|
|
|
|
/** ADD SHORTCODES */
|
|
function gancio_event_handler_function( $atts, $content, $tag) {
|
|
$a = shortcode_atts( array(
|
|
'baseurl' => 'https://demo.gancio.org',
|
|
'id' => 0
|
|
), $atts);
|
|
return '<gancio-event baseurl="' . $a['baseurl'] . '" id=' . $a['id'] . '></gancio-event>';
|
|
}
|
|
|
|
function gancio_events_handler_function( $atts, $content, $tag) {
|
|
$a = shortcode_atts( array(
|
|
'baseurl' => 'https://demo.gancio.org',
|
|
'places' => '',
|
|
'tags' => '',
|
|
'collection' => '',
|
|
'theme' => 'dark',
|
|
'maxlength' => null
|
|
), $atts);
|
|
return '<gancio-events baseurl="' . $a['baseurl'] . '" maxlength=' . $a['maxlength'] . ' theme="' . $a['theme'] . '" places="' . $a['places'] . '" tags="' . $a['tags'] . '" collection="' . $a['collection']. '"></gancio-events>';
|
|
}
|
|
|
|
add_action( 'init', function () {
|
|
global $allowedposttags;
|
|
$allowedposttags['gancio-event'] = array(
|
|
'id' => array(),
|
|
'baseurl' => array(),
|
|
'theme' => array()
|
|
);
|
|
add_shortcode('gancio-event', 'gancio_event_handler_function');
|
|
add_shortcode('gancio-events', 'gancio_events_handler_function');
|
|
});
|
|
|
|
|
|
/** ADD WEB COMPONENT SCRIPT */
|
|
add_action('wp_enqueue_scripts', 'add_gancio_custom_js');
|
|
function add_gancio_custom_js() {
|
|
wp_enqueue_script('gancio-wc', plugins_url('/js/gancio-events.es.js', __FILE__));
|
|
}
|
|
|