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,21 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Ajax method for wooCommerce cart.
|
||||
*/
|
||||
add_action( 'wp_ajax_nopriv_us_ajax_cart', 'us_ajax_cart' );
|
||||
add_action( 'wp_ajax_us_ajax_cart', 'us_ajax_cart' );
|
||||
function us_ajax_cart() {
|
||||
if ( ! class_exists( 'woocommerce' ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
global $woocommerce;
|
||||
|
||||
$count = $woocommerce->cart->cart_contents_count;
|
||||
|
||||
$result = array( 'count' => $count );
|
||||
|
||||
wp_send_json_success( $result );
|
||||
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Ajax method for sending contact form via us_cform shortcode
|
||||
*/
|
||||
add_action( 'wp_ajax_nopriv_us_ajax_cform', 'us_ajax_cform' );
|
||||
add_action( 'wp_ajax_us_ajax_cform', 'us_ajax_cform' );
|
||||
function us_ajax_cform() {
|
||||
$post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0;
|
||||
if ( $post_id <= 0 ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
$post = get_post( $post_id );
|
||||
if ( empty( $post ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$form_index = isset( $_POST['form_index'] ) ? intval( $_POST['form_index'] ) : 1;
|
||||
|
||||
// Retrieving the relevant shortcode from the page to get options
|
||||
$post_content = $post->post_content;
|
||||
preg_match_all( '~(\[us_cform(.*?)\])((.*?)\[/us_cform\])?~', $post_content, $matches );
|
||||
|
||||
if ( ! isset( $matches[0][ $form_index - 1 ] ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
// Getting the relevant shortcode options
|
||||
$shortcode = $matches[1][ $form_index - 1 ];
|
||||
|
||||
// For proper shortcode_parse_atts behaviour
|
||||
$shortcode = substr_replace( $shortcode, ' ]', - 1 );
|
||||
$shortcode_atts = shortcode_parse_atts( $shortcode );
|
||||
|
||||
// Compatibility with older versions (applying migrations)
|
||||
if ( class_exists( 'US_Migration' ) ) {
|
||||
foreach ( US_Migration::instance()->translators as $version => $translator ) {
|
||||
if ( method_exists( $translator, 'translate_us_cform' ) ) {
|
||||
$translator->translate_us_cform( 'us_cform', $shortcode_atts );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Take all field types from config
|
||||
$available_fields = us_config( 'elements/cform.params.items.params.type.options' );
|
||||
$field_types = is_array( $available_fields ) ? array_keys( $available_fields ) : array();
|
||||
|
||||
// Decode shortcode items
|
||||
$shortcode_items = json_decode( urldecode( $shortcode_atts['items'] ), TRUE );
|
||||
$shortcode_items = $shortcode_items ? $shortcode_items : array();
|
||||
|
||||
// Default shortcode has no content, take it from config
|
||||
if ( empty( $shortcode_items ) ) {
|
||||
$shortcode_items = json_decode( urldecode( us_config( 'elements/cform.params.items.std' ) ), TRUE );
|
||||
$shortcode_items = $shortcode_items ? $shortcode_items : array();
|
||||
}
|
||||
|
||||
$sorted_fields = array();
|
||||
// Sort shortcode fields
|
||||
foreach ( $shortcode_items as $shortcode_item_key => $shortcode_item ) {
|
||||
if ( in_array( $shortcode_item['type'], $field_types ) ) {
|
||||
// Pass info field
|
||||
if ( $shortcode_item['type'] == 'info' ) {
|
||||
continue;
|
||||
}
|
||||
// Set Agreement Box and Captcha to be required
|
||||
if ( $shortcode_item['type'] == 'agreement' OR $shortcode_item['type'] == 'captcha' ) {
|
||||
$shortcode_item['required'] = 1;
|
||||
}
|
||||
$existing_fields = isset( $sorted_fields[ $shortcode_item['type'] ] ) ? $sorted_fields[ $shortcode_item['type'] ] : array();
|
||||
$field_id = count( $existing_fields ) + 1;
|
||||
$shortcode_item['name'] = 'us_form_' . $form_index . '_' . $shortcode_item['type'] . '_' . $field_id;
|
||||
$sorted_fields[ $shortcode_item['type'] ][] = $shortcode_item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function us_cform_is_valid_captcha( $captcha = NULL ) {
|
||||
$fields = array();
|
||||
foreach ( $_POST as $key => $field ) {
|
||||
if ( preg_match( '~^us_form_\d_([^_]+_)\d_(\w+)$~', $key, $matches ) ) {
|
||||
$fields[ $matches[1] . $matches[2] ] = $field;
|
||||
} elseif ( preg_match( '~^us_form_\d_([^_]+)_\d$~', $key, $matches ) ) {
|
||||
$fields[ $matches[1] ] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
$captcha_hash = isset( $fields['captcha_hash'] ) ? stripslashes( $fields['captcha_hash'] ) : NULL;
|
||||
if ( $captcha_hash === md5( $captcha . NONCE_SALT ) ) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$errors = $headers = array();
|
||||
$body_content = '';
|
||||
|
||||
// Validate fields and compose a message
|
||||
foreach ( $sorted_fields as $sorted_field_key => $sorted_field ) {
|
||||
foreach ( $sorted_field as $field ) {
|
||||
$name = isset( $field['name'] ) ? $field['name'] : '';
|
||||
$field_type = isset( $field['type'] ) ? $field['type'] : '';
|
||||
|
||||
// Validate fields
|
||||
if ( isset( $field['required'] ) ) {
|
||||
// Validate Captcha
|
||||
if ( $field_type == 'captcha' ) {
|
||||
$captcha = isset( $_POST[ $name ] ) ? esc_attr( $_POST[ $name ] ) : NULL;
|
||||
if ( ! us_cform_is_valid_captcha( $captcha ) ) {
|
||||
if ( ! empty( $name ) ) {
|
||||
$errors[ $field['type'] ]['name'][] = $name;
|
||||
}
|
||||
}
|
||||
} elseif ( ! isset( $_POST[ $name ] ) OR ( isset( $_POST[ $name ] ) AND empty( $_POST[ $name ] ) ) ) {
|
||||
if ( ! empty( $name ) ) {
|
||||
$errors[ $field['type'] ]['name'][] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$email_content = isset( $_POST[ $name ] ) ? $_POST[ $name ] : '';
|
||||
|
||||
$skipped_fields = array(
|
||||
'captcha',
|
||||
);
|
||||
|
||||
// Skip empty and skipped fields
|
||||
if ( empty( $email_content ) OR in_array( $field_type, $skipped_fields ) ) {
|
||||
continue;
|
||||
}
|
||||
// Take message body
|
||||
if ( $field['type'] == 'agreement' AND ! empty( $field['value'] ) ) {
|
||||
$agreement = '<p>' . __( 'The sender has given his consent.', 'us' ) . '<br>';
|
||||
$agreement .= __( 'Agreement text', 'us' ) . ': <strong>' . strip_tags( $field['value'], '<a>' ) . '</strong><br>';
|
||||
$agreement .= __( 'Agreement date and time', 'us' ) . ': <strong>' . gmdate( 'Y-m-d H:i:s' ) . ' GMT</strong><br>';
|
||||
$agreement .= __( 'IP address', 'us' ) . ': <strong>' . us_get_ip() . '</strong></p>';
|
||||
} else {
|
||||
$body_content .= '<p>';
|
||||
if ( ! empty( $field['label'] ) ) {
|
||||
$body_content .= sanitize_text_field( $field['label'] ) . ':<br>';
|
||||
} elseif ( ! empty( $field['placeholder'] ) ) {
|
||||
$body_content .= sanitize_text_field( $field['placeholder'] ) . ':<br>';
|
||||
}
|
||||
if ( is_array( $email_content ) ) {
|
||||
$values_length = count( $email_content );
|
||||
$counter = 0;
|
||||
foreach ( $email_content as $value ) {
|
||||
$body_content .= '<strong>' . sanitize_text_field( stripslashes( $value ) ) . '</strong>';
|
||||
$counter ++;
|
||||
if ( $counter < $values_length ) {
|
||||
$body_content .= '<br>';
|
||||
}
|
||||
}
|
||||
} elseif ( $field['type'] == 'email' ) {
|
||||
$body_content .= '<strong>' . sanitize_email( stripslashes( $email_content ) ) . '</strong>';
|
||||
$headers[] = 'Reply-To: ' . sanitize_email( stripslashes( $email_content ) );
|
||||
} else {
|
||||
$body_content .= '<strong>' . sanitize_text_field( stripslashes( $email_content ) ) . '</strong>';
|
||||
}
|
||||
$body_content .= '</p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $errors ) ) {
|
||||
wp_send_json_error( $errors );
|
||||
}
|
||||
|
||||
// Get email receiver
|
||||
$email_to = get_option( 'admin_email' );
|
||||
if ( ! empty( $shortcode_atts['receiver_email'] ) ) {
|
||||
$email_to = array_map( 'sanitize_email', explode( ',', $shortcode_atts['receiver_email'] ) );
|
||||
}
|
||||
|
||||
$email_body = '<p>' . __( 'You received a message from', 'us' ) . ' <a href="' . site_url() . '">' . get_bloginfo( 'name' ) . '</a></p>';
|
||||
$email_body .= $body_content;
|
||||
|
||||
if ( isset( $agreement ) ) {
|
||||
$email_body .= $agreement;
|
||||
}
|
||||
|
||||
$email_subject = sprintf( __( 'Message from %s', 'us' ), get_bloginfo( 'name' ) );
|
||||
|
||||
if ( empty( $body_content ) ) {
|
||||
wp_send_json_error( __( 'Cannot send empty message. Please fill any of the fields.', 'us' ) );
|
||||
}
|
||||
|
||||
if ( is_rtl() ) {
|
||||
$email_body = '<div style="direction: rtl; unicode-bidi: embed;">' . $email_body . '</div>';
|
||||
}
|
||||
|
||||
add_filter( 'wp_mail_content_type', 'us_set_html_content_type' );
|
||||
function us_set_html_content_type() {
|
||||
return 'text/html';
|
||||
}
|
||||
|
||||
// Send attempt
|
||||
$success = wp_mail( $email_to, $email_subject, $email_body, $headers );
|
||||
|
||||
if ( $success ) {
|
||||
if ( isset( $shortcode_atts['success_message'] ) AND ! empty( $shortcode_atts['success_message'] ) ) {
|
||||
$success_message = trim( strip_tags( $shortcode_atts['success_message'], '<a><br><strong>' ) );
|
||||
} else {
|
||||
$success_message = us_config( 'elements/cform.params.success_message.std' );
|
||||
}
|
||||
wp_send_json_success( $success_message );
|
||||
} else {
|
||||
wp_send_json_error( __( 'Cannot send the message. Please contact the website administrator.', 'us' ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Ajax method for grids ajax pagination.
|
||||
*/
|
||||
add_action( 'wp_ajax_nopriv_us_ajax_grid', 'us_ajax_grid' );
|
||||
add_action( 'wp_ajax_us_ajax_grid', 'us_ajax_grid' );
|
||||
function us_ajax_grid() {
|
||||
|
||||
if ( class_exists( 'WPBMap' ) AND method_exists( 'WPBMap', 'addAllMappedShortcodes' ) ) {
|
||||
WPBMap::addAllMappedShortcodes();
|
||||
}
|
||||
|
||||
// Filtering $template_vars, as is will be extracted to the template as local variables
|
||||
$template_vars = shortcode_atts(
|
||||
array(
|
||||
'query_args' => array(),
|
||||
'post_id' => FALSE,
|
||||
'us_grid_index' => FALSE,
|
||||
'us_grid_ajax_index' => FALSE,
|
||||
'exclude_items' => 'none',
|
||||
'items_offset' => 0,
|
||||
'items_layout' => 'blog_1',
|
||||
'type' => 'grid',
|
||||
'columns' => 2,
|
||||
'img_size' => 'default',
|
||||
'lang' => FALSE,
|
||||
'overriding_link' => 'none',
|
||||
), us_maybe_get_post_json( 'template_vars' )
|
||||
);
|
||||
|
||||
if ( class_exists( 'SitePress' ) AND $template_vars['lang'] ) {
|
||||
global $sitepress;
|
||||
$sitepress->switch_lang( $template_vars['lang'] );
|
||||
}
|
||||
|
||||
$post_id = isset( $template_vars['post_id'] ) ? intval( $template_vars['post_id'] ) : 0;
|
||||
if ( $post_id > 0 ) {
|
||||
$post = get_post( $post_id );
|
||||
if ( empty( $post ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$us_grid_ajax_index = isset( $template_vars['us_grid_ajax_index'] ) ? intval( $template_vars['us_grid_ajax_index'] ) : 1;
|
||||
|
||||
// Retrieving the relevant shortcode from the page to get options
|
||||
$post_content = $post->post_content;
|
||||
|
||||
preg_match_all( '~\[us_grid(.*?)\]~', $post_content, $matches );
|
||||
|
||||
if ( ! isset( $matches[0][ $us_grid_ajax_index - 1 ] ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
// Getting the relevant shortcode options
|
||||
$shortcode = $matches[0][ $us_grid_ajax_index - 1 ];
|
||||
// For proper shortcode_parse_atts behaviour
|
||||
$shortcode = substr_replace( $shortcode, ' ]', - 1 );
|
||||
$shortcode_atts = shortcode_parse_atts( $shortcode );
|
||||
|
||||
$shortcode_atts = shortcode_atts(
|
||||
array(
|
||||
'post_type' => '',
|
||||
), $shortcode_atts
|
||||
);
|
||||
|
||||
if ( $shortcode_atts['post_type'] == '' ) {
|
||||
$shortcode_atts['post_type'] = 'post';
|
||||
}
|
||||
|
||||
$allowed_post_types = ( $shortcode_atts['post_type'] == 'current_query' ) ? NULL : array( $shortcode_atts['post_type'] );
|
||||
|
||||
if ( $shortcode_atts['post_type'] == 'current_query'
|
||||
AND $template_vars['query_args']['post_type'] == 'product'
|
||||
AND ! empty( $template_vars['query_args']['orderby'] ) ) {
|
||||
$add_wc_hooks = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// Filtering query_args
|
||||
if ( isset( $template_vars['query_args'] ) AND is_array( $template_vars['query_args'] ) ) {
|
||||
// Query Args keys, that won't be filtered
|
||||
$allowed_query_keys = array(
|
||||
// Grid listing shortcode requests
|
||||
'author_name',
|
||||
'us_portfolio_category',
|
||||
'us_portfolio_tag',
|
||||
'category_name',
|
||||
'tax_query',
|
||||
// Archive requests
|
||||
'year',
|
||||
'monthnum',
|
||||
'day',
|
||||
'cat',
|
||||
'tag',
|
||||
'product_cat',
|
||||
'product_tag',
|
||||
// Search requests
|
||||
's',
|
||||
// Pagination
|
||||
'paged',
|
||||
'order',
|
||||
'orderby',
|
||||
'posts_per_page',
|
||||
'post__not_in',
|
||||
'post__in',
|
||||
// For excluding 'out of stock' products
|
||||
'meta_query',
|
||||
// For products sorting
|
||||
'order',
|
||||
'meta_key',
|
||||
// Custom users' queries
|
||||
'post_type',
|
||||
);
|
||||
$public_cpt = array_keys( us_get_public_cpt() );
|
||||
if ( ! isset( $allowed_post_types ) OR ! is_array( $allowed_post_types ) ) {
|
||||
// TODO: make static part of this list to be detected dynamically
|
||||
$allowed_post_types = array_merge(
|
||||
array( 'us_portfolio', 'post', 'attachment', 'page', 'product' ), $public_cpt
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( $template_vars['query_args'] as $query_key => $query_val ) {
|
||||
if ( ! in_array( $query_key, $allowed_query_keys ) ) {
|
||||
unset( $template_vars['query_args'][ $query_key ] );
|
||||
}
|
||||
}
|
||||
if ( isset( $template_vars['query_args']['post_type'] ) ) {
|
||||
$is_allowed_post_type = TRUE;
|
||||
if ( is_array( $template_vars['query_args']['post_type'] ) ) {
|
||||
foreach ( $template_vars['query_args']['post_type'] as $post_type ) {
|
||||
if ( ! in_array( $post_type, $allowed_post_types ) ) {
|
||||
$is_allowed_post_type = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} elseif ( ! in_array( $template_vars['query_args']['post_type'], $allowed_post_types ) ) {
|
||||
$is_allowed_post_type = FALSE;
|
||||
}
|
||||
|
||||
if ( ! $is_allowed_post_type ) {
|
||||
unset( $template_vars['query_args']['post_type'] );
|
||||
}
|
||||
}
|
||||
if ( ! isset( $template_vars['query_args']['s'] ) AND ! isset( $template_vars['query_args']['post_type'] ) ) {
|
||||
$template_vars['query_args']['post_type'] = 'post';
|
||||
}
|
||||
// Providing proper post statuses
|
||||
if ( ! empty( $post_type ) AND ( $template_vars['query_args']['post_type'] == 'attachment' ) OR ( is_array( $template_vars['query_args']['post_type'] ) AND in_array( 'attachment', $template_vars['query_args']['post_type'] ) AND count( $template_vars['query_args']['post_type'] ) == 1 ) ) {
|
||||
$template_vars['query_args']['post_status'] = 'inherit';
|
||||
$template_vars['query_args']['post_mime_type'] = 'image';
|
||||
} else {
|
||||
$template_vars['query_args']['post_status'] = array( 'publish' => 'publish' );
|
||||
$template_vars['query_args']['post_status'] += (array) get_post_stati( array( 'public' => TRUE ) );
|
||||
// Add private states if user is capable to view them
|
||||
if ( is_user_logged_in() AND current_user_can( 'read_private_posts' ) ) {
|
||||
$template_vars['query_args']['post_status'] += (array) get_post_stati( array( 'private' => TRUE ) );
|
||||
}
|
||||
$template_vars['query_args']['post_status'] = array_values( $template_vars['query_args']['post_status'] );
|
||||
}
|
||||
|
||||
// Exclude sticky posts from rand query after 1 page
|
||||
if ( isset( $template_vars['query_args']['orderby'] ) AND ! ( is_array( $template_vars['query_args']['orderby'] ) ) ) {
|
||||
if ( ( substr( $template_vars['query_args']['orderby'], 0, 4 ) == 'rand' ) AND ( $template_vars['query_args']['paged'] > '1' ) ) {
|
||||
$sticky_posts = get_option( 'sticky_posts' );
|
||||
$template_vars['query_args']['ignore_sticky_posts'] = TRUE;
|
||||
foreach ( $sticky_posts as $post_id ) {
|
||||
$template_vars['query_args']['post__not_in'][] = $post_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Passing values that were filtered due to post protocol
|
||||
global $us_grid_loop_running;
|
||||
$us_grid_loop_running = TRUE;
|
||||
// Apply WooCommerce product ordering if set
|
||||
if ( ! empty( $add_wc_hooks ) AND class_exists( 'woocommerce' ) AND is_object( wc() ) ) {
|
||||
$_GET['orderby'] = $template_vars['query_args']['orderby'];
|
||||
add_action( 'pre_get_posts', array( wc()->query, 'product_query' ) );
|
||||
}
|
||||
us_load_template( 'templates/us_grid/listing', $template_vars );
|
||||
$us_grid_loop_running = FALSE;
|
||||
|
||||
// We don't use JSON to reduce data size
|
||||
die;
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Load elements list HTML to choose from
|
||||
*/
|
||||
add_action( 'wp_ajax_usgb_get_elist_html', 'ajax_usgb_get_elist_html' );
|
||||
function ajax_usgb_get_elist_html() {
|
||||
us_load_template( 'templates/elist', array(
|
||||
'elements' => us_config( 'grid-settings.elements', array() ),
|
||||
) );
|
||||
|
||||
// We don't use JSON to reduce data size
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load shortcode builder elements forms
|
||||
*/
|
||||
add_action( 'wp_ajax_usgb_get_ebuilder_html', 'ajax_usgb_get_ebuilder_html' );
|
||||
function ajax_usgb_get_ebuilder_html() {
|
||||
$template_vars = array(
|
||||
'titles' => array(),
|
||||
'body' => '',
|
||||
);
|
||||
|
||||
// Loading all the forms HTML
|
||||
foreach ( us_config( 'grid-settings.elements', array() ) as $type ) {
|
||||
$elm = us_config( 'elements/' . $type, array() );
|
||||
$template_vars['titles'][ $type ] = isset( $elm['title'] ) ? $elm['title'] : $type;
|
||||
$template_vars['body'] .= us_get_template( 'templates/eform', array(
|
||||
'type' => $type,
|
||||
'params' => $elm['params'],
|
||||
'context' => 'grid',
|
||||
) );
|
||||
}
|
||||
|
||||
us_load_template( 'templates/ebuilder', $template_vars );
|
||||
|
||||
// We don't use JSON to reduce data size
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load grid template selector forms
|
||||
*/
|
||||
add_action( 'wp_ajax_usgb_get_gtemplates_html', 'ajax_usgb_get_gtemplates_html' );
|
||||
function ajax_usgb_get_gtemplates_html() {
|
||||
|
||||
us_load_template( 'templates/gtemplates' );
|
||||
|
||||
// We don't use JSON to reduce data size
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save header
|
||||
*/
|
||||
add_action( 'wp_ajax_usgb_save', 'ajax_usgb_save' );
|
||||
function ajax_usgb_save() {
|
||||
$post = array(
|
||||
'ID' => isset( $_POST['ID'] ) ? intval( $_POST['ID'] ) : NULL,
|
||||
'post_title' => isset( $_POST['post_title'] ) ? $_POST['post_title'] : NULL,
|
||||
'post_content' => isset( $_POST['post_content'] ) ? $_POST['post_content'] : NULL,
|
||||
);
|
||||
|
||||
if ( ! check_admin_referer( 'usgb-update' ) OR ! current_user_can( 'edit_post', $post['ID'] ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! $post['ID'] ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( wp_update_post( $post ) !== $post['ID'] ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'message' => us_translate( 'Changes saved.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_usgb_add_group_params', 'usgb_ajax_add_group_params' );
|
||||
function usgb_ajax_add_group_params() {
|
||||
$element = sanitize_text_field( $_POST['element'] );
|
||||
$group = sanitize_text_field( $_POST['group'] );
|
||||
$index = sanitize_text_field( $_POST['index'] );
|
||||
|
||||
$config = us_config( 'grid-settings', array() );
|
||||
$element_config = us_config( 'elements/' . $element );
|
||||
|
||||
if ( isset( $element_config['params'][$group] ) ) {
|
||||
$field = $element_config['params'][$group];
|
||||
$result_html = '<div class="usof-form-group-item">';
|
||||
$result_html .= '<div class="usof-form-group-item-content">';
|
||||
ob_start();
|
||||
foreach ( $field['params'] as $param_name => $param ) {
|
||||
if ( isset( $param['show_if'] ) AND is_array( $param['show_if'] ) ) {
|
||||
$param['show_if'][0] = $group . '_' . $index . '_' . $param['show_if'][0];
|
||||
}
|
||||
us_load_template(
|
||||
'vendor/usof/templates/field', array(
|
||||
'name' => $group . '_' . $index . '_' . $param_name,
|
||||
'id' => 'usof_' . $group . '_' . $index . '_' . $param_name,
|
||||
'field' => $param,
|
||||
'values' => array(),
|
||||
)
|
||||
);
|
||||
}
|
||||
$result_html .= ob_get_clean();
|
||||
$result_html .= '</div>';
|
||||
$result_html .= '<div class="usof-form-group-delete" title="' . us_translate( 'Delete' ) . '"></div>';
|
||||
$result_html .= '</div>';
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'paramsHtml' => $result_html,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Ajax methods for us_login widget
|
||||
*/
|
||||
add_action( 'wp_ajax_nopriv_us_ajax_user_info', 'us_ajax_user_info' );
|
||||
add_action( 'wp_ajax_us_ajax_user_info', 'us_ajax_user_info' );
|
||||
function us_ajax_user_info() {
|
||||
if ( ! is_user_logged_in() ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
$current_user = wp_get_current_user();
|
||||
$logout_redirect = ( isset( $_POST['logout_redirect'] ) ) ? $_POST['logout_redirect'] : '';
|
||||
$logout_redirect = str_replace( '&', '&', wp_logout_url( esc_url( $logout_redirect ) ) );
|
||||
|
||||
$result = array(
|
||||
'name' => $current_user->display_name,
|
||||
'avatar' => get_avatar( get_current_user_id(), '64' ),
|
||||
'logout_url' => $logout_redirect,
|
||||
);
|
||||
wp_send_json_success( $result );
|
||||
}
|
||||
|
||||
if ( ! is_user_logged_in() ) {
|
||||
add_action( 'wp_ajax_nopriv_us_ajax_login', 'us_ajax_login' );
|
||||
add_action( 'wp_ajax_us_ajax_login', 'us_ajax_login' );
|
||||
}
|
||||
|
||||
function us_ajax_login() {
|
||||
// Check form nonce
|
||||
check_ajax_referer( 'us_ajax_login_nonce', 'us_login_nonce' );
|
||||
// Get form data
|
||||
$info = array(
|
||||
'user_login' => sanitize_user( $_POST['username'] ),
|
||||
'user_password' => strip_tags( $_POST['password'] ),
|
||||
'remember' => TRUE,
|
||||
);
|
||||
|
||||
// Logging
|
||||
$user_signon = wp_signon( $info, is_ssl() );
|
||||
$message = $user_signon->get_error_message();
|
||||
$error_code = $user_signon->get_error_code();
|
||||
// Format error message to cut a link and leading ERROR, NOTICE etc words
|
||||
$pattern = '#^(<strong>[^>]+>:\s)?((?:(?! <a href).)+)([\s\S]+)#i';
|
||||
$message = ucfirst( preg_replace( $pattern, '$2', $message ) );
|
||||
$result = array(
|
||||
'message' => $message,
|
||||
'code' => $error_code,
|
||||
);
|
||||
if ( is_wp_error( $user_signon ) ) {
|
||||
wp_send_json_error( $result );
|
||||
} else {
|
||||
wp_send_json_success();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,315 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Breadcrumbs
|
||||
*
|
||||
* @param $delimiter string
|
||||
* @param $home string Home label text
|
||||
* @param $item_before string
|
||||
* @param $item_after string
|
||||
* @param $link_attr string
|
||||
* @param $name_attr string
|
||||
* @param $position_attr string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
class US_Breadcrumbs {
|
||||
|
||||
protected $config;
|
||||
protected $counter;
|
||||
|
||||
public function __construct( $delimiter, $home, $item_before, $item_after, $link_attr, $name_attr, $position_attr ) {
|
||||
// Homepage Label
|
||||
$this->config['home'] = isset( $home ) ? $home : us_translate( 'Home' );
|
||||
// Separator between crumbs
|
||||
$this->config['delimiter'] = isset( $delimiter ) ? $delimiter : ' > ';
|
||||
// Code before the current crumb
|
||||
$this->config['before'] = isset( $item_before ) ? $item_before : '';
|
||||
$this->config['before_basic'] = '<li class="g-breadcrumbs-item">';
|
||||
// Code after the current crumb
|
||||
$this->config['after'] = isset( $item_after ) ? $item_after : '';
|
||||
$this->config['after_basic'] = '</li>';
|
||||
// Links attributes
|
||||
$this->config['link_attr'] = isset( $link_attr ) ? $link_attr : '';
|
||||
// Name attributes
|
||||
$this->config['name_attr'] = isset( $name_attr ) ? $name_attr : '';
|
||||
$this->config['name_before'] = $this->config['name_after'] = '';
|
||||
if ( ! empty( $this->config['name_attr'] ) ) {
|
||||
$this->config['name_before'] = '<span' . $this->config['name_attr'] . '>';
|
||||
$this->config['name_after'] = '</span>';
|
||||
}
|
||||
|
||||
// Position attributes
|
||||
$this->config['position_attr'] = isset( $position_attr ) ? $position_attr : '';
|
||||
|
||||
// Predefined link attributes
|
||||
$this->config['homeLink'] = trailingslashit( home_url() );
|
||||
|
||||
// Predefined text
|
||||
$this->config['text']['search'] = us_translate( 'Search Results' ); // text for a search results page
|
||||
$this->config['text']['404'] = us_translate( 'Page not found' ); // text for the 404 page
|
||||
$this->config['text']['forums'] = us_translate( 'Forums', 'bbpress' ); // text for the forums page
|
||||
|
||||
$this->counter = 1;
|
||||
}
|
||||
|
||||
private function replace_callback( $matches ) {
|
||||
$output = $matches[1] . '<meta ' . $this->config['position_attr'] . ' content="' . $this->counter ++ . '"/>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
private function get_breadcrumb_with_markup( $input = NULL ) {
|
||||
if ( empty( $this->config['position_attr'] ) AND $input ) {
|
||||
return $input;
|
||||
}
|
||||
|
||||
if ( ! $input ) {
|
||||
return '<meta' . $this->config['position_attr'] . ' content="' . $this->counter ++ . '"/>';
|
||||
}
|
||||
|
||||
$output = preg_replace_callback( '#(<\/a>)#', array( $this, 'replace_callback' ), $input );
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
private function get_breadcrumb( $link, $name ) {
|
||||
$output = $this->config['before'];
|
||||
$output .= '<a' . $this->config['link_attr'] . ' href="' . $link . '">';
|
||||
$output .= $this->config['name_before'] . $name . $this->config['name_after'];
|
||||
$output .= '</a>';
|
||||
$output .= $this->get_breadcrumb_with_markup();
|
||||
$output .= $this->config['after'];
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
global $post;
|
||||
// Generate HTML for output
|
||||
$output = '';
|
||||
// "Home" crumb
|
||||
if ( ! empty( $this->config['home'] ) ) {
|
||||
$output .= $this->get_breadcrumb( $this->config['homeLink'], $this->config['home'] );
|
||||
$output .= $this->config['delimiter'];
|
||||
}
|
||||
// Check whether The Events Calendar is activated and we're within it's archive
|
||||
$is_events_calendar = FALSE;
|
||||
if ( function_exists( 'tribe_is_month' ) AND function_exists( 'tribe_is_upcoming' ) AND function_exists( 'tribe_is_past' ) AND function_exists( 'tribe_is_day' ) ) {
|
||||
if ( tribe_is_month() OR tribe_is_upcoming() OR tribe_is_past() OR tribe_is_day() ) {
|
||||
$is_events_calendar = TRUE;
|
||||
}
|
||||
}
|
||||
// Category (for Posts only)
|
||||
if ( is_category() ) {
|
||||
$thisCat = get_category( get_query_var( 'cat' ), FALSE );
|
||||
if ( $thisCat->parent != 0 ) {
|
||||
$cats = get_category_parents( $thisCat->parent, TRUE, $this->config['delimiter'] );
|
||||
$cats = preg_replace( '#(<a\shref[^>]+>)([^<\/]+)(<\/a>)#', '${1}' . $this->config['name_before'] . '${2}' . $this->config['name_after'] . '${3}', $cats );
|
||||
$cats = str_replace( '<a', $this->config['before'] . '<a' . $this->config['link_attr'], $cats );
|
||||
$cats = str_replace( '</a>', '</a>' . $this->config['after'], $cats );
|
||||
$cats = $this->get_breadcrumb_with_markup( $cats );
|
||||
$output .= $cats;
|
||||
}
|
||||
$output .= $this->get_breadcrumb( get_category_link( get_query_var( 'cat' ) ), single_cat_title( '', FALSE ) );
|
||||
// Tag
|
||||
} elseif ( is_tag() ) {
|
||||
$output .= $this->get_breadcrumb( get_term_link( get_query_var( 'tag_id' ) ), single_tag_title( '', FALSE ) );
|
||||
// Author
|
||||
} elseif ( is_author() ) {
|
||||
global $author;
|
||||
$userdata = get_userdata( $author );
|
||||
$output .= $this->get_breadcrumb( get_author_posts_url( $userdata->ID ), $userdata->display_name );
|
||||
// 404 page
|
||||
} elseif ( is_404() ) {
|
||||
// Do not apply any markup to 404 page link
|
||||
$output .= $this->config['before_basic'] . $this->config['text']['404'] . $this->config['after_basic'];
|
||||
// Search Results
|
||||
} elseif ( is_search() ) {
|
||||
// Do not apply any markup to 404 page link
|
||||
$output .= $this->config['before_basic'] . $this->config['text']['search'] . $this->config['after_basic'];
|
||||
// Day
|
||||
} elseif ( is_day() ) {
|
||||
$day_link = get_day_link( get_the_time( 'Y' ), get_the_time( 'm' ), get_the_time( 'd' ) );
|
||||
$output .= $this->get_breadcrumb( get_year_link( get_the_time( 'Y' ) ), get_the_time( 'Y' ) );
|
||||
$output .= $this->config['delimiter'];
|
||||
$output .= $this->get_breadcrumb( get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ), __( get_the_time( 'F' ), 'us' ) );
|
||||
$output .= $this->config['delimiter'];
|
||||
$output .= $this->get_breadcrumb( $day_link, get_the_time( 'd' ) );
|
||||
// Month
|
||||
} elseif ( is_month() ) {
|
||||
$output .= $this->get_breadcrumb( get_year_link( get_the_time( 'Y' ) ), get_the_time( 'Y' ) );
|
||||
$output .= $this->config['delimiter'];
|
||||
$output .= $this->get_breadcrumb( get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ), __( get_the_time( 'F' ), 'us' ) );
|
||||
// Year
|
||||
} elseif ( is_year() ) {
|
||||
$output .= $this->get_breadcrumb( get_year_link( get_the_time( 'Y' ) ), get_the_time( 'Y' ) );
|
||||
} elseif ( ( is_post_type_archive( 'tribe_events' ) AND $is_events_calendar ) ) {
|
||||
// The Events Calendar
|
||||
// Set post type manually because the plugin returns wrong post type
|
||||
$post_type_obj = get_post_type_object( 'tribe_events' );
|
||||
if ( is_tax() ) {
|
||||
$output .= $this->get_breadcrumb( esc_url( tribe_get_events_link() ), $post_type_obj->labels->name );
|
||||
// Calendar Category Page
|
||||
$category_name = get_queried_object()->name;
|
||||
$output .= $this->config['delimiter'];
|
||||
$output .= $this->get_breadcrumb( esc_url( get_term_link( get_queried_object() ), 'tribe_events_cat' ), $category_name );
|
||||
} elseif ( tribe_is_month() OR tribe_is_past() OR tribe_is_upcoming() OR tribe_is_day() ) {
|
||||
$output .= $this->get_breadcrumb( esc_url( tribe_get_events_link() ), $post_type_obj->labels->name );
|
||||
}
|
||||
// Single post type
|
||||
} elseif ( is_single() ) {
|
||||
// Portfolio Pages
|
||||
if ( get_post_type() == 'us_portfolio' AND us_get_option( 'portfolio_breadcrumbs_page' ) != '' ) {
|
||||
$portfolio_breadcrumbs_page = get_post( us_get_option( 'portfolio_breadcrumbs_page' ) );
|
||||
if ( $portfolio_breadcrumbs_page ) {
|
||||
if ( class_exists( 'SitePress' ) AND defined( 'ICL_LANGUAGE_CODE' ) ) {
|
||||
$current_page_ID = apply_filters( 'wpml_object_id', $portfolio_breadcrumbs_page->ID, get_post_type( $portfolio_breadcrumbs_page->ID ), TRUE );
|
||||
$portfolio_breadcrumbs_page_title = get_the_title( $current_page_ID );
|
||||
} else {
|
||||
$portfolio_breadcrumbs_page_title = get_the_title( $portfolio_breadcrumbs_page->ID );
|
||||
}
|
||||
$output .= $this->get_breadcrumb( get_permalink( $portfolio_breadcrumbs_page->ID ), $portfolio_breadcrumbs_page_title );
|
||||
}
|
||||
|
||||
// Posts
|
||||
} elseif ( get_post_type() == 'post' ) {
|
||||
$cat = get_the_category();
|
||||
$cat = $cat[0];
|
||||
$cats = get_category_parents( $cat, TRUE, $this->config['delimiter'] );
|
||||
$cats = preg_replace( "#^(.+)" . $this->config['delimiter'] . "$#", "$1", $cats );
|
||||
$cats = preg_replace( '#(<a\shref[^>]+>)([^<\/]+)(<\/a>)#', '${1}' . $this->config['name_before'] . '${2}' . $this->config['name_after'] . '${3}', $cats );
|
||||
$cats = str_replace( '<a', $this->config['before'] . '<a' . $this->config['link_attr'], $cats );
|
||||
$cats = str_replace( '</a>', '</a>' . $this->config['after'], $cats );
|
||||
$cats = $this->get_breadcrumb_with_markup( $cats );
|
||||
$output .= $cats;
|
||||
// CPT
|
||||
} elseif ( get_post_type() == 'tribe_events' ) {
|
||||
// The Events Calendar
|
||||
$post_type_obj = get_post_type_object( get_post_type() );
|
||||
$output .= $this->get_breadcrumb( esc_url( tribe_get_events_link() ), $post_type_obj->labels->name );
|
||||
} else {
|
||||
$post_type_name = get_post_type();
|
||||
$taxonomies_found = FALSE;
|
||||
$taxonomy_names = get_object_taxonomies( $post_type_name, 'objects' );
|
||||
|
||||
if ( $taxonomy_names != NULL ) {
|
||||
foreach ( $taxonomy_names as $taxonomy_name ) {
|
||||
if ( ! $taxonomy_name->public ) {
|
||||
continue;
|
||||
}
|
||||
$post_taxonomy = get_the_terms( get_the_ID(), $taxonomy_name->name );
|
||||
if ( is_array( $post_taxonomy ) AND count( $post_taxonomy ) > 0 ) {
|
||||
$post_taxonomy = $post_taxonomy[0];
|
||||
$get_term_parents_args = array(
|
||||
'separator' => $this->config['delimiter'],
|
||||
'link' => TRUE,
|
||||
'format' => 'name',
|
||||
);
|
||||
$post_taxonomies = get_term_parents_list(
|
||||
$post_taxonomy, $taxonomy_name->name, $get_term_parents_args
|
||||
);
|
||||
$post_taxonomies = preg_replace( "#^(.+)" . $this->config['delimiter'] . "$#", "$1", $post_taxonomies );
|
||||
$post_taxonomies = preg_replace( '#(<a\shref[^>]+>)([^<\/]+)(<\/a>)#', '${1}' . $this->config['name_before'] . '${2}' . $this->config['name_after'] . '${3}', $post_taxonomies );
|
||||
$post_taxonomies = str_replace( '<a', $this->config['before'] . '<a' . $this->config['link_attr'], $post_taxonomies );
|
||||
$post_taxonomies = str_replace( '</a>', '</a>' . $this->config['after'], $post_taxonomies );
|
||||
$post_taxonomies = $this->get_breadcrumb_with_markup( $post_taxonomies );
|
||||
$output .= $post_taxonomies;
|
||||
$taxonomies_found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $taxonomies_found ) {
|
||||
$post_type_obj = get_post_type_object( get_post_type() );
|
||||
if ( ! empty( $post_type_obj->labels->name ) ) {
|
||||
$output .= $this->config['before'] . $post_type_obj->labels->name . $this->config['after'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$output .= $this->config['delimiter'];
|
||||
$output .= $this->get_breadcrumb( get_permalink( $post->ID ), get_the_title( $post->ID ) );
|
||||
// WooCommerce page
|
||||
} elseif ( function_exists( 'is_shop' ) and is_shop() ) {
|
||||
if ( ! $post->post_parent ) {
|
||||
$output .= $this->config['before'] . get_the_title() . $this->config['after'];
|
||||
} elseif ( $post->post_parent ) {
|
||||
$parent_id = $post->post_parent;
|
||||
$breadcrumbs = array();
|
||||
while ( $parent_id ) {
|
||||
$page = get_post( $parent_id );
|
||||
$breadcrumbs[] = $this->get_breadcrumb( get_permalink( $page->ID ), get_the_title( $page->ID ) );
|
||||
$parent_id = $page->post_parent;
|
||||
}
|
||||
$breadcrumbs = array_reverse( $breadcrumbs );
|
||||
for ( $i = 0; $i < count( $breadcrumbs ); $i ++ ) {
|
||||
$output .= $breadcrumbs[ $i ];
|
||||
if ( $i != count( $breadcrumbs ) - 1 ) {
|
||||
$output .= $this->config['delimiter'];
|
||||
}
|
||||
}
|
||||
$output .= $this->config['delimiter'];
|
||||
$output .= $this->config['before'] . get_the_title() . $this->config['after'];
|
||||
}
|
||||
// Page without parent
|
||||
} elseif ( is_page() AND ! $post->post_parent ) {
|
||||
// $output .= $before . get_the_title() . $after;
|
||||
$output .= $this->get_breadcrumb( get_permalink( $post->ID ), get_the_title( $post->ID ) );
|
||||
// Page with parent
|
||||
} elseif ( is_page() AND $post->post_parent ) {
|
||||
$parent_id = $post->post_parent;
|
||||
$breadcrumbs = array();
|
||||
$front_page_id = get_option( 'page_on_front' );
|
||||
$isFrontParent = FALSE;
|
||||
while ( $parent_id ) {
|
||||
$page = get_post( $parent_id );
|
||||
if ( $front_page_id == $parent_id ) {
|
||||
// Remove double home page when home is a parent
|
||||
$parent_id = $page->post_parent;
|
||||
if ( ! $parent_id ) {
|
||||
$isFrontParent = TRUE;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$breadcrumbs[] = $this->get_breadcrumb( get_permalink( $page->ID ), get_the_title( $page->ID ) );
|
||||
$parent_id = $page->post_parent;
|
||||
}
|
||||
$breadcrumbs = array_reverse( $breadcrumbs );
|
||||
for ( $i = 0; $i < count( $breadcrumbs ); $i ++ ) {
|
||||
$output .= $breadcrumbs[ $i ];
|
||||
if ( $i != count( $breadcrumbs ) - 1 ) {
|
||||
$output .= $this->config['delimiter'];
|
||||
}
|
||||
}
|
||||
if ( $isFrontParent AND ! count( $breadcrumbs ) ) {
|
||||
$this->config['delimiter'] = '';
|
||||
}
|
||||
$output .= $this->config['delimiter'];
|
||||
$output .= $this->get_breadcrumb( get_permalink( $post->ID ), get_the_title( $post->ID ) );
|
||||
// Any other page
|
||||
} elseif ( ! is_single() AND ! is_page() AND ! is_404() ) {
|
||||
$post_type_obj = get_post_type_object( get_post_type() );
|
||||
if ( isset( $post_type_obj->labels->name ) ) {
|
||||
// Don't add any markup to unknown posts
|
||||
$output .= $this->config['before_basic'] . $post_type_obj->labels->name . $this->config['after_basic'];
|
||||
}
|
||||
}
|
||||
// Add pagination numbers
|
||||
if ( get_query_var( 'paged' ) AND ! ( get_post_type() == 'topic' OR get_post_type() == 'forum' ) ) {
|
||||
if ( is_category() OR is_day() OR is_month() OR is_year() OR is_search() OR is_tag() OR is_author() ) {
|
||||
$output .= ' (';
|
||||
} else {
|
||||
$output .= $this->config['delimiter'];
|
||||
}
|
||||
$output .= us_translate_x( 'Page', 'post type singular name' ) . ' ' . get_query_var( 'paged' );
|
||||
if ( is_category() OR is_day() OR is_month() OR is_year() OR is_search() OR is_tag() OR is_author() ) {
|
||||
$output .= ')';
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
if ( ! function_exists( 'us_comment_start' ) ) {
|
||||
function us_comment_start( $comment, $args, $depth ) {
|
||||
$GLOBALS['comment'] = $comment;
|
||||
$author_link_start = $author_link_end = '';
|
||||
$author_url = get_comment_author_url();
|
||||
if ( $author_url != '' ) {
|
||||
$author_link_start = '<a href="' . $author_url . '" target="_blank" rel="nofollow">';
|
||||
$author_link_end = '</a>';
|
||||
}
|
||||
?>
|
||||
<div <?php comment_class( 'w-comments-item' ) ?> id="comment-<?php comment_ID() ?>">
|
||||
<div class="w-comments-item-meta">
|
||||
<?php echo $author_link_start; ?>
|
||||
<div class="w-comments-item-icon">
|
||||
<?php echo get_avatar( $comment, $size = '50' ); ?>
|
||||
</div>
|
||||
<div class="w-comments-item-author"><span><?php echo get_comment_author(); ?></span></div>
|
||||
<?php echo $author_link_end; ?>
|
||||
<a class="w-comments-item-date smooth-scroll" href="#comment-<?php comment_ID() ?>"><?php echo get_comment_date() . ' ' . get_comment_time() ?></a>
|
||||
</div>
|
||||
<div class="w-comments-item-text">
|
||||
<?php if ( $comment->comment_approved == '0') { ?>
|
||||
<div class="w-message color_yellow"><?php echo us_translate( 'Your comment is awaiting moderation.' ) ?></div>
|
||||
<?php }
|
||||
comment_text(); ?>
|
||||
</div>
|
||||
<?php comment_reply_link(
|
||||
array_merge(
|
||||
$args,
|
||||
array( 'depth' => $depth )
|
||||
)
|
||||
) ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'us_comment_end' ) ) {
|
||||
function us_comment_end( $comment, $args, $depth ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Write some variable value to debug file, when it's hard to output it directly
|
||||
*
|
||||
* @param $value
|
||||
* @param bool|FALSE $with_backtrace
|
||||
*/
|
||||
function us_write_debug( $value, $with_backtrace = FALSE ) {
|
||||
global $us_template_directory;
|
||||
static $first = TRUE;
|
||||
$data = '';
|
||||
if ( $with_backtrace ) {
|
||||
$backtrace = debug_backtrace();
|
||||
array_shift( $backtrace );
|
||||
$data .= print_r( $backtrace, TRUE ) . ":\n";
|
||||
}
|
||||
ob_start();
|
||||
var_dump( $value );
|
||||
$data .= ob_get_clean() . "\n\n";
|
||||
file_put_contents( $us_template_directory . '/debug.txt', $data, $first ? NULL : FILE_APPEND );
|
||||
$first = FALSE;
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Embed Google Fonts
|
||||
*/
|
||||
if ( us_get_option( 'lazyload_fonts', 0 ) == 1 ) {
|
||||
add_action( 'wp_footer', 'us_enqueue_fonts' );
|
||||
} else {
|
||||
add_action( 'wp_enqueue_scripts', 'us_enqueue_fonts' );
|
||||
}
|
||||
function us_enqueue_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( 'get_h1' );
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
$subset = '&subset=' . us_get_option( 'font_subset', 'latin' );
|
||||
$font_family = '';
|
||||
|
||||
foreach ( $fonts as $font_name => $font_variants ) {
|
||||
if ( count( $font_variants ) == 0 ) {
|
||||
continue;
|
||||
}
|
||||
$font_variants = array_unique( $font_variants );
|
||||
if ( $font_family != '' ) {
|
||||
$font_family .= urlencode( '|' );
|
||||
}
|
||||
$font_family .= $font_name . ':' . implode( ',', $font_variants );
|
||||
}
|
||||
if ( $font_family != '' ) {
|
||||
$font_url = 'https://fonts.googleapis.com/css?family=' . $font_family . $subset;
|
||||
wp_enqueue_style( 'us-fonts', $font_url );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Embed CSS files
|
||||
*/
|
||||
add_action( 'wp_enqueue_scripts', 'us_styles', 12 );
|
||||
function us_styles() {
|
||||
global $us_template_directory_uri;
|
||||
|
||||
$assets_config = us_config( 'assets', array() );
|
||||
|
||||
// Embed all CSS components, when DEV mode is enabled
|
||||
if ( defined( 'US_DEV' ) AND US_DEV ) {
|
||||
foreach ( $assets_config as $component => $component_atts ) {
|
||||
if ( isset( $component_atts['css'] ) ) {
|
||||
wp_enqueue_style( 'us-' . $component, $us_template_directory_uri . $component_atts['css'], array(), US_THEMEVERSION, 'all' );
|
||||
}
|
||||
}
|
||||
// Generate and embed single CSS file
|
||||
} elseif ( us_get_option( 'optimize_assets', 0 ) == 1 ) {
|
||||
|
||||
// Locate asset file
|
||||
$css_file = us_get_asset_file( 'css' );
|
||||
|
||||
// If the file doesn't exist
|
||||
if ( ! file_exists( $css_file ) ) {
|
||||
|
||||
// try to create the styles file
|
||||
us_generate_asset_file( 'css' );
|
||||
|
||||
// if create attempt failed
|
||||
if ( ! file_exists( $css_file ) ) {
|
||||
|
||||
// switch the Optimize option off
|
||||
global $usof_options;
|
||||
usof_load_options_once();
|
||||
$updated_options = $usof_options;
|
||||
$updated_options['optimize_assets'] = 0;
|
||||
usof_save_options( $updated_options );
|
||||
|
||||
// and load all styles to make sure site looks as it should
|
||||
foreach ( $assets_config as $component => $component_atts ) {
|
||||
wp_enqueue_style( 'us-' . $component, $us_template_directory_uri . $component_atts['css'], array(), US_THEMEVERSION, 'all' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Embed generated file
|
||||
if ( file_exists( $css_file ) ) {
|
||||
$css_file_url = us_get_asset_file( 'css', TRUE );
|
||||
wp_enqueue_style( 'us-theme', $css_file_url, array(), US_THEMEVERSION, 'all' );
|
||||
}
|
||||
|
||||
// Remove WP Block Editor styles
|
||||
wp_dequeue_style( 'wp-block-library' );
|
||||
|
||||
} else { // Embed default CSS file in other cases
|
||||
wp_register_style( 'us-style', $us_template_directory_uri . '/css/style.min.css', array(), US_THEMEVERSION, 'all' );
|
||||
wp_enqueue_style( 'us-style' );
|
||||
}
|
||||
}
|
||||
|
||||
// RTL styles
|
||||
add_action( 'wp_enqueue_scripts', 'us_rtl_styles', 15 );
|
||||
function us_rtl_styles() {
|
||||
global $us_template_directory_uri;
|
||||
|
||||
$min_ext = ( ! ( defined( 'US_DEV' ) AND US_DEV ) ) ? '.min' : '';
|
||||
if ( is_rtl() ) {
|
||||
wp_register_style( 'us-rtl', $us_template_directory_uri . '/css/rtl' . $min_ext . '.css', array(), US_THEMEVERSION, 'all' );
|
||||
wp_enqueue_style( 'us-rtl' );
|
||||
}
|
||||
}
|
||||
|
||||
// Responsive styles
|
||||
if ( us_get_option( 'responsive_layout', TRUE ) AND ( ( defined( 'US_DEV' ) AND US_DEV ) OR us_get_option( 'optimize_assets', 0 ) == 0 ) ) {
|
||||
add_action( 'wp_enqueue_scripts', 'us_responsive_styles', 16 );
|
||||
function us_responsive_styles() {
|
||||
global $us_template_directory_uri;
|
||||
|
||||
$min_ext = ( ! ( defined( 'US_DEV' ) AND US_DEV ) ) ? '.min' : '';
|
||||
wp_register_style( 'us-responsive', $us_template_directory_uri . '/css/responsive' . $min_ext . '.css', array(), US_THEMEVERSION, 'all' );
|
||||
wp_enqueue_style( 'us-responsive' );
|
||||
}
|
||||
}
|
||||
|
||||
// Child theme styles
|
||||
add_action( 'wp_enqueue_scripts', 'us_custom_styles', 18 );
|
||||
function us_custom_styles() {
|
||||
if ( is_child_theme() ) {
|
||||
global $us_stylesheet_directory_uri;
|
||||
wp_enqueue_style( 'theme-style', $us_stylesheet_directory_uri . '/style.css', array(), US_THEMEVERSION, 'all' );
|
||||
}
|
||||
}
|
||||
|
||||
// Disable jQuery migrate script
|
||||
if ( us_get_option( 'disable_jquery_migrate', 1 ) == 1 ) {
|
||||
add_action( 'wp_default_scripts', 'us_dequeue_jquery_migrate' );
|
||||
}
|
||||
function us_dequeue_jquery_migrate( &$wp_scripts ) {
|
||||
if ( is_admin() ) {
|
||||
return;
|
||||
}
|
||||
$jquery_core_obj = $wp_scripts->registered['jquery-core'];
|
||||
$wp_scripts->remove( 'jquery' );
|
||||
$wp_scripts->add( 'jquery', FALSE, array( 'jquery-core' ), $jquery_core_obj->ver );
|
||||
}
|
||||
|
||||
// Move jQuery scripts to the footer
|
||||
if ( us_get_option( 'jquery_footer', 1 ) == 1 ) {
|
||||
add_action( 'wp_default_scripts', 'us_move_jquery_to_footer' );
|
||||
}
|
||||
function us_move_jquery_to_footer( $wp_scripts ) {
|
||||
if ( is_admin() ) {
|
||||
return;
|
||||
}
|
||||
$wp_scripts->add_data( 'jquery', 'group', 1 );
|
||||
$wp_scripts->add_data( 'jquery-core', 'group', 1 );
|
||||
$wp_scripts->add_data( 'jquery-migrate', 'group', 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Embed JS files
|
||||
*/
|
||||
add_action( 'wp_enqueue_scripts', 'us_jscripts' );
|
||||
function us_jscripts() {
|
||||
global $us_template_directory_uri;
|
||||
|
||||
// Link Google Maps API key
|
||||
if ( us_get_option( 'gmaps_api_key', '' ) != '' ) {
|
||||
wp_register_script( 'us-google-maps', '//maps.googleapis.com/maps/api/js?key=' . trim( esc_attr( us_get_option( 'gmaps_api_key', '' ) ) ), array(), NULL, FALSE );
|
||||
} else {
|
||||
wp_register_script( 'us-google-maps', '//maps.googleapis.com/maps/api/js', array(), '', FALSE );
|
||||
}
|
||||
|
||||
// Embed vendor JS components
|
||||
if ( us_get_option( 'ajax_load_js', 0 ) == 0 ) {
|
||||
wp_register_script( 'us-isotope', $us_template_directory_uri . '/framework/js/vendor/isotope.js', array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
wp_register_script( 'us-royalslider', $us_template_directory_uri . '/framework/js/vendor/royalslider.js', array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
wp_register_script( 'us-owl', $us_template_directory_uri . '/framework/js/vendor/owl.carousel.js', array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
wp_register_script( 'us-gmap', $us_template_directory_uri . '/framework/js/vendor/gmaps.js', array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
wp_register_script( 'us-lmap', $us_template_directory_uri . '/framework/js/vendor/leaflet.js', array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
wp_register_script( 'us-magnific-popup', $us_template_directory_uri . '/framework/js/vendor/magnific-popup.js', array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
wp_enqueue_script( 'us-magnific-popup' );
|
||||
}
|
||||
|
||||
// Embed all JS components, when DEV mode is enabled
|
||||
if ( defined( 'US_DEV' ) AND US_DEV ) {
|
||||
$assets_config = us_config( 'assets', array() );
|
||||
foreach ( $assets_config as $component => $component_atts ) {
|
||||
if ( isset( $component_atts['js'] ) AND isset( $component_atts['order'] ) AND $component_atts['order'] == 'top' ) {
|
||||
wp_enqueue_script( 'us-' . $component, $us_template_directory_uri . $component_atts['js'], array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
}
|
||||
}
|
||||
foreach ( $assets_config as $component => $component_atts ) {
|
||||
if ( isset( $component_atts['js'] ) AND ! isset( $component_atts['order'] ) ) {
|
||||
wp_enqueue_script( 'us-' . $component, $us_template_directory_uri . $component_atts['js'], array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
}
|
||||
}
|
||||
// Generate and embed single JS file
|
||||
} elseif ( us_get_option( 'optimize_assets', 0 ) == 1 ) {
|
||||
|
||||
// Locate asset file
|
||||
$js_file = us_get_asset_file( 'js' );
|
||||
|
||||
// If the file doesn't exist
|
||||
if ( ! file_exists( $js_file ) ) {
|
||||
|
||||
// try to create the styles file
|
||||
us_generate_asset_file( 'js' );
|
||||
|
||||
// if create attempt failed
|
||||
if ( ! file_exists( $js_file ) ) {
|
||||
|
||||
// switch the Optimize option off
|
||||
global $usof_options;
|
||||
usof_load_options_once();
|
||||
$updated_options = $usof_options;
|
||||
$updated_options['optimize_assets'] = 0;
|
||||
usof_save_options( $updated_options );
|
||||
|
||||
// and load default core file to make sure site works
|
||||
wp_enqueue_script( 'us-core', $us_template_directory_uri . '/js/us.core.min.js', array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
// Embed generated file
|
||||
if ( file_exists( $js_file ) ) {
|
||||
$js_file_url = us_get_asset_file( 'js', TRUE );
|
||||
wp_register_script( 'us-core', $js_file_url, array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
} else {
|
||||
wp_register_script( 'us-core', $us_template_directory_uri . '/js/us.core.min.js', array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
}
|
||||
wp_enqueue_script( 'us-core' );
|
||||
|
||||
} else { // Embed default core file in other cases
|
||||
wp_enqueue_script( 'us-core', $us_template_directory_uri . '/js/us.core.min.js', array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
// Output Custom HTML before </body>
|
||||
add_action( 'wp_footer', 'us_custom_html_output', 99 );
|
||||
function us_custom_html_output() {
|
||||
echo us_get_option( 'custom_html', '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and cache theme options css data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function us_get_theme_options_css() {
|
||||
if ( ( $styles_css = get_option( 'us_theme_options_css' ) ) === FALSE OR ( defined( 'US_DEV' ) AND US_DEV ) ) {
|
||||
$styles_css = us_minify_css( us_get_template( 'config/theme-options.css' ) );
|
||||
if ( ! defined( 'US_DEV' ) OR ! US_DEV ) {
|
||||
update_option( 'us_theme_options_css', $styles_css, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
return $styles_css;
|
||||
}
|
||||
@@ -0,0 +1,758 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Get header option for the specified state
|
||||
*
|
||||
* @param string $name Option name
|
||||
* @param string $state Header state: 'default' / 'tablets' / 'mobiles'
|
||||
* @param string $default
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function us_get_header_option( $name, $state = 'default', $default = NULL ) {
|
||||
global $us_header_settings;
|
||||
us_load_header_settings_once();
|
||||
$shared_options = array( 'top_fullwidth', 'middle_fullwidth', 'bottom_fullwidth' );
|
||||
if ( $state != 'default' AND ( ! isset( $us_header_settings[ $state ]['options'][ $name ] ) OR in_array( $name, $shared_options ) ) ) {
|
||||
$state = 'default';
|
||||
}
|
||||
|
||||
return isset( $us_header_settings[ $state ]['options'][ $name ] ) ? $us_header_settings[ $state ]['options'][ $name ] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get header layout for the specified state
|
||||
*
|
||||
* @param $state
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function us_get_header_layout( $state = 'default' ) {
|
||||
global $us_header_settings;
|
||||
us_load_header_settings_once();
|
||||
$layout = array(
|
||||
'top_left' => array(),
|
||||
'top_center' => array(),
|
||||
'top_right' => array(),
|
||||
'middle_left' => array(),
|
||||
'middle_center' => array(),
|
||||
'middle_right' => array(),
|
||||
'bottom_left' => array(),
|
||||
'bottom_center' => array(),
|
||||
'bottom_right' => array(),
|
||||
'hidden' => array(),
|
||||
);
|
||||
if ( $state != 'default' AND isset( $us_header_settings['default']['layout'] ) AND is_array( $us_header_settings['default']['layout'] ) ) {
|
||||
$layout = array_merge( $layout, $us_header_settings['default']['layout'] );
|
||||
}
|
||||
if ( isset( $us_header_settings[ $state ]['layout'] ) AND is_array( $us_header_settings[ $state ]['layout'] ) ) {
|
||||
$layout = array_merge( $layout, $us_header_settings[ $state ]['layout'] );
|
||||
}
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the current header settings for all possible responsive states
|
||||
*/
|
||||
function us_load_header_settings_once() {
|
||||
|
||||
global $us_header_settings;
|
||||
|
||||
if ( isset( $us_header_settings ) ) {
|
||||
return;
|
||||
}
|
||||
// Basic structure
|
||||
$us_header_settings = array(
|
||||
'default' => array( 'options' => array(), 'layout' => array() ),
|
||||
'tablets' => array( 'options' => array(), 'layout' => array() ),
|
||||
'mobiles' => array( 'options' => array(), 'layout' => array() ),
|
||||
'data' => array(),
|
||||
);
|
||||
$us_header_settings = apply_filters( 'us_load_header_settings', $us_header_settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Translating the v.2 USOF header settings to v.3 header-builder compatible ones
|
||||
*/
|
||||
add_filter( 'us_load_header_settings', 'us_load_usof_header_settings' );
|
||||
function us_load_usof_header_settings( $header_settings ) {
|
||||
|
||||
global $usof_options;
|
||||
usof_load_options_once();
|
||||
|
||||
// Side options defaults from theme-options.php config
|
||||
$side_options_config = us_config( 'header-settings.options', array() );
|
||||
foreach ( $side_options_config as $section_name => $section_options ) {
|
||||
foreach ( $section_options as $field_name => $field ) {
|
||||
$field_value = isset( $field['std'] ) ? $field['std'] : '';
|
||||
$header_settings['default']['options'][ $field_name ] = $field_value;
|
||||
$header_settings['tablets']['options'][ $field_name ] = $field_value;
|
||||
$header_settings['mobiles']['options'][ $field_name ] = $field_value;
|
||||
}
|
||||
}
|
||||
|
||||
// Layout-defined values
|
||||
$header_templates = us_config( 'header-templates', array() );
|
||||
if ( isset( $usof_options['header_layout'] ) AND isset( $header_templates[ $usof_options['header_layout'] ] ) ) {
|
||||
$header_template = us_fix_header_template_settings( $header_templates[ $usof_options['header_layout'] ] );
|
||||
$header_settings = us_array_merge( $header_settings, $header_template );
|
||||
}
|
||||
|
||||
// Filling elements' data with default values
|
||||
$header_settings = us_fix_header_settings( $header_settings );
|
||||
|
||||
// Side options
|
||||
$rules = array(
|
||||
'header_transparent' => array(
|
||||
'new_name' => 'transparent',
|
||||
),
|
||||
'header_fullwidth' => array(
|
||||
'new_names' => array( 'top_fullwidth', 'middle_fullwidth', 'bottom_fullwidth' ),
|
||||
),
|
||||
'header_top_height' => array(
|
||||
'new_name' => 'top_height',
|
||||
),
|
||||
'header_top_sticky_height' => array(
|
||||
'new_name' => 'top_sticky_height',
|
||||
),
|
||||
'header_middle_height' => array(
|
||||
'new_name' => 'middle_height',
|
||||
),
|
||||
'header_middle_sticky_height' => array(
|
||||
'new_name' => 'middle_sticky_height',
|
||||
),
|
||||
'header_bottom_height' => array(
|
||||
'new_name' => 'bottom_height',
|
||||
),
|
||||
'header_bottom_sticky_height' => array(
|
||||
'new_name' => 'bottom_sticky_height',
|
||||
),
|
||||
'header_main_width' => array(
|
||||
'new_name' => 'width',
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( $rules as $old_name => $rule ) {
|
||||
if ( ! isset( $usof_options[ $old_name ] ) AND ( isset( $rule['new_name'] ) OR isset( $rule['new_names'] ) ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( isset( $rule['transfer_if'] ) AND ! usof_execute_show_if( $rule['transfer_if'], $usof_options ) ) {
|
||||
continue;
|
||||
}
|
||||
$new_names = isset( $rule['new_names'] ) ? $rule['new_names'] : array( $rule['new_name'] );
|
||||
foreach ( $new_names as $new_name ) {
|
||||
$header_settings['default']['options'][ $new_name ] = $usof_options[ $old_name ];
|
||||
}
|
||||
}
|
||||
|
||||
// header_sticky => sticky
|
||||
if ( isset( $usof_options['header_sticky'] ) ) {
|
||||
if ( is_array( $usof_options['header_sticky'] ) ) {
|
||||
foreach ( array( 'default', 'tablets', 'mobiles' ) as $layout ) {
|
||||
$header_settings[ $layout ]['options']['sticky'] = in_array( $layout, $usof_options['header_sticky'] );
|
||||
}
|
||||
} else {
|
||||
$header_settings['default']['options']['sticky'] = $usof_options['header_sticky'];
|
||||
$header_settings['tablets']['options']['sticky'] = $usof_options['header_sticky'];
|
||||
$header_settings['mobiles']['options']['sticky'] = $usof_options['header_sticky'];
|
||||
}
|
||||
}
|
||||
|
||||
// Transferring elements' values
|
||||
$rules = array(
|
||||
'image:1' => array(
|
||||
'show_if' => array( 'logo_type', '=', 'img' ),
|
||||
'values' => array(
|
||||
'img' => '=logo_image',
|
||||
'link' => array( 'url' => '/' ),
|
||||
'height' => '=logo_height',
|
||||
'height_tablets' => '=logo_height_tablets',
|
||||
'height_mobiles' => '=logo_height_mobiles',
|
||||
'height_sticky' => '=logo_height_sticky',
|
||||
'height_sticky_tablets' => '=logo_height_tablets',
|
||||
'height_sticky_mobiles' => '=logo_height_mobiles',
|
||||
),
|
||||
),
|
||||
'text:1' => array(
|
||||
'show_if' => array( 'logo_type', '=', 'text' ),
|
||||
'values' => array(
|
||||
'text' => '=logo_text',
|
||||
'link' => array( 'url' => '/' ),
|
||||
'size' => '=logo_font_size',
|
||||
'size_tablets' => '=logo_font_size_tablets',
|
||||
'size_mobiles' => '=logo_font_size_mobiles',
|
||||
),
|
||||
),
|
||||
'text:2' => array(
|
||||
'show_if' => array(
|
||||
array( 'header_contacts_show', '=', 1 ),
|
||||
'and',
|
||||
array( 'header_contacts_phone', '!=', '' ),
|
||||
),
|
||||
'values' => array(
|
||||
'text' => '=header_contacts_phone',
|
||||
'icon' => 'fas|phone',
|
||||
),
|
||||
),
|
||||
'text:3' => array(
|
||||
'show_if' => array(
|
||||
array( 'header_contacts_show', '=', 1 ),
|
||||
'and',
|
||||
array( 'header_contacts_email', '!=', '' ),
|
||||
),
|
||||
'values' => array(
|
||||
'text' => '=header_contacts_email',
|
||||
'icon' => 'fas|envelope',
|
||||
),
|
||||
),
|
||||
'menu:1' => array(
|
||||
'values' => array(
|
||||
'source' => '=menu_source',
|
||||
'font_size' => '=menu_fontsize',
|
||||
'indents' => '=menu_indents',
|
||||
'vstretch' => '=menu_height',
|
||||
'dropdown_font_size' => '=menu_sub_fontsize',
|
||||
'mobile_width' => '=menu_mobile_width',
|
||||
'mobile_behavior' => '=menu_togglable_type',
|
||||
'mobile_font_size' => '=menu_fontsize_mobile',
|
||||
'mobile_dropdown_font_size' => '=menu_sub_fontsize_mobile',
|
||||
),
|
||||
),
|
||||
'search:1' => array(
|
||||
'show_if' => array( 'header_search_show', '=', 1 ),
|
||||
'values' => array(
|
||||
'layout' => '=header_search_layout',
|
||||
),
|
||||
),
|
||||
'socials:1' => array(
|
||||
'values' => array(
|
||||
'items' => array(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( $rules as $elm => $rule ) {
|
||||
if ( ! isset( $header_settings['data'][ $elm ] ) ) {
|
||||
$header_settings['data'][ $elm ] = array();
|
||||
$type = strtok( $elm, ':' );
|
||||
// Setting default values for fallback
|
||||
$elm_config = us_config( 'elements/' . $type, array() );
|
||||
foreach ( $elm_config['params'] as $field_name => $field ) {
|
||||
$value = isset( $field['std'] ) ? $field['std'] : '';
|
||||
// Some default header values may be based on main theme options' values
|
||||
if ( is_string( $value ) AND substr( $value, 0, 1 ) == '=' AND isset( $usof_options[ substr( $value, 1 ) ] ) ) {
|
||||
$value = $usof_options[ substr( $value, 1 ) ];
|
||||
}
|
||||
$header_settings['data'][ $elm ][ $field_name ] = $value;
|
||||
}
|
||||
}
|
||||
// Setting values
|
||||
if ( isset( $rule['values'] ) AND is_array( $rule['values'] ) ) {
|
||||
foreach ( $rule['values'] as $key => $value ) {
|
||||
if ( is_string( $value ) AND substr( $value, 0, 1 ) == '=' ) {
|
||||
$old_key = substr( $value, 1 );
|
||||
if ( ! isset( $usof_options[ $old_key ] ) ) {
|
||||
continue;
|
||||
}
|
||||
$value = $usof_options[ $old_key ];
|
||||
}
|
||||
$header_settings['data'][ $elm ][ $key ] = $value;
|
||||
}
|
||||
}
|
||||
// Hiding the element when needed
|
||||
if ( isset( $rule['show_if'] ) AND ! usof_execute_show_if( $rule['show_if'], $usof_options ) ) {
|
||||
foreach ( array( 'default', 'tablets', 'mobiles' ) as $layout ) {
|
||||
foreach ( $header_settings[ $layout ]['layout'] as $cell => $cell_elms ) {
|
||||
if ( $cell == 'hidden' ) {
|
||||
continue;
|
||||
}
|
||||
if ( ( $elm_pos = array_search( $elm, $cell_elms ) ) !== FALSE ) {
|
||||
array_splice( $header_settings[ $layout ]['layout'][ $cell ], $elm_pos, 1 );
|
||||
$header_settings[ $layout ]['layout']['hidden'][] = $elm;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Logos for tablets and mobiles states
|
||||
if ( isset( $header_settings['data']['image:1'] ) ) {
|
||||
foreach ( array( 'tablets' => 'image:2', 'mobiles' => 'image:3' ) as $layout => $key ) {
|
||||
if ( isset( $header_settings['data'][ $key ] ) OR ! isset( $usof_options[ 'logo_image_' . $layout ] ) OR empty( $usof_options[ 'logo_image_' . $layout ] ) ) {
|
||||
continue;
|
||||
}
|
||||
$header_settings['data'][ $key ] = array_merge(
|
||||
$header_settings['data']['image:1'], array(
|
||||
'img' => $usof_options[ 'logo_image_' . $layout ],
|
||||
'img_transparent' => '',
|
||||
)
|
||||
);
|
||||
foreach ( $header_settings[ $layout ]['layout'] as $cell => $cell_elms ) {
|
||||
if ( $cell == 'hidden' ) {
|
||||
continue;
|
||||
}
|
||||
if ( ( $elm_pos = array_search( 'image:1', $cell_elms ) ) !== FALSE ) {
|
||||
$header_settings[ $layout ]['layout'][ $cell ][ $elm_pos ] = $key;
|
||||
$header_settings[ $layout ]['layout']['hidden'][] = 'image:1';
|
||||
break;
|
||||
}
|
||||
}
|
||||
$header_settings['default']['layout']['hidden'][] = $key;
|
||||
$header_settings[ ( $layout == 'tablets' ) ? 'mobiles' : 'tablets' ]['layout']['hidden'][] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
// Fixing text links
|
||||
if ( isset( $header_settings['data']['text:3'] ) AND isset( $header_settings['data']['text:3']['text'] ) ) {
|
||||
$header_settings['data']['text:3']['link'] = 'mailto:' . $header_settings['data']['text:3']['text'];
|
||||
}
|
||||
|
||||
// Inverting logo position
|
||||
if ( isset( $usof_options['header_invert_logo_pos'] ) AND $usof_options['header_invert_logo_pos'] ) {
|
||||
foreach ( array( 'default', 'tablets', 'mobiles' ) as $layout ) {
|
||||
if ( isset( $header_settings[ $layout ]['layout']['middle_left'] ) AND isset( $header_settings[ $layout ]['layout']['middle_left'] ) ) {
|
||||
$tmp = $header_settings[ $layout ]['layout']['middle_left'];
|
||||
$header_settings[ $layout ]['layout']['middle_left'] = $header_settings[ $layout ]['layout']['middle_right'];
|
||||
$header_settings[ $layout ]['layout']['middle_right'] = $tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $header_settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively output elements of a certain state / place
|
||||
*
|
||||
* @param array $settings Current layout
|
||||
* @param string $state Current state
|
||||
* @param string $place Outputted place
|
||||
* @param string $context 'header' / 'grid'
|
||||
*/
|
||||
function us_output_builder_elms( &$settings, $state, $place, $context = 'header' ) {
|
||||
|
||||
$layout = &$settings[ $state ]['layout'];
|
||||
$data = &$settings['data'];
|
||||
if ( ! isset( $layout[ $place ] ) OR ! is_array( $layout[ $place ] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set 3 states for header and 1 for other contexts, like Grid Layouts
|
||||
$_states = ( $context === 'header' ) ? array( 'default', 'tablets', 'mobiles' ) : array( 'default' );
|
||||
|
||||
$visible_elms = array();
|
||||
foreach ( $_states as $_state ) {
|
||||
$visible_elms[ $_state ] = us_get_builder_shown_elements_list( us_arr_path( $settings, $_state . '.layout', array() ) );
|
||||
}
|
||||
|
||||
foreach ( $layout[ $place ] as $elm ) {
|
||||
$classes = '';
|
||||
if ( $context === 'header' ) {
|
||||
if ( isset( $data[ $elm ] ) ) {
|
||||
if ( us_arr_path( $data[ $elm ], 'hide_for_sticky', FALSE ) ) {
|
||||
$classes .= ' hide-for-sticky';
|
||||
}
|
||||
if ( us_arr_path( $data[ $elm ], 'hide_for_not_sticky', FALSE ) ) {
|
||||
$classes .= ' hide-for-not-sticky';
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ( $_states as $_state ) {
|
||||
if ( ! in_array( $elm, $visible_elms[ $_state ] ) ) {
|
||||
$classes .= ' hidden_for_' . $_state;
|
||||
}
|
||||
}
|
||||
if ( $context === 'header' ) {
|
||||
$classes .= ' ush_' . str_replace( ':', '_', $elm );
|
||||
} elseif ( in_array( $context, array( 'grid', 'grid_term' ) ) ) {
|
||||
$classes .= ' usg_' . str_replace( ':', '_', $elm );
|
||||
}
|
||||
if ( substr( $elm, 1, 7 ) == 'wrapper' ) {
|
||||
// Wrapper
|
||||
$type = strtok( $elm, ':' );
|
||||
if ( isset( $data[ $elm ] ) ) {
|
||||
if ( isset( $data[ $elm ]['alignment'] ) ) {
|
||||
$classes .= ' align_' . $data[ $elm ]['alignment'];
|
||||
}
|
||||
if ( isset( $data[ $elm ]['valign'] ) ) {
|
||||
$classes .= ' valign_' . $data[ $elm ]['valign'];
|
||||
}
|
||||
if ( isset( $data[ $elm ]['wrap'] ) AND $data[ $elm ]['wrap'] ) {
|
||||
$classes .= ' wrap';
|
||||
}
|
||||
if ( isset( $data[ $elm ]['bg_gradient'] ) AND $data[ $elm ]['bg_gradient'] ) {
|
||||
$classes .= ' bg_gradient';
|
||||
}
|
||||
if ( isset( $data[ $elm ]['el_class'] ) ) {
|
||||
$classes .= ' ' . $data[ $elm ]['el_class'];
|
||||
}
|
||||
}
|
||||
echo '<div class="w-' . $type . $classes . '">';
|
||||
us_output_builder_elms( $settings, $state, $elm, $context );
|
||||
echo '</div>';
|
||||
} else {
|
||||
// Element
|
||||
$type = strtok( $elm, ':' );
|
||||
$defaults = us_get_elm_defaults( $type, $context );
|
||||
if ( ! isset( $data[ $elm ] ) ) {
|
||||
$data[ $elm ] = us_get_elm_defaults( $type, $context );
|
||||
} else {
|
||||
if ( ! empty( $data[ $elm ]['color_text'] ) ) {
|
||||
$classes .= ' with_text_color';
|
||||
}
|
||||
if ( $context === 'header' AND ! empty( $data[ $elm ]['el_class'] ) ) {
|
||||
$classes .= ' ' . $data[ $elm ]['el_class'];
|
||||
}
|
||||
}
|
||||
$values = array_merge( $defaults, array_intersect_key( $data[ $elm ], $defaults ) );
|
||||
$values['id'] = $elm;
|
||||
$values['classes'] = ( isset( $values['classes'] ) ? $values['classes'] : '' ) . $classes;
|
||||
$values['us_elm_context'] = $context;
|
||||
|
||||
// Adding special classes
|
||||
us_load_template( 'templates/elements/' . $type, $values );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default value for an element
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $context 'header' or 'grid'
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function us_get_elm_defaults( $type, $context = 'header' ) {
|
||||
global $us_elm_defaults, $usof_options;
|
||||
if ( ! isset( $us_elm_defaults ) ) {
|
||||
$us_elm_defaults = array();
|
||||
}
|
||||
if ( ! isset( $us_elm_defaults[ $context ] ) ) {
|
||||
$us_elm_defaults[ $context ] = array();
|
||||
}
|
||||
if ( ! isset( $us_elm_defaults[ $context ][ $type ] ) ) {
|
||||
$us_elm_defaults[ $context ][ $type ] = array();
|
||||
$elm_config = us_config( 'elements/' . $type, array() );
|
||||
foreach ( $elm_config['params'] as $field_name => $field ) {
|
||||
$value = isset( $field['std'] ) ? $field['std'] : '';
|
||||
if ( $context === 'header' ) {
|
||||
// Some default header values may be based on main theme options' values
|
||||
usof_load_options_once();
|
||||
if ( is_string( $value ) AND substr( $value, 0, 1 ) == '=' AND isset( $usof_options[ substr( $value, 1 ) ] ) ) {
|
||||
$value = $usof_options[ substr( $value, 1 ) ];
|
||||
}
|
||||
}
|
||||
$us_elm_defaults[ $context ][ $type ][ $field_name ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return us_arr_path( $us_elm_defaults, array( $context, $type ), array() );
|
||||
}
|
||||
|
||||
// Backward compability with older HB versions
|
||||
if ( ! function_exists( 'us_get_header_elm_defaults' ) ) {
|
||||
function us_get_header_elm_defaults( $type ) {
|
||||
return us_get_elm_defaults( $type, 'header' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elements
|
||||
*
|
||||
* @param string $type
|
||||
* @param bool $key_as_class Should the keys of the resulting array be css classes instead of elms ids?
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function us_get_header_elms_of_a_type( $type, $key_as_class = TRUE ) {
|
||||
global $us_header_settings;
|
||||
us_load_header_settings_once();
|
||||
$defaults = us_get_elm_defaults( $type, 'header' );
|
||||
$result = array();
|
||||
if ( ! is_array( $us_header_settings['data'] ) ) {
|
||||
return $result;
|
||||
}
|
||||
foreach ( $us_header_settings['data'] as $elm_id => $elm ) {
|
||||
if ( strtok( $elm_id, ':' ) != $type ) {
|
||||
continue;
|
||||
}
|
||||
$key = $key_as_class ? ( 'ush_' . str_replace( ':', '_', $elm_id ) ) : $elm_id;
|
||||
$result[ $key ] = array_merge( $defaults, array_intersect_key( $elm, $defaults ) );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the provided header settings value consistent and proper
|
||||
*
|
||||
* @param $value array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function us_fix_header_settings( $value ) {
|
||||
if ( empty( $value ) OR ! is_array( $value ) ) {
|
||||
$value = array();
|
||||
}
|
||||
if ( ! isset( $value['data'] ) OR ! is_array( $value['data'] ) ) {
|
||||
$value['data'] = array();
|
||||
}
|
||||
$options_defaults = array();
|
||||
foreach ( us_config( 'header-settings.options', array() ) as $group => $opts ) {
|
||||
foreach ( $opts as $opt_name => $opt ) {
|
||||
$options_defaults[ $opt_name ] = isset( $opt['std'] ) ? $opt['std'] : '';
|
||||
}
|
||||
}
|
||||
foreach ( array( 'default', 'tablets', 'mobiles' ) as $state ) {
|
||||
if ( ! isset( $value[ $state ] ) OR ! is_array( $value[ $state ] ) ) {
|
||||
$value[ $state ] = array();
|
||||
}
|
||||
if ( ! isset( $value[ $state ]['layout'] ) OR ! is_array( $value[ $state ]['layout'] ) ) {
|
||||
if ( $state != 'default' AND isset( $value['default']['layout'] ) ) {
|
||||
$value[ $state ]['layout'] = $value['default']['layout'];
|
||||
} else {
|
||||
$value[ $state ]['layout'] = array();
|
||||
}
|
||||
}
|
||||
$state_elms = array();
|
||||
foreach ( $value[ $state ]['layout'] as $place => $elms ) {
|
||||
if ( ! is_array( $elms ) ) {
|
||||
$elms = array();
|
||||
}
|
||||
foreach ( $elms as $index => $elm_id ) {
|
||||
if ( ! is_string( $elm_id ) OR strpos( $elm_id, ':' ) == - 1 ) {
|
||||
unset( $elms[ $index ] );
|
||||
} else {
|
||||
$state_elms[] = $elm_id;
|
||||
if ( ! isset( $value['data'][ $elm_id ] ) ) {
|
||||
$value['data'][ $elm_id ] = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
$value[ $state ]['layout'][ $place ] = array_values( $elms );
|
||||
}
|
||||
if ( ! isset( $value[ $state ]['layout']['hidden'] ) OR ! is_array( $value[ $state ]['layout']['hidden'] ) ) {
|
||||
$value[ $state ]['layout']['hidden'] = array();
|
||||
}
|
||||
$value[ $state ]['layout']['hidden'] = array_merge( $value[ $state ]['layout']['hidden'], array_diff( array_keys( $value['data'] ), $state_elms ) );
|
||||
// Fixing options
|
||||
if ( ! isset( $value[ $state ]['options'] ) OR ! is_array( $value[ $state ]['options'] ) ) {
|
||||
$value[ $state ]['options'] = array();
|
||||
}
|
||||
$value[ $state ]['options'] = array_merge( $options_defaults, ( $state != 'default' ) ? $value['default']['options'] : array(), $value[ $state ]['options'] );
|
||||
}
|
||||
|
||||
foreach ( $value['data'] as $elm_id => $values ) {
|
||||
$type = strtok( $elm_id, ':' );
|
||||
$defaults = us_get_elm_defaults( $type, 'header' );
|
||||
$value['data'][ $elm_id ] = array_merge( $defaults, array_intersect_key( $value['data'][ $elm_id ], $defaults ) );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function us_fix_header_template_settings( $value ) {
|
||||
|
||||
if ( isset( $value['title'] ) ) {
|
||||
// Don't need this in data processing
|
||||
unset( $value['title'] );
|
||||
}
|
||||
$template_structure = array(
|
||||
'default' => array( 'options' => array(), 'layout' => array() ),
|
||||
'tablets' => array( 'options' => array(), 'layout' => array() ),
|
||||
'mobiles' => array( 'options' => array(), 'layout' => array() ),
|
||||
'data' => array(),
|
||||
);
|
||||
$value = us_array_merge( $template_structure, $value );
|
||||
$layout_structure = array(
|
||||
'top_left' => array(),
|
||||
'top_center' => array(),
|
||||
'top_right' => array(),
|
||||
'middle_left' => array(),
|
||||
'middle_center' => array(),
|
||||
'middle_right' => array(),
|
||||
'bottom_left' => array(),
|
||||
'bottom_center' => array(),
|
||||
'bottom_right' => array(),
|
||||
'hidden' => array(),
|
||||
);
|
||||
foreach ( array( 'default', 'tablets', 'mobiles' ) as $state ) {
|
||||
// Options
|
||||
$value[ $state ]['options'] = array_merge( ( $state == 'default' ) ? array() : $value['default']['options'], $value[ $state ]['options'] );
|
||||
// Layout
|
||||
$value[ $state ]['layout'] = array_merge( $layout_structure, ( $state == 'default' ) ? array() : $value['default']['layout'], $value[ $state ]['layout'] );
|
||||
}
|
||||
$value = us_fix_header_settings( $value );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of user registered nav menus with theirs proper names, in a format sutable for usof select field
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function us_get_nav_menus() {
|
||||
$menus = array();
|
||||
foreach ( get_terms( 'nav_menu', array( 'hide_empty' => TRUE ) ) as $menu ) {
|
||||
$menus[ $menu->slug ] = $menu->name;
|
||||
}
|
||||
|
||||
// Adding us_main_menu location if it is filled with mene
|
||||
$theme_locations = get_nav_menu_locations();
|
||||
if ( isset( $theme_locations['us_main_menu'] ) ) {
|
||||
$menu_obj = get_term( $theme_locations['us_main_menu'], 'nav_menu' );
|
||||
if ( $menu_obj AND is_object( $menu_obj ) AND isset ( $menu_obj->name ) ) {
|
||||
$menus['location:us_main_menu'] = $menu_obj->name . ' (' . __( 'Custom Menu', 'us' ) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
return $menus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of header elements that are shown in the certain layout listing
|
||||
*
|
||||
* @param array $list Euther layout or separate list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function us_get_builder_shown_elements_list( $list ) {
|
||||
$shown = array();
|
||||
foreach ( $list as $key => $sublist ) {
|
||||
if ( $key != 'hidden' ) {
|
||||
$shown = array_merge( $shown, $sublist );
|
||||
}
|
||||
}
|
||||
|
||||
return $shown;
|
||||
}
|
||||
|
||||
// Changing ordering to avoid JavaScript errors with NextGEN Gallery plugin
|
||||
add_action( 'wp_footer', 'us_pass_header_settings_to_js', - 2 );
|
||||
function us_pass_header_settings_to_js() {
|
||||
global $us_header_settings;
|
||||
us_load_header_settings_once();
|
||||
$header_settings = $us_header_settings;
|
||||
if ( isset( $header_settings['data'] ) ) {
|
||||
unset( $header_settings['data'] );
|
||||
}
|
||||
echo '<script>';
|
||||
echo '$us.headerSettings = ' . json_encode( $header_settings ) . ';';
|
||||
echo '</script>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the header design options css for all the fields
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function us_get_header_design_options_css() {
|
||||
global $us_header_settings;
|
||||
us_load_header_settings_once();
|
||||
$tablets_breakpoint = ( isset( $us_header_settings['tablets']['options']['breakpoint'] ) ) ? intval( $us_header_settings['tablets']['options']['breakpoint'] ) : 900;
|
||||
$mobiles_breakpoint = ( isset( $us_header_settings['mobiles']['options']['breakpoint'] ) ) ? intval( $us_header_settings['mobiles']['options']['breakpoint'] ) : 600;
|
||||
$sizes = array(
|
||||
'default' => '@media (min-width: ' . $tablets_breakpoint . 'px)',
|
||||
'tablets' => '@media (min-width: ' . $mobiles_breakpoint . 'px) and (max-width: ' . ( $tablets_breakpoint - 1 ) . 'px)',
|
||||
'mobiles' => '@media (max-width: ' . ( $mobiles_breakpoint - 1 ) . 'px)',
|
||||
);
|
||||
$data = array();
|
||||
foreach ( $us_header_settings['data'] as $elm_id => $elm ) {
|
||||
if ( ! isset( $elm['design_options'] ) OR empty( $elm['design_options'] ) OR ! is_array( $elm['design_options'] ) ) {
|
||||
continue;
|
||||
}
|
||||
$elm_class = 'ush_' . str_replace( ':', '_', $elm_id );
|
||||
foreach ( $elm['design_options'] as $key => $value ) {
|
||||
if ( $value === '' ) {
|
||||
continue;
|
||||
}
|
||||
$key = explode( '_', $key );
|
||||
if ( ! isset( $data[ $key[2] ] ) ) {
|
||||
$data[ $key[2] ] = array();
|
||||
}
|
||||
if ( ! isset( $data[ $key[2] ][ $elm_class ] ) ) {
|
||||
$data[ $key[2] ][ $elm_class ] = array();
|
||||
}
|
||||
if ( ! isset( $data[ $key[2] ][ $elm_class ][ $key[0] ] ) ) {
|
||||
$data[ $key[2] ][ $elm_class ][ $key[0] ] = array();
|
||||
}
|
||||
$data[ $key[2] ][ $elm_class ][ $key[0] ][ $key[1] ] = $value;
|
||||
}
|
||||
}
|
||||
$css = '';
|
||||
foreach ( $sizes as $state => $mquery ) {
|
||||
if ( ! isset( $data[ $state ] ) ) {
|
||||
continue;
|
||||
}
|
||||
$css .= $mquery . " {";
|
||||
foreach ( $data[ $state ] as $elm_class => $props ) {
|
||||
$css .= '.' . $elm_class . '{';
|
||||
foreach ( $props as $prop => $values ) {
|
||||
// Add solid border if its values not empty
|
||||
if ( $prop === 'border' AND ! empty( $values ) ) {
|
||||
$css .= 'border-style: solid; border-width: 0;';
|
||||
}
|
||||
if ( count( $values ) == 4 AND count( array_unique( $values ) ) == 1 ) {
|
||||
// All the directions have the same value, so grouping them together
|
||||
$values = array_values( $values );
|
||||
if ( $prop === 'border' ) {
|
||||
$css .= $prop . '-width:' . $values[0] . ';';
|
||||
} else {
|
||||
$css .= $prop . ':' . $values[0] . '!important;';
|
||||
}
|
||||
} else {
|
||||
foreach ( $values as $dir => $val ) {
|
||||
if ( $prop === 'border' ) {
|
||||
$css .= $prop . '-' . $dir . '-width:' . $val . ';';
|
||||
} else {
|
||||
$css .= $prop . '-' . $dir . ':' . $val . '!important;';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$css .= "}";
|
||||
}
|
||||
$css .= "}";
|
||||
}
|
||||
|
||||
return $css;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add link to Theme Options to Admin Bar
|
||||
*
|
||||
* @param $wp_admin_bar
|
||||
*/
|
||||
function us_admin_bar_theme_options_link( $wp_admin_bar ) {
|
||||
$wp_admin_bar->add_node(
|
||||
array(
|
||||
'id' => 'us_theme_otions',
|
||||
'title' => __( 'Theme Options', 'us' ),
|
||||
'href' => admin_url( 'admin.php?page=us-theme-options' ),
|
||||
'parent' => 'site-name',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! is_admin() AND function_exists( 'current_user_can' ) AND current_user_can( 'administrator' ) ) {
|
||||
add_action( 'admin_bar_menu', 'us_admin_bar_theme_options_link', 99 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "no-touch" class to html on desktops
|
||||
*/
|
||||
add_action( 'wp_head', 'us_output_no_touch_script' );
|
||||
function us_output_no_touch_script() {
|
||||
?>
|
||||
<script>
|
||||
if (!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
|
||||
var root = document.getElementsByTagName('html')[0]
|
||||
root.className += " no-touch";
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,196 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
class US_Layout {
|
||||
|
||||
/**
|
||||
* @var US_Layout
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* Singleton pattern: US_Layout::instance()->do_something()
|
||||
*
|
||||
* @return US_Layout
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self;
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var string Canvas type: wide / boxed
|
||||
*/
|
||||
public $canvas_type;
|
||||
|
||||
/**
|
||||
* @var string Default-state header orientation: 'hor' / 'ver'
|
||||
*/
|
||||
public $header_orientation;
|
||||
|
||||
/**
|
||||
* @var string Default-state header position: 'static' / 'fixed'
|
||||
*/
|
||||
public $header_pos;
|
||||
|
||||
/**
|
||||
* @var string Default-state header background: 'solid' / 'transparent'
|
||||
*/
|
||||
public $header_bg;
|
||||
|
||||
/**
|
||||
* @var string Default-state header show: 'always' / 'never'
|
||||
*/
|
||||
public $header_show;
|
||||
|
||||
protected function __construct() {
|
||||
|
||||
do_action( 'us_layout_before_init', $this );
|
||||
|
||||
if ( WP_DEBUG AND ! ( isset( $GLOBALS['post'] ) OR is_404() OR is_search() OR is_archive() OR ( is_home() AND ! have_posts() ) ) ) {
|
||||
wp_die( 'US_Layout can be inited only after the current post is obtained' );
|
||||
}
|
||||
|
||||
$this->canvas_type = us_get_option( 'canvas_layout', 'wide' );
|
||||
$this->header_orientation = us_get_header_option( 'orientation', 'default', 'hor' );
|
||||
$this->header_pos = us_get_header_option( 'sticky', 'default', FALSE ) ? 'fixed' : 'static';
|
||||
$this->header_initial_pos = 'top';
|
||||
$this->header_bg = us_get_header_option( 'transparent', 'default', FALSE ) ? 'transparent' : 'solid';
|
||||
$this->header_shadow = us_get_header_option( 'shadow', 'default', 'thin' );
|
||||
$this->header_show = 'always';
|
||||
|
||||
// Some of the options may be overloaded by post's meta settings
|
||||
$public_cpt = array_keys( us_get_public_cpt() );
|
||||
$postID = NULL;
|
||||
if ( is_singular() ) {
|
||||
$postID = get_the_ID();
|
||||
}
|
||||
if ( is_404() ) {
|
||||
$postID = us_get_option( 'page_404' );
|
||||
}
|
||||
if ( is_search() AND ! is_post_type_archive( 'product' ) ) {
|
||||
$postID = us_get_option( 'search_page' );
|
||||
}
|
||||
if ( is_home() ) {
|
||||
$postID = us_get_option( 'posts_page' );
|
||||
}
|
||||
if ( is_singular(
|
||||
array_merge(
|
||||
array(
|
||||
'post',
|
||||
'page',
|
||||
'us_portfolio',
|
||||
'product',
|
||||
), $public_cpt
|
||||
)
|
||||
) OR ( ( is_404() OR is_search() OR is_home() ) AND $postID != NULL AND $postID != 'default' ) ) {
|
||||
|
||||
if ( metadata_exists( 'post', $postID, 'us_header_id' ) AND usof_meta( 'us_header_id', array(), $postID ) == '' ) {
|
||||
$this->header_show = 'never';
|
||||
$this->header_orientation = 'none';
|
||||
} elseif ( usof_meta( 'us_header_sticky_pos', array(), $postID ) != '' AND $this->header_orientation == 'hor' ) {
|
||||
$this->header_initial_pos = usof_meta( 'us_header_sticky_pos', array(), $postID );
|
||||
}
|
||||
}
|
||||
|
||||
// Remove header for popup iframes (available in Grid Overriding Link)
|
||||
global $us_iframe;
|
||||
if ( isset( $us_iframe ) AND $us_iframe ) {
|
||||
$this->header_show = 'never';
|
||||
$this->header_orientation = 'none';
|
||||
}
|
||||
|
||||
$this->post_id = $postID;
|
||||
|
||||
if ( $this->header_orientation == 'ver' ) {
|
||||
$this->header_pos = 'fixed';
|
||||
$this->header_bg = 'solid';
|
||||
}
|
||||
|
||||
do_action( 'us_layout_after_init', $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain theme-defined CSS classes for <html> element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html_classes() {
|
||||
$classes = '';
|
||||
|
||||
if ( ! us_get_option( 'responsive_layout', TRUE ) ) {
|
||||
$classes .= 'no-responsive';
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain theme-defined CSS classes for <body> element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function body_classes() {
|
||||
$classes = US_THEMENAME . '_' . US_THEMEVERSION;
|
||||
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
||||
if ( is_plugin_active( 'us-header-builder/us-header-builder.php' ) ) {
|
||||
$classes .= ' HB';
|
||||
if ( defined( 'US_HB_VERSION' ) ) {
|
||||
$classes .= '_' . US_HB_VERSION;
|
||||
} else {
|
||||
$hb_data = @get_plugin_data( ABSPATH . 'wp-content/plugins/us-header-builder/us-header-builder.php' );
|
||||
$classes .= '_' . $hb_data['Version'];
|
||||
}
|
||||
}
|
||||
$classes .= ' header_' . $this->header_orientation;
|
||||
$classes .= ' headerinpos_' . $this->header_initial_pos;
|
||||
if ( us_get_option( 'links_underline' ) == TRUE ) {
|
||||
$classes .= ' links_underline';
|
||||
}
|
||||
if ( us_get_option( 'rounded_corners' ) !== NULL AND us_get_option( 'rounded_corners' ) == FALSE ) {
|
||||
$classes .= ' rounded_none';
|
||||
}
|
||||
$classes .= ' state_default';
|
||||
|
||||
global $us_iframe;
|
||||
if ( isset( $us_iframe ) AND $us_iframe ) {
|
||||
$classes .= ' us_iframe';
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain CSS classes for .l-canvas
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function canvas_classes() {
|
||||
|
||||
$classes = 'type_' . $this->canvas_type;
|
||||
|
||||
// Language modificator
|
||||
if ( defined( 'ICL_LANGUAGE_CODE' ) AND ICL_LANGUAGE_CODE ) {
|
||||
$classes .= ' wpml_lang_' . ICL_LANGUAGE_CODE;
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain CSS classes for .l-header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function header_classes() {
|
||||
|
||||
$classes = 'pos_' . $this->header_pos;
|
||||
$classes .= ' bg_' . $this->header_bg;
|
||||
$classes .= ' shadow_' . $this->header_shadow;
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
|
||||
// Add categories checkboxes to Image dialog
|
||||
add_filter( 'attachment_fields_to_edit', 'us_attachment_fields_to_edit_categories', 10, 2 );
|
||||
function us_attachment_fields_to_edit_categories( $form_fields, $post ) {
|
||||
|
||||
foreach ( get_attachment_taxonomies( $post->ID ) as $taxonomy ) {
|
||||
|
||||
$t = (array) get_taxonomy( $taxonomy );
|
||||
if ( ! $t['public'] OR ! $t['show_ui'] ) {
|
||||
continue;
|
||||
}
|
||||
if ( empty( $t['label'] ) ) {
|
||||
$t['label'] = $taxonomy;
|
||||
}
|
||||
if ( empty( $t['args'] ) ) {
|
||||
$t['args'] = array();
|
||||
}
|
||||
|
||||
$terms = get_object_term_cache( $post->ID, $taxonomy );
|
||||
if ( FALSE === $terms ) {
|
||||
$terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] );
|
||||
}
|
||||
|
||||
// Get the values in a list
|
||||
$values = array();
|
||||
foreach ( $terms as $term ) {
|
||||
$values[] = $term->slug;
|
||||
}
|
||||
$t['value'] = join( ', ', $values );
|
||||
|
||||
$t['show_in_edit'] = FALSE;
|
||||
|
||||
if ( $t['hierarchical'] OR $taxonomy == 'us_media_category' ) {
|
||||
ob_start();
|
||||
|
||||
wp_terms_checklist(
|
||||
$post->ID, array(
|
||||
'taxonomy' => $taxonomy,
|
||||
'checked_ontop' => FALSE,
|
||||
'walker' => new US_Walker_Media_Categories_Checklist(),
|
||||
)
|
||||
);
|
||||
|
||||
if ( ob_get_contents() != FALSE ) {
|
||||
$html = '<ul class="us-media-list">' . ob_get_contents() . '</ul>';
|
||||
} else {
|
||||
$html = '<div class="us-media-none">' . us_translate( 'No categories found.' ) . ' <a href="' . admin_url( '/edit-tags.php?taxonomy=us_media_category&post_type=attachment' ) . '">' . us_translate( 'Add new category' ) . '</a></div>';
|
||||
}
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
$t['input'] = 'html';
|
||||
$t['html'] = $html;
|
||||
}
|
||||
|
||||
$form_fields[ $taxonomy ] = $t;
|
||||
}
|
||||
|
||||
return $form_fields;
|
||||
}
|
||||
|
||||
class US_Walker_Media_Categories_Checklist extends Walker {
|
||||
var $tree_type = 'category';
|
||||
var $db_fields = array(
|
||||
'parent' => 'parent',
|
||||
'id' => 'term_id',
|
||||
);
|
||||
|
||||
public function start_lvl( &$output, $depth = 0, $args = array() ) {
|
||||
$indent = str_repeat( "\t", $depth );
|
||||
$output .= "$indent<ul class='children'>\n";
|
||||
}
|
||||
|
||||
public function end_lvl( &$output, $depth = 0, $args = array() ) {
|
||||
$indent = str_repeat( "\t", $depth );
|
||||
$output .= "$indent</ul>\n";
|
||||
}
|
||||
|
||||
public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
||||
|
||||
// Get taxonomy
|
||||
$taxonomy = empty( $args['taxonomy'] ) ? 'us_media_category' : $args['taxonomy'];
|
||||
|
||||
$name = 'tax_input[' . $taxonomy . ']';
|
||||
|
||||
$output .= "\n<li id='{$taxonomy}-{$category->term_id}'>";
|
||||
$output .= '<label class="selectit">';
|
||||
$output .= '<input value="' . $category->slug . '" ';
|
||||
$output .= 'type="checkbox" ';
|
||||
$output .= 'name="' . $name . '[' . $category->slug . ']" ';
|
||||
$output .= 'id="in-' . $taxonomy . '-' . $category->term_id . '"';
|
||||
$output .= checked( in_array( $category->term_id, $args['selected_cats'] ), TRUE, FALSE );
|
||||
$output .= disabled( empty( $args['disabled'] ), FALSE, FALSE );
|
||||
$output .= ' /> ';
|
||||
$output .= esc_html( apply_filters( 'the_category', $category->name ) );
|
||||
$output .= '</label>';
|
||||
}
|
||||
|
||||
public function end_el( &$output, $category, $depth = 0, $args = array() ) {
|
||||
$output .= "</li>\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Save categories from attachment edit menu
|
||||
add_action( 'wp_ajax_save-attachment-compat', 'us_save_attachment_compat', 0 );
|
||||
function us_save_attachment_compat() {
|
||||
if ( ! isset( $_REQUEST['id'] ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
if ( ! $id = absint( $_REQUEST['id'] ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
if ( empty( $_REQUEST['attachments'] ) OR empty( $_REQUEST['attachments'][ $id ] ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
$attachment_data = $_REQUEST['attachments'][ $id ];
|
||||
|
||||
check_ajax_referer( 'update-post_' . $id, 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'edit_post', $id ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$post = get_post( $id, ARRAY_A );
|
||||
|
||||
if ( 'attachment' != $post['post_type'] ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
// This filter is documented in wp-admin/includes/media.php
|
||||
$post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data );
|
||||
|
||||
if ( isset( $post['errors'] ) ) {
|
||||
$errors = $post['errors'];
|
||||
unset( $post['errors'] );
|
||||
}
|
||||
|
||||
wp_update_post( $post );
|
||||
|
||||
foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
|
||||
if ( isset( $attachment_data[ $taxonomy ] ) ) {
|
||||
wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $attachment_data[ $taxonomy ] ) ), $taxonomy, FALSE );
|
||||
} elseif ( isset( $_REQUEST['tax_input'] ) AND isset( $_REQUEST['tax_input'][ $taxonomy ] ) ) {
|
||||
wp_set_object_terms( $id, $_REQUEST['tax_input'][ $taxonomy ], $taxonomy, FALSE );
|
||||
} else {
|
||||
wp_set_object_terms( $id, '', $taxonomy, FALSE );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
wp_send_json_success( $attachment );
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_query-attachments', 'us_ajax_media_categories_query_attachments', 0 );
|
||||
function us_ajax_media_categories_query_attachments() {
|
||||
|
||||
// Bail if user cannot upload files
|
||||
if ( ! current_user_can( 'upload_files' ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
// Get names of media taxonomies
|
||||
$taxonomies = get_object_taxonomies( 'attachment', 'names' );
|
||||
|
||||
// Look for query
|
||||
$query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
|
||||
|
||||
// Default arguments
|
||||
$defaults = array(
|
||||
's',
|
||||
'order',
|
||||
'orderby',
|
||||
'posts_per_page',
|
||||
'paged',
|
||||
'post_mime_type',
|
||||
'post_parent',
|
||||
'post__in',
|
||||
'post__not_in',
|
||||
);
|
||||
|
||||
$query = array_intersect_key( $query, array_flip( array_merge( $defaults, $taxonomies ) ) );
|
||||
|
||||
$query['post_type'] = 'attachment';
|
||||
$query['post_status'] = 'inherit';
|
||||
if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) ) {
|
||||
$query['post_status'] .= ',private';
|
||||
}
|
||||
|
||||
$query['tax_query'] = array( 'relation' => 'AND' );
|
||||
|
||||
foreach ( $taxonomies as $taxonomy ) {
|
||||
if ( isset( $query[ $taxonomy ] ) ) {
|
||||
|
||||
// Filter a specific category
|
||||
if ( is_numeric( $query[ $taxonomy ] ) ) {
|
||||
array_push(
|
||||
$query['tax_query'], array(
|
||||
'taxonomy' => $taxonomy,
|
||||
'field' => 'id',
|
||||
'terms' => $query[ $taxonomy ],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Filter No category
|
||||
if ( $query[ $taxonomy ] == 'no_category' ) {
|
||||
$all_terms_ids = us_media_categories_get_terms_values( 'ids' );
|
||||
array_push(
|
||||
$query['tax_query'], array(
|
||||
'taxonomy' => $taxonomy,
|
||||
'field' => 'id',
|
||||
'terms' => $all_terms_ids,
|
||||
'operator' => 'NOT IN',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
unset( $query[ $taxonomy ] );
|
||||
}
|
||||
|
||||
$query = apply_filters( 'ajax_query_attachments_args', $query );
|
||||
$query = new WP_Query( $query );
|
||||
|
||||
$posts = array_map( 'wp_prepare_attachment_for_js', $query->posts );
|
||||
$posts = array_filter( $posts );
|
||||
|
||||
wp_send_json_success( $posts );
|
||||
}
|
||||
|
||||
// Get media categories
|
||||
function us_media_categories_get_terms_values( $keys = 'ids' ) {
|
||||
|
||||
$media_terms = get_terms(
|
||||
'us_media_category', array(
|
||||
'hide_empty' => 0,
|
||||
'fields' => 'id=>slug',
|
||||
)
|
||||
);
|
||||
|
||||
$media_values = array();
|
||||
foreach ( $media_terms as $key => $value ) {
|
||||
$media_values[] = ( $keys === 'ids' ) ? $key : $value;
|
||||
}
|
||||
|
||||
return $media_values;
|
||||
}
|
||||
|
||||
// update_count_callback
|
||||
function us_media_category_update_count_callback( $terms = array(), $media_taxonomy = 'us_media_category' ) {
|
||||
global $wpdb;
|
||||
|
||||
// select id & count from taxonomy
|
||||
$sql = "SELECT term_taxonomy_id, MAX(total) AS total FROM ((
|
||||
SELECT tt.term_taxonomy_id, COUNT(*) AS total
|
||||
FROM {$wpdb->term_relationships} tr, {$wpdb->term_taxonomy} tt
|
||||
WHERE tr.term_taxonomy_id = tt.term_taxonomy_id
|
||||
AND tt.taxonomy = %s
|
||||
GROUP BY tt.term_taxonomy_id
|
||||
) UNION ALL (
|
||||
SELECT term_taxonomy_id, 0 AS total
|
||||
FROM {$wpdb->term_taxonomy}
|
||||
WHERE taxonomy = %s
|
||||
)) AS unioncount GROUP BY term_taxonomy_id";
|
||||
|
||||
$prepared = $wpdb->prepare( $sql, $media_taxonomy->name, $media_taxonomy->name );
|
||||
$count = $wpdb->get_results( $prepared );
|
||||
|
||||
// update all count values from taxonomy
|
||||
foreach ( $count as $row_count ) {
|
||||
$wpdb->update(
|
||||
$wpdb->term_taxonomy, array( 'count' => $row_count->total ), array( 'term_taxonomy_id' => $row_count->term_taxonomy_id )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Media category filter
|
||||
add_action( 'admin_enqueue_scripts', 'us_media_categories_enqueue_admin_scripts' );
|
||||
function us_media_categories_enqueue_admin_scripts() {
|
||||
global $pagenow;
|
||||
global $us_template_directory_uri;
|
||||
|
||||
$pages_to_add = array( 'upload.php', 'post.php', 'post-new.php' );
|
||||
|
||||
if ( wp_script_is( 'media-editor' ) AND in_array( $pagenow, $pages_to_add ) ) {
|
||||
// Dropdown
|
||||
$attachment_terms = wp_dropdown_categories(
|
||||
array(
|
||||
'taxonomy' => 'us_media_category',
|
||||
'hide_empty' => FALSE,
|
||||
'hierarchical' => TRUE,
|
||||
'orderby' => 'name',
|
||||
'show_count' => TRUE,
|
||||
'walker' => new US_Walker_Media_Categories_Media_Grid(),
|
||||
'value' => 'id',
|
||||
'echo' => FALSE,
|
||||
)
|
||||
);
|
||||
// No select
|
||||
$attachment_terms = preg_replace( array( '/<select([^>]*)>/', '/<\/select>/' ), '', $attachment_terms );
|
||||
|
||||
// Add an attachment_terms for No category
|
||||
$no_category_term = ' ,{"term_id":"' . 'no_category' . '","term_name":"' . __( 'Without categories', 'us' ) . '"}';
|
||||
$attachment_terms = $no_category_term . substr( $attachment_terms, 1 );
|
||||
|
||||
echo '<script type="text/javascript">';
|
||||
echo '/* <![CDATA[ */';
|
||||
echo 'var us_media_categories_taxonomies = {"' . 'us_media_category' . '":';
|
||||
echo '{"list_title":"– ' . html_entity_decode( __( 'Filter by Categories', 'us' ), ENT_QUOTES, 'UTF-8' ) . ' –",';
|
||||
echo '"term_list":[' . substr( $attachment_terms, 2 ) . ']}};';
|
||||
echo '/* ]]> */';
|
||||
echo '</script>';
|
||||
|
||||
// Script
|
||||
wp_enqueue_script( 'us-media-categories-media-views', $us_template_directory_uri . '/framework/admin/js/media-views.js', array( 'media-views' ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Custom walker for wp_dropdown_categories for media grid view filter
|
||||
class US_Walker_Media_Categories_Media_Grid extends Walker_CategoryDropdown {
|
||||
|
||||
public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
||||
$pad = str_repeat( ' ', $depth * 3 );
|
||||
$cat_name = apply_filters( 'list_cats', $category->name, $category );
|
||||
|
||||
$output .= ',{"term_id":"' . $category->term_id . '","term_name":"' . $pad . esc_attr( $cat_name );
|
||||
if ( $args['show_count'] ) {
|
||||
$output .= ' (' . $category->count . ')';
|
||||
}
|
||||
$output .= '"}';
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_us_ajax_set_category_on_upload', 'us_ajax_media_categories_set_attachment_category' );
|
||||
function us_ajax_media_categories_set_attachment_category() {
|
||||
|
||||
$post_ID = intval( $_POST['post_id'] );
|
||||
$category = $_POST['category'];
|
||||
|
||||
// Check whether this user can edit this post
|
||||
if ( ! current_user_can( 'edit_post', $post_ID ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $category != 'all' OR $category != 'no_category' ) {
|
||||
$category = intval( $category );
|
||||
wp_set_object_terms( $post_ID, $category, 'us_media_category', TRUE );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
class US_Walker_Nav_Menu extends Walker_Nav_Menu {
|
||||
|
||||
public function start_lvl( &$output, $depth = 0, $args = array() ) {
|
||||
// depth dependent classes
|
||||
$level = ( $depth + 2 ); // because it counts the first submenu as 0
|
||||
|
||||
// build html
|
||||
$output .= '<ul class="w-nav-list level_' . $level . '">';
|
||||
}
|
||||
|
||||
public function end_lvl( &$output, $depth = 0, $args = array() ) {
|
||||
$output .= "</ul>";
|
||||
}
|
||||
|
||||
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
|
||||
$level = ( $depth + 1 ); // because it counts the first submenu as 0
|
||||
|
||||
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
|
||||
$classes[] = 'w-nav-item';
|
||||
$classes[] = 'level_' . $level;
|
||||
$classes[] = 'menu-item-' . $item->ID;
|
||||
|
||||
if ( ! empty( $item->mega_menu_cols ) ) {
|
||||
$classes[] = 'columns_' . $item->mega_menu_cols;
|
||||
}
|
||||
|
||||
// Removing active classes for scroll links, so they could be handled by JavaScript instead
|
||||
if ( isset( $item->url ) AND strpos( $item->url, '#' ) !== FALSE ) {
|
||||
$classes = array_diff(
|
||||
$classes, array(
|
||||
'current-menu-item',
|
||||
'current-menu-ancestor',
|
||||
'current-menu-parent',
|
||||
)
|
||||
);
|
||||
}
|
||||
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
|
||||
$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 .= '<li' . $id . $class_names .'>';
|
||||
if ( $item->object == 'us_widget_area' ) {
|
||||
$item_post = get_post( $item->object_id );
|
||||
if ( $item_post AND is_active_sidebar( $item_post->post_name ) ) {
|
||||
ob_start();
|
||||
dynamic_sidebar( $item_post->post_name );
|
||||
$output .= ob_get_clean();
|
||||
}
|
||||
|
||||
} else {
|
||||
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) . '"' : '';
|
||||
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) . '"' : '';
|
||||
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . '"' : '';
|
||||
$attributes .= ! empty( $item->url ) ? ' href="' . esc_url( $item->url ) . '"' : '';
|
||||
|
||||
$item_output = $args->before;
|
||||
$item_output .= '<a class="w-nav-anchor level_' . $level . '" ' . $attributes . '>';
|
||||
$item_output .= $args->link_before . '<span class="w-nav-title">' . apply_filters( 'the_title', $item->title, $item->ID ) . '</span><span class="w-nav-arrow"></span>' . $args->link_after;
|
||||
$item_output .= '</a>';
|
||||
$item_output .= $args->after;
|
||||
|
||||
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function end_el( &$output, $item, $depth = 0, $args = array() ) {
|
||||
$output .= "</li>";
|
||||
}
|
||||
}
|
||||
|
||||
class US_Walker_Simplenav_Menu extends Walker_Nav_Menu {
|
||||
|
||||
public function start_lvl( &$output, $depth = 0, $args = array() ) {
|
||||
$output .= '<div class="w-nav-list">';
|
||||
}
|
||||
|
||||
public function end_lvl( &$output, $depth = 0, $args = array() ) {
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
|
||||
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) . '"' : '';
|
||||
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) . '"' : '';
|
||||
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . '"' : '';
|
||||
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) . '"' : '';
|
||||
$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args );
|
||||
if ( ! empty( $id ) ) {
|
||||
$attributes .= ' id="' . esc_attr( $id ) . '"';
|
||||
}
|
||||
|
||||
$item_output = $args->before;
|
||||
|
||||
$classes_array = empty( $item->classes ) ? array() : (array) $item->classes;
|
||||
$classes = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes_array ), $item, $args ) );
|
||||
|
||||
$item_output .= '<a class="w-menu-item ' . $classes . '" ' . $attributes . '><span>';
|
||||
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
|
||||
$item_output .= '</span></a>';
|
||||
$item_output .= $args->after;
|
||||
|
||||
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
|
||||
}
|
||||
|
||||
public function end_el( &$output, $item, $depth = 0, $args = array() ) {
|
||||
}
|
||||
}
|
||||
|
||||
add_filter( 'wp_nav_menu_objects', 'us_mega_menu_wp_nav_menu_objects' );
|
||||
function us_mega_menu_wp_nav_menu_objects( $sorted_menu_items ) {
|
||||
foreach ( $sorted_menu_items as $index => $item ) {
|
||||
// IF it is a first level item or if it is a fake last item
|
||||
if ( $item->menu_item_parent == 0 ) {
|
||||
$mega_menu_settings = get_post_meta( $item->ID, 'us_mega_menu_settings', TRUE );
|
||||
|
||||
if ( is_array( $mega_menu_settings ) ) {
|
||||
if ( ! empty( $mega_menu_settings['columns'] ) AND intval( $mega_menu_settings['columns'] ) > 1 ) {
|
||||
$item->mega_menu_cols = intval( $mega_menu_settings['columns'] );
|
||||
}
|
||||
}
|
||||
|
||||
$sorted_menu_items[$index] = $item;
|
||||
}
|
||||
}
|
||||
return $sorted_menu_items;
|
||||
}
|
||||
|
||||
// Add fallback menu location, which can be used in some plugins
|
||||
add_action( 'init', 'register_us_menu' );
|
||||
function register_us_menu() {
|
||||
register_nav_menus(
|
||||
array(
|
||||
'us_main_menu' => __( 'Custom Menu', 'us' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
add_action( 'wp_head', 'us_output_meta_tags', 5 );
|
||||
function us_output_meta_tags() {
|
||||
// Some of the tags might be defined previously
|
||||
global $us_meta_tags;
|
||||
$us_meta_tags = apply_filters( 'us_meta_tags', isset( $us_meta_tags ) ? $us_meta_tags : array() );
|
||||
|
||||
// Some must-have general tags
|
||||
if ( ! isset( $us_meta_tags['viewport'] ) ) {
|
||||
$us_meta_tags['viewport'] = 'width=device-width';
|
||||
if ( us_get_option( 'responsive_layout' ) ) {
|
||||
$us_meta_tags['viewport'] .= ', initial-scale=1';
|
||||
}
|
||||
$us_meta_tags['viewport'] = apply_filters( 'us_meta_viewport', $us_meta_tags['viewport'] );
|
||||
}
|
||||
if ( ! isset( $us_meta_tags['SKYPE_TOOLBAR'] ) ) {
|
||||
$us_meta_tags['SKYPE_TOOLBAR'] = 'SKYPE_TOOLBAR_PARSER_COMPATIBLE';
|
||||
}
|
||||
// Coloring address bar in Chrome for Android
|
||||
if ( ! isset( $us_meta_tags['theme-color'] ) AND us_get_option( 'color_chrome_toolbar' ) != '' ) {
|
||||
$us_meta_tags['theme-color'] = us_get_color( 'color_chrome_toolbar' );
|
||||
}
|
||||
|
||||
// Open Graph meta tags when needed
|
||||
if ( us_get_option( 'og_enabled' ) AND is_singular() AND isset( $GLOBALS['post'] ) ) {
|
||||
if ( ! isset( $us_meta_tags['og:title'] ) ) {
|
||||
$us_meta_tags['og:title'] = get_the_title();
|
||||
}
|
||||
if ( ! isset( $us_meta_tags['og:type'] ) ) {
|
||||
$us_meta_tags['og:type'] = 'website';
|
||||
}
|
||||
if ( ! isset( $us_meta_tags['og:url'] ) ) {
|
||||
$us_meta_tags['og:url'] = site_url( $_SERVER['REQUEST_URI'] );
|
||||
}
|
||||
if ( ! isset( $us_meta_tags['og:image'] ) ) {
|
||||
if ( $the_post_thumbnail_id = get_post_thumbnail_id() AND $the_post_thumbnail_src = wp_get_attachment_image_src( $the_post_thumbnail_id, 'large' ) ) {
|
||||
$us_meta_tags['og:image'] = $the_post_thumbnail_src[0];
|
||||
} elseif ( $meta_image = get_post_meta( get_the_ID(), 'us_og_image' ) AND ! empty( $meta_image[0] ) ) {
|
||||
$us_meta_tags['og:image'] = $meta_image[0];
|
||||
}
|
||||
}
|
||||
if ( ! isset( $us_meta_tags['og:description'] ) AND has_excerpt() AND ( $the_excerpt = strip_tags( get_the_excerpt() ) ) ) {
|
||||
$us_meta_tags['og:description'] = $the_excerpt;
|
||||
}
|
||||
}
|
||||
|
||||
// Outputting the tags
|
||||
if ( isset( $us_meta_tags ) AND is_array( $us_meta_tags ) ) {
|
||||
foreach ( $us_meta_tags as $meta_name => $meta_content ) {
|
||||
if ( substr( $meta_name, 0 ,3 ) == 'og:' ) {
|
||||
echo '<meta property="' . esc_attr( $meta_name ) . '" content="' . esc_attr( $meta_content ) . '">';
|
||||
} else {
|
||||
echo '<meta name="' . esc_attr( $meta_name ) . '" content="' . esc_attr( $meta_content ) . '">';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'save_post', 'us_save_post_add_og_image' );
|
||||
function us_save_post_add_og_image( $post_id ) {
|
||||
// If the post has thumbnail - clear og_image meta data, in other case try to find an image inside post content
|
||||
if ( $the_post_thumbnail_id = get_post_thumbnail_id( $post_id ) AND $the_post_thumbnail_src = wp_get_attachment_image_src( $the_post_thumbnail_id, 'large' ) ) {
|
||||
update_post_meta( $post_id, 'us_og_image', '' );
|
||||
} else {
|
||||
$post = get_post( $post_id );
|
||||
$the_content = $post->post_content;
|
||||
$the_content = apply_filters( 'us_page_block_the_content', $the_content );
|
||||
if ( preg_match('/<img [^>]*src=["|\']([^"|\']+)/i', $the_content, $matches) ) {
|
||||
update_post_meta( $post_id, 'us_og_image', $matches[1] );
|
||||
} else {
|
||||
update_post_meta( $post_id, 'us_og_image', '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,888 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
class US_Migration {
|
||||
|
||||
/**
|
||||
* @var US_Migration
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
protected $migration_needed_message = '';
|
||||
protected $migration_completed_message = '';
|
||||
|
||||
/**
|
||||
* Singleton pattern: US_Migration::instance()->do_something()
|
||||
*
|
||||
* @return US_Migration
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new US_Migration;
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var array List of migration classes instances $version => $instance
|
||||
*/
|
||||
public $translators = array();
|
||||
public $current_translator;
|
||||
|
||||
protected function __construct() {
|
||||
|
||||
global $us_template_directory;
|
||||
|
||||
// Get the current DB version
|
||||
$db_version = $this->get_db_version();
|
||||
|
||||
// Get available migrations (should be set by the theme's us_config_migrations filter) and keep only the needed ones
|
||||
$migrations = array();
|
||||
foreach ( us_config( 'migrations', array() ) as $migration_version => $migration_file ) {
|
||||
if ( version_compare( $db_version, $migration_version, '<' ) ) {
|
||||
$class = basename( $migration_file, '.php' );
|
||||
if ( file_exists( trailingslashit( $us_template_directory ) . $migration_file ) ) {
|
||||
include trailingslashit( $us_template_directory ) . $migration_file;
|
||||
} elseif ( WP_DEBUG ) {
|
||||
wp_die( 'Defined migration file not found: ' . trailingslashit( $us_template_directory ) . $migration_file );
|
||||
}
|
||||
if ( class_exists( $class ) ) {
|
||||
$this->translators[ $migration_version ] = new $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( empty( $this->translators ) ) {
|
||||
// Regenerate theme CSS file on update
|
||||
if ( $db_version != US_THEMEVERSION ) {
|
||||
us_generate_asset_files();
|
||||
}
|
||||
|
||||
// Set DB version if the theme was just installed
|
||||
$this->set_db_version();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( defined( 'DOING_AJAX' ) AND DOING_AJAX ) {
|
||||
// Providing fall-back compatibility for the previous website db versions
|
||||
$this->provide_fallback( $migrations );
|
||||
} else {
|
||||
if ( $this->should_be_manual() ) {
|
||||
if ( ! is_admin() ) {
|
||||
// Providing fall-back compatibility for the previous website db versions
|
||||
$this->provide_fallback( $migrations );
|
||||
} else {
|
||||
if ( isset( $_GET['us-migration'] ) AND wp_verify_nonce( $_GET['us-migration'], 'us-migration' ) ) {
|
||||
// Performing the migration
|
||||
add_action( 'admin_init', array( $this, 'perform_migration' ), 1 );
|
||||
add_action( 'admin_notices', array( $this, 'display_migration_completed' ), 1 );
|
||||
} else {
|
||||
// Notifying about the needed migrations
|
||||
add_action( 'admin_notices', array( $this, 'display_migration_needed' ), 1 );
|
||||
add_action( 'admin_footer', array( $this, 'output_migration_needed_js' ), 1 );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( ! is_admin() ) {
|
||||
// Performing the migration silently
|
||||
add_action( 'init', array( $this, 'perform_migration' ), 11 );
|
||||
} else {
|
||||
// Performing the migration silently
|
||||
add_action( 'admin_init', array( $this, 'perform_migration' ), 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current set of migrations should be manual
|
||||
*/
|
||||
protected function should_be_manual() {
|
||||
$should_be_manual = FALSE;
|
||||
$migration_needed_message = '';
|
||||
$migration_completed_message = '';
|
||||
foreach ( $this->translators as $version => $translator ) {
|
||||
if ( method_exists( $translator, 'migration_needed_message' ) ) {
|
||||
$migration_needed_message .= $translator->migration_needed_message();
|
||||
}
|
||||
if ( method_exists( $translator, 'migration_completed_message' ) ) {
|
||||
$migration_completed_message .= $translator->migration_completed_message();
|
||||
}
|
||||
$should_be_manual = ( $should_be_manual OR $translator->should_be_manual );
|
||||
}
|
||||
|
||||
$this->migration_needed_message = $migration_needed_message;
|
||||
$this->migration_completed_message = $migration_completed_message;
|
||||
|
||||
return $should_be_manual;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the theme's current database version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_db_version() {
|
||||
// Getting from global options, not from the theme mods, as it affects content and general options (not theme mods)
|
||||
$result = get_option( 'us_db_version' ) ? get_option( 'us_db_version' ) : US_THEMEVERSION;
|
||||
// removing 'betaX' suffix from version
|
||||
$result = preg_replace( '~beta\d~', '', $result );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current database version
|
||||
*
|
||||
* @param string $version If not set will be updated to the current theme's version
|
||||
*/
|
||||
public function set_db_version( $version = NULL ) {
|
||||
if ( $version === NULL ) {
|
||||
$version = US_THEMEVERSION;
|
||||
}
|
||||
|
||||
// removing 'betaX' suffix from version
|
||||
$version = preg_replace( '~beta\d~', '', $version );
|
||||
|
||||
$current_version = get_option( 'us_db_version' );
|
||||
if ( $current_version != $version ) {
|
||||
update_option( 'us_db_version', $version, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
public function provide_fallback( $migrations ) {
|
||||
global $us_migration_doing_fallback;
|
||||
$us_migration_doing_fallback = TRUE;
|
||||
// For both frontend and ajax requests
|
||||
add_action( 'init', array( $this, 'fallback_theme_options' ), 12 );
|
||||
add_filter( 'get_post_metadata', array( $this, 'fallback_meta' ), 10, 4 );
|
||||
if ( ! is_admin() ) {
|
||||
// For frontend requests only
|
||||
add_filter( 'theme_mod_nav_menu_locations', array( $this, 'fallback_menus' ), 5 );
|
||||
add_filter( 'the_content', array( $this, 'fallback_content' ), 5 );
|
||||
}
|
||||
if ( $this->has_widgets_translators() ) {
|
||||
add_action( 'init', array( $this, 'fallback_widgets' ), 12 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that is bound to 'theme_mod_nav_menu_locations' filter to provide live fallback compatibility for menus migrations
|
||||
*
|
||||
* @param string $locations
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function fallback_menus( $locations ) {
|
||||
foreach ( $this->translators as $version => $translator ) {
|
||||
if ( method_exists( $translator, 'translate_menus' ) ) {
|
||||
$translator->translate_menus( $locations );
|
||||
}
|
||||
}
|
||||
|
||||
return $locations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for providing live fallback compatibility for options migrations
|
||||
*/
|
||||
public function fallback_theme_options() {
|
||||
|
||||
global $usof_options;
|
||||
usof_load_options_once();
|
||||
|
||||
foreach ( $this->translators as $version => $translator ) {
|
||||
if ( method_exists( $translator, 'translate_theme_options' ) ) {
|
||||
$translator->translate_theme_options( $usof_options );
|
||||
}
|
||||
}
|
||||
|
||||
$usof_options = array_merge( usof_defaults(), $usof_options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for providing live fallback compatibility for metas migrations
|
||||
*
|
||||
* @param mixed $meta_val
|
||||
* @param string $key
|
||||
* @param array $args
|
||||
* @param int $post_id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function fallback_meta( $meta_val, $post_id, $key, $single ) {
|
||||
if ( ! get_the_ID() OR $post_id != get_the_ID() OR empty( $key ) ) {
|
||||
return $meta_val;
|
||||
}
|
||||
$meta = get_post_meta( $post_id );
|
||||
$post_type = get_post_type( $post_id );
|
||||
foreach ( $this->translators as $version => $translator ) {
|
||||
if ( method_exists( $translator, 'translate_meta' ) ) {
|
||||
$translator->translate_meta( $meta, $post_type );
|
||||
}
|
||||
}
|
||||
if ( isset( $meta[ $key ] ) ) {
|
||||
if ( $single ) {
|
||||
return $meta[ $key ][0];
|
||||
} else {
|
||||
return $meta[ $key ];
|
||||
}
|
||||
} else {
|
||||
return $meta_val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that is bound to 'the_content' filter to provide live fallback compatibility for content migrations
|
||||
*
|
||||
* @param $content
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function fallback_content( $content ) {
|
||||
global $post;
|
||||
$postID = ( isset( $post->ID ) ) ? $post->ID : NULL; // TODO check if we really use passed post ID
|
||||
foreach ( $this->translators as $version => $translator ) {
|
||||
if ( method_exists( $translator, 'translate_content' ) ) {
|
||||
$translator->translate_content( $content, $postID );
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function has_widgets_translators() {
|
||||
foreach ( $this->translators as $version => $translator ) {
|
||||
if ( method_exists( $translator, 'translate_widgets' ) ) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
public $sidebars_widgets = array();
|
||||
public $widgets_instances = array();
|
||||
|
||||
public function fallback_widgets() {
|
||||
$this->sidebars_widgets = array();
|
||||
$this->widgets_instances = array();
|
||||
$filters_added = array();
|
||||
foreach ( get_option( 'sidebars_widgets', array() ) as $sidebar => $widgets ) {
|
||||
if ( ! is_array( $widgets ) ) {
|
||||
// For non-widgets additional option data
|
||||
$this->sidebars_widgets[ $sidebar ] = $widgets;
|
||||
continue;
|
||||
}
|
||||
foreach ( $widgets as $index => $widget_binding ) {
|
||||
if ( ! preg_match( '@^(.+)\-(\d+)$@', $widget_binding, $matches ) ) {
|
||||
continue;
|
||||
}
|
||||
$widget_name = $original_widget_name = $matches[1];
|
||||
$instance_id = $matches[2];
|
||||
|
||||
$this->widgets_instances[ $widget_name ] = get_option( 'widget_' . $widget_name, array() );
|
||||
if ( ! isset( $this->widgets_instances[ $widget_name ][ $instance_id ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $this->translators as $version => $translator ) {
|
||||
if ( ! method_exists( $translator, 'translate_widgets' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $translator->translate_widgets( $widget_name, $this->widgets_instances[ $widget_name ][ $instance_id ] ) ) {
|
||||
if ( $widget_name != $original_widget_name ) {
|
||||
if ( ! isset( $this->widgets_instances[ $widget_name ] ) ) {
|
||||
// Widget name has changed
|
||||
$this->widgets_instances[ $widget_name ] = isset( $this->widgets_instances[ $original_widget_name ] ) ? $this->widgets_instances[ $original_widget_name ] : array();
|
||||
} else {
|
||||
$this->widgets_instances[ $widget_name ][ $instance_id ] = $this->widgets_instances[ $original_widget_name ][ $instance_id ];
|
||||
}
|
||||
}
|
||||
if ( ! in_array( $widget_name, $filters_added ) ) {
|
||||
// Binding each widget once
|
||||
add_filter(
|
||||
'pre_option_widget_' . $widget_name, array(
|
||||
$this,
|
||||
'fallback_widgets_instance',
|
||||
)
|
||||
);
|
||||
$filters_added[] = $widget_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$widgets[ $index ] = $widget_name . '-' . $instance_id;
|
||||
}
|
||||
$this->sidebars_widgets[ $sidebar ] = $widgets;
|
||||
}
|
||||
|
||||
if ( count( $filters_added ) > 0 ) {
|
||||
add_filter( 'option_sidebars_widgets', array( $this, 'fallback_sidebars_widgets' ) );
|
||||
}
|
||||
}
|
||||
|
||||
public function fallback_sidebars_widgets() {
|
||||
return $this->sidebars_widgets;
|
||||
}
|
||||
|
||||
public function fallback_widgets_instance() {
|
||||
if ( ! preg_match( '@^pre_option_widget_(.+)$@', current_filter(), $matches ) OR ! isset( $this->widgets_instances[ $matches[1] ] ) ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return $this->widgets_instances[ $matches[1] ];
|
||||
}
|
||||
|
||||
public function display_migration_needed() {
|
||||
if ( $this->migration_needed_message != '' ) {
|
||||
$output = $this->migration_needed_message;
|
||||
} else {
|
||||
$output = '<div class="us-migration">';
|
||||
$output .= '<h2>Your website content needs to be changed to be compatible with ' . US_THEMENAME . ' ' . US_THEMEVERSION . '</h2>';
|
||||
|
||||
// Prevent migration access when "Wordfence" or "iThemes Security" plugins are active
|
||||
if ( class_exists( 'wordfence' ) OR class_exists( 'ITSEC_Core' ) ) {
|
||||
$output .= '<p>To proceed updating ';
|
||||
if ( get_current_screen()->id != 'plugins' ) {
|
||||
$output .= 'go to <a href="' . admin_url( 'plugins.php' ) . '">plugins page</a> and ';
|
||||
}
|
||||
$output .= 'deactivate <strong>';
|
||||
$output .= ( class_exists( 'wordfence' ) ) ? 'Wordfence Security' : 'iThemes Security';
|
||||
$output .= '</strong> plugin.</p>';
|
||||
$output .= '<p><input type="submit" value="Update website content" class="button" disabled></p>';
|
||||
} else {
|
||||
$output .= '<p><label><input type="checkbox" name="allow_migration" id="allow_migration"> I made a full backup of my website</p>';
|
||||
$output .= '<p><input type="submit" value="Update website content" class="button" id="migration-start"></p>';
|
||||
}
|
||||
$output .= '</div>';
|
||||
$output .= '<style>
|
||||
.us-migration {
|
||||
padding: 20px 20px 10px;
|
||||
margin-left: -20px;
|
||||
background-color: #ffe14c;
|
||||
color: #000;
|
||||
}
|
||||
.us-migration h2 {
|
||||
margin: 0 0 10px;
|
||||
color: inherit;
|
||||
}
|
||||
.us-migration p {
|
||||
font-size: 15px;
|
||||
}
|
||||
.us-migration .button {
|
||||
font-size: 15px;
|
||||
height: auto;
|
||||
padding: 4px 20px;
|
||||
color: #111;
|
||||
}
|
||||
</style>';
|
||||
}
|
||||
echo $output;
|
||||
}
|
||||
|
||||
public function output_migration_needed_js() {
|
||||
|
||||
$output = '<script type="text/javascript">';
|
||||
$output .= 'jQuery(function($){
|
||||
$(".us-migration input.button").attr("disabled", "");
|
||||
$(".error.us-migration.for-hb").hide();
|
||||
$("#allow_migration").removeAttr("checked").on("click", function(){
|
||||
if ($(this).is(":checked")){
|
||||
$(".us-migration input.button").removeAttr("disabled");
|
||||
}else{
|
||||
$(".us-migration input.button").attr("disabled", "");
|
||||
}
|
||||
});
|
||||
$(".us-migration input.button").click(function(){
|
||||
if ( ! $(".us-migration input[type=\"checkbox\"]").is(":checked")) return;
|
||||
$(this).val("Updating...");
|
||||
$(".us-migration input.button").attr("disabled", "");
|
||||
var locationHref = window.location.href;console.log(locationHref);
|
||||
if ( locationHref.indexOf("?") >= 0 ) {
|
||||
locationHref = locationHref + "&us-migration=' . wp_create_nonce( 'us-migration' ) . '";
|
||||
} else {
|
||||
locationHref = locationHref + "?us-migration=' . wp_create_nonce( 'us-migration' ) . '";
|
||||
}
|
||||
location.assign(locationHref);
|
||||
});
|
||||
});';
|
||||
$output .= '</script>';
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
public function display_migration_completed() {
|
||||
if ( $this->migration_completed_message != '' ) {
|
||||
$output = $this->migration_completed_message;
|
||||
} else {
|
||||
$output = '<div class="us-migration">';
|
||||
$output .= '<h2>Update to ' . US_THEMENAME . ' ' . US_THEMEVERSION . ' is completed. Now check your website. If you notice some issues, <a href="https://help.us-themes.com/' . strtolower( US_THEMENAME ) . '/tickets/" target="_blank">go to the support</a>.</h2>';
|
||||
$output .= '</div>';
|
||||
$output .= '<style>
|
||||
.us-migration {
|
||||
padding: 15px 20px;
|
||||
margin-left: -20px;
|
||||
background-color: #a7ee86;
|
||||
color: #000;
|
||||
}
|
||||
.us-migration h2 {
|
||||
margin: 0;
|
||||
color: inherit;
|
||||
}
|
||||
</style>';
|
||||
}
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should be bound to admin_init action, so all the needed stuff is initalized
|
||||
*/
|
||||
public function perform_migration() {
|
||||
$transient = get_transient( 'us_migration_running' );
|
||||
if ( $transient ) {
|
||||
return FALSE;
|
||||
}
|
||||
set_transient( 'us_migration_running', TRUE, 15 * 60 );
|
||||
set_time_limit( 0 );
|
||||
foreach ( $this->translators as $version => $translator ) {
|
||||
$this->current_translator = $translator;
|
||||
$this->migrate_menus();
|
||||
$this->migrate_theme_options();
|
||||
$this->migrate_widgets();
|
||||
$this->migrate_content_and_meta();
|
||||
}
|
||||
|
||||
$this->set_db_version();
|
||||
|
||||
// Regenerate theme asset file after migration
|
||||
us_generate_asset_files();
|
||||
|
||||
delete_transient( 'us_migration_running' );
|
||||
}
|
||||
|
||||
public function migrate_menus() {
|
||||
$locations = get_theme_mod( 'nav_menu_locations' );
|
||||
|
||||
$menus_changed = FALSE;
|
||||
if ( method_exists( $this->current_translator, 'translate_menus' ) ) {
|
||||
$menus_changed = ( $this->current_translator->translate_menus( $locations ) OR $menus_changed );
|
||||
}
|
||||
|
||||
if ( $menus_changed ) {
|
||||
set_theme_mod( 'nav_menu_locations', $locations );
|
||||
}
|
||||
}
|
||||
|
||||
public function migrate_theme_options() {
|
||||
// Getting Options
|
||||
global $usof_options;
|
||||
$updated_options = $usof_options;
|
||||
|
||||
usof_load_options_once();
|
||||
|
||||
$options_changed = FALSE;
|
||||
if ( method_exists( $this->current_translator, 'translate_theme_options' ) ) {
|
||||
$options_changed = ( $this->current_translator->translate_theme_options( $updated_options ) OR $options_changed );
|
||||
}
|
||||
if ( $options_changed ) {
|
||||
// Filling the missed options with default values
|
||||
$updated_options = array_merge( usof_defaults(), $updated_options );
|
||||
// Saving the changed options
|
||||
usof_save_options( $updated_options );
|
||||
}
|
||||
}
|
||||
|
||||
public function migrate_widgets() {
|
||||
$sidebars_widgets = array();
|
||||
$widgets_instances = array();
|
||||
// Name of changed widgets
|
||||
$changed_widgets = array();
|
||||
foreach ( get_option( 'sidebars_widgets', array() ) as $sidebar => $widgets ) {
|
||||
if ( ! is_array( $widgets ) ) {
|
||||
// For non-widgets additional option data
|
||||
$sidebars_widgets[ $sidebar ] = $widgets;
|
||||
continue;
|
||||
}
|
||||
foreach ( $widgets as $index => $widget_binding ) {
|
||||
if ( ! preg_match( '@^(.+)\-(\d+)$@', $widget_binding, $matches ) ) {
|
||||
continue;
|
||||
}
|
||||
$widget_name = $original_widget_name = $matches[1];
|
||||
$instance_id = $matches[2];
|
||||
|
||||
if ( ! isset( $widgets_instances[ $widget_name ] ) ) {
|
||||
$widgets_instances[ $widget_name ] = get_option( 'widget_' . $widget_name, array() );
|
||||
}
|
||||
|
||||
if ( ! isset( $widgets_instances[ $widget_name ][ $instance_id ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! method_exists( $this->current_translator, 'translate_widgets' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$widget_instance = $widgets_instances[ $widget_name ][ $instance_id ];
|
||||
|
||||
if ( $this->current_translator->translate_widgets( $widget_name, $widget_instance ) ) {
|
||||
if ( $widget_name != $original_widget_name ) {
|
||||
if ( ! isset( $widgets_instances[ $widget_name ] ) ) {
|
||||
$widgets_instances[ $widget_name ] = get_option( 'widget_' . $widget_name, array() );
|
||||
}
|
||||
if ( in_array( $instance_id, array_keys( $widgets_instances[ $widget_name ] ) ) ) {
|
||||
$instance_id = max( array_keys( $widgets_instances[ $widget_name ] ) ) + 1;
|
||||
}
|
||||
delete_option( 'widget_' . $original_widget_name );
|
||||
}
|
||||
$widgets_instances[ $widget_name ][ $instance_id ] = $widget_instance;
|
||||
|
||||
if ( ! in_array( $widget_name, $changed_widgets ) ) {
|
||||
$changed_widgets[] = $widget_name;
|
||||
}
|
||||
}
|
||||
|
||||
$widgets[ $index ] = $widget_name . '-' . $instance_id;
|
||||
}
|
||||
$sidebars_widgets[ $sidebar ] = $widgets;
|
||||
}
|
||||
|
||||
if ( count( $changed_widgets ) > 0 ) {
|
||||
update_option( 'sidebars_widgets', $sidebars_widgets );
|
||||
foreach ( $changed_widgets as $widget_name ) {
|
||||
update_option( 'widget_' . $widget_name, $widgets_instances[ $widget_name ], TRUE );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function migrate_content_and_meta() {
|
||||
global $vc_manager, $us_migration_current_post_id;
|
||||
if ( class_exists( 'Vc_Manager' ) AND isset( $vc_manager ) ) {
|
||||
$vc = $vc_manager->vc();
|
||||
}
|
||||
|
||||
$predefined_posts_types = array( 'post', 'page', 'us_portfolio', 'us_page_block', 'us_testimonial', 'product', 'templatera' );
|
||||
$public_cpt = array_keys( us_get_public_cpt() );
|
||||
$posts_types = us_array_merge( $predefined_posts_types, $public_cpt );
|
||||
|
||||
// Iterating thru needed post types
|
||||
foreach ( $posts_types as $post_type ) {
|
||||
$args = array(
|
||||
'posts_per_page' => - 1,
|
||||
'post_type' => $post_type,
|
||||
'post_status' => 'any',
|
||||
'numberposts' => - 1,
|
||||
);
|
||||
|
||||
// Fetching posts and iterating them
|
||||
$posts = get_posts( $args );
|
||||
foreach ( $posts as $post ) {
|
||||
$us_migration_current_post_id = $post->ID;
|
||||
|
||||
// Translating shortcodes
|
||||
$content = $post->post_content;
|
||||
$content_changed = FALSE;
|
||||
if ( method_exists( $this->current_translator, 'translate_content' ) ) {
|
||||
$content_changed = ( $this->current_translator->translate_content( $content, $post->ID ) OR $content_changed );
|
||||
}
|
||||
if ( $content_changed ) {
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $post->ID,
|
||||
'post_content' => $content,
|
||||
)
|
||||
);
|
||||
if ( isset( $vc ) AND method_exists( $vc, 'buildShortcodesCustomCss' ) ) {
|
||||
$vc->buildShortcodesCustomCss( $post->ID );
|
||||
}
|
||||
}
|
||||
|
||||
// Translating Meta fields
|
||||
$meta_changed = FALSE;
|
||||
$original_meta = $meta = get_post_meta( $post->ID );
|
||||
if ( method_exists( $this->current_translator, 'translate_meta' ) ) {
|
||||
$meta_changed = ( $this->current_translator->translate_meta( $meta, $post_type ) OR $meta_changed );
|
||||
}
|
||||
if ( $meta_changed ) {
|
||||
$deleted_meta = array_diff_key( $original_meta, $meta );
|
||||
foreach ( $meta as $key => $value ) {
|
||||
if ( ! isset( $original_meta[ $key ] ) OR $original_meta[ $key ] !== $value ) {
|
||||
update_post_meta( $post->ID, $key, $value[0] );
|
||||
}
|
||||
}
|
||||
foreach ( $deleted_meta as $key => $value ) {
|
||||
delete_post_meta( $post->ID, $key );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class US_Migration_Translator {
|
||||
|
||||
/**
|
||||
* @var bool Possibly dangerous translation that needs to be migrated manually (don't use this too often)
|
||||
*/
|
||||
public $should_be_manual = FALSE;
|
||||
|
||||
/**
|
||||
* @var string Extra css that will be appended to the end of the body
|
||||
*/
|
||||
public $_extra_css = '';
|
||||
|
||||
public function __construct() {
|
||||
add_action( 'wp_footer', array( $this, 'append_css' ), 20 );
|
||||
}
|
||||
|
||||
public function append_css() {
|
||||
if ( ! empty( $this->_extra_css ) ) {
|
||||
echo '<style id="' . get_class( $this ) . '">' . $this->_extra_css . '</style>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param array $locations
|
||||
* @param array $rules
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _translate_menus( &$locations, $rules ) {
|
||||
$changed = FALSE;
|
||||
// Obtaining the valid menu ids
|
||||
$menu_ids = wp_get_nav_menus( array( 'fields' => 'ids' ) );
|
||||
foreach ( $rules as $old => $new ) {
|
||||
if ( isset( $locations[ $old ] ) AND in_array( $locations[ $old ], $menu_ids ) ) {
|
||||
$locations[ $new ] = $locations[ $old ];
|
||||
unset( $locations[ $old ] );
|
||||
$changed = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return $changed;
|
||||
}
|
||||
|
||||
protected function _translate_theme_options( &$options, $rules ) {
|
||||
$changed = FALSE;
|
||||
foreach ( $rules as $option => $rule ) {
|
||||
if ( isset( $options[ $option ] ) ) {
|
||||
if ( isset( $rule['values'] ) ) {
|
||||
foreach ( $rule['values'] as $old_value => $new_value ) {
|
||||
if ( $options[ $option ] == $old_value ) {
|
||||
$options[ $option ] = $new_value;
|
||||
$changed = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $rule['new_name'] ) ) {
|
||||
if ( ! is_array( $rule['new_name'] ) ) {
|
||||
$rule['new_name'] = array( $rule['new_name'] );
|
||||
}
|
||||
$option_value = $options[ $option ];
|
||||
unset( $options[ $option ] );
|
||||
foreach ( $rule['new_name'] as $new_name ) {
|
||||
if ( ! isset( $options[ $new_name ] ) ) {
|
||||
$options[ $new_name ] = $option_value;
|
||||
}
|
||||
}
|
||||
$changed = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $changed;
|
||||
}
|
||||
|
||||
protected function _translate_meta( &$meta, $post_type, $rules ) {
|
||||
$changed = FALSE;
|
||||
foreach ( $rules as $meta_name => $rule ) {
|
||||
if ( isset( $meta[ $meta_name ] ) AND in_array( $post_type, $rule['post_types'] ) ) {
|
||||
if ( isset( $rule['values'] ) ) {
|
||||
foreach ( $rule['values'] as $old_value => $new_value ) {
|
||||
if ( $meta[ $meta_name ][0] == $old_value ) {
|
||||
$changed = TRUE;
|
||||
$meta[ $meta_name ][0] = $new_value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $rule['new_name'] ) ) {
|
||||
if ( ! is_array( $rule['new_name'] ) ) {
|
||||
$rule['new_name'] = array( $rule['new_name'] );
|
||||
}
|
||||
$meta_value = $meta[ $meta_name ];
|
||||
//unset( $meta[$meta_name] );
|
||||
foreach ( $rule['new_name'] as $new_name ) {
|
||||
if ( ! isset( $meta[ $new_name ] ) ) {
|
||||
$changed = TRUE;
|
||||
$meta[ $new_name ] = $meta_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $changed;
|
||||
}
|
||||
|
||||
public function translate_params( &$params, $rules ) {
|
||||
$params_changed = FALSE;
|
||||
|
||||
foreach ( $rules as $param => $rule ) {
|
||||
if ( isset( $params[ $param ] ) ) {
|
||||
if ( isset( $rule['values'] ) ) {
|
||||
foreach ( $rule['values'] as $old_value => $new_value ) {
|
||||
if ( $params[ $param ] == $old_value ) {
|
||||
if ( $new_value === NULL ) {
|
||||
unset( $params[ $param ] );
|
||||
} else {
|
||||
$params[ $param ] = $new_value;
|
||||
}
|
||||
$params_changed = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $params[ $param ] ) AND isset( $rule['new_name'] ) ) {
|
||||
if ( $rule['new_name'] !== NULL ) {
|
||||
$params[ $rule['new_name'] ] = $params[ $param ];
|
||||
}
|
||||
unset( $params[ $param ] );
|
||||
$params_changed = TRUE;
|
||||
}
|
||||
} elseif ( isset( $rule['values'] ) AND isset( $rule['values'][ NULL ] ) ) {
|
||||
$params[ $param ] = $rule['values'][ NULL ];
|
||||
}
|
||||
}
|
||||
|
||||
return $params_changed;
|
||||
}
|
||||
|
||||
public function _translate_content( &$content ) {
|
||||
$content_changed = FALSE;
|
||||
|
||||
// Searching for all shortcodes
|
||||
$shortcode_pattern = $this->get_shortcode_regex();
|
||||
if ( preg_match_all( '/' . $shortcode_pattern . '/s', $content, $matches ) ) {
|
||||
if ( count( $matches[2] ) ) {
|
||||
foreach ( $matches[2] as $i => $shortcode_name ) {
|
||||
$shortcode_content_changed = $shortcode_changed = FALSE;
|
||||
$shortcode_string = $matches[0][ $i ];
|
||||
$shortcode_params_string = $matches[3][ $i ];
|
||||
$shortcode_content = $matches[5][ $i ];
|
||||
|
||||
// Check if params of this shortcode should be translated
|
||||
$translate_shortcode_method = 'translate_' . $shortcode_name;
|
||||
if ( method_exists( $this, $translate_shortcode_method ) ) {
|
||||
if ( ! empty( $shortcode_params_string ) ) {
|
||||
$shortcode_params = shortcode_parse_atts( $shortcode_params_string );
|
||||
} else {
|
||||
$shortcode_params = array();
|
||||
}
|
||||
$shortcode_changed = $this->$translate_shortcode_method( $shortcode_name, $shortcode_params, $shortcode_content );
|
||||
// If params should be changed, remaking params string
|
||||
if ( $shortcode_changed ) {
|
||||
$shortcode_params_string = '';
|
||||
foreach ( $shortcode_params as $param => $value ) {
|
||||
$shortcode_params_string .= ' ' . $param . '="' . $value . '"';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Using recursion to translate shortcodes inside found shortcode
|
||||
if ( ! empty( $shortcode_content ) ) {
|
||||
$shortcode_content_changed = $this->translate_content( $shortcode_content );
|
||||
}
|
||||
|
||||
// If it is a text containing pricing - leave just pricing
|
||||
if ( get_class( $this ) == 'us_migration_2_0' ) {
|
||||
if ( $shortcode_name == 'vc_column_text' AND preg_match( '/^' . $this->get_shortcode_regex( array( 'us_pricing' ) ) . '$/s', trim( $shortcode_content ) ) ) {
|
||||
$content = str_replace( $shortcode_string, $shortcode_content, $content );
|
||||
$content_changed = TRUE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// If content or params of the shortcode have been changed, making new shortcode string and replacing it in the content
|
||||
if ( $shortcode_content_changed OR $shortcode_changed ) {
|
||||
$new_shortcode_string = '[' . $shortcode_name . $shortcode_params_string . ']';
|
||||
if ( ! empty( $shortcode_content ) ) {
|
||||
$new_shortcode_string .= $shortcode_content;
|
||||
}
|
||||
if ( strpos( $shortcode_string, '[/' . $matches[2][ $i ] . ']' ) ) {
|
||||
$new_shortcode_string .= '[/' . $shortcode_name . ']';
|
||||
}
|
||||
|
||||
// Doing str_replace only once to avoid collisions
|
||||
$pos = strpos( $content, $shortcode_string );
|
||||
if ( $pos !== FALSE ) {
|
||||
$content = substr_replace( $content, $new_shortcode_string, $pos, strlen( $shortcode_string ) );
|
||||
}
|
||||
|
||||
$content_changed = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $content_changed;
|
||||
}
|
||||
|
||||
public $shortcode_tagnames = NULL;
|
||||
|
||||
public function get_shortcode_regex( $tagnames = NULL ) {
|
||||
|
||||
if ( empty( $tagnames ) OR ! is_array( $tagnames ) ) {
|
||||
if ( $this->shortcode_tagnames === NULL ) {
|
||||
// Retrieving list of possible shortcode translations from the class methods
|
||||
$this->shortcode_tagnames = array();
|
||||
foreach ( get_class_methods( $this ) as $method_name ) {
|
||||
if ( substr( $method_name, 0, 10 ) != 'translate_' ) {
|
||||
continue;
|
||||
}
|
||||
$tagname = substr( $method_name, 10 );
|
||||
if ( ! in_array( $tagname, explode( '|', 'menus|params|content|theme_options|meta|widgets' ) ) ) {
|
||||
$this->shortcode_tagnames[] = $tagname;
|
||||
}
|
||||
}
|
||||
}
|
||||
$tagnames = $this->shortcode_tagnames;
|
||||
}
|
||||
|
||||
$tagregexp = implode( '|', array_map( 'preg_quote', $tagnames ) );
|
||||
|
||||
// WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag()
|
||||
// Also, see shortcode_unautop() and shortcode.js.
|
||||
$this->shortcode_regex = '\\[' // Opening bracket
|
||||
. '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
|
||||
. "($tagregexp)" // 2: Shortcode name
|
||||
. '(?![\\w-])' // Not followed by word character or hyphen
|
||||
. '(' // 3: Unroll the loop: Inside the opening shortcode tag
|
||||
. '[^\\]\\/]*' // Not a closing bracket or forward slash
|
||||
. '(?:' . '\\/(?!\\])' // A forward slash not followed by a closing bracket
|
||||
. '[^\\]\\/]*' // Not a closing bracket or forward slash
|
||||
. ')*?' . ')' . '(?:' . '(\\/)' // 4: Self closing tag ...
|
||||
. '\\]' // ... and closing bracket
|
||||
. '|' . '\\]' // Closing bracket
|
||||
. '(?:' . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags
|
||||
. '[^\\[]*+' // Not an opening bracket
|
||||
. '(?:' . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag
|
||||
. '[^\\[]*+' // Not an opening bracket
|
||||
. ')*+' . ')' . '\\[\\/\\2\\]' // Closing shortcode tag
|
||||
. ')?' . ')' . '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]]
|
||||
|
||||
return $this->shortcode_regex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
US_Migration::instance();
|
||||
@@ -0,0 +1,602 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
// Should be inited before the WPBakery Page Builder (that is 9)
|
||||
$portfolio_slug = us_get_option( 'portfolio_slug', 'portfolio' );
|
||||
add_action( 'init', 'us_create_post_types', 8 );
|
||||
function us_create_post_types() {
|
||||
|
||||
if ( us_get_option( 'enable_portfolio', 1 ) == 1 ) {
|
||||
global $portfolio_slug;
|
||||
if ( $portfolio_slug == '' ) {
|
||||
$portfolio_rewrite = array( 'slug' => FALSE, 'with_front' => FALSE );
|
||||
} else {
|
||||
$portfolio_rewrite = array( 'slug' => untrailingslashit( $portfolio_slug ) );
|
||||
}
|
||||
// Portfolio Page post type
|
||||
register_post_type(
|
||||
'us_portfolio', array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Portfolio', 'us' ),
|
||||
'singular_name' => __( 'Portfolio Page', 'us' ),
|
||||
'all_items' => __( 'Portfolio Pages', 'us' ),
|
||||
'add_new' => __( 'Add Portfolio Page', 'us' ),
|
||||
'add_new_item' => __( 'Add Portfolio Page', 'us' ),
|
||||
'edit_item' => __( 'Edit Portfolio Page', 'us' ),
|
||||
'featured_image' => us_translate_x( 'Featured Image', 'page' ),
|
||||
'view_item' => us_translate( 'View Page' ),
|
||||
'not_found' => us_translate( 'No pages found.' ),
|
||||
'not_found_in_trash' => us_translate( 'No pages found in Trash.' ),
|
||||
),
|
||||
'public' => TRUE,
|
||||
'rewrite' => $portfolio_rewrite,
|
||||
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'comments', 'author' ),
|
||||
'capability_type' => array( 'us_portfolio', 'us_portfolios' ),
|
||||
'map_meta_cap' => TRUE,
|
||||
'menu_icon' => 'dashicons-images-alt',
|
||||
)
|
||||
);
|
||||
|
||||
// Portfolio Categories
|
||||
register_taxonomy(
|
||||
'us_portfolio_category', array( 'us_portfolio' ), array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Portfolio Categories', 'us' ),
|
||||
'menu_name' => us_translate( 'Categories' ),
|
||||
),
|
||||
'show_admin_column' => TRUE,
|
||||
'hierarchical' => TRUE,
|
||||
'rewrite' => array( 'slug' => us_get_option( 'portfolio_category_slug', 'portfolio_category' ) ),
|
||||
)
|
||||
);
|
||||
|
||||
// Portfolio Tags
|
||||
register_taxonomy(
|
||||
'us_portfolio_tag', array( 'us_portfolio' ), array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Portfolio Tags', 'us' ),
|
||||
'menu_name' => us_translate( 'Tags' ),
|
||||
),
|
||||
'show_admin_column' => TRUE,
|
||||
'rewrite' => array( 'slug' => us_get_option( 'portfolio_tag_slug' ) ),
|
||||
)
|
||||
);
|
||||
|
||||
// Add "Preview" column for Portfolio Pages
|
||||
add_filter( 'manage_us_portfolio_posts_columns', 'us_add_preview_column' );
|
||||
add_action( 'manage_us_portfolio_posts_custom_column', 'us_add_preview_column_value', 10, 2 );
|
||||
function us_add_preview_column( $columns ) {
|
||||
$num = 1; // after which column paste new column
|
||||
$new_column = array( 'us_preview' => ' ' );
|
||||
|
||||
return array_slice( $columns, 0, $num ) + $new_column + array_slice( $columns, $num );
|
||||
}
|
||||
function us_add_preview_column_value( $column_name, $post_ID ) {
|
||||
if ( $column_name == 'us_preview' AND $thumbnail_id = get_post_meta( $post_ID, '_thumbnail_id', TRUE ) ) {
|
||||
echo wp_get_attachment_image( $thumbnail_id, 'thumbnail', TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
// Portfolio slug may have changed, so we need to keep WP's rewrite rules fresh
|
||||
if ( get_transient( 'us_flush_rules' ) ) {
|
||||
flush_rewrite_rules();
|
||||
delete_transient( 'us_flush_rules' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( us_get_option( 'enable_testimonials', 1 ) == 1 ) {
|
||||
// Testimonial post type
|
||||
register_post_type(
|
||||
'us_testimonial', array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Testimonials', 'us' ),
|
||||
'singular_name' => __( 'Testimonial', 'us' ),
|
||||
'add_new' => __( 'Add Testimonial', 'us' ),
|
||||
'add_new_item' => __( 'Add Testimonial', 'us' ),
|
||||
'edit_item' => __( 'Edit Testimonial', 'us' ),
|
||||
'featured_image' => __( 'Author Photo', 'us' ),
|
||||
),
|
||||
'public' => TRUE,
|
||||
'publicly_queryable' => FALSE,
|
||||
'show_in_nav_menus' => FALSE,
|
||||
'supports' => array( 'title', 'editor', 'thumbnail' ),
|
||||
'menu_icon' => 'dashicons-testimonial',
|
||||
'capability_type' => array( 'us_testimonial', 'us_testimonials' ),
|
||||
'map_meta_cap' => TRUE,
|
||||
'rewrite' => FALSE,
|
||||
)
|
||||
);
|
||||
|
||||
// Testimonial Categories
|
||||
register_taxonomy(
|
||||
'us_testimonial_category', array( 'us_testimonial' ), array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Testimonial Categories', 'us' ),
|
||||
'menu_name' => us_translate( 'Categories' ),
|
||||
),
|
||||
'public' => TRUE,
|
||||
'show_admin_column' => TRUE,
|
||||
'publicly_queryable' => FALSE,
|
||||
'show_in_nav_menus' => FALSE,
|
||||
'show_in_rest' => FALSE,
|
||||
'show_tagcloud' => FALSE,
|
||||
'hierarchical' => TRUE,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Media Categories
|
||||
if ( us_get_option( 'media_category', 0 ) ) {
|
||||
register_taxonomy(
|
||||
'us_media_category', array( 'attachment' ), array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Media Categories', 'us' ),
|
||||
'menu_name' => us_translate( 'Categories' ),
|
||||
),
|
||||
'public' => TRUE,
|
||||
'show_admin_column' => TRUE,
|
||||
'publicly_queryable' => FALSE,
|
||||
'show_in_nav_menus' => FALSE,
|
||||
'show_in_rest' => FALSE,
|
||||
'show_tagcloud' => FALSE,
|
||||
'hierarchical' => TRUE,
|
||||
'update_count_callback' => 'us_media_category_update_count_callback',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Widget Area post type (used in Menus)
|
||||
register_post_type(
|
||||
'us_widget_area', array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Sidebars', 'us' ),
|
||||
'singular_name' => __( 'Sidebar', 'us' ),
|
||||
),
|
||||
'public' => FALSE,
|
||||
'show_in_nav_menus' => TRUE,
|
||||
)
|
||||
);
|
||||
|
||||
// Page Block post type
|
||||
register_post_type(
|
||||
'us_page_block', array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Page Blocks', 'us' ),
|
||||
'singular_name' => __( 'Page Block', 'us' ),
|
||||
'add_new' => __( 'Add Page Block', 'us' ),
|
||||
'add_new_item' => __( 'Add Page Block', 'us' ),
|
||||
'edit_item' => __( 'Edit Page Block', 'us' ),
|
||||
),
|
||||
'public' => TRUE,
|
||||
'show_in_menu' => 'us-theme-options',
|
||||
'exclude_from_search' => TRUE,
|
||||
'show_in_admin_bar' => FALSE,
|
||||
'publicly_queryable' => FALSE,
|
||||
'show_in_nav_menus' => FALSE,
|
||||
'capability_type' => array( 'us_page_block', 'us_page_blocks' ),
|
||||
'map_meta_cap' => TRUE,
|
||||
'rewrite' => FALSE,
|
||||
'register_meta_box_cb' => 'us_page_block_type_pages',
|
||||
)
|
||||
);
|
||||
|
||||
// Add "Used in" column into Page Blocks admin page
|
||||
add_filter( 'manage_us_page_block_posts_columns', 'us_manage_page_block_columns_head' );
|
||||
add_action( 'manage_us_page_block_posts_custom_column', 'us_manage_page_block_columns_content', 10, 2 );
|
||||
function us_manage_page_block_columns_head( $defaults ) {
|
||||
$result = array();
|
||||
foreach ( $defaults as $key => $title ) {
|
||||
if ( $key == 'date' ) {
|
||||
$result['used_in'] = __( 'Used in', 'us' );
|
||||
}
|
||||
$result[ $key ] = $title;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
function us_manage_page_block_columns_content( $column_name, $post_ID ) {
|
||||
if ( $column_name == 'used_in' ) {
|
||||
echo us_get_used_in_locations( $post_ID );
|
||||
}
|
||||
}
|
||||
|
||||
// Add ability to duplicate posts
|
||||
add_filter( 'post_row_actions', 'us_page_block_post_row_actions', 10, 2 );
|
||||
function us_page_block_post_row_actions( $actions, $post ) {
|
||||
if ( $post->post_type === 'us_page_block' ) {
|
||||
// Removing duplicate post plugin affection
|
||||
unset( $actions['duplicate'], $actions['edit_as_new_draft'] );
|
||||
$actions = us_array_merge_insert(
|
||||
$actions, array(
|
||||
'duplicate' => '<a href="' . admin_url( 'post-new.php?post_type=us_page_block&duplicate_from=' . $post->ID ) . '" aria-label="' . esc_attr__( 'Duplicate', 'us' ) . '">' . esc_html__( 'Duplicate', 'us' ) . '</a>',
|
||||
), 'before', isset( $actions['trash'] ) ? 'trash' : 'untrash'
|
||||
);
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
function us_page_block_type_pages() {
|
||||
global $post;
|
||||
// Dev note: This check is not necessary, but still wanted to make sure this function won't be bound somewhere else
|
||||
if ( ! ( $post instanceof WP_Post ) OR $post->post_type !== 'us_page_block' ) {
|
||||
return;
|
||||
}
|
||||
if ( $post->post_status === 'auto-draft' ) {
|
||||
// Page for creating new Page Block: creating it instantly and proceeding to editing
|
||||
$post_data = array( 'ID' => $post->ID );
|
||||
// Retrieving occupied names to generate new post title properly
|
||||
$existing_page_blocks = array();
|
||||
$page_blocks = get_posts(
|
||||
array(
|
||||
'post_type' => 'us_page_block',
|
||||
'posts_per_page' => - 1,
|
||||
'post_status' => 'any',
|
||||
'suppress_filters' => 0,
|
||||
)
|
||||
);
|
||||
foreach ( $page_blocks as $page_block ) {
|
||||
$existing_page_blocks[ $page_block->ID ] = $page_block->post_title;
|
||||
}
|
||||
if ( isset( $_GET['duplicate_from'] ) AND ( $original_post = get_post( (int) $_GET['duplicate_from'] ) ) !== NULL ) {
|
||||
// Handling post duplication
|
||||
$post_data['post_content'] = $original_post->post_content;
|
||||
$title_pattern = $original_post->post_title . ' (%d)';
|
||||
$cur_index = 2;
|
||||
} else {
|
||||
// Handling creation from scratch
|
||||
$title_pattern = __( 'Page Block', 'us' ) . ' %d';
|
||||
$cur_index = count( $existing_page_blocks ) + 1;
|
||||
}
|
||||
// Generating new post title
|
||||
while ( in_array( $post_data['post_title'] = sprintf( $title_pattern, $cur_index ), $existing_page_blocks ) ) {
|
||||
$cur_index ++;
|
||||
}
|
||||
wp_update_post( $post_data );
|
||||
wp_publish_post( $post->ID );
|
||||
// Redirect
|
||||
if ( isset( $_GET['duplicate_from'] ) ) {
|
||||
// When duplicating post, showing posts list next
|
||||
wp_redirect( admin_url( 'edit.php?post_type=us_page_block' ) );
|
||||
} else {
|
||||
// When creating from scratch proceeding to post editing next
|
||||
wp_redirect( admin_url( 'post.php?post=' . $post->ID . '&action=edit' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add iframe param for posts and pages opened in grid lightbox
|
||||
global $us_iframe;
|
||||
$us_iframe = ( isset( $_GET['us_iframe'] ) AND $_GET['us_iframe'] == 1 ) ? TRUE : FALSE;
|
||||
|
||||
if ( $us_iframe ) {
|
||||
add_filter( 'show_admin_bar', '__return_false' );
|
||||
remove_action( 'wp_head', '_admin_bar_bump_cb' );
|
||||
}
|
||||
}
|
||||
|
||||
// Set Portfolio Pages slug
|
||||
if ( us_get_option( 'enable_portfolio', 1 ) == 1 ) {
|
||||
if ( strpos( $portfolio_slug, '%us_portfolio_category%' ) !== FALSE ) {
|
||||
function us_portfolio_link( $post_link, $id = 0 ) {
|
||||
$post = get_post( $id );
|
||||
if ( is_object( $post ) ) {
|
||||
$terms = wp_get_object_terms( $post->ID, 'us_portfolio_category' );
|
||||
if ( $terms ) {
|
||||
return str_replace( '%us_portfolio_category%', $terms[0]->slug, $post_link );
|
||||
} else {
|
||||
// If no terms are assigned to this post, use a string instead (can't leave the placeholder there)
|
||||
return str_replace( '%us_portfolio_category%', 'uncategorized', $post_link );
|
||||
}
|
||||
}
|
||||
|
||||
return $post_link;
|
||||
}
|
||||
|
||||
add_filter( 'post_type_link', 'us_portfolio_link', 1, 3 );
|
||||
} elseif ( $portfolio_slug == '' ) {
|
||||
function us_portfolio_remove_slug( $post_link, $post, $leavename ) {
|
||||
if ( 'us_portfolio' != $post->post_type OR 'publish' != $post->post_status ) {
|
||||
return $post_link;
|
||||
}
|
||||
$post_link = str_replace( '/' . trailingslashit( $post->post_type ), '/', $post_link );
|
||||
|
||||
return $post_link;
|
||||
}
|
||||
|
||||
add_filter( 'post_type_link', 'us_portfolio_remove_slug', 10, 3 );
|
||||
|
||||
function us_portfolio_parse_request( $query ) {
|
||||
if ( ! $query->is_main_query() OR 2 != count( $query->query ) OR ! isset( $query->query['page'] ) ) {
|
||||
return;
|
||||
}
|
||||
if ( ! empty( $query->query['name'] ) ) {
|
||||
$query->set( 'post_type', array( 'post', 'us_portfolio', 'page' ) );
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'pre_get_posts', 'us_portfolio_parse_request' );
|
||||
}
|
||||
}
|
||||
|
||||
// Exclude Testimonials from search results
|
||||
if ( us_get_option( 'enable_testimonials', 1 ) == 1 ) {
|
||||
add_action( 'pre_get_posts', 'us_exclude_testimonials_from_search' );
|
||||
function us_exclude_testimonials_from_search() {
|
||||
if ( ! is_search() ) {
|
||||
return;
|
||||
}
|
||||
global $wp_post_types;
|
||||
if ( post_type_exists( 'us_testimonial' ) ) {
|
||||
$wp_post_types['us_testimonial']->exclude_from_search = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add admin capabilities to Portfolio, Testimonials, Page Blocks
|
||||
add_action( 'admin_init', 'us_add_theme_caps' );
|
||||
function us_add_theme_caps() {
|
||||
global $wp_post_types;
|
||||
$role = get_role( 'administrator' );
|
||||
$force_refresh = FALSE;
|
||||
$custom_post_types = array( 'us_portfolio', 'us_testimonial', 'us_page_block' );
|
||||
foreach ( $custom_post_types as $post_type ) {
|
||||
if ( ! post_type_exists( $post_type ) ) {
|
||||
continue;
|
||||
}
|
||||
foreach ( $wp_post_types[ $post_type ]->cap as $cap ) {
|
||||
if ( ! $role->has_cap( $cap ) ) {
|
||||
$role->add_cap( $cap );
|
||||
$force_refresh = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $force_refresh AND current_user_can( 'manage_options' ) AND ! isset( $_COOKIE['us_cap_page_refreshed'] ) ) {
|
||||
// To prevent infinite refreshes when the DB is not writable
|
||||
setcookie( 'us_cap_page_refreshed' );
|
||||
header( 'Refresh: 0' );
|
||||
}
|
||||
}
|
||||
|
||||
// Add role capabilities to Portfolio & Testimonials
|
||||
add_action( 'admin_init', 'us_theme_activation_add_caps' );
|
||||
function us_theme_activation_add_caps() {
|
||||
global $pagenow;
|
||||
if ( is_admin() AND $pagenow == 'themes.php' AND isset( $_GET['activated'] ) ) {
|
||||
if ( get_option( US_THEMENAME . '_editor_caps_set' ) == 1 ) {
|
||||
return;
|
||||
}
|
||||
update_option( US_THEMENAME . '_editor_caps_set', 1 );
|
||||
global $wp_post_types;
|
||||
$role = get_role( 'editor' );
|
||||
$custom_post_types = array( 'us_portfolio', 'us_testimonial' );
|
||||
foreach ( $custom_post_types as $post_type ) {
|
||||
if ( ! post_type_exists( $post_type ) ) {
|
||||
continue;
|
||||
}
|
||||
foreach ( $wp_post_types[ $post_type ]->cap as $cap ) {
|
||||
if ( ! $role->has_cap( $cap ) ) {
|
||||
$role->add_cap( $cap );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add Default Footer on theme activation
|
||||
function us_add_default_footer() {
|
||||
|
||||
// If any Page Block exists, do nothing
|
||||
$args = array(
|
||||
'post_type' => 'us_page_block',
|
||||
'post_status' => 'any',
|
||||
'numberposts' => - 1,
|
||||
);
|
||||
$page_blocks = get_posts( $args );
|
||||
if ( $page_blocks ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Create Default Footer
|
||||
$footer_content = '[vc_row color_scheme="footer-bottom"][vc_column][vc_column_text]<p style="text-align: center;">© Copyright text goes here</p>[/vc_column_text][/vc_column][/vc_row]';
|
||||
$footer_post_array = array(
|
||||
'post_type' => 'us_page_block',
|
||||
'post_date' => date( 'Y-m-d H:i', time() ),
|
||||
'post_title' => __( 'Default Footer', 'us' ),
|
||||
'post_content' => $footer_content,
|
||||
'post_status' => 'publish',
|
||||
);
|
||||
$footer_post_id = wp_insert_post( $footer_post_array );
|
||||
|
||||
// Set Default Footer as default in Theme Options
|
||||
global $usof_options;
|
||||
usof_load_options_once();
|
||||
|
||||
$updated_options = $usof_options;
|
||||
$updated_options['footer_id'] = $footer_post_id;
|
||||
$updated_options = array_merge( usof_defaults(), $updated_options );
|
||||
|
||||
usof_save_options( $updated_options );
|
||||
}
|
||||
|
||||
// Remove not public post types from insert/edit link dialog
|
||||
add_filter( 'wp_link_query_args', 'us_link_query_filter' );
|
||||
function us_link_query_filter( $query ) {
|
||||
|
||||
$not_public_post_types = get_post_types(
|
||||
array(
|
||||
'publicly_queryable' => FALSE,
|
||||
'_builtin' => FALSE,
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $query['post_type'] as $key => $value ) {
|
||||
if ( in_array( $value, $not_public_post_types ) ) {
|
||||
unset( $query['post_type'][ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
// Add needed filters to Page Block content
|
||||
add_filter( 'us_page_block_the_content', 'wptexturize' );
|
||||
add_filter( 'us_page_block_the_content', 'wpautop' );
|
||||
add_filter( 'us_page_block_the_content', 'shortcode_unautop' );
|
||||
add_filter( 'us_page_block_the_content', 'wp_make_content_images_responsive' );
|
||||
add_filter( 'us_page_block_the_content', 'do_shortcode', 12 );
|
||||
add_filter( 'us_page_block_the_content', 'convert_smilies', 20 );
|
||||
|
||||
// Remember extra IDs when save post. For "Used in" UI
|
||||
add_action( 'save_post', 'us_save_post_add_in_content_ids' );
|
||||
function us_save_post_add_in_content_ids( $post_id ) {
|
||||
$ids = '';
|
||||
$post = get_post( $post_id );
|
||||
$the_content = $post->post_content;
|
||||
|
||||
// Add Grid Layouts IDs
|
||||
if ( preg_match_all('/\[us_grid[^\]]+items_layout="([0-9]+)"/i', $the_content, $matches) ) {
|
||||
$ids = implode( ',', $matches[1] );
|
||||
}
|
||||
|
||||
// Add Page Blocks IDs
|
||||
if ( preg_match_all('/\[us_page_block[^\]]+id="([0-9]+)"/i', $the_content, $matches) ) {
|
||||
$ids .= implode( ',', $matches[1] );
|
||||
}
|
||||
|
||||
update_post_meta( $post_id, '_us_in_content_ids', $ids );
|
||||
}
|
||||
|
||||
// Generate locations names where used specific element
|
||||
function us_get_used_in_locations( $post_ID, $show_no_results = FALSE ) {
|
||||
$result = '';
|
||||
global $usof_options, $wpdb;
|
||||
usof_load_options_once();
|
||||
|
||||
$areas = array(
|
||||
'header' => _x( 'Header', 'site top area', 'us' ),
|
||||
'content' => __( 'Content template', 'us' ),
|
||||
'footer' => __( 'Footer', 'us' ),
|
||||
);
|
||||
$used_in = array(
|
||||
'theme_options' => array(),
|
||||
'singulars_meta' => array(),
|
||||
'singulars_content' => array(),
|
||||
);
|
||||
|
||||
// Theme Options > Pages Layout
|
||||
$pages_layout_types = array_merge(
|
||||
array(
|
||||
'' => us_translate_x( 'Pages', 'post type general name' ),
|
||||
'post' => us_translate_x( 'Posts', 'post type general name' ),
|
||||
'portfolio' => __( 'Portfolio Pages', 'us' ),
|
||||
),
|
||||
us_get_public_cpt()
|
||||
);
|
||||
if ( ! $usof_options['enable_portfolio'] ) {
|
||||
unset( $pages_layout_types['portfolio'] );
|
||||
}
|
||||
foreach ( $pages_layout_types as $type => $title ) {
|
||||
$type = ( $type != '' ) ? ( '_' . $type ) : '';
|
||||
$edit_link = ' (<a href="' . admin_url() . 'admin.php?page=us-theme-options#pages_layout" target="_blank">' . __( 'edit in Theme Options', 'us' ) . '</a>)</div>';
|
||||
|
||||
foreach ( $areas as $area => $area_name ) {
|
||||
if ( isset( $usof_options[ $area . $type . '_id' ] ) AND $usof_options[ $area . $type . '_id' ] == $post_ID ) {
|
||||
$used_in['theme_options'][] = '<div><strong>' . $title . ' > ' . $area_name . '</strong>' . $edit_link;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Theme Options > Archives Layout
|
||||
$archives_layout_types = array_merge(
|
||||
array(
|
||||
'archive' => us_translate( 'Archives' ),
|
||||
'author' => __( 'Authors', 'us' ),
|
||||
), us_get_taxonomies( TRUE, FALSE )
|
||||
);
|
||||
foreach ( $archives_layout_types as $type => $title ) {
|
||||
if ( ! in_array( $type, array( 'archive', 'shop', 'author' ) ) ) {
|
||||
$type = 'tax_' . $type;
|
||||
}
|
||||
$edit_link = ' (<a href="' . admin_url() . 'admin.php?page=us-theme-options#archives_layout" target="_blank">' . __( 'edit in Theme Options', 'us' ) . '</a>)</div>';
|
||||
foreach ( $areas as $area => $area_name ) {
|
||||
if ( isset( $usof_options[ $area . '_' . $type . '_id' ] ) AND $usof_options[ $area . '_' . $type . '_id' ] == $post_ID ) {
|
||||
$used_in['theme_options'][] = '<div><strong>' . $title . ' > ' . $area_name . '</strong>' . $edit_link;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Theme Options > Shop
|
||||
if ( class_exists( 'woocommerce' ) ) {
|
||||
$woocommerce_types = array(
|
||||
'product' => us_translate( 'Products', 'woocommerce' ),
|
||||
'shop' => us_translate( 'Shop Page', 'woocommerce' ),
|
||||
);
|
||||
foreach ( $woocommerce_types as $type => $title ) {
|
||||
$edit_link = ' (<a href="' . admin_url() . 'admin.php?page=us-theme-options#woocommerce" target="_blank">' . __( 'edit in Theme Options', 'us' ) . '</a>)</div>';
|
||||
|
||||
foreach ( $areas as $area => $area_name ) {
|
||||
if ( isset( $usof_options[ $area . '_' . $type . '_id' ] ) AND $usof_options[ $area . '_' . $type . '_id' ] == $post_ID ) {
|
||||
$used_in['theme_options'][] = '<div><strong>' . $title . ' > ' . $area_name . '</strong>' . $edit_link;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Append locations to result string
|
||||
$result .= implode( $used_in['theme_options'] );
|
||||
|
||||
// Singulars (metabox)
|
||||
foreach ( $areas as $area => $area_name ) {
|
||||
$usage_query = "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = 'us_" . $area . "_id' AND meta_value = '" . $post_ID . "' LIMIT 0, 100";
|
||||
// Do not show area name for headers
|
||||
if ( $area == 'header' ) {
|
||||
$area_name = '';
|
||||
} else {
|
||||
$area_name = ' > ' . $area_name;
|
||||
}
|
||||
|
||||
foreach ( $wpdb->get_results( $usage_query ) as $usage_result ) {
|
||||
$post = get_post( $usage_result->post_id );
|
||||
if ( $post ) {
|
||||
$post_title = ( get_the_title( $post->ID ) != '' ) ? get_the_title( $post->ID ) : us_translate( '(no title)' );
|
||||
|
||||
$used_in['singulars_meta'][] = '<div><a href="' . get_permalink( $post->ID ) . '" target="_blank" title="' . us_translate( 'View Page' ) . '">' . $post_title . '</a>' . $area_name . '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Append locations to result string
|
||||
$result .= implode( $used_in['singulars_meta'] );
|
||||
|
||||
// Singulars (content)
|
||||
$usage_query = "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = '_us_in_content_ids' AND meta_value LIKE '%" . $post_ID . "%' LIMIT 0, 100";
|
||||
foreach ( $wpdb->get_results( $usage_query ) as $usage_result ) {
|
||||
$post = get_post( $usage_result->post_id );
|
||||
if ( $post ) {
|
||||
$used_in['singulars_content'][$post->ID] = array(
|
||||
'url' => get_permalink( $post->ID ),
|
||||
'edit_url' => get_edit_post_link( $post->ID ),
|
||||
'title' => ( get_the_title( $post->ID ) != '' ) ? get_the_title( $post->ID ) : us_translate( '(no title)' ),
|
||||
'post_type' => get_post_type( $post->ID ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Append locations to result string
|
||||
foreach ( $used_in['singulars_content'] as $location ) {
|
||||
if ( $location['post_type'] == 'us_page_block' ) {
|
||||
// output admin Edit link for Page Blocks
|
||||
$result .= '<div><a href="' . $location['edit_url'] . '" target="_blank" title="' . __( 'Edit Page Block', 'us' ) . '">' . $location['title'] . '</a></div>';
|
||||
} else {
|
||||
// output Permalink for other post types
|
||||
$result .= '<div><a href="' . $location['url'] . '" target="_blank" title="' . us_translate( 'View Page' ) . '">' . $location['title'] . '</a></div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Return "No results" message if set
|
||||
if ( empty( $result ) AND $show_no_results ) {
|
||||
return us_translate( 'No results found.' );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Retrieves and returns the part of current post that can be used as the post's preview.
|
||||
*
|
||||
* (!) Should be called in WP_Query fetching loop only.
|
||||
*
|
||||
* @param string $the_content Post content, retrieved with get_the_content() (without 'the_content' filters)
|
||||
* @param bool $strip_from_the_content Should the found element be removed from post content not to be duplicated?
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function us_get_post_preview( &$the_content, $strip_from_the_content = FALSE ) {
|
||||
// Retrieving post format
|
||||
$post_format = get_post_format() ? get_post_format() : 'standard';
|
||||
$preview_html = '';
|
||||
|
||||
global $us_post_img_ratio;
|
||||
if ( ! empty( $us_post_img_ratio ) ) {
|
||||
$video_h_style = ' style="padding-bottom:' . $us_post_img_ratio . '%;"';
|
||||
} else {
|
||||
$video_h_style = '';
|
||||
}
|
||||
|
||||
// Retrieving post preview
|
||||
if ( $post_format == 'gallery' ) {
|
||||
if ( preg_match( '~\[us_image_slider.+?\]|\[gallery.+?\]~', $the_content, $matches ) ) {
|
||||
|
||||
// Replacing with a simple image slider
|
||||
$gallery = preg_replace( '~(vc_gallery|gallery)~', 'us_image_slider', $matches[0] );
|
||||
|
||||
global $us_post_slider_size;
|
||||
if ( ! empty( $us_post_slider_size ) ) {
|
||||
if ( preg_match( '~img_size=\"[^"]+"~', $gallery ) ) {
|
||||
$gallery = preg_replace( '~img_size=\"[^"]+"~', 'img_size="' . $us_post_slider_size . '"', $gallery );
|
||||
} else {
|
||||
$gallery = str_replace( '[us_image_slider', '[us_image_slider img_size="' . $us_post_slider_size . '"', $gallery );
|
||||
}
|
||||
|
||||
}
|
||||
$preview_html = do_shortcode( $gallery );
|
||||
|
||||
if ( $strip_from_the_content ) {
|
||||
$the_content = str_replace( $matches[0], '', $the_content );
|
||||
}
|
||||
} elseif ( preg_match( '~\[us_grid.+post_type="attachment".+?\]~', $the_content, $matches ) ) {
|
||||
// Replacing with a simple image slider
|
||||
$gallery = preg_replace( '~us_grid.+post_type="attachment".+images="([^"]+)([^]]+)~', 'us_image_slider ids=$1', $matches[0] );
|
||||
|
||||
global $us_post_slider_size;
|
||||
if ( ! empty( $us_post_slider_size ) ) {
|
||||
$gallery = str_replace( '[us_image_slider', '[us_image_slider img_size="' . $us_post_slider_size . '"', $gallery );
|
||||
}
|
||||
$preview_html = do_shortcode( $gallery );
|
||||
|
||||
if ( $strip_from_the_content ) {
|
||||
$the_content = str_replace( $matches[0], '', $the_content );
|
||||
}
|
||||
}
|
||||
|
||||
} elseif ( $post_format == 'video' ) {
|
||||
$post_content = preg_replace( '~^\s*(https?://[^\s"]+)\s*$~im', "[embed]$1[/embed]", $the_content );
|
||||
|
||||
if ( preg_match( '~\[embed.+?\]|\[vc_video.+?\]~', $post_content, $matches ) ) {
|
||||
|
||||
global $wp_embed;
|
||||
$video = $matches[0];
|
||||
$preview_html = do_shortcode( $wp_embed->run_shortcode( $video ) );
|
||||
if ( strpos( $preview_html, 'w-video' ) === FALSE ) {
|
||||
$preview_html = '<div class="w-video"><div class="w-video-h"' . $video_h_style . '>' . $preview_html . '</div></div>';
|
||||
}
|
||||
$post_content = str_replace( $matches[0], "", $post_content );
|
||||
}
|
||||
if ( ! empty( $preview_html ) AND $strip_from_the_content ) {
|
||||
$the_content = $post_content;
|
||||
}
|
||||
|
||||
} elseif ( $post_format == 'audio' ) {
|
||||
$post_content = preg_replace( '~^\s*(https?://[^\s"]+)\s*$~im', "[embed]$1[/embed]", $the_content );
|
||||
|
||||
if ( preg_match( '~\[audio.+?\]\[\/audio\]~', $post_content, $matches ) ) {
|
||||
$audio = $matches[0];
|
||||
$preview_html = do_shortcode( $audio );
|
||||
|
||||
$post_content = str_replace( $matches[0], "", $post_content );
|
||||
} elseif ( preg_match( '~\[embed.+?\]~', $post_content, $matches ) ) {
|
||||
|
||||
global $wp_embed;
|
||||
$video = $matches[0];
|
||||
$preview_html = do_shortcode( $wp_embed->run_shortcode( $video ) );
|
||||
if ( strpos( $preview_html, 'w-video' ) === FALSE ) {
|
||||
$preview_html = '<div class="w-video"><div class="w-video-h"' . $video_h_style . '>' . $preview_html . '</div></div>';
|
||||
}
|
||||
$post_content = str_replace( $matches[0], "", $post_content );
|
||||
}
|
||||
if ( ! empty( $preview_html ) AND $strip_from_the_content ) {
|
||||
$the_content = $post_content;
|
||||
}
|
||||
}
|
||||
|
||||
$preview_html = apply_filters( 'us_get_post_preview', $preview_html, get_the_ID() );
|
||||
|
||||
return $preview_html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL for link post format
|
||||
*
|
||||
* @param $the_content
|
||||
* @param bool|FALSE $strip_from_the_content
|
||||
*/
|
||||
function us_get_post_format_link_url( $url, $post ) {
|
||||
|
||||
if ( get_post_format( $post->ID ) != 'link' ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$post_content = $post->post_content;
|
||||
$link = '';
|
||||
|
||||
if ( preg_match( '$(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$i', $post_content, $matches ) ) {
|
||||
$link = $matches[0];
|
||||
}
|
||||
|
||||
if ( $link != '' ) {
|
||||
//$post->post_content = str_replace( $link, "", $post->post_content );
|
||||
return $link;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
add_filter( 'post_link', 'us_get_post_format_link_url', 10, 3 );
|
||||
|
||||
/**
|
||||
* Get information about previous and next post or page (should be used in singular element context)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function us_get_post_prevnext( $invert = FALSE, $in_same_term = FALSE, $taxonomy = 'category' ) {
|
||||
$prev = $next = array();
|
||||
|
||||
// Exclude posts with "Link" format
|
||||
if ( is_singular( 'post' ) ) {
|
||||
global $us_post_prevnext_exclude_ids;
|
||||
if ( $us_post_prevnext_exclude_ids === NULL ) {
|
||||
global $wpdb;
|
||||
$wpdb_query = 'SELECT `object_id` FROM `' . $wpdb->terms . '`, `' . $wpdb->term_relationships . '` ';
|
||||
$wpdb_query .= 'WHERE (`slug`=\'post-format-link\' AND `term_id`=`term_taxonomy_id`)';
|
||||
$us_post_prevnext_exclude_ids = apply_filters( 'us_get_post_prevnext_exclude_ids', $wpdb->get_col( $wpdb_query ) );
|
||||
if ( ! empty( $us_post_prevnext_exclude_ids ) ) {
|
||||
add_filter( 'get_next_post_where', 'us_exclude_post_format_link_from_prevnext' );
|
||||
add_filter( 'get_previous_post_where', 'us_exclude_post_format_link_from_prevnext' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$next_post = get_next_post( $in_same_term, '', $taxonomy );
|
||||
$prev_post = get_previous_post( $in_same_term, '', $taxonomy );
|
||||
|
||||
if ( ! empty( $prev_post ) ) {
|
||||
$prev = array(
|
||||
'id' => $prev_post->ID,
|
||||
'link' => get_permalink( $prev_post->ID ),
|
||||
'title' => get_the_title( $prev_post->ID ),
|
||||
'meta' => us_translate( 'Previous Post' ),
|
||||
);
|
||||
}
|
||||
if ( ! empty( $next_post ) ) {
|
||||
$next = array(
|
||||
'id' => $next_post->ID,
|
||||
'link' => get_permalink( $next_post->ID ),
|
||||
'title' => get_the_title( $next_post->ID ),
|
||||
'meta' => us_translate( 'Next Post' ),
|
||||
);
|
||||
}
|
||||
|
||||
return ( $invert ) ? array( 'next' => $next, 'prev' => $prev ) : array( 'prev' => $prev, 'next' => $next );
|
||||
}
|
||||
|
||||
function us_exclude_post_format_link_from_prevnext( $where ) {
|
||||
global $us_post_prevnext_exclude_ids;
|
||||
if ( ! empty( $us_post_prevnext_exclude_ids ) AND is_array( $us_post_prevnext_exclude_ids ) ) {
|
||||
$where .= ' AND p.ID NOT IN (' . implode( ',', $us_post_prevnext_exclude_ids ) . ')';
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
// Display specific page when Maintenance Mode is enabled in Theme Options
|
||||
add_action( 'init', 'us_maintenance_mode' );
|
||||
function us_maintenance_mode() {
|
||||
if ( is_user_logged_in() ) {
|
||||
add_action( 'admin_bar_menu', 'us_maintenance_admin_bar_menu', 1000 );
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
if ( us_get_option( 'maintenance_mode' ) AND us_get_option( 'maintenance_page' ) ) {
|
||||
$maintenance_page = get_post( us_get_option( 'maintenance_page' ) );
|
||||
if ( $maintenance_page ) {
|
||||
if ( function_exists( 'bp_is_active' ) ) {
|
||||
add_action( 'template_redirect', 'us_display_maintenance_page', 9 );
|
||||
} else {
|
||||
add_action( 'template_redirect', 'us_display_maintenance_page' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Show indication in admin bar when Maintenance Mode is enabled
|
||||
function us_maintenance_admin_bar_menu( $wp_admin_bar ) {
|
||||
if ( us_get_option( 'maintenance_mode' ) AND us_get_option( 'maintenance_page' ) ) {
|
||||
$maintenance_page = get_post( us_get_option( 'maintenance_page' ) );
|
||||
if ( $maintenance_page ) {
|
||||
|
||||
$wp_admin_bar->add_node(
|
||||
array(
|
||||
'id' => 'us-maintenance-notice',
|
||||
'href' => admin_url() . 'admin.php?page=us-theme-options',
|
||||
'title' => __( 'Maintenance Mode', 'us' ),
|
||||
'meta' => array(
|
||||
'class' => 'us-maintenance',
|
||||
'html' => '<style>.us-maintenance a{font-weight:600!important;color:#f90!important;}</style>',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Show specified page when Maintenance Mode is enabled
|
||||
function us_display_maintenance_page() {
|
||||
$maintenance_page = get_post( us_get_option( 'maintenance_page' ) );
|
||||
|
||||
if ( $maintenance_page ) {
|
||||
if ( class_exists( 'SitePress' ) ) {
|
||||
$maintenance_page = get_post( apply_filters( 'wpml_object_id', $maintenance_page->ID, 'page', TRUE ) );
|
||||
}
|
||||
us_open_wp_query_context();
|
||||
global $wp_query;
|
||||
$wp_query = new WP_Query(
|
||||
array(
|
||||
'p' => $maintenance_page->ID,
|
||||
'post_type' => 'page',
|
||||
)
|
||||
);
|
||||
the_post();
|
||||
|
||||
if ( us_get_option( 'maintenance_503', 1 ) == 1 ) {
|
||||
header( 'HTTP/1.1 503 Service Temporarily Unavailable' );
|
||||
header( 'Status: 503 Service Temporarily Unavailable' );
|
||||
header( 'Retry-After: 86400' ); // retry in a day
|
||||
}
|
||||
|
||||
$us_layout = US_Layout::instance();
|
||||
$us_layout->header_show = 'never';
|
||||
|
||||
get_header();
|
||||
?>
|
||||
<main class="l-main"<?php echo ( us_get_option( 'schema_markup' ) ) ? ' itemprop="mainContentOfPage"' : ''; ?>>
|
||||
<?php
|
||||
do_action( 'us_before_page' );
|
||||
|
||||
$the_content = apply_filters( 'the_content', $maintenance_page->post_content );
|
||||
|
||||
echo $the_content;
|
||||
|
||||
do_action( 'us_after_page' );
|
||||
?>
|
||||
</main>
|
||||
<?php
|
||||
global $us_hide_footer;
|
||||
$us_hide_footer = TRUE;
|
||||
|
||||
get_footer();
|
||||
us_close_wp_query_context();
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of posts titles by a certain post type
|
||||
* @param string $post_type Post type to get
|
||||
* @param bool $force_no_cache Allow using cache (use FALSE to force not-cached version)
|
||||
* @return array
|
||||
*/
|
||||
function us_get_posts_titles_for( $post_type, $orderby = 'title', $force_no_cache = TRUE ) {
|
||||
// Caching results
|
||||
static $result = array();
|
||||
if ( ! isset( $result[ $post_type ] ) OR $force_no_cache ) {
|
||||
$result[ $post_type ] = array();
|
||||
$get_posts_args = array(
|
||||
'post_type' => $post_type,
|
||||
'posts_per_page' => - 1,
|
||||
'post_status' => 'any',
|
||||
'suppress_filters' => 0,
|
||||
);
|
||||
if ( ! empty( $orderby ) AND $orderby == 'title' ) {
|
||||
$get_posts_args['orderby'] = 'title';
|
||||
$get_posts_args['order'] = 'ASC';
|
||||
}
|
||||
$posts = get_posts( $get_posts_args );
|
||||
foreach ( $posts as $post ) {
|
||||
if ( $post->post_title != '' ) {
|
||||
$result[ $post_type ][ $post->ID ] = $post->post_title;
|
||||
} else {
|
||||
$result[ $post_type ][ $post->ID ] = us_translate( '(no title)' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result[ $post_type ];
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
class US_Shortcodes {
|
||||
|
||||
/**
|
||||
* @var {String} Template directory
|
||||
*/
|
||||
protected $_template_directory;
|
||||
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var array Current shortcode config
|
||||
*/
|
||||
protected $_settings;
|
||||
|
||||
/**
|
||||
* Retrieve one setting (used for compatibility with VC)
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function settings( $key ) {
|
||||
return isset( $this->_settings[ $key ] ) ? $this->_settings[ $key ] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var US_Shortcodes
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* Singleton pattern: US_Shortcodes::instance()->us_grid($atts, $content)
|
||||
*
|
||||
* @return US_Shortcodes
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self;
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
protected function __construct() {
|
||||
global $us_template_directory, $us_stylesheet_directory;
|
||||
$this->config = us_config( 'shortcodes' );
|
||||
|
||||
add_filter( 'the_content', 'us_paragraph_fix' );
|
||||
add_filter( 'us_page_block_the_content', 'us_paragraph_fix', 11 );
|
||||
|
||||
add_filter( 'the_content', array( $this, 'a_to_img_magnific_pupup' ) );
|
||||
add_filter( 'us_page_block_the_content', array( $this, 'a_to_img_magnific_pupup' ) );
|
||||
|
||||
// Make sure that priority makes the class init after WPBakery Page Builder
|
||||
add_action( 'init', array( $this, 'init' ), 20 );
|
||||
|
||||
$this->_template_directory = $us_template_directory;
|
||||
$this->_stylesheet_directory = $us_stylesheet_directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var bool Is the shortcode inited?
|
||||
*/
|
||||
protected $inited = FALSE;
|
||||
|
||||
public function init() {
|
||||
// Adding new shortcodes
|
||||
foreach ( $this->config['theme_elements'] as $element ) {
|
||||
$shortcode = 'us_' . $element;
|
||||
add_shortcode( $shortcode, array( $this, $shortcode ) );
|
||||
}
|
||||
|
||||
// Adding aliases
|
||||
foreach ( $this->config['alias'] as $shortcode => $alias ) {
|
||||
// Overloading the previous declaration if exists
|
||||
if ( shortcode_exists( $shortcode ) ) {
|
||||
remove_shortcode( $shortcode );
|
||||
}
|
||||
add_shortcode( $shortcode, array( $this, $shortcode ) );
|
||||
}
|
||||
|
||||
// Modifying existing shortcodes
|
||||
foreach ( $this->config['modified'] as $shortcode => $shortcode_params ) {
|
||||
// Some shortcodes should not be overloaded
|
||||
if ( isset( $shortcode_params['overload'] ) AND ! $shortcode_params['overload'] ) {
|
||||
continue;
|
||||
}
|
||||
// Overloading the previous declaration if exists
|
||||
if ( shortcode_exists( $shortcode ) ) {
|
||||
remove_shortcode( $shortcode );
|
||||
}
|
||||
add_shortcode( $shortcode, array( $this, $shortcode ) );
|
||||
}
|
||||
|
||||
// Removing disabled shortcodes
|
||||
if ( us_get_option( 'disable_extra_vc', 1 ) == 1 ) {
|
||||
foreach ( $this->config['disabled'] as $shortcode ) {
|
||||
if ( shortcode_exists( $shortcode ) ) {
|
||||
remove_shortcode( $shortcode );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->inited = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling shortcodes
|
||||
*
|
||||
* @param string $shortcode Shortcode name
|
||||
* @param array $args
|
||||
*
|
||||
* @return string Generated shortcode output
|
||||
*
|
||||
*/
|
||||
public function __call( $shortcode, $args ) {
|
||||
$_output = '';
|
||||
$shortcode_base = $shortcode;
|
||||
// Checking wif it is alias and getting real shortcode name
|
||||
if ( isset( $this->config['alias'][ $shortcode ] ) ) {
|
||||
$shortcode = $this->config['alias'][ $shortcode ];
|
||||
}
|
||||
|
||||
// Check if it is theme element or modified shortcode
|
||||
if ( substr( $shortcode, 0, 3 ) == 'us_' ) {
|
||||
$element = substr( $shortcode, 3 );
|
||||
} else {
|
||||
$element = $shortcode;
|
||||
}
|
||||
|
||||
if ( ! in_array( $element, $this->config['theme_elements'] ) AND ! isset( $this->config['modified'][ $element ] ) ) {
|
||||
return $_output;
|
||||
}
|
||||
|
||||
// Preparing params for shortcodes (can be used inside of the input)
|
||||
$atts = isset( $args[0] ) ? $args[0] : array();
|
||||
$content = isset( $args[1] ) ? $args[1] : '';
|
||||
|
||||
// VC's special chars replacement
|
||||
if ( is_array( $atts ) ) {
|
||||
$atts_result = array();
|
||||
foreach ( $atts as $key => $val ) {
|
||||
$atts_result[ $key ] = str_replace(
|
||||
array(
|
||||
'`{`',
|
||||
'`}`',
|
||||
'``',
|
||||
), array(
|
||||
'[',
|
||||
']',
|
||||
'"',
|
||||
), $val
|
||||
);
|
||||
}
|
||||
$atts = $atts_result;
|
||||
}
|
||||
|
||||
// Preserving VC before hook
|
||||
if ( substr( $shortcode_base, 0, 3 ) == 'vc_' AND defined( 'VC_SHORTCODE_BEFORE_CUSTOMIZE_PREFIX' ) ) {
|
||||
$custom_output_before = VC_SHORTCODE_BEFORE_CUSTOMIZE_PREFIX . $shortcode_base;
|
||||
if ( function_exists( $custom_output_before ) ) {
|
||||
$_output .= $custom_output_before( $atts, $content );
|
||||
}
|
||||
unset( $custom_output_before );
|
||||
}
|
||||
|
||||
|
||||
$_filename = $this->_template_directory . '/framework/templates/elements/' . $element . '.php';
|
||||
|
||||
// We are using this context in some element templates
|
||||
$us_elm_context = 'shortcode';
|
||||
|
||||
$filled_atts = us_shortcode_atts( $atts, $shortcode );
|
||||
// Only for theme elements aliases: get params for both base and alias
|
||||
if ( $shortcode_base != $shortcode AND substr( $shortcode, 0, 3 ) == 'us_' ) {
|
||||
$filled_atts_base = us_shortcode_atts( $atts, $shortcode_base );
|
||||
$filled_atts = us_array_merge( $filled_atts, $filled_atts_base );
|
||||
}
|
||||
|
||||
unset( $filled_atts['content'] );
|
||||
extract( $filled_atts );
|
||||
|
||||
ob_start();
|
||||
require $_filename;
|
||||
$_output .= ob_get_clean();
|
||||
|
||||
// Preserving VC after hooks
|
||||
if ( substr( $shortcode_base, 0, 3 ) == 'vc_' ) {
|
||||
if ( defined( 'VC_SHORTCODE_AFTER_CUSTOMIZE_PREFIX' ) ) {
|
||||
$custom_output_after = VC_SHORTCODE_AFTER_CUSTOMIZE_PREFIX . $shortcode_base;
|
||||
if ( function_exists( $custom_output_after ) ) {
|
||||
$_output .= $custom_output_after( $atts, $content );
|
||||
}
|
||||
}
|
||||
$this->_settings = array(
|
||||
'base' => $shortcode_base,
|
||||
);
|
||||
$_output = apply_filters( 'vc_shortcode_output', $_output, $this, isset( $args[0] ) ? $args[0] : array() );
|
||||
}
|
||||
|
||||
return $_output;
|
||||
}
|
||||
|
||||
public function paragraph_fix( $content ) {
|
||||
$array = array(
|
||||
'<p>[' => '[',
|
||||
']</p>' => ']',
|
||||
']<br />' => ']',
|
||||
']<br>' => ']',
|
||||
);
|
||||
|
||||
$content = strtr( $content, $array );
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function a_to_img_magnific_pupup( $content ) {
|
||||
$pattern = "/<a(.*?)href=('|\")([^>]*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
|
||||
$replacement = '<a$1ref="magnificPopup" href=$2$3.$4$5$6>';
|
||||
$content = preg_replace( $pattern, $replacement, $content );
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove some of the shortcodes handlers to use native VC shortcodes instead for front-end compatibility
|
||||
*/
|
||||
public function vc_front_end_compatibility() {
|
||||
if ( WP_DEBUG AND $this->inited ) {
|
||||
wp_die( 'Shortcodes VC front end compatibility should be provided before the shortcodes init' );
|
||||
}
|
||||
unset( $this->config['modified']['vc_tta_tabs'], $this->config['modified']['vc_tta_accordion'], $this->config['modified']['vc_tta_tour'], $this->config['alias']['vc_tta_accordion'], $this->config['alias']['vc_tta_tour'], $this->config['modified']['vc_tta_section'] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
global $us_shortcodes;
|
||||
$us_shortcodes = US_Shortcodes::instance();
|
||||
|
||||
// Add custom options to WP Gallery window
|
||||
add_action( 'print_media_templates', 'us_media_templates' );
|
||||
function us_media_templates() {
|
||||
?>
|
||||
<script type="text/html" id="tmpl-us-custom-gallery-setting">
|
||||
<label class="setting">
|
||||
<span><?php _e( 'Add indents between items', 'us' ) ?></span>
|
||||
<input type="checkbox" data-setting="indents">
|
||||
</label>
|
||||
<label class="setting">
|
||||
<span><?php _e( 'Display as', 'us' ) ?> <?php _e( 'Masonry', 'us' ) ?></span>
|
||||
<input type="checkbox" data-setting="masonry">
|
||||
</label>
|
||||
<label class="setting">
|
||||
<span><?php _e( 'Show image title and description', 'us' ) ?></span>
|
||||
<input type="checkbox" data-setting="meta">
|
||||
</label>
|
||||
</script>
|
||||
<script>
|
||||
jQuery(document).ready(function(){
|
||||
|
||||
// add your shortcode attribute and its default value to the
|
||||
// gallery settings list; $.extend should work as well...
|
||||
_.extend(wp.media.gallery.defaults, {
|
||||
type: 'default_val'
|
||||
});
|
||||
|
||||
// merge default gallery settings template with yours
|
||||
wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({
|
||||
template: function(view){
|
||||
return wp.media.template('gallery-settings')(view)
|
||||
+ wp.media.template('us-custom-gallery-setting')(view);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="tmpl-us-custom-image-setting">
|
||||
<label class="setting" data-setting="us_attachment_link">
|
||||
<span class="name"><?php _e( 'Custom Link', 'us' ); ?></span>
|
||||
<input type="text" value="{{ data.us_attachment_link || '' }}"><?php /* value="{{ data.meta.us_attachment_link || '' }}" */ ?>
|
||||
</label>
|
||||
|
||||
</script>
|
||||
<script>
|
||||
jQuery(document).ready(function(){
|
||||
wp.media.view.Attachment.Details = wp.media.view.Attachment.Details.extend({
|
||||
template: function(view){
|
||||
return wp.media.template('attachment-details')(view).replace('attachment-info">', 'attachment-info">' + wp.media.template('us-custom-image-setting')(view));
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_save-attachment', 'us_ajax_save_attachment', 1 );
|
||||
function us_ajax_save_attachment() {
|
||||
|
||||
if ( ! isset( $_REQUEST['id'] ) || ! isset( $_REQUEST['changes'] ) )
|
||||
wp_send_json_error();
|
||||
|
||||
if ( ! $id = absint( $_REQUEST['id'] ) )
|
||||
wp_send_json_error();
|
||||
|
||||
check_ajax_referer( 'update-post_' . $id, 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'edit_post', $id ) )
|
||||
wp_send_json_error();
|
||||
|
||||
$changes = $_REQUEST['changes'];
|
||||
$post = get_post( $id, ARRAY_A );
|
||||
|
||||
if ( 'attachment' != $post['post_type'] )
|
||||
wp_send_json_error();
|
||||
|
||||
if ( isset( $changes['us_attachment_link'] ) ) {
|
||||
update_post_meta( $post['ID'], 'us_attachment_link', $changes['us_attachment_link'] );
|
||||
}
|
||||
}
|
||||
|
||||
add_filter( 'wp_prepare_attachment_for_js', 'us_prepare_attachment_for_js', 10, 3 );
|
||||
function us_prepare_attachment_for_js( $response, $attachment, $meta ) {
|
||||
$response['us_attachment_link'] = get_post_meta( $attachment->ID, 'us_attachment_link', TRUE );
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Add theme image sizes to WP selector in Gallery options
|
||||
add_filter( 'image_size_names_choose', 'us_image_size_names_choose' );
|
||||
function us_image_size_names_choose( $sizes ) {
|
||||
return us_image_sizes_select_values();
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options: USOF + UpSolution extendings
|
||||
*
|
||||
* Should be included in global context.
|
||||
*/
|
||||
|
||||
add_action( 'usof_after_save', 'us_generate_asset_files' );
|
||||
add_action( 'usof_ajax_mega_menu_save_settings', 'us_generate_asset_files' );
|
||||
add_action( 'update_option_siteurl', 'us_generate_asset_files' );
|
||||
add_action( 'update_option_home', 'us_generate_asset_files' );
|
||||
function us_generate_asset_files() {
|
||||
us_generate_asset_file( 'css' );
|
||||
us_generate_asset_file( 'js' );
|
||||
}
|
||||
|
||||
/* Get asset file path */
|
||||
function us_get_asset_file( $ext, $url = FALSE ) {
|
||||
if ( empty( $ext ) ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Set file name based on site name
|
||||
$site_url_parts = parse_url( site_url() );
|
||||
$file_name = ( ! empty( $site_url_parts['host'] ) ) ? $site_url_parts['host'] : '';
|
||||
$file_name .= ( ! empty( $site_url_parts['path'] ) ) ? str_replace( '/', '_', $site_url_parts['path'] ) : '';
|
||||
|
||||
$file = '';
|
||||
$upload_dir = wp_get_upload_dir();
|
||||
|
||||
if ( $url ) {
|
||||
$file = $upload_dir['baseurl'] . '/us-assets/' . $file_name . '.' . $ext;
|
||||
// remove protocols for better compatibility with caching plugins and services
|
||||
$file = str_replace( array( 'http:', 'https:' ), '', $file );
|
||||
} else {
|
||||
// Create file directory
|
||||
$file_dir = wp_normalize_path( $upload_dir['basedir'] . '/us-assets' );
|
||||
if ( ! is_dir( $file_dir ) ) {
|
||||
wp_mkdir_p( trailingslashit( $file_dir ) );
|
||||
}
|
||||
$file = trailingslashit( $file_dir ) . $file_name . '.' . $ext;
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/* Generate single asset file with specified extension */
|
||||
function us_generate_asset_file( $ext ) {
|
||||
if ( empty( $ext ) ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
global $usof_options, $us_template_directory;
|
||||
usof_load_options_once();
|
||||
|
||||
if ( isset( $usof_options['optimize_assets'] ) AND $usof_options['optimize_assets'] ) {
|
||||
$content = $first_content = '';
|
||||
|
||||
// Add assets specified in Theme Options
|
||||
$assets_config = us_config( 'assets', array() );
|
||||
foreach ( $assets_config as $component => $component_atts ) {
|
||||
if ( isset( $component_atts['apply_if'] ) AND ! $component_atts['apply_if'] ) {
|
||||
continue;
|
||||
}
|
||||
if ( $component == 'lazy-load' AND ! us_get_option( 'lazy_load', 0 ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! isset( $component_atts[ $ext ] ) OR ! $component_atts[ $ext ] ) {
|
||||
continue;
|
||||
}
|
||||
if ( ( isset( $component_atts['hidden'] ) AND $component_atts['hidden'] ) OR ! isset( $usof_options['assets'] ) OR in_array( $component, $usof_options['assets'] ) ) {
|
||||
$asset_filename = $us_template_directory . $component_atts[ $ext ];
|
||||
if ( $ext == 'js' ) {
|
||||
$asset_filename = str_replace( '.js', '.min.js', $asset_filename );
|
||||
}
|
||||
// Move assets with "order" to the top of generated file
|
||||
if ( isset( $component_atts['order'] ) AND $component_atts['order'] == 'top' ) {
|
||||
$first_content .= file_get_contents( $asset_filename );
|
||||
$first_content .= ( $ext == 'js' ) ? ';' : '';
|
||||
} else {
|
||||
$content .= file_get_contents( $asset_filename );
|
||||
$content .= ( $ext == 'js' ) ? ';' : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Combine first content with other
|
||||
$content = $first_content . $content;
|
||||
|
||||
// For CSS
|
||||
if ( $ext == 'css' ) {
|
||||
// add theme-options styles
|
||||
delete_option( 'us_theme_options_css' );
|
||||
$content .= us_get_template( 'config/theme-options.css' );
|
||||
// add responsive styles
|
||||
if ( $usof_options['responsive_layout'] ) {
|
||||
$content .= file_get_contents( $us_template_directory . '/css/responsive.css' );
|
||||
}
|
||||
// add user custom styles
|
||||
if ( ( $us_custom_css = us_get_option( 'custom_css', '' ) ) != '' ) {
|
||||
$content .= $us_custom_css;
|
||||
}
|
||||
// minify
|
||||
$content = us_minify_css( $content );
|
||||
}
|
||||
|
||||
// Break if content is empty
|
||||
if ( empty( $content ) ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Locate asset file
|
||||
$file = us_get_asset_file( $ext );
|
||||
|
||||
// Generate file in directory
|
||||
$handle = @fopen( $file, 'w' );
|
||||
if ( $handle ) {
|
||||
if ( ! fwrite( $handle, $content ) ) {
|
||||
return FALSE;
|
||||
}
|
||||
fclose( $handle );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
} elseif ( $ext == 'css' ) {
|
||||
update_option( 'us_theme_options_css', us_minify_css( us_get_template( 'config/theme-options.css' ) ), TRUE );
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Flushing WP rewrite rules on portfolio slug changes
|
||||
add_action( 'usof_before_save', 'us_maybe_flush_rewrite_rules' );
|
||||
add_action( 'usof_after_save', 'us_maybe_flush_rewrite_rules' );
|
||||
function us_maybe_flush_rewrite_rules( $updated_options ) {
|
||||
// The function is called twice: before and after options change
|
||||
static $old_portfolio_slug = NULL;
|
||||
static $old_portfolio_category_slug = NULL;
|
||||
$flush_rules = FALSE;
|
||||
if ( ! isset( $updated_options['portfolio_slug'] ) ) {
|
||||
$updated_options['portfolio_slug'] = NULL;
|
||||
}
|
||||
if ( ! isset( $updated_options['portfolio_category_slug'] ) ) {
|
||||
$updated_options['portfolio_category_slug'] = NULL;
|
||||
}
|
||||
if ( $old_portfolio_slug === NULL ) {
|
||||
// At first call we're storing the previous portfolio slug
|
||||
$old_portfolio_slug = us_get_option( 'portfolio_slug', 'portfolio' );
|
||||
} elseif ( $old_portfolio_slug != $updated_options['portfolio_slug'] ) {
|
||||
// At second call we're triggering flush rewrite rules at the next app execution
|
||||
// We're using transients to reduce the number of excess auto-loaded options
|
||||
$flush_rules = TRUE;
|
||||
}
|
||||
if ( $old_portfolio_category_slug === NULL ) {
|
||||
// At first call we're storing the previous portfolio slug
|
||||
$old_portfolio_category_slug = us_get_option( 'portfolio_category_slug', 'portfolio_category' );
|
||||
} elseif ( $old_portfolio_slug != $updated_options['portfolio_category_slug'] ) {
|
||||
// At second call we're triggering flush rewrite rules at the next app execution
|
||||
// We're using transients to reduce the number of excess auto-loaded options
|
||||
$flush_rules = TRUE;
|
||||
}
|
||||
|
||||
if ( $flush_rules ) {
|
||||
set_transient( 'us_flush_rules', TRUE, DAY_IN_SECONDS );
|
||||
}
|
||||
}
|
||||
|
||||
// Allow to change Site Icon via Theme Options page
|
||||
add_action( 'usof_after_save', 'us_update_site_icon_from_options' );
|
||||
function us_update_site_icon_from_options( $updated_options ) {
|
||||
$options_site_icon = $updated_options['site_icon'];
|
||||
$wp_site_icon = get_option( 'site_icon' );
|
||||
|
||||
if ( $options_site_icon != $wp_site_icon ) {
|
||||
update_option( 'site_icon', $options_site_icon );
|
||||
}
|
||||
}
|
||||
|
||||
// Get Site Icon to display on Theme Options page
|
||||
add_filter( 'usof_load_options_once', 'us_get_site_icon_for_options' );
|
||||
function us_get_site_icon_for_options( $usof_options ) {
|
||||
$wp_site_icon = get_option( 'site_icon' );
|
||||
|
||||
$usof_options['site_icon'] = $wp_site_icon;
|
||||
|
||||
return $usof_options;
|
||||
}
|
||||
|
||||
// Allow upload woff, woff2 files on Theme Options page
|
||||
add_filter( 'upload_mimes', 'us_mime_types' );
|
||||
function us_mime_types( $mimes ) {
|
||||
$mimes['woff2'] = 'font/woff';
|
||||
$mimes['woff2'] = 'font/woff2';
|
||||
|
||||
return $mimes;
|
||||
}
|
||||
|
||||
// Using USOF for theme options
|
||||
$usof_directory = $us_template_directory . '/framework/vendor/usof';
|
||||
$usof_directory_uri = $us_template_directory_uri . '/framework/vendor/usof';
|
||||
require $us_template_directory . '/framework/vendor/usof/usof.php';
|
||||
|
||||
// Exclude pages that are set as Search results / Posts page / 404 not found
|
||||
add_action( 'pre_get_posts', 'us_exclude_special_pages_from_search' );
|
||||
function us_exclude_special_pages_from_search( $query ) {
|
||||
if ( $query->is_search && $query->is_main_query() ) {
|
||||
$special_pages = array();
|
||||
$special_pages_names = array( 'search_page', 'posts_page', 'page_404' );
|
||||
foreach ( $special_pages_names as $special_page_name ) {
|
||||
$special_page_id = us_get_option( $special_page_name, 'default' );
|
||||
if ( $special_page_id != 'default' AND intval( $special_page_id ) > 0 ) {
|
||||
$special_pages[] = intval( $special_page_id );
|
||||
}
|
||||
}
|
||||
if ( count( $special_pages ) > 0 ) {
|
||||
$post__not_in = $query->get( 'post__not_in' );
|
||||
if ( ! is_array( $post__not_in ) ) {
|
||||
$post__not_in = array();
|
||||
}
|
||||
$post__not_in = array_merge( $post__not_in, $special_pages );
|
||||
$query->set( 'post__not_in', $post__not_in );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Lazy Load
|
||||
if ( us_get_option( 'lazy_load', 1 ) ) {
|
||||
add_filter( 'the_content', 'us_filter_content_for_lazy_load', 99, 1 );
|
||||
}
|
||||
function us_filter_content_for_lazy_load( $content ) {
|
||||
|
||||
// Default image before loading originals
|
||||
$placeholder_url = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
|
||||
|
||||
$matches = $search = $replace = array();
|
||||
preg_match_all( '/<img[\s\r\n]+.*?>/is', $content, $matches );
|
||||
|
||||
// Skip Images Classes
|
||||
$skip_images_classes = array( 'rev-slidebg', 'not-lazy' );
|
||||
$skip_images_regex = sprintf( '/class=".*(%s).*"/s', implode( '|', $skip_images_classes ) );
|
||||
|
||||
$i = 0;
|
||||
foreach ( $matches[0] as $imgHTML ) {
|
||||
// don't to the replacement if a skip class is provided and the image has the class, or if the image is a data-uri
|
||||
if ( ! preg_match( $skip_images_regex, $imgHTML ) AND ! preg_match( "/src=['\"]data:image/is", $imgHTML ) ) {
|
||||
$i ++;
|
||||
// replace the src and add the data-src attribute
|
||||
$replaceHTML = '';
|
||||
$replaceHTML = preg_replace( '/<img(.*?)src=/is', '<img$1src="' . $placeholder_url . '" data-lazy-type="image" data-src=', $imgHTML );
|
||||
$replaceHTML = preg_replace( '/<img(.*?)srcset=/is', '<img$1srcset="" data-srcset=', $replaceHTML );
|
||||
|
||||
// add the lazy class to the img element
|
||||
if ( preg_match( '/class=["\']/i', $replaceHTML ) ) {
|
||||
$replaceHTML = preg_replace( '/class=(["\'])(.*?)["\']/is', 'class=$1lazy lazy-hidden $2$1', $replaceHTML );
|
||||
} else {
|
||||
$replaceHTML = preg_replace( '/<img/is', '<img class="lazy lazy-hidden"', $replaceHTML );
|
||||
}
|
||||
|
||||
array_push( $search, $imgHTML );
|
||||
array_push( $replace, $replaceHTML );
|
||||
}
|
||||
}
|
||||
|
||||
$search = array_unique( $search );
|
||||
$replace = array_unique( $replace );
|
||||
|
||||
$content = str_replace( $search, $replace, $content );
|
||||
|
||||
return $content;
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Adding custom sidebars
|
||||
*/
|
||||
|
||||
class US_Widget_Areas {
|
||||
|
||||
public $widget_areas = array();
|
||||
public $option_name = 'us_widget_areas';
|
||||
|
||||
public function __construct() {
|
||||
|
||||
add_action( 'load-widgets.php', array( &$this, 'load_widgets' ), 5 );
|
||||
add_action( 'widgets_init', array( &$this, 'register_widget_areas' ), 100 );
|
||||
add_action( 'wp_ajax_us_delete_custom_widget_area', array( &$this, 'delete_widget_area' ), 100 );
|
||||
add_action( 'admin_init', array( &$this, 'add_missing_posts' ), 10 );
|
||||
}
|
||||
|
||||
public function load_widgets() {
|
||||
|
||||
add_action( 'admin_print_scripts', array( &$this, 'template_add_widget_area' ) );
|
||||
add_action( 'load-widgets.php', array( &$this, 'add_widget_area' ), 100 );
|
||||
|
||||
global $us_template_directory_uri;
|
||||
wp_enqueue_script( 'us_widget_areas', $us_template_directory_uri . '/framework/admin/js/widget_areas.js' );
|
||||
}
|
||||
|
||||
public function template_add_widget_area() {
|
||||
$nonce = wp_create_nonce( 'us_delete_widget_area_nonce' );
|
||||
$nonce = '<input type="hidden" name="us_delete_widget_area_nonce" value="' . $nonce . '" />';
|
||||
|
||||
?>
|
||||
<div id="us_add_widget_area" style="display: none;">
|
||||
<form method="POST" class="us-custom-area-form widgets-holder-wrap">
|
||||
<input type="text" value="" placeholder="<?php _e( 'Sidebar Name', 'us' ) ?>" name="us_widget_area" />
|
||||
<input class="button button-primary" type="submit" value="<?php _e( 'Add Sidebar', 'us' ) ?>" />
|
||||
<?php echo $nonce; ?>
|
||||
</form>
|
||||
<span id="us_confirm_widget_area_deletion" style="display: none;"><?php _e( 'Do you really want to delete this sidebar?', 'us' ); ?></span>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function add_widget_area() {
|
||||
if ( ! empty( $_POST['us_widget_area'] ) ) {
|
||||
|
||||
$this->widget_areas = get_option( $this->option_name );
|
||||
$name = $this->get_name( trim( $_POST['us_widget_area'] ) );
|
||||
$id = $this->name_to_id( $name );
|
||||
|
||||
if ( empty( $this->widget_areas ) ) {
|
||||
$this->widget_areas = array( $id => $name );
|
||||
} else {
|
||||
$this->widget_areas = array_merge( $this->widget_areas, array( $id => $name ) );
|
||||
}
|
||||
|
||||
// New post to represent Widget Area in menu
|
||||
wp_insert_post( array(
|
||||
'post_type' => 'us_widget_area',
|
||||
'post_date' => date( 'Y-m-d H:i', time() - 86400 ),
|
||||
'post_name' => $id,
|
||||
'post_title' => $name,
|
||||
'post_status' => 'publish',
|
||||
) );
|
||||
|
||||
update_option( $this->option_name, $this->widget_areas );
|
||||
wp_redirect( admin_url( 'widgets.php' ) );
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public function delete_widget_area() {
|
||||
check_ajax_referer( 'us_delete_widget_area_nonce' );
|
||||
|
||||
if ( ! empty( $_POST['name'] ) ) {
|
||||
$name = stripslashes( $_POST['name'] );
|
||||
$this->widget_areas = get_option( $this->option_name );
|
||||
|
||||
if ( ( $id = array_search( $name, $this->widget_areas ) ) !== FALSE ) {
|
||||
$widget_area_post = get_page_by_path( $id, OBJECT, 'us_widget_area' );
|
||||
if ( $widget_area_post ) {
|
||||
wp_delete_post( $widget_area_post->ID );
|
||||
}
|
||||
unset( $this->widget_areas[$id] );
|
||||
update_option( $this->option_name, $this->widget_areas );
|
||||
echo "success";
|
||||
}
|
||||
}
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
public function get_name( $name ) {
|
||||
if ( empty( $GLOBALS['wp_registered_sidebars'] ) ) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
$taken = array();
|
||||
foreach ( $GLOBALS['wp_registered_sidebars'] as $widget_area ) {
|
||||
$taken[] = $widget_area['name'];
|
||||
}
|
||||
|
||||
if ( empty( $this->widget_areas ) ) {
|
||||
$this->widget_areas = array();
|
||||
}
|
||||
$taken = array_merge( array( $taken ), $this->widget_areas );
|
||||
|
||||
if ( in_array( $name, $taken ) ) {
|
||||
$counter = substr( $name, - 1 );
|
||||
|
||||
if ( ! is_numeric( $counter ) ) {
|
||||
$new_name = $name . " 1";
|
||||
} else {
|
||||
$new_name = substr( $name, 0, - 1 ) . ( (int) $counter + 1 );
|
||||
}
|
||||
|
||||
$name = $this->get_name( $new_name );
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
public function register_widget_areas() {
|
||||
if ( empty( $this->widget_areas ) ) {
|
||||
$this->widget_areas = get_option( $this->option_name );
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'description' => __( 'Custom Sidebar', 'us' ),
|
||||
'before_widget' => '<div id="%1$s" class="widget %2$s">',
|
||||
'after_widget' => '</div>',
|
||||
'before_title' => '<h3 class="widgettitle">',
|
||||
'after_title' => '</h3>',
|
||||
'class' => 'us-custom-area',
|
||||
);
|
||||
|
||||
if ( is_array( $this->widget_areas ) ) {
|
||||
foreach ( $this->widget_areas as $id => $name ) {
|
||||
$args['name'] = $name;
|
||||
$args['id'] = $id;
|
||||
register_sidebar( $args );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function add_missing_posts() {
|
||||
global $pagenow;
|
||||
if ( is_admin() AND $pagenow == 'nav-menus.php' ) {
|
||||
if ( empty( $this->widget_areas ) ) {
|
||||
$this->widget_areas = get_option( $this->option_name );
|
||||
}
|
||||
|
||||
if ( is_array( $this->widget_areas ) ) {
|
||||
foreach ( $this->widget_areas as $id => $name ) {
|
||||
if ( get_page_by_path( $id, OBJECT, 'us_widget_area' ) == NULL ) {
|
||||
wp_insert_post( array(
|
||||
'post_type' => 'us_widget_area',
|
||||
'post_date' => date( 'Y-m-d H:i', time() - 86400 ),
|
||||
'post_name' => $id,
|
||||
'post_title' => $name,
|
||||
'post_status' => 'publish',
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function name_to_id( $name ) {
|
||||
$name = strtolower( $name );
|
||||
|
||||
$trans = array(
|
||||
'&\S+?;' => '',
|
||||
'\s+' => '_',
|
||||
'ä' => 'ae',
|
||||
'ö' => 'oe',
|
||||
'ü' => 'ue',
|
||||
'Ä' => 'Ae',
|
||||
'Ö' => 'Oe',
|
||||
'Ü' => 'Ue',
|
||||
'ß' => 'ss',
|
||||
'[^a-z0-9\-\._]' => '',
|
||||
'-+' => '-',
|
||||
'-$' => '-',
|
||||
'^-' => '-',
|
||||
'\.+$' => '',
|
||||
'_+' => '_',
|
||||
'^_$' => '',
|
||||
);
|
||||
|
||||
$name = strip_tags( $name );
|
||||
|
||||
foreach ( $trans as $key => $val ) {
|
||||
$name = preg_replace( "#" . $key . "#i", $val, $name );
|
||||
}
|
||||
|
||||
if ( $name == '' ) {
|
||||
$name = 'us_widget_area_' . rand( 99999, 999999 );
|
||||
} else {
|
||||
$name = 'us_widget_area_' . $name;
|
||||
}
|
||||
|
||||
return stripslashes( $name );
|
||||
}
|
||||
}
|
||||
|
||||
new US_Widget_Areas();
|
||||
|
||||
// Add Sidebars from config
|
||||
add_action( 'widgets_init', 'us_register_sidebars' );
|
||||
function us_register_sidebars() {
|
||||
$config = us_config( 'sidebars' );
|
||||
foreach ( $config as $sidebar ) {
|
||||
register_sidebar( $sidebar );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
abstract class US_Widget extends WP_Widget {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
// Widget name may be set either from overloading class attribute ...
|
||||
$id_base = $this->id_base;
|
||||
if ( empty( $id_base ) ) {
|
||||
// ... or fetched from the US_Widget_<name> part
|
||||
$id_base = preg_replace( '/(wp_)?widget_/', '', strtolower( get_class( $this ) ) );
|
||||
}
|
||||
|
||||
$this->config = us_config( 'widgets.' . $id_base );
|
||||
if ( $this->config === NULL ) {
|
||||
wp_die( 'Wrong UpSolution widget definition: id_base should be set by attribute or by class name' );
|
||||
}
|
||||
|
||||
parent::__construct(
|
||||
$id_base, $this->config['name'], array(
|
||||
'description' => $this->config['description'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common widgets' jobs
|
||||
*
|
||||
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
|
||||
* @param array $instance The settings for the particular instance of the widget.
|
||||
*/
|
||||
public function before_widget( &$args, &$instance ) {
|
||||
if ( isset( $this->config['params'] ) AND is_array( $this->config['params'] ) ) {
|
||||
foreach ( $this->config['params'] as $param_name => $param ) {
|
||||
if ( ! isset( $instance[$param_name] ) ) {
|
||||
$instance[$param_name] = isset( $param['std'] ) ? $param['std'] : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$instance['title'] = ( isset( $instance['title'] ) AND ! empty( $instance['title'] ) ) ? $instance['title'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings update form.
|
||||
*
|
||||
* @param array $instance Current settings.
|
||||
*
|
||||
* @return string Form's output marker that could be used for further hooks
|
||||
*/
|
||||
public function form( $instance ) {
|
||||
if ( ! isset( $this->config['params'] ) OR ! is_array( $this->config['params'] ) OR empty( $this->config['params'] ) ) {
|
||||
// 'noform'
|
||||
return parent::form( $instance );
|
||||
}
|
||||
|
||||
foreach ( $this->config['params'] as $param_name => $param ) {
|
||||
if ( ! isset( $param['type'] ) ) {
|
||||
$param['type'] = 'textfield';
|
||||
}
|
||||
if ( ! method_exists( $this, 'form_' . $param['type'] ) ) {
|
||||
continue;
|
||||
}
|
||||
$param['name'] = isset( $param['name'] ) ? $param['name'] : $param_name;
|
||||
$param['std'] = isset( $param['std'] ) ? $param['std'] : '';
|
||||
$value = isset( $instance[$param_name] ) ? $instance[$param_name] : $param['std'];
|
||||
$this->{'form_' . $param['type']}( $param, $value );
|
||||
}
|
||||
|
||||
return 'usform';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output form's textfield element
|
||||
*
|
||||
* @param array $param Parameter from config
|
||||
* @param string $value Current value
|
||||
*/
|
||||
public function form_textfield( $param, $value ) {
|
||||
$param['heading'] = isset( $param['heading'] ) ? $param['heading'] : $param['name'];
|
||||
$field_id = $this->get_field_id( $param['name'] );
|
||||
$output = '<p>';
|
||||
$output .= '<label for="' . esc_attr( $field_id ) . '">' . $param['heading'] . ':</label>';
|
||||
$output .= '<input class="widefat" id="' . esc_attr( $field_id ) . '" ';
|
||||
$output .= 'name="' . esc_attr( $this->get_field_name( $param['name'] ) ) . '" type="text" value="' . esc_attr( $value ) . '" />';
|
||||
$output .= '</p>';
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output form's dropdown element
|
||||
*
|
||||
* @param array $param Parameter from config
|
||||
* @param string $value Current value
|
||||
*/
|
||||
public function form_dropdown( $param, $value ) {
|
||||
$param['heading'] = isset( $param['heading'] ) ? $param['heading'] : $param['name'];
|
||||
$field_id = $this->get_field_id( $param['name'] );
|
||||
$output = '<p><label for="' . esc_attr( $field_id ) . '">' . $param['heading'] . ':</label>';
|
||||
$output .= '<select name="' . esc_attr( $this->get_field_name( $param['name'] ) ) . '" id="' . esc_attr( $field_id ) . '" class="widefat">';
|
||||
if ( isset( $param['value'] ) AND is_array( $param['value'] ) ) {
|
||||
$is_first_optgroup = TRUE;
|
||||
foreach ( $param['value'] as $key => $option ) {
|
||||
if ( is_array( $option ) AND isset( $option['optgroup'] ) AND $option['optgroup'] ) {
|
||||
if ( ! $is_first_optgroup ) {
|
||||
$output .= '</optgroup>';
|
||||
}
|
||||
$output .= '<optgroup label="' . esc_attr( $option['title'] ) . '">';
|
||||
$is_first_optgroup = FALSE;
|
||||
|
||||
} else {
|
||||
$output .= '<option value="' . esc_attr( $key ) . '"' . selected( $value, $key, FALSE ) . '>' . $option . '</option>';
|
||||
}
|
||||
}
|
||||
if ( ! $is_first_optgroup ) {
|
||||
$output .= '</optgroup>';
|
||||
}
|
||||
}
|
||||
$output .= '</select></p>';
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output form's checkbox element
|
||||
*
|
||||
* @param array $param Parameter from config
|
||||
* @param string $value Current value
|
||||
*/
|
||||
public function form_checkbox( $param, $value ) {
|
||||
$output = '<p>';
|
||||
if ( $param['heading'] ) {
|
||||
$output .= '<span>' . $param['heading'] . ':</span><br>';
|
||||
}
|
||||
if ( isset( $param['value'] ) AND is_array( $param['value'] ) ) {
|
||||
foreach ( $param['value'] as $value_title => $value_key ) {
|
||||
$name = $param['name'] . '-' . esc_attr( $value_key );
|
||||
$checked = ( is_array( $value ) AND in_array( $value_key, $value ) ) ? ' checked="checked"' : '';
|
||||
$output .= '<label><input name="' . esc_attr( $this->get_field_name( $param['name'] ) ) . '[]" type="checkbox" value="' . esc_attr( $value_key ) . '"' . $checked . '>' . $value_title . '</label><br>';
|
||||
}
|
||||
}
|
||||
$output .= '</p>';
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output form's textarea element
|
||||
*
|
||||
* @param array $param Parameter from config
|
||||
* @param string $value Current value
|
||||
*/
|
||||
public function form_textarea( $param, $value ) {
|
||||
$param['heading'] = isset( $param['heading'] ) ? $param['heading'] : $param['name'];
|
||||
$field_id = $this->get_field_id( $param['name'] );
|
||||
$output = '<p>';
|
||||
$output .= '<label for="' . esc_attr( $field_id ) . '">' . $param['heading'] . ':</label>';
|
||||
$output .= '<textarea class="widefat" rows="5" cols="20" id="' . esc_attr( $field_id ) . '" ';
|
||||
$output .= 'name="' . esc_attr( $this->get_field_name( $param['name'] ) ) . '" style="height: 47px;">' . esc_textarea( $value ) . '</textarea>';
|
||||
$output .= '</p>';
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
add_action( 'widgets_init', 'us_widgets_init' );
|
||||
function us_widgets_init() {
|
||||
$config = us_config( 'widgets', array() );
|
||||
|
||||
if ( us_get_option( 'enable_portfolio', 1 ) == 0 ) {
|
||||
unset( $config['us_portfolio'] );
|
||||
}
|
||||
|
||||
foreach ( $config as $widget_id => $widget ) {
|
||||
if ( ! isset( $widget['class'] ) ) {
|
||||
wp_die( 'Widget class should be defined for ' . $widget_id );
|
||||
}
|
||||
if ( ! class_exists( $widget['class'] ) ) {
|
||||
$filepath = us_locate_file( 'widgets/' . $widget_id . '.php' );
|
||||
if ( $filepath === FALSE ) {
|
||||
continue;
|
||||
}
|
||||
include $filepath;
|
||||
if ( ! class_exists( $widget['class'] ) ) {
|
||||
wp_die( 'Widget class ' . $widget['class'] . ' is not found at ' . $filepath );
|
||||
}
|
||||
}
|
||||
register_widget( $widget['class'] );
|
||||
}
|
||||
|
||||
//override WP gallery
|
||||
if ( class_exists( 'WP_Widget_Media_Gallery' ) ) {
|
||||
$filepath = us_locate_file( 'widgets/us_gallery.php' );
|
||||
include $filepath;
|
||||
unregister_widget( 'WP_Widget_Media_Gallery' );
|
||||
register_widget( 'US_Widget_Media_Gallery' );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user