Import legacy nurinda.co.id website
This commit is contained in:
1 parent
3f59bb9038
commit
6e21646ac4
13389 files changed
+3246690
No files matched your search
@@ -0,0 +1,140 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
add_action( 'wp_ajax_usof_ajax_mega_menu_save_settings', 'usof_ajax_mega_menu_save_settings' );
|
||||
function usof_ajax_mega_menu_save_settings() {
|
||||
$item_id = $_POST['item'];
|
||||
$settings = $_POST['settings'];
|
||||
|
||||
if ( ! check_ajax_referer( 'usof-mega-menu-save', 'security', FALSE ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( $settings as $key => $val ) {
|
||||
if ( strip_tags( $val ) != $val ) {
|
||||
$settings[$key] = strip_tags( $val );
|
||||
}
|
||||
}
|
||||
|
||||
update_post_meta( $item_id, 'us_mega_menu_settings', $settings );
|
||||
|
||||
do_action( 'usof_ajax_mega_menu_save_settings' );
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'message' => us_translate( 'Changes saved.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_usof_ajax_mega_menu', 'usof_ajax_mega_menu' );
|
||||
function usof_ajax_mega_menu() {
|
||||
$menu_id = $_GET['menu_id'];
|
||||
$item_id = $_GET['item_id'];
|
||||
|
||||
$menu_items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'any' ) );
|
||||
|
||||
$menu_label = '';
|
||||
if ( is_array( $menu_items ) AND count( $menu_items ) > 0 ) {
|
||||
foreach ( $menu_items as $menu_item ) {
|
||||
if ( $menu_item->ID == $item_id ) {
|
||||
$menu_label = $menu_item->title;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $menu_label == '' ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$settings_config = us_config( 'mega-menu', array() );
|
||||
|
||||
?>
|
||||
<div class="usof-header">
|
||||
<h2><?php echo $menu_label; ?><span> – <?php _e( 'Dropdown Settings', 'us' ) ?></span></h2>
|
||||
<div class="usof-control for_save status_clear">
|
||||
<button class="usof-button type_save" type="button">
|
||||
<span><?php echo us_translate( 'Save Changes' ) ?></span>
|
||||
<span class="usof-preloader"></span>
|
||||
</button>
|
||||
<div class="usof-control-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="us-mm-body">
|
||||
<div class="us-mm-settings" id="section_settings">
|
||||
<?php
|
||||
|
||||
$values = ( get_post_meta( $item_id, 'us_mega_menu_settings', TRUE ) ) ? get_post_meta( $item_id, 'us_mega_menu_settings', TRUE ) : array();
|
||||
foreach ( $settings_config as $field_id => $field ) {
|
||||
if ( ! isset( $values[$field_id] ) AND isset( $field['std'] ) ) {
|
||||
$values[$field_id] = $field['std'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $settings_config as $field_id => $field ) {
|
||||
us_load_template(
|
||||
'vendor/usof/templates/field', array(
|
||||
'name' => $field_id,
|
||||
'id' => 'usof_' . $field_id,
|
||||
'field' => $field,
|
||||
'values' => &$values,
|
||||
)
|
||||
);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
jQuery(function ($) {
|
||||
$('#TB_window').addClass('usof-container');
|
||||
var $USMMHeader = $('.usof-header'),
|
||||
$saveButton = $USMMHeader.find('.usof-control.for_save'),
|
||||
$saveMessage = $saveButton.find('.usof-control-message'),
|
||||
saveStateTimer = null;
|
||||
|
||||
"use strict";
|
||||
var USMMSave = function(){
|
||||
$saveButton.usMod('status', 'loading');
|
||||
$saveMessage.html('');
|
||||
$saveButton.off('click', USMMSave);
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'usof_ajax_mega_menu_save_settings',
|
||||
menu: <?php echo $menu_id; ?>,
|
||||
item: <?php echo $item_id; ?>,
|
||||
settings: USMMSettings,
|
||||
security: '<?php echo wp_create_nonce( 'usof-mega-menu-save' ); ?>'
|
||||
},
|
||||
success: function(result){
|
||||
if ($saveButton.usMod('status') !== 'loading') return;
|
||||
$saveMessage.html(result.data.message);
|
||||
$saveButton.usMod('status', 'success');
|
||||
clearTimeout(saveStateTimer);
|
||||
saveStateTimer = setTimeout(function(){
|
||||
$saveMessage.html('');
|
||||
$saveButton.usMod('status', 'clear');
|
||||
}.bind(this), 4000);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$(document.body).trigger('usof_mm_load');
|
||||
|
||||
$(document.body).off('usof_mm_save').on('usof_mm_save', function(){
|
||||
clearTimeout(saveStateTimer);
|
||||
$saveButton.usMod('status', 'notsaved');
|
||||
$saveButton.off('click').on('click', USMMSave);
|
||||
})
|
||||
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
die();
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
add_action( 'wp_ajax_usof_save', 'usof_ajax_save' );
|
||||
function usof_ajax_save() {
|
||||
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
do_action( 'usof_before_ajax_save' );
|
||||
|
||||
global $usof_options;
|
||||
usof_load_options_once();
|
||||
|
||||
$config = us_config( 'theme-options', array(), TRUE );
|
||||
|
||||
// Logic do not seek here, young padawan. For WPML string translation compability such copying method is used.
|
||||
// If result of array_merge is put directly to $updated_options, the options will not save.
|
||||
$usof_options_fallback = array_merge( usof_defaults(), $usof_options );
|
||||
$updated_options = array();
|
||||
foreach ( $usof_options_fallback as $key => $val ) {
|
||||
$updated_options[ $key ] = $val;
|
||||
}
|
||||
|
||||
$post_options = us_maybe_get_post_json( 'usof_options' );
|
||||
|
||||
if ( empty( $post_options ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => __( 'There\'s no options to save', 'us' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( $post_options as $key => $value ) {
|
||||
if ( isset( $updated_options[ $key ] ) ) {
|
||||
$updated_options[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
usof_save_options( $updated_options );
|
||||
|
||||
do_action( 'usof_after_ajax_save' );
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'message' => us_translate( 'Changes saved.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_usof_reset', 'usof_ajax_reset' );
|
||||
function usof_ajax_reset() {
|
||||
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$updated_options = usof_defaults();
|
||||
usof_save_options( $updated_options );
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'message' => __( 'Options were reset', 'us' ),
|
||||
'usof_options' => $updated_options,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_usof_backup', 'usof_ajax_backup' );
|
||||
function usof_ajax_backup() {
|
||||
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
global $usof_options;
|
||||
usof_load_options_once();
|
||||
|
||||
$backup = array(
|
||||
'time' => current_time( 'mysql', TRUE ),
|
||||
'usof_options' => $usof_options,
|
||||
);
|
||||
$backup_time = strtotime( $backup['time'] ) + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
|
||||
|
||||
update_option( 'usof_backup_' . US_THEMENAME, $backup, FALSE );
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'status' => __( 'Last Backup', 'us' ) . ': <span>' . date_i18n( 'F j, Y - G:i T', $backup_time ) . '</span>',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_usof_restore_backup', 'usof_ajax_restore_backup' );
|
||||
function usof_ajax_restore_backup() {
|
||||
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
global $usof_options;
|
||||
|
||||
$backup = get_option( 'usof_backup_' . US_THEMENAME );
|
||||
if ( ! $backup OR ! is_array( $backup ) OR ! isset( $backup['usof_options'] ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => __( 'There\'s no backup to restore', 'us' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$usof_options = $backup['usof_options'];
|
||||
update_option( 'usof_options_' . US_THEMENAME, $usof_options, TRUE );
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'message' => __( 'Backup was restored', 'us' ),
|
||||
'usof_options' => $usof_options,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_usof_save_style_scheme', 'usof_ajax_save_style_scheme' );
|
||||
function usof_ajax_save_style_scheme() {
|
||||
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$custom_color_schemes = get_option( 'usof_style_schemes_' . US_THEMENAME );
|
||||
if ( ! is_array( $custom_color_schemes ) ) {
|
||||
$custom_color_schemes = array();
|
||||
}
|
||||
|
||||
$scheme = us_maybe_get_post_json( 'scheme' );
|
||||
if ( isset( $scheme['id'] ) ) {
|
||||
$scheme_id = $scheme['id'];
|
||||
} else {
|
||||
$max_index = 0;
|
||||
if ( count( $custom_color_schemes ) > 0 ) {
|
||||
$max_index = intval( max( array_keys( $custom_color_schemes ) ) );
|
||||
}
|
||||
$scheme_id = $max_index + 1;
|
||||
}
|
||||
|
||||
$custom_color_schemes[ $scheme_id ] = array( 'title' => $scheme['name'], 'values' => $scheme['colors'] );
|
||||
update_option( 'usof_style_schemes_' . US_THEMENAME, $custom_color_schemes, TRUE );
|
||||
|
||||
$color_schemes = us_config( 'style-schemes' );
|
||||
$output = '';
|
||||
|
||||
$custom_color_schemes_reversed = array_reverse( $custom_color_schemes, TRUE );
|
||||
|
||||
foreach ( $custom_color_schemes_reversed as $key => &$scheme ) {
|
||||
$output .= '<li class="usof-schemes-item type_custom" data-id="' . $key . '">';
|
||||
$output .= usof_color_scheme_preview( $scheme );
|
||||
// Overwrite btn
|
||||
$output .= '<div class="usof-schemes-item-save" title="' . us_translate( 'Save' ) . '"></div>';
|
||||
// Delete btn
|
||||
$output .= '<div class="usof-schemes-item-delete" title="' . us_translate( 'Delete' ) . '"></div>';
|
||||
$output .= '</li>';
|
||||
}
|
||||
foreach ( $color_schemes as $key => &$scheme ) {
|
||||
$output .= '<li class="usof-schemes-item" data-id="' . $key . '">';
|
||||
$output .= usof_color_scheme_preview( $scheme );
|
||||
$output .= '</li>';
|
||||
}
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'customSchemes' => $custom_color_schemes,
|
||||
'schemes' => $color_schemes,
|
||||
'schemesHtml' => $output,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_usof_delete_style_scheme', 'usof_ajax_delete_style_scheme' );
|
||||
function usof_ajax_delete_style_scheme() {
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$scheme = sanitize_text_field( $_POST['scheme'] );
|
||||
|
||||
$custom_color_schemes = get_option( 'usof_style_schemes_' . US_THEMENAME );
|
||||
|
||||
if ( ! is_array( $custom_color_schemes ) ) {
|
||||
$custom_color_schemes = array();
|
||||
}
|
||||
if ( isset( $custom_color_schemes[ $scheme ] ) ) {
|
||||
unset( $custom_color_schemes[ $scheme ] );
|
||||
}
|
||||
update_option( 'usof_style_schemes_' . US_THEMENAME, $custom_color_schemes, TRUE );
|
||||
|
||||
$color_schemes = us_config( 'style-schemes' );
|
||||
$output = '';
|
||||
|
||||
$custom_color_schemes_reversed = array_reverse( $custom_color_schemes, TRUE );
|
||||
|
||||
foreach ( $custom_color_schemes_reversed as $key => &$scheme ) {
|
||||
$output .= '<li class="usof-schemes-item type_custom" data-id="' . $key . '">';
|
||||
$output .= usof_color_scheme_preview( $scheme );
|
||||
// Overwrite btn
|
||||
$output .= '<div class="usof-schemes-item-save" title="' . us_translate( 'Save' ) . '"></div>';
|
||||
// Delete btn
|
||||
$output .= '<div class="usof-schemes-item-delete" title="' . us_translate( 'Delete' ) . '"></div>';
|
||||
$output .= '</li>';
|
||||
}
|
||||
foreach ( $color_schemes as $key => &$scheme ) {
|
||||
$output .= '<li class="usof-schemes-item" data-id="' . $key . '">';
|
||||
$output .= usof_color_scheme_preview( $scheme );
|
||||
$output .= '</li>';
|
||||
}
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'customSchemes' => $custom_color_schemes,
|
||||
'schemes' => $color_schemes,
|
||||
'schemesHtml' => $output,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Adding palette values for color picker
|
||||
add_action( 'wp_ajax_usof_color_palette', 'usof_ajax_color_palette' );
|
||||
function usof_ajax_color_palette() {
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
$paletteColors = get_option( 'usof_color_palette_' . US_THEMENAME );
|
||||
if ( ! is_array( $paletteColors ) ) {
|
||||
$paletteColors = array();
|
||||
}
|
||||
$paletteLength = count( $paletteColors );
|
||||
$color = us_maybe_get_post_json( 'color' );
|
||||
$output = '';
|
||||
if ( isset( $color['value'] ) AND $paletteLength < 8 ) {
|
||||
// Appending new color
|
||||
$paletteColors[] = $color['value'];
|
||||
update_option( 'usof_color_palette_' . US_THEMENAME, $paletteColors, TRUE );
|
||||
foreach ( $paletteColors as $color ) {
|
||||
$output .= '<div class="usof_colpick_palette_value"><span style="background:' . $color . '" title="' . esc_attr( $color ) . '"></span><div class="usof_colpick_palette_delete" title="' . us_translate( 'Delete' ) . '"></div></div>';
|
||||
}
|
||||
$output .= '<div class="usof_colpick_palette_add" title="' . __( 'Add the current color to the palette', 'us' ) . '"></div>';
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'output' => $output,
|
||||
)
|
||||
);
|
||||
} elseif ( isset( $color['colorId'] ) ) {
|
||||
// Deleting current color
|
||||
unset( $paletteColors[ $color['colorId'] ] );
|
||||
$newPalette = array();
|
||||
foreach ( $paletteColors as $color ) {
|
||||
$newPalette[] = $color;
|
||||
}
|
||||
update_option( 'usof_color_palette_' . US_THEMENAME, $newPalette, TRUE );
|
||||
foreach ( $paletteColors as $color ) {
|
||||
$output .= '<div class="usof_colpick_palette_value"><span style="background:' . $color . '" title="' . esc_attr( $color ) . '"></span><div class="usof_colpick_palette_delete" title="' . us_translate( 'Delete' ) . '"></div></div>';
|
||||
}
|
||||
$output .= '<div class="usof_colpick_palette_add" title="' . __( 'Add the current color to the palette', 'us' ) . '"></div>';
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'output' => $output,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Get Color Schemes
|
||||
add_action( 'wp_ajax_usof_get_style_schemes', 'usof_get_style_schemes' );
|
||||
function usof_get_style_schemes() {
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
$color_schemes = us_config( 'style-schemes' );
|
||||
$custom_color_schemes = get_option( 'usof_style_schemes_' . US_THEMENAME );
|
||||
if ( ! is_array( $custom_color_schemes ) ) {
|
||||
$custom_color_schemes = array();
|
||||
}
|
||||
|
||||
// Reverse Custom schemes order to make last added item first
|
||||
$custom_color_schemes = array_reverse( $custom_color_schemes, TRUE );
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'schemes' => $color_schemes,
|
||||
'custom_schemes' => $custom_color_schemes,
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
add_action( 'admin_menu', 'us_options_admin_menu', 9 );
|
||||
function us_options_admin_menu() {
|
||||
add_menu_page( __( 'Theme Options', 'us' ), US_THEMENAME, 'manage_options', 'us-theme-options', 'us_theme_options_page', NULL, '59.001' );
|
||||
$usof_page = add_submenu_page( 'us-theme-options', US_THEMENAME, __( 'Theme Options', 'us' ), 'edit_theme_options', 'us-theme-options', 'us_theme_options_page' );
|
||||
add_action( 'admin_print_scripts-' . $usof_page, 'usof_print_scripts' );
|
||||
add_action( 'admin_print_styles-' . $usof_page, 'usof_print_styles' );
|
||||
add_action( 'admin_print_styles-' . $usof_page, 'usof_print_fonts' );
|
||||
|
||||
add_action( 'admin_print_scripts-post-new.php', 'usof_print_scripts' );
|
||||
add_action( 'admin_print_scripts-post.php', 'usof_print_scripts' );
|
||||
|
||||
add_action( 'admin_print_scripts-nav-menus.php', 'usof_print_scripts' );
|
||||
|
||||
add_action( 'admin_notices', 'usof_hide_admin_notices_start', 1 );
|
||||
add_action( 'admin_notices', 'usof_hide_admin_notices_end', 1000 );
|
||||
}
|
||||
|
||||
function us_theme_options_page() {
|
||||
|
||||
// For notices
|
||||
echo '<div class="wrap"><h2 class="hidden"></h2>';
|
||||
|
||||
global $usof_options, $usof_img_sizes, $usof_enable_portfolio, $usof_sidebar_titlebar;
|
||||
usof_load_options_once();
|
||||
$usof_options = array_merge( usof_defaults(), $usof_options );
|
||||
|
||||
// Preserving values for hidden fields
|
||||
$hidden_fields_values = array();
|
||||
|
||||
$visited_new_sections = array();
|
||||
if ( isset( $_COOKIE ) AND isset( $_COOKIE['usof_visited_new_sections'] ) ) {
|
||||
$visited_new_sections = explode( ',', $_COOKIE['usof_visited_new_sections'] );
|
||||
}
|
||||
|
||||
$usof_img_sizes = us_image_sizes_select_values();
|
||||
$usof_enable_portfolio = us_get_option( 'enable_portfolio', 1 );
|
||||
$usof_sidebar_titlebar = us_get_option( 'enable_sidebar_titlebar', 0 );
|
||||
|
||||
$config = us_config( 'theme-options', array(), TRUE );
|
||||
echo '<div class="usof-container';
|
||||
echo apply_filters( 'usof_container_classes', '' );
|
||||
if ( get_option( 'us_license_activated', 0 ) OR ( defined( 'US_DEV' ) AND US_DEV ) ) {
|
||||
echo ' theme_activated';
|
||||
}
|
||||
echo '" data-ajaxurl="' . esc_attr( admin_url( 'admin-ajax.php' ) ) . '">';
|
||||
echo '<form class="usof-form" method="post" action="#" autocomplete="off">';
|
||||
// Output _nonce and _wp_http_referer hidden fields for ajax secuirity checks
|
||||
wp_nonce_field( 'usof-actions' );
|
||||
echo '<div class="usof-header">';
|
||||
echo '<div class="usof-header-logo">';
|
||||
echo US_THEMENAME . ' <span>' . US_THEMEVERSION . '</span></div>';
|
||||
echo '<div class="usof-header-title"><span>' . __( 'Theme Options', 'us' ) . ' — </span>';
|
||||
echo '<h2>' . us_translate_x( 'General', 'settings screen' ) . '</h2></div>';
|
||||
// Control for opening color schemes window
|
||||
echo '<div class="usof-control for_schemes hidden">';
|
||||
echo '<button class="usof-button" type="button">' . __( 'Color Schemes', 'us' ) . '</button>';
|
||||
echo '</div>';
|
||||
// Control for saving changes button
|
||||
echo '<div class="usof-control for_save status_clear">';
|
||||
echo '<button class="usof-button type_save" type="button"><span>' . us_translate( 'Save Changes' ) . '</span>';
|
||||
echo '<span class="usof-preloader"></span></button>';
|
||||
echo '<div class="usof-control-message"></div>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
|
||||
// Saving empty or outdated selects
|
||||
$empty_select_present = FALSE;
|
||||
|
||||
$usof_options_fallback = array_merge( usof_defaults(), $usof_options );
|
||||
$updated_options = array();
|
||||
foreach ( $usof_options_fallback as $key => $val ) {
|
||||
$updated_options[ $key ] = $val;
|
||||
}
|
||||
|
||||
foreach ( $config as $section_id => $section ) {
|
||||
if ( isset( $section['fields'] ) ) {
|
||||
foreach ( $section['fields'] as $field_id => $field ) {
|
||||
if ( $field['type'] == 'select' ) {
|
||||
$field_values = array_keys( $field['options'] );
|
||||
if ( ! isset( $updated_options[ $field_id ] ) OR ! in_array( $updated_options[ $field_id ], $field_values ) ) {
|
||||
$empty_select_present = TRUE;
|
||||
$updated_options[ $field_id ] = array_shift( $field_values );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $empty_select_present ) {
|
||||
usof_save_options( $updated_options );
|
||||
}
|
||||
|
||||
// Sided Menu
|
||||
echo '<div class="usof-nav"><div class="usof-nav-bg"></div><ul class="usof-nav-list level_1">';
|
||||
foreach ( $config as $section_id => &$section ) {
|
||||
if ( isset( $section['place_if'] ) AND ! $section['place_if'] ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! isset( $active_section ) ) {
|
||||
$active_section = $section_id;
|
||||
}
|
||||
echo '<li class="usof-nav-item level_1 id_' . $section_id . ( ( $section_id == $active_section ) ? ' current' : '' ) . '"';
|
||||
echo ' data-id="' . $section_id . '">';
|
||||
echo '<a class="usof-nav-anchor level_1" href="#' . $section_id . '">';
|
||||
echo '<img class="usof-nav-icon" src="' . $section['icon'] . '.png" srcset="' . $section['icon'] . '-2x.png 2x" alt="icon">';
|
||||
echo '<span class="usof-nav-title">' . $section['title'] . '</span>';
|
||||
echo '<span class="usof-nav-arrow"></span>';
|
||||
echo '</a>';
|
||||
if ( isset( $section['new'] ) AND $section['new'] AND ! in_array( $section_id, $visited_new_sections ) ) {
|
||||
echo '<span class="usof-nav-popup">' . __( 'New', 'us' ) . '</span>';
|
||||
}
|
||||
echo '</li>';
|
||||
}
|
||||
echo '<ul></div>';
|
||||
|
||||
// Content
|
||||
echo '<div class="usof-content">';
|
||||
foreach ( $config as $section_id => &$section ) {
|
||||
if ( isset( $section['place_if'] ) AND ! $section['place_if'] ) {
|
||||
if ( isset( $section['fields'] ) ) {
|
||||
$hidden_fields_values = array_merge( $hidden_fields_values, array_intersect_key( $usof_options, $section['fields'] ) );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
echo '<section class="usof-section ' . ( ( $section_id == $active_section ) ? 'current' : '' ) . '" data-id="' . $section_id . '">';
|
||||
echo '<div class="usof-section-header" data-id="' . $section_id . '">';
|
||||
echo '<h3>' . $section['title'] . '</h3><span class="usof-section-header-control"></span></div>';
|
||||
echo '<div class="usof-section-content" style="display: ' . ( ( $section_id == $active_section ) ? 'block' : 'none' ) . '">';
|
||||
if ( isset( $section['fields'] ) ) {
|
||||
foreach ( $section['fields'] as $field_name => &$field ) {
|
||||
if ( isset( $field['place_if'] ) AND ! $field['place_if'] ) {
|
||||
if ( isset( $usof_options[ $field_name ] ) ) {
|
||||
$hidden_fields_values[ $field_name ] = $usof_options[ $field_name ];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
us_load_template(
|
||||
'vendor/usof/templates/field', array(
|
||||
'name' => $field_name,
|
||||
'id' => 'usof_' . $field_name,
|
||||
'field' => $field,
|
||||
'values' => &$usof_options,
|
||||
)
|
||||
);
|
||||
unset( $hidden_fields_values[ $field_name ] );
|
||||
}
|
||||
}
|
||||
echo '</div></section>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
|
||||
echo '</div>';
|
||||
echo '<div class="usof-hidden-fields"' . us_pass_data_to_js( $hidden_fields_values ) . '></div>';
|
||||
}
|
||||
|
||||
function usof_print_scripts() {
|
||||
global $usof_directory_uri;
|
||||
if ( ! did_action( 'wp_enqueue_media' ) ) {
|
||||
wp_enqueue_media();
|
||||
}
|
||||
wp_enqueue_script( 'usof-colorpicker', $usof_directory_uri . '/js/usof-colpick.js', array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
wp_enqueue_script( 'usof-select2', $usof_directory_uri . '/js/select2.min.js', array( 'jquery' ), '4.0.5', TRUE );
|
||||
wp_enqueue_script( 'usof-scripts', $usof_directory_uri . '/js/usof.js', array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
do_action( 'usof_print_scripts' );
|
||||
}
|
||||
|
||||
function usof_print_styles() {
|
||||
global $usof_directory_uri, $us_template_directory_uri;
|
||||
wp_enqueue_style( 'usof-styles', $usof_directory_uri . '/css/usof.css', array(), US_THEMEVERSION );
|
||||
do_action( 'usof_print_styles' );
|
||||
}
|
||||
|
||||
function usof_print_fonts() {
|
||||
$prefixes = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'body' );
|
||||
$font_options = $fonts = array();
|
||||
|
||||
$uploaded_fonts = us_get_option( 'uploaded_fonts', array() );
|
||||
$uploaded_font_names = array();
|
||||
if ( is_array( $uploaded_fonts ) AND count( $uploaded_fonts ) > 0 ) {
|
||||
foreach ( $uploaded_fonts as $uploaded_font ) {
|
||||
$uploaded_font_names[] = esc_attr( strip_tags( $uploaded_font['name'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $prefixes as $prefix ) {
|
||||
$font_option = explode( '|', us_get_option( $prefix . '_font_family', 'none' ), 2 );
|
||||
if ( in_array( $font_option[0], $uploaded_font_names ) ) {
|
||||
continue;
|
||||
}
|
||||
$font_options[] = $font_option;
|
||||
}
|
||||
|
||||
$custom_fonts = us_get_option( 'custom_font', array() );
|
||||
if ( is_array( $custom_fonts ) AND count( $custom_fonts ) > 0 ) {
|
||||
foreach ( $custom_fonts as $custom_font ) {
|
||||
$font_options[] = explode( '|', $custom_font['font_family'], 2 );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $font_options as $font ) {
|
||||
if ( ! isset( $font[1] ) OR empty( $font[1] ) ) {
|
||||
// Fault tolerance for missing font-variants
|
||||
$font[1] = '400,700';
|
||||
}
|
||||
$selected_font_variants = explode( ',', $font[1] );
|
||||
// Empty font or web safe combination selected
|
||||
if ( $font[0] == 'none' OR strpos( $font[0], ',' ) !== FALSE ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$font[0] = str_replace( ' ', '+', $font[0] );
|
||||
if ( ! isset( $fonts[ $font[0] ] ) ) {
|
||||
$fonts[ $font[0] ] = array();
|
||||
}
|
||||
|
||||
foreach ( $selected_font_variants as $font_variant ) {
|
||||
$fonts[ $font[0] ][] = $font_variant;
|
||||
}
|
||||
}
|
||||
|
||||
$protocol = is_ssl() ? 'https' : 'http';
|
||||
$subset = '&subset=' . us_get_option( 'font_subset', 'latin' );
|
||||
$font_index = 1;
|
||||
foreach ( $fonts as $font_name => $font_variants ) {
|
||||
if ( count( $font_variants ) == 0 OR $font_name == 'get_h1' ) {
|
||||
continue;
|
||||
}
|
||||
$font_variants = array_unique( $font_variants );
|
||||
|
||||
// Google font url
|
||||
$font_url = $protocol . '://fonts.googleapis.com/css?family=' . $font_name . ':' . implode( ',', $font_variants ) . $subset;
|
||||
wp_enqueue_style( 'us-font-' . $font_index, $font_url );
|
||||
$font_index ++;
|
||||
}
|
||||
|
||||
// Generate font-face for Uploaded Fonts
|
||||
$uploaded_fonts = us_get_option( 'uploaded_fonts', array() );
|
||||
if ( is_array( $uploaded_fonts ) AND count( $uploaded_fonts ) > 0 ) {
|
||||
echo '<style>';
|
||||
foreach ( $uploaded_fonts as $uploaded_font ) {
|
||||
$files = explode( ',', $uploaded_font['files'] );
|
||||
$urls = array();
|
||||
foreach ( $files as $file ) {
|
||||
$url = wp_get_attachment_url( $file );
|
||||
if ( $url ) {
|
||||
$urls[] = 'url(' . esc_url( $url ) . ') format("' . pathinfo( $url, PATHINFO_EXTENSION ) . '")';
|
||||
}
|
||||
}
|
||||
if ( count( $urls ) ) {
|
||||
$src = implode( ', ', $urls );
|
||||
echo '@font-face {';
|
||||
echo 'font-display: swap;';
|
||||
echo 'font-style: normal;';
|
||||
echo 'font-family:"' . strip_tags( $uploaded_font['name'] ) . '";';
|
||||
echo 'font-weight:' . $uploaded_font['weight'] . ';';
|
||||
echo 'src:' . $src . ';';
|
||||
echo '}';
|
||||
}
|
||||
}
|
||||
echo '</style>';
|
||||
}
|
||||
}
|
||||
|
||||
function usof_hide_admin_notices_start() {
|
||||
?><div class="hidden"><?php
|
||||
}
|
||||
|
||||
function usof_hide_admin_notices_end() {
|
||||
?></div><?php
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
add_action( 'admin_init', 'usof_mega_menu_init' );
|
||||
function usof_mega_menu_init() {
|
||||
global $pagenow, $usof_version;
|
||||
if ( $pagenow == 'nav-menus.php') {
|
||||
global $us_template_directory_uri;
|
||||
|
||||
add_action('admin_footer', 'usof_mega_menu_admin_footer');
|
||||
|
||||
wp_enqueue_style( 'usof-styles', $us_template_directory_uri . '/framework/vendor/usof/css/usof.css', array(), $usof_version );
|
||||
add_thickbox();
|
||||
}
|
||||
}
|
||||
|
||||
function usof_mega_menu_admin_footer() {
|
||||
?>
|
||||
<script>
|
||||
jQuery(function ($) {
|
||||
"use strict";
|
||||
var menuId = $('input#menu').val();
|
||||
|
||||
$('#menu-to-edit li.menu-item.menu-item-depth-0').each(function() {
|
||||
var $menuItem = $(this),
|
||||
itemId = parseInt($menuItem.attr('id').match(/[0-9]+/)[0], 10),
|
||||
$nextMenuItem = $menuItem.next();
|
||||
|
||||
if ( $nextMenuItem.length == 0 || $nextMenuItem.is('li.menu-item.menu-item-depth-0') ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $button = $('<a href="<?php echo admin_url(); ?>admin-ajax.php?action=usof_ajax_mega_menu&menu_id='+menuId+'&item_id='+itemId+'">')
|
||||
.addClass("us-mm-btn thickbox")
|
||||
.html('<?php _e( 'Dropdown Settings', 'us' ); ?>');
|
||||
|
||||
$('.item-title', $menuItem).append($button);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
add_action( 'load-post.php', 'us_post_meta_boxes_setup' );
|
||||
add_action( 'load-post-new.php', 'us_post_meta_boxes_setup' );
|
||||
|
||||
function us_post_meta_boxes_setup() {
|
||||
|
||||
$config = us_config( 'meta-boxes', array() );
|
||||
|
||||
foreach ( $config as &$meta_box ) {
|
||||
new US_Meta_Box( $meta_box );
|
||||
}
|
||||
}
|
||||
|
||||
class US_Meta_Box {
|
||||
|
||||
public $meta_box;
|
||||
|
||||
public function __construct( $meta_box ) {
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->meta_box = $meta_box;
|
||||
|
||||
// Add meta box
|
||||
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
|
||||
|
||||
// Save meta box
|
||||
foreach ( $this->meta_box['post_types'] as $post_type ) {
|
||||
add_action( 'save_post_' . $post_type, array( $this, 'save_meta_boxes' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function add_meta_boxes() {
|
||||
foreach ( $this->meta_box['post_types'] as $post_type ) {
|
||||
add_meta_box(
|
||||
$this->meta_box['id'], $this->meta_box['title'], array(
|
||||
$this,
|
||||
'meta_box_body',
|
||||
), $post_type, $this->meta_box['context'], $this->meta_box['priority']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function meta_box_body() {
|
||||
|
||||
echo '<div class="usof-metabox">';
|
||||
global $us_metabox_marker_placed;
|
||||
if ( empty( $us_metabox_marker_placed ) ) {
|
||||
echo '<input type="hidden" name="us_metabox_save" value="1">';
|
||||
$us_metabox_marker_placed = TRUE;
|
||||
}
|
||||
|
||||
$post = get_post();
|
||||
$post_id = isset( $post->ID ) ? $post->ID : 0;
|
||||
$values = array();
|
||||
|
||||
// Output "Used in" locations for Page Blocks metabox
|
||||
if ( 'us_post_info' == $this->meta_box['id'] ) {
|
||||
$this->meta_box['fields']['used_in_locations']['description'] = us_get_used_in_locations( $post->ID, TRUE );
|
||||
}
|
||||
|
||||
foreach ( $this->meta_box['fields'] as $field_id => $field ) {
|
||||
if ( $post_id ) {
|
||||
if ( metadata_exists( 'post', $post_id, $field_id ) ) {
|
||||
$values[ $field_id ] = get_post_meta( $post_id, $field_id, TRUE );
|
||||
} elseif ( isset( $field['std'] ) ) {
|
||||
$values[ $field_id ] = $field['std'];
|
||||
} else {
|
||||
$values[ $field_id ] = '';
|
||||
}
|
||||
if ( $field['type'] == 'link' ) {
|
||||
$values[ $field_id ] = json_decode( $values[ $field_id ], TRUE );
|
||||
}
|
||||
}
|
||||
if ( isset( $field['options'] ) AND ( ! in_array( $field['type'], array( 'checkboxes' ) ) ) AND ( ! in_array( $values[ $field_id ], array_keys( $field['options'] ) ) ) ) {
|
||||
$values[ $field_id ] = ( isset( $field['std'] ) ) ? $field['std'] : '';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $this->meta_box['fields'] as $field_id => $field ) {
|
||||
us_load_template(
|
||||
'vendor/usof/templates/field', array(
|
||||
'name' => $field_id,
|
||||
'id' => 'usof_' . $field_id,
|
||||
'field' => $field,
|
||||
'values' => &$values,
|
||||
'is_metabox' => TRUE,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public function save_meta_boxes( $post_id ) {
|
||||
if ( ! ( isset( $_POST['us_metabox_save'] ) AND $_POST['us_metabox_save'] == 1 ) ) {
|
||||
return;
|
||||
}
|
||||
foreach ( $this->meta_box['fields'] as $field_id => $field ) {
|
||||
if ( $field['type'] == 'heading' ) {
|
||||
continue;
|
||||
}
|
||||
$new_value = isset( $_POST[ $field_id ] ) ? $_POST[ $field_id ] : NULL;
|
||||
|
||||
update_post_meta( $post_id, $field_id, $new_value );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user