first commit
This commit is contained in:
@@ -0,0 +1,305 @@
|
||||
<?php
|
||||
/**
|
||||
* OptionTree Meta Box.
|
||||
*
|
||||
* @package OptionTree
|
||||
*/
|
||||
|
||||
if ( ! defined( 'OT_VERSION' ) ) {
|
||||
exit( 'No direct script access allowed' );
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'OT_Meta_Box' ) ) {
|
||||
|
||||
/**
|
||||
* OptionTree Meta Box class.
|
||||
*
|
||||
* This class loads all the methods and helpers specific to build a meta box.
|
||||
*/
|
||||
class OT_Meta_Box {
|
||||
|
||||
/**
|
||||
* Stores the meta box config array.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $meta_box;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* This method adds other methods of the class to specific hooks within WordPress.
|
||||
*
|
||||
* @uses add_action()
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
*
|
||||
* @param array $meta_box Meta box config array.
|
||||
*/
|
||||
public function __construct( $meta_box ) {
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $ot_meta_boxes;
|
||||
|
||||
if ( ! isset( $ot_meta_boxes ) ) {
|
||||
$ot_meta_boxes = array();
|
||||
}
|
||||
|
||||
$ot_meta_boxes[] = $meta_box;
|
||||
|
||||
$this->meta_box = $meta_box;
|
||||
|
||||
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
|
||||
|
||||
add_action( 'save_post', array( $this, 'save_meta_box' ), 1, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds meta box to any post type
|
||||
*
|
||||
* @uses add_meta_box()
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
*/
|
||||
public function add_meta_boxes() {
|
||||
global $wp_version;
|
||||
|
||||
$is_wp_5 = version_compare( $wp_version, '5.0', '>=' );
|
||||
|
||||
foreach ( (array) $this->meta_box['pages'] as $page ) {
|
||||
add_meta_box( $this->meta_box['id'], $this->meta_box['title'], array( $this, 'build_meta_box' ), $page, $this->meta_box['context'], $this->meta_box['priority'], $this->meta_box['fields'] );
|
||||
|
||||
if ( $is_wp_5 ) {
|
||||
add_filter(
|
||||
'postbox_classes_' . $page . '_' . $this->meta_box['id'],
|
||||
function( $classes ) {
|
||||
array_push( $classes, 'ot-meta-box' );
|
||||
return $classes;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Meta box view.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
*
|
||||
* @param object $post The WP_Post object.
|
||||
* @param array $fields The meta box fields.
|
||||
*/
|
||||
public function build_meta_box( $post, $fields ) {
|
||||
unset( $fields ); // @todo Check if the loop can use this param.
|
||||
|
||||
echo '<div class="ot-metabox-wrapper">';
|
||||
|
||||
// Use nonce for verification.
|
||||
echo '<input type="hidden" name="' . esc_attr( $this->meta_box['id'] ) . '_nonce" value="' . esc_attr( wp_create_nonce( $this->meta_box['id'] ) ) . '" />';
|
||||
|
||||
// Meta box description.
|
||||
echo isset( $this->meta_box['desc'] ) && ! empty( $this->meta_box['desc'] ) ? '<div class="description" style="padding-top:10px;">' . htmlspecialchars_decode( $this->meta_box['desc'] ) . '</div>' : ''; // phpcs:ignore
|
||||
|
||||
// Loop through meta box fields.
|
||||
foreach ( $this->meta_box['fields'] as $field ) {
|
||||
|
||||
// Get current post meta data.
|
||||
$field_value = get_post_meta( $post->ID, $field['id'], true );
|
||||
|
||||
// Set standard value.
|
||||
if ( isset( $field['std'] ) ) {
|
||||
$field_value = ot_filter_std_value( $field_value, $field['std'] );
|
||||
}
|
||||
|
||||
// Build the arguments array.
|
||||
$_args = array(
|
||||
'type' => $field['type'],
|
||||
'field_id' => $field['id'],
|
||||
'field_name' => $field['id'],
|
||||
'field_value' => $field_value,
|
||||
'field_desc' => isset( $field['desc'] ) ? $field['desc'] : '',
|
||||
'field_std' => isset( $field['std'] ) ? $field['std'] : '',
|
||||
'field_rows' => isset( $field['rows'] ) && ! empty( $field['rows'] ) ? $field['rows'] : 10,
|
||||
'field_post_type' => isset( $field['post_type'] ) && ! empty( $field['post_type'] ) ? $field['post_type'] : 'post',
|
||||
'field_taxonomy' => isset( $field['taxonomy'] ) && ! empty( $field['taxonomy'] ) ? $field['taxonomy'] : 'category',
|
||||
'field_min_max_step' => isset( $field['min_max_step'] ) && ! empty( $field['min_max_step'] ) ? $field['min_max_step'] : '0,100,1',
|
||||
'field_class' => isset( $field['class'] ) ? $field['class'] : '',
|
||||
'field_condition' => isset( $field['condition'] ) ? $field['condition'] : '',
|
||||
'field_operator' => isset( $field['operator'] ) ? $field['operator'] : 'and',
|
||||
'field_choices' => isset( $field['choices'] ) ? $field['choices'] : array(),
|
||||
'field_settings' => isset( $field['settings'] ) && ! empty( $field['settings'] ) ? $field['settings'] : array(),
|
||||
'post_id' => $post->ID,
|
||||
'meta' => true,
|
||||
);
|
||||
|
||||
$conditions = '';
|
||||
|
||||
// Setup the conditions.
|
||||
if ( isset( $field['condition'] ) && ! empty( $field['condition'] ) ) {
|
||||
$conditions = ' data-condition="' . esc_attr( $field['condition'] ) . '"';
|
||||
$conditions .= isset( $field['operator'] ) && in_array( $field['operator'], array( 'and', 'AND', 'or', 'OR' ), true ) ? ' data-operator="' . esc_attr( $field['operator'] ) . '"' : '';
|
||||
}
|
||||
|
||||
// Only allow simple textarea due to DOM issues with wp_editor().
|
||||
if ( false === apply_filters( 'ot_override_forced_textarea_simple', false, $field['id'] ) && 'textarea' === $_args['type'] ) {
|
||||
$_args['type'] = 'textarea-simple';
|
||||
}
|
||||
|
||||
// Build the setting CSS class.
|
||||
if ( ! empty( $_args['field_class'] ) ) {
|
||||
|
||||
$classes = explode( ' ', $_args['field_class'] );
|
||||
|
||||
foreach ( $classes as $key => $value ) {
|
||||
|
||||
$classes[ $key ] = $value . '-wrap';
|
||||
|
||||
}
|
||||
|
||||
$class = 'format-settings ' . implode( ' ', $classes );
|
||||
} else {
|
||||
|
||||
$class = 'format-settings';
|
||||
}
|
||||
|
||||
// Option label.
|
||||
echo '<div id="setting_' . esc_attr( $field['id'] ) . '" class="' . esc_attr( $class ) . '"' . $conditions . '>'; // phpcs:ignore
|
||||
|
||||
echo '<div class="format-setting-wrap">';
|
||||
|
||||
// Don't show title with textblocks.
|
||||
if ( 'textblock' !== $_args['type'] && ! empty( $field['label'] ) ) {
|
||||
echo '<div class="format-setting-label">';
|
||||
// @hu_custom: allow html in the label field
|
||||
echo '<label for="' . esc_attr( $field['id'] ) . '" class="label">' . $field['label'] . '</label>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
// Get the option HTML.
|
||||
echo ot_display_by_type( $_args ); // phpcs:ignore
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo '<div class="clear"></div>';
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the meta box values
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
*
|
||||
* @param int $post_id The post ID.
|
||||
* @param object $post_object The WP_Post object.
|
||||
* @return int|void
|
||||
*/
|
||||
public function save_meta_box( $post_id, $post_object ) {
|
||||
global $pagenow;
|
||||
|
||||
// Verify nonce.
|
||||
if ( !isset( $_POST[ $this->meta_box['id'] . '_nonce' ] ) || !wp_verify_nonce( $_POST[ $this->meta_box['id'] . '_nonce' ], $this->meta_box['id'] ) ) { // phpcs:ignore
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
// Store the post global for use later.
|
||||
$post_global = $_POST;
|
||||
|
||||
// Don't save if $_POST is empty.
|
||||
if ( empty( $post_global ) || ( isset( $post_global['vc_inline'] ) && true === $post_global['vc_inline'] ) ) {
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
// Don't save during quick edit.
|
||||
if ( 'admin-ajax.php' === $pagenow ) {
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
// Don't save during autosave.
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
// Don't save if viewing a revision.
|
||||
if ( 'revision' === $post_object->post_type || 'revision.php' === $pagenow ) {
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
// Check permissions.
|
||||
if ( isset( $post_global['post_type'] ) && 'page' === $post_global['post_type'] ) {
|
||||
if ( ! current_user_can( 'edit_page', $post_id ) ) {
|
||||
return $post_id;
|
||||
}
|
||||
} else {
|
||||
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
||||
return $post_id;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $this->meta_box['fields'] as $field ) {
|
||||
|
||||
$old = get_post_meta( $post_id, $field['id'], true );
|
||||
$new = '';
|
||||
|
||||
// There is data to validate.
|
||||
if ( isset( $post_global[ $field['id'] ] ) ) {
|
||||
// Run through validation.
|
||||
$new = ot_validate_setting( $post_global[ $field['id'] ], $field['type'], $field['id'] );
|
||||
|
||||
// Insert CSS.
|
||||
if ( 'css' === $field['type'] ) {
|
||||
|
||||
if ( '' !== $new ) {
|
||||
|
||||
// insert CSS into dynamic.css.
|
||||
ot_insert_css_with_markers( $field['id'], $new, true );
|
||||
} else {
|
||||
|
||||
// Remove old CSS from dynamic.css.
|
||||
ot_remove_old_css( $field['id'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $new ) && $new !== $old ) {
|
||||
update_post_meta( $post_id, $field['id'], $new );
|
||||
} elseif ( '' === $new && $old ) {
|
||||
delete_post_meta( $post_id, $field['id'], $old );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'ot_register_meta_box' ) ) {
|
||||
|
||||
/**
|
||||
* This method instantiates the meta box class & builds the UI.
|
||||
*
|
||||
* @uses OT_Meta_Box()
|
||||
*
|
||||
* @param array $args Meta box arguments.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0
|
||||
*/
|
||||
function ot_register_meta_box( $args ) {
|
||||
if ( ! $args ) {
|
||||
return;
|
||||
}
|
||||
|
||||
new OT_Meta_Box( $args );
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
/**
|
||||
* OptionTree Compatibility Functions.
|
||||
*
|
||||
* @package OptionTree
|
||||
*/
|
||||
|
||||
if ( ! defined( 'OT_VERSION' ) ) {
|
||||
exit( 'No direct script access allowed' );
|
||||
}
|
||||
|
||||
// Run the actions & filters.
|
||||
add_filter( 'ot_option_types_array', 'compat_ot_option_types_array', 10, 1 );
|
||||
add_filter( 'ot_recognized_font_styles', 'compat_ot_recognized_font_styles', 10, 2 );
|
||||
add_filter( 'ot_recognized_font_weights', 'compat_ot_recognized_font_weights', 10, 2 );
|
||||
add_filter( 'ot_recognized_font_variants', 'compat_ot_recognized_font_variants', 10, 2 );
|
||||
add_filter( 'ot_recognized_font_families', 'compat_ot_recognized_font_families', 10, 2 );
|
||||
add_filter( 'ot_recognized_background_repeat', 'compat_ot_recognized_background_repeat', 10, 2 );
|
||||
add_filter( 'ot_recognized_background_position', 'compat_ot_recognized_background_position', 10, 2 );
|
||||
add_filter( 'ot_measurement_unit_types', 'compat_ot_measurement_unit_types', 10, 2 );
|
||||
|
||||
|
||||
if ( ! function_exists( 'compat_ot_option_types_array' ) ) {
|
||||
|
||||
/**
|
||||
* Filters the option types array.
|
||||
*
|
||||
* Allows the old 'option_tree_option_types' filter to
|
||||
* change the new 'ot_option_types_array' return value.
|
||||
*
|
||||
* @param array $array The option types in key:value format.
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0
|
||||
*/
|
||||
function compat_ot_option_types_array( $array ) {
|
||||
|
||||
return apply_filters( 'option_tree_option_types', $array );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'compat_ot_recognized_font_styles' ) ) {
|
||||
|
||||
/**
|
||||
* Filters the recognized font styles array.
|
||||
*
|
||||
* Allows the old 'recognized_font_styles' filter to
|
||||
* change the new 'ot_recognized_font_styles' return value.
|
||||
*
|
||||
* @param array $array The option types in key:value format.
|
||||
* @param string $id The field ID.
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0
|
||||
*/
|
||||
function compat_ot_recognized_font_styles( $array, $id ) {
|
||||
|
||||
return apply_filters( 'recognized_font_styles', $array, $id );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'compat_ot_recognized_font_weights' ) ) {
|
||||
|
||||
/**
|
||||
* Filters the recognized font weights array.
|
||||
*
|
||||
* Allows the old 'recognized_font_weights' filter to
|
||||
* change the new 'ot_recognized_font_weights' return value.
|
||||
*
|
||||
* @param array $array The option types in key:value format.
|
||||
* @param string $id The field ID.
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0
|
||||
*/
|
||||
function compat_ot_recognized_font_weights( $array, $id ) {
|
||||
|
||||
return apply_filters( 'recognized_font_weights', $array, $id );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'compat_ot_recognized_font_variants' ) ) {
|
||||
|
||||
/**
|
||||
* Filters the recognized font variants array.
|
||||
*
|
||||
* Allows the old 'recognized_font_variants' filter to
|
||||
* change the new 'ot_recognized_font_variants' return value.
|
||||
*
|
||||
* @param array $array The option types in key:value format.
|
||||
* @param string $id The field ID.
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0
|
||||
*/
|
||||
function compat_ot_recognized_font_variants( $array, $id ) {
|
||||
|
||||
return apply_filters( 'recognized_font_variants', $array, $id );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'compat_ot_recognized_font_families' ) ) {
|
||||
|
||||
/**
|
||||
* Filters the recognized font families array.
|
||||
*
|
||||
* Allows the old 'recognized_font_families' filter to
|
||||
* change the new 'ot_recognized_font_families' return value.
|
||||
*
|
||||
* @param array $array The option types in key:value format.
|
||||
* @param string $id The field ID.
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0
|
||||
*/
|
||||
function compat_ot_recognized_font_families( $array, $id ) {
|
||||
|
||||
return apply_filters( 'recognized_font_families', $array, $id );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'compat_ot_recognized_background_repeat' ) ) {
|
||||
|
||||
/**
|
||||
* Filters the recognized background repeat array.
|
||||
*
|
||||
* Allows the old 'recognized_background_repeat' filter to
|
||||
* change the new 'ot_recognized_background_repeat' return value.
|
||||
*
|
||||
* @param array $array The option types in key:value format.
|
||||
* @param string $id The field ID.
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0
|
||||
*/
|
||||
function compat_ot_recognized_background_repeat( $array, $id ) {
|
||||
|
||||
return apply_filters( 'recognized_background_repeat', $array, $id );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'compat_ot_recognized_background_position' ) ) {
|
||||
|
||||
/**
|
||||
* Filters the recognized background position array.
|
||||
*
|
||||
* Allows the old 'recognized_background_position' filter to
|
||||
* change the new 'ot_recognized_background_position' return value.
|
||||
*
|
||||
* @param array $array The option types in key:value format.
|
||||
* @param string $id The field ID.
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0
|
||||
*/
|
||||
function compat_ot_recognized_background_position( $array, $id ) {
|
||||
|
||||
return apply_filters( 'recognized_background_position', $array, $id );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'compat_ot_measurement_unit_types' ) ) {
|
||||
|
||||
/**
|
||||
* Filters the measurement unit types array.
|
||||
*
|
||||
* Allows the old 'measurement_unit_types' filter to
|
||||
* change the new 'ot_measurement_unit_types' return value.
|
||||
*
|
||||
* @param array $array The option types in key:value format.
|
||||
* @param string $id The field ID.
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0
|
||||
*/
|
||||
function compat_ot_measurement_unit_types( $array, $id ) {
|
||||
|
||||
return apply_filters( 'measurement_unit_types', $array, $id );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* OptionTree Deprecated Functions.
|
||||
*
|
||||
* @package OptionTree
|
||||
*/
|
||||
|
||||
if ( ! defined( 'OT_VERSION' ) ) {
|
||||
exit( 'No direct script access allowed' );
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'get_option_tree' ) ) {
|
||||
|
||||
/**
|
||||
* Displays or returns a value from the 'option_tree' array.
|
||||
*
|
||||
* @param string $item_id The item ID.
|
||||
* @param array $options Options array.
|
||||
* @param bool $echo Whether to echo or return value.
|
||||
* @param bool $is_array Whether the value option is an array or string.
|
||||
* @param int $offset The array key.
|
||||
* @return mixed Array or comma separated lists of values.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0.0
|
||||
* @updated 2.0
|
||||
* @deprecated 2.0
|
||||
*/
|
||||
function get_option_tree( $item_id = '', $options = array(), $echo = false, $is_array = false, $offset = -1 ) {
|
||||
|
||||
// Load saved options.
|
||||
if ( ! $options ) {
|
||||
$options = get_option( ot_options_id() );
|
||||
}
|
||||
|
||||
// No value return.
|
||||
if ( ! isset( $options[ $item_id ] ) || empty( $options[ $item_id ] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set content value & strip slashes.
|
||||
$content = option_tree_stripslashes( $options[ $item_id ] );
|
||||
|
||||
if ( true === $is_array ) {
|
||||
if ( ! is_array( $content ) ) {
|
||||
$content = explode( ',', $content );
|
||||
}
|
||||
|
||||
if ( is_numeric( $offset ) && 0 <= $offset ) {
|
||||
$content = $content[ $offset ];
|
||||
} elseif ( ! is_numeric( $offset ) && isset( $content[ $offset ] ) ) {
|
||||
$content = $content[ $offset ];
|
||||
}
|
||||
} else {
|
||||
if ( is_array( $content ) ) {
|
||||
$content = implode( ',', $content );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $echo ) {
|
||||
echo $content; // phpcs:ignore
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'option_tree_stripslashes' ) ) {
|
||||
|
||||
/**
|
||||
* Custom stripslashes from single value or array.
|
||||
*
|
||||
* @param mixed $input Input string or array.
|
||||
* @return mixed
|
||||
*
|
||||
* @access public
|
||||
* @since 1.1.3
|
||||
* @deprecated 2.0
|
||||
*/
|
||||
function option_tree_stripslashes( $input ) {
|
||||
if ( is_array( $input ) ) {
|
||||
foreach ( $input as &$val ) {
|
||||
if ( is_array( $val ) ) {
|
||||
$val = option_tree_stripslashes( $val );
|
||||
} else {
|
||||
$val = stripslashes( $val );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$input = stripslashes( $input );
|
||||
}
|
||||
return $input;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
/**
|
||||
* OptionTree Function.
|
||||
*
|
||||
* @package OptionTree
|
||||
*/
|
||||
|
||||
if ( ! defined( 'OT_VERSION' ) ) {
|
||||
exit( 'No direct script access allowed' );
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'ot_options_id' ) ) {
|
||||
|
||||
/**
|
||||
* Theme Options ID
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @access public
|
||||
* @since 2.3.0
|
||||
*/
|
||||
function ot_options_id() {
|
||||
|
||||
return apply_filters( 'ot_options_id', 'option_tree' );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'ot_settings_id' ) ) {
|
||||
|
||||
/**
|
||||
* Theme Settings ID
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @access public
|
||||
* @since 2.3.0
|
||||
*/
|
||||
function ot_settings_id() {
|
||||
|
||||
return apply_filters( 'ot_settings_id', 'option_tree_settings' );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'ot_layouts_id' ) ) {
|
||||
|
||||
/**
|
||||
* Theme Layouts ID
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @access public
|
||||
* @since 2.3.0
|
||||
*/
|
||||
function ot_layouts_id() {
|
||||
|
||||
return apply_filters( 'ot_layouts_id', 'option_tree_layouts' );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'ot_get_option' ) ) {
|
||||
|
||||
/**
|
||||
* Get Option.
|
||||
*
|
||||
* Helper function to return the option value.
|
||||
* If no value has been saved, it returns $default.
|
||||
*
|
||||
* @param string $option_id The option ID.
|
||||
* @param string $default The default option value.
|
||||
* @return mixed
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0
|
||||
*/
|
||||
function ot_get_option( $option_id, $default = '' ) {
|
||||
|
||||
// @hu_custom Temporary hack.
|
||||
if ( ! apply_filters( 'use_option_tree' , true ) && class_exists( 'HU_utils' ) ) {
|
||||
return HU_utils::$inst->hu_opt( $option_id );
|
||||
}
|
||||
|
||||
// Get the saved options.
|
||||
$options = get_option( ot_options_id() );
|
||||
|
||||
// Look for the saved value.
|
||||
if ( isset( $options[ $option_id ] ) && '' !== $options[ $option_id ] ) {
|
||||
|
||||
return ot_wpml_filter( $options, $option_id );
|
||||
|
||||
}
|
||||
|
||||
return $default;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'ot_echo_option' ) ) {
|
||||
|
||||
/**
|
||||
* Echo Option.
|
||||
*
|
||||
* Helper function to echo the option value.
|
||||
* If no value has been saved, it echos $default.
|
||||
*
|
||||
* @param string $option_id The option ID.
|
||||
* @param string $default The default option value.
|
||||
* @return mixed
|
||||
*
|
||||
* @access public
|
||||
* @since 2.2.0
|
||||
*/
|
||||
function ot_echo_option( $option_id, $default = '' ) {
|
||||
|
||||
echo ot_get_option( $option_id, $default ); // phpcs:ignore
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'ot_wpml_filter' ) ) {
|
||||
|
||||
/**
|
||||
* Filter the return values through WPML
|
||||
*
|
||||
* @param array $options The current options.
|
||||
* @param string $option_id The option ID.
|
||||
* @return mixed
|
||||
*
|
||||
* @access public
|
||||
* @since 2.1
|
||||
*/
|
||||
function ot_wpml_filter( $options, $option_id ) {
|
||||
|
||||
// Return translated strings using WMPL.
|
||||
if ( function_exists( 'icl_t' ) ) {
|
||||
|
||||
$settings = get_option( ot_settings_id() );
|
||||
|
||||
if ( isset( $settings['settings'] ) ) {
|
||||
|
||||
foreach ( $settings['settings'] as $setting ) {
|
||||
|
||||
// List Item & Slider.
|
||||
if ( $option_id === $setting['id'] && in_array( $setting['type'], array( 'list-item', 'slider' ), true ) ) {
|
||||
|
||||
foreach ( $options[ $option_id ] as $key => $value ) {
|
||||
|
||||
foreach ( $value as $ckey => $cvalue ) {
|
||||
|
||||
$id = $option_id . '_' . $ckey . '_' . $key;
|
||||
$_string = icl_t( 'Theme Options', $id, $cvalue );
|
||||
|
||||
if ( ! empty( $_string ) ) {
|
||||
|
||||
$options[ $option_id ][ $key ][ $ckey ] = $_string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// List Item & Slider.
|
||||
} elseif ( $option_id === $setting['id'] && 'social-links' === $setting['type'] ) {
|
||||
|
||||
foreach ( $options[ $option_id ] as $key => $value ) {
|
||||
|
||||
foreach ( $value as $ckey => $cvalue ) {
|
||||
|
||||
$id = $option_id . '_' . $ckey . '_' . $key;
|
||||
$_string = icl_t( 'Theme Options', $id, $cvalue );
|
||||
|
||||
if ( ! empty( $_string ) ) {
|
||||
|
||||
$options[ $option_id ][ $key ][ $ckey ] = $_string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// All other acceptable option types.
|
||||
} elseif ( $option_id === $setting['id'] && in_array( $setting['type'], apply_filters( 'ot_wpml_option_types', array( 'text', 'textarea', 'textarea-simple' ) ), true ) ) {
|
||||
|
||||
$_string = icl_t( 'Theme Options', $option_id, $options[ $option_id ] );
|
||||
|
||||
if ( ! empty( $_string ) ) {
|
||||
|
||||
$options[ $option_id ] = $_string;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $options[ $option_id ];
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'ot_load_dynamic_css' ) ) {
|
||||
|
||||
/**
|
||||
* Enqueue the dynamic CSS.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0
|
||||
*/
|
||||
function ot_load_dynamic_css() {
|
||||
|
||||
// Don't load in the admin.
|
||||
if ( is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter whether or not to enqueue a `dynamic.css` file at the theme level.
|
||||
*
|
||||
* By filtering this to `false` OptionTree will not attempt to enqueue any CSS files.
|
||||
*
|
||||
* Example: add_filter( 'ot_load_dynamic_css', '__return_false' );
|
||||
*
|
||||
* @since 2.5.5
|
||||
*
|
||||
* @param bool $load_dynamic_css Default is `true`.
|
||||
* @return bool
|
||||
*/
|
||||
if ( false === (bool) apply_filters( 'ot_load_dynamic_css', true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Grab a copy of the paths.
|
||||
$ot_css_file_paths = get_option( 'ot_css_file_paths', array() );
|
||||
if ( is_multisite() ) {
|
||||
$ot_css_file_paths = get_blog_option( get_current_blog_id(), 'ot_css_file_paths', $ot_css_file_paths );
|
||||
}
|
||||
|
||||
if ( ! empty( $ot_css_file_paths ) ) {
|
||||
|
||||
$last_css = '';
|
||||
|
||||
// Loop through paths.
|
||||
foreach ( $ot_css_file_paths as $key => $path ) {
|
||||
|
||||
if ( '' !== $path && file_exists( $path ) ) {
|
||||
|
||||
$parts = explode( '/wp-content', $path );
|
||||
|
||||
if ( isset( $parts[1] ) ) {
|
||||
|
||||
$sub_parts = explode( '/', $parts[1] );
|
||||
|
||||
if ( isset( $sub_parts[1] ) && isset( $sub_parts[2] ) ) {
|
||||
if ( 'themes' !== $sub_parts[1] && get_stylesheet() !== $sub_parts[2] ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$css = set_url_scheme( WP_CONTENT_URL ) . $parts[1];
|
||||
|
||||
if ( $last_css !== $css ) {
|
||||
|
||||
// Enqueue filtered file.
|
||||
wp_enqueue_style( 'ot-dynamic-' . $key, $css, false, OT_VERSION );
|
||||
|
||||
$last_css = $css;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'ot_load_google_fonts_css' ) ) {
|
||||
|
||||
/**
|
||||
* Enqueue the Google Fonts CSS.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.5.0
|
||||
*/
|
||||
function ot_load_google_fonts_css() {
|
||||
|
||||
/* don't load in the admin */
|
||||
if ( is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ot_google_fonts = get_theme_mod( 'ot_google_fonts', array() );
|
||||
$ot_set_google_fonts = get_theme_mod( 'ot_set_google_fonts', array() );
|
||||
$families = array();
|
||||
$subsets = array();
|
||||
$append = '';
|
||||
|
||||
if ( ! empty( $ot_set_google_fonts ) ) {
|
||||
|
||||
foreach ( $ot_set_google_fonts as $id => $fonts ) {
|
||||
|
||||
foreach ( $fonts as $font ) {
|
||||
|
||||
// Can't find the font, bail!
|
||||
if ( ! isset( $ot_google_fonts[ $font['family'] ]['family'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Set variants & subsets.
|
||||
if ( ! empty( $font['variants'] ) && is_array( $font['variants'] ) ) {
|
||||
|
||||
// Variants string.
|
||||
$variants = ':' . implode( ',', $font['variants'] );
|
||||
|
||||
// Add subsets to array.
|
||||
if ( ! empty( $font['subsets'] ) && is_array( $font['subsets'] ) ) {
|
||||
foreach ( $font['subsets'] as $subset ) {
|
||||
$subsets[] = $subset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add family & variants to array.
|
||||
if ( isset( $variants ) ) {
|
||||
$families[] = str_replace( ' ', '+', $ot_google_fonts[ $font['family'] ]['family'] ) . $variants;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $families ) ) {
|
||||
|
||||
$families = array_unique( $families );
|
||||
|
||||
// Append all subsets to the path, unless the only subset is latin.
|
||||
if ( ! empty( $subsets ) ) {
|
||||
$subsets = implode( ',', array_unique( $subsets ) );
|
||||
if ( 'latin' !== $subsets ) {
|
||||
$append = '&subset=' . $subsets;
|
||||
}
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'ot-google-fonts', esc_url( '//fonts.googleapis.com/css?family=' . implode( '%7C', $families ) ) . $append, false, null ); // phpcs:ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'ot_register_theme_options_admin_bar_menu' ) ) {
|
||||
|
||||
/**
|
||||
* Registers the Theme Option page link for the admin bar.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.1
|
||||
*
|
||||
* @param object $wp_admin_bar The WP_Admin_Bar object.
|
||||
*/
|
||||
function ot_register_theme_options_admin_bar_menu( $wp_admin_bar ) {
|
||||
|
||||
if ( ! current_user_can( apply_filters( 'ot_theme_options_capability', 'edit_theme_options' ) ) || ! is_admin_bar_showing() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$wp_admin_bar->add_node(
|
||||
array(
|
||||
'parent' => 'appearance',
|
||||
'id' => apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ),
|
||||
'title' => apply_filters( 'ot_theme_options_page_title', __( 'Theme Options', 'hueman' ) ),
|
||||
'href' => admin_url( apply_filters( 'ot_theme_options_parent_slug', 'themes.php' ) . '?page=' . apply_filters( 'ot_theme_options_menu_slug', 'ot-theme-options' ) ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user