true,
'topost' => $post_id,
'medialib' => true,
'fields' => $meta_box['name']
);
?>
';
echo $out;
}
/**
* Generates checkbox field
*
* @param array $args Field settings
*
* @since 1.3.2
* @return string
*/
function themify_meta_field_checkbox( $args ) {
$meta_box = $args['meta_box'];
$meta_value = $args['meta_value'];
extract($args, EXTR_OVERWRITE);
$checked = $meta_value || ( isset( $meta_box['default'] ) && 'checked' === $meta_box['default'] && 'auto-draft' === get_post_status() ) ? 'checked="checked"' : '';
$html = sprintf('
',
esc_attr( $meta_box['name'] ), esc_attr( $meta_box['name'] ), $checked, esc_attr( $meta_box['name'] ).'-toggle-control', esc_attr( $meta_box['name'] ));
if ( isset( $meta_box['label'] ) && '' != $meta_box['label'] ) {
$html = sprintf( '
%s %s ', esc_attr( $meta_box['name'] ), $html, esc_attr( $meta_box['label'] ) );
}
if ( isset( $meta_box['description'] ) ) {
$html .= themify_meta_field_get_description( $meta_box['description'] );
}
if( isset( $meta_box['before'] ) && $meta_box['before'] ) $html = $meta_box['before'] . $html;
if( isset( $meta_box['after'] ) && $meta_box['after'] ) $html .= $meta_box['after'];
echo $html;
}
/**
* Generates text field
*
* @param array $args Field settings
*
* @since 1.3.2
* @return string
*/
function themify_meta_field_textbox( $args ) {
$meta_box = $args['meta_box'];
$meta_value = $args['meta_value'];
extract($args, EXTR_OVERWRITE);
if( isset( $meta_box['default'] ) && empty( $meta_value ) && ! ( $meta_value === 0 || $meta_value === '0' ) ) {
$meta_value = $meta_box['default'];
}
if ( isset( $meta_box['meta']['size'] ) && '' != $meta_box['meta']['size'] ) {
$class = $meta_box['meta']['size'];
} else {
$class = '';
}
$html = sprintf('
',
esc_attr( $meta_box['name'] ), esc_attr( $meta_box['name'] ), esc_attr( $meta_value ), $class);
if ( isset( $meta_box['label'] ) && '' != $meta_box['label'] ) {
$html = themify_meta_field_get_label($html, $meta_box);
}
if ( isset( $meta_box['description'] ) ) {
$html .= themify_meta_field_get_description( $meta_box['description'] );
}
if( isset( $meta_box['before'] ) && $meta_box['before'] ) $html = $meta_box['before'] . $html;
if( isset( $meta_box['after'] ) && $meta_box['after'] ) $html .= $meta_box['after'];
echo $html;
}
/**
* Generates textarea field
*
* @param array $args Field settings
*
* @since 1.3.2
* @return string
*/
function themify_meta_field_textarea( $args ) {
extract( $args, EXTR_OVERWRITE );
$meta_box = wp_parse_args( $meta_box, array(
'size' => 55,
'rows' => 4,
'class' => '',
'attr' => '',
) );
$meta_value = $args['meta_value'];
$html = sprintf( '
',
esc_attr( $meta_box['name'] ), esc_attr( $meta_box['name'] ), $meta_box['size'], $meta_box['rows'], $meta_box['class'], $meta_box['attr'], esc_textarea( $meta_value ) );
$html = themify_meta_field_get_label($html, $meta_box);
if ( isset( $meta_box['description'] ) ) {
$html .= themify_meta_field_get_description( $meta_box['description'] );
}
if( isset( $meta_box['before'] ) && $meta_box['before'] ) $html = $meta_box['before'] . $html;
if( isset( $meta_box['after'] ) && $meta_box['after'] ) $html .= $meta_box['after'];
echo $html;
}
function themify_meta_field_video( $args ) {
global $post;
$meta_box = $args['meta_box'];
$meta_value = $args['meta_value'];
extract($args, EXTR_OVERWRITE);
ob_start();
/** Parameters for the uploader @var Array */
$featimg_uploader_args = array(
'tomedia' => true,
'topost' => $post_id,
'medialib' => true,
'fields' => $meta_box['name'],
'formats' => 'mp4,m4v,webm,ogv,wmv,flv',
'type' => 'video',
);
?>
';
echo $html;
}
/**
* Returns label before or after field
* @param string $html field markup
* @param array $meta_box field definition in key => value format
* @param bool $echo Whether to echo or return the field
* @return string field markup with label
* @since 1.3.2
*/
function themify_meta_field_get_label( $html, $meta_box, $echo = false ) {
$label_for = ( isset( $meta_box['name'] ) && '' != $meta_box['name'] ) ? esc_attr( $meta_box['name'] ) : '';
if ( isset( $meta_box['label'] ) && '' != $meta_box['label'] ) {
if ( isset( $meta_box['label_before'] ) && $meta_box['label_before'] ) {
$html = sprintf( '
%s %s ', $label_for, wp_kses_post( $meta_box['label'] ), $html );
} else {
$html = sprintf( '
%s %s ', $label_for, $html, wp_kses_post( $meta_box['label'] ) );
}
}
if ( $echo ) echo $html;
return $html;
}
/**
* Renders description for meta fields.
*
* @uses wp_kses_post()
*
* @param string $desc
*
* @return string
*/
function themify_meta_field_get_description( $desc = '' ) {
return ( isset( $desc ) && '' != $desc ) ? '
' . wp_kses_post( $desc ) . ' ' : '';
}
function themify_ajax_create_page_pagination() {
if ( ! current_user_can( 'edit_posts' ) ) {
die;
}
$current_page = isset( $_POST['current_page'] ) ? (int) $_POST['current_page'] : 1;
$num_of_pages = isset( $_POST['num_of_pages'] ) ? (int) $_POST['num_of_pages'] : 0;
echo themify_create_page_pagination($current_page, $num_of_pages);
die;
}
/**
* Render pagination for specific page.
*
* @param Integer $current_page The current page that needs to be rendered.
* @param Integer $num_of_pages The number of all pages.
*
* @return String The HTML with pagination.
*/
function themify_create_page_pagination( $current_page, $num_of_pages ) {
$links_in_the_middle = 4;
$links_in_the_middle_min_1 = $links_in_the_middle - 1;
$first_link_in_the_middle = $current_page - floor( $links_in_the_middle_min_1 / 2 );
$last_link_in_the_middle = $current_page + ceil( $links_in_the_middle_min_1 / 2 );
if ( $first_link_in_the_middle <= 0 ) {
$first_link_in_the_middle = 1;
}
if ( ( $last_link_in_the_middle - $first_link_in_the_middle ) != $links_in_the_middle_min_1 ) {
$last_link_in_the_middle = $first_link_in_the_middle + $links_in_the_middle_min_1;
}
if ( $last_link_in_the_middle > $num_of_pages ) {
$first_link_in_the_middle = $num_of_pages - $links_in_the_middle_min_1;
$last_link_in_the_middle = (int) $num_of_pages;
}
if ( $first_link_in_the_middle <= 0 ) {
$first_link_in_the_middle = 1;
}
$pagination = '';
if ( $current_page != 1 ) {
$pagination .= '
';
}
if ( $first_link_in_the_middle >= 3 && $links_in_the_middle < $num_of_pages ) {
$pagination .= '
1 ... ';
}
for ( $i = $first_link_in_the_middle; $i <= $last_link_in_the_middle; $i ++ ) {
if ( $i == $current_page ) {
$pagination .= '
' . $i . ' ';
} else {
$pagination .= '
' . $i . ' ';
}
}
if ( $last_link_in_the_middle < $num_of_pages ) {
if ( $last_link_in_the_middle != ( $num_of_pages - 1 ) ) {
$pagination .= '
... ';
}
$pagination .= '
' . $num_of_pages . ' ';
}
if ( $current_page != $last_link_in_the_middle ) {
$pagination .= '
';
}
return $pagination;
}
function themify_ajax_create_inner_page() {
if ( ! current_user_can( 'edit_posts' ) ) {
die;
}
$selected = array();
if ( isset( $_POST['post_id'] ) ) {
$post_id = (int) $_POST['post_id'];
$selected = get_post_meta( $post_id, 'popup_show', TRUE );
}
$type= isset( $_POST['type'] ) ? sanitize_text_field( $_POST['type'] ) : 'pages';
echo themify_create_inner_page($type, $selected);
die;
}
/**
* Renders pages, posts types and categories items based on current page.
*
* @param string $type The type of items to render.
* @param array $selected The array of all selected options.
*
* @return string The HTML to render items as HTML.
*/
function themify_create_inner_page( $type, $selected ) {
$posts_per_page = 26;
$output = '';
switch ($type) {
case 'page':
$key = 'page';
$posts = get_posts( array( 'post_type' => $key, 'posts_per_page' => -1, 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'title', 'no_found_rows' => true,'ignore_sticky_posts'=>true) );
if( ! empty( $posts ) ) {
$i = 1;
$page_id = 1;
$num_of_single_pages = count($posts);
$num_of_pages = (int) ceil( $num_of_single_pages / $posts_per_page );
$output .= '
';
$output .= '
';
foreach ( $posts as $post ) :
if ( $post->post_parent > 0 ) {
$post->post_name = str_replace( home_url(), '', get_permalink( $post->ID ) );
}
$checked = isset( $selected['post_type'][ $key ][ $post->post_name ] ) ? checked( $selected['post_type'][ $key ][ $post->post_name ], 'on', false ) : '';
/* note: slugs are more reliable than IDs, they stay unique after export/import */
$output .= ' ' . $post->post_title . ' ';
if ( $i === ($page_id * $posts_per_page) ) {
$output .= '
';
$page_id++;
$output .= '
';
}
$i++;
endforeach;
$output .= '
';
if ( $num_of_pages > 1 ) {
$output .= '';
}
$output .= '
';
}
break;
case 'category_single':
$key = 'category_single';
$terms = get_terms( array('taxonomy'=>'category', 'hide_empty' => true ) );
if ( ! empty( $terms ) ) {
$i = 1;
$page_id = 1;
$num_of_single_pages = count( $terms );
$num_of_pages = (int) ceil( $num_of_single_pages / $posts_per_page );
$output .= '
';
$output .= '
';
foreach ( $terms as $term ) :
$checked = isset( $selected['tax'][ $key ][ $term->slug ] ) ? checked( $selected['tax'][ $key ][ $term->slug ], 'on', false ) : '';
$output .= ' ' . $term->name . ' ';
if ( $i === ( $page_id * $posts_per_page ) ) {
$output .= '
';
$page_id ++;
$output .= '
';
}
$i++;
endforeach;
$output .= '
';
if ( $num_of_pages > 1 ) {
$output .= '';
}
$output .= '
';
}
break;
case 'category':
$key = 'category';
$terms = get_terms( array('taxonomy'=>'category', 'hide_empty' => true ) );
if ( ! empty( $terms ) ) {
$i = 1;
$page_id = 1;
$num_of_single_pages = count( $terms );
$num_of_pages = (int) ceil( $num_of_single_pages / $posts_per_page );
$output .= '
';
$output .= '
';
foreach ( $terms as $term ) :
$checked = isset( $selected['tax'][ $key ][ $term->slug ] ) ? checked( $selected['tax'][ $key ][ $term->slug ], 'on', false ) : '';
$output .= ' ' . $term->name . ' ';
if ( $i === ( $page_id * $posts_per_page ) ) {
$output .= '
';
$page_id ++;
$output .= '
';
}
$i++;
endforeach;
$output .= '
';
if ( $num_of_pages > 1 ) {
$output .= '';
}
$output .= '
';
}
break;
default :
$post_types = get_post_types( array( 'public' => true ) );
unset( $post_types['page'] );
$post_types = array_map( 'get_post_type_object', $post_types );
$post_id = 1;
foreach ( $post_types as $key => $post_type ) {
$output .= '
';
$post_id++;
}
$output .= '';
break;
}
wp_reset_postdata();
return $output;
}
function themify_meta_field_assignments( $args ) {
extract( $args );
$field = $meta_box;
$pre = $field['name'];
$selected = $meta_value;
if( '' == $selected )
$selected = array();
$post_types = apply_filters( 'themify_assignments_post_types', get_post_types( array( 'public' => true ) ) );
unset( $post_types['page'] );
unset( $post_types['attachment'] );
if( isset( $field['exclude_post_types'] ) ) {
foreach( $field['exclude_post_types'] as $type ) {
unset( $post_types[$type] );
}
}
$post_types = array_map( 'get_post_type_object', $post_types );
$taxonomies = apply_filters( 'themify_assignments_taxonomies', get_taxonomies( array( 'public' => true ) ) );
unset( $taxonomies['category'] );
if( isset( $field['exclude_taxonomies'] ) ) {
foreach( $field['exclude_taxonomies'] as $tax ) {
unset( $taxonomies[$tax] );
}
}
$taxonomies = array_map( 'get_taxonomy', $taxonomies );
$output = '';
/* build the tab items */
$output .= '
';
$checked = isset($selected['general']['home']) ? checked($selected['general']['home'], 'on', false) : '';
$output .= ' ' . __( 'Home page', 'themify' ) . ' ';
$checked = isset($selected['general']['page']) ? checked($selected['general']['page'], 'on', false) : '';
$output .= ' ' . __( 'Page views', 'themify' ) . ' ';
$checked = isset($selected['general']['single']) ? checked($selected['general']['single'], 'on', false) : '';
$output .= ' ' . __( 'Single post views', 'themify' ) . ' ';
$checked = isset($selected['general']['search']) ? checked($selected['general']['search'], 'on', false) : '';
$output .= ' ' . __( 'Search pages', 'themify' ) . ' ';
$checked = isset($selected['general']['category']) ? checked($selected['general']['category'], 'on', false) : '';
$output .= ' ' . __( 'Category archive', 'themify' ) . ' ';
$checked = isset($selected['general']['tag']) ? checked($selected['general']['tag'], 'on', false) : '';
$output .= ' ' . __( 'Tag archive', 'themify' ) . ' ';
$checked = isset($selected['general']['author']) ? checked($selected['general']['author'], 'on', false) : '';
$output .= ' ' . __( 'Author pages', 'themify' ) . ' ';
/* General views for CPT */
foreach ( get_post_types( array( 'public' => true, 'exclude_from_search' => false, '_builtin' => false ) ) as $key => $post_type ) {
$post_type = get_post_type_object( $key );
$checked = isset( $selected['general'][$key] ) ? checked( $selected['general'][$key], 'on', false ) : '';
$output .= ' ' . sprintf( __( 'Single %s View', 'themify' ), $post_type->labels->singular_name ) . ' ';
}
/* Custom taxonomies archive view */
foreach ( get_taxonomies( array( 'public' => true, '_builtin' => false ) ) as $key => $tax ) {
$tax = get_taxonomy( $key );
$checked = isset( $selected['general'][$key] ) ? checked( $selected['general'][$key], 'on', false ) : '';
$output .= ' ' . sprintf( __( '%s Archive View', 'themify' ), $tax->labels->singular_name ) . ' ';
}
$output .= '
'; // tab-general
// Pages tab
wp_reset_postdata();
$output .= '
';
$output .= '
'; // tab-pages
// Category Singles tab
$output .= '
';
$output .= '
';
// Categories tab
$output .= '
';
$output .= '
'; // tab-categories
// Post types tab
$output .= '
';
$output .= '
';
$output .= '
';
$output .= '
';
$output .= '
';
$output .= '
'; // tab-post-types
// Taxonomies tab
$output .= '
';
$output .= '
';
$output .= '
';
foreach ( $taxonomies as $key => $tax ) {
$output .= '
';
$terms = get_terms( array('taxonomy'=>$key, 'hide_empty' => true ) );
if ( ! empty( $terms ) ) : foreach ( $terms as $term ) :
$checked = isset( $selected['tax'][$key][$term->slug] ) ? checked( $selected['tax'][$key][$term->slug], 'on', false ) : '';
$output .= ' ' . esc_html( $term->name ) . ' ';
endforeach;
endif;
$output .= '
';
}
$output .= '
';
$output .= '
'; // tab-taxonomies
// User Roles tab
$output .= '
';
foreach ( $GLOBALS['wp_roles']->roles as $key => $role ) {
$checked = isset( $selected['roles'][$key] ) ? checked( $selected['roles'][$key], 'on', false ) : '';
$output .= ' ' . esc_html( $role['name'] ) . ' ';
}
$output .= '
'; // tab-userroles
$output .= '
';
$output .= themify_array_to_input( $selected, $pre );
$output .= '
';
$output .= '
';
echo $output;
}
/**
* Returns a PLUPLOAD instance. If it's a multisite, checks user quota and shows message if it's not enough to continue upload files.
*
* @param string $id
* @param array $params $label = '', $thumbs = false, $filelist = false, $multiple = false, $message = '', $fallback = ''
*
* @return string
*/
function themify_get_uploader( $id = '', $args = array() ){
$defaults = array(
'label' => __('Upload', 'themify'),
'preset' => false,
'preview' => false,
'tomedia' => false,
'topost' => '',
'fields' => '',
'featured' => '',
'message' => '',
'fallback' => '',
'dragfiles' => false,
'confirm' => '',
'medialib' => false,
'formats' => 'jpg,jpeg,gif,png,ico,zip,txt,svg',
'type' => 'image',
'action' => 'themify_plupload',
'button_class' => '',
);
// Extract $label, $preset, $thumbs, $filelist, $multiple, $message, $fallback, $confirm
$args = wp_parse_args($args, $defaults);
$upload_visible = false;
if ( is_multisite() && !is_upload_space_available() ) {
if( '' != $args['message'] ){
$html = $args['message'];
} else {
$html = '';
if( isset( $meta_value ) && is_array( $meta_value ) ) {
foreach( $meta_value as $id => $values ) {
themify_meta_field_repeater_template( $meta_box, $values, $id );
}
}
echo '
';
$label = isset( $meta_box['add_new_label'] ) ? $meta_box['add_new_label'] : __( 'Add New', 'themify' );
echo '