public function load_page_template($template)
 {
     global $post;
     if (SB_Core::is_error($post)) {
         return $template;
     }
     $page_template = get_post_meta($post->ID, '_wp_page_template', true);
     if (!isset($this->templates[$page_template])) {
         return $template;
     }
     $file = $this->plugin_path . '/';
     if (!empty($this->plugin_folder_path)) {
         $file .= untrailingslashit($this->plugin_folder_path) . '/';
     }
     $file .= $page_template;
     if (file_exists($file)) {
         $template = $file;
     }
     return $template;
 }
Пример #2
0
 public static function get_previous_post_url()
 {
     $result = '';
     $post = get_adjacent_post(false, '', false);
     if (!SB_Core::is_error($post)) {
         $result = get_permalink($post);
     }
     return $result;
 }
Пример #3
0
 public static function select_term($args = array())
 {
     $container_class = isset($args['container_class']) ? $args['container_class'] : '';
     $id = isset($args['id']) ? $args['id'] : '';
     $name = isset($args['name']) ? $args['name'] : '';
     $field_class = isset($args['field_class']) ? $args['field_class'] : '';
     $label = isset($args['label']) ? $args['label'] : '';
     $options = isset($args['options']) ? $args['options'] : array();
     $value = isset($args['value']) ? $args['value'] : '';
     $description = isset($args['description']) ? $args['description'] : '';
     $taxonomy = isset($args['taxonomy']) ? $args['taxonomy'] : '';
     $taxonomy_id = isset($args['taxonomy_id']) ? $args['taxonomy_id'] : '';
     $taxonomy_name = isset($args['taxonomy_name']) ? $args['taxonomy_name'] : '';
     $show_count = isset($args['show_count']) ? $args['show_count'] : true;
     $before = isset($args['before']) ? $args['before'] : '<p class="' . esc_attr($container_class) . '">';
     $after = isset($args['after']) ? $args['after'] : '</p>';
     echo $before;
     self::label(array('for' => $id, 'text' => $label));
     $all_option = '<option value="0">' . __('Choose term', 'sb-core') . '</option>';
     $args['before'] = '';
     if (count($options) > 0) {
         foreach ($options as $tax) {
             $terms = get_terms($tax->name);
             if (!SB_Core::is_error($terms) && count($terms) > 0) {
                 $tmp = '<optgroup label="' . $tax->labels->name . '">';
                 foreach ($terms as $cat) {
                     $option_text = $cat->name . $show_count ? ' (' . $cat->count . ')' : '';
                     $tmp .= self::get_option(array('value' => $cat->term_id, 'attributes' => array('data-taxonomy' => $tax->name), 'selected' => $value, 'text' => $option_text));
                 }
                 $tmp .= '</optgroup>';
                 $all_option .= $tmp;
             }
         }
     } else {
         $terms = SB_Term::get($taxonomy);
         if (!SB_Core::is_error($terms) && count($terms) > 0) {
             foreach ($terms as $cat) {
                 $all_option .= self::get_option(array('value' => $cat->term_id, 'attributes' => array('data-taxonomy' => $tax->name), 'selected' => $value, 'text' => $option_text));
             }
         }
     }
     $args['all_option'] = $all_option;
     self::select($args);
     if (!empty($taxonomy_name)) {
         $args['id'] = $taxonomy_id;
         $args['name'] = $taxonomy_name;
         $args['value'] = $taxonomy;
         $args['field_class'] = 'widefat taxonomy';
         $args['type'] = 'hidden';
         self::text($args);
     }
     echo $after;
 }