Skip to content

Instantly share code, notes, and snippets.

@smeyer
Created July 16, 2012 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smeyer/3123300 to your computer and use it in GitHub Desktop.
Save smeyer/3123300 to your computer and use it in GitHub Desktop.
function.php
<?php
/* ------------ Linked PHP Files ------------
*/
require_once( get_stylesheet_directory() . '/extensions/theme-options.php');
require_once( get_stylesheet_directory() . '/extensions/testimonial-post-type.php');
require_once( get_stylesheet_directory() . '/extensions/news-post-type.php');
require_once( get_stylesheet_directory() . '/extensions/resources-post-type.php');
require_once( get_stylesheet_directory() . '/extensions/partners-post-type.php');
require_once( get_stylesheet_directory() . '/extensions/customers-post-type.php');
/* ------------ end of Linked PHP Files ------------ */
/* ------------ Add theme support ------------ */
/*** Add thumbnails */
add_theme_support( 'post-thumbnails', array( 'post', 'partners', 'ai1ec_event', 'employees', 'news', 'customers' ) );
update_option('thumbnail_size_w', 120);
update_option('thumbnail_size_h', 100);
update_option('medium_size_w', 260);
update_option('medium_size_h', 200);
/* Check if page is a child */
function env_is_subpage() {
global $post;
if ( is_page() && $post->post_parent ) {
$parentID = $post->post_parent;
return $parentID;
} else {
return false;
};
}
/* display Sub menu */
function env_display_subpages()
{
global $post;
$ancestor = $post->ancestors[1];
$ancestor2 = $post->ancestors[2];
$ancestor3 = $post->ancestors[3];
if($post->post_parent && $ancestor3)
{ $children = preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a$2><span>$3</span></a>', wp_list_pages("title_li=&child_of=".$ancestor3."&echo=0&depth=2")); }
else if($post->post_parent && $ancestor2)
{ $children = preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a$2><span>$3</span></a>', wp_list_pages("title_li=&child_of=".$ancestor2."&echo=0&depth=2")); }
else if($post->post_parent && $ancestor)
{ $children = preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a$2><span>$3</span></a>', wp_list_pages("title_li=&child_of=".$ancestor."&echo=0&depth=2")); }
else if($post->post_parent)
{ $children = preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a$2><span>$3</span></a>', wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&depth=2")); }
else
{ $children = preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a$2><span>$3</span></a>', wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=2")); }
if ($children) { ?>
<div class="widget widget_nav"><div class="widget-bottom"><div class="widget-content"><div class="widget-text">
<ul id="subnav">
<?php echo $children; ?>
</ul><!--subnav-->
</div> <!-- .widget-text --> </div> <!-- .widget-content--></div> <!-- .widget-bottom--></div> <!-- .widget-->
<?php }
}
/* display specific subnav */
function env_display_spec_subpages($post_ID)
{
$children = preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a$2><span>$3</span></a>', wp_list_pages("title_li=&child_of=".$post_ID."&echo=0&depth=2"));
if ($children) { ?>
<div class="widget widget_nav"><div class="widget-bottom"><div class="widget-content"><div class="widget-text">
<ul id="subnav">
<?php echo $children; ?>
</ul><!--subnav-->
</div> <!-- .widget-text --> </div> <!-- .widget-content--></div> <!-- .widget-bottom--></div> <!-- .widget-->
<?php }
}
/*** Register Nav menus */
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'env' ),
'secondary' => __( 'Secondary Menu', 'env' ),
) );
/*** Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
function portfolio_page_menu_args($args) {
$args['show_home'] = true;
$args['menu_class'] = 'menu';
return $args;
}
add_filter( 'wp_page_menu_args', 'portfolio_page_menu_args' );*/
/*** Register sidebar */
function sidebars_init() {
register_sidebar( array (
'name' => __( 'General Sidebar', 'env' ),
'id' => 'primary'
));
register_sidebar( array (
'name' => __( 'Customers Sidebar', 'env' ),
'id' => 'customers'
));
register_sidebar( array (
'name' => __( 'News Sidebar', 'env' ),
'id' => 'news'
));
register_sidebar( array (
'name' => __( 'Partners Sidebar', 'env' ),
'id' => 'partners'
));
register_sidebar( array (
'name' => __( 'Blog Sidebar', 'env' ),
'id' => 'blog'
));
register_sidebar( array (
'name' => __( 'Resources Sidebar', 'env' ),
'id' => 'resources'
));
}
add_action( 'init', 'sidebars_init' );
/*** Add default posts and comments RSS feed links to head */
add_theme_support( 'automatic-feed-links' );
/*** Enqueue scripts */
function my_init() {
if (!is_admin()) {
/* remove comment from the next two lines to load the special copy of jQuery */
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js', false, '1.6.2');
wp_enqueue_script('jquery');
wp_enqueue_script( 'formsclear', get_template_directory_uri() . '/js/jquery.formsclear.js', array( 'jquery' ) );
wp_enqueue_script( 'cyclelite', get_template_directory_uri() . '/js/jquery.cycle.lite.js', array( 'jquery' ) );
wp_enqueue_script( 'testi-cycle', get_template_directory_uri() . '/js/testi-cycle.js', array( 'jquery' ) );
wp_enqueue_script( 'resource-form', get_template_directory_uri() . '/js/resource-form.js', array( 'jquery' ) );
wp_enqueue_script( 'lettering', get_template_directory_uri() . '/js/lettering.js', array( 'jquery' ) );
//wp_enqueue_script(array('jquery', 'editor', 'thickbox', 'media-upload'));
//wp_enqueue_style('thickbox');
}
}
add_action('init', 'my_init');
function myplugin_load_tiny_mce() {
wp_tiny_mce( false ); // true gives you a stripped down version of the editor
}
add_action("admin_head","myplugin_load_tiny_mce");
/*** Remove Enqueued scripts */
function my_deregister_javascript() {
if ( !is_page_template( 'template-form.php' ) ) {
wp_deregister_script( 'formsclear' );
}
}
//add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
/*** Add editor function to custom meta */
function my_admin_print_footer_scripts()
{
?><script type="text/javascript">/* <![CDATA[ */
jQuery(function($)
{
var i=1;
$('.customEditor textarea').each(function(e)
{
var id = $(this).attr('id');
if (!id)
{
id = 'customEditor-' + i++;
$(this).attr('id',id);
}
tinyMCE.execCommand('mceAddControl', false, id);
});
});
/* ]]> */</script><?php
}
add_action('admin_print_footer_scripts','my_admin_print_footer_scripts',99);
add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 25 );
function custom_editor() {
echo '<style type="text/css">'; ?>
/* custom editor styles */
#env_home_data .customEditor, #env_employee_meta .customEditor
{ margin:15px 6px; border:1px solid #ccc; }
#env_home_data .customEditor textarea, #env_employee_meta .customEditor textarea
{ border:0; }
#post-body .my_meta_control .customEditor .mceStatusbar a.mceResize
{ top:-2px; }
/* extra styles used in other WPAlchemy meta boxes */
#env_home_data .description, #env_employee_meta .description
{ display:none; }
#env_home_data label, #env_employee_meta label
{ display:block; font-weight:bold; margin:6px; margin-bottom:0; margin-top:12px; }
#env_home_data label span, #env_employee_meta label span
{ display:inline; font-weight:normal; }
#env_home_data span, #env_employee_meta span
{ color:#999; }
#env_home_data textarea, #env_home_data input[type='text'], #env_employee_meta textarea, #env_employee_meta input[type='text']
{ margin-bottom:3px; width:99%; }
#env_home_data h4, #env_employee_meta h4
{ color:#999; font-size:1em; margin:15px 6px; text-transform:uppercase; }
<?php echo '</style>';
}
add_action('admin_head', 'custom_editor');
/* ------------ end of Add theme support ------------ */
/* ------------ Change defaults ------------ */
/*** Admin clean-up
function remove_menu_items() {
global $menu;
$restricted = array(__('Links'), __('Comments'));
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){
unset($menu[key($menu)]);}
}
}
add_action('admin_menu', 'remove_menu_items');
*/
/*** Change Excerpt length */
function custom_excerpt_length( $length ) {
if (is_front_page()) { return 10; }
else return 30;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
/**
* Always add a "read more" link to ALL excerpts (if there is more to read ;)
* and still check to add elipsis if the excerpt was truncated
*
* Maintains consistency between manually written excerpts
* and WP auto-generated excerpts using the_excerpt()
*
* These (2) filters use (3) functions
* @uses the_excerpt_read_more_link()
* @uses the_excerpt_always_show_read_more()
* @uses the_excerpt_was_truncated_so_format()
*/
add_filter( 'get_the_excerpt', 'the_excerpt_always_show_read_more', 9 );
add_filter( 'excerpt_more', 'the_excerpt_was_truncated_so_format' );
/**
* The custom text in the "read more" permalink
* Abstracted so it can also be used in the_content() to make ALL excerpts consistent
*/
function the_excerpt_read_more_text_for_link() {
return '// more';
}
/**
* The permalink / read more output we will use on all the_excerpt output
*/
function the_excerpt_read_more_link() {
global $post;
return ' <a href="'. get_permalink($post->ID) . '" class="morelink">' . the_excerpt_read_more_text_for_link() . '</a>';
}
/**
* Check to see if the current post in the loop was manually written
* and add our link if it was. Manually written excerpts are formatted
* so we have to add this here if we want it inline with the last
* paragraph/element. Manually written excerpts are never truncated so no worries.
*/
function the_excerpt_always_show_read_more() {
global $post;
// Only manually add the link if the excerpt was manually written
// otherwise WP generated excerpts will never trigger
if ( !empty($post->post_excerpt) )
return $post->post_excerpt . the_excerpt_read_more_link();
else
return $post->post_excerpt;
}
/**
* If WP truncates auto generated excerpt then add this plus our read more permalink
*/
function the_excerpt_was_truncated_so_format() {
return the_excerpt_read_more_link();
}
/* ------------ env of Change defaults ------------ */
/* ------------ Additional Meta ------------ */
/*** Add Home Metabox */
function my_meta_init()
{
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
/* check for a template type */
if ($template_file == 'template-home.php')
{
add_meta_box('env_home_data', 'Homepage Custom Data', 'env_home_data', 'page', 'normal', 'high');
}
add_action('save_post', 'env_save_home_meta', 1, 4); /* save the custom fields */
}
add_action('admin_init','my_meta_init');
/*** The Home Metabox */
function env_home_data() {
global $post;
/* Noncename needed to verify where the data originated */
echo '<input type="hidden" name="envmeta_noncename" id="envmeta_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
/* Get the location data if its already been entered */
$home_header = get_post_meta($post->ID, '_home_header', true);
$home_sidebox_content = get_post_meta($post->ID, '_home_sidebox_content', true);
/* Echo out the field */
echo '<p>Enter the home header:</p>';
echo '<input type="text" name="_home_header" value="' . $home_header . '" class="widefat" />';
echo '<p>Insert Content for Sidebox</p>';
wp_editor( $home_sidebox_content, "2" );
}
/*** Save the Metabox Data */
function env_save_home_meta($post_id, $post) {
/* verify this came from the our screen and with proper authorization, */
/* because save_post can be triggered at other times */
if ( !wp_verify_nonce( $_POST['envmeta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
/* Is the user allowed to edit the post or page? */
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
/* OK, we're authenticated: we need to find and save the data */
/* We'll put it into an array to make it easier to loop though. */
$home_meta['_home_header'] = $_POST['_home_header'];
$home_meta['_home_sidebox_content'] = $_POST['_home_sidebox_content'];
/* Add values of $events_meta as custom fields */
foreach ($home_meta as $key => $value) { /* Cycle through the $home_meta array! */
if( $post->post_type == 'revision' ) return; /* Don't store custom data twice */
$value = implode(',', (array)$value); /* If $value is an array, make it a CSV (unlikely) */
if(get_post_meta($post->ID, $key, FALSE)) { /* If the custom field already has a value */
update_post_meta($post->ID, $key, $value);
} else { /* If the custom field doesn't have a value */
add_post_meta($post->ID, $key, $value);
}
if(!$value) delete_post_meta($post->ID, $key); /* Delete if blank */
}
}
/*** Add Post Metabox */
function my_postmeta_init()
{
add_meta_box('env_feat_post', 'Featured', 'env_feat_post', 'post', 'side', 'high');
add_action('save_post', 'env_save_post_meta', 1, 4); /* save the custom fields */
}
add_action('admin_init','my_postmeta_init');
/*** Add Post Metabox */
function env_feat_post($post) {
// Noncename needed to verify where the data originated
echo '<input type="hidden" name="envmeta_noncename" id="envmeta_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
// Get the location data if its already been entered
$post_feat = get_post_meta($post->ID, '_home_feat', true);
// Echo out the field
echo '<label for="_home_feat">Feature on homepage?</label> ';
?><input type="checkbox" name="_home_feat" id="post_feat" <?php checked( $post_feat, 'on' ); ?> /><?php
}
/* Save the Metabox Data */
function env_save_feat_post($post_id, $post) {
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( !wp_verify_nonce( $_POST['envmeta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
// Is the user allowed to edit the post or page?
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
// OK, we're authenticated: we need to find and save the data
$chk = isset( $_POST['_home_feat'] ) && $_POST['_home_feat'] ? 'on' : 'off';
update_post_meta( $post_id, '_home_feat', $chk );
}
add_action('save_post', 'env_save_feat_post', 1, 2); // save the custom fields
function admin_post_header_columns($columns)
{
if (!isset($columns['featured']))
$columns['featured'] = "Featured";
return $columns;
}
function admin_post_data_row($column_name, $post_id)
{
switch($column_name)
{
case 'featured':
/* Get the post meta. */
$feat = get_post_meta( $post_id, '_home_feat', true );
/* If no duration is found, output a default message. */
if ($feat == 'on') { echo '<b>yes</b>'; }
else { echo ''; }
break;
default:
break;
}
}
add_filter( 'manage_edit-post_columns', 'admin_post_header_columns', 10, 1);
add_action( 'manage_posts_custom_column', 'admin_post_data_row', 10, 2);
/*** Add Event Metabox */
function my_eventmeta_init()
{
add_meta_box('env_event_presentor', 'Event Presentor', 'env_event_presentor', 'ai1ec_event', 'normal', 'core');
add_meta_box('env_feat_event', 'Featured', 'env_feat_event', 'ai1ec_event', 'side', 'high');
add_action('save_post', 'env_save_event_meta', 1, 4); /* save the custom fields */
}
add_action('admin_init','my_eventmeta_init');
/*** The Event Metabox */
function env_event_presentor() {
global $post;
/* Noncename needed to verify where the data originated */
echo '<input type="hidden" name="envmeta_noncename" id="envmeta_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
/* Get the location data if its already been entered */
$event_presentor = get_post_meta($post->ID, '_event_presentor', true);
/* Echo out the field */
echo '<p>Event Presentor:</p>';
echo '<input type="text" name="_event_presentor" value="' . $event_presentor . '" class="widefat" />';
}
function env_feat_event($post) {
// Noncename needed to verify where the data originated
echo '<input type="hidden" name="envmeta_noncename" id="envmeta_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
// Get the location data if its already been entered
$event_feat = get_post_meta($post->ID, '_home_feat', true);
// Echo out the field
echo '<label for="_home_feat">Feature on homepage?</label> ';
?><input type="checkbox" name="_home_feat" id="event_feat" <?php checked( $event_feat, 'on' ); ?> /><?php
}
/*** Save the Metabox Data */
function env_save_event_meta($post_id, $post) {
/* verify this came from the our screen and with proper authorization, */
/* because save_post can be triggered at other times */
if ( !wp_verify_nonce( $_POST['envmeta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
/* Is the user allowed to edit the post or page? */
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
/* OK, we're authenticated: we need to find and save the data */
/* We'll put it into an array to make it easier to loop though. */
$event_meta['_event_presentor'] = $_POST['_event_presentor'];
/* Add values of $events_meta as custom fields */
foreach ($event_meta as $key => $value) { /* Cycle through the $home_meta array! */
if( $post->post_type == 'revision' ) return; /* Don't store custom data twice */
$value = implode(',', (array)$value); /* If $value is an array, make it a CSV (unlikely) */
if(get_post_meta($post->ID, $key, FALSE)) { /* If the custom field already has a value */
update_post_meta($post->ID, $key, $value);
} else { /* If the custom field doesn't have a value */
add_post_meta($post->ID, $key, $value);
}
if(!$value) delete_post_meta($post->ID, $key); /* Delete if blank */
}
}
/* Save the Metabox Data */
function env_save_feat_event($post_id, $post) {
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( !wp_verify_nonce( $_POST['envmeta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
// Is the user allowed to edit the post or page?
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
// OK, we're authenticated: we need to find and save the data
$chk = isset( $_POST['_home_feat'] ) && $_POST['_home_feat'] ? 'on' : 'off';
update_post_meta( $post_id, '_home_feat', $chk );
}
add_action('save_post', 'env_save_feat_event', 1, 2); // save the custom fields
function admin_event_header_columns($columns)
{
if (!isset($columns['featured']))
$columns['featured'] = "Featured";
return $columns;
}
add_filter( 'manage_edit-ai1ec_event_columns', 'admin_event_header_columns', 10, 1);
/*** Add Post Date Metabox */
function my_postdatemeta_init()
{
add_meta_box('env_post_date_meta', 'Admin Meta', 'env_post_date_meta', 'post', 'normal', 'low');
add_meta_box('env_post_date_meta', 'Admin Meta', 'env_post_date_meta', 'news', 'normal', 'low');
add_meta_box('env_event_date_meta', 'Admin Meta', 'env_event_date_meta', 'ai1ec_event', 'normal', 'low');
}
add_action('admin_init','my_postdatemeta_init');
/*** The Post Date Metabox */
function env_post_date_meta() {
global $post;
/* Noncename needed to verify where the data originated */
echo '<input type="hidden" name="envmeta_noncename" id="envmeta_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
/* Get the location data if its already been entered */
$env_post_date_meta = get_post_meta($post->ID, '_post_date_meta', true);
/* Echo out the field */
echo '<p>For admin purposes. <strong>DO NOT USE</strong></p>';
echo '<input type="text" name="_post_date_meta" value="' . $env_post_date_meta . '" class="widefat" />';
}
/*** Save the Metabox Data */
function env_save_post_date_meta($post_id, $post) {
/* verify this came from the our screen and with proper authorization, */
/* because save_post can be triggered at other times */
if ( !wp_verify_nonce( $_POST['envmeta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
/* Is the user allowed to edit the post or page? */
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
/* OK, we're authenticated: we need to find and save the data */
/* We'll put it into an array to make it easier to loop though. */
$post_date_meta['_post_date_meta'] = $post->post_date;
/* Add values of $events_meta as custom fields */
foreach ($post_date_meta as $key => $value) { /* Cycle through the $home_meta array! */
if( $post->post_type == 'revision' ) return; /* Don't store custom data twice */
$value = implode(',', (array)$value); /* If $value is an array, make it a CSV (unlikely) */
if(get_post_meta($post->ID, $key, FALSE)) { /* If the custom field already has a value */
update_post_meta($post->ID, $key, $value);
} else { /* If the custom field doesn't have a value */
add_post_meta($post->ID, $key, $value);
}
if(!$value) delete_post_meta($post->ID, $key); /* Delete if blank */
}
}
add_action('wp_insert_post', 'env_save_post_date_meta', 1, 2); // save the custom fields
/*** The Event Date Metabox */
function env_event_date_meta() {
global $post;
/* Noncename needed to verify where the data originated */
echo '<input type="hidden" name="envmeta_noncename" id="envmeta_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
/* Get the location data if its already been entered */
$env_post_date_meta = get_post_meta($post->ID, '_post_date_meta', true);
/* Echo out the field */
echo '<p>For admin purposes. <strong>DO NOT USE</strong></p>';
echo '<input type="text" name="_post_date_meta" value="' . $env_post_date_meta . '" class="widefat" />';
}
/*** Save the Metabox Data */
function env_save_event_date_meta($post_id, $post) {
/* verify this came from the our screen and with proper authorization, */
/* because save_post can be triggered at other times */
if ( !wp_verify_nonce( $_POST['envmeta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
/* Is the user allowed to edit the post or page? */
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
/* OK, we're authenticated: we need to find and save the data */
/* We'll put it into an array to make it easier to loop though. */
global $wpdb;
$pID = $post->ID;
$event = $wpdb->get_var( $wpdb->prepare( "SELECT start FROM acM_ai1ec_events WHERE post_ID = '$pID'" ) );
$post_date_meta['_post_date_meta'] = $event;
/* Add values of $events_meta as custom fields */
foreach ($post_date_meta as $key => $value) { /* Cycle through the $home_meta array! */
if( $post->post_type == 'revision' ) return; /* Don't store custom data twice */
$value = implode(',', (array)$value); /* If $value is an array, make it a CSV (unlikely) */
if(get_post_meta($post->ID, $key, FALSE)) { /* If the custom field already has a value */
update_post_meta($post->ID, $key, $value);
} else { /* If the custom field doesn't have a value */
add_post_meta($post->ID, $key, $value);
}
if(!$value) delete_post_meta($post->ID, $key); /* Delete if blank */
}
}
add_action('wp_insert_post', 'env_save_event_date_meta', 1, 2); // save the custom fields
/* ------------ end of Additional Meta ------------ */
/* ------------ Standard Plugin Functions ------------ */
/*** For Gravity Form Tabbing */
add_filter("gform_tabindex", create_function("", "return 1;"));
add_filter("gform_tabindex_3", create_function("", "return 1;"));
add_filter("gform_tabindex_4", create_function("", "return 2;"));
add_filter("gform_tabindex_2", create_function("", "return 500;"));
/*** Label extra thumbnails for MultiPostThumbnails
if (class_exists('MultiPostThumbnails')) { new MultiPostThumbnails(array( 'label' => '', 'id' => '', 'post_type' => '' ) ); }
*/
/*function my_connection_types() {
// Make sure the Posts 2 Posts plugin is active.
if ( !function_exists( 'p2p_register_connection_type' ) )
return;
p2p_register_connection_type( array(
'name' => 'posts_to_pages',
'from' => 'page',
'to' => 'post'
) );
}
add_action( 'wp_loaded', 'my_connection_types' );*/
// populate the field with "user_firstname" as the population parameter with the "first_name" of the current user
add_filter('gform_field_value_user_firstname', create_function("", '$value = populate_usermeta(\'first_name\'); return $value;' ));
// populate the field with "user_lastname" as the population parameter with the "last_name" of the current user
add_filter('gform_field_value_user_lastname', create_function("", '$value = populate_usermeta(\'last_name\'); return $value;' ));
// populate the field with "user_email" as the population parameter with the "last_name" of the current user
add_filter('gform_field_value_user_email', create_function("", '$value = populate_usermeta(\'user_email\'); return $value;' ));
// populate the field with "user_email" as the population parameter with the "last_name" of the current user
function env_populate_title() {
$s2title = get_user_field ("title");
if ($s2title == '') { $value = populate_usermeta('Title'); }
else { $value = $s2title; }
return $value;
}
add_filter('gform_field_value_Title', 'env_populate_title' );
// populate the field with "user_address_line_1" as the population parameter with the "user_address_line_1" of the current user
function env_populate_address1() {
$s2add1 = get_user_field ("street_address");
if ($s2add1 == '') { $value = populate_usermeta('user_address_line_1'); }
else { $value = $s2add1; }
return $value;
}
add_filter('gform_field_value_user_address_line_1', 'env_populate_address1' );
// populate the field with "user_address_line_2" as the population parameter with the "user_address_line_2" of the current user
function env_populate_address2() {
$s2add2 = get_user_field ("address_line_2");
if ($s2add2 == '') { $value = populate_usermeta('user_address_line_2'); }
else { $value = $s2add2; }
return $value;
}
add_filter('gform_field_value_user_address_line_2', 'env_populate_address2' );
// populate the field with "user_city" as the population parameter with the "user_city" of the current user
function env_populate_city() {
$s2city = get_user_field ("city");
if ($s2city == '') { $value = populate_usermeta('user_city'); }
else { $value = $s2city; }
return $value;
}
add_filter('gform_field_value_user_city', 'env_populate_city' );
// populate the field with "user_state" as the population parameter with the "user_state" of the current user
function env_populate_state() {
$s2state = get_user_field ("state");
if ($s2state == '') { $value = populate_usermeta('user_state'); }
else { $value = $s2state; }
return $value;
}
add_filter('gform_field_value_user_state', 'env_populate_state' );
// populate the field with "user_zip" as the population parameter with the "user_zip" of the current user
function env_populate_zip() {
$s2zip = get_user_field ("zip");
if ($s2zip == '') { $value = populate_usermeta('user_zip'); }
else { $value = $s2zip; }
return $value;
}
add_filter('gform_field_value_user_zip', 'env_populate_zip' );
// populate the field with "user_country" as the population parameter with the "user_country" of the current user
function env_populate_country() {
$s2country = get_user_field ("country");
if ($s2country == '') { $value = populate_usermeta('user_country'); }
else { $value = $s2country; }
return $value;
}
add_filter('gform_field_value_user_country', 'env_populate_country' );
// populate the field with "company" as the population parameter with the "last_name" of the current user
function env_populate_company() {
$s2comp = get_user_field ("Company");
if ($s2comp == '') { $value = populate_usermeta('Company'); }
else { $value = $s2comp; }
return $value;
}
add_filter('gform_field_value_Company', 'env_populate_company');
// this function is called by both filters and returns the requested user meta of the current user
function populate_usermeta($meta_key){
global $current_user;
return $current_user->__get($meta_key);
}
function my_qmt_reset_url( $reset_url ) {
return get_bloginfo('wpurl') . '?page_id=199';
}
add_filter( 'qmt_reset_url', 'my_qmt_reset_url' );
function pippin_login_form_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'redirect' => ''
), $atts ) );
if (!is_user_logged_in()) {
if($redirect) {
$redirect_url = $redirect;
} else {
$redirect_url = get_permalink();
}
$form = wp_login_form(array('echo' => false, 'redirect' => $redirect_url ));
}
return $form;
}
add_shortcode('loginform', 'pippin_login_form_shortcode');
function my_qmt_base_url( $base ) {
$additional_args = array(
'orderby' => 'date',
);
$base = get_bloginfo('wpurl') . '/resources';
return add_query_arg( $additional_args, $base );
}
add_filter( 'qmt_base_url', 'my_qmt_base_url' );
function set_s2_user_company($entry, $form){
global $current_user;
get_currentuserinfo();
$s2comp = get_user_field ("Company");
if ($s2comp == '') { update_user_option($current_user->user_ID, 'acM_s2member_custom_fields', $entry['6']); }
}
add_action("gform_post_submission", "set_s2_user_company", 10, 2);
/* ------------ end of Standard Plugin Functions ------------ */
/* ------------ Display Functions ------------ */
/*** Function for displaying post excerpts from a custom type for feed page with pagination */
/*** Function for displaying post excerpts from a custom type for feed page with pagination */
function env_display_exerpts_from_type($the_type, $the_num, $orderby, $the_order, $thumbsize, $inc_date = 'false', $status = 'publish')
{
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => $the_type,
'posts_per_page' => $the_num,
'orderby' => $orderby,
'order' => $the_order,
'paged' => $paged,
'post_status' => $status,
'ignore_sticky_posts' => 1,
);
$my_posts = new WP_Query( $args );
if( $my_posts->have_posts() ): while ( $my_posts->have_posts() ) : $my_posts->the_post();
global $post;
?>
<div class="article clear">
<?php if (has_post_thumbnail()) { ?><div class="thumb_image"><?php the_post_thumbnail($thumbsize); ?></div><?php } ?>
<div class="entry-content <?php if (!has_post_thumbnail()) { echo 'full-width'; }?>">
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?><?php if ($inc_date == 'true') { echo ' - '; the_time('F d, Y'); } ?></a></h3>
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; else: if ($the_type == 'events') { $verb = 'are'; } else $verb = 'is'; ?> <br /><h2><?php echo 'Sorry, there ' . $verb . ' no ' . $the_type .' at this time.'; ?></h2> <?php endif; ?>
<?php if (function_exists('wp_pagenavi') ) { ?>
<?php wp_pagenavi(); ?>
<?php } else { ?>
<nav id="nav-below">
<p class="screen-reader-text"><?php _e( 'Post navigation', 'env' ); ?></p>
<div class="nav-previous"><?php next_posts_link( __( '&#047;&#047; More posts', 'env' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( '&#047;&#047; Previous posts', 'env' ) ); ?></div>
</nav>
<?php }
wp_reset_postdata();
}
/*** Function for displaying post excerpts from a custom type for feed page with pagination */
function env_display_events_from_tax ($the_num, $orderby, $the_order, $thumbsize, $inc_date = 'false', $status = 'publish', $tax, $tax_term)
{
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'ai1ec_event',
'posts_per_page' => $the_num,
'orderby' => $orderby,
'order' => $the_order,
'paged' => $paged,
'post_status' => $status,
'ignore_sticky_posts' => 1,
'tax_query' => array(
array(
'taxonomy' => $tax,
'field' => 'slug',
'terms' => ($tax_term)
)
)
);
$my_posts = new WP_Query( $args );
echo '<ul class="event_list">';
if( $my_posts->have_posts() ): while ( $my_posts->have_posts() ) : $my_posts->the_post();
global $post;
?>
<?php if (has_post_thumbnail()) { ?><div class="thumb_image"><?php the_post_thumbnail($thumbsize); ?></div><?php } ?>
<li class="entry-content <?php if (!has_post_thumbnail()) { echo 'full-width'; }?>">
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?><?php if ($inc_date == 'true') { echo ' - '; the_time('F d, Y'); } ?></a></h3>
</li>
<?php endwhile; echo '</ul>'; else: echo '<h2>Sorry, there are no events at this time.'; ?></h2> <?php endif; ?>
<?php if (function_exists('wp_pagenavi') ) { ?>
<?php wp_pagenavi(); ?>
<?php } else { ?>
<nav id="nav-below">
<p class="screen-reader-text"><?php _e( 'Post navigation', 'env' ); ?></p>
<div class="nav-previous"><?php next_posts_link( __( '&#047;&#047; More events', 'env' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( '&#047;&#047; Previous events', 'env' ) ); ?></div>
</nav>
<?php }
wp_reset_postdata();
}
/*** Function for displaying post content from a custom type for feed page with pagination */
function env_display_posts_from_type($the_type, $the_num, $orderby, $the_order, $meta_url, $detailpg = 'false', $thumbsize ='', $inc_date = 'false', $status = 'publish')
{
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => $the_type,
'posts_per_page' => $the_num,
'orderby' => $orderby,
'order' => $the_order,
'paged' => $paged,
'post_status' => $status,
'ignore_sticky_posts' => 1
);
$my_posts = new WP_Query( $args );
if( $my_posts->have_posts() ): while ( $my_posts->have_posts() ) : $my_posts->the_post();
global $post;
if ($meta_url != '') $post_url = get_post_meta($post->ID, $meta_url, true);
?>
<div class="article clear">
<?php if (has_post_thumbnail()) { if ($detailpg == 'true') { echo '<a href="'; the_permalink(); echo '">'; } else if ($post_url) { ?><a href="http://<?php echo $post_url; ?>" rel="bookmark" target="_blank"><?php } ?><div class="thumb_image"><?php the_post_thumbnail($thumbsize); ?></div><?php if (($detailpg == 'true') || $post_url) { echo '</a>'; } } ?>
<div class="entry-content <?php if (!has_post_thumbnail()) { echo 'no-thumb'; }?>">
<h3><?php if ($post_url) { ?><a href="http://<?php echo $post_url; ?>" rel="bookmark" target="_blank"><?php } else if ($detailpg == 'true') { echo '<a href="'; the_permalink(); echo '">'; } the_title(); if ($inc_date == 'true') { echo ' - '; the_time('F d, Y'); } if ($post_url || $detailpg == 'true') { ?></a><?php } ?></h3>
<?php the_content(); ?>
</div>
</div>
<?php endwhile; else: ?> <br /><h2><?php _e('Sorry, no posts matched your criteria.'); ?></h2> <?php endif; ?>
<?php if (function_exists('wp_pagenavi') ) { ?>
<?php wp_pagenavi(); ?>
<?php } else { ?>
<nav id="nav-below">
<p class="screen-reader-text"><?php _e( 'Post navigation', 'env' ); ?></p>
<div class="nav-previous"><?php next_posts_link( __( 'Older posts', 'env' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts', 'env' ) ); ?></div>
</nav>
<?php }
wp_reset_postdata();
}
/*** Function for displaying 3 posts from a custom type in a short feed, no pagination */
function env_display_excerpt_feed_from_type($the_type, $the_order, $the_number = 3, $orderby = 'date', $status = 'publish')
{
$args = array(
'post_type' => $the_type,
'posts_per_page' => $the_number,
'orderby' => $orderby,
'order' => $the_order,
'post_status' => $status
);
$my_posts = new WP_Query( $args );
if( $my_posts->have_posts() ): while ( $my_posts->have_posts() ) : $my_posts->the_post();
global $post;
?>
<div class="post_items">
<div class="post_item_date"><?php the_time('m.d.y') ?></div>
<div class="post_item_content">
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<?php if ($the_type!='resources') { env_excerpt('env_excerptlength_home'); } ?>
</div><!--post_item_content-->
<div class="clear"></div>
</div><!--post_items-->
<?php endwhile; endif;
wp_reset_postdata();
}
/*** Function for displaying 3 posts from a custom type in a short feed, no pagination */
function env_display_feed_from_types($the_type, $the_order, $the_number = 3, $orderby = 'date', $status = 'publish')
{
$args = array(
'post_type' => ($the_type),
'posts_per_page' => $the_number,
'orderby' => $orderby,
'order' => $the_order,
'post_status' => ($status),
'meta_query' => array(
array(
'key' => '_home_feat',
'value' => 'on'
)
)
);
$my_posts = new WP_Query( $args );
if( $my_posts->have_posts() ):
echo '<ul class="short_feed">';
while ( $my_posts->have_posts() ) : $my_posts->the_post();
global $post;
if (get_post_type($post->ID) == "ai1ec_event") { $ptype = "event"; $event = Ai1ec_Events_Helper::get_event($post->ID); } else if (get_post_type($post->ID) == "news") { $ptype = "news"; } else { $ptype = "blog"; } ?>
<li class="post_items clear">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/feat_<?php echo $ptype; ?>.jpg" alt="<?php echo $ptype; ?>" />
<div class="p_data">
<a href="<?php the_permalink() ?>" class="p_title"><span><?php the_title(); ?> |</span> <?php if ($ptype == "event") { echo $event->long_start_date; } else { the_time('m.d.y'); } ?></a>
<?php the_excerpt(); ?>
</div>
</li><!--post_items-->
<?php endwhile; ?>
</ul>
<?php endif; wp_reset_postdata();
}
/*** Function for displaying 3 posts from a custom type in a short feed, no pagination
function env_display_feed_from_types($the_type, $the_order, $the_number = 3, $orderby = 'date', $status = 'publish')
{
$args = array(
'post_type' => ($the_type),
'posts_per_page' => $the_number,
'order' => $the_order,
'post_status' => ($status),
'meta_query' => array(
array(
'key' => '_home_feat',
'value' => 'on'
),
array(
'key' => '_post_date_meta'
)
),
'meta_key' => '_post_date_meta',
'orderby' => 'meta_value_num'
);
$my_posts = new WP_Query( $args );
if( $my_posts->have_posts() ):
echo '<ul class="short_feed">';
while ( $my_posts->have_posts() ) : $my_posts->the_post();
global $post;
if (get_post_type($post->ID) == "ai1ec_event") { $ptype = "event"; $event = Ai1ec_Events_Helper::get_event($post->ID); } else if (get_post_type($post->ID) == "news") { $ptype = "news"; } else { $ptype = "blog"; } ?>
<li class="post_items clear">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/feat_<?php echo $ptype; ?>.jpg" alt="<?php echo $ptype; ?>" />
<div class="p_data">
<a href="<?php the_permalink() ?>" class="p_title"><span><?php the_title(); ?> |</span> <?php if ($ptype == "event") { echo $event->long_start_date; } else { the_time('m.d.y'); } ?></a>
<?php the_excerpt(); ?>
</div>
</li><!--post_items-->
<?php endwhile; ?>
</ul>
<?php endif; wp_reset_postdata();
}
*/
/* Display featured post at top of feed */
function env_display_featured_post($the_type, $meta_key, $thumbsize='', $post_status = 'publish')
{
$args = array(
'orderby' => 'date',
'order' => ASC,
'posts_per_page' => 1,
'post_type' => $the_type,
'meta_query' => array(
array(
'key' => $meta_key,
'value' => 'on'
)
),
'post_status' => $post_status
);
$my_posts = new WP_Query( $args );
if( $my_posts->have_posts() ): while ( $my_posts->have_posts() ) : $my_posts->the_post();
global $post;
?>
<div class="featured_post clear">
<h2>Featured:</h2>
<div id="feat">
<?php if (has_post_thumbnail()) { ?><div class="thumb_image"><?php the_post_thumbnail($thumbsize); ?></div><?php } ?>
<div class="entry-content <?php if (!has_post_thumbnail()) { echo 'full-width'; }?>">
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?> - <?php the_time('F d, Y'); ?></a></h3>
<?php the_content(); ?>
</div>
</div><!--feat-->
</div>
<?php endwhile;
endif; wp_reset_postdata();
}
/*** Display list of posts, function must go inside of a list tag */
function env_list_my_post_links($the_type, $the_num, $the_order, $orderby = 'date')
{
$args = array(
'post_type' => $the_type,
'posts_per_page' => $the_num,
'orderby' => $orderby,
'order' => $the_order
);
$the_query = new WP_Query($args);
if ($the_query->have_posts()): while ($the_query->have_posts()) : $the_query->the_post();
global $post;
?>
<li><a href="<?php the_permalink() ?>"><span><?php the_title(); ?></span></a></li>
<?php endwhile; endif;
}
/* ------------ end of Display Functions ------------ */
function get_the_slug($the_id) {
global $post;
if ( is_single($the_id) || is_page($the_id)) {
return $post->post_name;
}
else {
return "";
}
}
function register( $atts, $content = null ) {
return '<a href="http://' .$content.'" target="_blank" class="reg_button">Register</a>';
}
add_shortcode("register", "register");
function load( $atts, $content = null ) {
return '<div class="downld_button">' .$content.'</div>';
}
add_shortcode("download", "download");
function number_feed() {
$ProductLaunch2012 = "2012-01-01 00:00";
$TimeNow = date("F j, Y, g:i a");
$diff = abs(strtotime($TimeNow) - strtotime($ProductLaunch2012));
$minutes = floor($diff/60);
$fusetotalsincejan2012 = floor($minutes*0.3);
$totalfusetodate = $fusetotalsincejan2012+219235;
$str = "$totalfusetodate";
$numbers = str_split($str);
$images = array();
$base_url = get_bloginfo('stylesheet_directory');
foreach($numbers as $number)
{
$images[] = '<img src="' . $base_url . '/images/num_' . $number . '.png" />';
}
$images_string = implode($images);
echo $images_string;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment