/**
* framework functions and definitions
* @package WordPress
* @subpackage Framework
* @since Framework 1.0
*/
/*-----------------------------------------------------------------------------------
DEREGISTER, REGISTER, AND ENQUEUE CUSTOM SCRIPTS
-------------------------------------------------------------------------------------*/
function wp_add_scripts() {
/*********************************************************************************
* By default, jQuery is already registered in Wordpress so
* we need to deregister the built in one so that we can
* register our own version of jQuery. After registering it,
* we need to add it to the header by enqueuing it.
**********************************************************************************/
// DEREGISTER BUILT-IN JQUERY
wp_deregister_script('jquery');
// REGISTER CUSTOM JQUERY
wp_register_script('jquery', get_template_directory_uri() . '/js/jquery-1.11.0.min.js' );
// ENQUEUE CUSTOM JQUERY
wp_enqueue_script('jquery');
// *******************************************************************************
// FILES TO ENQUEUE TO THE HEADER
// *******************************************************************************
// ENQUEUE DEFAULT STYLESHEET
wp_enqueue_style('styles', get_template_directory_uri() . '/style.css');
// ENQUEUE MOBILE STYLESHEET
wp_enqueue_style('mobile-styles', get_template_directory_uri() . '/mobile.css');
// ENQUEUE MODERNIZR SCRIPT
wp_enqueue_script('modernizr', get_template_directory_uri() . '/js/modernizr-2.5.3.js');
// ENQUEUE RWD IMAGE MAPS SCRIPT
wp_enqueue_script('rwd-imgage-maps', get_template_directory_uri() . '/js/jquery.rwdImageMaps.min.js');
// ENQUEUE LIGHTBOX STYLESHEET
wp_enqueue_style('lightbox-styles', get_template_directory_uri() . '/lightbox.css');
// ENQUEUE SCRIPTS FOR NESTED COMMENTS
if (is_singular() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
// *******************************************************************************
// FILES TO ENQUEUE TO THE FOOTER
// *******************************************************************************
// ENQUEUE LIGHTBOX SCRIPT
wp_enqueue_script('lightbox-script', get_template_directory_uri() . '/js/lightbox.js', null, null, true);
// ENQUEUE FOOTER SCRIPTS
wp_enqueue_script('scripts', get_template_directory_uri() . '/js/scripts.js', null, null, true);
}
add_action( 'wp_enqueue_scripts', 'wp_add_scripts' );
/*-----------------------------------------------------------------------------------
INCLUDES FOR FUNCTION FILES & OTHER LIBRARIES
-------------------------------------------------------------------------------------*/
// *******************************************************************************
// INCLUDE FOR CUSTOM POST TYPES (USE PLUGIN INSTEAD)
// *******************************************************************************
// include(TEMPLATEPATH . '/php/post_types.php');
// *******************************************************************************
// INCLUDE FOR CUSTOM FIELDS (USE PLUGIN INSTEAD)
// *******************************************************************************
// include(TEMPLATEPATH . '/php/custom_fields.php');
// *******************************************************************************
// INCLUDE FOR COMMENT & PING BACK FUNCTIONS
// *******************************************************************************
include(TEMPLATEPATH . '/php/comment_functions.php');
/*-----------------------------------------------------------------------------------
FUNCTION TO GENERATE SITE TITLE BASED ON CURRENT PAGE TITLE
-------------------------------------------------------------------------------------*/
function generate_title() {
global $title_override;
if($title_override) {
echo $title_override;
} else {
global $page, $paged; wp_title('|', true, 'right'); bloginfo('name');
// ***************************************************************************
// USE THE BLOG DESCRIPTION FOR THE HOME/FRONT PAGE
// ***************************************************************************
$site_description = get_bloginfo('description', 'display');
if ($site_description && (is_home() || is_front_page())) {
echo " | $site_description";
}
// ***************************************************************************
// ADD A PAGE NUMBER IF NECESSARY
// ***************************************************************************
if ($paged >= 2 || $page >= 2) {
echo ' | ' . sprintf(__('Page %s', 'framework'), max($paged, $page));
}
}
}
/*-----------------------------------------------------------------------------------
VARIOUS FUNCTIONS FOR THE DASHBOARD
-------------------------------------------------------------------------------------*/
// *******************************************************************************
// USE THE EDITOR-STYLE.CSS FILE TO STYLE THE VISUAL EDITOR
// *******************************************************************************
// add_editor_style();
// *******************************************************************************
// AUTOMATICALLY UPDATES WP_NAV_MENU TO ONLY SHOW ITEMS SET TO 'PUBLISHED'
// *******************************************************************************
function exclude_nav_items($items, $menu, $args) {
global $wpdb;
//add your custom post types to this array
$allowed_post_types = array('post', 'page');
$sql = "SELECT ID FROM {$wpdb->prefix}posts WHERE (post_status='draft' OR post_status='pending' OR post_status='trash') AND ID=%d && post_type=%s";
foreach ($items as $k => $item) {
if(in_array($item->object, $allowed_post_types)) {
$query = $wpdb->prepare($sql, $item->object_id, $item->object);
$result = $wpdb->get_var($query);
if($result) unset($items[$k]);
}
}
return $items;
}
add_filter('wp_get_nav_menu_items', 'exclude_nav_items', 10, 3);
// *******************************************************************************
// REGISTER CUSTOM IMAGE SIZES FOR MEDIA LIBRARY
// *******************************************************************************
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' ); // ADDS SUPPORT FOR FEATURED IMAGES
add_image_size( 'small', 200, 200, true ); // SMALL PHOTOS
add_image_size( 'extra-large', 960, 640, true ); // EXTRA LARGE PHOTOS
}
// *******************************************************************************
// ADD CUSTOM IMAGE SIZES TO PRESETS MENU
// *******************************************************************************
function show_custom_image_sizes( $sizes ) {
global $_wp_additional_image_sizes;
if ( empty($_wp_additional_image_sizes) ) {
return $sizes;
}
foreach ( $_wp_additional_image_sizes as $id => $data ) {
if ( !isset($sizes[$id]) ) {
$sizes[$id] = ucwords( str_replace( '-', ' ', $id ) );
}
}
return $sizes;
}
add_filter( 'image_size_names_choose', 'show_custom_image_sizes' );
// *******************************************************************************
// UPDATE NATIVE WP GALLERY SHORTCODE
// *******************************************************************************
// REGISTER NEW GALLERY SHORTCODE
add_shortcode('gallery', 'my_photo_gallery');
function my_photo_gallery($attr) {
$post = get_post();
static $instance = 0;
$instance++;
if ( ! empty( $attr['ids'] ) ) {
if ( empty( $attr['orderby'] ) )
$attr['orderby'] = 'post__in';
$attr['include'] = $attr['ids'];
}
$output = apply_filters('post_gallery', '', $attr);
if ( $output != '' )
return $output;
if ( isset( $attr['orderby'] ) ) {
$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
if ( !$attr['orderby'] )
unset( $attr['orderby'] );
}
extract(shortcode_atts(array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post->ID,
'itemtag' => 'dl',
'icontag' => 'dt',
'captiontag' => 'dd',
'columns' => 3,
'size' => 'thumbnail',
'include' => '',
'exclude' => ''
), $attr));
$id = intval($id);
if ( 'RAND' == $order )
$orderby = 'none';
if ( !empty($include) ) {
$_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
$attachments = array();
foreach ( $_attachments as $key => $val ) {
$attachments[$val->ID] = $_attachments[$key];
}
} elseif ( !empty($exclude) ) {
$attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
} else {
$attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
}
if ( empty($attachments) )
return '';
if ( is_feed() ) {
$output = "\n";
foreach ( $attachments as $att_id => $attachment )
$output .= wp_get_attachment_link($att_id, $size, true) . "\n";
return $output;
}
$itemtag = tag_escape($itemtag);
$captiontag = tag_escape($captiontag);
$icontag = tag_escape($icontag);
$valid_tags = wp_kses_allowed_html( 'post' );
if ( ! isset( $valid_tags[ $itemtag ] ) )
$itemtag = 'dl';
if ( ! isset( $valid_tags[ $captiontag ] ) )
$captiontag = 'dd';
if ( ! isset( $valid_tags[ $icontag ] ) )
$icontag = 'dt';
$columns = intval($columns);
$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
$selector = "gallery-{$instance}";
$gallery_style = $gallery_div = '';
if ( apply_filters( 'use_default_gallery_style', true ) )
$gallery_style = "
";
$size_class = sanitize_html_class( $size );
$gallery_div = "
";
$output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
$i = 0;
foreach ( $attachments as $id => $attachment ) {
$caption = '';
$description = '';
$link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
$url = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_url($id) : wp_get_attachment_url($id);
$thumb = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_thumb_url($id) : wp_get_attachment_thumb_url($id);
$title = $attachment->post_title;
$caption = $attachment->post_excerpt;
if (trim($caption)) {
$description .= "data-title='";
$description .= wptexturize($caption);
$description .= "'";
}
$output .= "<{$itemtag} class='gallery-item'>";
$output .= "<{$icontag} class='gallery-item-container'>";
$output .= "

";
$output .= "{$icontag}>";
$output .= "{$itemtag}>";
}
$output .= "
\n";
return $output;
}
/*-----------------------------------------------------------------------------------
FUNCTIONS FOR WP NAV MENUS
-------------------------------------------------------------------------------------*/
// *******************************************************************************
// REGISTER WP NAV MENU LOCATIONS
// *******************************************************************************
register_nav_menus(array(
'main-navigation' => __('Main Navigation', 'Framework'),
'footer-navigation' => __('Footer Navigation', 'Framework'),
'footer-links' => __('Footer Links', 'Framework'),
'side-links' => __('Side Links', 'Framework'),
));
// *******************************************************************************
// ADDS WP NAV MENU WALKER CAPABILITIES
// *******************************************************************************
/*********************************************************************************
* By Default, the Walker is hidden. To show it, you need to change the display
* to "Block" instead of "None" in the stylesheet.
*********************************************************************************/
class My_Walker extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth, $args) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty($item->classes) ? array() : (array) $item->classes;
$class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item));
$class_names = ' class="'. esc_attr($class_names) . '"';
$output .= $indent . '\n";
}
function start_lvl(&$output, $depth = 0, $args = array()) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent\n";
}
}
//.................. CUSTOM NAV MENU FALLBACK TO SHOW A HOME LINK ....................//
// CYSY Framework 3 Copyright(c) 2012-2013 - CYber SYtes, Inc. All Rights Reserved
/* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
*
* To override this in a child theme, remove the filter and optionally add
* your own function tied to the wp_page_menu_args filter hook.
*
*/
function framework_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'framework_page_menu_args' );
/**
* sets the_content length in posts of wordpress
*
TO use this, echo this on your page: the_content_limit(390,"learn more"); ?>
*/
/*
function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
if (strlen($_GET['p']) > 0) {
echo $content;
}
else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
$content = substr($content, 0, $espacio);
$content = $content;
echo $content;
echo "...".$more_link_text."";
}
else {
echo $content;
}
}
*/
/**
* Sets the post excerpt length to 40 characters.
*
* To override this length in a child theme, remove the filter and add your own
* function tied to the excerpt_length filter hook.
*
* @return int
// CYSY Framework 3 Copyright(c) 2012-2013 - CYber SYtes, Inc. All Rights Reserved
*/
function framework_excerpt_length( $length ) {
return 40;
}
add_filter( 'excerpt_length', 'framework_excerpt_length' );
/**
* Set Your Own Custom Excerpt Length
* To set the amount of words that you want your excerpt to be simply use:
* echo excerpt(15); ?>
*/
/*
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
*/
/**
* Returns a "Continue Reading" link for excerpts
// Copyright(c) 2012-2013 - CYber SYtes, Inc. All Rights Reserved
*/
function framework_continue_reading_link() {
return ' ' . __( 'Continue reading →', 'CYSY Framework 3' ) . '';
}
/**
* Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and framework_continue_reading_link().
*
* To override this in a child theme, remove the filter and add your own
* function tied to the excerpt_more filter hook.
*
// CYSY Framework 3 Copyright(c)2012-2013 - CYber SYtes, Inc. All Rights Reserved
/*
function framework_auto_excerpt_more( $more ) {
return ' …' . framework_continue_reading_link();
}
add_filter( 'excerpt_more', 'framework_auto_excerpt_more' );
*/
/**
* Adds a pretty "Continue Reading" link to custom post excerpts.
*
* To override this link in a child theme, remove the filter and add your own
* function tied to the get_the_excerpt filter hook.
*
*/
/*
function framework_custom_excerpt_more( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
$output .= framework_continue_reading_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'framework_custom_excerpt_more' );
*/
//..................................................... ADD IS_CHILD FUNCTION
// This is a neat little function that allows for you to use interact with a
// page based on whether or not it is a child of a page.
// is_child()
function is_child($parent) {
global $wp_query;
if ($wp_query->post->post_parent == $parent) {
$return = true;
}
else {
$return = false;
}
return $return;
}
if ( ! function_exists( 'framework_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
*/
function framework_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
?>
id="li-comment- comment_ID(); ?>">
break;
case 'pingback' :
case 'trackback' :
?>
_e( 'Pingback:', 'CYSY Framework 3' ); ?> comment_author_link(); ?> edit_comment_link( __('(Edit)', 'CYSY Framework 3'), ' ' ); ?>
break;
endswitch;
}
endif;
/**
* Register widgetized areas, including two sidebars widgets for this framework.
// CYSY Framework 3 Copyright(c) 2012-2013 - CYber SYtes, Inc. All Rights Reserved
* @since CYSY Framework 3
* @uses register_sidebar
*/
// Area 1, located at the top of the sidebar.
register_sidebar( array(
'name' => __( 'Primary Widget Area', 'CYSY Framework 3' ),
'id' => 'primary-widget-area',
'description' => __( 'The primary widget area', 'CYSY Framework 3' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
) );
// Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
register_sidebar( array(
'name' => __( 'Secondary Widget Area', 'CYSY Framework 3' ),
'id' => 'secondary-widget-area',
'description' => __( 'The secondary widget area', 'CYSY Framework 3' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
) );
/**
* Removes the default styles that are packaged with the Recent Comments widget.
*
* To override this in a child theme, remove the filter and optionally add your own
* function tied to the widgets_init action hook.
*
*/
function framework_remove_recent_comments_style() {
global $wp_widget_factory;
remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
}
add_action( 'widgets_init', 'framework_remove_recent_comments_style' );
if ( ! function_exists( 'framework_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post—date/time and author.
*
*/
function framework_posted_on() {
printf( __( 'Posted on %2$s by %3$s', 'CYSY Framework 3' ),
'meta-prep meta-prep-author',
sprintf( '%3$s',
get_permalink(),
esc_attr( get_the_time() ),
get_the_date()
),
sprintf( '%3$s',
get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr__( 'View all posts by %s', 'CYSY Framework 3' ), get_the_author() ),
get_the_author()
)
);
}
endif;
if ( ! function_exists( 'framework_posted_in' ) ) :
/**
* Prints HTML with meta information for the current post (category, tags and permalink).
*
*/
function framework_posted_in() {
// Retrieves tag list of current post, separated by commas.
$tag_list = get_the_tag_list( '', ', ' );
if ( $tag_list ) {
$posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the permalink.', 'CYSY Framework 3' );
} elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
$posted_in = __( 'This entry was posted in %1$s. Bookmark the permalink.', 'CYSY Framework 3' );
} else {
$posted_in = __( 'Bookmark the permalink.', 'CYSY Framework 3' );
}
// Prints the string, replacing the placeholders.
printf(
$posted_in,
get_the_category_list( ', ' ),
$tag_list,
get_permalink(),
the_title_attribute( 'echo=0' )
);
}
endif;
// Pull an image URL from the media gallery
function sp_get_image($num = 0) {
global $post;
$children = get_children(array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'ASC'
));
$count = 0;
foreach ((array)$children as $key => $value) {
$images[$count] = $value;
$count++;
}
if(isset($images[$num]))
return wp_make_link_relative(wp_get_attachment_url($images[$num]->ID));
else
return false;
}
/********************* THESE LINES OF CODE ARE FOR THE .htaccess file
The first two lines of code are used to allow you to include .php files from outside of the /wordpress/ directory.
The next two lines of code are used for increasing the upload sizes for media to wordpress.
*** These lines below need to be added to the top of the .htaccess file that is in the root of the site.
php_value allow_url_fopen on
php_value allow_url_include on
php_value post_max_size 8M
php_value upload_max_filesize 8M
*/
/*** THIS MODIFIES THE ADMIN LOGIN SCREEN LOGO TO DISPLAY A
CUSTOM LOGO FROM THE THEME DIRECTORY.
add_filter( 'login_headerurl', 'namespace_login_headerurl' );
/**
* Replaces the login header logo URL
*
* @param $url
*/
function namespace_login_headerurl( $url ) {
$url = home_url( '/' );
return $url;
}
add_filter( 'login_headertitle', 'namespace_login_headertitle' );
/**
* Replaces the login header logo title
*
* @param $title
*/
function namespace_login_headertitle( $title ) {
$title = get_bloginfo( 'name' );
return $title;
}
add_action( 'login_head', 'namespace_login_style' );
/**
* Replaces the login header logo
*/
function namespace_login_style() {
echo '';
}
// remove version info from head and feeds
// for security buff
function complete_version_removal() {
return '';
}
add_filter('the_generator', 'complete_version_removal');
// Reformatts dashboard to eliminate a lot of the annoying things our clients see first off.
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
function my_custom_dashboard_widgets() {
global $wp_meta_boxes;
//Right Now - Comments, Posts, Pages at a glance
//unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
//Recent Comments
//unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
//Incoming Links
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
//Plugins - Popular, New and Recently updated Wordpress Plugins
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
//Wordpress Development Blog Feed
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
//Other Wordpress News Feed
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
//Quick Press Form
//unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
//Recent Drafts List
//unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
}
// remove unncessary header info in the of our sites
function remove_header_info() {
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link');
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
}
add_action('init', 'remove_header_info');
// remove extra css that recent comments widget injects
function remove_recent_comments_style() {
global $wp_widget_factory;
remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
}
add_action('widgets_init', 'remove_recent_comments_style');
// this changes the footer in the admin section of wordpress
function remove_footer_admin () {
echo 'Site Developed by: CYber SYtes, Inc. Web SYtes by Design';
}
add_filter('admin_footer_text', 'remove_footer_admin');
//this line of code removes the error messages above login screen if incorrect login is entered.
// basically removes information hackers could use to know if they're having success.
add_filter('login_errors',create_function('$a', "return null;"));
//remove please update now link for clients, but keeps it live for admins
if ( !current_user_can( 'edit_users' ) ) {
remove_action('admin_notices','update_nag',3);
}
//remove links menu tab from wordpress installs, because we don't use them.
function sb_remove_admin_menus(){
if ( function_exists('remove_menu_page') ) {
remove_menu_page('link-manager.php'); // Remove the Links tab by providing its slug
}
}
add_action('admin_menu', 'sb_remove_admin_menus');
add_action('after_setup_theme',
function() {
add_theme_support( 'html5', [ 'script', 'style' ] );
}
);
add_filter('nav_menu_item_id', 'clear_nav_menu_item_id', 10, 3);
function clear_nav_menu_item_id($id, $item, $args) {
return "";
}
?>
endif; ?>