本文整理汇总了PHP中MS_Factory::_reset方法的典型用法代码示例。如果您正苦于以下问题:PHP MS_Factory::_reset方法的具体用法?PHP MS_Factory::_reset怎么用?PHP MS_Factory::_reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MS_Factory
的用法示例。
在下文中一共展示了MS_Factory::_reset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reset
/**
* Resets the database.
*
* @since 1.0.0
*/
public static function reset()
{
global $wpdb;
// wipe all existing data.
$wpdb->query("TRUNCATE TABLE {$wpdb->users};");
$wpdb->query("TRUNCATE TABLE {$wpdb->usermeta};");
$wpdb->query("TRUNCATE TABLE {$wpdb->posts};");
$wpdb->query("TRUNCATE TABLE {$wpdb->postmeta};");
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '%transient_%';");
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'MS_%';");
self::$ids = array('user' => array(), 'post' => array(), 'membership' => array());
// create demo users
$users = array('admin' => array('role' => 'administrator'), 'editor' => array('role' => 'editor'));
foreach ($users as $login => $data) {
$defaults = array('user_login' => $login, 'user_pass' => $login . '-password', 'user_email' => $login . '@local.dev', 'role' => 'subscriber', 'user_nicename' => '', 'user_url' => '', 'display_name' => 'User ' . $login, 'nickname' => '', 'first_name' => '', 'last_name' => '', 'description' => '', 'user_registered' => '');
$data = shortcode_atts($defaults, $data);
$id = wp_insert_user($data);
if (!empty($data['meta'])) {
foreach ($data['meta'] as $key => $val) {
$val = maybe_serialize($val);
update_user_meta($id, $key, $val);
}
}
self::$ids['user'][$login] = $id;
}
// create demo posts
$posts = array('sample-post' => array('post_content' => 'Just a very simple sample post...'), 'sample-page' => array('post_type' => 'page', 'post_content' => 'Just a very simple sample page...'));
foreach ($posts as $slug => $data) {
$defaults = array('post_type' => 'post', 'post_author' => self::id('user', 'admin'), 'post_title' => $slug, 'post_name' => $slug);
$data = shortcode_atts($defaults, $data);
$id = wp_insert_post($data);
if (!empty($data['meta'])) {
foreach ($data['meta'] as $key => $val) {
$val = maybe_serialize($val);
update_post_meta($id, $key, $val);
}
}
self::$ids['post'][$slug] = $id;
}
// create demo memberships
$memberships = array('simple' => array('name' => 'Simple Membership', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_PERMANENT, 'price' => 29, 'rule_values' => array()), 'simple-free' => array('name' => 'Simple Membership', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_PERMANENT, 'is_free' => true, 'price' => 0, 'rule_values' => array()), 'simple-trial' => array('name' => 'Simple Membership with Trial', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_PERMANENT, 'price' => 29, 'rule_values' => array(), 'trial_period_enabled' => true, 'trial_period' => array('period_unit' => 14, 'period_type' => 'days')), 'limited' => array('name' => 'Limited Membership', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_FINITE, 'price' => 19, 'rule_values' => array(), 'period' => array('period_unit' => 28, 'period_type' => 'days')), 'limited-trial' => array('name' => 'Limited Membership with Trial', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_FINITE, 'price' => 19, 'rule_values' => array(), 'period' => array('period_unit' => 28, 'period_type' => 'days'), 'trial_period_enabled' => true, 'trial_period' => array('period_unit' => 14, 'period_type' => 'days')), 'daterange-trial' => array('name' => 'Date-Range Membership with Trial', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_DATE_RANGE, 'price' => 39, 'rule_values' => array(), 'period_date_start' => date('Y-m-d', time() + self::ONE_DAY), 'period_date_end' => date('Y-m-d', time() + 10 * self::ONE_DAY), 'trial_period_enabled' => true, 'trial_period' => array('period_unit' => 14, 'period_type' => 'days')), 'free-limited' => array('name' => 'Free Limited Membership', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_FINITE, 'is_free' => true, 'price' => 0, 'rule_values' => array(), 'period' => array('period_unit' => 28, 'period_type' => 'days')), 'recurring' => array('name' => 'Unit-Test Recurring', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_RECURRING, 'is_free' => false, 'price' => 4, 'rule_values' => array(), 'pay_cycle_period' => array('period_unit' => 7, 'period_type' => 'days'), 'pay_cycle_repetitions' => 2));
foreach ($memberships as $key => $data) {
$item = new MS_Model_Membership();
foreach ($data as $prop => $val) {
if (!property_exists($item, $prop)) {
continue;
}
$item->{$prop} = $val;
}
$item->save();
$id = $item->id;
self::$ids['membership'][$key] = $id;
}
// Prepare Payment Gateways.
$gateway = MS_Model_Gateway::factory(MS_Gateway_Stripe::ID);
$gateway->mode = MS_Gateway::MODE_SANDBOX;
$gateway->active = true;
$gateway->test_secret_key = 'sk_test_MSKvYHhIm3kKNr4tshnZHIEk';
$gateway->test_publishable_key = 'pk_test_h8fk0CAW287ToA3o6aeehThB';
$gateway->save();
$gateway = MS_Model_Gateway::factory(MS_Gateway_Stripeplan::ID);
$gateway->mode = MS_Gateway::MODE_SANDBOX;
$gateway->active = true;
$gateway->test_secret_key = 'sk_test_MSKvYHhIm3kKNr4tshnZHIEk';
$gateway->test_publishable_key = 'pk_test_h8fk0CAW287ToA3o6aeehThB';
$gateway->save();
// Clear the plugin Factory-Cache
MS_Factory::_reset();
}