Skip to content

Instantly share code, notes, and snippets.

@live-mesh
Last active June 12, 2024 19:12
Show Gist options
  • Save live-mesh/90a79048686651fa0bfbf0eb40493611 to your computer and use it in GitHub Desktop.
Save live-mesh/90a79048686651fa0bfbf0eb40493611 to your computer and use it in GitHub Desktop.
Examples of WP filters/hooks used to customize Livemesh Addons for Elementor
<?php
add_filter('lae_posts_carousel_entry_excerpt', 'mytheme_modify_posts_carousel_excerpt1', 10, 3);
function mytheme_modify_posts_carousel_excerpt1($excerpt, $post_id, $settings) {
$output = wp_trim_words($excerpt, 40, '...');
return $output;
}
add_filter('lae_gallery_image_lightbox_link', 'mytheme_modify_gallery_lightbox', 10, 3);
function mytheme_modify_gallery_lightbox($output, $item, $settings) {
$anchor_type = (empty($item['item_link']['url']) ? 'lae-click-anywhere' : 'lae-click-icon');
$output = '<a class="lae-lightbox-item ' . $anchor_type . '" data-fancybox="' . $settings['gallery_class'] . '" href="' . $item['item_image']['url'] . '" data-elementor-open-lightbox="no" title="' . esc_html($item['item_name']) . '" data-description="' . wp_kses_post($item['item_description']) . '">';
$output .= '<i class="lae-icon-full-screen"></i>';
$output .= '</a>';
return $output;
}
add_filter('lae_gallery_entry_text', 'mytheme_add_inline_title_for_videos', 10, 3);
function mytheme_add_inline_title_for_videos($entry_text, $item, $settings) {
$target = $item['item_link']['is_external'] ? 'target="_blank"' : '';
$entry_text = '<a href="' . esc_url($item['item_link']['url']) . '" title="' . esc_html($item['item_name']) . '"' . $target . '>' . esc_html($item['item_name']) . '</a>';
$entry_text = '<div class="entry-title">' . $entry_text . '</div>';
$entry_text .= '<div class="entry-description">' . esc_html($item['item_description']) . '</div>';
return $entry_text;
}
add_filter('lae_image_slider_flexslider_slider_button_output', 'mytheme_image_slider_slider_button_output', 10, 3);
add_filter('lae_image_slider_slickslider_slider_button_output', 'mytheme_image_slider_slider_button_output', 10, 3);
add_filter('lae_image_slider_responsiveslider_slider_button_output', 'mytheme_image_slider_slider_button_output', 10, 3);
function mytheme_image_slider_slider_button_output($slider_button, $slide, $settings) {
$button_type = ' my-custom-class'; // put your class here
$color_class = ' lae-' . esc_attr($slide['button_color']);
if (!empty($slide['button_type']))
$button_type = ' lae-' . esc_attr($slide['button_type']);
$rounded = ($slide['rounded'] == 'yes') ? ' lae-rounded' : '';
$slider_button = '<a class="lae-button ' . $color_class . $button_type . $rounded
. '" href="' . esc_url($slide['button_url']['url'])
. '" ' . (($slide['button_url']['is_external']) ? ' target="_blank"' : '')
. '>' . $slide['button_text'] . '</a>';
return $slider_button;
}
add_filter('lae_taxonomies_info', 'mytheme_modify_taxonomies_info', 10, 2);
function mytheme_modify_taxonomies_info($output, $taxonomies) {
$output .= '';
return $output;
}
add_filter('lae_posts_grid_xvbsgh_query_args', 'mytheme_modify_posts_grid_query1', 10, 2);
function mytheme_modify_posts_grid_query1($query_args, $settings) {
$query_args['post__not_in'] = array('1234'); // exclude post 1234
return $query_args;
}
add_filter('lae_block_d4c918d_query_args', 'mytheme_modify_posts_grid_query2', 10, 2);
function mytheme_modify_posts_grid_query2($query_args, $settings) {
$query_args['ignore_sticky_posts'] = 0; // do not ignore sticky posts
if (is_front_page()) {
$query_args['post__not_in'] = array(35139, 35069, 35037);
}
return $query_args;
}
add_filter('lae_block_filter_terms', 'mytheme_modify_block_filter_terms', 10, 2);
function mytheme_modify_block_filter_terms($block_filter_terms, $block) {
// sort the $block_filter_terms and return the sorted array
$sorted_terms = array();
$taxonomies[] = $block->settings['taxonomy_chosen'];
$block->settings['taxonomies'] = $taxonomies;
if ($block->settings['filterable']) {
$terms = get_terms(array(
'taxonomy' => $taxonomies[0],
'orderby' => 'name',
'order' => 'DESC'
));
if (!empty($terms) && !is_wp_error($terms)) {
$sorted_terms = $terms;
}
}
return $sorted_terms;
}
add_filter('lae_gallery_block_filter_terms', 'mytheme_modify_gallery_block_filter_terms', 10, 2);
function mytheme_modify_gallery_block_filter_terms($block_filter_terms, $block) {
// sort the $block_filter_terms and return the sorted array
$tags = $terms = array();
foreach ($block->block_items as $item) {
if (!empty($item['item_tags']))
$tags = array_merge($tags, explode(',', $item['item_tags']));
}
// trim whitespaces before applying array_unique
$tags = array_map('trim', $tags);
$success = sort(array_values(array_unique($tags))); // SORT HERE
if ($success && $block->settings['filterable']) {
foreach ($tags as $tag) {
$term = array();
$term['term_id'] = preg_replace('/\s+/', '-', $tag); // use the unique tag name itself as an id
$term['name'] = $tag;
$term['taxonomy'] = 'gallery_tag';
$terms[] = (object)$term;
}
}
return $terms;
}
add_filter('lae_taxonomy_terms_dropdown_limit', 'mytheme_taxonomy_terms_dropdown_limit', 10, 1);
function mytheme_taxonomy_terms_dropdown_limit($limit) {
$limit = 5000;
return $limit;
}
add_filter('lae_block_d4c918d_query_args', 'mytheme_modify_posts_grid_query3', 10, 2);
function mytheme_modify_posts_grid_query3($query_args, $settings) {
$query_args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => 123,
'order' => 'ASC',
'orderby' => 'menu_order'
);
return $query_args;
}
add_filter('lae_posts_grid_xvbsgh_query_args', 'mytheme_modify_posts_grid_query4', 10, 2);
function mytheme_modify_posts_grid_query4($query_args, $settings) {
global $post;
$query_args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
return $query_args;
}
add_filter('lae_block_d4c918d_query_args', 'mytheme_modify_posts_grid_query5', 10, 2);
function mytheme_modify_posts_grid_query5($query_args, $settings) {
global $post;
$query_args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
return $query_args;
}
add_filter('lae_block_module_3', 'mytheme_modify_module_3', 10, 2);
function mytheme_modify_module_3($output, $source) {
ob_start();
?>
<div class="lae-module-3 lae-small-thumb">
<?php echo $source->get_thumbnail('thumbnail'); ?>
<div class="lae-entry-details">
<?php echo $source->get_title(); ?>
<div class="lae-module-meta">
<?php echo $source->get_date(); ?>
</div>
</div>
</div>
<?php $output = ob_get_clean();
return $output;
}
add_filter('lae_posts_carousel_entry_excerpt', 'mytheme_modify_posts_carousel_entry_excerpt', 10, 3);
function mytheme_modify_posts_carousel_entry_excerpt($excerpt, $post_id, $settings) {
$excerpt = '<div class="lae-entry-content">';
$excerpt .= apply_filters('the_content', get_post_field('post_content', $post_id));
$excerpt .= '</div>';
return $excerpt;
}
add_filter('lae_block_filter_terms', 'mytheme_modify_block_filter_terms1', 10, 2);
function mytheme_modify_block_filter_terms1($block_filter_terms, $block) {
// sort the $block_filter_terms and return the sorted array
$sorted_terms = array();
$taxonomies[] = $this->settings['taxonomy_chosen'];
$this->settings['taxonomies'] = $taxonomies;
if ($this->settings['filterable']) {
$terms = get_terms(array(
'taxonomy' => $taxonomies[0],
'orderby' => 'name',
'order' => 'DESC'
));
if (!empty($terms) && !is_wp_error($terms)) {
$sorted_terms = $terms;
}
}
return $sorted_terms;
}
add_filter('lae_posts_grid_xvbsgh_query_args', 'mytheme_modify_posts_grid_query6', 10, 2);
function mytheme_modify_posts_grid_query6($query_args, $settings) {
global $post;
$query_args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
return $query_args;
}
add_filter('lae_posts_grid_entry_image', 'mytheme_modify_posts_grid_entry_image', 10, 3);
function mytheme_modify_posts_grid_entry_image($entry_image, $image_setting, $settings) {
$entry_image = '';
return $entry_image;
}
add_filter('lae_post_item_excerpt', 'mytheme_modify_posts_grid_entry_excerpt', 10, 2);
function mytheme_modify_posts_grid_entry_excerpt($output, $source) {
if ($source->settings['display_summary']) :
$excerpt_count = $source->settings['excerpt_length'];
$output = '<div class="entry-summary">';
if (empty($source->post->post_excerpt))
$excerpt = $source->post->post_content;
else
$excerpt = $source->post->post_excerpt;
if ($source->settings['rich_text_excerpt'])
$output .= do_shortcode(force_balance_tags(html_entity_decode(wp_trim_words(htmlentities($excerpt), $excerpt_count, '…'))));
else
$output .= wp_trim_words(wp_strip_all_tags(strip_shortcodes($excerpt)), $excerpt_count, '…');
$output .= '</div><!-- .entry-summary -->';
endif;
return $output;
}
add_filter('lae_block_d4c918d_query_args', 'mytheme_modify_posts_grid_query7', 10, 2);
function mytheme_modify_posts_grid_query7($query_args, $settings) {
$query_args['ignore_sticky_posts'] = 0; // do not ignore sticky posts
if (is_front_page()) {
$query_args['post__not_in'] = array(35139, 35069, 35037);
return $query_args;
}
}
add_filter('lae_posts_carousel_entry_excerpt', 'mytheme_modify_posts_carousel_add_read_more', 10, 3);
function mytheme_modify_posts_carousel_add_read_more($excerpt, $post_id, $settings) {
$read_more_text = __('Read More', 'livemesh-el-addons');
$excerpt .= '<div class="lae-read-more">';
$excerpt .= '<a class="lae-button" href="' . get_the_permalink($post_id) . '">' . $read_more_text . '</a>';
$excerpt .= '</div>';
return $excerpt;
}
// Free plugin
add_filter('lae_posts_grid_entry_excerpt', 'mytheme_restrict_excerpt', 10, 1);
function mytheme_restrict_excerpt($excerpt) {
$excerpt = '<div class="entry-summary">';
$length = 120; // number of characters without breaking the words
$append = '...';
$string = get_the_excerpt();
$string = trim($string);
if(strlen($string) > $length) {
$string = wordwrap($string, $length);
$string = explode("\n", $string, 2);
$string = $string[0] . $append;
}
$excerpt .= $string;
$excerpt .= '</div>';
return $excerpt;
}
add_filter('lae_block_filter_terms', 'mytheme_modify_block_filter_terms', 10, 2);
function mytheme_modify_block_filter_terms($block_filter_terms, $block) {
// change the position of array contents
mytheme_move_element($block_filter_terms, 0, 1);
return $block_filter_terms;
}
function mytheme_move_element(&$array, $a, $b) {
$out = array_splice($array, $a, 1);
array_splice($array, $b, 0, $out);
}
add_filter('lae_posts_grid_entry_excerpt', 'mytheme_restrict_excerpt', 10, 1);
function mytheme_restrict_excerpt($excerpt) {
$excerpt = '<div class="entry-summary">';
$length = 120; // number of characters without breaking the words
$append = '...';
$string = get_the_excerpt();
$string = trim($string);
if(strlen($string) > $length) {
$string = wordwrap($string, $length);
$string = explode("\n", $string, 2);
$string = $string[0] . $append;
}
$excerpt .= $string;
$read_more_text = __('Read More', 'livemesh-el-addons');
$excerpt .= '<div class="lae-read-more">';
$excerpt .= '<a class="lae-button" href="' . get_the_permalink($post_id) . '">' . $read_more_text . '</a>';
$excerpt .= '</div><!-- .lae-read-more -->';
$excerpt .= '</div><!-- .entry-summary -->';
return $excerpt;
}
add_filter('lae_posts_grid_image_info', 'mytheme_posts_grid_image_info', 10, 3);
function mytheme_posts_grid_image_info( $image_info, $post_id, $settings) {
$image_info = '<div class="lae-image-info">';
$image_info .= '<div class="lae-entry-info">';
$terms = get_the_terms($post_id, 'post_tag');
if (!empty($terms) && !is_wp_error($terms)) {
$image_info .= '<span class="lae-terms">';
$term_count = 0;
foreach ($terms as $term) {
if ($term_count != 0)
$image_info .= ', ';
$image_info .= $term->name;
$term_count = $term_count + 1;
}
$image_info .= '</span>';
}
$image_info .= '</div>';
$image_info .= '</div><!-- .lae-image-info -->';
return $image_info;
}
add_filter('lae_posts_carousel_image_info', 'mytheme_posts_carousel_image_info', 10, 3);
function mytheme_posts_carousel_image_info( $image_info, $post_id, $settings) {
$image_info = '<div class="lae-image-info">';
$image_info .= '<div class="lae-entry-info">';
// $image_info .= '<' . $settings['title_tag'] . ' class="lae-post-title"><a href="' . get_permalink() . '" title="' . get_the_title() . '" rel="bookmark">' . get_the_title() . '</a></' . $settings['title_tag'] . '>';
$image_info .= lae_get_info_for_taxonomies(array('category'));
$image_info .= '</div>';
$image_info .= '</div><!-- .lae-image-info -->';
return $image_info;
}
add_filter('lae_posts_carousel_image_info', 'mytheme_posts_carousel_image_info', 10, 3);
function mytheme_posts_carousel_image_info($image_info, $post_id, $settings) {
$image_info = '<div class="lae-image-info">';
$image_info .= '<div class="lae-entry-info">';
// $image_info .= '<' . $settings['title_tag'] . ' class="lae-post-title"><a href="' . get_permalink() . '" title="' . get_the_title() . '" rel="bookmark">' . get_the_title() . '</a></' . $settings['title_tag'] . '>';
$image_info .= lae_get_info_for_taxonomies(array('category'));
$image_info .= '</div>';
$image_info .= '</div><!-- .lae-image-info -->';
return $image_info;
}
add_filter('lae_posts_block_parsed_query_args', 'mytheme_modify_posts_grid_query1', 10, 2);
function mytheme_modify_posts_grid_query1($query_args, $params) {
$query_args['orderby'] = 'rand'; // sort random
return $query_args;
}
add_filter('lae_block_filter_terms', 'mytheme_modify_block_filter_terms', 10, 2);
function mytheme_modify_block_filter_terms($block_filter_terms, $block) {
// sort the $block_filter_terms and return the sorted array
$sorted_terms = array();
$taxonomies[] = $block->settings['taxonomy_chosen'];
$block->settings['taxonomies'] = $taxonomies;
if ($block->settings['filterable']) {
$terms = get_terms(array(
'taxonomy' => $taxonomies[0],
'orderby' => 'name',
'order' => 'ASC'
));
if (!empty($terms) && !is_wp_error($terms)) {
$sorted_terms = $terms;
}
}
return $sorted_terms;
}
add_filter('lae_posts_carousel_entry_excerpt', 'mytheme_modify_posts_carousel_excerpt1', 10, 3);
function mytheme_modify_posts_carousel_excerpt1($excerpt, $post_id, $settings) {
$output = wp_trim_words($excerpt, 40, '...');
return $output;
}
function my_theme_woocommerce_grid_add_to_quote_button($output, $source) {
ob_start();
?>
<article
class="lae-module-25 lae-module <?php echo join(' ', get_post_class('', $source->post_ID)); ?>">
<?php if ($thumbnail_exists = has_post_thumbnail($source->post_ID)): ?>
<div class="lae-module-image">
<?php echo $source->get_media(); ?>
<?php echo $source->get_product_on_sale(); ?>
<?php echo $source->get_product_wishlist(); ?>
<?php echo $source->get_product_quick_view(); ?>
</div>
<?php endif; ?>
<div class="lae-module-entry-text">
<?php echo $source->get_title(); ?>
<?php echo $source->get_product_rating(); ?>
<?php echo $source->get_product_full_price(); ?>
<?php echo $source->get_product_cart_button(); ?>
<?php $shortcode = '[yith_ywraq_button_quote product="' . $source->post_ID . '"]'; ?>
<?php echo do_shortcode($shortcode); ?>
</div>
</article><!-- .hentry -->
<?php $output = ob_get_clean();
return $output;
}
add_filter('lae_block_module_25', 'my_theme_woocommerce_grid_add_to_quote_button', 10, 2);
add_filter('lae_gallery_block_filter_terms', 'mytheme_modify_gallery_block_filter_terms', 10, 2);
function mytheme_modify_gallery_block_filter_terms($block_filter_terms, $block) {
$tags = $terms = array();
$tags = array('adventure', 'coffee', 'cooking', 'cottage', 'gallery'); // LIST YOUR TAGS HERE OR OMIT SOME UNIMPORTANT ONES FROM THE FILTER
if ($block->settings['filterable']) {
foreach ($tags as $tag) {
$term = array();
$term['term_id'] = preg_replace('/\s+/', '-', $tag); // use the unique tag name itself as an id
$term['name'] = $tag;
$term['taxonomy'] = 'gallery_tag';
$terms[] = (object)$term;
}
}
return $terms;
}
function mytheme_modify_module_9($output, $source) {
ob_start();
?>
<article
class="lae-module-9 lae-module-trans1 lae-module <?php echo join(' ', get_post_class('', $source->post_ID)); ?>">
<div class="lae-module-image">
<?php echo $source->get_media(); ?>
<?php echo $source->get_lightbox(); ?>
</div>
<div class="lae-entry-details">
<?php echo $source->get_title();?>
<div class="lae-excerpt">
<?php echo $source->get_excerpt();?>
</div>
</div>
</article>
<?php $output = ob_get_clean();
return $output;
}
add_filter('lae_block_module_9', 'mytheme_modify_module_9', 10, 2);
/* Remove fancybox scripts and stylesheet */
add_action('elementor/frontend/after_enqueue_scripts', function() {
wp_dequeue_script( 'jquery-fancybox' );
});
add_action('elementor/frontend/after_enqueue_styles', function() {
wp_dequeue_style( 'fancybox' );
});
function mytheme_modify_posts_carousel_entry_title($title, $post_id, $settings) {
$entry_title = '<' . $settings['entry_title_tag']
. ' class="entry-title"><a href="' . get_permalink($post_id)
. '" title="' . get_the_title($post_id)
. '" rel="bookmark" target="_blank">' . get_the_title($post_id)
. '</a></' . $settings['entry_title_tag'] . '>';
return $title;
}
add_filter('lae_posts_carousel_entry_title', 'mytheme_modify_posts_carousel_entry_title', 10, 3);
add_filter('lae_posts_grid_entry_excerpt', 'mytheme_shortcode_excerpt', 10, 2);
function mytheme_shortcode_excerpt($excerpt, $post_id) {
$output = '<div class="entry-summary">';
$excerpt_count = 120;
$post = get_post($post_id);
if (empty($post->post_excerpt))
$excerpt = $post->post_content;
else
$excerpt = $post->post_excerpt;
$output .= do_shortcode(force_balance_tags(html_entity_decode(wp_trim_words(htmlentities($excerpt), $excerpt_count, '…'))));
$output .= '</div>';
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment