Example #1
1
 /**
  * Get comments
  *
  * @since 0.0.1
  *
  * @param array $data Sanitized data from request
  *
  * @return array
  */
 public static function get_comments($data)
 {
     $args = api_helper::get_comment_args($data['postID']);
     $options = options::get_display_options();
     $comments = get_comments($args);
     if ('ASC' == $options['order']) {
         $parents = array_combine(wp_list_pluck($comments, 'comment_ID'), wp_list_pluck($comments, 'comment_parent'));
         asort($parents);
         $comments = (array) $comments;
         $comments = array_combine(wp_list_pluck($comments, 'comment_ID'), $comments);
         $i = 0;
         foreach ($comments as $id => $parent) {
             $_comments[$i] = $comments[$id];
             $i++;
         }
         rsort($_comments);
         $comments = $_comments;
     }
     if (!empty($comments) && is_array($comments)) {
         $comments = api_helper::improve_comment_response($comments, !api_helper::thread());
         $comments = wp_json_encode($comments);
     } else {
         return false;
     }
     return array('comments' => $comments);
 }
 /**
  * @ticket 26948
  */
 public function test_dont_process_terms_if_taxonomy_does_not_allow_show_on_quick_edit()
 {
     register_taxonomy('wptests_tax_1', 'post', array('show_in_quick_edit' => false, 'hierarchical' => true));
     register_taxonomy('wptests_tax_2', 'post', array('show_in_quick_edit' => true, 'hierarchical' => true));
     $t1 = self::factory()->term->create(array('taxonomy' => 'wptests_tax_1'));
     $t2 = self::factory()->term->create(array('taxonomy' => 'wptests_tax_2'));
     // Become an administrator.
     $this->_setRole('administrator');
     $post = self::factory()->post->create_and_get(array('post_author' => get_current_user_id()));
     // Set up a request.
     $_POST['_inline_edit'] = wp_create_nonce('inlineeditnonce');
     $_POST['post_ID'] = $post->ID;
     $_POST['post_type'] = $post->post_type;
     $_POST['content'] = $post->post_content;
     $_POST['excerpt'] = $post->post_excerpt;
     $_POST['_status'] = $post->post_status;
     $_POST['post_status'] = $post->post_status;
     $_POST['screen'] = 'post';
     $_POST['post_view'] = 'excerpt';
     $_POST['tax_input'] = array('wptests_tax_1' => array($t1), 'wptests_tax_2' => array($t2));
     // Make the request.
     try {
         $this->_handleAjax('inline-save');
     } catch (WPAjaxDieContinueException $e) {
         unset($e);
     }
     // wptests_tax_1 terms should have been refused.
     $post_terms_1 = wp_get_object_terms($post->ID, 'wptests_tax_1');
     $this->assertEmpty($post_terms_1);
     // wptests_tax_2 terms should have been added successfully.
     $post_terms_2 = wp_get_object_terms($post->ID, 'wptests_tax_2');
     $this->assertEqualSets(array($t2), wp_list_pluck($post_terms_2, 'term_id'));
 }
 /**
  * Get all data needed for this report and store in the class
  */
 private function query_report_data()
 {
     $this->report_data = new stdClass();
     $this->report_data->orders = (array) $this->get_order_report_data(array('data' => array('_order_total' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_sales'), '_order_shipping' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_shipping'), '_order_tax' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_tax'), '_order_shipping_tax' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_shipping_tax'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => array_merge(array('shop_order_refund'), wc_get_order_types('sales-reports')), 'order_status' => array('completed', 'processing', 'on-hold'), 'parent_order_status' => array('completed', 'processing', 'on-hold')));
     $this->report_data->order_counts = (array) $this->get_order_report_data(array('data' => array('ID' => array('type' => 'post_data', 'function' => 'COUNT', 'name' => 'count', 'distinct' => true), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('completed', 'processing', 'on-hold')));
     $this->report_data->coupons = (array) $this->get_order_report_data(array('data' => array('order_item_name' => array('type' => 'order_item', 'function' => '', 'name' => 'order_item_name'), 'discount_amount' => array('type' => 'order_item_meta', 'order_item_type' => 'coupon', 'function' => 'SUM', 'name' => 'discount_amount'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'where' => array(array('key' => 'order_items.order_item_type', 'value' => 'coupon', 'operator' => '=')), 'group_by' => $this->group_by_query . ', order_item_name', 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('completed', 'processing', 'on-hold')));
     $this->report_data->order_items = (array) $this->get_order_report_data(array('data' => array('_qty' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'order_item_count'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'where' => array(array('key' => 'order_items.order_item_type', 'value' => 'line_item', 'operator' => '=')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('completed', 'processing', 'on-hold')));
     $this->report_data->refunded_order_items = (array) $this->get_order_report_data(array('data' => array('_qty' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'order_item_count'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'where' => array(array('key' => 'order_items.order_item_type', 'value' => 'line_item', 'operator' => '=')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('refunded')));
     $this->report_data->partial_refunds = (array) $this->get_order_report_data(array('data' => array('_refund_amount' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_refund'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date'), '_qty' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'order_item_count')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_status' => false, 'parent_order_status' => array('completed', 'processing', 'on-hold')));
     foreach ($this->report_data->partial_refunds as $key => $value) {
         $this->report_data->partial_refunds[$key]->order_item_count = $this->report_data->partial_refunds[$key]->order_item_count * -1;
     }
     $this->report_data->order_items = array_merge($this->report_data->order_items, $this->report_data->partial_refunds);
     $this->report_data->total_order_refunds = array_sum((array) absint($this->get_order_report_data(array('data' => array('ID' => array('type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders')), 'query_type' => 'get_var', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('refunded')))));
     $this->report_data->full_refunds = (array) $this->get_order_report_data(array('data' => array('_order_total' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_refund'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_status' => array('refunded')));
     $this->report_data->refunds = array_merge($this->report_data->partial_refunds, $this->report_data->full_refunds);
     $this->report_data->total_sales = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->orders, 'total_sales')), 2);
     $this->report_data->total_tax = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->orders, 'total_tax')), 2);
     $this->report_data->total_shipping = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->orders, 'total_shipping')), 2);
     $this->report_data->total_shipping_tax = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->orders, 'total_shipping_tax')), 2);
     $this->report_data->total_refunds = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->partial_refunds, 'total_refund')) + array_sum(wp_list_pluck($this->report_data->full_refunds, 'total_refund')), 2);
     $this->report_data->total_coupons = number_format(array_sum(wp_list_pluck($this->report_data->coupons, 'discount_amount')), 2);
     $this->report_data->total_orders = absint(array_sum(wp_list_pluck($this->report_data->order_counts, 'count')));
     $this->report_data->total_partial_refunds = array_sum(wp_list_pluck($this->report_data->partial_refunds, 'order_item_count')) * -1;
     $this->report_data->total_item_refunds = array_sum(wp_list_pluck($this->report_data->refunded_order_items, 'order_item_count')) * -1;
     $this->report_data->total_items = absint(array_sum(wp_list_pluck($this->report_data->order_items, 'order_item_count')) * -1);
     $this->report_data->average_sales = wc_format_decimal($this->report_data->total_sales / ($this->chart_interval + 1), 2);
     $this->report_data->net_sales = wc_format_decimal($this->report_data->total_sales - $this->report_data->total_shipping - $this->report_data->total_tax - $this->report_data->total_shipping_tax, 2);
 }
 public static function bulky_woocommerce_cart_shipping_packages($packages)
 {
     // Reset the packages
     $packages = array();
     // Bulky items
     $free_items = array();
     $regular_items = array();
     // Sort free from others
     foreach (WC()->cart->get_cart() as $item) {
         if ($item['data']->needs_shipping()) {
             if ($item['data']->get_shipping_class() == 'free' || $item['data']->get_shipping_class() == '') {
                 $free_items[] = $item;
             } else {
                 $regular_items[] = $item;
             }
         }
     }
     // Put inside packages
     if ($free_items) {
         $packages[] = array('ship_via' => array('free_shipping'), 'contents' => $free_items, 'contents_cost' => array_sum(wp_list_pluck($free_items, 'line_total')), 'applied_coupons' => WC()->cart->applied_coupons, 'destination' => array('country' => WC()->customer->get_shipping_country(), 'state' => WC()->customer->get_shipping_state(), 'postcode' => WC()->customer->get_shipping_postcode(), 'city' => WC()->customer->get_shipping_city(), 'address' => WC()->customer->get_shipping_address(), 'address_2' => WC()->customer->get_shipping_address_2()));
     }
     if ($regular_items) {
         $packages[] = array('ship_via' => array('flat_rate'), 'contents' => $regular_items, 'contents_cost' => array_sum(wp_list_pluck($regular_items, 'line_total')), 'applied_coupons' => WC()->cart->applied_coupons, 'destination' => array('country' => WC()->customer->get_shipping_country(), 'state' => WC()->customer->get_shipping_state(), 'postcode' => WC()->customer->get_shipping_postcode(), 'city' => WC()->customer->get_shipping_city(), 'address' => WC()->customer->get_shipping_address(), 'address_2' => WC()->customer->get_shipping_address_2()));
     }
     return $packages;
 }
Example #5
0
 /**
  * List terms in a taxonomy.
  *
  * ## OPTIONS
  *
  * <taxonomy>...
  * : List terms of one or more taxonomies
  *
  * [--<field>=<value>]
  * : Filter by one or more fields (see get_terms() $args parameter for a list of fields).
  *
  * [--field=<field>]
  * : Prints the value of a single field for each term.
  *
  * [--fields=<fields>]
  * : Limit the output to specific object fields.
  *
  * [--format=<format>]
  * : Accepted values: table, csv, json, count, yaml. Default: table
  *
  * ## AVAILABLE FIELDS
  *
  * These fields will be displayed by default for each term:
  *
  * * term_id
  * * term_taxonomy_id
  * * name
  * * slug
  * * description
  * * parent
  * * count
  *
  * There are no optionally available fields.
  *
  * ## EXAMPLES
  *
  *     wp term list category --format=csv
  *
  *     wp term list post_tag --fields=name,slug
  *
  * @subcommand list
  */
 public function list_($args, $assoc_args)
 {
     foreach ($args as $taxonomy) {
         if (!taxonomy_exists($taxonomy)) {
             WP_CLI::error("Taxonomy {$taxonomy} doesn't exist.");
         }
     }
     $formatter = $this->get_formatter($assoc_args);
     $defaults = array('hide_empty' => false);
     $assoc_args = array_merge($defaults, $assoc_args);
     if (!empty($assoc_args['term_id'])) {
         $term = get_term_by('id', $assoc_args['term_id'], $args[0]);
         $terms = array($term);
     } else {
         $terms = get_terms($args, $assoc_args);
     }
     $terms = array_map(function ($term) {
         $term->count = (int) $term->count;
         $term->parent = (int) $term->parent;
         return $term;
     }, $terms);
     if ('ids' == $formatter->format) {
         $terms = wp_list_pluck($terms, 'term_id');
         echo implode(' ', $terms);
     } else {
         $formatter->display_items($terms);
     }
 }
Example #6
0
 public function get_pages($pages, $args)
 {
     $language = empty($args['lang']) ? $this->curlang : $this->model->get_language($args['lang']);
     if (empty($language) || empty($pages) || !$this->model->is_translated_post_type($args['post_type'])) {
         return $pages;
     }
     static $once = false;
     // obliged to redo the get_pages query if we want to get the right number
     if (!empty($args['number']) && !$once) {
         $once = true;
         // avoid infinite loop
         $r = array('lang' => 0, 'numberposts' => -1, 'nopaging' => true, 'post_type' => $args['post_type'], 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'language', 'field' => 'term_taxonomy_id', 'terms' => $language->term_taxonomy_id, 'operator' => 'NOT IN')));
         $args['exclude'] = array_merge($args['exclude'], get_posts($r));
         $pages = get_pages($args);
     }
     $ids = wp_list_pluck($pages, 'ID');
     // filters the queried list of pages by language
     if (!$once) {
         $ids = array_intersect($ids, $this->model->get_objects_in_language($language));
         foreach ($pages as $key => $page) {
             if (!in_array($page->ID, $ids)) {
                 unset($pages[$key]);
             }
         }
     }
     // not done by WP but extremely useful for performance when manipulating taxonomies
     update_object_term_cache($ids, $args['post_type']);
     $once = false;
     // in case get_pages is called another time
     return $pages;
 }
/**
 * Wrapper for wp_get_post_terms which supports ordering by parent.
 *
 * NOTE: At this point in time, ordering by menu_order for example isn't possible with this function. wp_get_post_terms has no
 *   filters which we can utilise to modify it's query. https://core.trac.wordpress.org/ticket/19094
 * 
 * @param  int $product_id
 * @param  string $taxonomy
 * @param  array  $args
 * @return array
 */
function wc_get_product_terms($product_id, $taxonomy, $args = array())
{
    if (!taxonomy_exists($taxonomy)) {
        return array();
    }
    if (empty($args['orderby']) && taxonomy_is_product_attribute($taxonomy)) {
        $args['orderby'] = wc_attribute_orderby($taxonomy);
    }
    // Support ordering by parent
    if (!empty($args['orderby']) && $args['orderby'] == 'parent') {
        $fields = isset($args['fields']) ? $args['fields'] : 'all';
        // Unset for wp_get_post_terms
        unset($args['orderby']);
        unset($args['fields']);
        $terms = wp_get_post_terms($product_id, $taxonomy, $args);
        usort($terms, '_wc_get_product_terms_parent_usort_callback');
        switch ($fields) {
            case 'names':
                $terms = wp_list_pluck($terms, 'name');
                break;
            case 'ids':
                $terms = wp_list_pluck($terms, 'term_id');
                break;
            case 'slugs':
                $terms = wp_list_pluck($terms, 'slug');
                break;
        }
    } else {
        $terms = wp_get_post_terms($product_id, $taxonomy, $args);
    }
    return $terms;
}
Example #8
0
 /**
  * @ticket BP7237
  * @ticket BP6643
  * @ticket BP7245
  */
 public function test_last_activity_should_bust_activity_with_last_activity_cache()
 {
     global $wpdb;
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $time_1 = date('Y-m-d H:i:s', time() - HOUR_IN_SECONDS);
     $time_2 = date('Y-m-d H:i:s', time() - HOUR_IN_SECONDS * 2);
     bp_update_user_last_activity($u1, $time_1);
     bp_update_user_last_activity($u2, $time_2);
     $activity_args_a = array('filter' => array('object' => buddypress()->members->id, 'action' => 'last_activity'), 'max' => 1);
     $activity_args_b = array('filter' => array('action' => 'new_member'), 'fields' => 'ids');
     // Prime bp_activity and bp_activity_with_last_activity caches.
     $a1 = bp_activity_get($activity_args_a);
     $expected = array($u1, $u2);
     $found = array_map('intval', wp_list_pluck($a1['activities'], 'user_id'));
     $this->assertSame($expected, $found);
     $b1 = bp_activity_get($activity_args_b);
     // Bump u2 activity so it should appear first.
     $new_time = date('Y-m-d H:i:s', time() - HOUR_IN_SECONDS);
     bp_update_user_last_activity($u2, $new_time);
     $a2 = bp_activity_get($activity_args_a);
     $expected = array($u2, $u1);
     $found = array_map('intval', wp_list_pluck($a2['activities'], 'user_id'));
     $this->assertSame($expected, $found);
     $num_queries = $wpdb->num_queries;
     // bp_activity cache should not have been touched.
     $b2 = bp_activity_get($activity_args_b);
     $this->assertEqualSets($b1, $b2);
     $this->assertSame($num_queries, $wpdb->num_queries);
 }
Example #9
0
/**
 * Return array of notice alerts
 *
 * @since 0.1.0
 *
 * @return array
 */
function wp_user_alerts_get_notices()
{
    // Dismissed notices are excluded
    $dismissed = wp_list_pluck(wp_user_alerts_get_dismissed_notices(), 'ID');
    // Get alerts
    return wp_user_alerts_get_posts(array('numberposts' => 10, 'exclude' => $dismissed, 'meta_query' => wp_user_alerts_get_meta_query(array('user' => wp_user_alerts_get_meta_query_user(), 'role' => wp_user_alerts_get_meta_query_role(), 'method' => 'notice'))));
}
/**
 * Adds a single registration entry. This is a motley function.
 *
 * @param string The status of the registration record.
 **/
function thatcamp_registrations_add_registration($status = 'pending')
{
    global $wpdb;
    $table = $wpdb->prefix . "thatcamp_registrations";
    $_POST = stripslashes_deep($_POST);
    // The user_id is set to the posted user ID, or null.
    $user_id = isset($_POST['user_id']) ? $_POST['user_id'] : null;
    $applicant_info = array();
    $applicant_fields = wp_list_pluck(thatcamp_registrations_fields(), 'id');
    foreach ($applicant_fields as $field) {
        $applicant_info[$field] = isset($_POST[$field]) ? $_POST[$field] : null;
    }
    $date = isset($_POST['date']) ? $_POST['date'] : null;
    $applicationText = isset($_POST['application_text']) ? $_POST['application_text'] : null;
    // Lets serialize the applicant_info before putting it in the database.
    $applicant_info = maybe_serialize($applicant_info);
    $applicant_email = isset($_POST['user_email']) ? $_POST['user_email'] : null;
    // Check for an existing registration
    $user_exists = false;
    if (!is_null($user_id) && thatcamp_registrations_get_registration_by_user_id($user_id) || thatcamp_registrations_get_registration_by_applicant_email($applicant_email)) {
        $user_exists = true;
    }
    if ($user_exists) {
        return 'You have already submitted your registration.';
    } else {
        $reg_id = $wpdb->insert($table, array('applicant_info' => $applicant_info, 'applicant_email' => $applicant_email, 'application_text' => $applicationText, 'status' => $status, 'date' => $date, 'user_id' => $user_id));
        thatcamp_registrations_send_applicant_email($applicant_email);
        thatcamp_registrations_send_admin_notification($wpdb->insert_id);
    }
}
	function test_category__and_var() {
		$term_id = $this->factory->category->create( array( 'slug' => 'woo', 'name' => 'WOO!' ) );
		$term_id2 = $this->factory->category->create( array( 'slug' => 'hoo', 'name' => 'HOO!' ) );
		$post_id = $this->factory->post->create();

		wp_set_post_categories( $post_id, $term_id );

		$posts = $this->q->query( array( 'category__and' => array( $term_id ) ) );

		$this->assertEmpty( $this->q->get( 'category__and' ) );
		$this->assertCount( 0, $this->q->get( 'category__and' ) );
		$this->assertNotEmpty( $this->q->get( 'category__in' ) );
		$this->assertCount( 1, $this->q->get( 'category__in' ) );

		$this->assertNotEmpty( $posts );
		$this->assertEquals( array( $post_id ), wp_list_pluck( $posts, 'ID' ) );

		$posts2 = $this->q->query( array( 'category__and' => array( $term_id, $term_id2 ) ) );
		$this->assertNotEmpty( $this->q->get( 'category__and' ) );
		$this->assertCount( 2, $this->q->get( 'category__and' ) );
		$this->assertEmpty( $this->q->get( 'category__in' ) );
		$this->assertCount( 0, $this->q->get( 'category__in' ) );

		$this->assertEmpty( $posts2 );
	}
 /**
  * Check whether settings has particular field type
  *
  * @param string field type
  * @return bool
  */
 function has_field_type($type)
 {
     if (in_array($type, wp_list_pluck($this->settings['fields'], 'type'))) {
         return true;
     }
     return false;
 }
 /**
  * Add Plugin License Menu
  *
  * @since 1.5.6
  */
 function license_menu()
 {
     global $submenu;
     if (isset($submenu[$this->main_menu_slug]) && !in_array($this->license_page_slug, wp_list_pluck($submenu[$this->main_menu_slug], 2))) {
         add_submenu_page($this->main_menu_slug, __('Plugin License', 'feed-them-social'), __('Plugin License', 'feed-them-social'), 'manage_options', $this->license_page_slug, array($this, 'license_page'));
     }
 }
Example #14
0
 function init()
 {
     //move away from kl_ prefix
     $opts = get_option('kl_addnewdefaultavatar', false);
     if ($opts) {
         update_option('add_new_default_avatar', $opts);
         delete_option('kl_addnewdefaultavatar');
     }
     $opts = get_option('add_new_default_avatar', false);
     //upgrade option, we can now save multiple avatar options
     if (isset($opts['name'])) {
         $opts = array($opts);
         update_option('add_new_default_avatar', $opts);
     }
     if (!$opts) {
         return;
     }
     //get current default opton
     $current = get_option('avatar_default');
     //get any custom created avatars
     $unavailable = wp_list_pluck($opts, 'url');
     //if the current wasn't created by this plugin, update the backup
     if (!in_array($current, $unavailable)) {
         update_option('pre_anda_avatar_default', $current);
     }
 }
 protected function display_posts_filter($args = array())
 {
     $default_args = array('post_type' => 'post', 'taxonomy' => 'category', 'query' => null, 'select' => 'all', 'show_category_filter' => true);
     $args = wp_parse_args($args, $default_args);
     $filter_args = array();
     if ($args['show_category_filter']) {
         // categorizer args
         $filter_args = array('taxonomy' => $args['taxonomy'], 'post_type' => $args['post_type'], 'select' => $args['select']);
         if ('only' == $args['select'] && $args['query'] && $args['query']->posts && isset($args['query']->tax_query->queried_terms[$args['taxonomy']]['terms'])) {
             $filter_args['terms'] = array();
             $queried_terms = $args['query']->tax_query->queried_terms[$args['taxonomy']]['terms'];
             $posts_ids = wp_list_pluck($args['query']->posts, 'ID');
             $posts_terms = wp_get_object_terms($posts_ids, $args['taxonomy']);
             foreach ($posts_terms as $term) {
                 if (in_array($term->slug, $queried_terms)) {
                     $filter_args['terms'][] = intval($term->term_id);
                 }
             }
             $filter_args['terms'] = array_unique($filter_args['terms']);
         }
     }
     $filter_class = '';
     if (!$this->config->get('template.posts_filter.orderby.enabled') && !$this->config->get('template.posts_filter.order.enabled')) {
         $filter_class .= ' extras-off';
     }
     // display categorizer
     presscore_get_category_list(array('data' => dt_prepare_categorizer_data($filter_args), 'class' => 'filter iso-filter' . $filter_class));
 }
Example #16
0
 /**
  * Create meta box based on given data
  *
  * @see demo/demo.php file for details
  *
  * @param array $meta_box Meta box definition
  *
  * @return \RW_Meta_Box
  */
 function __construct($meta_box)
 {
     // Run script only in admin area
     if (!is_admin()) {
         return;
     }
     // Assign meta box values to local variables and add it's missed values
     $this->meta_box = self::normalize($meta_box);
     $this->fields =& $this->meta_box['fields'];
     $this->validation =& $this->meta_box['validation'];
     // List of meta box field types
     $this->types = array_unique(wp_list_pluck($this->fields, 'type'));
     // Enqueue common styles and scripts
     add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
     foreach ($this->types as $type) {
         $class = self::get_class_name($type);
         // Add additional actions for fields
         if (method_exists($class, 'add_actions')) {
             call_user_func(array($class, 'add_actions'));
         }
     }
     // Add meta box
     foreach ($this->meta_box['pages'] as $page) {
         add_action("add_meta_boxes_{$page}", array($this, 'add_meta_boxes'));
     }
     // Save post meta
     add_action('save_post', array($this, 'save_post'));
 }
 public function test_static_front_page_search()
 {
     $this->tearDown();
     $this->setUp();
     $en_fp = $this->factory->post->create_and_get(array('post_type' => 'page', 'post_title' => 'Front Page'));
     update_option('show_on_front', 'page');
     update_option('page_on_front', $en_fp->ID);
     $uk_fp = $this->create_post_translation($en_fp, 'en_GB');
     $fr_fp = $this->create_post_translation($en_fp, 'fr_FR');
     $posts = $this->create_test_posts();
     // We shouldn't need to test all search scenarios in the context
     // of a static front page
     // UBIQUITOUS_WORD should be present in both US English posts
     $this->go_to('/en/?s=UBIQUITOUS_WORD');
     $matching_post_ids = wp_list_pluck($GLOBALS['wp_query']->posts, 'ID');
     $expected_post_ids = wp_list_pluck(array($posts['en1'], $posts['en2']), 'ID');
     $this->assertEqualSets($expected_post_ids, $matching_post_ids);
     // UNIQUE_WORD_2 should only be in the second US English post
     $this->go_to('/en/?s=UNIQUE_WORD_2_EN_US');
     $matching_post_ids = wp_list_pluck($GLOBALS['wp_query']->posts, 'ID');
     $expected_post_ids = wp_list_pluck(array($posts['en2']), 'ID');
     $this->assertEqualSets($expected_post_ids, $matching_post_ids);
     $this->set_post_types_to_locale('fr_FR');
     // UNIQUE_WORD_2_FR_FR should only be in the second French post
     $this->go_to('/fr/?s=UNIQUE_WORD_2_FR_FR');
     $matching_post_ids = wp_list_pluck($GLOBALS['wp_query']->posts, 'ID');
     $expected_post_ids = wp_list_pluck(array($posts['fr2']), 'ID');
     $this->assertEqualSets($expected_post_ids, $matching_post_ids);
 }
 public function status()
 {
     if ($this->_status) {
         return $this->_status;
     }
     $info = get_plugins();
     $installed = array_flip(wp_list_pluck($info, 'PluginURI'));
     foreach ($this->plugins as $plugin) {
         $slug = $plugin->slug;
         $stat["link"] = false;
         if (isset($installed[$slug])) {
             $file = $installed[$slug];
             $this->installed[$file] = true;
             $stat["file"] = $file;
             $stat["version"] = $info[$file]["Version"];
             if (is_plugin_active($file)) {
                 // active
                 $stat["status"] = "active";
             } else {
                 // installed
                 $stat["status"] = "installed";
                 $stat["link"] = wp_nonce_url(self_admin_url("plugins.php?action=activate&peredirect=1&plugin={$file}"), "activate-plugin_{$file}");
             }
         } else {
             // not installed
             $stat["status"] = "not-installed";
             $stat["link"] = wp_nonce_url(self_admin_url("update.php?action=install-plugin&peredirect=1&plugin={$slug}"), "install-plugin_{$slug}");
         }
         $res[$slug] = (object) $stat;
     }
     // cache result
     $this->_status = $res;
     return $res;
 }
Example #19
0
 static function unplaceholdit($template, $content, $object_key = 'object')
 {
     /** Early bailout? */
     if (strpos($template, '%%') === false) {
         return $template;
     }
     /** First, get a list of all placeholders. */
     $matches = $replaces = array();
     preg_match_all('/%%([^%]+)%%/u', $template, $matches, PREG_SET_ORDER);
     $searches = wp_list_pluck($matches, 0);
     /* Cast the object */
     $object = array_key_exists($object_key, $content) ? (array) $content[$object_key] : false;
     foreach ($matches as $match) {
         /**
          * 0 => %%template_tag%%
          * 1 => variable_name
          */
         if ($object && isset($object[$match[1]])) {
             array_push($replaces, $object[$match[1]]);
         } else {
             if (isset($content[$match[1]])) {
                 array_push($replaces, $content[$match[1]]);
             } else {
                 array_push($replaces, $match[0]);
             }
         }
     }
     return str_replace($searches, $replaces, $template);
 }
 public function fetch_items()
 {
     global $wpdb;
     $vars = array(WPSC_Purchase_Log::ACCEPTED_PAYMENT, WPSC_Purchase_Log::JOB_DISPATCHED, WPSC_Purchase_Log::CLOSED_ORDER, get_current_user_id());
     /* @todo: seems all we use here is fileid and product_id.  Investigate benchmarking selecting only those two columns. */
     $sql = $wpdb->prepare("\n\t\t\tSELECT\n\t\t\t\td.*\n\t\t\tFROM " . WPSC_TABLE_DOWNLOAD_STATUS . " AS d\n\t\t\tINNER JOIN " . WPSC_TABLE_PURCHASE_LOGS . " AS p\n\t\t\tON\n\t\t\t\td.purchid = p.id\n\t\t\tWHERE\n\t\t\t\td.active = 1 AND\n\t\t\t\tp.processed IN (%d, %d, %d) AND\n\t\t\t\tp.user_ID = %d\n\t\t\tORDER BY p.id DESC\n\t\t", $vars);
     $downloadables = $wpdb->get_results($sql);
     $product_ids = wp_list_pluck($downloadables, 'product_id');
     $product_ids = array_unique(array_map('absint', $product_ids));
     $this->items = get_posts(array('post_type' => 'wpsc-product', 'post__in' => $product_ids));
     $this->total_items = count($this->items);
     $this->digital_items = array();
     foreach ($downloadables as $file) {
         if (!in_array($file->product_id, $product_ids)) {
             continue;
         }
         if (!array_key_exists($file->product_id, $this->digital_items)) {
             $this->digital_items[$file->product_id] = array();
         }
         $this->digital_items[$file->product_id][] = $file;
     }
     // cache files
     $files = wp_list_pluck($downloadables, 'fileid');
     get_posts(array('post_type' => 'wpsc-product-file', 'post__in' => $files));
 }
 /**
  * Test the whole array as input
  */
 public function test_urlencode_deep_should_encode_all_values_in_array()
 {
     $data = $this->data_test_values();
     $actual = wp_list_pluck($data, 0);
     $expected = wp_list_pluck($data, 1);
     $this->assertEquals($expected, urlencode_deep($actual));
 }
	function test_wp_list_pluck() {
		$list = wp_list_pluck( $this->object_list, 'name' );
		$this->assertEquals( array( 'foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz' ) , $list );

		$list = wp_list_pluck( $this->array_list, 'name' );
		$this->assertEquals( array( 'foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz' ) , $list );
	}
Example #23
0
 /**
  * Pre-populates the p2p meta cache to decrease the number of queries.
  */
 static function cache_p2p_meta($the_posts, $wp_query)
 {
     if (isset($wp_query->_p2p_query) && !empty($the_posts)) {
         update_meta_cache('p2p', wp_list_pluck($the_posts, 'p2p_id'));
     }
     return $the_posts;
 }
 static function add_attachment_fields_to_edit($form_fields, $post)
 {
     $terms = get_object_term_cache($post->ID, self::TAXONOMY);
     $field = array();
     $taxonomy_obj = (array) get_taxonomy(self::TAXONOMY);
     if (!$taxonomy_obj['public'] || !$taxonomy_obj['show_ui']) {
         continue;
     }
     if (false === $terms) {
         $terms = wp_get_object_terms($post->ID, self::TAXONOMY);
     }
     $values = wp_list_pluck($terms, 'term_id');
     ob_start();
     wp_terms_checklist($post->ID, array('taxonomy' => self::TAXONOMY, 'checked_ontop' => false, 'walker' => new Walker_WP_Media_Taxonomy_Checklist($post->ID)));
     $output = ob_get_clean();
     if (!empty($output)) {
         $output = '<ul class="term-list">' . $output . '</ul>';
         $output .= wp_nonce_field('save_attachment_media_categories', 'media_category_nonce', false, false);
     } else {
         $output = '<ul class="term-list"><li>No ' . $taxonomy_obj['label'] . '</li></ul>';
     }
     $field = array('label' => !empty($taxonomy_obj['label']) ? $taxonomy_obj['label'] : self::TAXONOMY, 'value' => join(', ', $values), 'show_in_edit' => false, 'input' => 'html', 'html' => $output);
     $form_fields[self::TAXONOMY] = $field;
     return $form_fields;
 }
Example #25
0
 /**
  * Create meta box based on given data
  *
  * @see demo/demo.php file for details
  *
  * @param array $meta_box Meta box definition
  *
  * @return \RW_Meta_Box
  */
 function __construct($meta_box)
 {
     // Run script only in admin area
     if (!is_admin()) {
         return;
     }
     // Assign meta box values to local variables and add it's missed values
     $this->meta_box = self::normalize($meta_box);
     $this->fields =& $this->meta_box['fields'];
     // List of meta box field types
     $this->types = array_unique(wp_list_pluck($this->fields, 'type'));
     // Load translation file
     // Call directly because we define meta boxes in 'admin_init' hook (@see demo/demo.php)
     // So the function won't run if we use 'add_action' to load textdomain here
     self::load_textdomain();
     // Enqueue common styles and scripts
     add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
     foreach ($this->types as $type) {
         $class = self::get_class_name($type);
         // Add additional actions for fields
         if (method_exists($class, 'add_actions')) {
             call_user_func(array($class, 'add_actions'));
         }
     }
     // Add meta box
     foreach ($this->meta_box['pages'] as $page) {
         add_action("add_meta_boxes_{$page}", array(&$this, 'add_meta_boxes'));
     }
     // Save post meta
     add_action('save_post', array(&$this, 'save_post'));
 }
 function widget($args, $instance)
 {
     if (!isset($args['widget_id'])) {
         $args['widget_id'] = $this->id;
     }
     $output = '';
     $title = !empty($instance['title']) ? $instance['title'] : __('Recent Comments');
     $title = apply_filters('widget_title', $title, $instance, $this->id_base);
     $number = !empty($instance['number']) ? absint($instance['number']) : 5;
     if (!$number) {
         $number = 5;
     }
     $comments = get_comments(apply_filters('widget_comments_args', array('number' => $number, 'status' => 'approve', 'post_status' => 'publish')));
     $output .= $args['before_widget'];
     if ($title) {
         $output .= $args['before_title'] . $title . $args['after_title'];
     }
     $output .= '<ul id="recentcomments">';
     if (is_array($comments) && $comments) {
         $post_ids = array_unique(wp_list_pluck($comments, 'comment_post_ID'));
         _prime_post_caches($post_ids, strpos(get_option('permalink_structure'), '%category%'), false);
         foreach ((array) $comments as $comment) {
             $title = get_the_title($comment->comment_post_ID);
             $output .= '<li class="recentcomments"><i class="fa fa-comments">&nbsp;</i> ';
             $output .= sprintf(_x('%1$s on %2$s', 'widgets'), '<span class="comment-author-link"><strong> ' . get_comment_author_link($comment) . '</strong></span>', '<br><a href="' . esc_url(get_comment_link($comment)) . '">' . $title . '</a>');
             $output .= '</li>';
         }
     }
     $output .= '</ul>';
     $output .= $args['after_widget'];
     echo $output;
 }
 function get_views()
 {
     $modules = Jetpack_Admin::init()->get_modules();
     $array_of_module_tags = wp_list_pluck($modules, 'module_tags');
     $module_tags = call_user_func_array('array_merge', $array_of_module_tags);
     $module_tags_unique = array_count_values($module_tags);
     ksort($module_tags_unique);
     $format = '<a href="%3$s"%4$s data-title="%1$s">%1$s <span class="count">(%2$s)</span></a>';
     $title = __('All', 'jetpack');
     $count = count($modules);
     $url = esc_url(remove_query_arg('module_tag'));
     $current = empty($_GET['module_tag']) ? ' class="current all"' : ' class="all"';
     $views = array('all' => sprintf($format, $title, $count, $url, $current));
     foreach ($module_tags_unique as $title => $count) {
         $key = sanitize_title($title);
         $display_title = esc_html(wptexturize($title));
         $url = esc_url(add_query_arg('module_tag', urlencode($title)));
         $current = '';
         if (!empty($_GET['module_tag']) && $title == $_GET['module_tag']) {
             $current = ' class="current"';
         }
         $views[$key] = sprintf($format, $display_title, $count, $url, $current);
     }
     return $views;
 }
 /**
  * BP_Groups_Invite_Template constructor.
  *
  * @since 1.5.0
  *
  * @param array $args
  */
 public function __construct($args = array())
 {
     // Backward compatibility with old method of passing arguments.
     if (!is_array($args) || func_num_args() > 1) {
         _deprecated_argument(__METHOD__, '2.0.0', sprintf(__('Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress'), __METHOD__, __FILE__));
         $old_args_keys = array(0 => 'user_id', 1 => 'group_id');
         $func_args = func_get_args();
         $args = bp_core_parse_args_array($old_args_keys, $func_args);
     }
     $r = wp_parse_args($args, array('page' => 1, 'per_page' => 10, 'page_arg' => 'invitepage', 'user_id' => bp_loggedin_user_id(), 'group_id' => bp_get_current_group_id()));
     $this->pag_arg = sanitize_key($r['page_arg']);
     $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']);
     $this->pag_num = bp_sanitize_pagination_arg('num', $r['per_page']);
     $iquery = new BP_Group_Member_Query(array('group_id' => $r['group_id'], 'type' => 'first_joined', 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'is_confirmed' => false, 'inviter_id' => $r['user_id']));
     $this->invite_data = $iquery->results;
     $this->total_invite_count = $iquery->total_users;
     $this->invites = array_values(wp_list_pluck($this->invite_data, 'ID'));
     $this->invite_count = count($this->invites);
     // If per_page is set to 0 (show all results), don't generate
     // pag_links.
     if (!empty($this->pag_num)) {
         $this->pag_links = paginate_links(array('base' => add_query_arg($this->pag_arg, '%#%'), 'format' => '', 'total' => ceil($this->total_invite_count / $this->pag_num), 'current' => $this->pag_page, 'prev_text' => '&larr;', 'next_text' => '&rarr;', 'mid_size' => 1, 'add_args' => array()));
     } else {
         $this->pag_links = '';
     }
 }
 public function prepare_items()
 {
     if (!empty($this->items)) {
         return;
     }
     $per_page = $this->get_items_per_page('edit_wpsc-product-variations_per_page');
     $per_page = apply_filters('edit_wpsc_product_variations_per_page', $per_page);
     $this->args = array('post_type' => 'wpsc-product', 'orderby' => 'menu_order title', 'post_parent' => $this->product_id, 'post_status' => 'publish, inherit', 'numberposts' => -1, 'order' => "ASC", 'posts_per_page' => $per_page);
     if (isset($_REQUEST['post_status'])) {
         $this->args['post_status'] = $_REQUEST['post_status'];
     }
     if (isset($_REQUEST['s'])) {
         $this->args['s'] = $_REQUEST['s'];
     }
     if (isset($_REQUEST['paged'])) {
         $this->args['paged'] = $_REQUEST['paged'];
     }
     $query = new WP_Query($this->args);
     $this->items = $query->posts;
     $total_items = $query->found_posts;
     $total_pages = $query->max_num_pages;
     $this->set_pagination_args(array('total_items' => $total_items, 'total_pages' => $total_pages, 'per_page' => $per_page));
     if (empty($this->items)) {
         return;
     }
     $ids = wp_list_pluck($this->items, 'ID');
     $object_terms = wp_get_object_terms($ids, 'wpsc-variation', array('fields' => 'all_with_object_id'));
     foreach ($object_terms as $term) {
         if (!array_key_exists($term->object_id, $this->object_terms_cache)) {
             $this->object_terms_cache[$term->object_id] = array();
         }
         $this->object_terms_cache[$term->object_id][$term->parent] = $term->name;
     }
 }
/**
 * Displays a list of restricted pages the currently logged-in user has access to
 *
 * @since       1.5.0
 * @param       array $atts The attributes to pass to the shortcode
 * @param       string $content The content of the shortcode
 * @return      string $content The data to return for the shortcode
 */
function edd_cr_pages_shortcode($atts, $content = null)
{
    $atts = shortcode_atts(array('class' => ''), $atts);
    if (is_user_logged_in()) {
        $pages = array();
        $purchases = edd_get_users_purchases(get_current_user_id(), -1);
        if ($purchases) {
            foreach ($purchases as $purchase) {
                $restricted = edd_cr_get_restricted_pages($purchase->ID);
                if (empty($restricted)) {
                    continue;
                }
                $page_ids = wp_list_pluck($restricted, 'ID');
                $pages = array_unique(array_merge($page_ids, $pages));
            }
            if (!empty($pages)) {
                $content = '<ul class="edd_cr_pages">';
                foreach ($pages as $page_id) {
                    $content .= '<li><a href="' . esc_url(get_permalink($page_id)) . '">' . get_the_title($page_id) . '</a></li>';
                }
                $content .= '</ul>';
            } else {
                $content = '<div class="edd_cr_no_pages">' . __('You have not purchased access to any content.', 'edd-cr') . '</div>';
            }
        } else {
            $content = '<div class="edd_cr_no_pages">' . __('You have not purchased access to any content.', 'edd-cr') . '</div>';
        }
    } else {
        $content = '<div class="edd_cr_not_logged_in">' . __('You must be logged in to access your purchased content.', 'edd-cr') . '</div>';
    }
    return $content;
}