anorgatarrak-wordpress-theme/functions.php

214 lines
8.7 KiB
PHP
Raw Normal View History

2017-11-09 19:40:49 +01:00
<?php
function anorgatarrak_scripts() {
//CSS
wp_enqueue_style( 'style', get_stylesheet_uri() );
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/node_modules/bootstrap/dist/css/bootstrap.min.css',false,'1.1','all');
wp_enqueue_style( 'anorgatarrak', get_template_directory_uri() . '/css/anorgatarrak.css',false,'1.1','all');
wp_enqueue_style( 'slideshow', get_template_directory_uri() . '/node_modules/simple-slideshow/src/slideshow.css',false,'1.1','all');
wp_enqueue_style( 'google-fonts', 'https://fonts.googleapis.com/css?family=Montserrat|Nothing+You+Could+Do|Roboto',false,'1.1','all');
2018-02-15 19:26:12 +01:00
wp_enqueue_style('angular-loading-bar', get_template_directory_uri() . '/node_modules/angular-loading-bar/src/loading-bar.css');
wp_enqueue_style('mediaelement', get_template_directory_uri() . '/node_modules/mediaelement/build/mediaelementplayer.min.css');
2017-11-09 19:40:49 +01:00
//Scripts
wp_enqueue_script('html5shiv', 'https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js');
wp_enqueue_script('respond', 'https://oss.maxcdn.com/respond/1.4.2/respond.min.js');
2018-02-15 19:26:12 +01:00
wp_enqueue_script('mediaelement', get_template_directory_uri().'/node_modules/mediaelement/build/mediaelement-and-player.min.js');
2017-11-09 19:40:49 +01:00
wp_enqueue_script('slideshow', get_template_directory_uri() .'/node_modules/simple-slideshow/src/slideshow.js');
wp_enqueue_script('jquery', get_template_directory_uri() .'/node_modules/jquery/dist/jquery.min.js');
wp_enqueue_script('bootstrap', get_template_directory_uri() .'/node_modules/bootstrap/dist/js/bootstrap.min.js');
wp_enqueue_script('angularjs', get_template_directory_uri() .'/node_modules/angular/angular.js');
wp_enqueue_script('angularjs-route', get_template_directory_uri() .'/node_modules/angular-route/angular-route.js');
wp_enqueue_script('angularjs-sanitize', get_stylesheet_directory_uri() . '/node_modules/angular-sanitize/angular-sanitize.min.js');
2018-02-15 19:26:12 +01:00
wp_enqueue_script('angular-loading-bar', get_stylesheet_directory_uri() . '/node_modules/angular-loading-bar/src/loading-bar.js');
wp_enqueue_script('angular-gettext', get_template_directory_uri() . '/node_modules/angular-gettext/dist/angular-gettext.min.js');
wp_enqueue_script('angular-translation', get_template_directory_uri() . '/src/js/translations.js');
2017-11-09 19:40:49 +01:00
wp_enqueue_script('anorgatarrak', get_template_directory_uri() .'/app/anorgatarrak.js');
wp_enqueue_script('catalog-module', get_template_directory_uri() .'/app/catalog/catalog.module.js');
wp_enqueue_script('catalog-config', get_template_directory_uri() .'/app/catalog/catalog.config.js');
wp_enqueue_script('catalog-component', get_template_directory_uri() .'/app/catalog/catalog.component.js');
wp_enqueue_script('item-module', get_template_directory_uri() .'/app/catalog/item.module.js');
wp_enqueue_script('item-component', get_template_directory_uri() .'/app/catalog/item.component.js');
//TEMPLATES
wp_localize_script('anorgatarrak', 'localized', array('partials' => get_template_directory_uri() . '/partials/'));
}
function create_posttype() {
//Add Slidehow type
register_post_type('slideshow',
array(
'labels' => array(
'name' => __( 'Slides'),
'singular_name' => __('Slide')
),
'supports' => array( 'title', 'excerpt', 'thumbnail' ),
'show_in_rest' => true,
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'slideshow'),
)
);
//Add Entrevista type
register_post_type('entrevista',
array(
'labels' => array(
'name' => __('Entrevistas'),
'singular_name' => __('Entrevista')
),
'supports' => array('title','thumbnail'),
'show_in_rest' => true,
'public' => true,
'rewrite' => array('slug' => 'catalog'),
2017-11-09 19:40:49 +01:00
)
);
//Add Persona
register_post_type('entidad',
array(
'labels' => array(
'name' => __('Personas'),
'singular_name' => __('Persona')
),
'supports' => array('thumbnail','title'),
'show_in_rest' => true,
'public' => true,
'rewrite' => array('slug'=> 'entidad'),
)
);
//ADD EXCERPT TO PAGES
add_post_type_support( 'page', 'excerpt' );
}
function my_rest_prepare_slideshow($data,$post,$request) {
$_data = $data->data;
$thumbnail_id = get_post_thumbnail_id($post->ID);
#$thumbnail = wp_get_attachment_image_src ($thumbnail_id);
$thumbnail = wp_get_attachment_image_src ($thumbnail_id,'full',false);
2017-11-09 19:40:49 +01:00
$_data['featured_image_thumbnail_url'] = $thumbnail[0];
$_data['excerpt_clean'] = strip_tags(get_the_excerpt($post->ID));
$_data['link_eu'] = str_replace('http://es.','http://',get_permalink(pll_get_post($post->ID,'eu')));
$_data['link_es'] = str_replace('http://','http://es.',get_permalink(pll_get_post($post->ID,'es')));
//$data = array(array('es',get_permalink(pll_get_post($id,'es'))),array('eus',get_permalink(pll_get_post($id,'eu'))));
2017-11-09 19:40:49 +01:00
$data->data = $_data;
return $data;
}
function my_rest_prepare_entrevista($data,$post,$request) {
$_data = $data->data;
//thumbnail
$thumbnail_id = get_post_thumbnail_id($post->ID);
$thumbnail = wp_get_attachment_image_src ($thumbnail_id);
$_data['featured_image_thumbnail_url'] = $thumbnail[0];
//category
$_data['category'] = wp_get_post_terms($post->ID,'termino');
//acf
$_data['e_idioma'] = get_field('idioma',$post->ID);
$_data['e_informantes'] = get_field('informantes',$post->ID);
$_data['e_audiovisual'] = get_field('audiovisual',$post->ID);
$_data['e_transcripcion'] = get_field('transcripcion',$post->ID);
$_data['e_fecha_de_entrevista'] = get_field('fecha_de_entrevista',$post->ID);
$find = array('http://','https://');
$_data['link_eu'] = str_replace('http://es.','http://',get_permalink(pll_get_post($post->ID,'eu')));
$_data['link_es'] = str_replace($find,'http://es.',get_permalink(pll_get_post($post->ID,'es')));
$_data['e_localizacion'] = get_field('lugar',$post->ID);
$data->data = $_data;
return $data;
}
2017-11-09 19:40:49 +01:00
function anorgatarrak_metabox() {
add_meta_box('entrevista-anorgatarrak-metabox',__('Datos entrevista'),'cd_metabox_entrevista', 'entrevista','normal','high');
}
function cd_metabox_entrevista() {
echo '<p>Datos relativos a las entrevistas</p>';
}
function remove_menus(){
remove_menu_page( 'edit-comments.php' ); //Comments
remove_menu_page( 'edit.php' ); //Posts
}
function anorgatarrak_get_lan_id(WP_REST_Request $request) {
$url = $request['url'];
$id = url_to_postid($url);
$data = array(array('es',get_permalink(pll_get_post($id,'es'))),array('eus',get_permalink(pll_get_post($id,'eu'))));
$response = new WP_REST_Response( $data );
// $postid = url_to_postid( $url );
// https://developer.wordpress.org/reference/functions/register_rest_route/
// get_page_by_path()
// return new WP_Error( 'no_author', 'Invalid author', array( 'status' => 404 ) );
return $response;
}
2017-11-09 19:40:49 +01:00
function create_anorgatarrak_tesaurus() {
register_taxonomy(
'termino',
'entrevista',
array(
'label' => __('Terminos'),
'rewrite' => array('slug'=> 'termino'),
'hierarchical' => true,
)
);
register_taxonomy('profesion','entidad', array (
'label' => __('Profesiones'),
'rewrite' => array('slug' => 'profesion'),
));
register_taxonomy('etapas','entrevista',array(
'label' => _('Etapas del proyecto'),
'rewrite' => array('slug' => 'etapas'),
));
2017-11-09 19:40:49 +01:00
}
add_action( 'init', 'create_anorgatarrak_tesaurus' );
add_action( 'admin_menu', 'remove_menus' );
add_filter('rest_prepare_slideshow','my_rest_prepare_slideshow', 12, 3);
add_filter('rest_prepare_entrevista','my_rest_prepare_entrevista', 12, 3);
add_filter('rest_prepare_post','my_rest_prepare_slideshow', 12, 3);
add_filter('rest_prepare_page','my_rest_prepare_slideshow', 12, 3);
2017-11-09 19:40:49 +01:00
add_theme_support( 'post-thumbnails' );
add_action('init','create_posttype');
//add_action('add_meta_boxes','anorgatarrak_metabox');
add_action('wp_enqueue_scripts', 'anorgatarrak_scripts');
add_action( 'widgets_init', 'anorgatarrak_widgets_init' );
function anorgatarrak_widgets_init() {
register_sidebar( array(
'name' => __( 'Main Sidebar', 'anorgatarrak' ),
'id' => 'sidebar-anorgatarrak-1',
'class' => '',
'description' => __( 'Widgets on header', 'anorgatarrak' ),
'before_widget' => '<div class="collapse navbar-collapse" id="an-navbar-collapse">',
'after_widget' => '</div>',
'before_title' => '',
'after_title' => '',
) );
}
function register_anorgatarrak_menu() {
register_nav_menu( 'header-menu-anorgatarrak',__( 'Header Menu Anorgatarrak' ) );
register_nav_menu( 'footer-menu-anorgatarrak',__( 'Footer Menu Anorgatarrak' ) );
}
add_action( 'init', 'register_anorgatarrak_menu' );
function my_acf_google_map_api( $api ){
$api['key'] = 'AIzaSyCASefiswqiqrc74Ebs68_HI6vubGJMR9M';
return $api;
}
add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');
add_action( 'rest_api_init', function () {
register_rest_route( 'anorgatarrak/v1', '/link/(?P<url>[a-zA-Z0-9-]+)', array(
'methods' => 'GET',
'callback' => 'anorgatarrak_get_lan_id',
) );
} );
2017-11-09 19:40:49 +01:00
?>