public function parse_request($qty, $request = array()) { if (is_null($qty)) { $qty = Utils::instance()->get_qty_from_range(Variable::super(INPUT_POST, array(Plugin::$slug, 'qty'), FILTER_UNSAFE_RAW)); } if (0 === $qty) { return esc_attr__('Zero is not a good number of terms to fake...', 'fakerpress'); } $name_size = Variable::super(INPUT_POST, array(Plugin::$slug, 'size'), FILTER_UNSAFE_RAW); // Fetch taxomies $taxonomies = Variable::super($request, array('taxonomies'), FILTER_SANITIZE_STRING); $taxonomies = array_map('trim', explode(',', $taxonomies)); $taxonomies = array_intersect(get_taxonomies(array('public' => true)), $taxonomies); // Only has meta after 4.4-beta $has_metas = version_compare($GLOBALS['wp_version'], '4.4-beta', '>='); if ($has_metas) { $metas = Variable::super($request, array('meta'), FILTER_UNSAFE_RAW); } for ($i = 0; $i < $qty; $i++) { $this->set('taxonomy', $taxonomies); $this->set('name', $name_size); $this->set('description'); $this->set('parent_term'); $term_id = $this->generate()->save(); if ($has_metas && $term_id && is_numeric($term_id)) { foreach ($metas as $meta_index => $meta) { Meta::instance()->object($term_id, 'term')->generate($meta['type'], $meta['name'], $meta)->save(); } } $results[] = $term_id; } $results = array_filter((array) $results, 'absint'); return $results; }
public function name($qty = 4) { $qty = FakerPress\Utils::instance()->get_qty_from_range($qty); $name = $this->generator->sentence($qty); // This removes the last dot on the end of the sentence $name = rtrim($name, '.'); return $name; }
public function parse_request($qty, $request = array()) { if (is_null($qty)) { $qty = Utils::instance()->get_qty_from_range(Variable::super(INPUT_POST, array(Plugin::$slug, 'qty'), FILTER_UNSAFE_RAW)); } if (0 === $qty) { return esc_attr__('Zero is not a good number of comments to fake...', 'fakerpress'); } $comment_content_use_html = Variable::super($request, array('use_html'), FILTER_SANITIZE_STRING, 'off') === 'on'; $comment_content_html_tags = array_map('trim', explode(',', Variable::super($request, array('html_tags'), FILTER_SANITIZE_STRING))); $min_date = Variable::super($request, array('interval_date', 'min')); $max_date = Variable::super($request, array('interval_date', 'max')); $metas = Variable::super($request, array('meta'), FILTER_UNSAFE_RAW); $results = array(); for ($i = 0; $i < $qty; $i++) { $this->set('comment_date', $min_date, $max_date); $this->set('comment_content', $comment_content_use_html, array('elements' => $comment_content_html_tags)); $this->set('user_id', 0); $this->set('comment_author'); $this->set('comment_parent'); $this->set('comment_author_IP'); $this->set('comment_agent'); $this->set('comment_approved'); $this->set('comment_post_ID'); $this->set('comment_author_email'); $this->set('comment_author_url'); $comment_id = $this->generate()->save(); if ($comment_id && is_numeric($comment_id)) { foreach ($metas as $meta_index => $meta) { Meta::instance()->object($comment_id, 'comment')->generate($meta['type'], $meta['name'], $meta)->save(); } } $results[] = $comment_id; } $results = array_filter($results, 'absint'); return $results; }
public function tax_input($config = null) { $output = array(); if (is_null($config)) { return $output; } // The percentage of change in which the terms will be applied $rates = apply_filters('fakerpress/provider/WP_Post/tax_input.rates', array('category' => 50, 'post_tag' => 45, '__default' => 35)); // The amount of terms that might have, provide a number for exact and array( int, int ) to range $ranges = apply_filters('fakerpress/provider/WP_Post/tax_input.ranges', array('category' => array(1, 3), 'post_tag' => array(0, 15), '__default' => array(0, 3))); foreach ($config as $settings) { $settings = (object) $settings; if (is_string($settings->taxonomies)) { $settings->taxonomies = explode(',', $settings->taxonomies); } $settings->taxonomies = (array) $settings->taxonomies; if (is_string($settings->terms)) { $settings->terms = explode(',', $settings->terms); } $settings->terms = (array) $settings->terms; foreach ($settings->taxonomies as $taxonomy) { if (empty($settings->terms)) { $terms = get_terms($taxonomy, array('fields' => 'ids', 'hide_empty' => false)); } else { $terms = $settings->terms; } // Get all the term ids $terms = array_filter(array_map('absint', $terms)); if (!isset($settings->qty)) { $qty = FakerPress\Utils::instance()->get_qty_from_range(isset($ranges[$taxonomy]) ? $ranges[$taxonomy] : $ranges['__default'], $terms); } else { $qty = FakerPress\Utils::instance()->get_qty_from_range($settings->qty, $terms); } if (!isset($settings->rate)) { $rate = isset($rates[$taxonomy]) ? $rates[$taxonomy] : $rates['__default']; } else { $rate = $settings->rate; } // Select the elements based on qty $output[$taxonomy] = $this->generator->optional($rate / 100, null)->randomElements($terms, $qty); } } return $output; }