protected function handle_private_loggedin_multisite($options) { if (is_multisite() && $options['aioi_ms_requiremember'] && !is_network_admin()) { // Need to check logged-in user is a member of this sub-site $blogs = get_blogs_of_user(get_current_user_id()); if (!wp_list_filter($blogs, array('userblog_id' => get_current_blog_id()))) { // Not a member $blog_name = get_bloginfo('name'); $output = '<p>' . esc_html(sprintf('You attempted to access the "%1$s" sub-site, but you are not currently a member of this site. If you believe you should be able to access "%1$s", please contact your network administrator.', $blog_name)) . '</p>'; if (!empty($blogs)) { $output .= '<p>You <i>are</i> a member of the following sites:</p>'; $output .= '<table>'; foreach ($blogs as $blog) { $output .= "<tr>"; $output .= "<td valign='top'>"; $output .= "<a href='" . esc_url(get_home_url($blog->userblog_id)) . "'>" . esc_html($blog->blogname) . "</a>"; $output .= "</td>"; $output .= "</tr>"; } $output .= '</table>'; } wp_die($output); } } }
function myplugin_save_postdata($post_id) { if (!isset($_POST['myplugin_noncename'])) { return $post_id; } if (!wp_verify_nonce($_POST['myplugin_noncename'], plugin_basename(__FILE__))) { return $post_id; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } $post_type = isset($_POST['post_type']) ? $_POST['post_type'] : ''; $post_types = wp_list_filter(get_post_types(array('public' => true)), array('attachment'), 'NOT'); if (in_array($post_type, $post_types)) { if (!current_user_can('edit_' . $post_type, $post_id)) { return $post_id; } } else { return $post_id; } $mydata = isset($_POST['dmm_id']) ? $_POST['dmm_id'] : ''; if (!empty($mydata)) { update_post_meta($post_id, 'dmm_id', $mydata); } else { delete_post_meta($post_id, 'dmm_id'); } return $mydata; }
public static function get_settings($settings) { // Insert before miscellaneous settings $misc_section_start = wp_list_filter($settings, array('id' => 'woocommerce_subscriptions_miscellaneous', 'type' => 'title')); $spliced_array = array_splice($settings, key($misc_section_start), 0, array(array('name' => __('Skip One', 'woocommerce-skip-one'), 'type' => 'title', 'desc' => __('Allow your customers to skip a subscription rather than cancelling it and pickup the subscription again after X amount of the subscription period.', 'woocommerce-skip-one'), 'id' => 'woocommerce_skip_one'), array('name' => __('Cancel/Skip Button Text', 'woocommerce-skip-one'), 'desc' => __('By default, "Cancel/Skip". Customise the new "Cancel" action button text to how you like.', 'woocommerce-skip-one'), 'tip' => '', 'id' => 'woocommerce_skip_one_cancel_skip_button_text', 'css' => 'min-width:300px;', 'default' => __('Cancel/Skip', 'woocommerce-skip-one'), 'type' => 'text', 'desc_tip' => true), array('name' => __('Cancel Subscription Button Text', 'woocommerce-skip-one'), 'desc' => __('By default, "Cancel Subscription". Customise the cancel button text to how you like.', 'woocommerce-skip-one'), 'tip' => '', 'id' => 'woocommerce_skip_one_cancel_button_text', 'css' => 'min-width:300px;', 'default' => __('Cancel Subscription', 'woocommerce-skip-one'), 'type' => 'text', 'desc_tip' => true), array('name' => __('Cancel Subscription Message', 'woocommerce-skip-one'), 'desc' => __('Enter a custom message to your customers if they still wish to cancel their subscription.', 'woocommerce-skip-one'), 'tip' => '', 'id' => 'woocommerce_skip_one_cancel_message', 'css' => 'min-width:480px; min-height:120px;', 'default' => __('We\'re bummed if you have to go, but we understand. Please note: You will still receive your remaining subscription owed.', 'woocommerce-skip-one'), 'type' => 'textarea', 'desc_tip' => true), array('name' => __('Minimum Cost', 'woocommerce-skip-one'), 'desc' => __('Only subscriptions that cost this amount or higher can be allowed to skip a subscription. Leave blank to disable this option.', 'woocommerce-skip-one'), 'tip' => '', 'id' => 'woocommerce_skip_one_minium_sub_value', 'css' => 'min-width:300px;', 'default' => '30', 'type' => 'number', 'desc_tip' => true), array('name' => __('Allow specific periods', 'woocommerce-skip-one'), 'desc' => __('Choose which periods a subscription must be on in order for a customer to skip the subscription.', 'woocommerce-skip-one'), 'id' => 'woocommerce_skip_one_allow_periods', 'css' => 'min-width:120px;', 'default' => 'month', 'type' => 'multiselect', 'class' => 'wc-enhanced-select', 'options' => array('day' => __('Day', 'woocommerce-skip-one'), 'week' => __('Week', 'woocommerce-skip-one'), 'month' => __('Month', 'woocommerce-skip-one'), 'year' => __('Year', 'woocommerce-skip-one')), 'desc_tip' => false), array('name' => __('Stop skipping Free Trials?', 'woocommerce-skip-one'), 'desc' => __('Enable this and any subscription that has a free trial will stop customers from skipping.', 'woocommerce-skip-one'), 'id' => 'woocommerce_skip_one_deny_free_trials', 'default' => 'no', 'type' => 'checkbox', 'desc_tip' => false), array('name' => __('Allow Unskipping?', 'woocommerce-skip-one'), 'desc' => __('Enable this and your customers can unskip a subscription they skipped.', 'woocommerce-skip-one'), 'id' => 'woocommerce_skip_one_can_customer_unskip', 'default' => 'no', 'type' => 'checkbox', 'desc_tip' => false), array('name' => __('Allow Cancel Confirmation?', 'woocommerce-skip-one'), 'desc' => __('Enable this and your customers can confirm if they wish to cancel a subscription.', 'woocommerce-skip-one'), 'id' => 'woocommerce_skip_one_can_customer_confirm', 'default' => 'yes', 'type' => 'checkbox', 'desc_tip' => false), array('type' => 'sectionend', 'id' => 'woocommerce_skip_one'))); return $settings; }
function entry_ease_divide_output_fields() { $post_types = wp_list_filter(get_post_types(array('public' => true)), array('attachment'), 'NOT'); add_settings_section('general', __('General', 'entry_ease_divide_output'), '', 'entry_ease_divide_output'); add_settings_field('entry_ease_divide_output_post_types', __('Active post types', 'entry_ease_divide_output'), 'entry_ease_divide_output_post_type_checkbox', 'entry_ease_divide_output', 'general', array('name' => 'eedo_post_types[]', 'value' => get_option('eedo_post_types'), 'option' => $post_types)); add_settings_section('before', __('Default for before', 'entry_ease_divide_output'), '', 'entry_ease_divide_output'); add_settings_field('entry_ease_divide_output_before_default_text', __('Before Text', 'entry_ease_divide_output'), 'entry_ease_divide_output_textarea_field', 'entry_ease_divide_output', 'before', array('name' => 'eedo_before_default_text', 'value' => get_option('eedo_before_default_text'))); add_settings_section('after', __('Default for after', 'entry_ease_divide_output'), '', 'entry_ease_divide_output'); add_settings_field('entry_ease_divide_output_after_default_text', __('After Text', 'entry_ease_divide_output'), 'entry_ease_divide_output_textarea_field', 'entry_ease_divide_output', 'after', array('name' => 'eedo_after_default_text', 'value' => get_option('eedo_after_default_text'))); }
function wp_filter_object_list($list, $args = array(), $operator = 'and', $field = false) { if (!is_array($list)) { return array(); } $list = wp_list_filter($list, $args, $operator); if ($field) { $list = wp_list_pluck($list, $field); } return $list; }
public static function get_categories() { global $wp_query; $defaults = array('before' => '', 'after' => '', 'force_display' => false); $args = array(); $args = wp_parse_args($args, $defaults); extract($args); $term = get_queried_object(); $parent_id = empty($term->term_id) ? 0 : $term->term_id; if (is_product_category()) { $display_type = get_woocommerce_term_meta($term->term_id, 'display_type', true); switch ($display_type) { case 'products': return; break; case '': if (get_option('woocommerce_category_archive_display') == '') { return; } break; } } $product_categories = get_categories(apply_filters('woocommerce_product_subcategories_args', array('parent' => $parent_id, 'menu_order' => 'ASC', 'hide_empty' => 0, 'hierarchical' => 1, 'taxonomy' => 'product_cat', 'pad_counts' => 1))); if (!apply_filters('woocommerce_product_subcategories_hide_empty', false)) { $product_categories = wp_list_filter($product_categories, array('count' => 0), 'NOT'); } if ($product_categories) { echo $before; foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); } if (is_product_category()) { $display_type = get_woocommerce_term_meta($term->term_id, 'display_type', true); switch ($display_type) { case 'subcategories': $wp_query->post_count = 0; $wp_query->max_num_pages = 0; break; case '': if (get_option('woocommerce_category_archive_display') == 'subcategories') { $wp_query->post_count = 0; $wp_query->max_num_pages = 0; } break; } } if (is_shop() && get_option('woocommerce_shop_page_display') == 'subcategories') { $wp_query->post_count = 0; $wp_query->max_num_pages = 0; } echo $after; return true; } }
function walk($elements, $args = array()) { $output = ''; $args = wp_parse_args($args, array('value' => 'slug', 'name' => 'lang_choice')); if (!empty($args['flag'])) { $current = wp_list_filter($elements, array($args['value'] => $args['selected'])); $lang = reset($current); $output = sprintf('<span class="pll-select-flag">%s</span>', empty($lang->flag) ? esc_html($lang->slug) : $lang->flag); } $output .= sprintf('<select name="%1$s" %2$s%3$s%4$s>' . "\n" . '%5$s' . "\n" . '</select>' . "\n", $name = esc_attr($args['name']), isset($args['id']) && !$args['id'] ? '' : ' id="' . (empty($args['id']) ? $name : esc_attr($args['id'])) . '"', empty($args['class']) ? '' : ' class="' . esc_attr($args['class']) . '"', empty($args['disabled']) ? '' : ' disabled="disabled"', parent::walk($elements, -1, $args)); return $output; }
public function categoryitems_short($atts) { global $woocommerce_loop, $woocommerce; extract(shortcode_atts(array('number' => 4, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'hide_empty' => 1, 'parent' => '', 'itemselection' => 'featured', 'limit' => 4, 'mode' => ''), $atts)); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $cat_args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent); $product_categories = get_terms('product_cat', $cat_args); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($number) { $product_categories = array_slice($product_categories, 0, $number); } $woocommerce_loop['columns'] = $columns; $this->print_scripts_styles(); ob_start(); $html = '<nav>'; if ($product_categories) { echo '<div class="main"> <div ' . ($mode == 'slider' ? ' ' : ' id="mi-slider" class="mi-slider" ') . ' >'; if ($mode == 'slider') { echo '<ul data-slider="ios" class="ios-products">'; } foreach ($product_categories as $category) { $html .= '<a href="#">' . $category->name . '</a>'; if ($mode != 'slider') { echo '<ul>'; } $this->products($category->slug, $itemselection, array('per_page' => $limit, 'mode' => $mode, 'cat_name' => $category->name)); if ($mode != 'slider') { echo '</ul>'; } } $html .= '</nav>'; if ($mode != 'slider') { echo $html; } if ($mode == 'slider') { echo '</ul>'; } echo ' </div> </div>'; } return '<div class="woocommerce">' . ob_get_clean() . '</div>'; }
protected function content($atts, $content = null) { $atts = shortcode_atts(array('per_page' => '', 'orderby' => 'name', 'order' => 'ASC', 'ids' => '', 'categories_style' => 'normal', 'hide_empty' => 'true', 'parent' => '', 'autoheight' => true, 'autoplay' => false, 'mousedrag' => true, 'autoplayspeed' => 5000, 'slidespeed' => 200, 'carousel_skin' => '', 'desktop' => 4, 'desktopsmall' => 3, 'tablet' => 2, 'mobile' => 1, 'gutters' => false, 'navigation' => true, 'navigation_always_on' => true, 'navigation_position' => 'center-outside', 'navigation_style' => 'normal', 'pagination' => false, 'pagination_position' => 'center-bottom', 'pagination_style' => 'dot-stroke', 'css_animation' => '', 'el_class' => '', 'css' => ''), $atts); if ($atts['categories_style'] == 'modern') { $atts['gutters'] = true; } $atts['columns'] = $atts['desktop']; $atts['number'] = $atts['per_page']; $atts['hide_empty'] = apply_filters('sanitize_boolean', $atts['hide_empty']); extract($atts); $elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'products-categories-carousel ', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => $this->getCSSAnimation($css_animation), 'woocommerce' => 'woocommerce columns-' . $desktop, 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' '), 'style' => 'style-' . $categories_style); $carousel_ouput = cruxstore_render_carousel(apply_filters('cruxstore_render_args', $atts), '', 'cruxstore-owl-carousel'); $output = $carousel_html = ''; if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $atts['hide_empty'] == true || $atts['hide_empty'] == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $atts['orderby'], 'order' => $atts['order'], 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $atts['parent']); $product_categories = get_terms('product_cat', $args); if ('' !== $atts['parent']) { $product_categories = wp_list_filter($product_categories, array('parent' => $atts['parent'])); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($atts['number']) { $product_categories = array_slice($product_categories, 0, $atts['number']); } ob_start(); if ($product_categories) { global $woocommerce_carousel; $woocommerce_carousel = $categories_style; foreach ($product_categories as $category) { wc_get_template('content-product_cat_carousel.php', array('category' => $category)); } } wp_reset_postdata(); $carousel_html .= ob_get_clean(); if ($carousel_html) { $elementClass = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClass)); $output = '<div class="' . esc_attr($elementClass) . '">' . str_replace('%carousel_html%', $carousel_html, $carousel_ouput) . '</div>'; } return $output; }
/** * Removes a link from the response. * * @since 4.4.0 * @access public * * @param string $rel Link relation. Either an IANA registered type, or an absolute URL. * @param string $href Optional. Only remove links for the relation matching the given href. * Default null. */ public function remove_link($rel, $href = null) { if (!isset($this->links[$rel])) { return; } if ($href) { $this->links[$rel] = wp_list_filter($this->links[$rel], array('href' => $href), 'NOT'); } else { $this->links[$rel] = array(); } if (!$this->links[$rel]) { unset($this->links[$rel]); } }
protected function content($atts, $content = null) { $atts = shortcode_atts(array('per_page' => '', 'orderby' => 'name', 'order' => 'ASC', 'ids' => '', 'hide_empty' => 'true', 'columns' => '4', 'parent' => '', 'css_animation' => '', 'animation_delay' => '', 'el_class' => '', 'css' => ''), $atts); $atts['number'] = $atts['per_page']; $atts['hide_empty'] = apply_filters('sanitize_boolean', $atts['hide_empty']); extract($atts); $elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'products-categories-grid ', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => cruxstore_getCSSAnimation($css_animation), 'woocommerce' => 'woocommerce columns-' . $columns, 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' ')); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $atts['hide_empty'] == true || $atts['hide_empty'] == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $atts['orderby'], 'order' => $atts['order'], 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $atts['parent']); $product_categories = get_terms('product_cat', $args); if ('' !== $atts['parent']) { $product_categories = wp_list_filter($product_categories, array('parent' => $atts['parent'])); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($atts['number']) { $product_categories = array_slice($product_categories, 0, $atts['number']); } ob_start(); if ($product_categories) { echo '<div class="row multi-columns-row">'; $bootstrapColumn = round(12 / $columns); foreach ($product_categories as $category) { echo '<div class="col-md-' . $bootstrapColumn . ' col-sm-' . $bootstrapColumn . '">'; wc_get_template('content-product_cat_grid.php', array('category' => $category)); echo '</div>'; } echo '</div>'; } wp_reset_postdata(); $output = ob_get_clean(); $elementClass = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClass)); if ($animation_delay) { $animation_delay = sprintf(' data-wow-delay="%sms"', $animation_delay); } return '<div class="' . esc_attr($elementClass) . '"' . $animation_delay . '>' . $output . '</div>'; }
protected function content($atts, $content = null) { $atts = shortcode_atts(array('title' => esc_html__('Title', 'js_composer'), 'per_page' => '', 'orderby' => 'name', 'order' => 'ASC', 'ids' => '', 'categories_style' => 'normal', 'hide_empty' => 'true', 'parent' => '', 'css_animation' => '', 'animation_delay' => '', 'el_class' => '', 'css' => ''), $atts); $atts['hide_empty'] = apply_filters('sanitize_boolean', $atts['hide_empty']); $atts['number'] = $atts['per_page']; extract($atts); $output = ''; $elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'products-categories-list ', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => cruxstore_getCSSAnimation($css_animation), 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' '), 'style' => 'style-' . $categories_style); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $atts['hide_empty'] == true || $atts['hide_empty'] == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $atts['orderby'], 'order' => $atts['order'], 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $atts['parent']); $product_categories = get_terms('product_cat', $args); if ('' !== $atts['parent']) { $product_categories = wp_list_filter($product_categories, array('parent' => $atts['parent'])); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($atts['number']) { $product_categories = array_slice($product_categories, 0, $atts['number']); } $output .= sprintf('<h4 class="%s">%s</h4>', 'products-categories-heading', $title); if ($product_categories) { $output .= '<ul>'; foreach ($product_categories as $category) { $output .= sprintf('<li><a href="%s">%s</a></li>', get_term_link($category->slug, 'product_cat'), $category->name); } $output .= '</ul>'; } if ($animation_delay) { $animation_delay = sprintf(' data-wow-delay="%sms"', $animation_delay); } $elementClass = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClass)); return '<div class="' . esc_attr($elementClass) . '"' . $animation_delay . '>' . $output . '</div>'; }
function wb_products($atts, $before, $after) { global $woocommerce_loop; $atts = shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'hide_empty' => 1, 'parent' => '', 'ids' => ''), $atts); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $atts['hide_empty'] == true || $atts['hide_empty'] == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $atts['orderby'], 'order' => $atts['order'], 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $atts['parent']); $product_categories = get_terms('product_cat', $args); if ('' !== $atts['parent']) { $product_categories = wp_list_filter($product_categories, array('parent' => $atts['parent'])); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($atts['number']) { $product_categories = array_slice($product_categories, 0, $atts['number']); } $columns = absint($atts['columns']); $woocommerce_loop['columns'] = $columns; ob_start(); // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_categories) { echo $before; foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); } echo $after; } woocommerce_reset_loop(); return ob_get_clean(); }
public function generate_completion($post) { /** * Used for exclude functions * * @param array list to exclude * @param string current function name */ $exclude_functions = apply_filters('sublime_export_exclude_functions', array(), $post->post_title); $exclude_functions = is_array($exclude_functions) ? $exclude_functions : array(); if (in_array($post->post_title, $exclude_functions)) { return false; } /** * Used for exclude private functions * * @param bool true or false for exclude * @param object post * */ if (apply_filters('sublime_export_exclude_private_functions', false, $post)) { return false; } $arguments = $this->get_arguments($post->ID); $return = wp_list_filter(get_post_meta($post->ID, '_wp-parser_tags', true), array('name' => 'return')); /** * Used for change defaults arguments * * @param array $arguments * @param string $name * * @return array $arguments */ $arguments = apply_filters('sublime_export_default_arguments', $arguments, $post->post_title); if ($last = array_pop($arguments)) { if (!$this->is_deprecated($last)) { $arguments[] = $last; } } return array('trigger' => "{$post->post_title}\tWP Function", 'contents' => $this->contents($post->post_title, $this->parse_arguments($arguments), !empty($return))); }
public static function show_field($field, $fields) { $result = null; if (isset($field['conditional_logic']) && !empty($field['conditional_logic'])) { foreach ($field['conditional_logic'] as $logic_group) { $group_result = true; foreach ($logic_group as $rule) { $other_field = wp_list_filter($fields, array('key' => $rule['field'])); $other_value = null; if ($other_field) { $other_field = array_shift($other_field); $other_value = isset($other_field['value']) ? $other_field['value'] : null; } switch ($rule['operator']) { case '==': if (is_array($other_value)) { $group_result &= in_array($other_value, $rule['value']); } else { $group_result &= $other_value == $rule['value']; } break; case '!=': if (is_array($other_value)) { $group_result &= !in_array($other_value, $rule['value']); } else { $group_result &= $other_value != $rule['value']; } break; default: break; } } if ($result == null) { $result = $group_result; } else { $result |= $group_result; } } } return $result !== null ? $result : true; }
public function widget($args, $instance) { global $post; $instance = wp_parse_args($instance, $this->defaults); $title = apply_filters('widget_title', $instance['title']); extract($args); add_image_size('wpsc_product_widget_thumbnail', $instance['width'], $instance['height'], wpsc_get_option('crop_thumbnails')); $on_sale_products = get_posts(array('post_type' => 'wpsc-product', 'nopaging' => true, 'post_status' => array('publish', 'inherit'), 'meta_query' => array(array('key' => '_wpsc_special_price', 'value' => 0, 'compare' => '>', 'type' => 'NUMERIC')))); // extract products with no parents $products = wp_list_filter($on_sale_products, array('post_parent' => 0)); // get parent of variations $parent_ids = array_unique(wp_list_pluck($on_sale_products, 'post_parent')); $parents = array(); if (!empty($parent_ids)) { $parents = get_posts(array('post_type' => 'wpsc-product', 'nopaging' => true, 'post_status' => 'publish', 'post__in' => $parent_ids, 'post__not_in' => wp_list_pluck($products, 'ID'))); } $products = array_merge($products, $parents); if (!empty($instance['post_count'])) { $products = array_slice($products, 0, $instance['post_count']); } include WPSC_TE_V2_SNIPPETS_PATH . '/widgets/on-sale/widget.php'; }
/** * Retrieve queried object. * * If queried object is not set, then the queried object will be set from * the category, tag, taxonomy, posts page, single post, page, or author * query variable. After it is set up, it will be returned. * * @since 1.5.0 * @access public * * @return object */ public function get_queried_object() { if (isset($this->queried_object)) { return $this->queried_object; } $this->queried_object = null; $this->queried_object_id = null; if ($this->is_category || $this->is_tag || $this->is_tax) { if ($this->is_category) { if ($this->get('cat')) { $term = get_term($this->get('cat'), 'category'); } elseif ($this->get('category_name')) { $term = get_term_by('slug', $this->get('category_name'), 'category'); } } elseif ($this->is_tag) { if ($this->get('tag_id')) { $term = get_term($this->get('tag_id'), 'post_tag'); } elseif ($this->get('tag')) { $term = get_term_by('slug', $this->get('tag'), 'post_tag'); } } else { // For other tax queries, grab the first term from the first clause. $tax_query_in_and = wp_list_filter($this->tax_query->queried_terms, array('operator' => 'NOT IN'), 'NOT'); if (!empty($tax_query_in_and)) { $queried_taxonomies = array_keys($tax_query_in_and); $matched_taxonomy = reset($queried_taxonomies); $query = $tax_query_in_and[$matched_taxonomy]; if ($query['terms']) { if ('term_id' == $query['field']) { $term = get_term(reset($query['terms']), $matched_taxonomy); } else { $term = get_term_by($query['field'], reset($query['terms']), $matched_taxonomy); } } } } if (!empty($term) && !is_wp_error($term)) { $this->queried_object = $term; $this->queried_object_id = (int) $term->term_id; if ($this->is_category && 'category' === $this->queried_object->taxonomy) { _make_cat_compat($this->queried_object); } } } elseif ($this->is_post_type_archive) { $post_type = $this->get('post_type'); if (is_array($post_type)) { $post_type = reset($post_type); } $this->queried_object = get_post_type_object($post_type); } elseif ($this->is_posts_page) { $page_for_posts = get_option('page_for_posts'); $this->queried_object = get_post($page_for_posts); $this->queried_object_id = (int) $this->queried_object->ID; } elseif ($this->is_singular && !empty($this->post)) { $this->queried_object = $this->post; $this->queried_object_id = (int) $this->post->ID; } elseif ($this->is_author) { $this->queried_object_id = (int) $this->get('author'); $this->queried_object = get_userdata($this->queried_object_id); } return $this->queried_object; }
/** * @param $column string name of the setting key (authors|roles|actions|ip_addresses|contexts|connectors) * * @return array */ public static function get_excluded_by_key($column) { $option_name = 'authors' === $column || 'roles' === $column ? 'exclude_authors_and_roles' : 'exclude_' . $column; $excluded_values = isset(self::$options[$option_name]) ? self::$options[$option_name] : array(); if (is_callable($excluded_values)) { $excluded_values = call_user_func($excluded_values); } $excluded_values = wp_list_filter($excluded_values, array('__placeholder__'), 'NOT'); if ('exclude_authors_and_roles' === $option_name) { // Convert numeric strings to integers array_walk($excluded_values, function (&$value) { if (is_numeric($value)) { $value = absint($value); } }); $filter = 'roles' === $column ? 'is_string' : 'is_int'; // Author roles are always strings and author ID's are always integers $excluded_values = array_values(array_filter($excluded_values, $filter)); // Reset the array keys } return $excluded_values; }
protected function update_many($args, $assoc_args) { call_user_func($this->upgrade_refresh); if (!empty($assoc_args['format']) && in_array($assoc_args['format'], array('json', 'csv'))) { $logger = new \WP_CLI\Loggers\Quiet(); \WP_CLI::set_logger($logger); } if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'all') && empty($args)) { \WP_CLI::error("Please specify one or more {$this->item_type}s, or use --all."); } $items = $this->get_item_list(); if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'all')) { $items = $this->filter_item_list($items, $args); } $items_to_update = wp_list_filter($items, array('update' => true)); if (\WP_CLI\Utils\get_flag_value($assoc_args, 'dry-run')) { if (empty($items_to_update)) { \WP_CLI::line("No {$this->item_type} updates available."); return; } if (!empty($assoc_args['format']) && in_array($assoc_args['format'], array('json', 'csv'))) { \WP_CLI\Utils\format_items($assoc_args['format'], $items_to_update, array('name', 'status', 'version', 'update_version')); } else { if (!empty($assoc_args['format']) && 'summary' === $assoc_args['format']) { \WP_CLI::line("Available {$this->item_type} updates:"); foreach ($items_to_update as $item_to_update => $info) { \WP_CLI::log("{$info['title']} update from version {$info['version']} to version {$info['update_version']}"); } } else { \WP_CLI::line("Available {$this->item_type} updates:"); \WP_CLI\Utils\format_items('table', $items_to_update, array('name', 'status', 'version', 'update_version')); } } return; } $result = array(); // Only attempt to update if there is something to update if (!empty($items_to_update)) { $cache_manager = \WP_CLI::get_http_cache_manager(); foreach ($items_to_update as $item) { $cache_manager->whitelist_package($item['update_package'], $this->item_type, $item['name'], $item['update_version']); } $upgrader = $this->get_upgrader($assoc_args); $result = $upgrader->bulk_upgrade(wp_list_pluck($items_to_update, 'update_id')); } // Let the user know the results. $num_to_update = count($items_to_update); $num_updated = count(array_filter($result)); $line = "Updated {$num_updated}/{$num_to_update} {$this->item_type}s."; if ($num_to_update == $num_updated) { \WP_CLI::success($line); } else { if ($num_updated > 0) { \WP_CLI::warning($line); } else { \WP_CLI::error($line); } } if ($num_to_update > 0) { if (!empty($assoc_args['format']) && 'summary' === $assoc_args['format']) { foreach ($items_to_update as $item_to_update => $info) { $message = $result[$info['update_id']] !== null ? 'updated successfully' : 'did not update'; \WP_CLI::log("{$info['title']} {$message} from version {$info['version']} to version {$info['update_version']}"); } } else { $status = array(); foreach ($items_to_update as $item_to_update => $info) { $status[$item_to_update] = array('name' => $info['name'], 'old_version' => $info['version'], 'new_version' => $info['update_version'], 'status' => $result[$info['update_id']] !== null ? 'Updated' : 'Error'); } $format = 'table'; if (!empty($assoc_args['format']) && in_array($assoc_args['format'], array('json', 'csv'))) { $format = $assoc_args['format']; } \WP_CLI\Utils\format_items($format, $status, array('name', 'old_version', 'new_version', 'status')); } } }
public function product_lookbook_shortcode($atts, $content = null) { global $woocommerce_loop; $atts = shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'hide_empty' => 1, 'parent' => '', 'ids' => ''), $atts); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $atts['hide_empty'] == true || $atts['hide_empty'] == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $atts['orderby'], 'order' => $atts['order'], 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $atts['parent']); $product_brands = get_terms('product_brand', $args); if ('' !== $atts['parent']) { $product_brands = wp_list_filter($product_brands, array('parent' => $atts['parent'])); } if ($hide_empty) { foreach ($product_brands as $key => $brand) { if ($brand->count == 0) { unset($product_brands[$key]); } } } if ($atts['number']) { $product_brands = array_slice($product_brands, 0, $atts['number']); } $woocommerce_loop['columns'] = $atts['columns']; ob_start(); // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_brands) { woocommerce_product_loop_start(); foreach ($product_brands as $brand) { wc_get_template('content-product_brand.php', array('brand' => $brand)); } woocommerce_product_loop_end(); } woocommerce_reset_loop(); return '<div class="woocommerce columns-' . $atts['columns'] . '">' . ob_get_clean() . '</div>'; }
/** * Display product sub categories as thumbnails. * * @access public * @subpackage Loop * @param array $args * @return null|boolean */ function woocommerce_product_subcategories($args = array()) { global $wp_query; $defaults = array('before' => '', 'after' => '', 'force_display' => false); $args = wp_parse_args($args, $defaults); extract($args); // Main query only if (!is_main_query() && !$force_display) { return; } // Don't show when filtering, searching or when on page > 1 and ensure we're on a product archive if (is_search() || is_filtered() || is_paged() || !is_product_category() && !is_shop()) { return; } // Check categories are enabled if (is_shop() && get_option('woocommerce_shop_page_display') == '') { return; } // Find the category + category parent, if applicable $term = get_queried_object(); $parent_id = empty($term->term_id) ? 0 : $term->term_id; if (is_product_category()) { $display_type = get_woocommerce_term_meta($term->term_id, 'display_type', true); switch ($display_type) { case 'products': return; break; case '': if (get_option('woocommerce_category_archive_display') == '') { return; } break; } } // NOTE: using child_of instead of parent - this is not ideal but due to a WP bug ( http://core.trac.wordpress.org/ticket/15626 ) pad_counts won't work $product_categories = get_categories(apply_filters('woocommerce_product_subcategories_args', array('parent' => $parent_id, 'menu_order' => 'ASC', 'hide_empty' => 0, 'hierarchical' => 1, 'taxonomy' => 'product_cat', 'pad_counts' => 1))); if (!apply_filters('woocommerce_product_subcategories_hide_empty', false)) { $product_categories = wp_list_filter($product_categories, array('count' => 0), 'NOT'); } $product_category_found = false; if ($product_categories) { echo $before; foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); } // If we are hiding products disable the loop and pagination if (is_product_category()) { $display_type = get_woocommerce_term_meta($term->term_id, 'display_type', true); switch ($display_type) { case 'subcategories': $wp_query->post_count = 0; $wp_query->max_num_pages = 0; break; case '': if (get_option('woocommerce_category_archive_display') == 'subcategories') { $wp_query->post_count = 0; $wp_query->max_num_pages = 0; } break; } } if (is_shop() && get_option('woocommerce_shop_page_display') == 'subcategories') { $wp_query->post_count = 0; $wp_query->max_num_pages = 0; } echo $after; } return true; }
/** * Extract [video] shortcodes from text. * * @since 2.3.0 * * @see wp_get_video_extensions() for supported video formats. * * @param string $richtext Content to parse. * @param string $plaintext Sanitized version of the content. * @param array $extra_args Bespoke data for a particular extractor (optional). * * @return array { * @type array $has Extracted media counts. { * @type int $video * } * @type array $videos Extracted video. { * Array of extracted media. * * @type string $source Media source. Currently only "shortcodes". * @type string $url Link to audio. * } * } */ protected function extract_video($richtext, $plaintext, $extra_args = array()) { $data = array('has' => array('videos' => 0), 'videos' => array()); $videos = $this->extract_shortcodes($richtext, $plaintext, $extra_args); $video_types = wp_get_video_extensions(); // [video] $videos = wp_list_filter($videos['shortcodes'], array('type' => 'video')); foreach ($videos as $video) { // Media URL can appear as the first parameter inside the shortcode brackets. if (isset($video['attributes']['src'])) { $src_param = 'src'; } elseif (isset($video['attributes'][0])) { $src_param = 0; } else { continue; } $path = untrailingslashit(parse_url($video['attributes'][$src_param], PHP_URL_PATH)); foreach ($video_types as $extension) { $extension = '.' . $extension; // Check this URL's file extension matches that of an accepted video format (-5 for webm). if (!$path || substr($path, -4) !== $extension && substr($path, -5) !== $extension) { continue; } $data['videos'][] = array('original' => $video['original'], 'source' => 'shortcodes', 'url' => esc_url_raw($video['attributes'][$src_param])); } } $data['has']['videos'] = count($data['videos']); /** * Filters videos extracted from text. * * @since 2.3.0 * * @param array $data Extracted videos. See {@link BP_Media_Extractor::extract_videos()} for format. * @param string $richtext Content to parse. * @param string $plaintext Copy of $richtext without any markup. * @param array $extra_args Bespoke data for a particular extractor. */ return apply_filters('bp_media_extractor_videos', $data, $richtext, $plaintext, $extra_args); }
/** * Prepares a post type object for serialization. * * @since 4.7.0 * @access public * * @param stdClass $post_type Post type data. * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response Response object. */ public function prepare_item_for_response($post_type, $request) { $taxonomies = wp_list_filter(get_object_taxonomies($post_type->name, 'objects'), array('show_in_rest' => true)); $taxonomies = wp_list_pluck($taxonomies, 'name'); $base = !empty($post_type->rest_base) ? $post_type->rest_base : $post_type->name; $data = array('capabilities' => $post_type->cap, 'description' => $post_type->description, 'hierarchical' => $post_type->hierarchical, 'labels' => $post_type->labels, 'name' => $post_type->label, 'slug' => $post_type->name, 'taxonomies' => array_values($taxonomies), 'rest_base' => $base); $context = !empty($request['context']) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object($data, $request); $data = $this->filter_response_by_context($data, $context); // Wrap the data in a response object. $response = rest_ensure_response($data); $response->add_links(array('collection' => array('href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base))), 'https://api.w.org/items' => array('href' => rest_url(sprintf('wp/v2/%s', $base))))); /** * Filters a post type returned from the API. * * Allows modification of the post type data right before it is returned. * * @since 4.7.0 * * @param WP_REST_Response $response The response object. * @param object $item The original post type object. * @param WP_REST_Request $request Request used to generate the response. */ return apply_filters('rest_prepare_post_type', $response, $post_type, $request); }
/** * Create a post for an item (a class or a function). * * Anything that needs to be dealt identically for functions or methods should go in this function. * Anything more specific should go in either import_function() or import_class() as appropriate. * * @param array $data Data. * @param int $parent_post_id Optional; post ID of the parent (class or function) this item belongs to. Defaults to zero (no parent). * @param bool $import_ignored Optional; defaults to false. If true, functions or classes marked `@ignore` will be imported. * Disabled, not remove to prevent PHP Warning * @param array $arg_overrides Optional; array of parameters that override the defaults passed to wp_update_post(). * * @return bool|int Post ID of this item, false if any failure. */ public function import_item(array $data, $parent_post_id = 0, $import_ignored = false, array $arg_overrides = array()) { /** @var \wpdb $wpdb */ global $wpdb; $is_new_post = true; $slug = sanitize_title(str_replace('::', '-', $data['name'])); $post_data = wp_parse_args($arg_overrides, array('post_content' => $data['doc']['long_description'], 'post_excerpt' => $data['doc']['description'], 'post_name' => $slug, 'post_parent' => (int) $parent_post_id, 'post_status' => 'publish', 'post_title' => $data['name'], 'post_type' => $this->post_type_function)); $post_type_name_to_log = substr($post_data['post_type'], 10); // Don't import items marked @ignore if (wp_list_filter($data['doc']['tags'], array('name' => 'ignore'))) { $indent = $parent_post_id ? "\t\t" : "\t"; global $wpdb; if ($ignore = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s", $slug, $post_data['post_type']))) { $this->logger->info($indent . sprintf('Deleting @ignore-d %s "%s"', $post_type_name_to_log, $data['name'])); foreach ($ignore as $ignore_post_id) { if (wp_list_filter(get_post_meta($ignore_post_id, '_wp-parser_tags', true), array('name' => 'ignore'))) { if (!wp_delete_post($ignore_post_id, true)) { $this->errors[] = $indent . sprintf('Problem deleting @ignore-d post for %s "%s"', $post_type_name_to_log, $data['name']); } } } } return false; } /** * Filter whether to proceed with adding/updating a prospective import item. * * Returning a falsey value to the filter will short-circuit addition of the import item. * * @param bool $display Whether to proceed with adding/updating the import item. Default true. * @param array $data Data * @param int $parent_post_id Optional; post ID of the parent (class or function) this item belongs to. Defaults to zero (no parent). * @param bool $import_ignored Optional; defaults to false. If true, functions or classes marked `@ignore` will be imported. * @param array $arg_overrides Optional; array of parameters that override the defaults passed to wp_update_post(). */ if (!apply_filters('wp_parser_pre_import_item', true, $data, $parent_post_id, $import_ignored, $arg_overrides)) { return false; } // Look for an existing post for this item $existing_post_id = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s ORDER BY post_date ASC", $slug, $post_data['post_type'])); // If the file or this items is deprecated not import, if exists deleted if ($this->file_meta['deprecated'] || wp_list_filter($data['doc']['tags'], array('name' => 'deprecated'))) { if (!empty($existing_post_id)) { $indent = $parent_post_id ? "\t\t" : "\t"; $this->logger->info($indent . sprintf('Deleting deprecated %s "%s"', $post_type_name_to_log, $data['name'])); $deleted_with_error = array(); foreach ($existing_post_id as $exists_post_id) { if ($this->file_meta['deprecated'] || wp_list_filter(get_post_meta($exists_post_id, '_wp-parser_tags', true), array('name' => 'deprecated'))) { if (!wp_delete_post($exists_post_id, true)) { $deleted_with_error[] = $exists_post_id; } } } if ($deleted_with_error) { $this->errors[] = $indent . sprintf('Problem deleting deprecated post for %s "%s"', $post_type_name_to_log, $data['name']); } } return false; } /** * Filter an import item's post data before it is updated or inserted. * * @param array $post_data Array of post data. * @param array $existing_post_id ID if the post already exists, empty otherwise. */ $post_data = apply_filters('wp_parser_import_item_post_data', $post_data, $existing_post_id); // Insert/update the item post if (!empty($existing_post_id)) { $is_new_post = false; $post_id = $post_data['ID'] = (int) array_shift($existing_post_id); $post_needed_update = array_diff_assoc(sanitize_post($post_data, 'db'), get_post($post_id, ARRAY_A, 'db')); if ($existing_post_id) { $indent = $parent_post_id ? "\t\t" : "\t"; $this->errors[] = $indent . sprintf('Possible Duplicate posts of the %s "%s"', $post_type_name_to_log, $data['name']); } if ($post_needed_update) { $post_id = wp_update_post(wp_slash($post_data), true); } } else { $post_id = wp_insert_post(wp_slash($post_data), true); } $anything_updated = array(); if (!$post_id || is_wp_error($post_id)) { $indent = $parent_post_id ? "\t\t" : "\t"; $this->errors[] = $indent . sprintf('Problem inserting/updating post for %s "%s"', $post_type_name_to_log, $data['name']); return false; } // If the item has @since markup, assign the taxonomy $since_versions = wp_list_filter($data['doc']['tags'], array('name' => 'since')); if (!empty($since_versions)) { // Loop through all @since versions. foreach ($since_versions as $since_version) { if (!empty($since_version['content'])) { $since_term = $this->insert_term($since_version['content'], $this->taxonomy_since_version); // Assign the tax item to the post if (!is_wp_error($since_term)) { $added_term_relationship = did_action('added_term_relationship'); wp_set_object_terms($post_id, (int) $since_term['term_id'], $this->taxonomy_since_version, true); if (did_action('added_term_relationship') > $added_term_relationship) { $anything_updated[] = true; } } else { $this->logger->warning("\tCannot set @since term: " . $since_term->get_error_message()); } } } } $packages = array('main' => wp_list_filter($data['doc']['tags'], array('name' => 'package')), 'sub' => wp_list_filter($data['doc']['tags'], array('name' => 'subpackage'))); // If the @package/@subpackage is not set by the individual function or class, get it from the file scope if (empty($packages['main'])) { $packages['main'] = wp_list_filter($this->file_meta['docblock']['tags'], array('name' => 'package')); } if (empty($packages['sub'])) { $packages['sub'] = wp_list_filter($this->file_meta['docblock']['tags'], array('name' => 'subpackage')); } $main_package_id = false; $package_term_ids = array(); // If the item has any @package/@subpackage markup (or has inherited it from file scope), assign the taxonomy. foreach ($packages as $pack_name => $pack_value) { if (empty($pack_value)) { continue; } $pack_value = array_shift($pack_value); $pack_value = $pack_value['content']; $package_term_args = array('parent' => 0); // Set the parent term_id to look for, as the package taxonomy is hierarchical. if ('sub' === $pack_name && is_int($main_package_id)) { $package_term_args = array('parent' => $main_package_id); } // If the package doesn't already exist in the taxonomy, add it $package_term = $this->insert_term($pack_value, $this->taxonomy_package, $package_term_args); $package_term_ids[] = (int) $package_term['term_id']; if ('main' === $pack_name && false === $main_package_id && !is_wp_error($package_term)) { $main_package_id = (int) $package_term['term_id']; } if (is_wp_error($package_term)) { if (is_int($main_package_id)) { $this->logger->warning("\tCannot create @subpackage term: " . $package_term->get_error_message()); } else { $this->logger->warning("\tCannot create @package term: " . $package_term->get_error_message()); } } } $added_term_relationship = did_action('added_term_relationship'); wp_set_object_terms($post_id, $package_term_ids, $this->taxonomy_package); if (did_action('added_term_relationship') > $added_term_relationship) { $anything_updated[] = true; } // Set other taxonomy and post meta to use in the theme templates $added_item = did_action('added_term_relationship'); wp_set_object_terms($post_id, $this->file_meta['term_id'], $this->taxonomy_file); if (did_action('added_term_relationship') > $added_item) { $anything_updated[] = true; } if ($post_data['post_type'] !== $this->post_type_class) { $anything_updated[] = update_post_meta($post_id, '_wp-parser_args', $data['arguments']); } $anything_updated[] = update_post_meta($post_id, '_wp-parser_line_num', (string) $data['line']); $anything_updated[] = update_post_meta($post_id, '_wp-parser_end_line_num', (string) $data['end_line']); $anything_updated[] = update_post_meta($post_id, '_wp-parser_tags', $data['doc']['tags']); // If the post didn't need to be updated, but meta or tax changed, update it to bump last modified. if (!$is_new_post && !$post_needed_update && array_filter($anything_updated)) { wp_update_post(wp_slash($post_data), true); } $action = $is_new_post ? 'Imported' : 'Updated'; $indent = $parent_post_id ? "\t\t" : "\t"; $this->logger->info("{$indent}{$action} {$post_type_name_to_log} \"{$data['name']}\""); /** * Action at the end of importing an item. * * @param int $post_id Optional; post ID of the inserted or updated item. * @param array $data PHPDoc data for the item we just imported * @param array $post_data WordPress data of the post we just inserted or updated */ do_action('wp_parser_import_item', $post_id, $data, $post_data); $this->imported[$post_data['post_type']][] = $post_id; return $post_id; }
/** * Resolve Types checkboxes query filters in Views and WordPress Archives * * @param $meta_query array Meta query instances * @param $data array( * domain string 'posts'|'terms'|'users' The kind of query being run. Optional. Defaults to `posts`. * ) * * @uses auxiliar_recursive_add_comma_values Auxiliar method for adding recursive values from a comma-separated list. * @uses types_filter_query_field_definitions Native Types filter to get Types fields based on some conditions. * * @return array * * @since 2.3.0 */ function resolve_types_checkboxes_views_meta_query($meta_query, $data = array()) { $defaults = array('domain' => 'posts'); $data = wp_parse_args($data, $defaults); /** * Get Types checkboxes meta fields * * @uses types_filter_query_field_definitions */ $args = array('domain' => $data['domain'], 'field_type' => array('checkboxes')); $fields_to_check = apply_filters('types_filter_query_field_definitions', array(), $args); $fields_to_check_slugs = wp_list_pluck($fields_to_check, 'meta_key'); if (empty($fields_to_check)) { return $meta_query; } global $wp_version; foreach ($meta_query as $meta_query_index => $meta_query_entry) { if (is_array($meta_query_entry) && isset($meta_query_entry['key']) && in_array($meta_query_entry['key'], $fields_to_check_slugs)) { $original_meta_query_entry = $meta_query_entry; unset($meta_query[$meta_query_index]); /** * According to http://codex.wordpress.org/Class_Reference/WP_Meta_Query#Accepted_Arguments, * $meta_query_entry['value'] can be an array or a string. In case of a string we additionally allow * multiple comma-separated values. */ if (is_array($meta_query_entry['value'])) { $meta_query_entry_values = $meta_query_entry['value']; // Add comma-separated combinations of meta values, since a legit value containing a comma might have been removed $meta_query_entry_values = $this->auxiliar_recursive_add_comma_values($meta_query_entry_values); } elseif (is_string($meta_query_entry['value'])) { $meta_query_entry_values = explode(',', $meta_query_entry['value']); if (count($meta_query_entry_values) > 1) { // Add comma-separated combinations of meta values, since a legit value containing a comma might have been removed $meta_query_entry_values = $this->auxiliar_recursive_add_comma_values($meta_query_entry_values); // Also add the original one, as it might be a legitimate value containing several commas instead of a comma-separated list $meta_query_entry_values[] = $meta_query_entry['value']; } } else { // This can happen if $meta_query_entry['value'] is a number, for example. $meta_query_entry_values = array($meta_query_entry['value']); } $field_definition_candidates = wp_list_filter($fields_to_check, array('meta_key' => $meta_query_entry['key'])); $field_definition = reset($field_definition_candidates); $field_options = isset($field_definition['data']['options']) ? $field_definition['data']['options'] : array(); if (version_compare($wp_version, '4.1', '<')) { // We can not use nested meta_query entries foreach ($meta_query_entry_values as $value_to_filter_by) { foreach ($field_options as $field_options_key => $field_options_option) { if ($field_options_option['title'] == $value_to_filter_by || isset($field_options_option['set_value']) && $field_options_option['set_value'] == $value_to_filter_by) { $meta_query[] = array('key' => $meta_query_entry['key'], 'compare' => in_array($original_meta_query_entry['compare'], array('!=', 'NOT LIKE', 'NOT IN')) ? 'NOT LIKE' : 'LIKE', 'value' => $field_options_key, 'type' => 'CHAR'); break; } } } } else { // We can use nested meta_query entries if (count($meta_query_entry_values) < 2) { // Only one value to filter by, so no need to add nested meta_query entries foreach ($meta_query_entry_values as $value_to_filter_by) { foreach ($field_options as $field_options_key => $field_options_option) { if ($field_options_option['title'] == $value_to_filter_by || isset($field_options_option['set_value']) && $field_options_option['set_value'] == $value_to_filter_by) { $meta_query[] = array('key' => $meta_query_entry['key'], 'compare' => in_array($original_meta_query_entry['compare'], array('!=', 'NOT LIKE', 'NOT IN')) ? 'NOT LIKE' : 'LIKE', 'value' => $field_options_key, 'type' => 'CHAR'); break; } } } } else { // We will translate each value into a meta_query clause and add them all as a nested meta_query entry $inner_relation = in_array($original_meta_query_entry['compare'], array('!=', 'NOT LIKE', 'NOT IN')) ? 'AND' : 'OR'; $inner_compare = in_array($original_meta_query_entry['compare'], array('!=', 'NOT LIKE', 'NOT IN')) ? 'NOT LIKE' : 'LIKE'; $inner_meta_query = array('relation' => $inner_relation); foreach ($meta_query_entry_values as $value_to_filter_by) { foreach ($field_options as $field_options_key => $field_options_option) { if ($field_options_option['title'] == $value_to_filter_by || isset($field_options_option['set_value']) && $field_options_option['set_value'] == $value_to_filter_by) { $inner_meta_query[] = array('key' => $meta_query_entry['key'], 'compare' => $inner_compare, 'value' => $field_options_key, 'type' => 'CHAR'); break; } } } $meta_query[] = $inner_meta_query; } } } } return $meta_query; }
function _access_denied_splash() { if ( ! is_user_logged_in() || is_network_admin() ) return; $blogs = get_blogs_of_user( get_current_user_id() ); if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) ) return; $blog_name = get_bloginfo( 'name' ); if ( empty( $blogs ) ) wp_die( sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) ); $output = '<p>' . sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) . '</p>'; $output .= '<p>' . __( 'If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.' ) . '</p>'; $output .= '<h3>' . __('Your Sites') . '</h3>'; $output .= '<table>'; foreach ( $blogs as $blog ) { $output .= "<tr>"; $output .= "<td valign='top'>"; $output .= "{$blog->blogname}"; $output .= "</td>"; $output .= "<td valign='top'>"; $output .= "<a href='" . esc_url( get_admin_url( $blog->userblog_id ) ) . "'>" . __( 'Visit Dashboard' ) . "</a> | <a href='" . esc_url( get_home_url( $blog->userblog_id ) ). "'>" . __( 'View Site' ) . "</a>" ; $output .= "</td>"; $output .= "</tr>"; } $output .= '</table>'; wp_die( $output ); }
public function select(array $where, $operator = 'AND') { return new static(wp_list_filter($this->getArrayCopy(), $where, $operator)); }
/** * Get the array of the repair list * * @since 2.0.0 bbPress (r2613) * * @uses apply_filters() Calls 'bbp_repair_list' with the list array * @return array Repair list of options */ function bbp_admin_repair_list() { // Define empty array $repair_list = array(); // Get the available tools $list = bbp_get_admin_repair_tools(); $search = !empty($_GET['s']) ? stripslashes($_GET['s']) : ''; $overhead = !empty($_GET['overhead']) ? sanitize_key($_GET['overhead']) : ''; $component = !empty($_GET['components']) ? sanitize_key($_GET['components']) : ''; // Overhead filter if (!empty($overhead)) { $list = wp_list_filter($list, array('overhead' => ucwords($overhead))); } // Loop through and key by priority for sorting foreach ($list as $id => $tool) { // Component filter if (!empty($component)) { if (!in_array($component, $tool['components'])) { continue; } } // Search if (!empty($search)) { if (!strstr(strtolower($tool['description']), strtolower($search))) { continue; } } // Add to repair list $repair_list[$tool['priority']] = array('id' => sanitize_key($id), 'description' => $tool['description'], 'callback' => $tool['callback'], 'overhead' => $tool['overhead'], 'components' => $tool['components']); } // Sort ksort($repair_list); return (array) apply_filters('bbp_repair_list', $repair_list); }
function woocomposer_carousel_shortcode($atts) { global $woocommerce_loop; $number = $orderby = $order = $columns = $options = $parent = $design_style = $text_align = $border_style = $border_color = ''; $border_size = $border_radius = $product_animation = $color_categories = $size_cat = $img_animate = $color_categories_bg = $cat_count = ''; $slides_to_scroll = $scroll_speed = $advanced_opts = $output = $autoplay_speed = $scroll_opts = $color_cat_count_color = $color_cat_count_bg = ''; extract(shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'ids' => '', 'options' => '', 'cat_count' => '', 'design_style' => '', 'text_align' => '', 'border_style' => '', 'border_color' => '', 'border_size' => '', 'border_radius' => '', 'product_animation' => '', 'color_categories_bg' => '', 'color_categories' => '', 'color_cat_count_bg' => '', 'color_cat_count_color' => '', 'size_cat' => '', 'slides_to_scroll' => '1', 'scroll_speed' => '1000', 'advanced_opts' => '', 'autoplay_speed' => '500', 'scroll_opts' => '', 'img_animate' => ''), $atts)); $border = $size = $count_style = ''; $opts = explode(",", $options); $infinite = $autoplay = $dots = 'false'; if ($product_animation !== '') { $product_animation = 'animated ' . $product_animation . ' '; } $uid = uniqid(); $advanced_opts = explode(",", $advanced_opts); if (in_array("infinite", $advanced_opts)) { $infinite = 'true'; } if (in_array("autoplay", $advanced_opts)) { $autoplay = 'true'; } if (in_array("dots", $advanced_opts)) { $dots = 'true'; } if ($color_categories !== '') { $size .= 'color:' . $color_categories . ';'; } if ($color_categories_bg !== '') { $size .= 'background:' . $color_categories_bg . ';'; } if ($size_cat !== '') { $size .= 'font-size:' . $size_cat . 'px;'; } if ($color_cat_count_bg !== '') { $count_style .= 'background:' . $color_cat_count_bg . ';'; } if ($color_cat_count_color !== '') { $count_style .= 'color:' . $color_cat_count_color . ';'; } if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = in_array('hide_empty', $opts) ? 1 : 0; $parent = in_array('parent', $opts) ? '' : 0; if ($border_style !== '') { $border .= 'border:' . $border_size . 'px ' . $border_style . ' ' . $border_color . ';'; $border .= 'border-radius:' . $border_radius . 'px;'; } // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent); $product_categories = get_terms('product_cat', $args); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($number) { $product_categories = array_slice($product_categories, 0, $number); } $woocommerce_loop['columns'] = $columns; ob_start(); // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_categories) { //woocommerce_product_loop_start(); foreach ($product_categories as $category) { $vc_span = ''; if ($columns == "2") { $vc_span = 'vc_span6 wpb_column column_container'; } elseif ($columns == "3") { $vc_span = 'vc_span4 wpb_column column_container'; } elseif ($columns == "4") { $vc_span = 'vc_span3 wpb_column column_container'; } echo '<div id="wcmp-category-' . uniqid() . '" class="wooproduct">'; // Store loop count we're currently on if (empty($woocommerce_loop['loop'])) { $woocommerce_loop['loop'] = 0; } // Store column count for displaying the grid if (empty($woocommerce_loop['columns'])) { $woocommerce_loop['columns'] = apply_filters('loop_shop_columns', 4); } // Increase loop count $woocommerce_loop['loop']++; ?> <div class="wcmp-carousel-item <?php $product_animation; ?> product-category <?php if (($woocommerce_loop['loop'] - 1) % $woocommerce_loop['columns'] == 0 || $woocommerce_loop['columns'] == 1) { echo ' first'; } if ($woocommerce_loop['loop'] % $woocommerce_loop['columns'] == 0) { echo ' last'; } ?> " style="<?php //echo $border; ?> "> <div class="wcmp-product wcmp-img-<?php echo $img_animate; ?> woocommerce wcmp-cat-<?php echo $design_style; ?> "> <?php do_action('woocommerce_before_subcategory', $category); ?> <a href="<?php echo get_term_link($category->slug, 'product_cat'); ?> " style="text-align:<?php echo $text_align; ?> ;"> <div class="wcmp-product-image"> <?php do_action('woocommerce_before_subcategory_title', $category); ?> </div><!--.wcmp-product-image--> <h3 style="<?php echo $size; ?> "> <?php echo $category->name; if ($category->count > 0) { echo apply_filters('woocommerce_subcategory_count_html', ' <mark class="count" style="' . $count_style . '">' . $category->count . ' ' . $cat_count . '</mark>', $category); } ?> </h3> <?php do_action('woocommerce_after_subcategory_title', $category); ?> </a> <?php do_action('woocommerce_after_subcategory', $category); ?> </div> </div> <?php echo '</div>'; } //woocommerce_product_loop_end(); } woocommerce_reset_loop(); ?> <script type="text/javascript"> jQuery(document).ready(function(e) { jQuery("#woo-carousel-<?php echo $uid; ?> > .woocomposer").slick({ infinite: <?php echo $infinite; ?> , slidesToShow: <?php echo $columns; ?> , slidesToScroll: <?php echo $slides_to_scroll; ?> , speed: <?php echo $scroll_speed; ?> , dots: <?php echo $dots; ?> , autoplay: <?php echo $autoplay; ?> , autoplaySpeed: <?php echo $autoplay_speed; ?> , responsive: [{ breakpoint: 1024, settings: { slidesToShow: 3, slidesToScroll: 3, infinite: true, dots: true } }, { breakpoint: 600, settings: { slidesToShow: 2, slidesToScroll: 2 } }, { breakpoint: 480, settings: { slidesToShow: 1, slidesToScroll: 1 } }] }); }); </script> <?php $output = '<div id="woo-carousel-' . $uid . '" class="woocommerce woocomposer_carousel wcmp-cat-carousel">'; $output .= '<div class="woocomposer" data-columns="' . $columns . '">'; $output .= ob_get_clean(); $output .= '</div>'; $output .= '</div>'; return $output; }
/** * Prepares and sends an email of a full log of background update results, useful for debugging and geekery. * * @since 3.7.0 */ protected function send_debug_email() { $update_count = 0; foreach ($this->update_results as $type => $updates) { $update_count += count($updates); } $body = array(); $failures = 0; $body[] = sprintf(__('WordPress site: %s'), network_home_url('/')); // Core if (isset($this->update_results['core'])) { $result = $this->update_results['core'][0]; if ($result->result && !is_wp_error($result->result)) { $body[] = sprintf(__('SUCCESS: WordPress was successfully updated to %s'), $result->name); } else { $body[] = sprintf(__('FAILED: WordPress failed to update to %s'), $result->name); $failures++; } $body[] = ''; } // Plugins, Themes, Translations foreach (array('plugin', 'theme', 'translation') as $type) { if (!isset($this->update_results[$type])) { continue; } $success_items = wp_list_filter($this->update_results[$type], array('result' => true)); if ($success_items) { $messages = array('plugin' => __('The following plugins were successfully updated:'), 'theme' => __('The following themes were successfully updated:'), 'translation' => __('The following translations were successfully updated:')); $body[] = $messages[$type]; foreach (wp_list_pluck($success_items, 'name') as $name) { $body[] = ' * ' . sprintf(__('SUCCESS: %s'), $name); } } if ($success_items != $this->update_results[$type]) { // Failed updates $messages = array('plugin' => __('The following plugins failed to update:'), 'theme' => __('The following themes failed to update:'), 'translation' => __('The following translations failed to update:')); $body[] = $messages[$type]; foreach ($this->update_results[$type] as $item) { if (!$item->result || is_wp_error($item->result)) { $body[] = ' * ' . sprintf(__('FAILED: %s'), $item->name); $failures++; } } } $body[] = ''; } $site_title = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($failures) { $body[] = trim(__("\nBETA TESTING?\n=============\n\nThis debugging email is sent when you are using a development version of WordPress.\n\nIf you think these failures might be due to a bug in WordPress, could you report it?\n * Open a thread in the support forums: https://wordpress.org/support/forum/alphabeta\n * Or, if you're comfortable writing a bug report: https://core.trac.wordpress.org/\n\nThanks! -- The WordPress Team")); $body[] = ''; $subject = sprintf(__('[%s] There were failures during background updates'), $site_title); } else { $subject = sprintf(__('[%s] Background updates have finished'), $site_title); } $body[] = trim(__(' UPDATE LOG ==========')); $body[] = ''; foreach (array('core', 'plugin', 'theme', 'translation') as $type) { if (!isset($this->update_results[$type])) { continue; } foreach ($this->update_results[$type] as $update) { $body[] = $update->name; $body[] = str_repeat('-', strlen($update->name)); foreach ($update->messages as $message) { $body[] = " " . html_entity_decode(str_replace('…', '...', $message)); } if (is_wp_error($update->result)) { $results = array('update' => $update->result); // If we rolled back, we want to know an error that occurred then too. if ('rollback_was_required' === $update->result->get_error_code()) { $results = (array) $update->result->get_error_data(); } foreach ($results as $result_type => $result) { if (!is_wp_error($result)) { continue; } if ('rollback' === $result_type) { /* translators: 1: Error code, 2: Error message. */ $body[] = ' ' . sprintf(__('Rollback Error: [%1$s] %2$s'), $result->get_error_code(), $result->get_error_message()); } else { /* translators: 1: Error code, 2: Error message. */ $body[] = ' ' . sprintf(__('Error: [%1$s] %2$s'), $result->get_error_code(), $result->get_error_message()); } if ($result->get_error_data()) { $body[] = ' ' . implode(', ', (array) $result->get_error_data()); } } } $body[] = ''; } } $email = array('to' => get_site_option('admin_email'), 'subject' => $subject, 'body' => implode("\n", $body), 'headers' => ''); /** * Filter the debug email that can be sent following an automatic * background core update. * * @since 3.8.0 * * @param array $email { * Array of email arguments that will be passed to wp_mail(). * * @type string $to The email recipient. An array of emails * can be returned, as handled by wp_mail(). * @type string $subject Email subject. * @type string $body Email message body. * @type string $headers Any email headers. Default empty. * } * @param int $failures The number of failures encountered while upgrading. * @param mixed $results The results of all attempted updates. */ $email = apply_filters('automatic_updates_debug_email', $email, $failures, $this->update_results); wp_mail($email['to'], wp_specialchars_decode($email['subject']), $email['body'], $email['headers']); }