Skip to content

Commit

Permalink
Updates to RSVP and added groups SVG.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauteri committed Dec 23, 2024
1 parent e0e185c commit d4216fb
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build/blocks/icon/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'bde5c36600fbb0593248');
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '2f2688ce878edc670694');
2 changes: 1 addition & 1 deletion build/blocks/icon/index.js

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

1 change: 1 addition & 0 deletions includes/assets/svg/groups.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions includes/core/classes/blocks/class-general-block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php
/**
* The "General_Block" class handles general-purpose block functionality,
* providing a catch-all for block-related logic that is not specific to any single block.
*
* This class ensures proper behavior and rendering adjustments for blocks
* that do not belong to a specific block type but require additional processing.
*
* @package GatherPress\Core
* @since 1.0.0
*/

namespace GatherPress\Core\Blocks;

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore

use GatherPress\Core\Block;
use GatherPress\Core\Traits\Singleton;
use WP_HTML_Tag_Processor;

/**
* Class responsible for managing general block-related functionality
* and applying modifications that are not tied to specific block types.
*
* This class acts as a central handler for non-specific block logic,
* such as filtering or injecting attributes for blocks with certain characteristics.
*
* @since 1.0.0
*/
class General_Block {
/**
* Enforces a single instance of this class.
*/
use Singleton;

/**
* Class constructor.
*
* This method initializes the object and sets up necessary hooks.
*
* @since 1.0.0
*/
protected function __construct() {
$this->setup_hooks();
}

/**
* Set up hooks for various purposes.
*
* This method adds hooks for different purposes as needed.
*
* @since 1.0.0
*
* @return void
*/
protected function setup_hooks(): void {
add_filter( 'render_block', array( $this, 'remove_block_if_user_logged_in' ), 10, 2 );
add_filter( 'render_block', array( $this, 'remove_block_if_registration_disabled' ), 10, 2 );
}

/**
* Removes blocks with the `gatherpress--has-login-url` class if the user is logged in.
*
* This method checks if the block contains the `gatherpress--has-login-url` class
* and removes it from rendering if the user is currently logged in.
*
* @since 1.0.0
*
* @param string $block_content The HTML content of the block.
* @param array $block The parsed block data.
*
* @return string The modified block content or an empty string if the block should be removed.
*/
public function remove_block_if_user_logged_in( string $block_content, array $block ): string {
if (
false !== strpos( $block['attrs']['className'] ?? '', 'gatherpress--has-login-url' ) &&
is_user_logged_in()
) {
return '';
}

return $block_content;
}

/**
* Removes blocks with the `gatherpress--has-registration-url` class if user registration is disabled.
*
* This method checks if the block contains the `gatherpress--has-registration-url` class
* and removes it from rendering if the WordPress `users_can_register` option is disabled.
*
* @since 1.0.0
*
* @param string $block_content The HTML content of the block.
* @param array $block The parsed block data.
*
* @return string The modified block content or an empty string if the block should be removed.
*/
public function remove_block_if_registration_disabled( string $block_content, array $block ): string {
if (
false !== strpos( $block['attrs']['className'] ?? '', 'gatherpress--has-registration-url' ) &&
! get_option( 'users_can_register' )
) {
return '';
}

return $block_content;
}
}
18 changes: 9 additions & 9 deletions includes/core/classes/blocks/class-rsvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ class Rsvp {
*/
use Singleton;

/**
* Constant representing the Block Name.
*
* @since 1.0.0
* @var string
*/
const BLOCK_NAME = 'gatherpress/rsvp-v2';

/**
* Class constructor.
*
Expand Down Expand Up @@ -67,7 +75,7 @@ protected function setup_hooks(): void {
public function transform_block_content( string $block_content, array $block ): string {
$block_instance = Block::get_instance();

if ( 'gatherpress/rsvp-v2' === $block['blockName'] ) {
if ( self::BLOCK_NAME === $block['blockName'] ) {
$inner_blocks = isset( $block['innerBlocks'] ) ? $block['innerBlocks'] : array();
$tag = new WP_HTML_Tag_Processor( $block_content );
$attributes = isset( $block['attrs'] ) ? $block['attrs'] : array();
Expand Down Expand Up @@ -145,14 +153,6 @@ public function transform_block_content( string $block_content, array $block ):
$block_content = $tag->get_updated_html();
}

if (
isset( $block['attrs']['className'] ) &&
false !== strpos( $block['attrs']['className'], 'gatherpress--has-registration-url' ) &&
! get_option( 'users_can_register' )
) {
return '';
}

return $block_content;
}
}
1 change: 1 addition & 0 deletions includes/core/classes/class-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function register_blocks(): void {
*/
public function register_block_classes(): void {
Blocks\Add_To_Calendar::get_instance();
Blocks\General_Block::get_instance();
Blocks\Modal::get_instance();
Blocks\Modal_Manager::get_instance();
Blocks\Rsvp::get_instance();
Expand Down
1 change: 1 addition & 0 deletions src/blocks/icon/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const Edit = ({ attributes, setAttributes }) => {
{ label: __('Calendar', 'gatherpress'), value: 'calendar' },
{ label: __('Dismiss', 'gatherpress'), value: 'dismiss' },
{ label: __('Editor Help', 'gatherpress'), value: 'editor-help' },
{ label: __('Groups', 'gatherpress'), value: 'groups' },
{ label: __('Location', 'gatherpress'), value: 'location' },
{ label: __('Nametag', 'gatherpress'), value: 'nametag' },
{ label: __('Yes Alt', 'gatherpress'), value: 'yes-alt' },
Expand Down

0 comments on commit d4216fb

Please sign in to comment.