function mltlngg_admin_init()
 {
     global $bws_plugin_info, $mltlngg_plugin_info, $bws_shortcode_list;
     if (!isset($bws_plugin_info) || empty($bws_plugin_info)) {
         $bws_plugin_info = array('id' => '143', 'version' => $mltlngg_plugin_info["Version"]);
     }
     /* Actions for categories & tags translation */
     $mltlngg_taxonomies = get_object_taxonomies('post');
     if (is_array($mltlngg_taxonomies)) {
         foreach ($mltlngg_taxonomies as $mltlngg_taxonomy) {
             add_action($mltlngg_taxonomy . '_add_form_fields', 'mltlngg_new_terms_translate');
             add_action('created_' . $mltlngg_taxonomy, 'mltlngg_new_terms_created');
             add_action($mltlngg_taxonomy . '_edit_form_fields', 'mltlngg_terms_translate');
             add_action('edited_' . $mltlngg_taxonomy, 'mltlngg_terms_update');
             add_action('delete_' . $mltlngg_taxonomy, 'mltlngg_delete_term');
             /* Add language column in the taxonomy wp_list_table to display if language is translated */
             add_filter('manage_edit-' . $mltlngg_taxonomy . '_columns', 'mltlngg_add_term_column');
             add_filter('manage_' . $mltlngg_taxonomy . '_custom_column', 'mltlngg_term_column', 10, 3);
         }
     }
     /* Add language column in the post wp_list_table to display if language is translated */
     add_filter('manage_edit-post_columns', 'mltlngg_add_post_column');
     add_filter('manage_post_posts_custom_column', 'mltlngg_post_column', 10, 3);
     add_filter('manage_edit-page_columns', 'mltlngg_add_post_column');
     add_filter('manage_page_posts_custom_column', 'mltlngg_post_column', 10, 3);
     /* add Multilanguage to global $bws_shortcode_list  */
     $bws_shortcode_list['mltlngg'] = array('name' => 'Multilanguage');
     /* add 'Multilanguage switcher' into the Menu */
     add_action('wp_update_nav_menu_item', 'mltlngg_wp_update_nav_menu_item', 10, 2);
     add_meta_box('mltlngg_language_switcher_box', __('Multilanguage switcher', 'multilanguage'), 'mltlngg_language_switcher_box', 'nav-menus', 'side', 'high');
 }
    /**
     * widget function.
     *
     * @see WP_Widget
     *
     * @param array $args
     * @param array $instance
     */
    public function widget($args, $instance)
    {
        global $_chosen_attributes, $wpdb, $wp;
        if (!is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) {
            return;
        }
        if (!sizeof(WC()->query->unfiltered_product_ids)) {
            return;
            // None shown - return
        }
        $min_rating = isset($_GET['min_rating']) ? absint($_GET['min_rating']) : '';
        $this->widget_start($args, $instance);
        echo '<ul>';
        for ($rating = 4; $rating >= 1; $rating--) {
            $link = $this->get_page_base_url();
            $link = $min_rating !== $rating ? add_query_arg('min_rating', $rating, $link) : $link;
            echo '<li class="wc-layered-nav-rating ' . (!empty($_GET['min_rating']) && $rating === absint($_GET['min_rating']) ? 'chosen' : '') . '">';
            echo '<a href="' . esc_url(apply_filters('woocommerce_rating_filter_link', $link)) . '">';
            echo '<span class="star-rating" title="' . esc_attr(sprintf(__('Rated %s and above', 'woocommerce'), $rating)) . '">
					<span style="width:' . esc_attr($rating / 5 * 100) . '%">' . sprintf(__('Rated %s and above', 'woocommerce'), $rating) . '</span>
				</span>';
            echo '</a>';
            echo '</li>';
        }
        echo '</ul>';
        $this->widget_end($args);
    }
Пример #3
0
 public function add()
 {
     $this->validateNonce();
     if (!isset($_REQUEST['id'])) {
         die('ID not specified');
     }
     // Код товара
     $id = (int) $_REQUEST['id'];
     $product = get_post($id);
     $title = $product->post_title;
     // Цена
     $price = simple_basket_custom_fields($id, get_option('simple_basket_catalog_price'));
     // Вычисляем категорию по таксономии
     $category = '';
     // Тип записи каталога товара
     $postType = $product->post_type;
     // Таксономии записи
     $taxonomies = get_object_taxonomies($postType);
     // Ищем таксономию, которая не тег
     foreach ($taxonomies as $taxonomy) {
         if (strpos($taxonomy, 'tag') !== FALSE) {
             continue;
         }
         // Берем элементы этой таксономии
         $categories = get_the_terms($id, $taxonomy);
         $category = count($categories) > 0 ? $categories[0]->name : '';
         // Следующие таксономии не рассматриваем
         break;
     }
     // Добавляем в корзину
     if (!empty($title)) {
         $this->basket->add($id, $title, $price, $category);
     }
     $this->responce($this->basket);
 }
Пример #4
0
/**
 * Set Default Terms
 * Used in attachment-functions.php
 *
 * @since 0.1
 */
function sell_media_set_default_terms($post_id, $post = null, $term_ids = null)
{
    if (is_null($post)) {
        $post_type = get_post_type($post_id);
    } else {
        $post_type = $post->post_type;
        $post_status = $post->post_status;
    }
    if (empty($post_status)) {
        return;
    }
    if (empty($term_ids) || $term_ids === true) {
        $term_ids = sell_media_get_default_terms();
    }
    $taxonomy = 'licenses';
    $default_terms = array();
    foreach ($term_ids as $term_id) {
        $tmp_term_id = get_term_by('id', $term_id, $taxonomy);
        if ($tmp_term_id) {
            $default_terms[] = (int) $tmp_term_id->term_id;
            $default_terms[] = (int) $tmp_term_id->parent;
        }
    }
    $defaults = array($taxonomy => $default_terms);
    $taxonomies = get_object_taxonomies($post_type);
    foreach ((array) $taxonomies as $taxonomy) {
        $terms = wp_get_post_terms($post_id, $taxonomy);
        if (empty($terms) && array_key_exists($taxonomy, $defaults)) {
            wp_set_object_terms($post_id, $defaults[$taxonomy], $taxonomy);
        }
    }
}
Пример #5
0
/**
 * Get all terms archives urls associated to a specific post
 *
 * @since 1.0
 *
 * @param int $post_ID The post ID
 * @return array $urls List of taxonomies URLs
 */
function get_rocket_post_terms_urls($post_ID)
{
    $urls = array();
    $taxonomies = get_object_taxonomies(get_post_type($post_ID), 'objects');
    foreach ($taxonomies as $taxonomy) {
        if (!$taxonomy->public) {
            continue;
        }
        // Get the terms related to post
        $terms = get_the_terms($post_ID, $taxonomy->name);
        if (!empty($terms)) {
            foreach ($terms as $term) {
                $term_url = get_term_link($term->slug, $taxonomy->name);
                if (!is_wp_error($term_url)) {
                    $urls[] = $term_url;
                }
            }
        }
    }
    /**
     * Filter the list of taxonomies URLs
     *
     * @since 1.1.0
     *
     * @param array $urls List of taxonomies URLs
     */
    $urls = apply_filters('rocket_post_terms_urls', $urls);
    return $urls;
}
 /**
  *  Load constants
  */
 public static function load_static_vars()
 {
     if (!isset($_REQUEST['page']) || $_REQUEST['page'] != 'lead_management') {
         return;
     }
     /* clean POST and REQUEST arrays of added slashes */
     $_POST = stripslashes_deep($_POST);
     $_REQUEST = stripslashes_deep($_REQUEST);
     /* set ordering & paging vars */
     self::$per_page = 60;
     self::$page = empty($_REQUEST['pull_page']) ? 1 : intval($_REQUEST['pull_page']);
     self::$paged = empty($_REQUEST['paged']) ? 1 : intval($_REQUEST['paged']);
     self::$orderby = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : '';
     self::$order = isset($_REQUEST['order']) ? strtoupper($_REQUEST['order']) : 'ASC';
     /* set ordering vars */
     self::$orderbys = array(__('Date First Created', 'leads') => 'date', __('Date Last Modified', 'leads') => 'modified', __('Alphabetical Sort', 'leads') => 'title', __('Status', 'leads') => 'post_status');
     /* set ordering vars */
     self::$orderbys_flip = array_flip(self::$orderbys);
     /* number of leads affected by action if any */
     self::$num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : 0;
     self::$what = isset($_REQUEST['what']) ? htmlentities($_REQUEST['what']) : "";
     self::$relation = isset($_REQUEST['relation']) ? htmlentities($_REQUEST['relation']) : "AND";
     self::$on = isset($_REQUEST['on']) ? htmlentities($_REQUEST['on']) : "";
     self::$tag = isset($_REQUEST['t']) ? $_REQUEST['t'] : '';
     self::$keyword = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
     self::$taxonomies = get_object_taxonomies('wp-lead', 'objects');
 }
Пример #7
0
 /**
  * Get related post ids
  *
  * @param int $post_id
  *
  * @return array Post ids
  */
 function get_related($post_id)
 {
     $related = array();
     $taxonomies = get_object_taxonomies($this->post->post_type);
     if ($taxonomies) {
         foreach ($taxonomies as $taxonomy) {
             $terms = wp_get_post_terms($this->post->ID, $taxonomy);
             if ($terms) {
                 foreach ($terms as $term) {
                     $posts = new WP_Query(wp_parse_args(array('posts_per_page' => '-1', 'tax_query' => array(array('taxonomy' => $taxonomy, 'terms' => $term->slug, 'field' => 'slug'))), $this->args));
                     if ($posts->have_posts()) {
                         while ($posts->have_posts()) {
                             $posts->the_post();
                             if (!isset($related[get_the_ID()])) {
                                 $related[get_the_ID()] = 0;
                             }
                             $related[get_the_ID()] += 1;
                         }
                     }
                     wp_reset_postdata();
                 }
             }
         }
     }
     //Put them in the right order and chop off what we don't need
     asort($related);
     $related = array_reverse($related, true);
     if ($this->args['posts_per_page'] != -1) {
         $related = array_chunk($related, $this->args['posts_per_page'], true);
     } else {
         $related = array($related);
     }
     return isset($related[0]) ? array_keys($related[0]) : array();
 }
 /**
  * This action is hooked to the 'deleted_term_relationships' hook.
  * It removes terms from translated posts as soon as they are removed from the original post.
  * It only fires, if the setting 'sync_post_taxonomies' is activated.
  *
  * @param int   $post_id      ID of the post the deleted terms were attached to
  * @param array $delete_terms Array of term taxonomy id's for those terms that were deleted from the post.
  */
 public function deleted_term_relationships($post_id, $delete_terms)
 {
     $post = get_post($post_id);
     $trid = $this->sitepress->get_element_trid($post_id, 'post_' . $post->post_type);
     if ($trid) {
         $translations = $this->sitepress->get_element_translations($trid, 'post_' . $post->post_type);
         foreach ($translations as $translation) {
             if ($translation->original == 1 && $translation->element_id == $post_id) {
                 $taxonomies = get_object_taxonomies($post->post_type);
                 foreach ($taxonomies as $taxonomy) {
                     foreach ($delete_terms as $delete_term) {
                         $trid = $this->sitepress->get_element_trid($delete_term, 'tax_' . $taxonomy);
                         if ($trid) {
                             $tags = $this->sitepress->get_element_translations($trid, 'tax_' . $taxonomy);
                             foreach ($tags as $tag) {
                                 if (!$tag->original && isset($translations[$tag->language_code])) {
                                     $translated_post = $translations[$tag->language_code];
                                     $this->wpdb->delete($this->wpdb->term_relationships, array('object_id' => $translated_post->element_id, 'term_taxonomy_id' => $tag->element_id));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #9
0
/**
 * Load the Genesis-fied templates, instead of the WooCommerce defaults.
 *
 * Hooked to 'template_include' filter
 *
 * This template loader determines which template file will be used for the requested page, and uses the
 * following hierarchy to find the template:
 * 1. First looks in the child theme's 'woocommerce' folder.
 * 2. If no template found, falls back to GCW's templates.
 *
 * For taxonomy templates, first looks in child theme's 'woocommerce' folder and searches for term specific template,
 * then taxonomy specific template, then taxonomy.php. If no template found, falls back to GCW's taxonomy.php.
 *
 * GCW provides three templates in the plugin's 'templates' directory:
 * - single-product.php
 * - archive-product.php
 * - taxonomy.php
 *
 * Users can override GCW templates by placing their own templates in their child theme's 'woocommerce' folder.
 * The 'woocommerce' folder must be a folder in the child theme's root directory, eg themes/my-child-theme/woocommerce
 * Permitted user templates (as per WP Template Hierarchy) are:
 * - single-product.php
 * - archive-product.php
 * - taxonomy-{taxonomy-name}-{term-name}.php
 * - taxonomy-{taxonomy-name}.php
 * - taxonomy.php
 *
 * Note that in the case of taxonomy templates, this function accommodates ALL taxonomies registered to the
 * 'product' custom post type. This means that it will cater for users' own custom taxonomies as well as WooC's.
 *
 * @since 0.9.0
 *
 * @param string $template Template file as per template hierarchy
 * @return string $template Specific GCW template if a product page (single or archive)
 * or a product taxonomy term, or returns original template
 */
function gencwooc_template_loader($template)
{
    if (is_single() && 'product' == get_post_type()) {
        $template = locate_template(array('woocommerce/single-product.php'));
        if (!$template) {
            $template = GCW_TEMPLATE_DIR . '/single-product.php';
        }
    } elseif (is_post_type_archive('product') || is_page(get_option('woocommerce_shop_page_id'))) {
        $template = locate_template(array('woocommerce/archive-product.php'));
        if (!$template) {
            $template = GCW_TEMPLATE_DIR . '/archive-product.php';
        }
    } elseif (is_tax()) {
        $term = get_query_var('term');
        $tax = get_query_var('taxonomy');
        /** Get an array of all relevant taxonomies */
        $taxonomies = get_object_taxonomies('product', 'names');
        if (in_array($tax, $taxonomies)) {
            $tax = sanitize_title($tax);
            $term = sanitize_title($term);
            $templates = array('woocommerce/taxonomy-' . $tax . '-' . $term . '.php', 'woocommerce/taxonomy-' . $tax . '.php', 'woocommerce/taxonomy.php');
            $template = locate_template($templates);
            /** Fallback to GCW template */
            if (!$template) {
                $template = GCW_TEMPLATE_DIR . '/taxonomy.php';
            }
        }
    }
    return $template;
}
Пример #10
0
 public function admin_init()
 {
     //set the settings
     $page = $this->page;
     //add_section
     //you can pass section_id, section_title, section_description, the section id must be unique for this page, section descriptiopn is optional
     $page->add_section('basic_section', __('Settings', 'buddyblog'), __('Settings for BuddyBlog.', 'buddyblog'));
     $post_types = get_post_types(array('public' => true));
     //public post types
     $post_type_options = array();
     foreach ($post_types as $post_type) {
         $post_type_object = get_post_type_object($post_type);
         $post_type_options[$post_type] = $post_type_object->labels->name;
     }
     $post_statuses = array('publish' => __('Published', 'buddyblog'), 'draft' => __('Draft', 'buddyblog'));
     $comment_statuses = array('open' => __('Open', 'buddyblog'), 'close' => __('Closed', 'buddyblog'));
     $default_post_type = buddyblog_get_posttype() ? buddyblog_get_posttype() : 'post';
     $taxonomies = get_object_taxonomies($default_post_type);
     if (isset($taxonomies['post_format'])) {
         unset($taxonomies['post_format']);
     }
     $tax = array();
     foreach ($taxonomies as $taxonomy) {
         $tax_object = get_taxonomy($taxonomy);
         $tax[$taxonomy] = $tax_object->labels->name;
     }
     //add fields
     $page->get_section('basic_section')->add_fields(array(array('name' => 'post_type', 'label' => __('Blog Post Type', 'buddyblog'), 'desc' => __('Set the post type for user blog.', 'buddyblog'), 'type' => 'select', 'default' => $default_post_type, 'options' => $post_type_options), array('name' => 'post_status', 'label' => __('Default post status', 'buddyblog'), 'desc' => __('What should be the post status when user submits the form?', 'buddyblog'), 'type' => 'select', 'default' => 'publish', 'options' => $post_statuses), array('name' => 'comment_status', 'label' => __('Comment status?', 'buddyblog'), 'desc' => __('Do you want to allow commenting on user posts?', 'buddyblog'), 'type' => 'select', 'default' => 'open', 'options' => $comment_statuses), array('name' => 'show_comment_option', 'label' => __('Allow post author to enable/disable comment?', 'buddyblog'), 'desc' => __('If you enable, A user will be able to change the comment status for his/her post.', 'buddyblog'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog'))), array('name' => 'enable_taxonomy', 'label' => __('Enable Taxonomy?', 'buddyblog'), 'desc' => __('If you enable, users will be able to select terms from the selected taxonomies.', 'buddyblog'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog'))), array('name' => 'allowed_taxonomies', 'label' => __('Select allowed taxonomies', 'buddyblog'), 'desc' => __('Please check the taxonomies you want users to be able to attach to their post.', 'buddyblog'), 'type' => 'multicheck', 'default' => 'category', 'options' => $tax), array('name' => 'show_posts_on_profile', 'label' => __('Show single posts on user profile?', 'buddyblog'), 'desc' => __('If you enable it, the permalink to single post will be something like http://yoursite.com/members/username/buddyblog/postname.', 'buddyblog'), 'type' => 'radio', 'default' => 0, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog'))), array('name' => 'limit_no_of_posts', 'label' => __('Limit number of posts a user can create?', 'buddyblog'), 'desc' => __('If you enable it, You can control the allowed number of posts from the next option.', 'buddyblog'), 'type' => 'radio', 'default' => 0, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog'))), array('name' => 'max_allowed_posts', 'label' => __('How many posts a user can create?', 'buddyblog'), 'desc' => __('Only applies if you have enabled the limit on posts from above option.', 'buddyblog'), 'type' => 'text', 'default' => 10), array('name' => 'publish_cap', 'label' => __('Which capability is required for pusblishing?', 'buddyblog'), 'desc' => __('Please check for https://codex.wordpress.org/Roles_and_Capabilities allowed capabilities.', 'buddyblog'), 'type' => 'text', 'default' => 'read'), array('name' => 'allow_unpublishing', 'label' => __('Allow users to unpublish their own post?', 'buddyblog'), 'desc' => '', 'type' => 'radio', 'default' => 0, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog'))), array('name' => 'post_cap', 'label' => __('Which capability is required for creating post?', 'buddyblog'), 'desc' => __('Please check for https://codex.wordpress.org/Roles_and_Capabilities allowed capabilities.', 'buddyblog'), 'type' => 'text', 'default' => 'read'), array('name' => 'allow_edit', 'label' => __('Allow user to edit their post?', 'buddyblog'), 'desc' => __('if you disable it, user will not be able to edit their own post.', 'buddyblog'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog'))), array('name' => 'dashboard_edit_cap', 'label' => __('Which capability can edit post in backend(WordPress Dashboard)?', 'buddyblog'), 'desc' => __('User with these capabilities will nto be redirected to front end editor for editing post., user will not be able to edit their own post.', 'buddyblog'), 'type' => 'text', 'default' => 'publish_posts'), array('name' => 'allow_delete', 'label' => __('Allow user to delete their post?', 'buddyblog'), 'desc' => __('if you disable it, user will not be able to delete their own post.', 'buddyblog'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog')))));
     $page->init();
 }
 function sync_variation_swatches_and_photos($original_product_id, $trnsl_product_id, $data = false)
 {
     global $sitepress, $wpdb;
     $atts = maybe_unserialize(get_post_meta($original_product_id, '_swatch_type_options', true));
     if (!is_array($atts)) {
         return;
     }
     $lang = $sitepress->get_language_for_element($trnsl_product_id, 'post_product');
     $tr_atts = $atts;
     $original_product_post = get_post($original_product_id);
     $original_product_taxonomies = get_object_taxonomies($original_product_post);
     $original_product_terms = get_terms($original_product_taxonomies);
     if (is_array($original_product_terms)) {
         foreach ($atts as $att_name => $att_opts) {
             $attributes_hashed_names = array_keys($att_opts['attributes']);
             foreach ($original_product_terms as $original_product_term) {
                 $original_product_term_slug_md5 = md5($original_product_term->slug);
                 if (in_array($original_product_term_slug_md5, $attributes_hashed_names)) {
                     $translated_product_term_id = apply_filters('wpml_object_id', $original_product_term->term_id, $original_product_term->taxonomy, false, $lang);
                     $translated_product_term = get_term($translated_product_term_id, $original_product_term->taxonomy);
                     if (is_object($translated_product_term)) {
                         $translated_product_term_slug_md5 = md5($translated_product_term->slug);
                         $tr_atts[$att_name]['attributes'][$translated_product_term_slug_md5] = $tr_atts[$att_name]['attributes'][$original_product_term_slug_md5];
                         unset($tr_atts[$att_name]['attributes'][$original_product_term_slug_md5]);
                     }
                 }
             }
         }
     }
     update_post_meta($trnsl_product_id, '_swatch_type_options', $tr_atts);
     // Meta gets overwritten
 }
 public function __construct($data)
 {
     parent::__construct($data);
     if ('' === $this->name) {
         $this->name = 'taxonomy-list';
     }
     // If a taxonomy wasn't passed in, assume the first taxonomy associated with the post type.
     if (!isset($data['taxonomy'])) {
         $post_object_taxonomies = get_object_taxonomies($this->post_object);
         $this->taxonomy = array_shift($post_object_taxonomies);
     } else {
         $this->taxonomy = $data['taxonomy'];
     }
     $this->before_list = isset($data['before-list']) ? $data['before-list'] : '';
     $this->separator = isset($data['separator']) ? $data['separator'] : ', ';
     $this->after_list = isset($data['after-list']) ? $data['after-list'] : '';
     $this->include_links = isset($data['include-links']) ? $data['include-links'] : true;
     $this->tag = isset($data['tag']) ? $data['tag'] : 'p';
     if (true === $this->include_links) {
         $this->content = get_the_term_list($this->post_object->ID, $this->taxonomy, $this->before_list, $this->separator, $this->after_list);
     } else {
         $terms_arr = get_the_terms($this->post_object->ID, $this->taxonomy);
         $term_names_arr = array();
         if (!empty($terms_arr)) {
             foreach ($terms_arr as $term_obj) {
                 $term_names_arr[] = '<span class="name">' . $term_obj->name . '</span>';
             }
             $terms_list = implode($this->separator, $term_names_arr);
             $this->content = $this->before_list . $terms_list . $this->after_list;
         } else {
             $this->content = '';
         }
     }
 }
function get_terms_list_callback()
{
    global $wpdb;
    $selected_post_type = $_POST['selected_post_type'];
    if ($_POST['widget_name']) {
        $widget_option = get_option('widget_' . $_POST['widget_name']);
        $post_category = $widget_option[$_POST['instance_id']]['post_category'];
    }
    $taxonomies = get_object_taxonomies($selected_post_type);
    if (!empty($taxonomies)) {
        $categories_content = '';
        foreach ($taxonomies as $taxonomy) {
            $args = array('taxonomy' => $taxonomy, 'orderby' => 'name', 'show_count' => 0, 'pad_counts' => 0, 'hierarchical' => 1, 'hide_empty' => 0);
            $categories = get_categories($args);
            foreach ($categories as $category) {
                if (!empty($post_category)) {
                    if (is_array($post_category) && in_array($category->term_id, $post_category)) {
                        $checked = 'checked="checked"';
                    } else {
                        $checked = '';
                    }
                } else {
                    $checked = '';
                }
                $categories_content .= '<li id="category-' . $category->term_id . '"><label class="selectit"><input type="checkbox" id="in-category-' . $category->term_id . '" name="post_category[]" value="' . $category->term_id . '" ' . $checked . '> ' . $category->name . '</label></li>' . "\n";
            }
        }
    } else {
        $categories_content = 'No taxonomies for selected post type';
    }
    echo $categories_content;
    wp_die();
}
function yt_to_posts_getPostTypeCats()
{
    // Returns an array of all Youtube ID (to check dupes)
    $type = $_POST['post_type'];
    $taxs = get_object_taxonomies($type);
    $results = array();
    if (empty($taxs)) {
        echo 'empty';
    } else {
        foreach ($taxs as $tax) {
            if ($tax === "post_tag" || $tax === "post_format") {
            } else {
                $args = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '', 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core');
                $tax_terms = get_terms($tax, $args);
                // var_dump($tax_terms);
                foreach ($tax_terms as $tax_term) {
                    if ($tax_term) {
                        $object = new stdClass();
                        $object->id = $tax_term->term_id;
                        $object->name = $tax_term->name;
                        $results[] = $object;
                    }
                }
            }
        }
        $results = json_encode($results);
        echo $results;
    }
    die;
}
Пример #15
0
 function default_item($key = 0, $old = array())
 {
     $default = array('title' => '', 'field' => '', 'taxonomy' => '', 'order' => '', 'style' => 'dark');
     extract(wp_parse_args($old, $default));
     $taxonomy_html = '<select name="taxonomy[' . $key . ']" class="widefat field_taxonomy">';
     $tax = get_object_taxonomies('st_rental', 'OBJECTS');
     if (!empty($tax)) {
         foreach ($tax as $key2 => $value2) {
             $taxonomy_html .= "<option " . selected($key2, $taxonomy, false) . " value='{$key2}'>{$value2->label}</option>";
         }
     }
     $taxonomy_html .= '</select>';
     $fields = '<select name="field[' . $key . ']" class="widefat field_name">
                 <option ' . selected('price', $field, false) . ' value="price">' . __('Price', ST_TEXTDOMAIN) . '</option>
                 <option ' . selected('rate', $field, false) . ' value="rate">' . __('Rate', ST_TEXTDOMAIN) . '</option>
                 <option ' . selected('taxonomy', $field, false) . ' value="taxonomy">' . __('Taxonomy', ST_TEXTDOMAIN) . '</option>
             </select>';
     return '<li class="ui-state-default">
         <p><label>' . __('Title', ST_TEXTDOMAIN) . ':</label><input class="widefat field_title" name="title[' . $key . ']" type="text" value="' . $title . '"></p>
         <input type="hidden" class="field_order" name="order[' . $key . ']" value="' . $key . '">
         <p><label>' . __('Field', ST_TEXTDOMAIN) . ':</label>' . $fields . '</p>
         <p class=""><label>' . __('Taxonomy', ST_TEXTDOMAIN) . ':</label>' . $taxonomy_html . '</p>
         <p class="field_tax_wrap"><a href="#" class="button st_delete_field" onclick="return false">' . __('Delete', ST_TEXTDOMAIN) . '</a></p>
         </li>';
 }
Пример #16
0
function hocwp_is_post_type_archive($post_type)
{
    if (is_tax(get_object_taxonomies($post_type)) || is_post_type_archive($post_type)) {
        return true;
    }
    return false;
}
Пример #17
0
function tfw_dynamic_counter($show_count = "total", $taxonomy = '', $term)
{
    // When the counter is dynamic, get the global $query_string,
    // and add our term to which we want to display the post count
    // and return the number of posts found if our term would have been selected
    global $wp_query;
    global $query_string;
    $post_type_taxonomies = isset($_GET['post_type']) ? get_object_taxonomies(esc_attr($_GET['post_type'])) : array();
    if (is_singular() || !in_array($taxonomy, $post_type_taxonomies)) {
        $show_count = "total";
    }
    if (($show_count == "dynamic" || $show_count == "none") && $wp_query->is_main_query()) {
        $args = array($taxonomy => $term->slug, 'posts_per_page' => -1);
        if (isset($wp_query->meta_query->queries)) {
            $args['meta_query'] = $wp_query->meta_query->queries;
        }
        $defaults = wp_parse_args($query_string);
        $args = wp_parse_args($args, $defaults);
        $counter_query = new WP_Query($args);
        return $counter_query->found_posts;
        // When counter is set to total, just output the term->count
    } elseif ($show_count == "total") {
        return $term->count;
    } else {
        return 0;
    }
}
 protected function getTaxonomies()
 {
     if ($this->taxonomies === false) {
         $this->taxonomies = get_object_taxonomies(!empty($this->loop_args['post_type']) ? $this->loop_args['post_type'] : get_post_types(array('public' => false, 'name' => 'attachment'), 'names', 'NOT'));
     }
     return $this->taxonomies;
 }
Пример #19
0
 /**
  * List all the rules available.
  *
  * @return array
  */
 public function listRules()
 {
     // Get all defined post types
     $post_types = $this->getPostTypes();
     // Break if there are no post types defined
     if (!$post_types) {
         return [];
     }
     // Get label and items for each post types
     $list = [];
     foreach ($post_types as $post_type) {
         $post_type = apply_filters('g5_assignments_' . $post_type->name . '_object', $post_type);
         if ($post_type) {
             $list[$post_type->name]['label'] = $post_type->labels->name;
             $list[$post_type->name]['items'] = $this->getItems($post_type);
             // Get current post type taxonomies and its terms
             $taxonomies = get_object_taxonomies($post_type->name);
             if (!empty($taxonomies)) {
                 $list[$post_type->name . '-terms']['label'] = $post_type->labels->name . ': Terms';
                 $list[$post_type->name . '-terms']['items'] = $this->getTerms($taxonomies, $post_type);
             }
         }
     }
     return $list;
 }
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     if (!is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) {
         return;
     }
     global $wcapf;
     // price range for filtered products
     $filtered_price_range = $wcapf->getPriceRange(true);
     // price range for all published products
     $unfiltered_price_range = $wcapf->getPriceRange(false);
     $html = '';
     // to be sure that these values are number
     $min_val = $max_val = 0;
     if (sizeof($unfiltered_price_range) === 2) {
         $min_val = $unfiltered_price_range[0];
         $max_val = $unfiltered_price_range[1];
     }
     // required scripts
     // enqueue necessary scripts
     wp_enqueue_style('wcapf-style');
     wp_enqueue_style('font-awesome');
     wp_enqueue_script('wcapf-script');
     wp_enqueue_script('wcapf-nouislider-script');
     wp_enqueue_script('wcapf-price-filter-script');
     wp_enqueue_style('wcapf-nouislider-style');
     // get values from url
     $set_min_val = null;
     if (isset($_GET['min-price']) && !empty($_GET['min-price'])) {
         $set_min_val = (int) $_GET['min-price'];
     }
     $set_max_val = null;
     if (isset($_GET['max-price']) && !empty($_GET['max-price'])) {
         $set_max_val = (int) $_GET['max-price'];
     }
     // HTML markup for price slider
     $html .= '<div class="wcapf-price-filter-wrapper">';
     $html .= '<div id="wcapf-noui-slider" class="noUi-extended" data-min="' . $min_val . '" data-max="' . $max_val . '" data-set-min="' . $set_min_val . '" data-set-max="' . $set_max_val . '"></div>';
     $html .= '<br />';
     $html .= '<div class="slider-values">';
     $html .= '<p>Min Price: <span class="wcapf-slider-value" id="wcapf-noui-slider-value-min"></span></p>';
     $html .= '<p>Max Price: <span class="wcapf-slider-value" id="wcapf-noui-slider-value-max"></span></p>';
     $html .= '</div>';
     $html .= '</div>';
     extract($args);
     // Add class to before_widget from within a custom widget
     // http://wordpress.stackexchange.com/questions/18942/add-class-to-before-widget-from-within-a-custom-widget
     $widget_class = 'woocommerce wcapf-price-filter-widget';
     // no class found, so add it
     if (strpos($before_widget, 'class') === false) {
         $before_widget = str_replace('>', 'class="' . $widget_class . '"', $before_widget);
     } else {
         $before_widget = str_replace('class="', 'class="' . $widget_class . ' ', $before_widget);
     }
     echo $before_widget;
     if (!empty($instance['title'])) {
         echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
     }
     echo $html;
     echo $args['after_widget'];
 }
Пример #21
0
 /**
  * Callback to pre-populate taxonomies before exporting ics.
  * All taxonomies which are not tags are exported as event_categories
  *
  * @param array $post_ids List of Post IDs to inspect.
  *
  * @return void
  */
 public function prepare_meta_for_ics(array $post_ids)
 {
     $taxonomies = get_object_taxonomies(AI1EC_POST_TYPE);
     $categories = array();
     $excluded_categories = array('events_tags' => true, 'events_feeds' => true);
     foreach ($taxonomies as $taxonomy) {
         if (isset($excluded_categories[$taxonomy])) {
             continue;
         }
         $categories[] = $taxonomy;
     }
     foreach ($post_ids as $post_id) {
         $post_id = (int) $post_id;
         $this->_taxonomy_map['events_categories'][$post_id] = array();
         $this->_taxonomy_map['events_tags'][$post_id] = array();
     }
     $tags = wp_get_object_terms($post_ids, array('events_tags'), array('fields' => 'all_with_object_id'));
     foreach ($tags as $term) {
         $this->_taxonomy_map[$term->taxonomy][$term->object_id][] = $term;
     }
     $category_terms = wp_get_object_terms($post_ids, $categories, array('fields' => 'all_with_object_id'));
     foreach ($category_terms as $term) {
         $this->_taxonomy_map['events_categories'][$term->object_id][] = $term;
     }
 }
function TOPluginMenu()
{
    include TOPATH . '/include/interface.php';
    include TOPATH . '/include/terms_walker.php';
    include TOPATH . '/include/options.php';
    add_options_page('Taxonomy Terms Order', '<img class="menu_pto" src="' . TOURL . '/images/menu-icon.gif" alt="" />' . __('Taxonomy Terms Order', 'to'), 'manage_options', 'to-options', 'to_plugin_options');
    $options = get_option('tto_options');
    if (!isset($options['level'])) {
        $options['level'] = 8;
    }
    //put a menu within all custom types if apply
    $post_types = get_post_types();
    foreach ($post_types as $post_type) {
        //check if there are any taxonomy for this post type
        $post_type_taxonomies = get_object_taxonomies($post_type);
        foreach ($post_type_taxonomies as $key => $taxonomy_name) {
            $taxonomy_info = get_taxonomy($taxonomy_name);
            if ($taxonomy_info->hierarchical !== TRUE) {
                unset($post_type_taxonomies[$key]);
            }
        }
        if (count($post_type_taxonomies) == 0) {
            continue;
        }
        if ($post_type == 'post') {
            add_submenu_page('edit.php', __('Taxonomy Order', 'to'), __('Taxonomy Order', 'to'), 'level_' . $options['level'], 'to-interface-' . $post_type, 'TOPluginInterface');
        } else {
            add_submenu_page('edit.php?post_type=' . $post_type, __('Taxonomy Order', 'to'), __('Taxonomy Order', 'to'), 'level_' . $options['level'], 'to-interface-' . $post_type, 'TOPluginInterface');
        }
    }
}
Пример #23
0
function custom_taxonomies_terms_links()
{
    // get post by post id
    $post = get_post($post->ID);
    // get post type by post
    $post_type = $post->post_type;
    // get post type taxonomies
    $taxonomies = get_object_taxonomies($post_type, 'objects');
    $out = array();
    foreach ($taxonomies as $taxonomy_slug => $taxonomy) {
        // get the terms related to post
        $terms = get_the_terms($post->ID, $taxonomy_slug);
        if (!empty($terms)) {
            //	  $out[] = "<h2>" . $taxonomy->label . "</h2>\n<ul>";
            foreach ($terms as $term) {
                $out[] = $term->slug . ' ';
                //	          '  <li><a href="'
                //	        .    get_term_link( $term->slug, $taxonomy_slug )
                //	        .'">'
                //	        .    $term->name
                //	        . "</a></li>\n";
            }
            //		  $out[] = "</ul>\n";
        }
    }
    return implode('', $out);
}
Пример #24
0
 public function register_taxonomies()
 {
     parent::register_taxonomies();
     foreach (get_object_taxonomies('wp-parser-function') as $taxonomy) {
         register_taxonomy_for_object_type($taxonomy, 'wp-parser-constant');
     }
 }
Пример #25
0
 public static function search_terms($request = null)
 {
     $response = (object) array('status' => false, 'message' => __('Your request has failed', 'fakerpress'), 'results' => array(), 'more' => true);
     if (!Admin::$is_ajax && is_null($request) || !is_user_logged_in()) {
         return Admin::$is_ajax ? exit(json_encode($response)) : $response;
     }
     $request = (object) wp_parse_args($request, array('search' => isset($_POST['search']) ? $_POST['search'] : '', 'post_type' => isset($_POST['post_type']) ? $_POST['post_type'] : null, 'page' => absint(isset($_POST['page']) ? $_POST['page'] : 0), 'page_limit' => absint(isset($_POST['page_limit']) ? $_POST['page_limit'] : 10)));
     if (is_null($request->post_type) || empty($request->post_type)) {
         $request->post_type = get_post_types(array('public' => true));
     }
     $response->status = true;
     $response->message = __('Request successful', 'fakerpress');
     preg_match('/@(\\w+)/i', $request->search, $response->regex);
     if (!empty($response->regex)) {
         $request->search = array_filter(array_map('trim', explode('|', str_replace($response->regex[0], '|', $request->search))));
         $request->search = reset($request->search);
         $taxonomies = $response->regex[1];
     } else {
         $taxonomies = get_object_taxonomies($request->post_type);
     }
     $response->taxonomies = get_object_taxonomies($request->post_type, 'objects');
     $response->results = get_terms((array) $taxonomies, array('hide_empty' => false, 'search' => $request->search, 'number' => $request->page_limit, 'offset' => $request->page_limit * ($request->page - 1)));
     if (empty($response->results) || count($response->results) < $request->page_limit) {
         $response->more = false;
     }
     return Admin::$is_ajax ? exit(json_encode($response)) : $response;
 }
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     if (!is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) {
         return;
     }
     // enqueue necessary scripts
     wp_enqueue_style('wcapf-style');
     wp_enqueue_style('font-awesome');
     wp_enqueue_script('wcapf-script');
     global $wcapf;
     $active_filters = $wcapf->getChosenFilters()['active_filters'];
     $found = false;
     $html = '';
     if (sizeof($active_filters) > 0) {
         $found = true;
         $html .= '<div class="wcapf-active-filters">';
         foreach ($active_filters as $key => $active_filter) {
             if ($key === 'term') {
                 foreach ($active_filter as $data_key => $terms) {
                     foreach ($terms as $term_id => $term_name) {
                         $html .= '<a href="javascript:void(0)" data-key="' . $data_key . '" data-value="' . $term_id . '">' . $term_name . '</a>';
                     }
                 }
             }
             if ($key === 'keyword') {
                 $html .= '<a href="javascript:void(0)" data-key="keyword">' . __('Search For: ', 'wcapf') . $active_filter . '</a>';
             }
             if ($key === 'orderby') {
                 $html .= '<a href="javascript:void(0)" data-key="orderby">' . __('Orderby: ', 'wcapf') . $active_filter . '</a>';
             }
             if ($key === 'min_price') {
                 $html .= '<a href="javascript:void(0)" data-key="min-price">' . __('Min Price: ', 'wcapf') . $active_filter . '</a>';
             }
             if ($key === 'max_price') {
                 $html .= '<a href="javascript:void(0)" data-key="max-price">' . __('Max Price: ', 'wcapf') . $active_filter . '</a>';
             }
         }
         $html .= '</div>';
     }
     extract($args);
     // Add class to before_widget from within a custom widget
     // http://wordpress.stackexchange.com/questions/18942/add-class-to-before-widget-from-within-a-custom-widget
     if ($found === false) {
         $widget_class = 'wcapf-widget-hidden woocommerce wcapf-ajax-term-filter';
     } else {
         $widget_class = 'woocommerce wcapf-ajax-term-filter';
     }
     // no class found, so add it
     if (strpos($before_widget, 'class') === false) {
         $before_widget = str_replace('>', 'class="' . $widget_class . '"', $before_widget);
     } else {
         $before_widget = str_replace('class="', 'class="' . $widget_class . ' ', $before_widget);
     }
     echo $before_widget;
     if (!empty($instance['title'])) {
         echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
     }
     echo $html;
     echo $args['after_widget'];
 }
Пример #27
0
 function wplb_get_taxonomies_by_post_type($post_types = array('post'))
 {
     if (!empty($post_types)) {
         if (is_string($post_types)) {
             $post_types = explode(',', $post_types);
         }
         foreach ($post_types as $post_type) {
             $post_type_object = get_post_type_object($post_type);
             $taxonomies = get_object_taxonomies($post_type);
             if ($taxonomies) {
                 foreach ($taxonomies as $taxonomy) {
                     if (!is_taxonomy_hierarchical($taxonomy)) {
                         continue;
                     }
                     $terms = get_terms($taxonomy, array('hide_empty' => false));
                     if ($terms) {
                         foreach ($terms as $term) {
                             $returns[$term->term_id] = $term->name;
                         }
                     }
                 }
             }
         }
     }
     return $returns;
 }
function frontier_clone_post($fpost_sc_parms = array())
{
    //extract($fpost_sc_parms);
    //echo "CLONE POST<br>";
    $frontier_permalink = get_permalink();
    $concat = get_option("permalink_structure") ? "?" : "&";
    if (isset($_POST['task'])) {
        $post_task = $_POST['task'];
    } else {
        if (isset($_GET['task'])) {
            $post_task = $_GET['task'];
        } else {
            $post_task = "notaskset";
        }
    }
    $post_action = isset($_POST['action']) ? $_POST['action'] : "Unknown";
    if ($post_task == "clone" && $_REQUEST['postid']) {
        $old_post = get_post($_REQUEST['postid']);
        $old_post_id = $old_post->ID;
        //double check current user can add a post with this post type
        if (frontier_can_add($old_post->post_type)) {
            require_once ABSPATH . '/wp-admin/includes/post.php';
            global $current_user;
            //Get permalink from old post
            $old_permalink = get_permalink($old_post_id);
            // lets clone it
            $thispost = get_default_post_to_edit($fpost_sc_parms['frontier_add_post_type'], true);
            $new_post_id = $thispost->ID;
            $tmp_post = array('ID' => $new_post_id, 'post_type' => $old_post->post_type, 'post_title' => __("CLONED from", "frontier-post") . ': <a href="' . $old_permalink . '">' . $old_post->post_title . '</a>', 'post_content' => __("CLONED from", "frontier-post") . ': <a href="' . $old_permalink . '">' . $old_post->post_title . '</a><br>' . $old_post->post_content, 'post_status' => "draft", 'post_author' => $current_user->ID);
            //****************************************************************************************************
            // Apply filter before update of post
            // filter:			frontier_post_clone
            // $tmp_post 		Array that holds the updated fields
            // $old_post  		The post being cloed (Object)
            //****************************************************************************************************
            $tmp_post = apply_filters('frontier_post_clone', $tmp_post, $old_post);
            // save post
            wp_update_post($tmp_post);
            //Get the updated post
            $new_post = get_post($new_post_id);
            //get all current post terms ad set them to the new post draft
            $taxonomies = get_object_taxonomies($old_post->post_type);
            // returns array of taxonomy names for post type, ex array("category", "post_tag");
            foreach ($taxonomies as $taxonomy) {
                $post_terms = wp_get_object_terms($old_post_id, $taxonomy, array('fields' => 'slugs'));
                wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);
            }
            // Set featured image:
            $post_thumbnail_id = get_post_thumbnail_id($old_post_id);
            if (intval($post_thumbnail_id) > 0) {
                set_post_thumbnail($new_post_id, $post_thumbnail_id);
            }
            // Add/Update message
            frontier_post_set_msg(__("Post Cloned and ready edit", "frontier-post") . ": " . $new_post->post_title);
            frontier_post_set_msg(__("Post status set to Draft", "frontier-post"));
            frontier_user_post_list($fpost_sc_parms);
        }
    }
}
Пример #29
0
 /**
  * Add taxonomies whihc should be extended to 'CF Taxonomy Post Type Binding' configutation
  */
 public function setup_extended_taxonomies($configs)
 {
     if (!is_array($configs)) {
         $configs = array();
     }
     $existed_taxonomies = array();
     foreach ($configs as $config) {
         $tax_name = false;
         if (empty($config['taxonomy'])) {
             continue;
         }
         if (is_string($config['taxonomy'])) {
             $tax_name = $config['taxonomy'];
         } else {
             if (is_array($config['taxonomy'])) {
                 $args = count($config['taxonomy']);
                 if (!$args == 3) {
                     continue;
                 } else {
                     if (!is_string($config['taxonomy'][0])) {
                         continue;
                     }
                 }
                 if (taxonomy_exists($config['taxonomy'][0])) {
                     $tax_name = $config['taxonomy'][0];
                 }
             }
         }
         if (!empty($tax_name)) {
             array_push($existed_taxonomies, $tax_name);
         }
     }
     $extended_taxonomies = array();
     foreach ($this->post_types as $post_type) {
         $taxonomies = get_object_taxonomies($post_type);
         if (!empty($taxonomies)) {
             foreach ($taxonomies as $taxonomy) {
                 /* Be sure taxonomy should not be excluded. */
                 if (in_array($taxonomy, $this->exclude)) {
                     continue;
                 }
                 /* Determine if taxonomy already added to the list. */
                 if (in_array($taxonomy, $extended_taxonomies)) {
                     continue;
                 }
                 /* Determine if taxonomy already added to configuration. */
                 if (in_array($taxonomy, $existed_taxonomies)) {
                     continue;
                 }
                 $extended_taxonomies[] = $taxonomy;
             }
         }
     }
     foreach ($extended_taxonomies as $taxonomy) {
         $_taxonomy = get_taxonomy($taxonomy);
         array_push($configs, array('taxonomy' => $taxonomy, 'post_type' => array(substr($taxonomy, 0, 20), array('label' => $_taxonomy->labels->name, 'hierarchical' => $_taxonomy->hierarchical, 'public' => true, 'publicly_queryable' => true, 'show_ui' => false, 'show_in_menu' => false, 'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'custom-fields'))), 'slave_title_editable' => false, 'slave_slug_editable' => false));
     }
     return $configs;
 }
function custom_taxonomies_terms_links()
{
    global $post, $post_id;
    // get post by post id
    $post =& get_post($post->ID);
    // get post type by post
    $post_type = $post->post_type;
    // get post type taxonomies
    $taxonomies = get_object_taxonomies($post_type);
    $return = '';
    foreach ($taxonomies as $taxonomy) {
        if ($taxonomy != 'category' && $taxonomy != 'post_tag') {
            // get the terms related to post
            $terms = get_the_terms($post->ID, $taxonomy);
            if (!empty($terms)) {
                $return .= $taxonomy . ' => ';
                $first = 1;
                foreach ($terms as $term) {
                    if ($first = 1) {
                        $return .= $term->slug;
                        $first = 0;
                    } else {
                        $return .= ',' . $term->slug;
                    }
                }
                $return .= '. ';
            }
        }
    }
    return $return;
}