本文整理汇总了PHP中WP_REST_Request::get_param方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_REST_Request::get_param方法的具体用法?PHP WP_REST_Request::get_param怎么用?PHP WP_REST_Request::get_param使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_REST_Request
的用法示例。
在下文中一共展示了WP_REST_Request::get_param方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _create_checkin_checkout_object
/**
* Toggles whether the user is checked in or not.
*
* @param \WP_REST_Request $request
* @return \WP_Error|\WP_REST_Response
*/
protected function _create_checkin_checkout_object(\WP_REST_Request $request)
{
$reg_id = $request->get_param('REG_ID');
$dtt_id = $request->get_param('DTT_ID');
$force = $request->get_param('force');
if ($force == 'true') {
$force = true;
} else {
$force = false;
}
$reg = \EEM_Registration::instance()->get_one_by_ID($reg_id);
if (!$reg instanceof \EE_Registration) {
return $this->send_response(new \WP_Error('rest_registration_toggle_checkin_invalid_id', sprintf(__('You cannot checkin registration with ID %1$s because it doesn\'t exist.', 'event_espresso'), $reg_id), array('status' => 422)));
}
if (!\EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
return $this->send_response(new \WP_Error('rest_user_cannot_toggle_checkin', sprintf(__('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'), $reg_id), array('status' => 403)));
}
$success = $reg->toggle_checkin_status($dtt_id, !$force);
if ($success === false) {
//rely on EE_Error::add_error messages to have been added to give more data about hwy it failed
return $this->send_response(new \WP_Error('rest_toggle_checkin_failed', __('Registration checkin failed. Please see additional error data.', 'event_espresso')));
}
$checkin = \EEM_Checkin::instance()->get_one(array(array('REG_ID' => $reg_id, 'DTT_ID' => $dtt_id), 'order_by' => array('CHK_timestamp' => 'DESC')));
if (!$checkin instanceof \EE_Checkin) {
return $this->send_response(new \WP_Error('rest_toggle_checkin_error', sprintf(__('Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.', 'event_espresso'), $reg_id, $dtt_id)));
}
$requested_version = $this->get_requested_version($request->get_route());
$get_request = new \WP_REST_Request('GET', \EED_Core_Rest_Api::ee_api_namespace . $requested_version . '/checkins/' . $checkin->ID());
$get_request->set_url_params(array('id' => $checkin->ID()));
return Read::handle_request_get_one($get_request);
}
示例2: array
function push_key(WP_REST_Request $request)
{
$post_id = $request->get_param('post_id');
$nonce = $request->get_param('nonce');
$key = $request->get_param('key');
if (!wp_verify_nonce($nonce, 'register_' . $key)) {
return new WP_Error('registration', 'Validation Fail', array('status' => 404));
}
return update_post_meta($post_id, 'push_key', $key);
}
示例3: verify_session_nonce
/**
* Verify sessions nonce
*
* @since 0.3.0
*
* @param \WP_REST_Request $request Full data about the request.
*
* @return \WP_Error|\WP_REST_Response
*/
public static function verify_session_nonce($request)
{
$nonce = $request->get_param('ingot_session_nonce');
if (is_string($nonce)) {
return ingot_verify_session_nonce($nonce);
}
}
示例4: e_tags
public function e_tags(WP_REST_Request $request)
{
$id = $request->get_param("id");
if (empty($id)) {
return get_tags();
}
return wp_get_post_tags($id);
}
示例5: uoltt_api_v1_get_ship
function uoltt_api_v1_get_ship(WP_REST_Request $request)
{
global $scdb;
$ships = $scdb->get_results("SELECT * FROM ships", ARRAY_A);
$ships_arr = array();
for ($i = 0; $i < sizeof($ships); $i++) {
$name = strtolower(str_replace(" ", "_", $ships[$i]['shipname']));
$ships_arr[$name] = $ships[$i];
}
$shipname = urldecode($request->get_param('shipname'));
$shipname = strtolower(str_replace(" ", "_", $shipname));
if (isset($ships_arr[$shipname])) {
return array($ships_arr[$shipname]['shipname'] => $ships_arr[$shipname]);
} else {
return new WP_Error('uoltt_api_v1_not_found', "Ship " . $request->get_param('shipname') . " not found", array('status' => 404));
}
}
示例6: get_form
/**
* Get one form
*
* @param \WP_REST_Request $request Full data about the request.
* @return \WP_Error|\WP_REST_Response
*/
public function get_form($request)
{
$form_id = $request;
if ($request instanceof \WP_REST_Request) {
$form_id = $request->get_param('id');
}
$form = \Caldera_Forms::get_form($form_id);
if (null === $form) {
return new \WP_Error('invalid_form_id', __('Invalid Form ID', 'caldera-forms'));
}
return new \WP_REST_Response($form, 200);
}
示例7: report_plugin_data
public function report_plugin_data(WP_REST_Request $request)
{
$plugin_slug = $request->get_param('plugin');
if (!($plugin = get_page_by_path($plugin_slug, OBJECT, 'plugin'))) {
$plugin = WP_Central_Plugins_CPT::create($plugin_slug);
if (!$plugin) {
return new WP_Error('rest_user_invalid_id', __("Plugin doesn't exist."), array('status' => 404));
}
}
if (!$plugin instanceof WP_Post) {
return new WP_Error('rest_user_invalid_id', __("Plugin doesn't exist."), array('status' => 404));
}
$postdata = $request->get_param('postdata');
if (is_array($postdata)) {
foreach ($postdata as $key => $value) {
if (is_string($value)) {
$postdata[$key] = sanitize_text_field($value);
} else {
unset($postdata[$key]);
}
}
if ($postdata) {
$postdata['ID'] = $plugin->ID;
wp_update_post($postdata);
}
}
$metadata = $request->get_param('metadata');
if (is_array($metadata)) {
foreach ($metadata as $key => $value) {
if (is_array($value)) {
$value = array_map('sanitize_text_field', $value);
} else {
$value = sanitize_text_field($value);
}
update_post_meta($plugin->ID, sanitize_text_field($key), $value);
}
}
$response = new WP_REST_Response(true);
return $response;
}
示例8: get_items
/**
* Get all products from an ecommerce plugin
*
* @since 0.2.0
*
* @param \WP_REST_Request $request Full data about the request.
* @return \WP_Error|\WP_REST_Response
*/
public function get_items($request)
{
$plugin = $request->get_param('plugin');
if (!in_array($plugin, ingot_accepted_plugins_for_price_tests())) {
return new \WP_Error('ingot-invalid-plugin');
}
if ('woo' == $plugin) {
$products = $this->get_all_woo();
} elseif ('edd' == $plugin) {
$products = $this->get_all_edd();
} else {
$products = array();
}
return rest_ensure_response($products);
}
示例9: foreign_key_values
/**
* Get a list of a table's records' IDs and titles, filtered by
* `$_GET['term']`, for foreign-key fields. Only used when there are more
* than N records in a foreign table (otherwise the options are presented in
* a select list).
* @param \WP_REST_Request $request The request, with a 'table_name' parameter.
* @return array
*/
public function foreign_key_values(\WP_REST_Request $request)
{
if (!isset($this->get['term'])) {
return array();
}
$db = new Database($this->wpdb);
$table = $db->getTable($request->get_param('table_name'));
if (!$table instanceof Table) {
return array();
}
// First get any exact matches.
$out = $this->foreign_key_values_build($table, '=', $this->get['term']);
// Then get any 'contains' matches.
$out += $this->foreign_key_values_build($table, 'like', '%' . $this->get['term'] . '%');
return $out;
}
示例10: imd_v1_add
function imd_v1_add(WP_REST_Request $request)
{
require_once SC_USER_DIR . "/library/sc_user_misc.class.php";
$misc = new sc_user_misc();
global $scdb;
$values = array('sc1', 'sc2', 'forum', 'rank', 'role', 'member', 'lastUID');
if ($misc->check_vars($values)) {
$uid = $request->get_param("lastUID") + 1;
$sql = "\n\t\t\tINSERT INTO lttname\n\t\t\t(sc1,sc2,forum,rank,role,member,nameUID) VALUES\n\t\t\t('" . implode("','", array($request->get_param("sc1"), $request->get_param("sc2"), $request->get_param("forum"), $request->get_param("rank"), $request->get_param("role"), $request->get_param("member"), $uid)) . "')\n\t\t";
$scdb->query($sql);
wp_redirect("http://www.insanemaths.com/reported.cfm?noc=1");
die;
// Keeping just in case ^^ does not work
//header('Location: http://www.insanemaths.com/reported.cfm?noc=1');
} else {
return new WP_Error('imd_api_v1_incomplete_request', "Not all required variables set", array('status' => 418));
}
}
示例11: check_session_nonce
/**
* Verify session nonce when registering a click
*
* @since 0.4.0
*
* @param \WP_REST_Request $request Full data about the request.
* @return bool
*/
public function check_session_nonce($request)
{
$verified = ingot_verify_session_nonce($request->get_param('ingot_session_nonce'));
return $verified;
}
示例12: creactions_rest_request_handler
/**
* Handler for a REST Request.
*
* @since 1.1.0
*
* @todo There is a race condition in counting of the reactions.
*
* @param WP_REST_Request $request The REST Request.
*/
function creactions_rest_request_handler(WP_REST_Request $request)
{
$reaction = sanitize_key($request->get_param('reaction'));
$action = sanitize_key($request->get_param('action'));
$comment_id = absint($request->get_param('id'));
// Get reaction count before the action.
$meta_key = 'creactions_' . $reaction;
$count = get_comment_meta($comment_id, $meta_key, true);
if (empty($count)) {
$count = 0;
}
// Figure out the new reaction count.
if ('react' == $action) {
$count = (int) $count + 1;
} else {
$count = (int) $count - 1;
}
// Update comment meta accordingly.
if ($count > 0) {
update_comment_meta($comment_id, $meta_key, $count);
} else {
delete_comment_meta($comment_id, $meta_key);
}
// Deal with caching.
creactions_clear_caching($comment_id);
creactions_set_comment_cookie(wp_get_current_user());
/**
* After submitting a reaction or a revert.
*
* @since 0.1.0
*
* @param string $reaction Reaction (Emoji) alias.
* @param string $action The submitted action, 'react' or 'revert'.
* @param int $comment_id Comment ID.
* @param int $count Count of these reactions on this comment after the execution.
*/
do_action('creactions_after_submit', $action, $comment_id, $count);
return new WP_REST_Response(array('count' => $count));
}
示例13: get_stats_data
/**
* Get stats data for this site
*
* @since 4.1.0
*
* @param WP_REST_Request $data {
* Array of parameters received by request.
*
* @type string $date Date range to restrict results to.
* }
*
* @return int|string Number of spam blocked by Akismet. Otherwise, an error message.
*/
public function get_stats_data(WP_REST_Request $data)
{
// Get parameters to fetch Stats data.
$range = $data->get_param('range');
// If no parameters were passed.
if (empty($range) || !in_array($range, array('day', 'week', 'month'), true)) {
$range = 'day';
}
if (!function_exists('stats_get_from_restapi')) {
require_once JETPACK__PLUGIN_DIR . 'modules/stats.php';
}
switch ($range) {
// This is always called first on page load
case 'day':
$initial_stats = stats_get_from_restapi();
return rest_ensure_response(array('general' => $initial_stats, 'day' => isset($initial_stats->visits) ? $initial_stats->visits : array()));
case 'week':
return rest_ensure_response(array('week' => stats_get_from_restapi(array(), 'visits?unit=week&quantity=14')));
case 'month':
return rest_ensure_response(array('month' => stats_get_from_restapi(array(), 'visits?unit=month&quantity=12&')));
}
}
示例14: rest_get_term_search
/**
* Gets the terms based on the search string/taxonomy provided via the endpoint.
*
* @since 0.1.0
*
* @param WP_REST_Request $request
*
* @return array|WP_Error Array of terms if successful.
*/
public function rest_get_term_search(WP_REST_Request $request)
{
$taxonomy = $request->get_param('taxonomy');
$search_query = $request->get_param('term');
if (!$taxonomy) {
return new WP_Error('cmb2_term_select_search_fail', 'No taxonomy provided.');
}
if (!taxonomy_exists($taxonomy)) {
return new WP_Error('cmb2_term_select_search_fail', 'That taxonomy doesn\'t exist.');
}
if (empty($search_query)) {
return new WP_Error('cmb2_term_select_search_fail', 'No search query provided.');
}
if ($terms = $this->terms_search_by_taxonomy($search_query, $taxonomy)) {
return $terms;
}
return new WP_Error('cmb2_term_select_no_results', 'No search results found.');
}
示例15: update_item
/**
* Update a single Shipping Zone.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Request|WP_Error
*/
public function update_item($request)
{
$zone = $this->get_zone($request->get_param('id'));
if (is_wp_error($zone)) {
return $zone;
}
$zone_changed = false;
if (!is_null($request->get_param('name'))) {
$zone->set_zone_name($request->get_param('name'));
$zone_changed = true;
}
if (!is_null($request->get_param('order'))) {
$zone->set_zone_order($request->get_param('order'));
$zone_changed = true;
}
if ($zone_changed) {
$zone->save();
}
return $this->get_item($request);
}