Exemplo n.º 1
0
 /**
  * Return an instance of this class.
  *
  * @since     3.0.0
  * @return    object    A single instance of this class.
  */
 public static function get_instance()
 {
     // If the single instance hasn't been set, set it now.
     if (null == self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Exemplo n.º 2
0
/**
 * Prepare the available options for the products
 *
 * @since 3.3
 * @return array
 */
function wpas_get_products_options()
{
    $products = array(array('name' => __('Multiple Products', 'awesome-support'), 'id' => 'support_products', 'type' => 'checkbox', 'desc' => __('If you need to provide support for multiple products, please enable this option. You will then be able to add your products.', 'awesome-support'), 'default' => false));
    $ecommerce_synced = WPAS_eCommerce_Integration::get_instance()->plugin;
    if (!is_null($ecommerce_synced)) {
        $plugin_name = ucwords(str_replace(array('-', '_'), ' ', $ecommerce_synced));
        $products[] = array('name' => sprintf(esc_html__('Synchronize %s Products', 'awesome-support'), $plugin_name), 'id' => 'support_products_' . $ecommerce_synced, 'type' => 'checkbox', 'desc' => sprintf(esc_html__('We have detected that you are using the e-commerce plugin %1$s. Would you like to automatically synchronize your e-commerce products with Awesome Support?', 'awesome-support'), $plugin_name), 'default' => true);
        $products[] = array('type' => 'note', 'desc' => wp_kses(sprintf(__('If you just disabled this option and want to remove the previously synchronized products, <a href="%1$s">please use the dedicated option &laquo;Delete Products&raquo;</a>', 'awesome-support'), esc_url(add_query_arg(array('post_type' => 'ticket', 'page' => 'wpas-status', 'tab' => 'tools'), admin_url('edit.php')))), array('a' => array('href' => array(), 'title' => array()))));
        $registered = WPAS_eCommerce_Integration::get_instance()->get_plugins();
        $post_type = $registered[$ecommerce_synced]['post_type'];
        $products[] = array('name' => __('Include Products', 'awesome-support'), 'id' => 'support_products_' . $ecommerce_synced . '_include', 'type' => 'select', 'multiple' => true, 'desc' => esc_html__('Which products do you want to synchronize with Awesome Support (leave blank for all products)', 'awesome-support'), 'options' => wpas_list_pages($post_type), 'default' => '');
        $products[] = array('name' => __('Exclude Products', 'awesome-support'), 'id' => 'support_products_' . $ecommerce_synced . '_exclude', 'type' => 'select', 'multiple' => true, 'desc' => esc_html__('Which products do you want to exclude from synchronization with Awesome Support (leave blank for no exclusion)', 'awesome-support'), 'options' => wpas_list_pages($post_type), 'default' => '');
        $products[] = array('type' => 'note', 'desc' => esc_html__('You cannot use the include and exclude options at the same time. Please use one or the other. You should use the option where you need to select the least amount of products.', 'awesome-support'));
    }
    return $products;
}
Exemplo n.º 3
0
 /**
  * Get taxonomy terms.
  *
  * Hooked on the get_terms() function and returns the post type
  * posts instead of the actual taxonomy terms.
  *
  * @since  3.0.2
  *
  * @param  array        $terms      Taxonomy terms
  * @param  array|string $taxonomies Taxonomies for which to retrieve the terms
  * @param  array        $args       Additional arguments
  *
  * @return array                     Array of term objects
  */
 public function get_terms($terms, $taxonomies, $args)
 {
     /* If taxonomy name is string, convert to array */
     if (!is_array($taxonomies)) {
         $taxonomies = array($taxonomies);
     }
     // Check if the product taxonomy is one of the taxonomies being queried in this instance. If not, then we immediately return the unchanged terms array
     if (!in_array($this->taxonomy, $taxonomies)) {
         return $terms;
     }
     $slug = WPAS_eCommerce_Integration::get_instance()->plugin;
     $include = array_filter(wpas_get_option('support_products_' . $slug . '_include', array()));
     // Because of the "None" option, the option returns an array with an empty value if none is selected. We need to filter that
     $exclude = array_filter(wpas_get_option('support_products_' . $slug . '_exclude', array()));
     /* Map the tax args to the WP_Query args */
     $query_args = $this->map_args($args);
     $query_defaults = array('post_type' => $this->post_type, 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'title', 'ignore_sticky_posts' => false, 'posts_per_page' => -1, 'perm' => 'readable', 'no_found_rows' => true, 'cache_results' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false);
     $query_args = wp_parse_args($query_args, $query_defaults);
     if (!empty($include)) {
         $query_args['post__in'] = $include;
     }
     if (!empty($exclude)) {
         $query_args['post__not_in'] = $exclude;
     }
     $query = new WP_Query($query_args);
     if (false === get_option("wpas_sync_{$this->post_type}", false)) {
         $this->run_initial_sync();
     }
     if (isset($query_args['wpas_get_post_count']) && $query_args['wpas_get_post_count']) {
         return $this->append ? $query->post_count + count($terms) : $query->post_count;
     }
     if (empty($query->posts)) {
         return $terms;
     }
     // We need to "index" the posts in order to be able to easily compare them to the terms
     $index = array();
     foreach ($query->posts as $post) {
         $index[$post->ID] = $post;
     }
     // We will store the new terms in this array
     $new_terms = array();
     // Now go go through each term, maybe update it, and add it to the final terms array
     foreach ($terms as $term) {
         // If the term is a synchronized product we build the custom term object
         if ($this->is_synced_term($term) && array_key_exists($term->name, $index)) {
             $term = $this->create_term_object($index[$term->name]);
         }
         if (false !== $term) {
             $new_terms[] = apply_filters('wpas_get_terms_term', $term, $this->taxonomy);
         }
     }
     return apply_filters('wpas_get_terms', $new_terms);
 }