>get_attribute( 'class' ); if ( is_string( $class_attribute ) && str_contains( $class_attribute, $inner_block_wrapper_classes ) ) { break; } } while ( $processor->next_tag() ); // Add the remaining class names. foreach ( $class_names as $class_name ) { $processor->add_class( $class_name ); } return $processor->get_updated_html(); } /** * Check if the parent block exists and if it has a layout attribute. * If it does, add the parent layout to the parsed block * * @since 6.6.0 * @access private * * @param array $parsed_block The parsed block. * @param array $source_block The source block. * @param WP_Block $parent_block The parent block. * @return array The parsed block with parent layout attribute if it exists. */ function wp_add_parent_layout_to_parsed_block( $parsed_block, $source_block, $parent_block ) { if ( $parent_block && isset( $parent_block->parsed_block['attrs']['layout'] ) ) { $parsed_block['parentLayout'] = $parent_block->parsed_block['attrs']['layout']; } return $parsed_block; } add_filter( 'render_block_data', 'wp_add_parent_layout_to_parsed_block', 10, 3 ); // Register the block support. WP_Block_Supports::get_instance()->register( 'layout', array( 'register_attribute' => 'wp_register_layout_support', ) ); add_filter( 'render_block', 'wp_render_layout_support_flag', 10, 2 ); /** * For themes without theme.json file, make sure * to restore the inner div for the group block * to avoid breaking styles relying on that div. * * @since 5.8.0 * @access private * * @param string $block_content Rendered block content. * @param array $block Block object. * @return string Filtered block content. */ function wp_restore_group_inner_container( $block_content, $block ) { $tag_name = isset( $block['attrs']['tagName'] ) ? $block['attrs']['tagName'] : 'div'; $group_with_inner_container_regex = sprintf( '/(^\s*<%1$s\b[^>]*wp-block-group(\s|")[^>]*>)(\s*]*wp-block-group__inner-container(\s|")[^>]*>)((.|\S|\s)*)/U', preg_quote( $tag_name, '/' ) ); if ( wp_theme_has_theme_json() || 1 === preg_match( $group_with_inner_container_regex, $block_content ) || ( isset( $block['attrs']['layout']['type'] ) && 'flex' === $block['attrs']['layout']['type'] ) ) { return $block_content; } /* * This filter runs after the layout classnames have been added to the block, so they * have to be removed from the outer wrapper and then added to the inner. */ $layout_classes = array(); $processor = new WP_HTML_Tag_Processor( $block_content ); if ( $processor->next_tag( array( 'class_name' => 'wp-block-group' ) ) ) { foreach ( $processor->class_list() as $class_name ) { if ( str_contains( $class_name, 'is-layout-' ) ) { $layout_classes[] = $class_name; $processor->remove_class( $class_name ); } } } $content_without_layout_classes = $processor->get_updated_html(); $replace_regex = sprintf( '/(^\s*<%1$s\b[^>]*wp-block-group[^>]*>)(.*)(<\/%1$s>\s*$)/ms', preg_quote( $tag_name, '/' ) ); $updated_content = preg_replace_callback( $replace_regex, static function ( $matches ) { return $matches[1] . '
' . $matches[2] . '
' . $matches[3]; }, $content_without_layout_classes ); // Add layout classes to inner wrapper. if ( ! empty( $layout_classes ) ) { $processor = new WP_HTML_Tag_Processor( $updated_content ); if ( $processor->next_tag( array( 'class_name' => 'wp-block-group__inner-container' ) ) ) { foreach ( $layout_classes as $class_name ) { $processor->add_class( $class_name ); } } $updated_content = $processor->get_updated_html(); } return $updated_content; } add_filter( 'render_block_core/group', 'wp_restore_group_inner_container', 10, 2 ); /** * For themes without theme.json file, make sure * to restore the outer div for the aligned image block * to avoid breaking styles relying on that div. * * @since 6.0.0 * @access private * * @param string $block_content Rendered block content. * @param array $block Block object. * @return string Filtered block content. */ function wp_restore_image_outer_container( $block_content, $block ) { $image_with_align = " /# 1) everything up to the class attribute contents ( ^\s* ]* \bclass= [\"'] ) # 2) the class attribute contents ( [^\"']* \bwp-block-image\b [^\"']* \b(?:alignleft|alignright|aligncenter)\b [^\"']* ) # 3) everything after the class attribute contents ( [\"'] [^>]* > .* <\/figure> )/iUx"; if ( wp_theme_has_theme_json() || 0 === preg_match( $image_with_align, $block_content, $matches ) ) { return $block_content; } $wrapper_classnames = array( 'wp-block-image' ); // If the block has a classNames attribute these classnames need to be removed from the content and added back // to the new wrapper div also. if ( ! empty( $block['attrs']['className'] ) ) { $wrapper_classnames = array_merge( $wrapper_classnames, explode( ' ', $block['attrs']['className'] ) ); } $content_classnames = explode( ' ', $matches[2] ); $filtered_content_classnames = array_diff( $content_classnames, $wrapper_classnames ); return '
' . $matches[1] . implode( ' ', $filtered_content_classnames ) . $matches[3] . '
'; } add_filter( 'render_block_core/image', 'wp_restore_image_outer_container', 10, 2 ); lendar', 'yarpp_support'=>true )); if ( get_option('dbem_recurrence_enabled') ){ $event_recurring_post_type = apply_filters('em_cpt_event_recurring', array( 'public' => apply_filters('em_cp_event_recurring_public', false), 'show_ui' => true, 'show_in_admin_bar' => true, 'show_in_menu' => 'edit.php?post_type='.EM_POST_TYPE_EVENT, 'show_in_nav_menus'=>false, 'publicly_queryable' => apply_filters('em_cp_event_recurring_publicly_queryable', false), 'exclude_from_search' => true, 'has_archive' => false, 'can_export' => true, 'hierarchical' => false, 'supports' => $event_post_type_supports, 'capability_type' => 'recurring_events', 'rewrite' => array('slug' => 'events-recurring','with_front'=>false), 'capabilities' => array( 'publish_posts' => 'publish_recurring_events', 'edit_posts' => 'edit_recurring_events', 'edit_others_posts' => 'edit_others_recurring_events', 'delete_posts' => 'delete_recurring_events', 'delete_others_posts' => 'delete_others_recurring_events', 'read_private_posts' => 'read_private_recurring_events', 'edit_post' => 'edit_recurring_event', 'delete_post' => 'delete_recurring_event', 'read_post' => 'read_recurring_event', ), 'label' => __('Recurring Events','events-manager'), 'description' => __('Recurring Events Template','events-manager'), 'labels' => array ( 'name' => __('Recurring Events','events-manager'), 'singular_name' => __('Recurring Event','events-manager'), 'menu_name' => __('Recurring Events','events-manager'), 'add_new' => __('Add Recurring Event','events-manager'), 'add_new_item' => __('Add New Recurring Event','events-manager'), 'edit' => __('Edit','events-manager'), 'edit_item' => __('Edit Recurring Event','events-manager'), 'new_item' => __('New Recurring Event','events-manager'), 'view' => __('View','events-manager'), 'view_item' => __('Add Recurring Event','events-manager'), 'search_items' => __('Search Recurring Events','events-manager'), 'not_found' => __('No Recurring Events Found','events-manager'), 'not_found_in_trash' => __('No Recurring Events Found in Trash','events-manager'), 'parent' => __('Parent Recurring Event','events-manager'), ) )); } if( get_option('dbem_locations_enabled', true) ){ $location_post_type = apply_filters('em_cpt_location', array( 'public' => true, 'hierarchical' => false, 'show_in_admin_bar' => true, //if in MS Global mode with locations shown on main blog, then the ui shouldn't be available on network blogs: 'show_ui' => !(EM_MS_GLOBAL && !is_main_site() && get_site_option('dbem_ms_mainblog_locations')), 'show_in_menu' => 'edit.php?post_type='.EM_POST_TYPE_EVENT, 'show_in_nav_menus'=>true, 'can_export' => true, 'exclude_from_search' => !get_option('dbem_cp_locations_search_results'), 'publicly_queryable' => true, 'rewrite' => array('slug' => EM_POST_TYPE_LOCATION_SLUG, 'with_front'=>false), 'query_var' => true, 'has_archive' => get_option('dbem_cp_locations_has_archive', false) == true, 'supports' => apply_filters('em_cp_location_supports', array('title','editor','excerpt','custom-fields','comments','thumbnail','author')), 'capability_type' => 'location', 'capabilities' => array( 'publish_posts' => 'publish_locations', 'delete_others_posts' => 'delete_others_locations', 'delete_posts' => 'delete_locations', 'delete_post' => 'delete_location', 'edit_others_posts' => 'edit_others_locations', 'edit_posts' => 'edit_locations', 'edit_post' => 'edit_location', 'read_private_posts' => 'read_private_locations', 'read_post' => 'read_location', ), 'label' => __('Locations','events-manager'), 'description' => __('Display locations on your blog.','events-manager'), 'labels' => array ( 'name' => __('Locations','events-manager'), 'singular_name' => __('Location','events-manager'), 'menu_name' => __('Locations','events-manager'), 'add_new' => __('Add Location','events-manager'), 'add_new_item' => __('Add New Location','events-manager'), 'edit' => __('Edit','events-manager'), 'edit_item' => __('Edit Location','events-manager'), 'new_item' => __('New Location','events-manager'), 'view' => __('View','events-manager'), 'view_item' => __('View Location','events-manager'), 'search_items' => __('Search Locations','events-manager'), 'not_found' => __('No Locations Found','events-manager'), 'not_found_in_trash' => __('No Locations Found in Trash','events-manager'), 'parent' => __('Parent Location','events-manager'), ), 'yarpp_support'=>true )); } //gutenberg support - define EM_GUTENBERG in your wp-config.php page to enable if( defined('EM_GUTENBERG') && EM_GUTENBERG ){ $event_post_type['show_in_rest'] = true; if ( get_option('dbem_recurrence_enabled') ) $event_recurring_post_type['show_in_rest'] = true; if( get_option('dbem_locations_enabled', true) ) $location_post_type['show_in_rest'] = true; function em_gutenberg_support( $can_edit, $post_type ){ $recurrences = $post_type == 'event-recurring' && get_option('dbem_recurrence_enabled'); $locations = $post_type == EM_POST_TYPE_LOCATION && get_option('dbem_locations_enabled', true); if( $post_type == EM_POST_TYPE_EVENT || $recurrences || $locations ) $can_edit = true; return $can_edit; } add_filter('gutenberg_can_edit_post_type', 'em_gutenberg_support', 10, 2 ); //Gutenberg } if( EM_POST_TYPE_LOCATION_SLUG !== '' && strstr(EM_POST_TYPE_EVENT_SLUG, EM_POST_TYPE_LOCATION_SLUG) !== FALSE ){ //Now register posts, but check slugs in case of conflicts and reorder registrations register_post_type(EM_POST_TYPE_EVENT, $event_post_type); if ( get_option('dbem_recurrence_enabled') ){ register_post_type('event-recurring', $event_recurring_post_type); } if( get_option('dbem_locations_enabled', true) ){ register_post_type(EM_POST_TYPE_LOCATION, $location_post_type); } }else{ if( get_option('dbem_locations_enabled', true) ){ register_post_type(EM_POST_TYPE_LOCATION, $location_post_type); } register_post_type(EM_POST_TYPE_EVENT, $event_post_type); //Now register posts, but check slugs in case of conflicts and reorder registrations if ( get_option('dbem_recurrence_enabled') ){ register_post_type('event-recurring', $event_recurring_post_type); } } } //Post Customization function supported_event_custom_fields($supported){ $remove = array(); if( !get_option('dbem_cp_events_custom_fields') ) $remove[] = 'custom-fields'; if( !get_option('dbem_cp_events_comments') ) $remove[] = 'comments'; return supported_custom_fields($supported, $remove); } add_filter('em_cp_event_supports', 'supported_event_custom_fields',10,1); function supported_location_custom_fields($supported){ $remove = array(); if( !get_option('dbem_cp_locations_custom_fields') ) $remove[] = 'custom-fields'; if( !get_option('dbem_cp_locations_comments') ) $remove[] = 'comments'; return supported_custom_fields($supported, $remove); } add_filter('em_cp_location_supports', 'supported_location_custom_fields',10,1); function supported_custom_fields($supported, $remove = array()){ foreach($supported as $key => $support_field){ if( in_array($support_field, $remove) ){ unset($supported[$key]); } } return $supported; } function em_map_meta_cap( $caps, $cap, $user_id, $args ) { if( !empty( $args[0]) ){ /* Handle event reads */ if ( 'edit_event' == $cap || 'delete_event' == $cap || 'read_event' == $cap ) { $post = get_post($args[0]); //check for revisions and deal with non-event post types if( !empty($post->post_type) && $post->post_type == 'revision' ) $post = get_post($post->post_parent); if( empty($post->post_type) || !in_array($post->post_type, array(EM_POST_TYPE_EVENT, 'event-recurring')) ) return $caps; //continue with getting post type and assigning caps $EM_Event = em_get_event($post); $post_type = get_post_type_object( $EM_Event->post_type ); /* Set an empty array for the caps. */ $caps = array(); //Filter according to event caps switch( $cap ){ case 'read_event': if ( 'private' != $EM_Event->post_status ) $caps[] = 'read'; elseif ( $user_id == $EM_Event->event_owner ) $caps[] = 'read'; else $caps[] = $post_type->cap->read_private_posts; break; case 'edit_event': if ( $user_id == $EM_Event->event_owner ) $caps[] = $post_type->cap->edit_posts; else $caps[] = $post_type->cap->edit_others_posts; break; case 'delete_event': if ( $user_id == $EM_Event->event_owner ) $caps[] = $post_type->cap->delete_posts; else $caps[] = $post_type->cap->delete_others_posts; break; } } if ( 'edit_recurring_event' == $cap || 'delete_recurring_event' == $cap || 'read_recurring_event' == $cap ) { $post = get_post($args[0]); //check for revisions and deal with non-event post types if( !empty($post->post_type) && $post->post_type == 'revision' ) $post = get_post($post->post_parent); if( empty($post->post_type) || $post->post_type != 'event-recurring' ) return $caps; //continue with getting post type and assigning caps $EM_Event = em_get_event($post); $post_type = get_post_type_object( $EM_Event->post_type ); /* Set an empty array for the caps. */ $caps = array(); //Filter according to recurring_event caps switch( $cap ){ case 'read_recurring_event': if ( 'private' != $EM_Event->post_status ) $caps[] = 'read'; elseif ( $user_id == $EM_Event->event_owner ) $caps[] = 'read'; else $caps[] = $post_type->cap->read_private_posts; break; case 'edit_recurring_event': if ( $user_id == $EM_Event->event_owner ) $caps[] = $post_type->cap->edit_posts; else $caps[] = $post_type->cap->edit_others_posts; break; case 'delete_recurring_event': if ( $user_id == $EM_Event->event_owner ) $caps[] = $post_type->cap->delete_posts; else $caps[] = $post_type->cap->delete_others_posts; break; } } if ( 'edit_location' == $cap || 'delete_location' == $cap || 'read_location' == $cap ) { $post = get_post($args[0]); //check for revisions and deal with non-location post types if( !empty($post->post_type) && $post->post_type == 'revision' ) $post = get_post($post->post_parent); if( empty($post->post_type) || $post->post_type != EM_POST_TYPE_LOCATION ) return $caps; //continue with getting post type and assigning caps $EM_Location = em_get_location($post); $post_type = get_post_type_object( $EM_Location->post_type ); /* Set an empty array for the caps. */ $caps = array(); //Filter according to location caps switch( $cap ){ case 'read_location': if ( 'private' != $EM_Location->post_status ) $caps[] = 'read'; elseif ( $user_id == $EM_Location->location_owner ) $caps[] = 'read'; else $caps[] = $post_type->cap->read_private_posts; break; case 'edit_location': if ( $user_id == $EM_Location->location_owner ) $caps[] = $post_type->cap->edit_posts; else $caps[] = $post_type->cap->edit_others_posts; break; case 'delete_location': if ( $user_id == $EM_Location->location_owner ) $caps[] = $post_type->cap->delete_posts; else $caps[] = $post_type->cap->delete_others_posts; break; } } } /* Return the capabilities required by the user. */ return $caps; } add_filter( 'map_meta_cap', 'em_map_meta_cap', 10, 4 );