* add_action( 'after_setup_theme', 'my_child_theme_setup' );
* function my_child_theme_setup() {
*
* remove_filter('filter_hook', 'callback_function' );
* ...
* }
*
*
* For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
*
* @package WordPress
* @subpackage Antiaris
* @since antiaris 1.0
*/
/**
* Retrieve the theme's user settings and default settings. Individual files can access
* these setting via a global variable call, so database query is only
* done once.
*
*/
include('admin/options-defaults.php');
$antiaris_settings = get_option('antiaris_settings');
/**
* If there is no theme settings in the database yet (e.g. first install), add the database entry.
*/
if (!function_exists('antiaris_db_init')) :
function antiaris_db_init(){
global $antiaris_settings, $antiaris_defaults;
if (!$antiaris_settings || (count($antiaris_settings) != count($antiaris_defaults))) {
$initial_settings = array();
// Add all the deafult settings if no setting in the database yet
if (!$antiaris_settings){
$initial_settings = $antiaris_defaults;
update_option('antiaris_settings', $initial_settings);
} else {
// Construct the updated settings
foreach ($antiaris_defaults as $option => $value) :
$initial_settings[$option] = (array_key_exists($option, $antiaris_settings)) ? $antiaris_settings[$option] : $value;
endforeach;
// Add the initial settings to the database
update_option('antiaris_settings', $initial_settings);
}
// Update the global $antiaris_settings;
$antiaris_settings = $initial_settings;
}
}
endif;
add_action('init', 'antiaris_db_init');
/*
echo '
';
*/
/**
* Set the content width based on the theme's design and stylesheet.
*
* Used to set the width of images and content. Should be equal to the width the theme
* is designed for, generally via the style.css stylesheet.
*/
if (!isset($content_width)){
if ((!is_active_sidebar('left-widget-area') || $antiaris_settings['disable_left_sidebar']) && $antiaris_settings['disable_right_sidebar'])
// one-column layout
$content_width = apply_filters('antiaris_one_column_content_width', 920);
elseif ((is_active_sidebar('left-widget-area') && !$antiaris_settings['disable_left_sidebar']) && !$antiaris_settings['disable_right_sidebar'])
// three-column layout
$content_width = apply_filters('antiaris_three_column_content_width', 480);
else
// two-column layout
$content_width = apply_filters('antiaris_two_column_content_width', 600);
}
/** Tell WordPress to run antiaris_setup() when the 'after_setup_theme' hook is run. */
add_action('after_setup_theme', 'antiaris_setup');
if (!function_exists( 'antiaris_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 post thumbnails.
*
* To override antiaris_setup() in a child theme, add your own antiaris_setup to your child theme's
* functions.php file.
*
* @uses add_theme_support() To add support for post thumbnails and automatic feed links.
* @uses register_nav_menus() To add support for navigation menus.
* @uses add_custom_background() To add support for a custom background.
* @uses load_theme_textdomain() For translation/localization support.
* @uses add_custom_image_header() To add support for a custom header.
* @uses register_default_headers() To register the default custom header images provided with the theme.
* @uses set_post_thumbnail_size() To set a custom post thumbnail size.
*
* @since antiaris 1.0
*/
function antiaris_setup() {
global $antiaris_settings, $antiaris_defaults;
// Define the theme's database version
define('ANTIARIS_DBVERSION', 1.0);
// Add the theme's dbversion in the database if none exist
if (!get_option('antiaris_dbversion')) {update_option('antiaris_dbversion', ANTIARIS_DBVERSION);}
// Add support for editor syling
add_editor_style();
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
// This theme uses post thumbnails
add_theme_support( 'post-thumbnails' );
// Make theme available for translation
// Translations can be filed in the /languages/ directory
load_theme_textdomain('antiaris', get_template_directory().'/languages');
// Add new image sizes to be used with the theme
add_image_size('antiaris-archive-thumb', 150, 100, true);
$height = ($antiaris_settings['slider_height']) ? $antiaris_settings['slider_height'] : $antiaris_defaults['slider_height'];
add_image_size('antiaris-medium-slider', apply_filters('antiaris_medium_slider_image_width', 555), $height, true);
add_image_size('antiaris-full-slider', apply_filters('antiaris_full_slider_image_width', 960), $height, true);
add_image_size('antiaris-homepage-pane', apply_filters('antiaris_homepage_pane_image_width', 290), apply_filters('antiaris_homepage_pane_image_height', 170), true);
//Register the custom menus
register_nav_menus( array(
'header-menu' => __('Header Menu', 'antiaris'),
'secondary-menu' => __('Secondary Menu', 'antiaris'),
'footer-menu' => __('Footer Menu', 'antiaris'),
) );
// This theme allows users to set a custom background
add_custom_background();
/* Set the constants required for the custom header function */
define('NO_HEADER_TEXT', apply_filters('antiaris_header_text', false));
define('HEADER_TEXTCOLOR', apply_filters('antiaris_header_textcolor', 'CADBF4'));
define('HEADER_IMAGE', apply_filters('antiaris_header_image', '%s/images/header-default.png')); // %s is the template dir uri
define('HEADER_IMAGE_WIDTH', apply_filters('antiaris_header_image_width', 960)); // use width and height appropriate for your theme
define('HEADER_IMAGE_HEIGHT', apply_filters('antiaris_header_image_height', 150));
// Add a way for the custom header to be styled in the admin panel that controls
// custom headers. See antiaris_admin_header_style(), below.
add_custom_image_header('', 'antiaris_admin_header_style');
// Register the default header
register_default_headers(array(
'Default Header' => array(
'url' => '%s/images/header-default.png',
'thumbnail_url' => '%s/images/header-default-thumb.png',
'description' => __('The default header image for the theme', 'antiaris')
),
));
do_action('antiaris_setup');
}
endif;
/**
* Register and print the main theme stylesheet
*/
function antiaris_main_stylesheet(){
wp_register_style('antiaris-stylesheet', get_stylesheet_uri(), array(), false, 'screen');
wp_register_style('googlefont-cuprum', 'http://fonts.googleapis.com/css?family=Cuprum', array(), false, 'all');
wp_enqueue_style('googlefont-cuprum');
wp_enqueue_style('antiaris-stylesheet');
}
add_action('wp_print_styles', 'antiaris_main_stylesheet');
/**
* Enqueue style for the theme's options page
*/
if (!function_exists('antiaris_admin_options_style')) :
function antiaris_admin_options_style() {
wp_enqueue_style('antiaris-admin-style');
if (is_rtl()) {wp_enqueue_style('antiaris-admin-style-rtl');}
}
endif;
/**
* Adds the theme options page
*/
function antiaris_options_init() {
$antiaris_options = add_theme_page(__('Antiaris Options', 'antiaris'), __('Antiaris Options', 'antiaris'), 'edit_theme_options', 'antiaris_options', 'antiaris_options');
// Register the style for the theme's options page
wp_register_style('antiaris-admin-style', get_template_directory_uri().'/admin/admin.css');
if (is_rtl()) {wp_register_style('antiaris-admin-style-rtl', get_template_directory_uri().'/admin/admin-rtl.css');}
// Print the style for the theme's options page
add_action('admin_print_styles-'.$antiaris_options, 'antiaris_admin_options_style');
// Action hook for additional customisations
do_action('antiaris_options_init');
}
add_action('admin_menu', 'antiaris_options_init');
// Include the file that handles the options page
include('admin/options.php');
if (!function_exists('antiaris_admin_header_style')) :
/**
* Styles the header image displayed on the Appearance > Header admin panel.
* Referenced via add_custom_image_header() in antiaris_setup().
*
* @since antiaris 1.0
*/
function antiaris_admin_header_style(){ ?>
$name,
'id' => 'left-widget-area',
'description' => __( 'The left sidebar widget area.', 'antiaris' ),
'before_widget' => '
',
'after_widget' => '
',
'before_title' => "
",
'after_title' => "
",
));
if ($antiaris_settings['enable_alternate_left_sidebar']) :
register_sidebar(array(
'name' => __('Left Sidebar (front page)', 'antiaris'),
'id' => 'left-frontpage-widget-area',
'description' => __( 'The left sidebar widget area that will only be displayed on the front page.', 'antiaris' ),
'before_widget' => '
",
));
if ($antiaris_settings['enable_alternate_right_sidebar']) :
register_sidebar(array(
'name' => __('Right Sidebar (front page)', 'antiaris'),
'id' => 'right-frontpage-widget-area',
'description' => __( 'The right sidebar widget area that will only be displayed on the front page.', 'antiaris' ),
'before_widget' => '
",
));
if ($antiaris_settings['enable_alternate_footer_widget']) :
register_sidebar(array(
'name' => $name.' '.__('(front page)', 'antiaris'),
'id' => 'footer-frontpage-widget-area-'.$i,
'description' => sprintf(__("The footer widget area that will only be displayed on the front page (column %d).", 'antiaris'), $i),
'before_widget' => '
",
));
endif;
/**
* Register alternate widget areas to be displayed on the front page, if enabled
*
* @package WordPress
* @subpackage antiaris
* @since antiaris 1.0
*/
/*
if (get_option('antiaris_alt_home_sidebar')) {
register_sidebar(array(
'name' => __('Sidebar Widget Area (Front Page)', 'antiaris'),
'id' => 'sidebar-widget-area-home',
'description' => __( 'The right sidebar widget area that will only be displayed on the front page.', 'antiaris' ),
'before_widget' => '
',
'after_widget' => '
',
'before_title' => "
",
'after_title' => "
",
));
}
if (get_option('antiaris_alt_home_footerwidget')) {
register_sidebar(array(
'name' => __('Front Page Footer Widget Area', 'antiaris'),
'id' => 'home-footer-widget-area',
'description' => __( "The footer widget area that will only be displayed on the front page. Leave empty to disable. Set the number of columns to display at the theme's Display Options page.", 'antiaris' ),
'before_widget' => '
',
'after_widget' => '
',
'before_title' => "
",
'after_title' => "
",
));
}
*/
}
do_action('antiaris_widgets_init');
}
/** Register sidebars by running antiaris_widgets_init() on the widgets_init hook. */
add_action('widgets_init', 'antiaris_widgets_init');
/**
* This functions adds additional classes to the element. The additional classes
* are added by filtering the Wordpress body_class() function.
*/
function antiaris_body_class($classes){
global $antiaris_settings;
// Check if both left and right sidebar is active (3 columns)
if ((is_active_sidebar('left-widget-area') && !$antiaris_settings['disable_left_sidebar']) && !$antiaris_settings['disable_right_sidebar']) {
$classes[] = 'three-column';
}
// Check if both sidebar is not active (one column)
elseif ((!is_active_sidebar('left-widget-area') || $antiaris_settings['disable_left_sidebar']) && $antiaris_settings['disable_right_sidebar']) {
$classes[] = 'one-column';
}
// Two-column layout. Also checks which sidebar is active
else {
if ($antiaris_settings['disable_left_sidebar'] || (!$antiaris_settings['disable_left_sidebar'] && !is_active_sidebar('left-widget-area'))){
$classes[] = 'sidebar-right';
}
if ($antiaris_settings['disable_right_sidebar']){
$classes[] = 'sidebar-left';
}
}
// Check if a static front page is being used
if (get_option('show_on_front') == 'page' && is_front_page()){
$classes[] = 'static-front-page';
}
// Prints the body class
return $classes;
}
add_filter('body_class', 'antiaris_body_class');
/**
* Register and enqueue the TinyDropdown menu script
*/
function antiaris_tinydropdown_js(){
wp_enqueue_script('tiny-dropdown', get_template_directory_uri().'/js/tinydropdown.js', array(), '', true);
}
add_action('template_redirect', 'antiaris_tinydropdown_js');
/**
* Add the TinyDropdown initialisation script
*/
function antiaris_tinydropdown_script(){ ?>
';
endforeach;
return $output;
}
/**
* Displays the Site Summary panel
*/
if (!function_exists('antiaris_site_summary')) :
function antiaris_site_summary(){ global $antiaris_settings, $antiaris_defaults; ?>
get_var('
SELECT
COUNT(comment_ID)
FROM
'.$wpdb->comments.'
WHERE
'.$typeSql.' AND
comment_approved="1" AND
comment_post_ID= '.get_the_ID()
);
if($result == 0):
return str_replace('%', $result, $noneText);
elseif($result == 1):
return str_replace('%', $result, $oneText);
elseif($result > 1):
return str_replace('%', $result, $moreText);
endif;
}
/**
* Enqueue the jQuery Tools Tabs JS and the necessary script for comments/pings tabs
*/
function antiaris_tabs_comments_js(){ ?>
'',
'email' => '',
'url' => '',
);
do_action('antiaris_comment_form_fields');
return $fields;
}
// The comment field textarea
function antiaris_comment_textarea(){
echo '';
do_action('antiaris_comment_textarea');
}
// Add all the filters we defined
add_filter('comment_form_default_fields', 'antiaris_comment_form_fields');
add_filter('comment_form_field_comment', 'antiaris_comment_textarea');
/**
* This function gets the URL of post thumbnail.
* Returns an array containing: [0] => Image URL, [1] => Image width, [2] => Image height
*/
function antiaris_get_post_thumbnail_uri($post_id = NULL, $size = 'thumbnail'){
if ($post_id == NULL){
_e('ERROR: antiaris_get_post_thumbnail_uri() function requires the post ID to be passed as an argument.');
return;
}
$src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $size);
return $src;
}
/**
* This function gets the first image (as ordered in the post's media gallery) attached to
* the current post. It outputs the complete tag, with height and width attributes.
* The function returns the thumbnail of the original image, linked to the post's
* permalink. Returns FALSE if the current post has no image.
*
* This function requires the post ID to get the image from to be supplied as the
* argument. If no post ID is supplied, it outputs an error message. An optional argument
* size can be used to determine the size of the image to be used.
*
* Based on code snippets by John Crenshaw
* (http://www.rlmseo.com/blog/get-images-attached-to-post/)
*
* @package WordPress
* @subpackage Antiaris
* @since Antiaris 1.0
*/
if (!function_exists('antiaris_get_post_image')) :
function antiaris_get_post_image($post_id = NULL, $size = 'thumbnail', $url_only = false){
/* Display error message if no post ID is supplied */
if ($post_id == NULL){
_e('ERROR: You must supply the post ID to get the image from as an argument when calling the antiaris_get_post_image() function.', 'antiaris');
return;
}
/* Get the images */
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_parent' => $post_id,
'orderby' => 'menu_order',
'order' => 'ASC',
'numberposts' => 1,
);
$images = get_children(apply_filters('antiaris_get_post_image_args', $args), ARRAY_A);
/* Returns FALSE if there is no image */
if (empty($images)) {
return FALSE;
}
/* Build the tag if there is an image */
$out = '';
if (!$url_only) {
foreach ($images as $image){
$out .= '';
$out .= wp_get_attachment_image($image['ID'], $size);
$out .= '';
}
} else {
foreach ($images as $image){
$out = wp_get_attachment_image_src($image['ID'], $size);
}
}
/* Returns the image HTMl */
return $out;
}
endif;
/**
* Add the post thumbnail or the thumbnail of the first image in post for
* archive pages.
*/
if (!function_exists('antiaris_archive_post_image')) :
function antiaris_archive_post_image($post_id){
$html = '';
$size = apply_filters('antiaris_archive_thumb_size', 'antiaris-archive-thumb');
// Return the post thumbnail if exists
if (has_post_thumbnail($post_id)){
$html .= '
';
}
return $html;
}
endif;
/**
* Prints the social sharing code if enabled
*/
function antiaris_print_social_sharing(){
global $antiaris_settings;
if (!is_page() || $antiaris_settings['enable_social_sharing_inpage']) {
echo $antiaris_settings['social_sharing_code'];
}
}
if ($antiaris_settings['enable_social_sharing'])
add_action('antiaris_social_sharing', 'antiaris_print_social_sharing');
/**
* Prints the Google Analytics code if enabled
*/
function antiaris_print_analytics(){
global $antiaris_settings;
echo $antiaris_settings['analytics_code'];
}
if ($antiaris_settings['enable_analytics'])
add_action('wp_head', 'antiaris_print_analytics', 100);
/**
* Output the Google Adsense code if enabled
*/
$adsense_count = 0;
function antiaris_print_adsense(){
global $antiaris_settings, $adsense_count;
$adsense_count++;
?>
ID, '_menu_item_object_id', true);
//get first menu item that is a child of that object
$children = $wpdb->get_var('SELECT post_id FROM '.$wpdb->postmeta.' WHERE meta_key like "_menu_item_menu_item_parent" AND meta_value='.$item->ID.' LIMIT 1');
//if there is at least one item, then $children variable will contain it's ID (which is of course more than 0)
if($children > 0)
//in that case - add the CSS class
$classlist[] = 'menu-item-ancestor';
//return class list
return $classlist;
}
//add filter to nav_menu_css_class list
add_filter('nav_menu_css_class', 'antiaris_add_ancestor_class', 2, 10);
/**
* Add the .htc file for partial CSS3 support in Internet Explorer
*/
function antiaris_ie_css3(){ ?>
'date',
'order' => 'DESC',
'suppress_filters' => 0,
'post_type' => array('post', 'page'),
);
// args specific to latest posts
if ($antiaris_settings['show_post_type'] == 'latest-posts' ){
$args_merge = array(
'numberposts' => $pane_count,
);
$args = array_merge($args, $args_merge);
}
// args specific to latest posts by category
if ($antiaris_settings['show_post_type'] == 'cat-latest-posts' ){
$args_merge = array(
'numberposts' => $pane_count,
'category' => $antiaris_settings['homepage_panes_cat'],
);
$args = array_merge($args, $args_merge);
}
// args specific to posts/pages
if ($antiaris_settings['show_post_type'] == 'posts' ){
$args_merge = array(
'numberposts' => $pane_count,
'include' => $antiaris_settings['homepage_panes_posts'],
);
$args = array_merge($args, $args_merge);
}
global $post;
// Get the posts to display as homepage panes
$posts = get_posts(apply_filters('antiaris_homepage_panes_args', $args));
?>
element,
* if a favicon URL is present in the options.
*/
function antiaris_favicon(){
global $antiaris_settings;
if ($antiaris_settings['favicon_url']) { ?>
: