PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -0,0 +1,224 @@
/* Options Framework Admin Styles */
#optionsframework {
max-width:840px;
background:#fff;
}
#optionsframework h3 {
cursor: default;
background-color: #f1f1f1;
border-bottom: 1px solid #ddd;
}
#optionsframework p {
margin-bottom:0;
padding-bottom:10px;
}
#optionsframework .section {
padding:10px 10px 0;
}
#optionsframework .group {
padding-bottom:40px;
}
#optionsframework .section .controls {
float: left;
min-width:350px;
width: 54%;
padding-right:2%;
}
#optionsframework .section .explain {
max-width:38%;
float: left;
font-size: 12px;
line-height:16px;
color: #777;
}
#optionsframework .section-checkbox .controls {
width: 98%;
}
#optionsframework .section-checkbox .explain {
max-width:94%;
}
#optionsframework .controls input[type=text] {
width:100%;
}
#optionsframework .controls input[type=text].wp-color-picker {
width: 65px;
}
#optionsframework .controls select, #optionsframework .controls textarea {
margin-bottom:10px;
width:100%;
}
#optionsframework .section-radio label, #optionsframework .section-multicheck label {
float:left;
max-width:90%;
line-height: 16px;
margin-bottom: 5px;
}
#optionsframework input.checkbox, #optionsframework input.of-radio {
margin: 0 10px 5px 0;
float:left;
clear:both;
}
#optionsframework .section-typography .controls {
float:none;
width:auto;
}
#optionsframework .section-typography .explain {
float:none;
width:auto;
}
#optionsframework .controls .of-typography-size {
width:80px;
float:left
}
#optionsframework .controls .of-typography-unit {
width:50px;
margin-left:5px;
float:left
}
#optionsframework .controls .of-typography-face {
width:100px;
margin-left:5px;
float:left
}
#optionsframework .controls .of-typography-style {
width:80px;
margin-left:5px;
margin-right:5px;
float:left
}
#optionsframework .section-typography .wp-picker-container {
margin-top:2px;
}
#optionsframework .of-background-properties {
clear:both;
margin-top: 18px;
}
#optionsframework .controls .of-background-repeat {
width:125px;
margin-right:5px;
float:left
}
#optionsframework .controls .of-background-position {
width:125px;
margin-right:5px;
float:left
}
#optionsframework .controls .of-background-attachment {
width:125px;
margin-right:5px;
float:left
}
#optionsframework .section-background .wp-picker-container {
margin-bottom:10px;
}
#optionsframework .controls .of-radio-img-img {
border:3px solid #f9f9f9;
margin:0 5px 10px 0;
display:none;
cursor:pointer;
float:left;
}
#optionsframework .controls .of-radio-img-selected {
border:3px solid #ccc
}
#optionsframework .controls .of-radio-img-img:hover {
opacity:.8;
}
#optionsframework .controls .of-border-width {
width:80px;
float:left
}
#optionsframework .controls .of-border-style {
width:120px;
float:left
}
#optionsframework .hide {
display:none;
}
#optionsframework .of-option-image {
max-width:340px;
margin:3px 0 18px 0;
}
#optionsframework .mini .controls select, #optionsframework .section .mini .controls {
width: 140px;
}
#optionsframework .mini .controls input, #optionsframework .mini .controls {
min-width:140px;
width: 140px;
}
#optionsframework .mini .explain {
max-width:74%;
}
/* Editor */
#optionsframework .section-editor .explain {
max-width: 98%;
float:none;
margin-bottom:5px;
}
/* Image Uploader */
#optionsframework .controls input.upload {
width:80%;
}
#optionsframework .screenshot {
float:left;
margin-left:1px;
position:relative;
width:344px;
margin-top:3px;
}
#optionsframework .screenshot img {
background:#fafafa;
border-color:#ccc #eee #eee #ccc;
border-style:solid;
border-width:1px;
float:left;
max-width:334px;
padding:4px;
margin-bottom:10px;
}
#optionsframework .screenshot .remove-image {
background:url("../images/ico-delete.png") no-repeat;
border:medium none;
bottom:4px;
display:block;
float:left;
height:16px;
padding:0;
position:absolute;
left:-4px;
text-indent:-9999px;
width:16px;
}
#optionsframework .screenshot .no_image .file_link {
margin-left: 20px;
}
#optionsframework .screenshot .no_image .remove-button {
bottom: 0px;
}
#optionsframework .reset-button {
float:left;
cursor:pointer;
}
/* Bottom Section */
#optionsframework-submit {
padding: 7px 10px;
border-top: 1px solid #ddd;
background-color: #f1f1f1;
}
#optionsframework .button-primary {
float:right;
}
#optionsframework .section:after {
content: "";
display: table;
}
#optionsframework .section:after {
clear: both;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

View File

@ -0,0 +1,350 @@
<?php
/**
* @package Options_Framework
* @author Devin Price <devin@wptheming.com>
* @license GPL-2.0+
* @link http://wptheming.com
* @copyright 2010-2014 WP Theming
*/
class Options_Framework_Admin {
/**
* Page hook for the options screen
*
* @since 1.7.0
* @type string
*/
protected $options_screen = null;
/**
* Hook in the scripts and styles
*
* @since 1.7.0
*/
public function init() {
// Gets options to load
$options = & Options_Framework::_optionsframework_options();
// Checks if options are available
if ( $options ) {
// Add the options page and menu item.
add_action( 'admin_menu', array( $this, 'add_custom_options_page' ) );
// Add the required scripts and styles
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
// Settings need to be registered after admin_init
add_action( 'admin_init', array( $this, 'settings_init' ) );
// Adds options menu to the admin bar
add_action( 'wp_before_admin_bar_render', array( $this, 'optionsframework_admin_bar' ) );
}
}
/**
* Registers the settings
*
* @since 1.7.0
*/
function settings_init() {
// Get the option name
$options_framework = new Options_Framework;
$name = $options_framework->get_option_name();
// Registers the settings fields and callback
register_setting( 'optionsframework', $name, array ( $this, 'validate_options' ) );
// Displays notice after options save
add_action( 'optionsframework_after_validate', array( $this, 'save_options_notice' ) );
}
/*
* Define menu options
*
* Examples usage:
*
* add_filter( 'optionsframework_menu', function( $menu ) {
* $menu['page_title'] = 'The Options';
* $menu['menu_title'] = 'The Options';
* return $menu;
* });
*
* @since 1.7.0
*
*/
static function menu_settings() {
$menu = array(
// Modes: submenu, menu
'mode' => 'submenu',
// Submenu default settings
'page_title' => __( 'Theme Options', 'myoos' ),
'menu_title' => __( 'Theme Options', 'myoos' ),
'capability' => 'edit_theme_options',
'menu_slug' => 'options-framework',
'parent_slug' => 'themes.php',
// Menu default settings
'icon_url' => 'dashicons-admin-generic',
'position' => '61'
);
return apply_filters( 'optionsframework_menu', $menu );
}
/**
* Add a subpage called "Theme Options" to the appearance menu.
*
* @since 1.7.0
*/
function add_custom_options_page() {
$menu = $this->menu_settings();
// If you want a top level menu, see this Gist:
// https://gist.github.com/devinsays/884d6abe92857a329d99
// Code removed because it conflicts with .org theme check.
$this->options_screen = add_theme_page(
$menu['page_title'],
$menu['menu_title'],
$menu['capability'],
$menu['menu_slug'],
array( $this, 'options_page' )
);
}
/**
* Loads the required stylesheets
*
* @since 1.7.0
*/
function enqueue_admin_styles( $hook ) {
if ( $this->options_screen != $hook )
return;
wp_enqueue_style( 'optionsframework', OPTIONS_FRAMEWORK_DIRECTORY . 'css/optionsframework.css', array(), Options_Framework::VERSION );
wp_enqueue_style( 'wp-color-picker' );
}
/**
* Loads the required javascript
*
* @since 1.7.0
*/
function enqueue_admin_scripts( $hook ) {
if ( $this->options_screen != $hook )
return;
// Enqueue custom option panel JS
wp_enqueue_script(
'options-custom',
OPTIONS_FRAMEWORK_DIRECTORY . 'js/options-custom.js',
array( 'jquery','wp-color-picker' ),
Options_Framework::VERSION
);
// Inline scripts from options-interface.php
add_action( 'admin_head', array( $this, 'of_admin_head' ) );
}
function of_admin_head() {
// Hook to add custom scripts
do_action( 'optionsframework_custom_scripts' );
}
/**
* Builds out the options panel.
*
* If we were using the Settings API as it was intended we would use
* do_settings_sections here. But as we don't want the settings wrapped in a table,
* we'll call our own custom optionsframework_fields. See options-interface.php
* for specifics on how each individual field is generated.
*
* Nonces are provided using the settings_fields()
*
* @since 1.7.0
*/
function options_page() { ?>
<div id="optionsframework-wrap" class="wrap">
<?php $menu = $this->menu_settings(); ?>
<h2><?php echo esc_html( $menu['page_title'] ); ?></h2>
<h2 class="nav-tab-wrapper">
<?php echo Options_Framework_Interface::optionsframework_tabs(); ?>
</h2>
<?php settings_errors( 'options-framework' ); ?>
<div id="optionsframework-metabox" class="metabox-holder">
<div id="optionsframework" class="postbox">
<form action="options.php" method="post">
<?php settings_fields( 'optionsframework' ); ?>
<?php Options_Framework_Interface::optionsframework_fields(); /* Settings */ ?>
<div id="optionsframework-submit">
<input type="submit" class="button-primary" name="update" value="<?php esc_attr_e( 'Save Options', 'myoos' ); ?>" />
<input type="submit" class="reset-button button-secondary" name="reset" value="<?php esc_attr_e( 'Restore Defaults', 'myoos' ); ?>" onclick="return confirm( '<?php print esc_js( __( 'Click OK to reset. Any theme settings will be lost!', 'myoos' ) ); ?>' );" />
<div class="clear"></div>
</div>
</form>
</div> <!-- / #container -->
</div>
<?php do_action( 'optionsframework_after' ); ?>
</div> <!-- / .wrap -->
<?php
}
/**
* Validate Options.
*
* This runs after the submit/reset button has been clicked and
* validates the inputs.
*
* @uses $_POST['reset'] to restore default options
*/
function validate_options( $input ) {
/*
* Restore Defaults.
*
* In the event that the user clicked the "Restore Defaults"
* button, the options defined in the theme's options.php
* file will be added to the option for the active theme.
*/
if ( isset( $_POST['reset'] ) ) {
add_settings_error( 'options-framework', 'restore_defaults', __( 'Default options restored.', 'myoos' ), 'updated fade' );
return $this->get_default_values();
}
/*
* Update Settings
*
* This used to check for $_POST['update'], but has been updated
* to be compatible with the theme customizer introduced in WordPress 3.4
*/
$clean = array();
$options = & Options_Framework::_optionsframework_options();
foreach ( $options as $option ) {
if ( ! isset( $option['id'] ) ) {
continue;
}
if ( ! isset( $option['type'] ) ) {
continue;
}
$id = preg_replace( '/[^a-zA-Z0-9._\-]/', '', strtolower( $option['id'] ) );
// Set checkbox to false if it wasn't sent in the $_POST
if ( 'checkbox' == $option['type'] && ! isset( $input[$id] ) ) {
$input[$id] = false;
}
// Set each item in the multicheck to false if it wasn't sent in the $_POST
if ( 'multicheck' == $option['type'] && ! isset( $input[$id] ) ) {
foreach ( $option['options'] as $key => $value ) {
$input[$id][$key] = false;
}
}
// For a value to be submitted to database it must pass through a sanitization filter
if ( has_filter( 'of_sanitize_' . $option['type'] ) ) {
$clean[$id] = apply_filters( 'of_sanitize_' . $option['type'], $input[$id], $option );
}
}
// Hook to run after validation
do_action( 'optionsframework_after_validate', $clean );
return $clean;
}
/**
* Display message when options have been saved
*/
function save_options_notice() {
add_settings_error( 'options-framework', 'save_options', __( 'Options saved.', 'myoos' ), 'updated fade' );
}
/**
* Get the default values for all the theme options
*
* Get an array of all default values as set in
* options.php. The 'id','std' and 'type' keys need
* to be defined in the configuration array. In the
* event that these keys are not present the option
* will not be included in this function's output.
*
* @return array Re-keyed options configuration array.
*
*/
function get_default_values() {
$output = array();
$config = & Options_Framework::_optionsframework_options();
foreach ( (array) $config as $option ) {
if ( ! isset( $option['id'] ) ) {
continue;
}
if ( ! isset( $option['std'] ) ) {
continue;
}
if ( ! isset( $option['type'] ) ) {
continue;
}
if ( has_filter( 'of_sanitize_' . $option['type'] ) ) {
$output[$option['id']] = apply_filters( 'of_sanitize_' . $option['type'], $option['std'], $option );
}
}
return $output;
}
/**
* Add options menu item to admin bar
*/
function optionsframework_admin_bar() {
$menu = $this->menu_settings();
global $wp_admin_bar;
if ( 'menu' == $menu['mode'] ) {
$href = admin_url( 'admin.php?page=' . $menu['menu_slug'] );
} else {
$href = admin_url( 'themes.php?page=' . $menu['menu_slug'] );
}
$args = array(
'parent' => 'appearance',
'id' => 'of_theme_options',
'title' => $menu['menu_title'],
'href' => $href
);
$wp_admin_bar->add_menu( apply_filters( 'optionsframework_admin_bar', $args ) );
}
}

View File

@ -0,0 +1,96 @@
<?php
/**
* @package Options_Framework
* @author Devin Price <devin@wptheming.com>
* @license GPL-2.0+
* @link http://wptheming.com
* @copyright 2010-2014 WP Theming
*/
class Options_Framework {
/**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 1.7.0
* @type string
*/
const VERSION = '1.9.1';
/**
* Gets option name
*
* @since 1.9.0
*/
function get_option_name() {
$name = '';
// Gets option name as defined in the theme
if ( function_exists( 'optionsframework_option_name' ) ) {
$name = optionsframework_option_name();
}
// Fallback
if ( '' == $name ) {
$name = get_option( 'stylesheet' );
$name = preg_replace( "/\W/", "_", strtolower( $name ) );
}
return apply_filters( 'options_framework_option_name', $name );
}
/**
* Wrapper for optionsframework_options()
*
* Allows for manipulating or setting options via 'of_options' filter
* For example:
*
* <code>
* add_filter( 'of_options', function( $options ) {
* $options[] = array(
* 'name' => 'Input Text Mini',
* 'desc' => 'A mini text input field.',
* 'id' => 'example_text_mini',
* 'std' => 'Default',
* 'class' => 'mini',
* 'type' => 'text'
* );
*
* return $options;
* });
* </code>
*
* Also allows for setting options via a return statement in the
* options.php file. For example (in options.php):
*
* <code>
* return array(...);
* </code>
*
* @return array (by reference)
*/
static function &_optionsframework_options() {
static $options = null;
if ( !$options ) {
// Load options from options.php file (if it exists)
$location = apply_filters( 'options_framework_location', array( 'options.php' ) );
if ( $optionsfile = locate_template( $location ) ) {
$maybe_options = load_template( $optionsfile );
if ( is_array( $maybe_options ) ) {
$options = $maybe_options;
} else if ( function_exists( 'optionsframework_options' ) ) {
$options = optionsframework_options();
}
}
// Allow setting/manipulating options via filters
$options = apply_filters( 'of_options', $options );
}
return $options;
}
}

View File

@ -0,0 +1,421 @@
<?php
/**
* @package Options_Framework
* @author Devin Price <devin@wptheming.com>
* @license GPL-2.0+
* @link http://wptheming.com
* @copyright 2010-2014 WP Theming
*/
class Options_Framework_Interface {
/**
* Generates the tabs that are used in the options menu
*/
static function optionsframework_tabs() {
$counter = 0;
$options = & Options_Framework::_optionsframework_options();
$menu = '';
foreach ( $options as $value ) {
// Heading for Navigation
if ( $value['type'] == "heading" ) {
$counter++;
$class = '';
$class = ! empty( $value['id'] ) ? $value['id'] : $value['name'];
$class = preg_replace( '/[^a-zA-Z0-9._\-]/', '', strtolower($class) ) . '-tab';
$menu .= '<a id="options-group-'. $counter . '-tab" class="nav-tab ' . $class .'" title="' . esc_attr( $value['name'] ) . '" href="' . esc_attr( '#options-group-'. $counter ) . '">' . esc_html( $value['name'] ) . '</a>';
}
}
return $menu;
}
/**
* Generates the options fields that are used in the form.
*/
static function optionsframework_fields() {
global $allowedtags;
$options_framework = new Options_Framework;
$option_name = $options_framework->get_option_name();
$settings = get_option( $option_name );
$options = & Options_Framework::_optionsframework_options();
$counter = 0;
$menu = '';
foreach ( $options as $value ) {
$val = '';
$select_value = '';
$output = '';
// Wrap all options
if ( ( $value['type'] != "heading" ) && ( $value['type'] != "info" ) ) {
// Keep all ids lowercase with no spaces
$value['id'] = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($value['id']) );
$id = 'section-' . $value['id'];
$class = 'section';
if ( isset( $value['type'] ) ) {
$class .= ' section-' . $value['type'];
}
if ( isset( $value['class'] ) ) {
$class .= ' ' . $value['class'];
}
$output .= '<div id="' . esc_attr( $id ) .'" class="' . esc_attr( $class ) . '">'."\n";
if ( isset( $value['name'] ) ) {
$output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n";
}
if ( $value['type'] != 'editor' ) {
$output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
}
else {
$output .= '<div class="option">' . "\n" . '<div>' . "\n";
}
}
// Set default value to $val
if ( isset( $value['std'] ) ) {
$val = $value['std'];
}
// If the option is already saved, override $val
if ( ( $value['type'] != 'heading' ) && ( $value['type'] != 'info') ) {
if ( isset( $settings[($value['id'])]) ) {
$val = $settings[($value['id'])];
// Striping slashes of non-array options
if ( !is_array($val) ) {
$val = stripslashes( $val );
}
}
}
// If there is a description save it for labels
$explain_value = '';
if ( isset( $value['desc'] ) ) {
$explain_value = $value['desc'];
}
// Set the placeholder if one exists
$placeholder = '';
if ( isset( $value['placeholder'] ) ) {
$placeholder = ' placeholder="' . esc_attr( $value['placeholder'] ) . '"';
}
if ( has_filter( 'optionsframework_' . $value['type'] ) ) {
$output .= apply_filters( 'optionsframework_' . $value['type'], $option_name, $value, $val );
}
switch ( $value['type'] ) {
// Basic text input
case 'text':
$output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="text" value="' . esc_attr( $val ) . '"' . $placeholder . ' />';
break;
// Password input
case 'password':
$output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="password" value="' . esc_attr( $val ) . '" />';
break;
// Textarea
case 'textarea':
$rows = '8';
if ( isset( $value['settings']['rows'] ) ) {
$custom_rows = $value['settings']['rows'];
if ( is_numeric( $custom_rows ) ) {
$rows = $custom_rows;
}
}
$val = stripslashes( $val );
$output .= '<textarea id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" rows="' . $rows . '"' . $placeholder . '>' . esc_textarea( $val ) . '</textarea>';
break;
// Select Box
case 'select':
$output .= '<select class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '">';
foreach ($value['options'] as $key => $option ) {
$output .= '<option'. selected( $val, $key, false ) .' value="' . esc_attr( $key ) . '">' . esc_html( $option ) . '</option>';
}
$output .= '</select>';
break;
// Radio Box
case "radio":
$name = $option_name .'['. $value['id'] .']';
foreach ($value['options'] as $key => $option) {
$id = $option_name . '-' . $value['id'] .'-'. $key;
$output .= '<input class="of-input of-radio" type="radio" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" value="'. esc_attr( $key ) . '" '. checked( $val, $key, false) .' /><label for="' . esc_attr( $id ) . '">' . esc_html( $option ) . '</label>';
}
break;
// Image Selectors
case "images":
$name = $option_name .'['. $value['id'] .']';
foreach ( $value['options'] as $key => $option ) {
$selected = '';
if ( $val != '' && ($val == $key) ) {
$selected = ' of-radio-img-selected';
}
$output .= '<input type="radio" id="' . esc_attr( $value['id'] .'_'. $key) . '" class="of-radio-img-radio" value="' . esc_attr( $key ) . '" name="' . esc_attr( $name ) . '" '. checked( $val, $key, false ) .' />';
$output .= '<div class="of-radio-img-label">' . esc_html( $key ) . '</div>';
$output .= '<img src="' . esc_url( $option ) . '" alt="' . $option .'" class="of-radio-img-img' . $selected .'" onclick="document.getElementById(\''. esc_attr($value['id'] .'_'. $key) .'\').checked=true;" />';
}
break;
// Checkbox
case "checkbox":
$output .= '<input id="' . esc_attr( $value['id'] ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" '. checked( $val, 1, false) .' />';
$output .= '<label class="explain" for="' . esc_attr( $value['id'] ) . '">' . wp_kses( $explain_value, $allowedtags) . '</label>';
break;
// Multicheck
case "multicheck":
foreach ($value['options'] as $key => $option) {
$checked = '';
$label = $option;
$option = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($key));
$id = $option_name . '-' . $value['id'] . '-'. $option;
$name = $option_name . '[' . $value['id'] . '][' . $option .']';
if ( isset($val[$option]) ) {
$checked = checked($val[$option], 1, false);
}
$output .= '<input id="' . esc_attr( $id ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $name ) . '" ' . $checked . ' /><label for="' . esc_attr( $id ) . '">' . esc_html( $label ) . '</label>';
}
break;
// Color picker
case "color":
$default_color = '';
if ( isset($value['std']) ) {
if ( $val != $value['std'] )
$default_color = ' data-default-color="' .$value['std'] . '" ';
}
$output .= '<input name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '" class="of-color" type="text" value="' . esc_attr( $val ) . '"' . $default_color .' />';
break;
// Uploader
case "upload":
$output .= Options_Framework_Media_Uploader::optionsframework_uploader( $value['id'], $val, null );
break;
// Typography
case 'typography':
unset( $font_size, $font_style, $font_face, $font_color );
$typography_defaults = array(
'size' => '',
'face' => '',
'style' => '',
'color' => ''
);
$typography_stored = wp_parse_args( $val, $typography_defaults );
$typography_options = array(
'sizes' => of_recognized_font_sizes(),
'faces' => of_recognized_font_faces(),
'styles' => of_recognized_font_styles(),
'color' => true
);
if ( isset( $value['options'] ) ) {
$typography_options = wp_parse_args( $value['options'], $typography_options );
}
// Font Size
if ( $typography_options['sizes'] ) {
$font_size = '<select class="of-typography of-typography-size" name="' . esc_attr( $option_name . '[' . $value['id'] . '][size]' ) . '" id="' . esc_attr( $value['id'] . '_size' ) . '">';
$sizes = $typography_options['sizes'];
foreach ( $sizes as $i ) {
$size = $i . 'px';
$font_size .= '<option value="' . esc_attr( $size ) . '" ' . selected( $typography_stored['size'], $size, false ) . '>' . esc_html( $size ) . '</option>';
}
$font_size .= '</select>';
}
// Font Face
if ( $typography_options['faces'] ) {
$font_face = '<select class="of-typography of-typography-face" name="' . esc_attr( $option_name . '[' . $value['id'] . '][face]' ) . '" id="' . esc_attr( $value['id'] . '_face' ) . '">';
$faces = $typography_options['faces'];
foreach ( $faces as $key => $face ) {
$font_face .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['face'], $key, false ) . '>' . esc_html( $face ) . '</option>';
}
$font_face .= '</select>';
}
// Font Styles
if ( $typography_options['styles'] ) {
$font_style = '<select class="of-typography of-typography-style" name="'.$option_name.'['.$value['id'].'][style]" id="'. $value['id'].'_style">';
$styles = $typography_options['styles'];
foreach ( $styles as $key => $style ) {
$font_style .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['style'], $key, false ) . '>'. $style .'</option>';
}
$font_style .= '</select>';
}
// Font Color
if ( $typography_options['color'] ) {
$default_color = '';
if ( isset($value['std']['color']) ) {
if ( $val != $value['std']['color'] )
$default_color = ' data-default-color="' .$value['std']['color'] . '" ';
}
$font_color = '<input name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" class="of-color of-typography-color type="text" value="' . esc_attr( $typography_stored['color'] ) . '"' . $default_color .' />';
}
// Allow modification/injection of typography fields
$typography_fields = compact( 'font_size', 'font_face', 'font_style', 'font_color' );
$typography_fields = apply_filters( 'of_typography_fields', $typography_fields, $typography_stored, $option_name, $value );
$output .= implode( '', $typography_fields );
break;
// Background
case 'background':
$background = $val;
// Background Color
$default_color = '';
if ( isset( $value['std']['color'] ) ) {
if ( $val != $value['std']['color'] )
$default_color = ' data-default-color="' .$value['std']['color'] . '" ';
}
$output .= '<input name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" class="of-color of-background-color" type="text" value="' . esc_attr( $background['color'] ) . '"' . $default_color .' />';
// Background Image
if ( !isset($background['image']) ) {
$background['image'] = '';
}
$output .= Options_Framework_Media_Uploader::optionsframework_uploader( $value['id'], $background['image'], null, esc_attr( $option_name . '[' . $value['id'] . '][image]' ) );
$class = 'of-background-properties';
if ( '' == $background['image'] ) {
$class .= ' hide';
}
$output .= '<div class="' . esc_attr( $class ) . '">';
// Background Repeat
$output .= '<select class="of-background of-background-repeat" name="' . esc_attr( $option_name . '[' . $value['id'] . '][repeat]' ) . '" id="' . esc_attr( $value['id'] . '_repeat' ) . '">';
$repeats = of_recognized_background_repeat();
foreach ($repeats as $key => $repeat) {
$output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['repeat'], $key, false ) . '>'. esc_html( $repeat ) . '</option>';
}
$output .= '</select>';
// Background Position
$output .= '<select class="of-background of-background-position" name="' . esc_attr( $option_name . '[' . $value['id'] . '][position]' ) . '" id="' . esc_attr( $value['id'] . '_position' ) . '">';
$positions = of_recognized_background_position();
foreach ($positions as $key=>$position) {
$output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['position'], $key, false ) . '>'. esc_html( $position ) . '</option>';
}
$output .= '</select>';
// Background Attachment
$output .= '<select class="of-background of-background-attachment" name="' . esc_attr( $option_name . '[' . $value['id'] . '][attachment]' ) . '" id="' . esc_attr( $value['id'] . '_attachment' ) . '">';
$attachments = of_recognized_background_attachment();
foreach ($attachments as $key => $attachment) {
$output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['attachment'], $key, false ) . '>' . esc_html( $attachment ) . '</option>';
}
$output .= '</select>';
$output .= '</div>';
break;
// Editor
case 'editor':
$output .= '<div class="explain">' . wp_kses( $explain_value, $allowedtags ) . '</div>'."\n";
echo $output;
$textarea_name = esc_attr( $option_name . '[' . $value['id'] . ']' );
$default_editor_settings = array(
'textarea_name' => $textarea_name,
'media_buttons' => false,
'tinymce' => array( 'plugins' => 'wordpress,wplink' )
);
$editor_settings = array();
if ( isset( $value['settings'] ) ) {
$editor_settings = $value['settings'];
}
$editor_settings = array_merge( $default_editor_settings, $editor_settings );
wp_editor( $val, $value['id'], $editor_settings );
$output = '';
break;
// Info
case "info":
$id = '';
$class = 'section';
if ( isset( $value['id'] ) ) {
$id = 'id="' . esc_attr( $value['id'] ) . '" ';
}
if ( isset( $value['type'] ) ) {
$class .= ' section-' . $value['type'];
}
if ( isset( $value['class'] ) ) {
$class .= ' ' . $value['class'];
}
$output .= '<div ' . $id . 'class="' . esc_attr( $class ) . '">' . "\n";
if ( isset($value['name']) ) {
$output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n";
}
if ( isset( $value['desc'] ) ) {
$output .= $value['desc'] . "\n";
}
$output .= '</div>' . "\n";
break;
// Heading for Navigation
case "heading":
$counter++;
if ( $counter >= 2 ) {
$output .= '</div>'."\n";
}
$class = '';
$class = ! empty( $value['id'] ) ? $value['id'] : $value['name'];
$class = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($class) );
$output .= '<div id="options-group-' . $counter . '" class="group ' . $class . '">';
$output .= '<h3>' . esc_html( $value['name'] ) . '</h3>' . "\n";
break;
}
if ( ( $value['type'] != "heading" ) && ( $value['type'] != "info" ) ) {
$output .= '</div>';
if ( ( $value['type'] != "checkbox" ) && ( $value['type'] != "editor" ) ) {
$output .= '<div class="explain">' . wp_kses( $explain_value, $allowedtags) . '</div>'."\n";
}
$output .= '</div></div>'."\n";
}
echo $output;
}
// Outputs closing div if there tabs
if ( Options_Framework_Interface::optionsframework_tabs() != '' ) {
echo '</div>';
}
}
}

View File

@ -0,0 +1,122 @@
<?php
/**
* @package Options_Framework
* @author Devin Price <devin@wptheming.com>
* @license GPL-2.0+
* @link http://wptheming.com
* @copyright 2010-2014 WP Theming
*/
class Options_Framework_Media_Uploader {
/**
* Initialize the media uploader class
*
* @since 1.7.0
*/
public function init() {
add_action( 'admin_enqueue_scripts', array( $this, 'optionsframework_media_scripts' ) );
}
/**
* Media Uploader Using the WordPress Media Library.
*
* Parameters:
*
* string $_id - A token to identify this field (the name).
* string $_value - The value of the field, if present.
* string $_desc - An optional description of the field.
*
*/
static function optionsframework_uploader( $_id, $_value, $_desc = '', $_name = '' ) {
// Gets the unique option id
$options_framework = new Options_Framework;
$option_name = $options_framework->get_option_name();
$output = '';
$id = '';
$class = '';
$int = '';
$value = '';
$name = '';
$id = strip_tags( strtolower( $_id ) );
// If a value is passed and we don't have a stored value, use the value that's passed through.
if ( $_value != '' && $value == '' ) {
$value = $_value;
}
if ($_name != '') {
$name = $_name;
}
else {
$name = $option_name.'['.$id.']';
}
if ( $value ) {
$class = ' has-file';
}
$output .= '<input id="' . $id . '" class="upload' . $class . '" type="text" name="'.$name.'" value="' . $value . '" placeholder="' . __('No file chosen', 'myoos') .'" />' . "\n";
if ( function_exists( 'wp_enqueue_media' ) ) {
if ( ( $value == '' ) ) {
$output .= '<input id="upload-' . $id . '" class="upload-button button" type="button" value="' . __( 'Upload', 'myoos' ) . '" />' . "\n";
} else {
$output .= '<input id="remove-' . $id . '" class="remove-file button" type="button" value="' . __( 'Remove', 'myoos' ) . '" />' . "\n";
}
} else {
$output .= '<p><i>' . __( 'Upgrade your version of WordPress for full media support.', 'myoos' ) . '</i></p>';
}
if ( $_desc != '' ) {
$output .= '<span class="of-metabox-desc">' . $_desc . '</span>' . "\n";
}
$output .= '<div class="screenshot" id="' . $id . '-image">' . "\n";
if ( $value != '' ) {
$remove = '<a class="remove-image">Remove</a>';
$image = preg_match( '/(^.*\.jpg|jpeg|png|gif|ico*)/i', $value );
if ( $image ) {
$output .= '<img src="' . $value . '" alt="" />' . $remove;
} else {
$parts = explode( "/", $value );
for( $i = 0; $i < sizeof( $parts ); ++$i ) {
$title = $parts[$i];
}
// No output preview if it's not an image.
$output .= '';
// Standard generic output if it's not an image.
$title = __( 'View File', 'myoos' );
$output .= '<div class="no-image"><span class="file_link"><a href="' . $value . '" target="_blank" rel="external">'.$title.'</a></span></div>';
}
}
$output .= '</div>' . "\n";
return $output;
}
/**
* Enqueue scripts for file uploader
*/
function optionsframework_media_scripts( $hook ) {
$menu = Options_Framework_Admin::menu_settings();
if ( substr( $hook, -strlen( $menu['menu_slug'] ) ) !== $menu['menu_slug'] )
return;
if ( function_exists( 'wp_enqueue_media' ) )
wp_enqueue_media();
wp_register_script( 'of-media-uploader', OPTIONS_FRAMEWORK_DIRECTORY .'js/media-uploader.js', array( 'jquery' ), Options_Framework::VERSION );
wp_enqueue_script( 'of-media-uploader' );
wp_localize_script( 'of-media-uploader', 'optionsframework_l10n', array(
'upload' => __( 'Upload', 'myoos' ),
'remove' => __( 'Remove', 'myoos' )
) );
}
}

View File

@ -0,0 +1,454 @@
<?php
/**
* @package Options_Framework
* @author Devin Price <devin@wptheming.com>
* @license GPL-2.0+
* @link http://wptheming.com
* @copyright 2010-2014 WP Theming
*/
/**
* Sanitization for text input
*
* @link http://developer.wordpress.org/reference/functions/sanitize_text_field/
*/
add_filter( 'of_sanitize_text', 'sanitize_text_field' );
/**
* Sanitization for password input
*
* @link http://developer.wordpress.org/reference/functions/sanitize_text_field/
*/
add_filter( 'of_sanitize_password', 'sanitize_text_field' );
/**
* Sanitization for select input
*
* Validates that the selected option is a valid option.
*/
add_filter( 'of_sanitize_select', 'of_sanitize_enum', 10, 2 );
/**
* Sanitization for radio input
*
* Validates that the selected option is a valid option.
*/
add_filter( 'of_sanitize_radio', 'of_sanitize_enum', 10, 2 );
/**
* Sanitization for image selector
*
* Validates that the selected option is a valid option.
*/
add_filter( 'of_sanitize_images', 'of_sanitize_enum', 10, 2 );
/**
* Sanitization for textarea field
*
* @param $input string
* @return $output sanitized string
*/
function of_sanitize_textarea( $input ) {
global $allowedposttags;
$output = wp_kses( $input, $allowedposttags );
return $output;
}
add_filter( 'of_sanitize_textarea', 'of_sanitize_textarea' );
/**
* Sanitization for checkbox input
*
* @param $input string (1 or empty) checkbox state
* @return $output '1' or false
*/
function of_sanitize_checkbox( $input ) {
if ( $input ) {
$output = '1';
} else {
$output = false;
}
return $output;
}
add_filter( 'of_sanitize_checkbox', 'of_sanitize_checkbox' );
/**
* Sanitization for multicheck
*
* @param array of checkbox values
* @return array of sanitized values ('1' or false)
*/
function of_sanitize_multicheck( $input, $option ) {
$output = '';
if ( is_array( $input ) ) {
foreach( $option['options'] as $key => $value ) {
$output[$key] = false;
}
foreach( $input as $key => $value ) {
if ( array_key_exists( $key, $option['options'] ) && $value ) {
$output[$key] = '1';
}
}
}
return $output;
}
add_filter( 'of_sanitize_multicheck', 'of_sanitize_multicheck', 10, 2 );
/**
* File upload sanitization.
*
* Returns a sanitized filepath if it has a valid extension.
*
* @param string $input filepath
* @returns string $output filepath
*/
function of_sanitize_upload( $input ) {
$output = '';
$filetype = wp_check_filetype( $input );
if ( $filetype["ext"] ) {
$output = esc_url( $input );
}
return $output;
}
add_filter( 'of_sanitize_upload', 'of_sanitize_upload' );
/**
* Sanitization for editor input.
*
* Returns unfiltered HTML if user has permissions.
*
* @param string $input
* @returns string $output
*/
function of_sanitize_editor( $input ) {
if ( current_user_can( 'unfiltered_html' ) ) {
$output = $input;
}
else {
global $allowedposttags;
$output = wpautop( wp_kses( $input, $allowedposttags ) );
}
return $output;
}
add_filter( 'of_sanitize_editor', 'of_sanitize_editor' );
/**
* Sanitization of input with allowed tags and wpautotop.
*
* Allows allowed tags in html input and ensures tags close properly.
*
* @param string $input
* @returns string $output
*/
function of_sanitize_allowedtags( $input ) {
global $allowedtags;
$output = wpautop( wp_kses( $input, $allowedtags ) );
return $output;
}
/**
* Sanitization of input with allowed post tags and wpautotop.
*
* Allows allowed post tags in html input and ensures tags close properly.
*
* @param string $input
* @returns string $output
*/
function of_sanitize_allowedposttags( $input ) {
global $allowedposttags;
$output = wpautop( wp_kses( $input, $allowedposttags) );
return $output;
}
/**
* Validates that the $input is one of the avilable choices
* for that specific option.
*
* @param string $input
* @returns string $output
*/
function of_sanitize_enum( $input, $option ) {
$output = '';
if ( array_key_exists( $input, $option['options'] ) ) {
$output = $input;
}
return $output;
}
/**
* Sanitization for background option.
*
* @returns array $output
*/
function of_sanitize_background( $input ) {
$output = wp_parse_args( $input, array(
'color' => '',
'image' => '',
'repeat' => 'repeat',
'position' => 'top center',
'attachment' => 'scroll'
) );
$output['color'] = apply_filters( 'of_sanitize_hex', $input['color'] );
$output['image'] = apply_filters( 'of_sanitize_upload', $input['image'] );
$output['repeat'] = apply_filters( 'of_background_repeat', $input['repeat'] );
$output['position'] = apply_filters( 'of_background_position', $input['position'] );
$output['attachment'] = apply_filters( 'of_background_attachment', $input['attachment'] );
return $output;
}
add_filter( 'of_sanitize_background', 'of_sanitize_background' );
/**
* Sanitization for background repeat
*
* @returns string $value if it is valid
*/
function of_sanitize_background_repeat( $value ) {
$recognized = of_recognized_background_repeat();
if ( array_key_exists( $value, $recognized ) ) {
return $value;
}
return apply_filters( 'of_default_background_repeat', current( $recognized ) );
}
add_filter( 'of_background_repeat', 'of_sanitize_background_repeat' );
/**
* Sanitization for background position
*
* @returns string $value if it is valid
*/
function of_sanitize_background_position( $value ) {
$recognized = of_recognized_background_position();
if ( array_key_exists( $value, $recognized ) ) {
return $value;
}
return apply_filters( 'of_default_background_position', current( $recognized ) );
}
add_filter( 'of_background_position', 'of_sanitize_background_position' );
/**
* Sanitization for background attachment
*
* @returns string $value if it is valid
*/
function of_sanitize_background_attachment( $value ) {
$recognized = of_recognized_background_attachment();
if ( array_key_exists( $value, $recognized ) ) {
return $value;
}
return apply_filters( 'of_default_background_attachment', current( $recognized ) );
}
add_filter( 'of_background_attachment', 'of_sanitize_background_attachment' );
/**
* Sanitization for typography option.
*/
function of_sanitize_typography( $input, $option ) {
$output = wp_parse_args( $input, array(
'size' => '',
'face' => '',
'style' => '',
'color' => ''
) );
if ( isset( $option['options']['faces'] ) && isset( $input['face'] ) ) {
if ( !( array_key_exists( $input['face'], $option['options']['faces'] ) ) ) {
$output['face'] = '';
}
}
else {
$output['face'] = apply_filters( 'of_font_face', $output['face'] );
}
$output['size'] = apply_filters( 'of_font_size', $output['size'] );
$output['style'] = apply_filters( 'of_font_style', $output['style'] );
$output['color'] = apply_filters( 'of_sanitize_color', $output['color'] );
return $output;
}
add_filter( 'of_sanitize_typography', 'of_sanitize_typography', 10, 2 );
/**
* Sanitization for font size
*/
function of_sanitize_font_size( $value ) {
$recognized = of_recognized_font_sizes();
$value_check = preg_replace('/px/','', $value);
if ( in_array( (int) $value_check, $recognized ) ) {
return $value;
}
return apply_filters( 'of_default_font_size', $recognized );
}
add_filter( 'of_font_size', 'of_sanitize_font_size' );
/**
* Sanitization for font style
*/
function of_sanitize_font_style( $value ) {
$recognized = of_recognized_font_styles();
if ( array_key_exists( $value, $recognized ) ) {
return $value;
}
return apply_filters( 'of_default_font_style', current( $recognized ) );
}
add_filter( 'of_font_style', 'of_sanitize_font_style' );
/**
* Sanitization for font face
*/
function of_sanitize_font_face( $value ) {
$recognized = of_recognized_font_faces();
if ( array_key_exists( $value, $recognized ) ) {
return $value;
}
return apply_filters( 'of_default_font_face', current( $recognized ) );
}
add_filter( 'of_font_face', 'of_sanitize_font_face' );
/**
* Get recognized background repeat settings
*
* @return array
*/
function of_recognized_background_repeat() {
$default = array(
'no-repeat' => __( 'No Repeat', 'myoos' ),
'repeat-x' => __( 'Repeat Horizontally', 'myoos' ),
'repeat-y' => __( 'Repeat Vertically', 'myoos' ),
'repeat' => __( 'Repeat All', 'myoos' ),
);
return apply_filters( 'of_recognized_background_repeat', $default );
}
/**
* Get recognized background positions
*
* @return array
*/
function of_recognized_background_position() {
$default = array(
'top left' => __( 'Top Left', 'myoos' ),
'top center' => __( 'Top Center', 'myoos' ),
'top right' => __( 'Top Right', 'myoos' ),
'center left' => __( 'Middle Left', 'myoos' ),
'center center' => __( 'Middle Center', 'myoos' ),
'center right' => __( 'Middle Right', 'myoos' ),
'bottom left' => __( 'Bottom Left', 'myoos' ),
'bottom center' => __( 'Bottom Center', 'myoos' ),
'bottom right' => __( 'Bottom Right', 'myoos')
);
return apply_filters( 'of_recognized_background_position', $default );
}
/**
* Get recognized background attachment
*
* @return array
*/
function of_recognized_background_attachment() {
$default = array(
'scroll' => __( 'Scroll Normally', 'myoos' ),
'fixed' => __( 'Fixed in Place', 'myoos')
);
return apply_filters( 'of_recognized_background_attachment', $default );
}
/**
* Sanitize a color represented in hexidecimal notation.
*
* @param string Color in hexidecimal notation. "#" may or may not be prepended to the string.
* @param string The value that this function should return if it cannot be recognized as a color.
* @return string
*/
function of_sanitize_hex( $hex, $default = '' ) {
if ( of_validate_hex( $hex ) ) {
return $hex;
}
return $default;
}
add_filter( 'of_sanitize_color', 'of_sanitize_hex' );
/**
* Get recognized font sizes.
*
* Returns an indexed array of all recognized font sizes.
* Values are integers and represent a range of sizes from
* smallest to largest.
*
* @return array
*/
function of_recognized_font_sizes() {
$sizes = range( 9, 71 );
$sizes = apply_filters( 'of_recognized_font_sizes', $sizes );
$sizes = array_map( 'absint', $sizes );
return $sizes;
}
/**
* Get recognized font faces.
*
* Returns an array of all recognized font faces.
* Keys are intended to be stored in the database
* while values are ready for display in in html.
*
* @return array
*/
function of_recognized_font_faces() {
$default = array(
'arial' => 'Arial',
'verdana' => 'Verdana, Geneva',
'trebuchet' => 'Trebuchet',
'georgia' => 'Georgia',
'times' => 'Times New Roman',
'tahoma' => 'Tahoma, Geneva',
'palatino' => 'Palatino',
'helvetica' => 'Helvetica*'
);
return apply_filters( 'of_recognized_font_faces', $default );
}
/**
* Get recognized font styles.
*
* Returns an array of all recognized font styles.
* Keys are intended to be stored in the database
* while values are ready for display in in html.
*
* @return array
*/
function of_recognized_font_styles() {
$default = array(
'normal' => __( 'Normal', 'myoos' ),
'italic' => __( 'Italic', 'myoos' ),
'bold' => __( 'Bold', 'myoos' ),
'bold italic' => __( 'Bold Italic', 'myoos' )
);
return apply_filters( 'of_recognized_font_styles', $default );
}
/**
* Is a given string a color formatted in hexidecimal notation?
*
* @param string Color in hexidecimal notation. "#" may or may not be prepended to the string.
* @return bool
*/
function of_validate_hex( $hex ) {
$hex = trim( $hex );
/* Strip recognized prefixes. */
if ( 0 === strpos( $hex, '#' ) ) {
$hex = substr( $hex, 1 );
}
elseif ( 0 === strpos( $hex, '%23' ) ) {
$hex = substr( $hex, 3 );
}
/* Regex match. */
if ( 0 === preg_match( '/^[0-9a-fA-F]{6}$/', $hex ) ) {
return false;
}
else {
return true;
}
}

View File

@ -0,0 +1,79 @@
jQuery(document).ready(function($){
var optionsframework_upload;
var optionsframework_selector;
function optionsframework_add_file(event, selector) {
var upload = $(".uploaded-file"), frame;
var $el = $(this);
optionsframework_selector = selector;
event.preventDefault();
// If the media frame already exists, reopen it.
if ( optionsframework_upload ) {
optionsframework_upload.open();
} else {
// Create the media frame.
optionsframework_upload = wp.media.frames.optionsframework_upload = wp.media({
// Set the title of the modal.
title: $el.data('choose'),
// Customize the submit button.
button: {
// Set the text of the button.
text: $el.data('update'),
// Tell the button not to close the modal, since we're
// going to refresh the page when the image is selected.
close: false
}
});
// When an image is selected, run a callback.
optionsframework_upload.on( 'select', function() {
// Grab the selected attachment.
var attachment = optionsframework_upload.state().get('selection').first();
optionsframework_upload.close();
optionsframework_selector.find('.upload').val(attachment.attributes.url);
if ( attachment.attributes.type == 'image' ) {
optionsframework_selector.find('.screenshot').empty().hide().append('<img src="' + attachment.attributes.url + '"><a class="remove-image">Remove</a>').slideDown('fast');
}
optionsframework_selector.find('.upload-button').unbind().addClass('remove-file').removeClass('upload-button').val(optionsframework_l10n.remove);
optionsframework_selector.find('.of-background-properties').slideDown();
optionsframework_selector.find('.remove-image, .remove-file').on('click', function() {
optionsframework_remove_file( $(this).parents('.section') );
});
});
}
// Finally, open the modal.
optionsframework_upload.open();
}
function optionsframework_remove_file(selector) {
selector.find('.remove-image').hide();
selector.find('.upload').val('');
selector.find('.of-background-properties').hide();
selector.find('.screenshot').slideUp();
selector.find('.remove-file').unbind().addClass('upload-button').removeClass('remove-file').val(optionsframework_l10n.upload);
// We don't display the upload button if .upload-notice is present
// This means the user doesn't have the WordPress 3.5 Media Library Support
if ( $('.section-upload .upload-notice').length > 0 ) {
$('.upload-button').remove();
}
selector.find('.upload-button').on('click', function(event) {
optionsframework_add_file(event, $(this).parents('.section'));
});
}
$('.remove-image, .remove-file').on('click', function() {
optionsframework_remove_file( $(this).parents('.section') );
});
$('.upload-button').click( function( event ) {
optionsframework_add_file(event, $(this).parents('.section'));
});
});

View File

@ -0,0 +1,71 @@
/**
* Custom scripts needed for the colorpicker, image button selectors,
* and navigation tabs.
*/
jQuery(document).ready(function($) {
// Loads the color pickers
$('.of-color').wpColorPicker();
// Image Options
$('.of-radio-img-img').click(function(){
$(this).parent().parent().find('.of-radio-img-img').removeClass('of-radio-img-selected');
$(this).addClass('of-radio-img-selected');
});
$('.of-radio-img-label').hide();
$('.of-radio-img-img').show();
$('.of-radio-img-radio').hide();
// Loads tabbed sections if they exist
if ( $('.nav-tab-wrapper').length > 0 ) {
options_framework_tabs();
}
function options_framework_tabs() {
var $group = $('.group'),
$navtabs = $('.nav-tab-wrapper a'),
active_tab = '';
// Hides all the .group sections to start
$group.hide();
// Find if a selected tab is saved in localStorage
if ( typeof(localStorage) != 'undefined' ) {
active_tab = localStorage.getItem('active_tab');
}
// If active tab is saved and exists, load it's .group
if ( active_tab != '' && $(active_tab).length ) {
$(active_tab).fadeIn();
$(active_tab + '-tab').addClass('nav-tab-active');
} else {
$('.group:first').fadeIn();
$('.nav-tab-wrapper a:first').addClass('nav-tab-active');
}
// Bind tabs clicks
$navtabs.click(function(e) {
e.preventDefault();
// Remove active class from all tabs
$navtabs.removeClass('nav-tab-active');
$(this).addClass('nav-tab-active').blur();
if (typeof(localStorage) != 'undefined' ) {
localStorage.setItem('active_tab', $(this).attr('href') );
}
var selected = $(this).attr('href');
$group.hide();
$(selected).fadeIn();
});
}
});

View File

@ -0,0 +1,94 @@
<?php
/**
* Options Framework
*
* @package Options Framework
* @author Devin Price <devin@wptheming.com>
* @license GPL-2.0+
* @link http://wptheming.com
* @copyright 2010-2014 WP Theming
*
* @wordpress-plugin
* Plugin Name: Options Framework
* Plugin URI: http://wptheming.com
* Description: A framework for building theme options.
* Version: 1.9.1
* Author: Devin Price
* Author URI: http://wptheming.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: optionsframework
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
// Don't load if optionsframework_init is already defined
if (is_admin() && ! function_exists( 'optionsframework_init' ) ) :
function optionsframework_init() {
// If user can't edit theme options, exit
if ( ! current_user_can( 'edit_theme_options' ) ) {
return;
}
// Loads the required Options Framework classes.
require plugin_dir_path( __FILE__ ) . 'includes/class-options-framework.php';
require plugin_dir_path( __FILE__ ) . 'includes/class-options-framework-admin.php';
require plugin_dir_path( __FILE__ ) . 'includes/class-options-interface.php';
require plugin_dir_path( __FILE__ ) . 'includes/class-options-media-uploader.php';
require plugin_dir_path( __FILE__ ) . 'includes/class-options-sanitization.php';
// Instantiate the options page.
$options_framework_admin = new Options_Framework_Admin;
$options_framework_admin->init();
// Instantiate the media uploader class
$options_framework_media_uploader = new Options_Framework_Media_Uploader;
$options_framework_media_uploader->init();
}
add_action( 'init', 'optionsframework_init', 20 );
endif;
/**
* Helper function to return the theme option value.
* If no value has been saved, it returns $default.
* Needed because options are saved as serialized strings.
*
* Not in a class to support backwards compatibility in themes.
*/
if ( ! function_exists( 'of_get_option' ) ) :
function of_get_option( $name, $default = false ) {
$option_name = '';
// Gets option name as defined in the theme
if ( function_exists( 'optionsframework_option_name' ) ) {
$option_name = optionsframework_option_name();
}
// Fallback option name
if ( '' == $option_name ) {
$option_name = get_option( 'stylesheet' );
$option_name = preg_replace( "/\W/", "_", strtolower( $option_name ) );
}
// Get option settings from database
$options = get_option( $option_name );
// Return specific option
if ( isset( $options[$name] ) ) {
return $options[$name];
}
return $default;
}
endif;

View File

@ -0,0 +1,126 @@
<?php
/**
* Sample implementation of the Custom Header feature
* http://codex.wordpress.org/Custom_Headers
*
* You can add an optional custom header image to header.php like so ...
*
<?php if ( get_header_image() ) : ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="">
</a>
<?php endif; // End header image check. ?>
*
* @package myoos
*/
/**
* Set up the WordPress core custom header feature.
*
* @uses myoos_header_style()
* @uses myoos_admin_header_style()
* @uses myoos_admin_header_image()
*/
function myoos_custom_header_setup() {
add_theme_support( 'custom-header', apply_filters( 'myoos_custom_header_args', array(
'default-image' => '',
'default-text-color' => '000000',
'width' => 1000,
'height' => 250,
'flex-height' => true,
'wp-head-callback' => 'myoos_header_style',
'admin-head-callback' => 'myoos_admin_header_style',
'admin-preview-callback' => 'myoos_admin_header_image',
) ) );
}
add_action( 'after_setup_theme', 'myoos_custom_header_setup' );
if ( ! function_exists( 'myoos_header_style' ) ) :
/**
* Styles the header image and text displayed on the blog
*
* @see myoos_custom_header_setup().
*/
function myoos_header_style() {
$header_text_color = get_header_textcolor();
// If no custom options for text are set, let's bail
// get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value.
if ( HEADER_TEXTCOLOR == $header_text_color ) {
return;
}
// If we get this far, we have custom styles. Let's do this.
?>
<style type="text/css">
<?php
// Has the text been hidden?
if ( 'blank' == $header_text_color ) :
?>
.site-title,
.site-description {
position: absolute;
clip: rect(1px, 1px, 1px, 1px);
}
<?php
// If the user has set a custom color for the text use that.
else :
?>
.site-title a,
.site-description {
color: #<?php echo esc_attr( $header_text_color ); ?>;
}
<?php endif; ?>
</style>
<?php
}
endif; // myoos_header_style
if ( ! function_exists( 'myoos_admin_header_style' ) ) :
/**
* Styles the header image displayed on the Appearance > Header admin panel.
*
* @see myoos_custom_header_setup().
*/
function myoos_admin_header_style() {
?>
<style type="text/css">
.appearance_page_custom-header #headimg {
border: none;
}
#headimg h1,
#desc {
}
#headimg h1 {
}
#headimg h1 a {
}
#desc {
}
#headimg img {
}
</style>
<?php
}
endif; // myoos_admin_header_style
if ( ! function_exists( 'myoos_admin_header_image' ) ) :
/**
* Custom header image markup displayed on the Appearance > Header admin panel.
*
* @see myoos_custom_header_setup().
*/
function myoos_admin_header_image() {
?>
<div id="headimg">
<h1 class="displaying-header-text">
<a id="name" style="<?php echo esc_attr( 'color: #' . get_header_textcolor() ); ?>" onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a>
</h1>
<div class="displaying-header-text" id="desc" style="<?php echo esc_attr( 'color: #' . get_header_textcolor() ); ?>"><?php bloginfo( 'description' ); ?></div>
<?php if ( get_header_image() ) : ?>
<img src="<?php header_image(); ?>" alt="">
<?php endif; ?>
</div>
<?php
}
endif; // myoos_admin_header_image

View File

@ -0,0 +1,26 @@
<?php
/**
* myoos Theme Customizer
*
* @package myoos
*/
/**
* Add postMessage support for site title and description for the Theme Customizer.
*
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
*/
function myoos_customize_register( $wp_customize ) {
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
}
add_action( 'customize_register', 'myoos_customize_register' );
/**
* Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
*/
function myoos_customize_preview_js() {
wp_enqueue_script( 'myoos_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true );
}
add_action( 'customize_preview_init', 'myoos_customize_preview_js' );

View File

@ -0,0 +1,142 @@
<?php
/**
* Custom functions that act independently of the theme templates
*
* Eventually, some of the functionality here could be replaced by core features
*
* @package myoos
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function myoos_body_classes( $classes ) {
// Adds a class of group-blog to blogs with more than 1 published author.
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
return $classes;
}
add_filter( 'body_class', 'myoos_body_classes' );
if ( version_compare( $GLOBALS['wp_version'], '4.1', '<' ) ) :
/**
* Filters wp_title to print a neat <title> tag based on what is being viewed.
*
* @param string $title Default title text for current view.
* @param string $sep Optional separator.
* @return string The filtered title.
*/
function myoos_wp_title( $title, $sep ) {
if ( is_feed() ) {
return $title;
}
global $page, $paged;
// Add the blog name.
$title .= get_bloginfo( 'name', 'display' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title .= " $sep $site_description";
}
// Add a page number if necessary.
if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
$title .= " $sep " . sprintf( esc_html__( 'Page %s', 'myoos' ), max( $paged, $page ) );
}
return $title;
}
add_filter( 'wp_title', 'myoos_wp_title', 10, 2 );
/**
* Title shim for sites older than WordPress 4.1.
*
* @link https://make.wordpress.org/core/2014/10/29/title-tags-in-4-1/
* @todo Remove this function when WordPress 4.3 is released.
*/
function myoos_render_title() {
?>
<title><?php wp_title( '|', true, 'right' ); ?></title>
<?php
}
add_action( 'wp_head', 'myoos_render_title' );
endif;
if ( ! function_exists( 'sparkling_featured_slider' ) ) :
/**
* Featured image slider, displayed on front page for static page and blog
*/
function sparkling_featured_slider() {
if ( is_front_page() && of_get_option( 'myoos_slider_checkbox' ) == 1 ) {
echo '<div class="flexslider">';
echo ' <ul class="slides">';
$count = of_get_option( 'myoos_slide_number' );
$slidecat =of_get_option( 'myoos_slide_categories' );
$query = new WP_Query( array( 'cat' =>$slidecat,'posts_per_page' =>$count ) );
if ($query->have_posts()) :
while ($query->have_posts()) : $query->the_post();
if ( (function_exists( 'has_post_thumbnail' )) && ( has_post_thumbnail() ) ) :
echo '<li><a href="'. get_permalink() .'">';
echo get_the_post_thumbnail();
echo '<div class="flex-caption">';
if ( get_the_title() != '' ) echo '<h2 class="entry-title">'. get_the_title().'</h2>';
if ( get_the_excerpt() != '' ) echo '<div class="excerpt">' . get_the_excerpt() .'</div>';
echo '</div>';
echo '</a></li>';
endif;
endwhile;
endif;
echo ' </ul>';
echo '</div>';
}
}
endif;
/*
* This one shows/hides the an option when a checkbox is clicked.
*/
add_action( 'optionsframework_custom_scripts', 'optionsframework_custom_scripts' );
function optionsframework_custom_scripts() { ?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#myoos_slider_checkbox').click(function() {
jQuery('#section-myoos_slide_categories').fadeToggle(400);
});
if (jQuery('#myoos_slider_checkbox:checked').val() !== undefined) {
jQuery('#section-myoos_slide_categories').show();
}
jQuery('#myoos_slider_checkbox').click(function() {
jQuery('#section-myoos_slide_number').fadeToggle(400);
});
if (jQuery('#myoos_slider_checkbox:checked').val() !== undefined) {
jQuery('#section-myoos_slide_number').show();
}
});
</script>
<?php
}

View File

@ -0,0 +1,30 @@
<?php
/**
* Jetpack Compatibility File
* See: https://jetpack.me/
*
* @package myoos
*/
/**
* Add theme support for Infinite Scroll.
* See: https://jetpack.me/support/infinite-scroll/
*/
function myoos_jetpack_setup() {
add_theme_support( 'infinite-scroll', array(
'container' => 'main',
'render' => 'myoos_infinite_scroll_render',
'footer' => 'page',
) );
} // end function myoos_jetpack_setup
add_action( 'after_setup_theme', 'myoos_jetpack_setup' );
/**
* Custom render function for Infinite Scroll.
*/
function myoos_infinite_scroll_render() {
while ( have_posts() ) {
the_post();
get_template_part( 'template-parts/content', get_post_format() );
}
} // end function myoos_infinite_scroll_render

View File

@ -0,0 +1,266 @@
<?php
/**
* Custom template tags for this theme.
*
* Eventually, some of the functionality here could be replaced by core features.
*
* @package myoos
*/
if ( ! function_exists( 'the_posts_navigation' ) ) :
/**
* Display navigation to next/previous set of posts when applicable.
*
* @todo Remove this function when WordPress 4.3 is released.
*/
function the_posts_navigation() {
// Don't print empty markup if there's only one page.
if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
return;
}
?>
<nav class="navigation posts-navigation" role="navigation">
<h2 class="screen-reader-text"><?php esc_html_e( 'Posts navigation', 'myoos' ); ?></h2>
<div class="nav-links">
<?php if ( get_next_posts_link() ) : ?>
<div class="nav-previous"><?php next_posts_link( esc_html__( 'Older posts', 'myoos' ) ); ?></div>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<div class="nav-next"><?php previous_posts_link( esc_html__( 'Newer posts', 'myoos' ) ); ?></div>
<?php endif; ?>
</div><!-- .nav-links -->
</nav><!-- .navigation -->
<?php
}
endif;
if ( ! function_exists( 'the_post_navigation' ) ) :
/**
* Display navigation to next/previous post when applicable.
*
* @todo Remove this function when WordPress 4.3 is released.
*/
function the_post_navigation() {
// Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous ) {
return;
}
?>
<nav class="navigation post-navigation" role="navigation">
<h2 class="screen-reader-text"><?php esc_html_e( 'Post navigation', 'myoos' ); ?></h2>
<div class="nav-links">
<?php
previous_post_link( '<div class="nav-previous">%link</div>', '%title' );
next_post_link( '<div class="nav-next">%link</div>', '%title' );
?>
</div><!-- .nav-links -->
</nav><!-- .navigation -->
<?php
}
endif;
if ( ! function_exists( 'myoos_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function myoos_posted_on() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf(
esc_html_x( 'Posted on %s', 'post date', 'myoos' ),
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
);
$byline = sprintf(
esc_html_x( 'by %s', 'post author', 'myoos' ),
'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
);
echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.
}
endif;
if ( ! function_exists( 'myoos_entry_footer' ) ) :
/**
* Prints HTML with meta information for the categories, tags and comments.
*/
function myoos_entry_footer() {
// Hide category and tag text for pages.
if ( 'post' == get_post_type() ) {
/* translators: used between list items, there is a space after the comma */
$categories_list = get_the_category_list( esc_html__( ', ', 'myoos' ) );
if ( $categories_list && myoos_categorized_blog() ) {
printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s', 'myoos' ) . '</span>', $categories_list ); // WPCS: XSS OK.
}
/* translators: used between list items, there is a space after the comma */
$tags_list = get_the_tag_list( '', esc_html__( ', ', 'myoos' ) );
if ( $tags_list ) {
printf( '<span class="tags-links">' . esc_html__( 'Tagged %1$s', 'myoos' ) . '</span>', $tags_list ); // WPCS: XSS OK.
}
}
if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
echo '<span class="comments-link">';
comments_popup_link( esc_html__( 'Leave a comment', 'myoos' ), esc_html__( '1 Comment', 'myoos' ), esc_html__( '% Comments', 'myoos' ) );
echo '</span>';
}
edit_post_link( esc_html__( 'Edit', 'myoos' ), '<span class="edit-link">', '</span>' );
}
endif;
if ( ! function_exists( 'the_archive_title' ) ) :
/**
* Shim for `the_archive_title()`.
*
* Display the archive title based on the queried object.
*
* @todo Remove this function when WordPress 4.3 is released.
*
* @param string $before Optional. Content to prepend to the title. Default empty.
* @param string $after Optional. Content to append to the title. Default empty.
*/
function the_archive_title( $before = '', $after = '' ) {
if ( is_category() ) {
$title = sprintf( esc_html__( 'Category: %s', 'myoos' ), single_cat_title( '', false ) );
} elseif ( is_tag() ) {
$title = sprintf( esc_html__( 'Tag: %s', 'myoos' ), single_tag_title( '', false ) );
} elseif ( is_author() ) {
$title = sprintf( esc_html__( 'Author: %s', 'myoos' ), '<span class="vcard">' . get_the_author() . '</span>' );
} elseif ( is_year() ) {
$title = sprintf( esc_html__( 'Year: %s', 'myoos' ), get_the_date( esc_html_x( 'Y', 'yearly archives date format', 'myoos' ) ) );
} elseif ( is_month() ) {
$title = sprintf( esc_html__( 'Month: %s', 'myoos' ), get_the_date( esc_html_x( 'F Y', 'monthly archives date format', 'myoos' ) ) );
} elseif ( is_day() ) {
$title = sprintf( esc_html__( 'Day: %s', 'myoos' ), get_the_date( esc_html_x( 'F j, Y', 'daily archives date format', 'myoos' ) ) );
} elseif ( is_tax( 'post_format' ) ) {
if ( is_tax( 'post_format', 'post-format-aside' ) ) {
$title = esc_html_x( 'Asides', 'post format archive title', 'myoos' );
} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
$title = esc_html_x( 'Galleries', 'post format archive title', 'myoos' );
} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
$title = esc_html_x( 'Images', 'post format archive title', 'myoos' );
} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
$title = esc_html_x( 'Videos', 'post format archive title', 'myoos' );
} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
$title = esc_html_x( 'Quotes', 'post format archive title', 'myoos' );
} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
$title = esc_html_x( 'Links', 'post format archive title', 'myoos' );
} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
$title = esc_html_x( 'Statuses', 'post format archive title', 'myoos' );
} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
$title = esc_html_x( 'Audio', 'post format archive title', 'myoos' );
} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
$title = esc_html_x( 'Chats', 'post format archive title', 'myoos' );
}
} elseif ( is_post_type_archive() ) {
$title = sprintf( esc_html__( 'Archives: %s', 'myoos' ), post_type_archive_title( '', false ) );
} elseif ( is_tax() ) {
$tax = get_taxonomy( get_queried_object()->taxonomy );
/* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
$title = sprintf( esc_html__( '%1$s: %2$s', 'myoos' ), $tax->labels->singular_name, single_term_title( '', false ) );
} else {
$title = esc_html__( 'Archives', 'myoos' );
}
/**
* Filter the archive title.
*
* @param string $title Archive title to be displayed.
*/
$title = apply_filters( 'get_the_archive_title', $title );
if ( ! empty( $title ) ) {
echo $before . $title . $after; // WPCS: XSS OK.
}
}
endif;
if ( ! function_exists( 'the_archive_description' ) ) :
/**
* Shim for `the_archive_description()`.
*
* Display category, tag, or term description.
*
* @todo Remove this function when WordPress 4.3 is released.
*
* @param string $before Optional. Content to prepend to the description. Default empty.
* @param string $after Optional. Content to append to the description. Default empty.
*/
function the_archive_description( $before = '', $after = '' ) {
$description = apply_filters( 'get_the_archive_description', term_description() );
if ( ! empty( $description ) ) {
/**
* Filter the archive description.
*
* @see term_description()
*
* @param string $description Archive description to be displayed.
*/
echo $before . $description . $after; // WPCS: XSS OK.
}
}
endif;
/**
* Returns true if a blog has more than 1 category.
*
* @return bool
*/
function myoos_categorized_blog() {
if ( false === ( $all_the_cool_cats = get_transient( 'myoos_categories' ) ) ) {
// Create an array of all the categories that are attached to posts.
$all_the_cool_cats = get_categories( array(
'fields' => 'ids',
'hide_empty' => 1,
// We only need to know if there is more than one category.
'number' => 2,
) );
// Count the number of categories that are attached to the posts.
$all_the_cool_cats = count( $all_the_cool_cats );
set_transient( 'myoos_categories', $all_the_cool_cats );
}
if ( $all_the_cool_cats > 1 ) {
// This blog has more than 1 category so myoos_categorized_blog should return true.
return true;
} else {
// This blog has only 1 category so myoos_categorized_blog should return false.
return false;
}
}
/**
* Flush out the transients used in myoos_categorized_blog.
*/
function myoos_category_transient_flusher() {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Like, beat it. Dig?
delete_transient( 'myoos_categories' );
}
add_action( 'edit_category', 'myoos_category_transient_flusher' );
add_action( 'save_post', 'myoos_category_transient_flusher' );

View File

@ -0,0 +1,223 @@
<?php
/**
* WP Bootstrap Navwalker
*
* @package WP-Bootstrap-Navwalker
*/
/**
* Class Name: WP_Bootstrap_Navwalker
* Plugin Name: WP Bootstrap Navwalker
* Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-navwalker
* Description: A custom WordPress nav walker class to implement the Bootstrap 3 navigation style in a custom theme using the WordPress built in menu manager.
* Author: Edward McIntyre - @twittem, WP Bootstrap, William Patton - @pattonwebz
* Version: 3.0.0
* Author URI: https://github.com/wp-bootstrap
* GitHub Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-navwalker
* GitHub Branch: master
* License: GPL-3.0+
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
*/
/* Check if Class Exists. */
if ( ! class_exists( 'WP_Bootstrap_Navwalker' ) ) {
/**
* WP_Bootstrap_Navwalker class.
*
* @extends Walker_Nav_Menu
*/
class WP_Bootstrap_Navwalker extends Walker_Nav_Menu {
/**
* Start Level.
*
* @see Walker::start_lvl()
* @since 3.0.0
*
* @access public
* @param mixed $output Passed by reference. Used to append additional content.
* @param int $depth (default: 0) Depth of page. Used for padding.
* @param array $args (default: array()) Arguments.
* @return void
*/
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul role=\"menu\" class=\" dropdown-menu\" >\n";
}
/**
* Start El.
*
* @see Walker::start_el()
* @since 3.0.0
*
* @access public
* @param mixed $output Passed by reference. Used to append additional content.
* @param mixed $item Menu item data object.
* @param int $depth (default: 0) Depth of menu item. Used for padding.
* @param array $args (default: array()) Arguments.
* @param int $id (default: 0) Menu item ID.
* @return void
*/
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
/**
* Dividers, Headers or Disabled
* =============================
* Determine whether the item is a Divider, Header, Disabled or regular
* menu item. To prevent errors we use the strcasecmp() function to so a
* comparison that is not case sensitive. The strcasecmp() function returns
* a 0 if the strings are equal.
*/
if ( 0 === strcasecmp( $item->attr_title, 'divider' ) && 1 === $depth ) {
$output .= $indent . '<li role="presentation" class="divider">';
} elseif ( 0 === strcasecmp( $item->title, 'divider' ) && 1 === $depth ) {
$output .= $indent . '<li role="presentation" class="divider">';
} elseif ( 0 === strcasecmp( $item->attr_title, 'dropdown-header' ) && 1 === $depth ) {
$output .= $indent . '<li role="presentation" class="dropdown-header">' . esc_attr( $item->title );
} elseif ( 0 === strcasecmp( $item->attr_title, 'disabled' ) ) {
$output .= $indent . '<li role="presentation" class="disabled"><a href="#">' . esc_attr( $item->title ) . '</a>';
} else {
$value = '';
$class_names = $value;
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
if ( $args->has_children ) {
$class_names .= ' dropdown';
}
if ( in_array( 'current-menu-item', $classes, true ) ) {
$class_names .= ' active';
}
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
$output .= $indent . '<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement"' . $id . $value . $class_names . '>';
$atts = array();
if ( empty( $item->attr_title ) ) {
$atts['title'] = ! empty( $item->title ) ? strip_tags( $item->title ) : '';
} else {
$atts['title'] = $item->attr_title;
}
$atts['target'] = ! empty( $item->target ) ? $item->target : '';
$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
// If item has_children add atts to a.
if ( $args->has_children && 0 === $depth ) {
$atts['href'] = '#';
$atts['data-toggle'] = 'dropdown';
$atts['class'] = 'dropdown-toggle';
$atts['aria-haspopup'] = 'true';
} else {
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
}
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args );
$attributes = '';
foreach ( $atts as $attr => $value ) {
if ( ! empty( $value ) ) {
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}
$item_output = $args->before;
/*
* Glyphicons/Font-Awesome
* ===========
* Since the the menu item is NOT a Divider or Header we check the see
* if there is a value in the attr_title property. If the attr_title
* property is NOT null we apply it as the class name for the glyphicon.
*/
if ( ! empty( $item->attr_title ) ) {
$pos = strpos( esc_attr( $item->attr_title ), 'glyphicon' );
if ( false !== $pos ) {
$item_output .= '<a' . $attributes . '><span class="glyphicon ' . esc_attr( $item->attr_title ) . '" aria-hidden="true"></span>&nbsp;';
} else {
$item_output .= '<a' . $attributes . '><i class="fa ' . esc_attr( $item->attr_title ) . '" aria-hidden="true"></i>&nbsp;';
}
} else {
$item_output .= '<a' . $attributes . '>';
}
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= ( $args->has_children && 0 === $depth ) ? ' <span class="caret"></span></a>' : '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
} // End if().
}
/**
* Traverse elements to create list from elements.
*
* Display one element if the element doesn't have any children otherwise,
* display the element and its children. Will only traverse up to the max
* depth and no ignore elements under that depth.
*
* This method shouldn't be called directly, use the walk() method instead.
*
* @see Walker::start_el()
* @since 2.5.0
*
* @access public
* @param mixed $element Data object.
* @param mixed $children_elements List of elements to continue traversing.
* @param mixed $max_depth Max depth to traverse.
* @param mixed $depth Depth of current element.
* @param mixed $args Arguments.
* @param mixed $output Passed by reference. Used to append additional content.
* @return null Null on failure with no changes to parameters.
*/
public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
if ( ! $element ) {
return; }
$id_field = $this->db_fields['id'];
// Display this element.
if ( is_object( $args[0] ) ) {
$args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); }
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
}
/**
* Menu Fallback
* =============
* If this function is assigned to the wp_nav_menu's fallback_cb variable
* and a menu has not been assigned to the theme location in the WordPress
* menu manager the function with display nothing to a non-logged in user,
* and will add a link to the WordPress menu manager if logged in as an admin.
*
* @param array $args passed from the wp_nav_menu function.
*/
public static function fallback( $args ) {
if ( current_user_can( 'edit_theme_options' ) ) {
/* Get Arguments. */
$container = $args['container'];
$container_id = $args['container_id'];
$container_class = $args['container_class'];
$menu_class = $args['menu_class'];
$menu_id = $args['menu_id'];
if ( $container ) {
echo '<' . esc_attr( $container );
if ( $container_id ) {
echo ' id="' . esc_attr( $container_id ) . '"';
}
if ( $container_class ) {
echo ' class="' . esc_attr( $container_class ) . '"'; }
echo '>';
}
echo '<ul';
if ( $menu_id ) {
echo ' id="' . esc_attr( $menu_id ) . '"'; }
if ( $menu_class ) {
echo ' class="' . esc_attr( $menu_class ) . '"'; }
echo '>';
echo '<li><a href="' . esc_url( admin_url( 'nav-menus.php' ) ) . '" title="">' . esc_attr( 'Add a menu', '' ) . '</a></li>';
echo '</ul>';
if ( $container ) {
echo '</' . esc_attr( $container ) . '>'; }
}
}
}
} // End if().

View File

@ -0,0 +1,29 @@
<?php
/**
* WordPress.com-specific functions and definitions.
*
* This file is centrally included from `wp-content/mu-plugins/wpcom-theme-compat.php`.
*
* @package _s
*/
/**
* Adds support for wp.com-specific theme functions.
*
* @global array $themecolors
*/
function _s_wpcom_setup() {
global $themecolors;
// Set theme colors for third party services.
if ( ! isset( $themecolors ) ) {
$themecolors = array(
'bg' => '',
'border' => '',
'text' => '',
'link' => '',
'url' => '',
);
}
}
add_action( 'after_setup_theme', '_s_wpcom_setup' );