/** * Add a shortcode for svg icons */ function keel_svg_shortcode($atts) { // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['svg_shortcode']) { return ''; } // Get user options $svg = shortcode_atts(array('id' => '', 'url' => '', 'class' => ''), $atts); // Bail if no link or label is set if (empty($svg['id']) && empty($svg['url'])) { return; } // Get SVG url $img = $svg['url']; if (empty($img)) { $img = wp_get_attachment_image_src($svg['id']); } // Get SVG content and add classes $file = @file_get_contents($img); if (empty($file)) { return; } if (!empty($svg['class'])) { $file = str_replace('<svg', '<svg class="' . $svg['class'] . '"', $file); } // Return SVG contents return $file; }
function keel_set_page_width_box() { // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['page_width']) { return; } add_meta_box('keel_set_page_width_checkbox', 'Page Width & Header', 'keel_set_page_width_checkbox', 'page', 'side', 'default'); }
function keel_theme_support_add_page() { // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['theme_support']) { return; } $theme_page = add_submenu_page('themes.php', __('Theme Support', 'keel'), __('Theme Support', 'keel'), 'edit_theme_options', 'keel_theme_support', 'keel_theme_support_render_page'); }
/** * Custom Logo * @link http://kwight.ca/2012/12/02/adding-a-logo-uploader-to-your-wordpress-site-with-the-theme-customizer/ * @link http://ottopress.com/tag/customizer/ */ function keel_add_custom_logo_support($wp_customize) { // Check if activated $dev_options = keel_developer_options(); if (!$dev_options['custom_logo']) { return; } $wp_customize->add_section('keel_logo_section', array('title' => __('Logo', 'keel'), 'priority' => 30, 'description' => 'Upload a logo to replace the default site name and description in the header')); $wp_customize->add_setting('keel_logo'); $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'keel_logo', array('label' => __('Logo', 'keel'), 'section' => 'keel_logo_section', 'settings' => 'keel_logo'))); }
function keel_pet_listings_add_custom_post_type() { // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['pets']) { return; } $options = keel_pet_listings_get_theme_options(); $labels = array('name' => _x('Pets', 'post type general name', 'keel'), 'singular_name' => _x('Pet', 'post type singular name', 'keel'), 'add_new' => _x('Add New', 'course', 'keel'), 'add_new_item' => __('Add New Pet', 'keel'), 'edit_item' => __('Edit Pet', 'keel'), 'new_item' => __('New Pet', 'keel'), 'all_items' => __('All Pets', 'keel'), 'view_item' => __('View Pet', 'keel'), 'search_items' => __('Search Pets', 'keel'), 'not_found' => __('No pets found', 'keel'), 'not_found_in_trash' => __('No pets found in the Trash', 'keel'), 'parent_item_colon' => '', 'menu_name' => __('Pet Listings', 'keel')); $args = array('labels' => $labels, 'description' => 'Holds our pets and pet-specific data from Petfinder', 'public' => true, 'menu_icon' => 'dashicons-screenoptions', 'has_archive' => true, 'rewrite' => array('slug' => $options['slug']), 'map_meta_cap' => true, 'capabilities' => array('create_posts' => false, 'edit_published_posts' => false, 'delete_posts' => false, 'delete_published_posts' => false)); register_post_type('pets', $args); }
/** * Add a shortcode for button links */ function keel_button_shortcode($atts) { // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['button_shortcode']) { return ''; } // Get user options $btn = shortcode_atts(array('link' => '', 'label' => '', 'size' => ''), $atts); // Bail if no link or label is set if (empty($btn['link']) || empty($btn['label'])) { return; } return '<a class="btn btn-' . $btn['size'] . '" href="' . $btn['link'] . '">' . $btn['label'] . '</a>'; }
function keel_has_hero($post_id = null) { // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['hero']) { return false; } // Return false on blog posts if (is_home() || is_single()) { return false; } // Get the post ID global $post; $post_id = $post_id ? $post_id : $post->ID; // Get hero content $hero = keel_get_hero_content($post_id); return empty($hero['content']) && empty($hero['image']) && empty($hero['img']) ? false : true; }
/** * Render a PayPal donation button * @return string The donation button markup */ public static function render_donations_button($atts) { // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['paypal']) { return ''; } // Shortcode values $paypal = shortcode_atts(array('amount' => '', 'label' => '', 'recurring' => false, 'description' => '', 'size' => ''), $atts); // Options and settings $options = keel_paypal_donations_get_theme_options(); // If not PayPal account is provided, do nothing if (empty($options['email'])) { return; } // Variables $amount = ltrim($paypal['amount'], '$ £'); $label = empty($paypal['label']) ? $options['currency'] . $amount : $paypal['label']; $recurring = empty($paypal['recurring']) ? '' : '<input type="hidden" name="paypal_donations_button_recurring" value="true">'; $description = empty($paypal['description']) ? '' : '<input type="hidden" name="paypal_donations_button_description" value="' . $paypal['description'] . '">'; $form = '<form class="paypal-donations-button" id="paypal-donations-table-' . $amount . '" name="paypal-donations-table" action="" method="post">' . '<input type="hidden" name="paypal_donations_button_amount" value="' . $amount . '">' . $recurring . $description . wp_nonce_field('keel_paypal_donations_button_nonce', 'keel_paypal_donations_button_process') . '<button class="btn btn-' . $paypal['size'] . '">' . $label . '</button>' . '</form>'; return $form; }
function keel_pet_listings_theme_options_add_page() { // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['pets']) { return; } // $theme_page = add_menu_page( __( 'Theme Options', 'keel' ), __( 'Theme Options', 'keel' ), 'edit_theme_options', 'keel_pet_listings_theme_options', 'keel_pet_listings_theme_options_render_page' ); $theme_page = add_submenu_page('edit.php?post_type=pets', __('Pet Listings Options', 'keel'), __('Options', 'keel'), 'edit_theme_options', 'keel_pet_listings_theme_options', 'keel_pet_listings_theme_options_render_page'); }
function keel_add_page_hero_scripts($hook) { // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['hero']) { return; } global $typenow; if (in_array($typenow, array('page', 'post'))) { wp_enqueue_media(); // Registers and enqueues the required javascript. wp_register_script('meta-box-image', get_template_directory_uri() . '/includes/keel-page-hero/keel-page-hero.js', array('jquery')); wp_localize_script('meta-box-image', 'meta_image', array('title' => __('Choose or Upload an Image', 'keel'), 'button' => __('Use this image', 'keel'))); wp_enqueue_script('meta-box-image'); } }
function keel_photoswipe_theme_options_add_page() { // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['gallery']) { return; } $theme_page = add_submenu_page('upload.php', 'Photo Galleries', 'Photo Galleries', 'edit_theme_options', 'keel_photoswipe_theme_options', 'keel_photoswipe_theme_options_render_page'); }
/** * Override default [gallery] shortcode * @link http://robido.com/wordpress/wordpress-gallery-filter-to-modify-the-html-output-of-the-default-gallery-shortcode-and-style/address>]> * @param String $output Default [gallery] output * @param Array $attr Settings and options * @return String New markup */ function keel_photoswipe_gallery($output, $attr) { // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['gallery']) { return; } // Initialize global $post; // Only run if PhotoSwipe galleries are activated $options = keel_photoswipe_get_theme_options(); if ($options['activate'] === 'off') { return; } // Gallery instance counter static $instance = 0; $instance++; // Validate the author's orderby attribute if (isset($attr['orderby'])) { $attr['orderby'] = sanitize_sql_orderby($attr['orderby']); if (!$attr['orderby']) { unset($attr['orderby']); } } // Get attributes from shortcode extract(shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'include' => '', 'exclude' => ''), $attr)); // Initialize $id = intval($id); $attachments = array(); if ($order == 'RAND') { $orderby = 'none'; } if (!empty($include)) { // Include attribute is present $include = preg_replace('/[^0-9,]+/', '', $include); $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); // Setup attachments array foreach ($_attachments as $key => $val) { $attachments[$val->ID] = $_attachments[$key]; } } else { if (!empty($exclude)) { // Exclude attribute is present $exclude = preg_replace('/[^0-9,]+/', '', $exclude); // Setup attachments array $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); } else { // Setup attachments array $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 ''; } // Filter gallery differently for feeds if (is_feed()) { $output = "\n"; foreach ($attachments as $att_id => $attachment) { $output .= wp_get_attachment_link($att_id, 'medium', true) . "\n"; } return $output; } // Set grid width based on number of images $count = count($attachments); if ($count === 1) { $grid = 'full'; } elseif ($count === 2) { $grid = 'half'; } else { $grid = 'dynamic'; } // Generate gallery $gallery = '<div data-photoswipe data-pswp-uid="' . $instance . '" class="row" data-masonry>'; foreach ($attachments as $id => $attachment) { // Image data $img_full = wp_get_attachment_image_src($id, 'full'); $img_medium = wp_get_attachment_image_src($id, 'medium'); $img = wp_get_attachment_image($id, 'medium', 0, array('class' => 'img-photo')); $caption = $attachment->post_excerpt; $figure = empty($caption) ? '' : '<figure hidden>' . $caption . '</figure>'; $gallery .= '<a data-size="' . $img_full[1] . 'x' . $img_full[2] . '" data-med="' . $img_medium[0] . '" data-med-size="' . $img_medium[1] . 'x' . $img_medium[2] . '" href="' . $img_full[0] . '" class="grid-' . $grid . '" data-masonry-content>' . $img . $figure . '</a>'; } $gallery .= '</div>'; $ps_framework = '<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">' . '<div class="pswp__bg"></div>' . '<div class="pswp__scroll-wrap">' . '<div class="pswp__container">' . '<div class="pswp__item"></div>' . '<div class="pswp__item"></div>' . '<div class="pswp__item"></div>' . '</div>' . '<div class="pswp__ui pswp__ui--hidden">' . '<div class="pswp__top-bar">' . '<div class="pswp__counter"></div>' . '<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>' . '<button class="pswp__button pswp__button--share" title="Share"></button>' . '<button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>' . '<button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>' . '<div class="pswp__preloader">' . '<div class="pswp__preloader__icn">' . '<div class="pswp__preloader__cut">' . '<div class="pswp__preloader__donut"></div>' . '</div>' . '</div>' . '</div>' . '</div>' . '<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">' . '<div class="pswp__share-tooltip"></div>' . '</div>' . '<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button>' . '<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button>' . '<div class="pswp__caption">' . '<div class="pswp__caption__center"></div>' . '</div>' . '</div>' . '</div>' . '</div>'; return $gallery . $ps_framework; }
function keel_paypal_donations_theme_options_add_page() { // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['paypal']) { return ''; } $theme_page = add_menu_page(__('PayPal Donations', 'keel'), __('PayPal Donations', 'keel'), 'edit_theme_options', 'keel_paypal_donations_theme_options', 'keel_paypal_donations_theme_options_render_page', 'dashicons-heart'); // $theme_page = add_submenu_page( 'tools.php', __( 'Theme Options', 'keel' ), __( 'Theme Options', 'keel' ), 'edit_theme_options', 'keel_paypal_donations_theme_options', 'keel_paypal_donations_theme_options_render_page' ); }
function keel_get_hero($post_id = null) { // Get the post ID global $post; $post_id = $post_id ? $post_id : $post->ID; // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['hero']) { return false; } // Get hero $hero = keel_get_hero_content($post_id); $page_header = get_post_meta($post->ID, 'keel_page_header', true); // If no hero, bail if (empty($hero['content']) && empty($hero['image']) && empty($hero['img'])) { return; } // Get hero image $check_image = wp_check_filetype($hero['image']); $image = strpos($check_image['type'], 'image') === false ? wp_oembed_get($hero['image']) : '<img src="' . $hero['image'] . '">'; $overlay = '0, 0, 0'; $transparency = '0.7'; $min_height = empty($hero['min_height']) ? '' : 'min-height: ' . $hero['min_height'] . '; '; ?> <header class="bg-hero <?php echo empty($hero['img']) ? 'bg-muted' : 'bg-dark text-shadow'; ?> margin-bottom" <?php if (!empty($hero['img'])) { echo 'style="' . (empty($hero['min_height']) ? '' : 'min-height: ' . $hero['min_height'] . '; ') . 'background-image: ' . (empty($hero['overlay']) ? '' : 'linear-gradient( rgba(' . $overlay . ', ' . $transparency . '), rgba(' . $overlay . ', ' . $transparency . ') ),') . ' url(' . $hero['img'][0] . ');"'; } ?> > <div class="container <?php if (!empty($hero['content']) && !empty($image)) { echo 'container-large'; } ?> <?php echo !empty($hero['img']) && is_array($hero['img']) && (empty($hero['content']) || empty($image)) ? 'padding-top-xlarge padding-bottom-xlarge' : 'padding-top padding-bottom'; ?> "> <?php // If there's hero content AND video if (!empty($hero['content']) && !empty($hero['image'])) { ?> <div class="row text-center"> <div class="grid-half text-left-large"> <?php if ($page_header !== 'on') { ?> <h1><?php the_title(); ?> </h1> <?php } ?> <?php echo do_shortcode($hero['content']); ?> </div> <div class="grid-half grid-flip margin-bottom"> <?php echo $image; ?> </div> </div> <?php // If there's hero content, but no video // OR, if there's video, but no content } elseif (!empty($hero['content']) || !empty($hero['image'])) { ?> <div class="text-center"> <?php if ($page_header !== 'on') { ?> <h1><?php the_title(); ?> </h1> <?php } ?> <?php echo do_shortcode($hero['content']); ?> <?php echo $image; ?> </div> <?php // If there's no content or video } else { ?> <h1 class="text-center"><?php the_title(); ?> </h1> <?php } ?> </div> </header> <?php }
<?php /** * content.php * Template for post content. */ // Get post options $options = keel_get_post_options(); $dev_options = keel_developer_options(); ?> <article <?php if (is_single()) { echo 'class="container"'; } ?> > <header> <?php /** * Headers * Unlinked h1 for invidual blog posts. Linked h1 for collections of posts. */ ?> <h1 class="no-margin-bottom"> <?php if (is_single()) { ?> <?php
function keel_post_options_add_page() { // add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function ); // add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function ); // add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function ); // $page_title - Name of page // $menu_title - Label in menu // $capability - Capability required // $menu_slug - Used to uniquely identify the page // $function - Function that renders the options page // $theme_page = add_theme_page( __( 'Post Options', 'keel' ), __( 'Post Options', 'keel' ), 'edit_theme_options', 'keel_post_options', 'keel_post_options_render_page' ); // Developer options $dev_options = keel_developer_options(); // $theme_page = add_menu_page( __( 'Theme Options', 'keel' ), __( 'Theme Options', 'keel' ), 'edit_theme_options', 'keel_post_options', 'keel_post_options_render_page' ); if ($dev_options['disable_comments'] || $dev_options['post_cta']) { $theme_page = add_submenu_page('edit.php', __('Post Options', 'keel'), __('Post Options', 'keel'), 'edit_theme_options', 'keel_post_options', 'keel_post_options_render_page'); } }
function keel_theme_options_init() { // Developer Options $dev_options = keel_developer_options(); // Register a setting and its sanitization callback // register_setting( $option_group, $option_name, $sanitize_callback ); // $option_group - A settings group name. // $option_name - The name of an option to sanitize and save. // $sanitize_callback - A callback function that sanitizes the option's value. register_setting('keel_theme_options', 'keel_theme_options', 'keel_theme_options_validate'); // Register our settings field group // add_settings_section( $id, $title, $callback, $page ); // $id - Unique identifier for the settings section // $title - Section title // $callback - // Section callback (we don't want anything) // $page - // Menu slug, used to uniquely identify the page. See keel_theme_options_add_page(). if ($dev_options['fonts']) { add_settings_section('fonts', 'Fonts', '__return_false', 'keel_theme_options'); } if ($dev_options['social']) { add_settings_section('social', 'Social Media Accounts', '__return_false', 'keel_theme_options'); } if ($dev_options['footer']) { add_settings_section('footer', 'Footer Content', '__return_false', 'keel_theme_options'); } // Register our individual settings fields // add_settings_field( $id, $title, $callback, $page, $section ); // $id - Unique identifier for the field. // $title - Setting field title. // $callback - Function that creates the field (from the Theme Option Fields section). // $page - The menu page on which to display this field. // $section - The section of the settings page in which to show the field. // Fonts add_settings_field('typeface', __('Typeface', 'keel'), 'keel_settings_field_style_typeface', 'keel_theme_options', 'fonts'); // Social add_settings_field('facebook', __('Facebook', 'keel'), 'keel_settings_field_social_facebook', 'keel_theme_options', 'social'); add_settings_field('twitter', __('Twitter', 'keel'), 'keel_settings_field_social_twitter', 'keel_theme_options', 'social'); add_settings_field('youtube', __('YouTube', 'keel'), 'keel_settings_field_social_youtube', 'keel_theme_options', 'social'); add_settings_field('google', __('Google+', 'keel'), 'keel_settings_field_social_google', 'keel_theme_options', 'social'); add_settings_field('instagram', __('Instagram', 'keel'), 'keel_settings_field_social_instagram', 'keel_theme_options', 'social'); add_settings_field('pinterest', __('Pinterest', 'keel'), 'keel_settings_field_social_pinterest', 'keel_theme_options', 'social'); add_settings_field('flickr', __('Flickr', 'keel'), 'keel_settings_field_social_flickr', 'keel_theme_options', 'social'); add_settings_field('newsletter', __('Newsletter', 'keel'), 'keel_settings_field_social_newsletter', 'keel_theme_options', 'social'); // Footer add_settings_field('footer1', __('Footer 1', 'keel'), 'keel_settings_field_footer_content_1', 'keel_theme_options', 'footer'); add_settings_field('footer2', __('Footer 2', 'keel'), 'keel_settings_field_footer_content_2', 'keel_theme_options', 'footer'); }