本文整理汇总了PHP中wc_rand_hash函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_rand_hash函数的具体用法?PHP wc_rand_hash怎么用?PHP wc_rand_hash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_rand_hash函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: update_api_key
/**
* Create/Update API key
*/
public static function update_api_key()
{
ob_start();
global $wpdb;
check_ajax_referer('update-api-key', 'security');
if (!current_user_can('manage_woocommerce')) {
die(-1);
}
try {
if (empty($_POST['description'])) {
throw new Exception(__('Description is missing.', 'woocommerce'));
}
if (empty($_POST['user'])) {
throw new Exception(__('User is missing.', 'woocommerce'));
}
if (empty($_POST['permissions'])) {
throw new Exception(__('Permissions is missing.', 'woocommerce'));
}
$key_id = absint($_POST['key_id']);
$description = sanitize_text_field($_POST['description']);
$permissions = in_array($_POST['permissions'], array('read', 'write', 'read_write')) ? sanitize_text_field($_POST['permissions']) : 'read';
$user_id = absint($_POST['user']);
if (0 < $key_id) {
$data = array('user_id' => $user_id, 'description' => $description, 'permissions' => $permissions);
$wpdb->update($wpdb->prefix . 'woocommerce_api_keys', $data, array('key_id' => $key_id), array('%d', '%s', '%s'), array('%d'));
$data['consumer_key'] = '';
$data['consumer_secret'] = '';
$data['message'] = __('API Key updated successfully.', 'woocommerce');
} else {
$status = 2;
$consumer_key = 'ck_' . wc_rand_hash();
$consumer_secret = 'cs_' . wc_rand_hash();
$data = array('user_id' => $user_id, 'description' => $description, 'permissions' => $permissions, 'consumer_key' => wc_api_hash($consumer_key), 'consumer_secret' => $consumer_secret, 'truncated_key' => substr($consumer_key, -7));
$wpdb->insert($wpdb->prefix . 'woocommerce_api_keys', $data, array('%d', '%s', '%s', '%s', '%s', '%s'));
$key_id = $wpdb->insert_id;
$data['consumer_key'] = $consumer_key;
$data['consumer_secret'] = $consumer_secret;
$data['message'] = __('API Key generated successfully. Make sure to copy your new API keys now. You won\'t be able to see it again!', 'woocommerce');
$data['revoke_url'] = '<a style="color: #a00; text-decoration: none;" href="' . esc_url(wp_nonce_url(add_query_arg(array('revoke-key' => $key_id), admin_url('admin.php?page=wc-settings&tab=api§ion=keys')), 'revoke')) . '">' . __('Revoke Key', 'woocommerce') . '</a>';
}
wp_send_json_success($data);
} catch (Exception $e) {
wp_send_json_error(array('message' => $e->getMessage()));
}
}
开发者ID:JodiWarren,项目名称:woocommerce,代码行数:48,代码来源:class-wc-ajax.php
示例2: create_key
public function create_key()
{
include_once plugin_dir_path(dirname(__FILE__)) . '/vendor/tenbucks_registration_client/lib/TenbucksRegistrationClient.php';
$form_is_valid = true;
$required_fields = array('email', 'email_confirmation');
foreach ($required_fields as $key) {
if (!array_key_exists($key, $_POST) || empty($_POST[$key])) {
$format = __('Field %s is missing.', 'tenbucks');
return wp_send_json_error(array('message' => sprintf($format, $key), 'field' => $key));
}
}
$post_data = array_map('strtolower', $_POST);
$email = $post_data['email'];
$email_confirmation = $post_data['email_confirmation'];
$sponsor = empty($post_data['sponsor']) ? null : $post_data['sponsor'];
$error_msg = false;
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_msg = __('Invalid email.', 'tenbucks');
}
if ($email !== $email_confirmation) {
$error_msg = __('Email and confirmation are different.', 'tenbucks');
}
if ($error_msg) {
return wp_send_json_error(array('message' => $error_msg, 'field' => 'email'));
}
try {
global $wpdb;
// If API disabled, active it
if (get_option('woocommerce_api_enabled') !== 'yes') {
update_option('woocommerce_api_enabled', 'yes');
}
$key_id = (int) get_option('tenbucks_ak_id');
$consumer_key = 'ck_' . wc_rand_hash();
$consumer_secret = 'cs_' . wc_rand_hash();
$table = $wpdb->prefix . 'woocommerce_api_keys';
$data = array('user_id' => get_current_user_id(), 'consumer_key' => wc_api_hash($consumer_key), 'consumer_secret' => $consumer_secret, 'truncated_key' => substr($consumer_key, -7));
if (!$key_id) {
$data['description'] = 'tenbucks';
$data['permissions'] = 'read_write';
$wpdb->insert($table, $data, array('%d', '%s', '%s', '%s', '%s', '%s'));
update_option('tenbucks_ak_id', $wpdb->insert_id);
} else {
$updated_rows = $wpdb->update($table, $data, array('key_id' => $key_id), array('%d', '%s', '%s', '%s'), array('%d'));
if (!$updated_rows) {
update_option('tenbucks_ak_id', 0);
return wp_send_json_error(array('message' => __('Keys update failed, please try again.', 'tenbucks')));
}
}
unset($data);
$client = new TenbucksRegistrationClient();
$url = get_site_url();
$lang_infos = explode('_', get_locale());
$opts = array('email' => $email, 'sponsor' => $sponsor, 'company' => get_bloginfo('name'), 'platform' => 'WooCommerce', 'locale' => $lang_infos[0], 'country' => $lang_infos[1], 'url' => get_site_url(), 'credentials' => array('api_key' => $consumer_key, 'api_secret' => $consumer_secret));
$query = $client->send($opts);
$success = array_key_exists('success', $query) && (bool) $query['success'];
if ($success) {
// success
update_option('tenbucks_registration_complete', true);
if ($query['new_account']) {
$msg = __('New account created. Please check your emails to confirm your address and start using tenbucks.', 'tenbucks');
$need_reload = false;
} else {
$msg = __('Shop added to your existing account. Page will reload shortly.', 'tenbucks');
$need_reload = true;
}
return wp_send_json_success(array('message' => $msg, 'needReload' => $need_reload));
} else {
return wp_send_json_error(array('message' => __('Creation failed, please try again.', 'tenbucks')));
}
} catch (Exception $e) {
return wp_send_json_error(array('message' => $e->getMessage()));
}
}
开发者ID:tenbucks-io,项目名称:tenbucks_woocommerce,代码行数:73,代码来源:class-tenbucks-admin.php
示例3: create_keys
/**
* Create keys.
*
* @since 2.4.0
*
* @param string $app_name
* @param string $app_user_id
* @param string $scope
*
* @return array
*/
protected function create_keys($app_name, $app_user_id, $scope)
{
global $wpdb;
$description = sprintf(__('%s - API %s (created on %s at %s).', 'woocommerce'), wc_clean($app_name), $this->get_i18n_scope($scope), date_i18n(wc_date_format()), date_i18n(wc_time_format()));
$user = wp_get_current_user();
// Created API keys.
$permissions = in_array($scope, array('read', 'write', 'read_write')) ? sanitize_text_field($scope) : 'read';
$consumer_key = 'ck_' . wc_rand_hash();
$consumer_secret = 'cs_' . wc_rand_hash();
$wpdb->insert($wpdb->prefix . 'woocommerce_api_keys', array('user_id' => $user->ID, 'description' => $description, 'permissions' => $permissions, 'consumer_key' => wc_api_hash($consumer_key), 'consumer_secret' => $consumer_secret, 'truncated_key' => substr($consumer_key, -7)), array('%d', '%s', '%s', '%s', '%s', '%s'));
return array('key_id' => $wpdb->insert_id, 'user_id' => $app_user_id, 'consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret, 'key_permissions' => $permissions);
}
开发者ID:slavic18,项目名称:cats,代码行数:23,代码来源:class-wc-auth.php
示例4: generate_v2_api_keys
/**
* Direct copy of how API keys are generated via AJAX in WooCommerce
*
* @return boolean
*/
private function generate_v2_api_keys($user_id)
{
global $wpdb;
$consumer_key = 'ck_' . wc_rand_hash();
$consumer_secret = 'cs_' . wc_rand_hash();
$data = array('user_id' => $user_id, 'description' => 'TaxJar', 'permissions' => 'read', 'consumer_key' => wc_api_hash($consumer_key), 'consumer_secret' => $consumer_secret, 'truncated_key' => substr($consumer_key, -7));
$wpdb->insert($wpdb->prefix . 'woocommerce_api_keys', $data, array('%d', '%s', '%s', '%s', '%s', '%s'));
$key_id = $wpdb->insert_id;
return array('consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret);
}
开发者ID:JustinSainton,项目名称:taxjar-woocommerce-plugin,代码行数:15,代码来源:class-wc-taxjar-download-orders.php
注:本文中的wc_rand_hash函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论