HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
File: /datos/www/www.colombia.co/public_html/wp-content/themes/colombia2016-old/functions.php
<?php
/**
 * Register latest jQuery, load on footer
 */
function minimal_jquery_script() {
	if ( ! is_admin() ) {
		wp_deregister_script('jquery');
		wp_register_script('jquery', '//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js', false, '2.2.3', true);
	}
}
add_action('wp_enqueue_scripts', 'minimal_jquery_script');

function dequeue_css_from_plugins()  {
	wp_dequeue_style('wpdm-front'); 
}
add_action('wp_print_styles', 'dequeue_css_from_plugins', 100);

/**
 * Theme setup
 */
function minimal_theme_setup() {
	// Adds RSS feed links to <head> for posts and comments.
	add_theme_support('automatic-feed-links');

	// Custom menu support.
	register_nav_menu('primary', 'Primary Menu');
	register_nav_menu('secondary', 'Secondary Menu');
	register_nav_menu('lang', 'Language Selector');
	register_nav_menu('social', 'Social Networks');
	register_nav_menu('footer', 'Footer Menu');

	// Most themes need featured images.
	add_theme_support('post-thumbnails' );

	add_theme_support('post-formats', array('image','audio','video'));

	// Localization support
	load_theme_textdomain('colombia', get_template_directory() . '/lang');
}
add_action('after_setup_theme', 'minimal_theme_setup');

/**
 * Remove code from the <head>
 */
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);// http://www.tech-evangelist.com/2011/09/05/disable-remove-wordpress-shortlink/
//remove_action('wp_head', 'rsd_link'); // Might be necessary if you or other people on this site use remote editors.
//remove_action('wp_head', 'feed_links', 2); // Display the links to the general feeds: Post and Comment Feed
//remove_action('wp_head', 'feed_links_extra', 3); // Display the links to the extra feeds such as category feeds
//remove_action('wp_head', 'index_rel_link'); // Displays relations link for site index
remove_action('wp_head', 'wlwmanifest_link'); // Might be necessary if you or other people on this site use Windows Live Writer.
//remove_action('wp_head', 'start_post_rel_link', 10, 0); // Start link
//remove_action('wp_head', 'parent_post_rel_link', 10, 0); // Prev link
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); // Display relational links for the posts adjacent to the current post.

// http://justintadlock.com/archives/2010/07/08/lowercase-p-dangit
remove_filter( 'the_title', 'capital_P_dangit', 11 );
remove_filter( 'the_content', 'capital_P_dangit', 11 );
remove_filter( 'comment_text', 'capital_P_dangit', 31 );

// Hide the version of WordPress you're running from source and RSS feed // Want to JUST remove it from the source? Try: remove_action('wp_head', 'wp_generator');
add_filter('the_generator', '__return_false');

//add_filter('show_admin_bar', '__return_false');

function custom_excerpt_length( $length ) {
	return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

function htpify( $link ){
	if (preg_match("#https?://#", $link) === 0) {
		$link = 'http://'.$link;
	}
	return $link;
}

function padre_class($classes){
	global $post;
	$cat=get_the_category(get_query_var('post'));
	if(is_array($cat)&&!empty($cat)){
		if($cat[0]->category_parent!=0){
			$parents=get_category_parents($cat[0]->term_id,false,'@',true);
			if(!empty($parents)){
				$parent=explode('@',$parents);
				$classes[]='category-'.$parent[0];
			}
		}
	}
	return $classes;
}
//add_filter('post_class','padre_class');

// Funcion para traer al padre de primer nivel
function get_top_parent($cat){
	$curr_cat = get_category_parents($cat, false, '/' ,true);
	$curr_cat = explode('/',$curr_cat);
	$idObj = get_category_by_slug($curr_cat[0]);
	return  $curr_cat[0];
}

// Funcion para incluir clase de categoria superior en paginas de archivo
function cat_rats_class($classes){
	global $wp_query;
	$cat=$wp_query->get_queried_object();
		
	if( $cat ){
		if($cat->category_parent!=0){
			$parents=get_category_parents($cat->term_id,false,'@',true);
			if(!empty($parents)){
				$parent=explode('@',$parents);
				$classes[]='category-'.$parent[0];
			}
		}
	}

	return $classes;

}
add_filter('body_class','cat_rats_class');

/**
 * retornar todos los posts del post type "lugares unicos"
 */
function get_all_sites_map() {
    // $obj_seg = new security();
    // $categories = $obj_seg->clear_all($_POST['categories']);


    $args = array(
        'post_type' => 'tp_lugares_unicos',
        'post_status' => 'publish',
        'posts_per_page' => -1
    );
    $obj_result = array();
    query_posts($args);
    if (have_posts()):
        while (have_posts()) : the_post();
            $coordinates = get_field('coordinates_pt_lugares_unicos');
            $coordinates = explode(',', $coordinates );
			$longitude = $coordinates[1];
			$latitude = $coordinates[0];

            $obj_result[] = array(
                'location' => array(
                		'lat' => $latitude,
                		'lon' => $longitude,
                		'zoom' => 10,
                		'line' => true
                	),
                'text' => array(
                		'headline' => get_the_title(),
                		'text' => get_the_content()
                	)
            );
        endwhile;
    endif;
    $storymap = array( 
    				"storymap" => array( 
    						"slides" => $obj_result 
    					) 
    				);
    die(json_encode($storymap));
}

add_filter('wp_ajax_get_all_sites_map', 'get_all_sites_map');
add_action('wp_ajax_nopriv_get_all_sites_map', 'get_all_sites_map');

function get_filtered_calendar_events(){
	global $wpdb;

	$desde = $_POST['desde'];
	$hasta = $_POST['hasta'];

	// args
	$args = array(
		'numberposts'	=> -1,
		'post_type'		=> 'tp_eventos',
		'meta_query'	=> array(
			'relation'		=> 'AND',
			array(
				'key'		=> 'date_start_pt_eventos',
				'compare'	=> '>=',
				'value'		=> $desde
			),
			array(
				'key'		=> 'date_end_pt_eventos',
				'compare'	=> '<=',
				'value'		=> $hasta
			)
		)
	);


	// query
	$results = array();

	$posts = get_posts( $args );
	global $post;

	foreach ($posts as $post) {
		setup_postdata( $post );
		$id = get_the_id();
		$title = get_the_title();
		$start_date = get_field('date_start_pt_eventos');
		$end_date = get_field('date_end_pt_eventos');
		$location = get_field('place_pt_eventos');
		$content = get_the_content();
		$ext_link = get_field('link_pt_eventos');
		$link = htpify($ext_link);
		$image = get_field('image_pt_eventos');
		$results[] = array(
			'ID' => $id,
			'title' => $title,
			'fecha_inicio' => $start_date,
			'fecha_fin' => $end_date,
			'location' => $location,
			'content' => $content,
			'link' => $link,
			'image' => $image['sizes']['medium'],
            'img_alt' => $image['alt'],
            'img_title' => $image['title']
		);
	}
	
	if( empty( $results ) ){
		$results[] = array(
				'ID' => 0,
				'title' => __('Aún no hay eventos para este mes','colombia'),
				'fecha_inicio' => '-',
				'fecha_fin' => '-',
				'location' => '-',
				'content' => '',
				'link' => '',
				'image' => 'http://placehold.it/1x1'
			);
	}

	die( json_encode( $results ) );
}

add_filter('wp_ajax_get_filtered_calendar_events', 'get_filtered_calendar_events');
add_action('wp_ajax_nopriv_get_filtered_calendar_events', 'get_filtered_calendar_events');

function searchfilter($query) {

    if ($query->is_search && !is_admin() ) {
        $query->set('post_type',array('post'));
    }

	return $query;
}

add_filter('pre_get_posts','searchfilter');

/* Redirect if there is only one product in the category */
add_action( 'template_redirect', 'correct_category_link', 10 );
function correct_category_link ($wp_query) {
	global $wp_query;
	if (is_category()) {
		$current_url = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
		$cat = get_cat_ID(single_cat_title('', false));
		$cat_id = get_cat_ID(single_cat_title('', false));
		$real_id = get_cat_ID($cat_id);

		$category_link = get_term_link( $cat_id, 'category' );

		if( ( $current_url != $category_link ) && !is_paged() ){
			wp_redirect( esc_url( $category_link ), 301 );
			exit();
			// echo $current_url . " vs. " . $category_link;
		}
	}
}

// change page link to display published pages only
function wcs_change_admin_page_link() {
    global $submenu;
    $submenu['edit.php?post_type=page'][5][2] = 'edit.php?post_type=page&post_status=publish';
}
add_action( 'admin_menu', 'wcs_change_admin_page_link' );

// change post link to display published posts only
function wcs_change_admin_post_link() {
    global $submenu;
    $submenu['edit.php'][5][2] = 'edit.php?post_status=publish';
}
add_action( 'admin_menu', 'wcs_change_admin_post_link' );

//Add excerpt support to pages
/*add_action( 'init', 'my_add_excerpts_to_pages' );
function my_add_excerpts_to_pages(){
    add_post_type_support( 'page', 'excerpt' );
}*/

/**
 * Removes the regular excerpt box. We're not getting rid
 * of it, we're just moving it above the wysiwyg editor
 *
 * @return null
 */
function oz_remove_normal_excerpt() {
    remove_meta_box( 'postexcerpt' , 'post' , 'normal' );
}
add_action( 'admin_menu' , 'oz_remove_normal_excerpt' );
 
/**
 * Add the excerpt meta box back in with a custom screen location
 *
 * @param  string $post_type
 * @return null
 */
function oz_add_excerpt_meta_box( $post_type ) {
    if ( in_array( $post_type, array( 'post', 'page' ) ) ) {
        add_meta_box(
            'oz_postexcerpt',
            __( 'Extracto', 'colombia' ),
            'post_excerpt_meta_box',
            $post_type,
            'after_title',
            'high'
        );
    }
}
add_action( 'add_meta_boxes', 'oz_add_excerpt_meta_box' );
 
/**
 * You can't actually add meta boxes after the title by default in WP so
 * we're being cheeky. We've registered our own meta box position
 * `after_title` onto which we've regiestered our new meta boxes and
 * are now calling them in the `edit_form_after_title` hook which is run
 * after the post tile box is displayed.
 *
 * @return null
 */
function oz_run_after_title_meta_boxes() {
    global $post, $wp_meta_boxes;
    # Output the `below_title` meta boxes:
    do_meta_boxes( get_current_screen(), 'after_title', $post );
}
add_action( 'edit_form_after_title', 'oz_run_after_title_meta_boxes' );

// allow script & iframe tag within posts
function allow_post_tags( $allowedposttags ){
    $allowedposttags['script'] = array(
        'type' => true,
        'src' => true,
        'height' => true,
        'width' => true,
    );
    $allowedposttags['iframe'] = array(
        'src' => true,
        'width' => true,
        'height' => true,
        'class' => true,
        'frameborder' => true,
        'webkitAllowFullScreen' => true,
        'mozallowfullscreen' => true,
        'allowFullScreen' => true
    );
    return $allowedposttags;
}
add_filter('wp_kses_allowed_html','allow_post_tags', 1);