Skip to content

Commit

Permalink
Merge pull request #9 from abstractwp/feature/blocks-allowed
Browse files Browse the repository at this point in the history
limit blocks on presentation
  • Loading branch information
danhthong authored May 31, 2024
2 parents 33cd9fd + 632885b commit 3362441
Show file tree
Hide file tree
Showing 15 changed files with 11,165 additions and 14,466 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Thank you so much for your support!

## :scroll: Changelog

1.0.4

- Add a button to easily add a new slide.
- Update the allowed blocks on slides.

1.0.3

- Bug fixes to have build files.
Expand Down
103 changes: 62 additions & 41 deletions build/js/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/js/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/js/speaker.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'ff11960ef286343d79f4');
<?php return array('dependencies' => array(), 'version' => '307062363b25dbe5bbee');
2 changes: 1 addition & 1 deletion build/js/speaker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/js/template.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'b3d2b2853ad50319c0a0');
<?php return array('dependencies' => array(), 'version' => '09337a6b8bc56cecd4d0');
2 changes: 1 addition & 1 deletion build/js/template.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 64 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Presentation Block
* Plugin URI: https://wordpress.org/plugins/presentation-block/
* Description: Creates a custom post type “Presentation”, which will render as a presentation on the front end using Reveal.js.
* Version: 1.0.3
* Version: 1.0.4
* Author: AbstractWP
* Author URI: https://www.abstractwp.com/
* Text Domain: slide
Expand Down Expand Up @@ -359,3 +359,66 @@ function presentation_render_block( $block_content, $block ) {
return substr_replace( $block_content, $notes, $pos, 0 );
}
add_filter( 'render_block', __NAMESPACE__ . '\presentation_render_block', 10, 2 );

/**
* Only allow formanting and media blocks on presentation cpt.
*
* @param array $allowed_block_types the list of blocks.
* @param object $editor_context the editor context data.
*/
function presentation_allowed_block_types ( $allowed_block_types, $editor_context ) {
if ( ! empty( $editor_context->post ) ) {
if ( 'presentation' === $editor_context->post->post_type ) {
return array(
'core/heading',
'core/paragraph',
'core/list',
'core/list-item',
'core/quote',
'core/image',
'core/media-text',
'core/group',
'slide/slide',
);
}
}
return $allowed_block_types;
}
add_filter('allowed_block_types_all', __NAMESPACE__ . '\presentation_allowed_block_types', 10, 2);

/**
* Registers the block pattern categories.
*/
function presentation_register_block_pattern_categories() {
if ( function_exists( 'register_block_pattern_category' ) ) {
register_block_pattern_category( 'slide', array( 'label' => esc_html_x( 'Slide', 'Slide patterns category', 'slide' ) ) );
}
}
add_action( 'init', __NAMESPACE__ . '\presentation_register_block_pattern_categories' );

/**
* Registers the block patterns.
*/
function presentation_register_block_patterns() {

$files = array(
'home.php'
);

$path = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'patterns/';

foreach ( $files as $file ) {
if ( file_exists( $path . $file ) ) {
require_once $path . $file;
}
}
}
add_action( 'init', __NAMESPACE__ . '\presentation_register_block_patterns', 10, 1 );

/**
* Remove core patterns on presentation.
*/
function remove_block_patterns_support() {
remove_theme_support( 'core-block-patterns', array( 'presentation' ));
}
add_action('init', __NAMESPACE__ . '\remove_block_patterns_support');
Loading

0 comments on commit 3362441

Please sign in to comment.