From: Laury GvR Date: Wed, 5 Oct 2016 21:11:11 +0000 (-0400) Subject: Functions.php reorganised, now like scss X-Git-Tag: v1.0.0^2~188 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=224d5b8f271ec6f63aec8168f998cdda0eda6f64;p=WP-Themes%2Fbaragacounty.git Functions.php reorganised, now like scss All the functions are now in their separate, sensible files, like we've done with our scss. All these files are include_once()'d in functions.php. --- diff --git a/functions.php b/functions.php index 5e25ff7..bf02d9c 100644 --- a/functions.php +++ b/functions.php @@ -1,328 +1,12 @@ __('Slideshow'), - 'id' => 'slideshow', - 'description' => __('Meta Slider/Slideshow Area') - )); - register_sidebar(array( - 'name' => __('Right Sidebar'), - 'id' => 'r-sidebar', - 'description' => __('General Sidebar') - )); - register_sidebar(array( - 'name' => __('Chamber Sidebar'), - 'id' => 'chamber-side', - 'description' => __('Sidebar for the Chamber Page') - )); - } - -} - -/** - * Return the client info option for the given key - * - * @param type $name Name of the client info option to return - * - * @return string Option - */ -if (!function_exists('glm_get_clientinfo_option')) { - function glm_get_clientinfo_option($name) - { - $settings = get_option('glmclientinfo_settings'); - $states = get_option('glmclientinfo_states'); - if ($name == 'stateFull' && $settings['state']) { - return $states[$settings['state']]; - } - if ($name == 'state2Full' && $settings['state2']) { - return $states[$settings['state2']]; - } - return ($settings && $settings[$name]) - ? $settings[$name] - : null; - } -} -add_theme_support('custom-fieldss'); -add_theme_support('post-thumbnails'); -set_post_thumbnail_size(120, 100, true); -add_post_type_support("page", 'excerpt'); -/** - * glm_site_scripts - * - * Add the scripts that we'll need for any home page stuff - */ -function glm_site_scripts() -{ -// wp_enqueue_script( -// 'modernizr', -// get_template_directory_uri() . '/js/modernizr/modernizr.min.js' -// ); - wp_enqueue_script('jquery'); - wp_enqueue_script( - 'glm_foundation', - get_template_directory_uri() . '/js/app.js', - 'jquery', - '1.0', - true - ); - if(is_front_page()) { - } -} - - -/* Header for posts*/ -function glm_get_header() { - echo ''; - echo ''; - echo '
'; - echo '
'; - echo '
'; - echo '
'; -} - -// // The code below is useful when you want the image to resize to -// if (has_post_thumbnail()) { -// $image_data = wp_get_attachment_image_src(get_post_thumbnail_id(), "full"); -// echo ''; -// } else { -// echo ''; -// } -// echo '
'; -// echo '
'; -// echo '
'; -// echo '
'; - -add_action('wp_enqueue_scripts', 'glm_site_scripts'); - - -// Start of the Contextual/Highlight Search functions -function mytheme_init() { - remove_action('thematic_searchloop', 'thematic_search_loop'); -} - -add_action('init', 'mytheme_init', 10); - -function wpse_setup_theme() { - add_image_size('glm-block-image', 339, 507,true); - add_image_size('dropdown-image', 270, 122, true); - add_image_size('map-image', 200, 150, true); -} - -add_action( 'after_setup_theme', 'wpse_setup_theme' ); -function mytheme_search_loop() { - while ( have_posts() ) : the_post(); ?> - -
- -
- - -
- -
- - post->ID)) return true; - return false; -} - -add_action('thematic_searchloop', 'mytheme_search_loop'); -// End of the Contextual/Highlight Search functions - -// This series of functions is used for forcing a template if one or any is picked. -// START FORCE TEMPLATE FUNCTIONS -add_filter( 'template_include', 'glm_force_template', 99 ); -function glm_force_template( $template ) { - if ($template != locate_template("woocommerce.php")) { - $template = locate_template( "index.php" ); - } - return $template; -} -function get_custom_page_templates() { - $templates = array(); - // maybe by options? --> $templates = get_option( 'custom_page_templates' ); - // maybe by conf file? --> $templates = include 'custom_page_templates.php'; - return apply_filters( 'custom_page_templates', $templates ); -} -add_action( 'edit_form_after_editor', 'custom_page_templates_init' ); -add_action( 'load-post.php', 'custom_page_templates_init_post' ); -add_action( 'load-post-new.php', 'custom_page_templates_init_post' ); - -function custom_page_templates_init() { - remove_action( current_filter(), __FUNCTION__ ); - if ( is_admin() && get_current_screen()->post_type === 'page' ) { - $templates = get_custom_page_templates(); // the function above - if ( ! empty( $templates ) ) { - set_custom_page_templates( $templates ); - } - } -} -function custom_page_templates_init_post() { - remove_action( current_filter(), __FUNCTION__ ); - $method = filter_input( INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_STRING ); - if ( empty( $method ) || strtoupper( $method ) !== 'POST' ) return; - if ( get_current_screen()->post_type === 'page' ) { - custom_page_templates_init(); - } -} -function set_custom_page_templates( $templates = array() ) { - if ( ! is_array( $templates ) || empty( $templates ) ) return; - $core = array_flip( (array) get_page_templates() ); // templates defined by file - $data = array_filter( array_merge( $core, $templates ) ); - ksort( $data ); - $stylesheet = get_stylesheet(); - $hash = md5( get_theme_root( $stylesheet ) . '/' . $stylesheet ); - $persistently = apply_filters( 'wp_cache_themes_persistently', false, 'WP_Theme' ); - $exp = is_int( $persistently ) ? $persistently : 1800; - wp_cache_set( 'page_templates-' . $hash, $data, 'themes', $exp ); -} -add_filter( 'custom_page_templates', function( $now_templates ) { - // Any slug->name pairs down here will be selectable in the admin side of - // a page. You do not need to create a new template file. You can refer to - // this template by its slug in our index.php using get_page_template_slug - // Below are some commented examples of custom quasi-templates. - $templates = array( - 'page-chamber' => 'Chamber Page', - 'no-sidebar' => 'No Sidebar' - // 'any-template-slug' => 'Sample Template' , - ); - - return array_merge( $now_templates, $templates ); -} ); -// END FORCE TEMPLATE FUNCTIONS - - -// THIS IS HOW IT CAN BE USED IN INDEX.PHP -// if (get_page_template_slug( $post->ID ) == "some-custom-page-template") { -// echo "
[I am totally not a block ._.]
"; -// } else { -// echo "

The current template used is:".get_page_template_slug( $post->ID )."

"; -// } - -/* - * This function returns true when the current page is the page given by ID - * or a descendent thereof. - */ -if (!function_exists('is_in_tree')) { - function is_in_tree( $pid ) { - global $post; - if ( is_page($pid) ) { - return true; - } - $anc = get_post_ancestors( $post->ID ); - foreach ( $anc as $ancestor ) { - if( is_page() && $ancestor == $pid ) { - return true; - } - } - return false; - } -} - -if ( ! function_exists( 'glm_members_only_menu')) { - function glm_members_only_menu() { - wp_nav_menu(array( - 'container' => false, // remove nav container - 'container_class' => 'members-only-menu', // class of container - 'menu' => '', // menu name - 'menu_class' => 'members-only-menu', // adding custom nav class - 'theme_location' => 'members-only-menu', // where it's located in the theme - 'before' => '', // before each link - 'after' => '', // after each link - 'link_before' => '', // before each link text - 'link_after' => '', // after each link text - 'depth' => 2, // limit the depth of the nav - 'fallback_cb' => false, // fallback function (see below) - 'items_wrap' => '%3$s', - 'walker' => new GLM_Members_Only_Walker() - )); - } -} - -if ( ! class_exists( 'GLM_Members_Only_Walker' ) ) : -class GLM_Members_Only_Walker extends Walker_Nav_Menu { - - function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { - $element->has_children = ! empty( $children_elements[ $element->ID ] ); - $element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : ''; - $element->classes[] = ( $element->has_children && 1 !== $max_depth ) ? 'page_item_has_children' : ''; - $element->classes[] = 'page_item'; - - parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); - } - - function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { - $item_html = ''; - parent::start_el( $item_html, $object, $depth, $args ); - - $classes = empty( $object->classes ) ? array() : (array) $object->classes; - - if ( in_array( 'label', $classes ) ) { - $item_html = preg_replace( '/]*>(.*)<\/a>/iU', '', $item_html ); - } - - $output .= $item_html; - } - - function start_lvl( &$output, $depth = 0, $args = array() ) { - $output .= "\n
    \n"; - } - - function end_lvl(&$output, $depth = 0, $args = array()){ - $output .= '
'; - } - -} -endif; - -function remove_billing_fields( $fields ) { - global $woocommerce; - // if the total is more than 0 then we still need the fields - if ( 0 != $woocommerce->cart->total ) { - return $fields; - } - // return the regular billing fields if we need shipping fields - if ( $woocommerce->cart->needs_shipping() ) { - return $fields; - } - // we don't need the billing fields so empty all of them except the email - unset( $fields['billing_country'] ); - unset( $fields['billing_first_name'] ); - unset( $fields['billing_last_name'] ); - unset( $fields['billing_company'] ); - unset( $fields['billing_address_1'] ); - unset( $fields['billing_address_2'] ); - unset( $fields['billing_city'] ); - unset( $fields['billing_state'] ); - unset( $fields['billing_postcode'] ); - unset( $fields['billing_phone'] ); - unset( $fields['billing_email'] ); - return $fields; -} - + require_once 'lib/defines.php'; + require_once 'lib/menu-walker.php'; + require_once 'lib/navigation.php'; + include_once 'lib/images.php'; + include_once 'lib/header.php'; + include_once 'lib/misc.php'; + include_once 'lib/widgets.php'; + include_once 'lib/enqueueing.php'; + include_once 'lib/images.php'; + include_once 'lib/plugins.php'; ?> \ No newline at end of file diff --git a/lib/defines.php b/lib/defines.php new file mode 100644 index 0000000..42d6251 --- /dev/null +++ b/lib/defines.php @@ -0,0 +1,7 @@ +ID ) == "some-custom-page-template") { +// echo "
[I am totally not a block ._.]
"; +// } else { +// echo "

The current template used is:".get_page_template_slug( $post->ID )."

"; +// } + +add_filter( 'template_include', 'glm_force_template', 99 ); +function glm_force_template( $template ) { + if ($template != locate_template("woocommerce.php")) { + $template = locate_template( "index.php" ); + } + return $template; +} +function get_custom_page_templates() { + $templates = array(); + // maybe by options? --> $templates = get_option( 'custom_page_templates' ); + // maybe by conf file? --> $templates = include 'custom_page_templates.php'; + return apply_filters( 'custom_page_templates', $templates ); +} +add_action( 'edit_form_after_editor', 'custom_page_templates_init' ); +add_action( 'load-post.php', 'custom_page_templates_init_post' ); +add_action( 'load-post-new.php', 'custom_page_templates_init_post' ); + +function custom_page_templates_init() { + remove_action( current_filter(), __FUNCTION__ ); + if ( is_admin() && get_current_screen()->post_type === 'page' ) { + $templates = get_custom_page_templates(); // the function above + if ( ! empty( $templates ) ) { + set_custom_page_templates( $templates ); + } + } +} +function custom_page_templates_init_post() { + remove_action( current_filter(), __FUNCTION__ ); + $method = filter_input( INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_STRING ); + if ( empty( $method ) || strtoupper( $method ) !== 'POST' ) return; + if ( get_current_screen()->post_type === 'page' ) { + custom_page_templates_init(); + } +} +function set_custom_page_templates( $templates = array() ) { + if ( ! is_array( $templates ) || empty( $templates ) ) return; + $core = array_flip( (array) get_page_templates() ); // templates defined by file + $data = array_filter( array_merge( $core, $templates ) ); + ksort( $data ); + $stylesheet = get_stylesheet(); + $hash = md5( get_theme_root( $stylesheet ) . '/' . $stylesheet ); + $persistently = apply_filters( 'wp_cache_themes_persistently', false, 'WP_Theme' ); + $exp = is_int( $persistently ) ? $persistently : 1800; + wp_cache_set( 'page_templates-' . $hash, $data, 'themes', $exp ); +} +add_filter( 'custom_page_templates', function( $now_templates ) { + // Any slug->name pairs down here will be selectable in the admin side of + // a page. You do not need to create a new template file. You can refer to + // this template by its slug in our index.php using get_page_template_slug + // Below are some commented examples of custom quasi-templates. + $templates = array( + 'page-chamber' => 'Chamber Page', + 'no-sidebar' => 'No Sidebar' + // 'any-template-slug' => 'Sample Template' , + ); + + return array_merge( $now_templates, $templates ); +} ); \ No newline at end of file diff --git a/lib/header.php b/lib/header.php new file mode 100644 index 0000000..5dd8d17 --- /dev/null +++ b/lib/header.php @@ -0,0 +1,18 @@ +'; + echo ''; + echo '
'; + echo '
'; + echo '
'; + echo '
'; +} \ No newline at end of file diff --git a/lib/images.php b/lib/images.php new file mode 100644 index 0000000..242e31a --- /dev/null +++ b/lib/images.php @@ -0,0 +1,11 @@ +TEST IS TRUE
"; +} + +if (!function_exists('glm_get_clientinfo_option')) { + function glm_get_clientinfo_option($name) + { + $settings = get_option('glmclientinfo_settings'); + $states = get_option('glmclientinfo_states'); + if ($name == 'stateFull' && $settings['state']) { + return $states[$settings['state']]; + } + if ($name == 'state2Full' && $settings['state2']) { + return $states[$settings['state2']]; + } + return ($settings && $settings[$name]) + ? $settings[$name] + : null; + } +} + +/** + * Helper function to determine post type easily + * @global type $wp_query + * @param type $type + * @return boolean + */ +function is_post_type($type){ + global $wp_query; + if($type == get_post_type($wp_query->post->ID)) return true; + return false; +} + +/* + * This function returns true when the current page is the page given by ID + * or a descendent thereof. + */ +if (!function_exists('is_in_tree')) { + function is_in_tree( $pid ) { + global $post; + if ( is_page($pid) ) { + return true; + } + $anc = get_post_ancestors( $post->ID ); + foreach ( $anc as $ancestor ) { + if( is_page() && $ancestor == $pid ) { + return true; + } + } + return false; + } +} + +// Start of the Contextual/Highlight Search functions +function mytheme_init() { + remove_action('thematic_searchloop', 'thematic_search_loop'); +} + +add_action('init', 'mytheme_init', 10); + +function mytheme_search_loop() { + while ( have_posts() ) : the_post(); ?> + +
+ +
+ + +
+ +
+ + has_children = ! empty( $children_elements[ $element->ID ] ); + $element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : ''; + $element->classes[] = ( $element->has_children && 1 !== $max_depth ) ? 'page_item_has_children' : ''; + $element->classes[] = 'page_item'; + + parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); + } + + function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { + $item_html = ''; + parent::start_el( $item_html, $object, $depth, $args ); + + $classes = empty( $object->classes ) ? array() : (array) $object->classes; + + if ( in_array( 'label', $classes ) ) { + $item_html = preg_replace( '/]*>(.*)<\/a>/iU', '', $item_html ); + } + + $output .= $item_html; + } + + function start_lvl( &$output, $depth = 0, $args = array() ) { + $output .= "\n
    \n"; + } + + function end_lvl(&$output, $depth = 0, $args = array()){ + $output .= '
'; + } + +} +endif; + + +if ( ! function_exists( 'glm_members_only_menu')) { + function glm_members_only_menu() { + wp_nav_menu(array( + 'container' => false, // remove nav container + 'container_class' => 'members-only-menu', // class of container + 'menu' => '', // menu name + 'menu_class' => 'members-only-menu', // adding custom nav class + 'theme_location' => 'members-only-menu', // where it's located in the theme + 'before' => '', // before each link + 'after' => '', // after each link + 'link_before' => '', // before each link text + 'link_after' => '', // after each link text + 'depth' => 2, // limit the depth of the nav + 'fallback_cb' => false, // fallback function (see below) + 'items_wrap' => '%3$s', + 'walker' => new GLM_Members_Only_Walker() + )); + } +} \ No newline at end of file diff --git a/lib/plugins/woocommerce.php b/lib/plugins/woocommerce.php new file mode 100644 index 0000000..21acded --- /dev/null +++ b/lib/plugins/woocommerce.php @@ -0,0 +1,33 @@ +cart->total ) { + return $fields; + } + // return the regular billing fields if we need shipping fields + if ( $woocommerce->cart->needs_shipping() ) { + return $fields; + } + // we don't need the billing fields so empty all of them except the email + unset( $fields['billing_country'] ); + unset( $fields['billing_first_name'] ); + unset( $fields['billing_last_name'] ); + unset( $fields['billing_company'] ); + unset( $fields['billing_address_1'] ); + unset( $fields['billing_address_2'] ); + unset( $fields['billing_city'] ); + unset( $fields['billing_state'] ); + unset( $fields['billing_postcode'] ); + unset( $fields['billing_phone'] ); + unset( $fields['billing_email'] ); + return $fields; +} \ No newline at end of file diff --git a/lib/theme-support.php b/lib/theme-support.php new file mode 100644 index 0000000..1b7a20d --- /dev/null +++ b/lib/theme-support.php @@ -0,0 +1,5 @@ + __('Slideshow'), + 'id' => 'slideshow', + 'description' => __('Meta Slider/Slideshow Area') + )); + register_sidebar(array( + 'name' => __('Right Sidebar'), + 'id' => 'r-sidebar', + 'description' => __('General Sidebar') + )); + register_sidebar(array( + 'name' => __('Chamber Sidebar'), + 'id' => 'chamber-side', + 'description' => __('Sidebar for the Chamber Page') + )); + } + +} \ No newline at end of file