本文整理汇总了PHP中rand_str函数的典型用法代码示例。如果您正苦于以下问题:PHP rand_str函数的具体用法?PHP rand_str怎么用?PHP rand_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rand_str函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
parent::setUp();
Fieldmanager_Field::$debug = true;
// insert a post
$this->post = $this->factory->post->create_and_get(array('post_title' => rand_str(), 'post_date' => '2009-07-01 00:00:00'));
}
示例2: xd_check_input
function xd_check_input($id = 1)
{
/*
*On génére un hash aléatoire qui sera
*ajouté aux formulaires, afin d'ajouter
*une vérification supplémentaire
*lors du traitement de ce dernier
*/
/*
* le parametre $id permet de selectionner le type de retour
* 0=> un input type hidden sans id
* 1=> un input type hidden avec id
* 2=> juste la valeur
*/
if (!isset($_SESSION['xd_check'])) {
//le générer
$_SESSION['xd_check'] = rand_str(25);
}
switch ($id) {
case 0:
return "<input type=\"hidden\" name=\"xd_check\" value=\"" . $_SESSION['xd_check'] . "\"/>";
break;
case 1:
return "<input type=\"hidden\" name=\"xd_check\" id=\"xd_check\" value=\"" . $_SESSION['xd_check'] . "\"/>";
break;
case 2:
return $_SESSION['xd_check'];
break;
default:
return "<input type=\"hidden\" name=\"xd_check\" id=\"xd_check\" value=\"" . $_SESSION['xd_check'] . "\"/>";
break;
}
}
示例3: setUp
function setUp()
{
parent::setUp();
sp_index_flush_data();
$this->demo_user = array('user_login' => 'author1', 'user_nicename' => 'author-nicename', 'user_pass' => rand_str(), 'role' => 'author', 'display_name' => 'Michael Scott');
$this->demo_user_id = $this->factory->user->create($this->demo_user);
$this->demo_term = array('taxonomy' => 'category', 'name' => 'cat-a', 'slug' => 'cat-a');
$this->demo_term_id = $this->factory->term->create($this->demo_term);
$post_date = '';
$this->demo_dates = array('post_date' => array('date' => '2013-02-28 01:23:45'), 'post_date_gmt' => array('date' => '2013-02-28 05:23:45'), 'post_modified' => array('date' => '2013-02-28 01:23:45'), 'post_modified_gmt' => array('date' => '2013-02-28 05:23:45'));
foreach ($this->demo_dates as &$date) {
$ts = strtotime($date['date']);
$date = array('date' => strval($date['date']), 'year' => intval(date('Y', $ts)), 'month' => intval(date('m', $ts)), 'day' => intval(date('d', $ts)), 'hour' => intval(date('H', $ts)), 'minute' => intval(date('i', $ts)), 'second' => intval(date('s', $ts)), 'week' => intval(date('W', $ts)), 'day_of_week' => intval(date('N', $ts)), 'day_of_year' => intval(date('z', $ts)), 'seconds_from_day' => intval(mktime(date('H', $ts), date('i', $ts), date('s', $ts), 1, 1, 1970)), 'seconds_from_hour' => intval(mktime(0, date('i', $ts), date('s', $ts), 1, 1, 1970)));
}
$this->demo_post = array('post_author' => $this->demo_user_id, 'post_date' => $this->demo_dates['post_date']['date'], 'post_date_gmt' => $this->demo_dates['post_date_gmt']['date'], 'post_content' => 'Welcome to <a href="http://wp.dev/">Local WordPress Dev Sites</a>. This is your first post. Edit or delete it, then start blogging!', 'post_title' => 'Hello world!', 'post_excerpt' => 'Lorem ipsum dolor sit amet', 'post_status' => 'publish', 'post_password' => 'foobar', 'post_name' => 'hello-world', 'post_parent' => 123, 'menu_order' => 456, 'post_type' => 'post', 'post_mime_type' => 'image/jpeg', 'post_category' => array($this->demo_term_id));
$this->demo_post_id = $this->factory->post->create($this->demo_post);
add_post_meta($this->demo_post_id, 'test_string', 'foo');
add_post_meta($this->demo_post_id, 'test_long', '123');
add_post_meta($this->demo_post_id, 'test_double', '123.456');
add_post_meta($this->demo_post_id, 'test_boolean_true', 'true');
add_post_meta($this->demo_post_id, 'test_boolean_false', 'false');
add_post_meta($this->demo_post_id, 'test_date', '2012-03-14 03:14:15');
SP_Sync_Manager()->sync_post($this->demo_post_id);
// Force refresh the index so the data is available immediately
SP_API()->post('_refresh');
}
示例4: upload
public function upload()
{
$img_url = array();
if (!empty($_FILES)) {
foreach ($_FILES as $file) {
if ($file["error"] > 0) {
echo "上传失败" . $_FILES["file"]["error"] . "<br>";
exit;
}
if (file_exists(STATICPATH . 'img/' . $file["name"])) {
echo $file["name"] . "已经存在!";
exit;
}
$folder = date('ym');
$img_dir = ADMIN_IMG_PATH . $folder;
!is_dir($img_dir) ? mkdir($img_dir) : null;
$new_file_name = rand_str(8) . time() . '.jpg';
move_uploaded_file($file["tmp_name"], $img_dir . '/' . $new_file_name);
$img_url[] = base_url('static/img/' . $folder . '/' . $new_file_name);
}
}
$json = json_encode($img_url);
echo $json;
exit;
}
示例5: test_wp_insert_delete_term
public function test_wp_insert_delete_term()
{
$taxonomy = 'wptests_tax';
register_taxonomy($taxonomy, 'post');
// a new unused term
$term = rand_str();
$this->assertNull(term_exists($term));
$initial_count = wp_count_terms($taxonomy);
$t = wp_insert_term($term, $taxonomy);
$this->assertInternalType('array', $t);
$this->assertNotWPError($t);
$this->assertTrue($t['term_id'] > 0);
$this->assertTrue($t['term_taxonomy_id'] > 0);
$this->assertEquals($initial_count + 1, wp_count_terms($taxonomy));
// make sure the term exists
$this->assertTrue(term_exists($term) > 0);
$this->assertTrue(term_exists($t['term_id']) > 0);
// now delete it
add_filter('delete_term', array($this, 'deleted_term_cb'), 10, 5);
$this->assertTrue(wp_delete_term($t['term_id'], $taxonomy));
remove_filter('delete_term', array($this, 'deleted_term_cb'), 10, 5);
$this->assertNull(term_exists($term));
$this->assertNull(term_exists($t['term_id']));
$this->assertEquals($initial_count, wp_count_terms($taxonomy));
}
示例6: sendtoaddress
public function sendtoaddress($address, $amount)
{
if ($amount >= $this->balance) {
throw new \Exception('Not enough balance');
}
return rand_str();
}
示例7: setUp
function setUp()
{
parent::setUp();
$this->post_date_ts = strtotime('+1 day');
$this->post_data = array('post_type' => 'page', 'post_title' => rand_str(), 'post_content' => rand_str(2000), 'post_excerpt' => rand_str(100), 'post_author' => $this->make_user_by_role('author'), 'post_date' => strftime("%Y-%m-%d %H:%M:%S", $this->post_date_ts));
$this->post_id = wp_insert_post($this->post_data);
}
示例8: test_submenu_contexts
/**
* Test context calculations for submenus.
*/
public function test_submenu_contexts()
{
$screen = get_current_screen();
$self = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : null;
$page = isset($_GET['page']) ? $_GET['page'] : null;
$submenus = _fieldmanager_registry('submenus');
_fieldmanager_registry('submenus', array());
// Spoof is_admin().
set_current_screen('dashboard-user');
// Submenu of a default WordPress menu.
$options_submenu = rand_str();
fm_register_submenu_page($options_submenu, 'options-general.php', 'Options');
$_SERVER['PHP_SELF'] = '/options-general.php';
$_GET['page'] = $options_submenu;
$this->assertEquals(array('submenu', $options_submenu), fm_calculate_context());
// Submenu of a custom menu.
$custom_menu_submenu = rand_str();
fm_register_submenu_page($custom_menu_submenu, rand_str(), 'Custom');
$_SERVER['PHP_SELF'] = '/admin.php';
$_GET['page'] = $custom_menu_submenu;
$this->assertEquals(array('submenu', $custom_menu_submenu), fm_calculate_context());
// Submenu that Fieldmanager didn't register.
$_SERVER['PHP_SELF'] = '/themes.php';
$_GET['page'] = rand_str();
$this->assertEquals(array(null, null), fm_calculate_context());
$GLOBALS['current_screen'] = $screen;
$_SERVER['PHP_SELF'] = $self;
$_GET['page'] = $page;
_fieldmanager_registry('submenus', $submenus);
}
示例9: setUp
function setUp()
{
parent::setUp();
$this->parent_term = wp_insert_term('parent' . rand_str(), 'category');
$this->assertInternalType('array', $this->parent_term);
$this->parent_term = $this->parent_term['term_id'];
}
示例10: setUp
function setUp()
{
parent::setUp();
$args = array('post_author' => 1, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_type' => 'post');
$id = wp_insert_post($args);
$this->post = get_post($id);
}
示例11: test_get_doesnt_cache_default_value
function test_get_doesnt_cache_default_value()
{
$option = rand_str();
$default = 'a default';
$this->assertEquals(get_site_option($option, $default), $default);
$this->assertFalse(get_site_option($option));
}
示例12: create_user
function create_user($username, $password, $first_name, $last_name, $email, $access)
{
$salt = rand_str(32);
$checksum = md5(md5($password) . $salt);
$s = q("insert into user values('', '" . clean_query($username) . "', '" . clean_query($checksum) . "', '" . clean_query($salt) . "', '" . clean_query($first_name) . "', '" . clean_query($last_name) . "', '" . clean_query($email) . "', '" . clean_query($access) . "');");
return a() > 0 ? true : false;
}
示例13: test_delete_user
function test_delete_user()
{
$user_id = $this->factory->user->create(array('role' => 'author'));
$user = new WP_User($user_id);
$post = array('post_author' => $user_id, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_type' => 'post');
// insert a post and make sure the ID is ok
$post_id = wp_insert_post($post);
$this->assertTrue(is_numeric($post_id));
$this->assertTrue($post_id > 0);
$post = get_post($post_id);
$this->assertEquals($post_id, $post->ID);
$post = array('post_author' => $user_id, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_type' => 'nav_menu_item');
// insert a post and make sure the ID is ok
$nav_id = wp_insert_post($post);
$this->assertTrue(is_numeric($nav_id));
$this->assertTrue($nav_id > 0);
$post = get_post($nav_id);
$this->assertEquals($nav_id, $post->ID);
wp_delete_user($user_id);
$user = new WP_User($user_id);
if (is_multisite()) {
$this->assertTrue($user->exists());
} else {
$this->assertFalse($user->exists());
}
$this->assertNotNull(get_post($post_id));
$this->assertEquals('trash', get_post($post_id)->post_status);
// nav_menu_item is delete_with_user = false so the nav post should remain published.
$this->assertNotNull(get_post($nav_id));
$this->assertEquals('publish', get_post($nav_id)->post_status);
wp_delete_post($nav_id, true);
$this->assertNull(get_post($nav_id));
wp_delete_post($post_id, true);
$this->assertNull(get_post($post_id));
}
示例14: insert_attachment
/**
* Helper function: insert an attachment to test properties of.
*
* @param int $parent_post_id
* @param str path to image to use
* @param array $post_fields Fields, in the format to be sent to `wp_insert_post()`
* @return int Post ID of inserted attachment
*/
private function insert_attachment($parent_post_id = 0, $image = null, $post_fields = array())
{
$filename = rand_str() . '.jpg';
$contents = rand_str();
if ($image) {
// @codingStandardsIgnoreStart
$filename = basename($image);
$contents = file_get_contents($image);
// @codingStandardsIgnoreEnd
}
$upload = wp_upload_bits($filename, null, $contents);
$this->assertTrue(empty($upload['error']));
$type = '';
if (!empty($upload['type'])) {
$type = $upload['type'];
} else {
$mime = wp_check_filetype($upload['file']);
if ($mime) {
$type = $mime['type'];
}
}
$attachment = wp_parse_args($post_fields, array('post_title' => basename($upload['file']), 'post_content' => 'Test Attachment', 'post_type' => 'attachment', 'post_parent' => $parent_post_id, 'post_mime_type' => $type, 'guid' => $upload['url']));
// Save the data
$id = wp_insert_attachment($attachment, $upload['file'], $parent_post_id);
wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $upload['file']));
return $id;
}
示例15: test_comment_content_length
public function test_comment_content_length() {
// `wp_new_comment()` checks REMOTE_ADDR, so we fake it to avoid PHP notices.
if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
$remote_addr = $_SERVER['REMOTE_ADDR'];
} else {
$_SERVER['REMOTE_ADDR'] = '';
}
$u = $this->factory->user->create();
$post_id = $this->factory->post->create( array( 'post_author' => $u ) );
$data = array(
'comment_post_ID' => $post_id,
'comment_author' => rand_str(),
'comment_author_url' => '',
'comment_author_email' => '',
'comment_type' => '',
'comment_content' => str_repeat( 'A', 65536 ),
'comment_date' => '2011-01-01 10:00:00',
'comment_date_gmt' => '2011-01-01 10:00:00',
);
add_filter( 'pre_option_moderation_notify', '__return_zero' );
$id = wp_new_comment( $data );
remove_filter( 'pre_option_moderation_notify', '__return_zero' );
$this->assertEmpty( $id );
// Cleanup.
if ( isset( $remote_addr ) ) {
$_SERVER['REMOTE_ADDR'] = $remote_addr;
} else {
unset( $_SERVER['REMOTE_ADDR'] );
}
}