Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
244 changes: 143 additions & 101 deletions composer.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ private function define_admin_hooks() {
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_public, 'insert_event_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
$this->loader->add_action( 'enqueue_block_editor_assets', $plugin_admin, 'enqueue_editor_scripts' );
$this->loader->add_filter( 'block_editor_settings_all', $plugin_public, 'inject_event_gradient_editor_style', 10, 2 );
$this->loader->add_action( 'init', $plugin_admin, 'new_cpts' );
$this->loader->add_action( 'init', $plugin_admin, 'register_event_categories' );
$this->loader->add_action( 'init', $plugin_admin, 'change_page_label' );
Expand Down Expand Up @@ -214,6 +215,7 @@ private function define_public_hooks() {
$this->loader->add_action( 'template_redirect', $plugin_public, 'redirects' );
$this->loader->add_action( 'wp_footer', $plugin_public, 'deregister_scripts' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'insert_event_styles' );
$this->loader->add_action( 'enqueue_block_assets', $plugin_public, 'insert_event_styles' );
$this->loader->add_filter( 'the_seo_framework_title_from_generation', $plugin_public, 'add_year_to_archive_titles' );
$this->loader->add_filter( 'excerpt_more', $plugin_public, 'new_excerpt_more' );
$this->loader->add_filter( 'excerpt_length', $plugin_public, 'custom_excerpt_length', 999 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,56 @@ public function deregister_scripts() {
* Inserts css into the head with the event gradient.
*/
public function insert_event_styles() {
static $did_enqueue = false;

if ( $did_enqueue ) {
return;
}

$post_id = 0;

global $pagenow;
// Run on frontend event post types, or pages.

// Frontend event pages.
if ( is_singular( lfe_get_post_types() ) ) {
self::create_event_styles();
$post_id = get_queried_object_id();
}

if ( is_admin() && 'post.php' == $pagenow ) {
self::create_event_styles();
// Block editor and classic admin post editing pages.
if ( is_admin() && ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) ) {
$get_post_id = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT );
$form_post_id = filter_input( INPUT_POST, 'post_ID', FILTER_VALIDATE_INT );

if ( $get_post_id ) {
$post_id = (int) $get_post_id;
} elseif ( $form_post_id ) {
$post_id = (int) $form_post_id;
} else {
global $post;
if ( is_object( $post ) && isset( $post->ID ) ) {
$post_id = (int) $post->ID;
}
}

// Some block editor asset requests do not include post in query params.
if ( ! $post_id ) {
$referer = wp_get_referer();
if ( $referer ) {
$referer_query = wp_parse_url( $referer, PHP_URL_QUERY );
if ( $referer_query ) {
parse_str( $referer_query, $referer_args );
if ( ! empty( $referer_args['post'] ) ) {
$post_id = (int) $referer_args['post'];
} elseif ( ! empty( $referer_args['postId'] ) ) {
$post_id = (int) $referer_args['postId'];
}
}
}
}
}

if ( $post_id ) {
$did_enqueue = self::create_event_styles( $post_id );
}
Comment on lines +188 to 190
}

Expand Down Expand Up @@ -355,44 +396,140 @@ public function add_header_cache() {

/**
* Creates css into the head with the event gradient
*
* @param int $post_id Optional post ID to derive event colors from.
* @return bool True when styles are generated and enqueued.
*/
public function create_event_styles() {
public function create_event_styles( $post_id = 0 ) {

global $post;
if ( ! $post_id ) {
global $post;
if ( ! is_object( $post ) || ! isset( $post->ID ) ) {
return false;
}
$post_id = (int) $post->ID;
}

if ( $post->post_parent ) {
$ancestors = get_post_ancestors( $post->ID );
$event_post = get_post( $post_id );
if ( ! $event_post ) {
return false;
}

if ( ! in_array( $event_post->post_type, lfe_get_post_types(), true ) ) {
return false;
}

if ( $event_post->post_parent ) {
$ancestors = get_post_ancestors( $post_id );
$parent_id = $ancestors[ count( $ancestors ) - 1 ];
} else {
$parent_id = $post->ID;
$parent_id = $post_id;
}
Comment on lines +422 to 427

if ( in_array( $post->post_type, lfe_get_post_types() ) && $parent_id ) {
if ( $parent_id ) {

$menu_color = get_post_meta( $parent_id, 'lfes_menu_color', true );
$menu_color_2 = get_post_meta( $parent_id, 'lfes_menu_color_2', true );
$background_color = 'background-color: ' . $menu_color . ';';
if ( $menu_color_2 ) {
$background_color = 'background: linear-gradient(90deg, ' . $menu_color . ' 0%, ' . $menu_color_2 . ' 100%);';
$event_css = $this->build_event_gradient_css( $parent_id );
if ( ! $event_css ) {
return false;
}

// Register and enqueue an empty style sheet first.
wp_register_style( 'event-gradient-inline-style', false, array(), $this->version, 'all' );
wp_enqueue_style( 'event-gradient-inline-style' );

// Then add the inline styles to it.
wp_add_inline_style( 'event-gradient-inline-style', $event_css );

return true;
}

return false;
}

/**
* Inject event gradient CSS directly into block editor settings.
*
* @param array $editor_settings Editor settings array.
* @param object $editor_context Current editor context.
* @return array
*/
public function inject_event_gradient_editor_style( $editor_settings, $editor_context ) {
$post_id = 0;

if ( is_object( $editor_context ) && isset( $editor_context->post ) && is_object( $editor_context->post ) ) {
$post_id = (int) $editor_context->post->ID;
}

if ( ! $post_id ) {
$get_post_id = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT );
if ( $get_post_id ) {
$post_id = (int) $get_post_id;
}
$background_style = '.is-style-event-gradient { ' . esc_html( $background_color ) . '}';
}

if ( ! $post_id ) {
return $editor_settings;
}

$event_post = get_post( $post_id );
if ( ! $event_post || ! in_array( $event_post->post_type, lfe_get_post_types(), true ) ) {
return $editor_settings;
}

if ( $event_post->post_parent ) {
$ancestors = get_post_ancestors( $post_id );
$parent_id = (int) end( $ancestors );
} else {
$parent_id = $post_id;
}
if ( ! $parent_id ) {
return $editor_settings;
}

$event_css = $this->build_event_gradient_css( $parent_id );
if ( ! $event_css ) {
return $editor_settings;
}

if ( ! isset( $editor_settings['styles'] ) || ! is_array( $editor_settings['styles'] ) ) {
$editor_settings['styles'] = array();
}

$editor_settings['styles'][] = array(
'css' => $event_css,
);

// adding CSS variables, use these for future styles per event.
$css_variables_for_events = '
return $editor_settings;
}

/**
* Build CSS for event gradient and event color variables.
*
* @param int $parent_id Root event page ID.
* @return string|false
*/
private function build_event_gradient_css( $parent_id ) {
$menu_color = get_post_meta( $parent_id, 'lfes_menu_color', true );
$menu_color_2 = get_post_meta( $parent_id, 'lfes_menu_color_2', true );

if ( empty( $menu_color ) ) {
return false;
}

$background_color = 'background-color: ' . $menu_color . ';';
if ( $menu_color_2 ) {
$background_color = 'background: linear-gradient(90deg, ' . $menu_color . ' 0%, ' . $menu_color_2 . ' 100%);';
}
Comment on lines +511 to +522

$background_style = '.is-style-event-gradient { ' . esc_html( $background_color ) . '}';

$css_variables_for_events = '
:root {
--event-color-1: ' . esc_html( $menu_color ) . ';
--event-color-2: ' . esc_html( $menu_color_2 ? $menu_color_2 : $menu_color ) . ';
}';

// Register and enqueue an empty style sheet first.
wp_register_style( 'event-gradient-inline-style', false, array(), true, 'all' );
wp_enqueue_style( 'event-gradient-inline-style' );

// Then add the inline styles to it.
wp_add_inline_style( 'event-gradient-inline-style', $background_style );
wp_add_inline_style( 'event-gradient-inline-style', $css_variables_for_events );
}
return $background_style . "\n" . $css_variables_for_events;
}

/**
Expand Down
10 changes: 8 additions & 2 deletions web/wp-content/plugins/countdown-block/src/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,17 @@ function countdown_block_assets() { // phpcs:ignore
);
}

function countdown_block_callback( $attributes ) { // phpcs:ignore
function countdown_block_callback( $attributes, $content = '', $block = null ) { // phpcs:ignore
$labels = array();
$block_id = isset( $attributes['blockID'] ) ? $attributes['blockID'] : '';
$end_date = isset( $attributes['endDate'] ) ? $attributes['endDate'] : false;
$style = isset( $attributes['style'] ) ? $attributes['style'] : 'Odometer';
// Read "style" from the raw parsed block attrs because WP core now treats
// the "style" attribute name as reserved (object schema for block supports)
// and strips our string value during prepare_attributes_for_render().
$raw_style = ( $block instanceof WP_Block && isset( $block->parsed_block['attrs']['style'] ) )
? $block->parsed_block['attrs']['style']
: ( isset( $attributes['style'] ) ? $attributes['style'] : null );
$style = is_string( $raw_style ) ? $raw_style : 'Odometer';
$circle_color = isset( $attributes['circleColor'] ) ? $attributes['circleColor'] : '#2DB7F5';
$expiry_message = isset( $attributes['expiryMessage'] ) ? $attributes['expiryMessage'] : 'Timer expired';
$labels['weeks'] = isset( $attributes['labelWeeks'] ) ? $attributes['labelWeeks'] : 'Weeks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function lfe_content_filter( $content ) {
preg_match( '/data-menu-slug="([^"]*)"/i', $match, $id );
preg_match( '/data-menu-title="([^"]*)"/i', $match, $menu_title );

if ( ! isset( $id[1], $menu_title[1] ) ) {
continue;
}

$menu .= '<li><a href="#' . $id[1] . '">' . $menu_title[1] . '</a></li>';
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.lf-footer {
padding-top: 5rem;
padding-bottom: 2rem;
background-color: #000f1a !important;

&__privacy {
font-size: 0.7rem;
Expand Down
Loading