/** * CT Meta Box setup * * The actual class is included by ctfw_include_files() in framework.php. * This is done here instead of there so ctfw_theme_url() is available to use. * * @since 0.9 */ function ctfw_ctmb_setup() { if (!defined('CTMB_URL')) { // in case also used in plugin define('CTMB_URL', ctfw_theme_url(CTFW_LIB_DIR . '/ct-meta-box')); // for enqueing JS/CSS } }
/** * Responsive embeds JavaScript */ function ctfw_responsive_embeds_enqueue_scripts() { // If theme supports this feature if (current_theme_supports('ctfw-responsive-embeds')) { // FitVids.js wp_enqueue_script('fitvids', ctfw_theme_url(CTFW_JS_DIR . '/jquery.fitvids.js'), array('jquery'), CTFW_THEME_VERSION); // bust cache on theme update // Responsive embeds script wp_enqueue_script('ctfw-responsive-embeds', ctfw_theme_url(CTFW_JS_DIR . '/responsive-embeds.js'), array('fitvids'), CTFW_THEME_VERSION); // bust cache on theme update } }
/** * Enqueue admin stylesheets * * Note: CT Meta Box and other framework components handle their own stylesheets. * * @since 0.9 */ function ctfw_admin_enqueue_styles() { $screen = get_current_screen(); // Admin widgets // Framework also enqueues this for Customizer in framework/includes/customize.php if ('widgets' == $screen->base) { wp_enqueue_style('ctfw-widgets', ctfw_theme_url(CTFW_CSS_DIR . '/admin-widgets.css'), false, CTFW_THEME_VERSION); // bust cache on update } // Theme license if ('appearance_page_theme-license' == $screen->base) { wp_enqueue_style('ctfw-license', ctfw_theme_url(CTFW_CSS_DIR . '/admin-license.css'), false, CTFW_THEME_VERSION); // bust cache on update } }
/** * Enqueue Admin JavaScript * * Note: CT Meta Box and other framework components handle their own scripts. * * @since 0.9 */ function ctfw_admin_enqueue_scripts() { $screen = get_current_screen(); // Widgets JavaScript // wp_enqueue_media() is run in classes/widget.php if ('widgets' == $screen->base) { // don't enqueue unless needed // New media uploader in WP 3.5+ wp_enqueue_media(); // Main widgets script wp_enqueue_script('ctfw-admin-widgets', ctfw_theme_url(CTFW_JS_DIR . '/admin-widgets.js'), array('jquery'), CTFW_THEME_VERSION); // bust cache on update wp_localize_script('ctfw-admin-widgets', 'ctfw_widgets', ctfw_admin_widgets_js_data()); // see admin-widgets.php } }
/** * Color scheme stylesheet URL * * This can be used to enqueue the stylesheet. * * @since 0.9 * @param string $theme 'child' or 'parent' * @return string URL of color scheme stylesheet */ function ctfw_color_style_url($theme = false) { $url = ''; // Make sure active color scheme is valid so nobody tries to mess with file path (ie. via front-end style picker cookie) if (ctfw_valid_color()) { $color = ctfw_customization('color'); $color_rel = CTFW_THEME_COLOR_DIR . '/' . $color . '/style.css'; $color_parent_path = CTFW_THEME_PATH . '/' . $color_rel; $color_parent_url = CTFW_THEME_URL . '/' . $color_rel; $color_child_path = CTFW_THEME_CHILD_PATH . '/' . $color_rel; $color_child_url = CTFW_THEME_CHILD_URL . '/' . $color_rel; // Force parent version if ('parent' == $theme && file_exists($color_parent_path)) { $url = $color_parent_url; } else { if ('child' == $theme && file_exists($color_child_path)) { $url = $color_child_url; } else { $url = ctfw_theme_url($color_rel); // use child theme version if provided } } } // Return filtered return apply_filters('ctfw_color_style_url', $url, $theme); }
/** * Get preset background URL (single) * * Return preset background image URL based on filename. * * @since 0.9 * @param string $filename File name of background image * @return string Absolute URL for single background image preset */ function ctfw_background_image_preset_url($filename) { $url = ctfw_theme_url(CTFW_THEME_BG_DIR . '/' . $filename); return apply_filters('ctfw_background_image_preset_url', $url); }
/** * Unsupported Internet Explorer * * Theme can use add_theme_support( 'ctfw-ie-unsupported', 7 ) * to prompt Internet Explorer 7 users to upgrade to a modern browser. * * Note script is always loaded because caching (WP Engine, etc) can cause server-side * detection to fail (giving non-IE users the warning). * * @since 0.9 */ function ctfw_enqueue_ie_unsupported() { // Only if theme requests this $support = get_theme_support('ctfw-ie-unsupported'); if ($support) { // Default and valid version range // Currently specified version must be between 5 and 9 (10 could require more complex regex, but that may never be needed) $default_version = 7; $min_version = 5; $max_version = 9; // Get version $version = isset($support[0]) ? $support[0] : $default_version; // Check version range $version = absint($version); if ($version < $min_version || $version > $max_version) { $version = $default_version; } // Client-side JS to compare versions, alert and redirect wp_enqueue_script('ctfw-ie-unsupported', ctfw_theme_url(CTFW_JS_DIR . '/ie-unsupported.js'), array('jquery'), CTFW_THEME_VERSION); // bust cache on theme update // Pass data wp_localize_script('ctfw-ie-unsupported', 'ctfw_ie_unsupported', array('default_version' => $default_version, 'min_version' => $min_version, 'max_version' => $max_version, 'version' => $version, 'message' => __('You are using an outdated version of Internet Explorer. Please upgrade your browser to use this site.', 'church-theme-framework'), 'redirect_url' => apply_filters('ctfw_upgrade_browser_url', 'http://browsehappy.com/'))); } }
/** * Display Google Map * * Only latitude and longitude are required. * * @since 0.9 * @param array $options Options for showing map * @return string Google Maps HTML */ function ctfw_google_map($options = false) { $html = ''; if (!empty($options['latitude']) && !empty($options['longitude'])) { // Defaults $options['type'] = isset($options['type']) ? strtoupper($options['type']) : ''; $options['zoom'] = isset($options['zoom']) ? (int) $options['zoom'] : ''; $options['container'] = isset($options['container']) ? $options['container'] : true; // default true $options['responsive'] = isset($options['responsive']) ? $options['responsive'] : true; // default true $options['marker'] = isset($options['marker']) ? $options['marker'] : true; // default true $options['center_resize'] = isset($options['center_resize']) ? $options['center_resize'] : true; // default true $options['callback_loaded'] = isset($options['callback_loaded']) ? $options['callback_loaded'] : ''; $options['callback_resize'] = isset($options['callback_resize']) ? $options['callback_resize'] : ''; // Unique ID for this map so can have multiple maps on a page // Can pass map_id as option for custom ID $google_map_id_default = 'ctfw-google-map-' . rand(1000000, 9999999); $google_map_id = isset($options['canvas_id']) ? $options['canvas_id'] : $google_map_id_default; // Classes for map canvas element $canvas_classes = array('ctfw-google-map'); if (!empty($options['canvas_class'])) { $canvas_classes[] = $options['canvas_class']; } if ($options['responsive']) { $canvas_classes[] = 'ctfw-google-map-responsive'; } $canvas_classes = implode(' ', $canvas_classes); // Height percentage of width? $map_style = ''; if (!empty($options['height_percent'])) { $options['height_percent'] = str_replace('%', '', $options['height_percent']); $map_style = ' style="padding-bottom: ' . $options['height_percent'] . '%;"'; } // Data Attributes $data_latitude = esc_attr($options['latitude']); $data_longitude = esc_attr($options['longitude']); $data_type = esc_attr($options['type']); $data_zoom = esc_attr($options['zoom']); $data_marker = esc_attr($options['marker']); $data_center_resize = esc_attr($options['center_resize']); $data_callback_loaded = esc_attr($options['callback_loaded']); $data_callback_resize = esc_attr($options['callback_resize']); // Map canvas tag with attributes $html = '<div id="' . esc_attr($google_map_id) . '" class="' . $canvas_classes . '" data-ctfw-map-lat="' . esc_attr($data_latitude) . '" data-ctfw-map-lng="' . esc_attr($data_longitude) . '" data-ctfw-map-type="' . esc_attr($data_type) . '" data-ctfw-map-zoom="' . esc_attr($data_zoom) . '" data-ctfw-map-marker="' . esc_attr($data_marker) . '" data-ctfw-map-center-resize="' . esc_attr($data_center_resize) . '" data-ctfw-map-callback-loaded="' . esc_attr($data_callback_loaded) . '" data-ctfw-map-callback-resize="' . esc_attr($data_callback_resize) . '"' . $map_style . '></div>'; // Use container? if ($options['container']) { $html = '<div class="ctfw-google-map-container">' . $html . '</div>'; } // Enqueue map scripts to handle Google Maps init // this way the scripts are loaded only when feature is used, not on every page wp_enqueue_script('google-maps', '//maps.googleapis.com/maps/api/js', false, null); // no version, generic name to share w/plugins wp_enqueue_script('ctfw-maps', ctfw_theme_url(CTFW_JS_DIR . '/maps.js'), array('jquery', 'google-maps'), CTFW_VERSION); // bust cache on theme update } elseif (!empty($options['show_error'])) { $html = __('<p><b>Google Map Error:</b> <i>latitude</i> and <i>longitude</i> attributes are required. See documentation for help.</p>', 'church-theme-framework'); } return apply_filters('ctfw_google_map', $html, $options); }
/** * Enqueue styles for customizer controls * * @since 1.2 */ function ctfw_customize_enqueue_styles() { // Admin widgets // Same stylesheet used for Appearance > Widgets wp_enqueue_style('ctfw-widgets', ctfw_theme_url(CTFW_CSS_DIR . '/admin-widgets.css'), false, CTFW_THEME_VERSION); // bust cache on update }