Last active
August 14, 2019 04:24
-
-
Save tranchausky/72d0dc31cdf954d9fa531bef147e2c13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Theme basic setup. | |
* | |
* @package understrap | |
*/ | |
// Exit if accessed directly. | |
defined( 'ABSPATH' ) || exit; | |
// Set the content width based on the theme's design and stylesheet. | |
if ( ! isset( $content_width ) ) { | |
$content_width = 640; /* pixels */ | |
} | |
add_action( 'after_setup_theme', 'understrap_setup' ); | |
if ( ! function_exists ( 'understrap_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 understrap_setup() { | |
/* | |
* Make theme available for translation. | |
* Translations can be filed in the /languages/ directory. | |
* If you're building a theme based on understrap, use a find and replace | |
* to change 'understrap' to the name of your theme in all the template files | |
*/ | |
load_theme_textdomain( 'understrap', 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' ); | |
// This theme uses wp_nav_menu() in one location. | |
register_nav_menus( array( | |
'primary' => __( 'Primary Menu', 'understrap' ), | |
) ); | |
/* | |
* 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', | |
) ); | |
/* | |
* Adding Thumbnail basic support | |
*/ | |
add_theme_support( 'post-thumbnails' ); | |
/* | |
* Adding support for Widget edit icons in customizer | |
*/ | |
add_theme_support( 'customize-selective-refresh-widgets' ); | |
/* | |
* Enable support for Post Formats. | |
* See http://codex.wordpress.org/Post_Formats | |
*/ | |
add_theme_support( 'post-formats', array( | |
'aside', | |
'image', | |
'video', | |
'quote', | |
'link', | |
) ); | |
// Set up the WordPress core custom background feature. | |
add_theme_support( 'custom-background', apply_filters( 'understrap_custom_background_args', array( | |
'default-color' => 'ffffff', | |
'default-image' => '', | |
) ) ); | |
// Set up the WordPress Theme logo feature. | |
//add_theme_support( 'custom-logo' ); | |
add_theme_support( 'custom-logo', array( | |
'height' => 150, | |
'width' => 40, | |
'flex-height' => true, | |
'flex-width' => true, | |
'header-text' => array( 'site-title', 'site-description' ), | |
) ); | |
// Add support for responsive embedded content. | |
add_theme_support( 'responsive-embeds' ); | |
// Check and setup theme default settings. | |
understrap_setup_theme_default_settings(); | |
} | |
} | |
add_filter( 'excerpt_more', 'understrap_custom_excerpt_more' ); | |
if ( ! function_exists( 'understrap_custom_excerpt_more' ) ) { | |
/** | |
* Removes the ... from the excerpt read more link | |
* | |
* @param string $more The excerpt. | |
* | |
* @return string | |
*/ | |
function understrap_custom_excerpt_more( $more ) { | |
if ( ! is_admin() ) { | |
$more = ''; | |
} | |
return $more; | |
} | |
} | |
add_filter( 'wp_trim_excerpt', 'understrap_all_excerpts_get_more_link' ); | |
if ( ! function_exists( 'understrap_all_excerpts_get_more_link' ) ) { | |
/** | |
* Adds a custom read more link to all excerpts, manually or automatically generated | |
* | |
* @param string $post_excerpt Posts's excerpt. | |
* | |
* @return string | |
*/ | |
function understrap_all_excerpts_get_more_link( $post_excerpt ) { | |
if ( ! is_admin() ) { | |
$post_excerpt = $post_excerpt . ' [...]<p><a class="btn btn-secondary understrap-read-more-link" href="' . esc_url( get_permalink( get_the_ID() ) ) . '">' . __( 'Read More...', | |
'understrap' ) . '</a></p>'; | |
} | |
return $post_excerpt; | |
} | |
} | |
for( $i = 1; $i <= 4; $i++ ) { | |
register_sidebar( array( | |
'name' => esc_html__( 'Footer Top Column ', 'singularity' ) . $i, | |
'id' => 'footer-' . $i, | |
'description' => esc_html__( 'Add widgets here.', 'singularity' ), | |
'before_widget' => '<section id="%1$s" class="widget %2$s">', | |
'after_widget' => '</section>', | |
'before_title' => '<h5 class="widget-title">', | |
'after_title' => '</h5>', | |
) ); | |
} | |
for( $i = 1; $i <= 3; $i++ ) { | |
register_sidebar( array( | |
'name' => esc_html__( 'Footer Mid Column ', 'singularity' ) . $i, | |
'id' => 'footer2-' . $i, | |
'description' => esc_html__( 'Add widgets here.', 'singularity' ), | |
'before_widget' => '<section id="%1$s" class="widget %2$s">', | |
'after_widget' => '</section>', | |
'before_title' => '<h5 class="widget-title">', | |
'after_title' => '</h5>', | |
) ); | |
} | |
for( $i = 1; $i <= 2; $i++ ) { | |
register_sidebar( array( | |
'name' => esc_html__( 'Footer Bottom Column ', 'singularity' ) . $i, | |
'id' => 'footer3-' . $i, | |
'description' => esc_html__( 'Add widgets here.', 'singularity' ), | |
'before_widget' => '<section id="%1$s" class="widget %2$s">', | |
'after_widget' => '</section>', | |
'before_title' => '<h5 class="widget-title">', | |
'after_title' => '</h5>', | |
) ); | |
} | |
if ( ! function_exists( 'singularity_categories' ) ) : | |
/** | |
* Prints HTML with meta information for the categories, tags and comments. | |
*/ | |
function singularity_categories() { | |
// Hide category and tag text for pages. | |
if ( 'post' === get_post_type() ) { | |
/* translators: used between list items, there is a space after the comma */ | |
$categories_list = get_the_category_list( esc_html__( ' ', 'singularity' ) ); | |
$categories =get_the_category(); | |
$catid = $categories[0]->term_id; | |
$get_category_name = get_cat_name($catid); | |
if ($get_category_name ) { | |
//printf( '<p class="cat-links">' . $categories_list . '</p>' ); // WPCS: XSS OK. | |
switch ($get_category_name) { | |
case 'Définitions': | |
# code... | |
$class_name_show = ' def '; | |
break; | |
case 'Avantage': | |
# code... | |
$class_name_show = ' avantage '; | |
break; | |
case 'Info utile': | |
$class_name_show = ' fact '; | |
# code... | |
break; | |
default: | |
# code... | |
break; | |
} | |
// printf( '<p class="cat-links '.$class_name_show.'">' . $categories_list . '</p>' ); // WPCS: XSS OK. | |
// $category_link = get_category_link( the_category_ID() ); | |
//btn-bulle avantage active | |
printf( '<div class="bulle'.$class_name_show.'type" select-thy="'.$class_name_show.'" select-state="on">'.$get_category_name.'</div>' ); // WPCS: XSS OK. | |
} | |
} | |
} | |
endif; | |
/** | |
* Returns true if a blog has more than 1 category. | |
* | |
* @return bool | |
*/ | |
function singularity_categorized_blog() { | |
if ( false === ( $all_the_cool_cats = get_transient( 'singularity_categories' ) ) ) { | |
// Create an array of all the categories that are attached to posts. | |
$all_the_cool_cats = get_categories( array( | |
'fields' => 'ids', | |
'hide_empty' => 1, | |
// We only need to know if there is more than one category. | |
'number' => 2, | |
) ); | |
// Count the number of categories that are attached to the posts. | |
$all_the_cool_cats = count( $all_the_cool_cats ); | |
set_transient( 'singularity_categories', $all_the_cool_cats ); | |
} | |
if ( $all_the_cool_cats > 1 ) { | |
// This blog has more than 1 category so singularity_categorized_blog should return true. | |
return true; | |
} else { | |
// This blog has only 1 category so singularity_categorized_blog should return false. | |
return false; | |
} | |
} | |
add_filter('wp_nav_menu','remove_title'); | |
function remove_title($menu) { | |
return $menu = preg_replace('/ title=\"(.*?)\"/', '', $menu ); | |
} | |
add_action( 'wp_ajax_sendemail', 'sendemail_init' ); | |
add_action( 'wp_ajax_nopriv_sendemail', 'sendemail_init' ); | |
function sendemail_init() { | |
ob_start(); //bắt đầu bộ nhớ đệm | |
$data = $_POST['data']; | |
$result = sendEmail($data); | |
wp_send_json_success($result); // trả vỠgiá trị dạng json | |
die();//bắt buộc phải có khi kết thúc | |
} | |
function sendEmail($data) | |
{ | |
$headers =array('Content-Type: text/html; charset=UTF-8'); | |
$sent = wp_mail( get_bloginfo('admin_email'), '[Portalia] New Contact form submitted from website Homepage', getTemplate($data), $headers); | |
if($sent) | |
{ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} | |
function getTemplate($data) | |
{ | |
$page_id = 4928; //Page ID | |
$page_data = get_page( $page_id ); | |
$content = $page_data->post_content; | |
$content = preg_replace(array('({firstname})','({lastname})','({email})','({message})'), array($data['firstname'],$data['lastname'],$data['email'],$data['message']), $content); | |
return $content; | |
} | |
add_action( 'wp_ajax_sendphone', 'sendphone_init' ); | |
add_action( 'wp_ajax_nopriv_sendphone', 'sendphone_init' ); | |
function sendphone_init() { | |
ob_start(); //bắt đầu bộ nhớ đệm | |
$tel = $_POST['tel']; | |
$result = sendPhone($tel); | |
wp_send_json_success($result); // trả vỠgiá trị dạng json | |
die();//bắt buộc phải có khi kết thúc | |
} | |
function sendPhone($tel) | |
{ | |
$headers =array('Content-Type: text/html; charset=UTF-8'); | |
$sent = wp_mail( get_bloginfo('admin_email'), 'New phone number submitted on Portalia website', getTemplate2($tel), $headers); | |
if($sent) | |
{ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} | |
function getTemplate2($tel) | |
{ | |
$page_id = 4919; //Page ID | |
$page_data = get_page( $page_id ); | |
$content = $page_data->post_content; | |
$content = preg_replace('({phone_number})', $tel, $content); | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment