true, 'topost' => $post_id, 'medialib' => true, 'fields' => $meta_box['name'] ); ?>
' . esc_attr__( 'Post Image', 'themify' ) . ' '; } else { echo '
'; } ?>
true, 'topost' => $post_id, 'medialib' => true, 'fields' => $sanitized_name, 'formats' => $meta_box['ext'], 'type' => 'font', ); $remove_data = array( 'postid' => esc_js( $post_id ), 'customfield' => esc_js( $meta_box['name'] ), 'nonce' => esc_js( $themify_custom_panel_nonce ) ); ?>
true, 'topost' => $post_id, 'medialib' => true, 'fields' => $sanitized_name, 'formats' => 'mp3,m4a,ogg,wav,wma', 'type' => 'audio', ); $remove_data = array( 'postid' => esc_js( $post_id ), 'customfield' => esc_js( $meta_box['name'] ), 'nonce' => esc_js( $themify_custom_panel_nonce ) ); ?>
$name){ $metakey = $meta_box['name'].'_'.$meta; $meta_class = 'all' != $meta? 'meta-sub meta-'.$meta : 'meta-all'; echo ' '; } ?>
', $required, esc_attr( $meta_box['name'] ), esc_attr( $meta_box['name'] ), esc_attr( $meta_value? $meta_value : $default ), 'clear-'.esc_attr( $meta_box['name'] ), esc_attr( $pick ), esc_attr( $close ), esc_attr( $date_format ), esc_attr( $time_format ), esc_attr( $timeseparator ), get_option( 'start_of_week', '0' ), 'clear-'.esc_attr( $meta_box['name'] ), esc_attr( $meta_box['name'] ), esc_attr( $clear ), $meta_value? 'themifyFadeIn' : '' ); if(isset($meta_box['label']) && '' != $meta_box['label']) $html = sprintf('', esc_attr( $meta_box['name'] ), $html, esc_attr( $meta_box['label'] )); $html .= isset( $meta_box['description'] )? themify_meta_field_get_description($meta_box['description']) : ''; if ( isset( $meta_box['before'] ) ) $html = $meta_box['before'] . $html; if ( isset( $meta_box['after'] ) ) $html .= $meta_box['after']; echo $html; } /** * Generates color picker * * @param array $args Field settings * * @since 1.3.2 * @return string */ function themify_meta_field_color( $args ) { $meta_box = $args['meta_box']; $meta_value = $args['meta_value']; extract($args, EXTR_OVERWRITE); $format = isset( $meta_box['format'] ) ? $meta_box['format'] : 'hex'; $default = isset( $meta_box['meta']['default'] ) ? $meta_box['meta']['default'] : ''; $html = sprintf( ' ', esc_attr( $meta_box['name'] ), esc_attr( $meta_box['name'] ), esc_attr( $meta_value? $meta_value : $default ), esc_attr( $format ) ); if(isset($meta_box['label']) && '' != $meta_box['label']) $html = sprintf('', esc_attr( $meta_box['name'] ), $html, esc_attr( $meta_box['label'] )); $html .= isset( $meta_box['description'] )? themify_meta_field_get_description($meta_box['description']) : ''; if ( isset( $meta_box['before'] ) ) $html = $meta_box['before'] . $html; if ( isset( $meta_box['after'] ) ) $html .= $meta_box['after']; echo $html; } /** * Generates layout field * * @param array $args Field settings * * @since 1.3.2 * @return string */ function themify_meta_field_layout( $args ) { $meta_box = $args['meta_box']; $meta_value = $args['meta_value']; extract( $args, EXTR_OVERWRITE ); $ops_html = ''; foreach ( $meta_box['meta'] as $options ) { if ( ( '' == $meta_value || !$meta_value || !isset($meta_value)) && ( isset( $options['selected'] ) && $options['selected'] ) ) { $meta_value = $options['value']; } $class = $meta_value == $options['value']?'selected':''; if(isset($meta_box['show_title'])){ $title = isset($options['title'])? $options['title']: ucwords(str_replace('-', ' ', $options['value'])); } else { $title = ''; } $w= isset($option['w'])?$option['w']:'46'; $h= isset($option['w'])?$option['w']:'35'; // Check image src whether absolute url or relative url $img_src = ( '' != parse_url( $options['img'], PHP_URL_SCHEME) ) ? $options['img'] : get_template_directory_uri() . '/' . $options['img']; $ops_html .= sprintf('%s%s', $class, esc_url( $img_src ), esc_attr( $options['value'] ), $title ); } $html = sprintf('%s', $ops_html, esc_attr( $meta_box['name'] ), esc_attr( $meta_value )); if(isset($meta_box['label']) && '' != $meta_box['label']) $html = sprintf('', esc_attr( $meta_box['name'] ), $html, esc_attr( $meta_box['label'] )); $html .= isset( $meta_box['description'] )? themify_meta_field_get_description($meta_box['description']) : ''; if( isset( $meta_box['before'] ) ) $html = $meta_box['before'] . $html; if( isset( $meta_box['after'] ) ) $html .= $meta_box['after']; echo $html; } /** * Generates select field as a button * * @since 1.3.2 * * @param array $args Field settings * * @return string */ function themify_meta_field_dropdownbutton( $args ) { $meta_box = $args['meta_box']; $meta_value = $args['meta_value']; $name = ''; extract($args, EXTR_OVERWRITE); if(isset($meta_box['main']) && $meta_box['main']) { $metakey = $meta_box['name']; $meta_class = 'ddbtn-all'; } else { $metakey = $meta_box['name']; $meta_class = 'ddbtn-sub'; } $additional_classes = isset( $meta_box['class'] ) ? $meta_box['class'] : ''; $toggle_class = ''; $ext_attr = ''; $toggle_enable = false; if( isset($meta_box['toggle']) ){ $toggle_class .= 'themify-toggle '; $toggle_class .= (is_array($meta_box['toggle'])) ? implode(' ', $meta_box['toggle']) : $meta_box['toggle']; } if( isset($meta_box['default_toggle']) && $meta_box['default_toggle'] == 'hidden' ){ $ext_attr = 'style="display:none;"'; } if( isset($meta_box['enable_toggle']) && $meta_box['enable_toggle'] == true ) { $toggle_class .= ' enable_toggle'; $toggle_enable = true; } $first = ''; $others = ''; $default_icon = ''; foreach($meta_box['states'] as $state) { $state['icon'] = sprintf( urldecode( $state['icon'] ), THEMIFY_METABOX_URI . '/img' ); if($state['value'] == $meta_value) { $first = '
'.esc_attr( $meta_box['title'] ).'
'; $selected = 'selected'; } else { $selected = ''; } $others .= '
'.esc_attr( $state['name'] ).'
'; if(isset($state['default']) && $state['default']){ $default_icon = $state['icon']; } } $html = sprintf('
', $additional_classes, esc_attr( $toggle_class ), esc_attr( $ext_attr ), esc_attr( $metakey ), esc_attr( $meta_class ), esc_attr( $name ), esc_attr( $default_icon ), // group $first, $others, // dropdown esc_attr( $meta_value ), esc_attr( $meta_class ), esc_attr( $metakey ), esc_attr( $metakey ) // hidden field ); $html = themify_meta_field_get_label($html, $meta_box); $html .= isset( $meta_box['description'] )? 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 select field * * @param array $args Field settings * * @since 1.3.2 * @return string */ function themify_meta_field_dropdown( $args ) { $meta_box = $args['meta_box']; $meta_value = $args['meta_value']; extract($args, EXTR_OVERWRITE); $ops_html = ''; /* dynamic data source, call a function to populate the field */ if( is_callable( $meta_box['meta'] ) ) { $meta_box['meta'] = call_user_func( $meta_box['meta'] ); } foreach($meta_box['meta'] as $option){ $ops_html .= sprintf('', esc_attr( $option['value'] ), isset( $meta_value ) && '' != $meta_value? selected( $meta_value, esc_attr( $option['value'] ), false ) : selected( isset( $option['selected'] )? $option['selected'] : '', true, false ), esc_html( $option['name'] ) ); } $html = sprintf('', esc_attr( $meta_box['name'] ), esc_attr( $meta_box['name'] ), $ops_html); $html = themify_meta_field_get_label($html, $meta_box); $html .= isset( $meta_box['description'] )? 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 radio buttons. * * @param array $args * * @return string */ function themify_meta_field_radio( $args ) { $meta_box = $args['meta_box']; $meta_value = $args['meta_value']; extract($args, EXTR_OVERWRITE); $html = ''; foreach ( $meta_box['meta'] as $k => $option ) { $radio_selected = ( isset( $option['selected'] ) && $option['selected'] && '' == $meta_value ) || ( isset( $meta_box['default'] ) && $option['value'] == $meta_box['default'] && '' == $meta_value ) ? 'checked="checked"' : checked( $meta_value, esc_attr( $option['value'] ), false ); $disabled = isset( $option['disabled'] ) && $option['disabled'] == true ? 'disabled="disabled"' : ''; $rid = $meta_box['name'] . '-' . esc_attr( $option['value'] ); $html .= sprintf( '', // radio esc_attr( $meta_box['name'] ), esc_attr( $rid ), esc_attr( $option['value'] ), $radio_selected, $disabled, // label esc_attr( $rid ), esc_html( $option['name'] ) ); } $html .= isset( $meta_box['description'] )? themify_meta_field_get_description($meta_box['description']) : ''; if( isset( $meta_box['before'] ) ) $html = $meta_box['before'] . $html; if( isset( $meta_box['after'] ) ) $html .= $meta_box['after']; echo $html; } /** * Generates separator * * @param array $args Field settings * @param bool $call_before_after Whether to output common wrapping markup before and after the field * @param bool $echo Whether to echo or return the field * * @since 1.3.2 * @return string */ function themify_meta_field_separator( $args ) { $meta_box = $args['meta_box']; extract($args, EXTR_OVERWRITE); $toggle_class = isset( $args['toggle_class'] ) ? $args['toggle_class'] : ''; $ext_attr = isset( $args['ext_attr'] ) ? $args['ext_attr'] : ''; $html = isset($meta_box['meta']['html']) && '' != $meta_box['meta']['html']? $meta_box['meta']['html'] : '
'; $html .= isset( $meta_box['description'] )? themify_meta_field_get_description($meta_box['description']) : ''; $out = '
'; 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( '', 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( '', $label_for, wp_kses_post( $meta_box['label'] ), $html ); } else { $html = sprintf( '', $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 .= ''; if ( $i === ($page_id * $posts_per_page) ) { $output .= '
'; $page_id++; $output .= ''; if ( $num_of_pages > 1 ) { $output .= '
'; $output .= themify_create_page_pagination( 1, $num_of_pages ); $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 .= ''; if ( $i === ( $page_id * $posts_per_page ) ) { $output .= '
'; $page_id ++; $output .= ''; if ( $num_of_pages > 1 ) { $output .= '
'; $output .= themify_create_page_pagination( 1, $num_of_pages ); $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 .= ''; if ( $i === ( $page_id * $posts_per_page ) ) { $output .= '
'; $page_id ++; $output .= ''; if ( $num_of_pages > 1 ) { $output .= '
'; $output .= themify_create_page_pagination( 1, $num_of_pages ); $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 .= ''; $checked = isset($selected['general']['page']) ? checked($selected['general']['page'], 'on', false) : ''; $output .= ''; $checked = isset($selected['general']['single']) ? checked($selected['general']['single'], 'on', false) : ''; $output .= ''; $checked = isset($selected['general']['search']) ? checked($selected['general']['search'], 'on', false) : ''; $output .= ''; $checked = isset($selected['general']['category']) ? checked($selected['general']['category'], 'on', false) : ''; $output .= ''; $checked = isset($selected['general']['tag']) ? checked($selected['general']['tag'], 'on', false) : ''; $output .= ''; $checked = isset($selected['general']['author']) ? checked($selected['general']['author'], 'on', false) : ''; $output .= ''; /* 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 .= ''; } /* 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 .= ''; } $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 .= ''; 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 .= ''; } $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 = '' . sprintf( __( 'Sorry, you have filled your %s MB storage quota so uploading has been disabled.', 'themify' ), get_space_allowed() ) . ''; } } else { if( '' != $args['fallback'] ) $html = $args['fallback']; else { ob_start(); // $id is the name of form field. File urls will be submitted in $_POST using this key. // If $id == "file" then $_POST["file"] will have all the file urls ?>
id="plupload-upload-ui" data-type="">
'themify_metabox_media_lib_browse', 'media_lib_nonce' => wp_create_nonce( 'media_lib_nonce' ), 'featured' => ($args['featured'] != '') ? 1 : 0, 'field_name' => $args['fields'], 'post_id' => $args['topost'] ); ?>
' . __( 'or', 'themify' ) . ''; endif; ?> 
true, 'action' => 'themify_plupload' ) ); // if $file returns error, return it and exit the function if ( isset( $file['error'] ) && ! empty( $file['error'] ) ) { wp_send_json_error( $file['error'] ); } //let's see if it's an image, a zip file or something else $ext = explode( '/', $file['type'] ); //Image Upload routines if ( 'tomedia' === $add_to_media_library ) { // Insert into Media Library // Set up options array to add this file as an attachment $attachment = array( 'post_mime_type' => sanitize_mime_type( $file['type'] ), 'post_title' => str_replace( '-', ' ', sanitize_file_name( pathinfo( $file['file'], PATHINFO_FILENAME ) ) ), 'post_status' => 'inherit' ); if ( $postid ) { $attach_id = wp_insert_attachment( $attachment, $file['file'], $postid ); } else { $attach_id = wp_insert_attachment( $attachment, $file['file'] ); } $file['id'] = $attach_id; // Common attachment procedures require_once( ABSPATH . 'wp-admin/includes/image.php' ); $attach_data = wp_generate_attachment_metadata( $attach_id, $file['file'] ); wp_update_attachment_metadata( $attach_id, $attach_data ); if ( $postid && ! empty( $_POST['fields'] ) ) { $full = wp_get_attachment_image_src( $attach_id, 'full' ); $fields = sanitize_text_field( wp_unslash( $_POST['fields'] ) ); update_post_meta( $postid, $fields, $full[0] ); update_post_meta( $postid, '_' . $fields . '_attach_id', $attach_id ); } $thumb = wp_get_attachment_image_src( $attach_id, 'thumbnail' ); //Return URL for the image field in meta box $file['thumb'] = $thumb[0]; } $file['type'] = isset( $ext[1] ) ? $ext[1] : $file['type']; // send the uploaded file url in response wp_send_json_success( $file ); } /** * @todo: remove this */ function themify_metabox_media_lib_browse() { if ( ! wp_verify_nonce( $_POST['media_lib_nonce'], 'media_lib_nonce' ) ) die(-1); if( ! current_user_can( 'upload_files' ) ) { die; } $file = array(); $postid = (int) $_POST['post_id']; $attach_id = (int) $_POST['attach_id']; $full = wp_get_attachment_image_src( $attach_id, 'full' ); update_post_meta($postid, sanitize_text_field( $_POST['field_name'] ), $full[0]); update_post_meta($postid, '_' . sanitize_text_field( $_POST['field_name'] ) . '_attach_id', $attach_id); $thumb = wp_get_attachment_image_src( $attach_id, 'thumbnail' ); //Return URL for the image field in meta box $file['thumb'] = $thumb[0]; echo json_encode($file); exit(); } function themify_meta_field_gallery_shortcode( $args ) { extract( $args ); wp_enqueue_script( 'gallery-shortcode' ); if( isset($meta_box['meta']) && '' != $meta_box['meta']['size'] && 'small' == $meta_box['meta']['size'] ) { $class = 'small'; } else { $class = ''; } ?> $field, 'meta_value' => get_post_meta( $post_id, $field['name'], true ), 'call_before_after' => false, 'post_id' => $post_id, 'themify_custom_panel_nonce' => $themify_custom_panel_nonce, ); // Do nested toggle for multi fields if ( isset( $field['enable_toggle'] ) ) { echo '
'; } elseif ( isset( $field['toggle'] ) ) { $field_toggle = is_array( $field['toggle'] ) ? implode( ' ', $field['toggle'] ) : $field['toggle']; echo '
'; } // Render the field call_user_func('themify_meta_field_'.$field['type'], $call_args); // End nested toggle for multi fields if ( isset( $field['enable_toggle'] ) ) { echo '
'; } elseif ( isset( $field['toggle'] ) ) { echo '
'; } if ( ! ( $field === end( $meta_box['meta']['fields'] ) ) ) { echo isset( $meta_box['meta']['separator'] ) ? $meta_box['meta']['separator'] : ''; } } } if ( isset( $meta_box['meta']['description'] ) && '' != $meta_box['meta']['description'] ) { echo '' . $meta_box['meta']['description'] . ''; } } if( ! function_exists( 'themify_meta_field_query_category' ) ) : /** * query_category field type, display an option to select categories for Query Posts feature * * @since 2.8.8 */ function themify_meta_field_query_category( $args ) { extract( $args ); $terms_tax = isset($meta_box['meta']['taxonomy'])? $meta_box['meta']['taxonomy']: 'category'; $terms_options = ''; $terms_by_tax = get_terms($terms_tax); if( ! empty( $terms_by_tax ) && ! is_wp_error( $terms_by_tax ) ) { $terms_list = array(); $terms_list['0'] = array( 'title' => __( 'All Categories', 'themify' ), 'slug' => '0' ); foreach ($terms_by_tax as $term) { $terms_list[$term->term_id] = array( 'title' => $term->name, 'slug' => $term->slug ); } foreach ($terms_list as $term_id => $term) { $term_selected = ''; if(!is_numeric($meta_value)) { if($meta_value == $term['slug']) $term_selected = 'selected="selected"'; } else { if($meta_value == $term_id) $term_selected = 'selected="selected"'; } $terms_options .= sprintf( '', $term['slug'], $term_id, $term_selected, $term['title'] ); } ?> ', '
'; foreach ( $meta_box['fields'] as $field ) { if ( is_callable( 'themify_meta_field_'.$field['type'] ) ) { echo '
'; ! empty( $field['title'] ) && printf( '
%s
', $field['title'] ); $field_id = $field['name']; $field['name'] = $meta_box['name'] . '[' . $id . '][' . $field['name'] . ']'; $call_args = array( 'meta_box' => $field, 'meta_value' => isset( $data[$field_id] ) ? $data[$field_id] : '', 'call_before_after' => false, 'post_id' => 0, 'themify_custom_panel_nonce' => 0, ); // Do nested toggle for multi fields if ( isset( $field['enable_toggle'] ) ) { echo '
'; } elseif ( isset( $field['toggle'] ) ) { $field_toggle = is_array( $field['toggle'] ) ? implode( ' ', $field['toggle'] ) : $field['toggle']; echo '
'; } printf( '
', $field['type'] ); // Render the field call_user_func('themify_meta_field_'.$field['type'], $call_args); echo '
'; // End nested toggle for multi fields if ( isset( $field['enable_toggle'] ) || isset( $field['toggle'] )) { echo '
'; } if ( ! ( $field === end( $meta_box['fields'] ) ) ) { echo isset( $meta_box['meta']['separator'] ) ? $meta_box['meta']['separator'] : ''; } echo '
'; } } echo '
'; } function themify_meta_field_repeater( $args, $call_before_after = true, $echo = true ) { global $post; extract( $args, EXTR_OVERWRITE ); echo ''; $meta_value = isset($meta_value) ? $meta_value : ''; $meta_value = !is_array( $meta_value ) && !empty($meta_box['show_first']) && true === $meta_box['show_first'] ? array(array()) : $meta_value ; echo '
'; 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 ''; if ( isset( $meta_box['meta']['description'] ) && '' != $meta_box['meta']['description'] ) { echo '' , $meta_box['meta']['description'] , ''; } } /** * Generates Image Radio * * @param array $args Field settings * * @since 1.3.2 * @return string */ function themify_meta_field_image_radio( $args ) { $meta_box = $args['meta_box']; $meta_value = $args['meta_value']; extract( $args, EXTR_OVERWRITE ); $html = ''; foreach ( $meta_box['meta'] as $option ) { if ( ( '' == $meta_value || ! $meta_value || ! isset( $meta_value ) ) && ( isset( $option['selected'] ) && $option['selected'] ) ) { $meta_value = $option['value']; } if ( $meta_value == $option['value'] ) { $class = 'selected'; } else { $class = ''; } if(isset($meta_box['show_title'])){ $title = isset( $option['title'] )? $option['title']: ucwords( str_replace( '-', ' ', $option['value'] ) ); } else { $title = ''; } // Check image src whether absolute url or relative url $img_src = ( '' != parse_url( $option['img'], PHP_URL_SCHEME) ) ? $option['img'] : get_template_directory_uri() . '/' . $option['img']; $rid = $meta_box['name'] . '-' . esc_attr( $option['value'] ); $html .= sprintf('
%s
', $meta_box['name'], $rid, $option['value'], checked( $meta_value, $option['value'], false ), $rid, $img_src, $title, $title ); } if(isset($meta_box['label']) && '' != $meta_box['label']) $html = sprintf('', esc_attr( $meta_box['name'] ), $html, esc_attr( $meta_box['label'] )); $html .= isset( $meta_box['description'] )? themify_meta_field_get_description($meta_box['description']) : ''; if( isset( $meta_box['before'] ) ) $html = $meta_box['before'] . $html; if( isset( $meta_box['after'] ) ) $html .= $meta_box['after']; echo $html; } /** * Display a hidden input. Value is retrieve from DB, or the "default" parameter if provided. */ function themify_meta_field_hidden( $args ) { $meta_value = $args['meta_value']; if ( isset( $args['meta_box']['default'] ) && empty( $meta_value ) && ! ( $meta_value === 0 || $meta_value === '0' ) ) { $meta_value = $args['meta_box']['default']; } $html = sprintf('', esc_attr( $args['meta_box']['name'] ), esc_attr( $args['meta_box']['name'] ), esc_attr( $meta_value ) ); echo $html; }