Skip to content

Commit

Permalink
Merge pull request #120 from bordoni/release/0.4.9
Browse files Browse the repository at this point in the history
Release: 0.4.9
  • Loading branch information
bordoni authored Aug 7, 2017
2 parents 13b7a7c + a2bd820 commit e429054
Show file tree
Hide file tree
Showing 20 changed files with 424 additions and 188 deletions.
2 changes: 1 addition & 1 deletion fakerpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: FakerPress
* Plugin URI: https://fakerpress.com
* Description: FakerPress is a clean way to generate fake data to your WordPress instalation, great for developers who need testing
* Version: 0.4.8
* Version: 0.4.9
* Author: Gustavo Bordoni
* Author URI: http://bordoni.me
* Text Domain: fakerpress
Expand Down
2 changes: 1 addition & 1 deletion inc/class-fp-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public function _action_admin_notices() {
// Plugin class to give the styling
'fakerpress-message',
// This is to use WordPress JS to move them above the h2
'updated-nag',
'notice',
);

if ( 0 === $k ) {
Expand Down
14 changes: 14 additions & 0 deletions inc/class-fp-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ public function __construct() {
}

public static function module_generate( $request = null ) {
/**
* Allows us to prevent `_encloseme` and `_pingme` meta when generating Posts
*
* @since 0.4.9
*
* @param bool $prevent_enclose_ping_meta
*/
$prevent_enclose_ping_meta = (bool) apply_filters( 'fakerpress.module.generate.prevent_enclose_ping_meta', true );

// This will prevent us having `_encloseme` and `_pingme`
if ( $prevent_enclose_ping_meta ) {
define( 'WP_IMPORTING', true );
}

$response = (object) array(
'status' => false,
'message' => __( 'Your request has failed', 'fakerpress' ),
Expand Down
36 changes: 35 additions & 1 deletion inc/class-fp-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,11 @@ public static function type_range( $field, $container = null, $output = 'string'
}

$min->class = array();

$min->placeholder = esc_attr__( 'e.g.: 3', 'fakerpress' );
if ( ! empty( $min->_placeholder_min ) ) {
$min->placeholder = $min->_placeholder_min;
}

$max = clone $field;
$max->_id[] = 'max';
Expand All @@ -825,7 +829,7 @@ public static function type_range( $field, $container = null, $output = 'string'

if ( isset( $field->max ) && is_numeric( $field->max ) ) {
$max->value = $field->max;
} else {
} elseif ( ! isset( $max->_prevent_disable ) || ! $max->_prevent_disable ) {
$max->disabled = true;
}

Expand All @@ -838,7 +842,11 @@ public static function type_range( $field, $container = null, $output = 'string'
}

$max->class = array();

$max->placeholder = esc_attr__( 'e.g.: 12', 'fakerpress' );
if ( ! empty( $max->_placeholder_max ) ) {
$max->placeholder = $max->_placeholder_max;
}

$content[] = self::type_input( $min, null, 'string', array() );
$content[] = '<div title="' . esc_attr__( 'To', 'fakerpress' ) . '" class="dashicons dashicons-arrow-right-alt2 dashicon-date" style="display: inline-block;"></div>';
Expand Down Expand Up @@ -1286,10 +1294,36 @@ public static function get_meta_types() {
$providers->value = implode( ',', wp_list_pluck( Module\Attachment::get_providers(), 'id' ) );
$providers->{'data-options'} = Module\Attachment::get_providers();

$size_width = clone $field;
$size_width->_id = array( 'meta', 'width' );
$size_width->_name = array( 'meta', 'width' );
$size_width->type = 'range';
$size_width->class = array();
$size_width->label = __( 'Range of possible width sizes for the image', 'fakerpress' );
$size_width->_min = 0;
$size_width->_placeholder_min = esc_attr__( 'e.g.: 350', 'fakerpress' );
$size_width->_placeholder_max = esc_attr__( 'e.g.: 900', 'fakerpress' );
$size_width->_prevent_disable = true;

$size_height = clone $field;
$size_height->_id = array( 'meta', 'height' );
$size_height->_name = array( 'meta', 'height' );
$size_height->type = 'range';
$size_height->class = array();
$size_height->label = __( 'Range of possible height sizes for the image', 'fakerpress' );
$size_height->_min = 0;
$size_height->_placeholder_min = esc_attr__( 'e.g.: 125', 'fakerpress' );
$size_height->_placeholder_max = esc_attr__( 'e.g.: 650', 'fakerpress' );
$size_height->_prevent_disable = true;

$html[] = Field::wrapper( Field::type_dropdown( $store, null, 'string' ), $store );
$html[] = Field::wrapper( Field::type_dropdown( $providers, null, 'string' ), $providers );
$html[] = Field::wrapper( Field::type_number( $default->weight, null, 'string' ), $default->weight );

// Image Dimensions
$html[] = Field::wrapper( Field::type_range( $size_width, null, 'string' ), $size_width );
$html[] = Field::wrapper( Field::type_range( $size_height, null, 'string' ), $size_height );

return implode( "\r\n", $html );
},
);
Expand Down
2 changes: 1 addition & 1 deletion inc/class-fp-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Plugin {
* @since 0.1.0
* @var string
*/
const version = '0.4.8';
const version = '0.4.9';

/**
* A static variable that holds a dinamic instance of the class
Expand Down
16 changes: 13 additions & 3 deletions inc/class-fp-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,23 @@ private function __construct() {

}

/**
* Remove the Period on the end of the Setence from Faker
*
* @param string $sentence Which sentence we should remove the period from
* @return string
*/
public function remove_sentence_period( $sentence ) {
return rtrim( $sentence, '.' );
}


/**
* From range return a random Integer
* Providing the $elements param will limit the returning integer to the total number of elements
* Providing the $total param will limit the returning integer to the total number of elements
*
* @param array|int $qty The range or integer
* @param null|int|array $elements {
* @param array|int $qty The range or integer
* @param null|int|array $total {
* @example null Will not limit the Range to a maximum int
* @example int Limits the range to this maximum
* @example array Counts the elements in array and limit to that
Expand Down
93 changes: 89 additions & 4 deletions modules/meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@
use FakerPress\Variable;
use FakerPress\Plugin;


/**
* Meta Module which will generate one Meta Value at a time
*
* @since 0.3.0
*
*/
class Meta extends Base {

/**
* Which Faker Dependencies this Module will need
*
* @since 0.3.0
*
* @var array
*/
public $dependencies = array(
'\Faker\Provider\Base',
'\Faker\Provider\Lorem',
Expand All @@ -19,31 +31,93 @@ class Meta extends Base {
'\Faker\Provider\en_US\Person',
);

/**
* Which Faker Provider class we are using here
*
* @since 0.3.0
*
* @var string
*/
public $provider = '\Faker\Provider\WP_Meta';

/**
* Wether or not FakerPress will generate a page for this
*
* @since 0.3.0
*
* @var boolean
*/
public $page = false;

// Default Object is Posts
/**
* Which type of object we are saving to
*
* @since 0.3.0
*
* @var string
*/
public $object_name = 'post';

/**
* Which object we are saving to
*
* @since 0.3.0
*
* @var integer
*/
public $object_id = 0;

/**
* Initalize and Add the correct hooks into the Meta Module
*
* @since 0.3.0
*
* @return void
*/
public function init() {
add_filter( "fakerpress.module.{$this->slug}.save", array( $this, 'do_save' ), 10, 3 );
}

/**
* Resets which original object that we will save the meta to
*
* @since 0.3.0
*
* @return self
*/
public function reset() {
parent::reset();

$this->object_id = 0;

return $this;
}

/**
* Configure which Object we will save Meta to
*
* @since 0.3.0
*
* @return self
*/
public function object( $id = 0, $name = 'post' ) {
$this->object_id = $id;
$this->object_name = $name;

return $this;
}

/**
* Generate the meta based on the Params given
*
* @since 0.3.0
*
* @param string $type Type of Meta we are dealing with
* @param string $name Name of the Meta, used to save
* @param array $args Arguments used to setup the Meta
*
* @return self
*/
public function generate() {
// Allow a bunch of params
$arguments = func_get_args();
Expand Down Expand Up @@ -79,7 +153,7 @@ public function generate() {

/**
* Allow filtering for the value for a Meta
*
*
* @since 0.4.8
*
* @param mixed $meta_value The Meta value that will be filtered
Expand All @@ -91,7 +165,7 @@ public function generate() {

/**
* Allow filtering for the Value of a specific meta value based on it's key
*
*
* @since 0.4.8
*
* @param mixed $meta_value The Meta value that will be filtered
Expand All @@ -103,6 +177,17 @@ public function generate() {
return $this;
}

/**
* Actually save the meta value into the Database
*
* @since 0.3.0
*
* @param string $return_val Unsed variable that comes from the hook
* @param string $data Data generated, meta_key and meta_value
* @param array $module Arguments used to setup the Meta
*
* @return self
*/
public function do_save( $return_val, $data, $module ) {
$status = false;

Expand Down
1 change: 1 addition & 0 deletions modules/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public function parse_request( $qty, $request = array() ) {
$this->set( 'post_date', $date );
$this->set( 'post_parent', $post_parents );
$this->set( 'post_content', $post_content_use_html, array( 'elements' => $post_content_html_tags, 'sources' => $images_origin ) );
$this->set( 'post_excerpt' );
$this->set( 'post_author', $post_author );
$this->set( 'post_type', $post_types );
$this->set( 'comment_status', $comment_status );
Expand Down
Loading

0 comments on commit e429054

Please sign in to comment.