本文整理汇总了PHP中WP_REST_Request::get_header方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_REST_Request::get_header方法的具体用法?PHP WP_REST_Request::get_header怎么用?PHP WP_REST_Request::get_header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_REST_Request
的用法示例。
在下文中一共展示了WP_REST_Request::get_header方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onGithubRequest
/**
* This method use for handler request from Github's webhook.
*
* Because of github not required to response payload on response, so we can make a do_action instead of apply_filters
*
* @param \WP_REST_Request $request
*
* @return \WP_REST_Response
*/
public function onGithubRequest(\WP_REST_Request $request)
{
// Create the response object
$request_payload = json_decode($request->get_body());
$response = new \WP_REST_Response();
if ($request_payload) {
ob_start();
$repo = new Repository($request_payload->repository->git_url);
if ($repo->exists()) {
$event = $request->get_header('X-Github-Event');
do_action('wppm_webhook_recived_' . $event, $repo, $request_payload);
} else {
$response->set_status(404);
echo "Repo is not exist.";
}
$out_put = ob_get_clean();
$response->set_data($out_put);
} else {
$response->set_status(500);
}
return $response;
}
示例2: prepare_item_for_database
/**
* Prepares a single comment to be inserted into the database.
*
* @since 4.7.0
* @access protected
*
* @param WP_REST_Request $request Request object.
* @return array|WP_Error Prepared comment, otherwise WP_Error object.
*/
protected function prepare_item_for_database($request)
{
$prepared_comment = array();
/*
* Allow the comment_content to be set via the 'content' or
* the 'content.raw' properties of the Request object.
*/
if (isset($request['content']) && is_string($request['content'])) {
$prepared_comment['comment_content'] = $request['content'];
} elseif (isset($request['content']['raw']) && is_string($request['content']['raw'])) {
$prepared_comment['comment_content'] = $request['content']['raw'];
}
if (isset($request['post'])) {
$prepared_comment['comment_post_ID'] = (int) $request['post'];
}
if (isset($request['parent'])) {
$prepared_comment['comment_parent'] = $request['parent'];
}
if (isset($request['author'])) {
$user = new WP_User($request['author']);
if ($user->exists()) {
$prepared_comment['user_id'] = $user->ID;
$prepared_comment['comment_author'] = $user->display_name;
$prepared_comment['comment_author_email'] = $user->user_email;
$prepared_comment['comment_author_url'] = $user->user_url;
} else {
return new WP_Error('rest_comment_author_invalid', __('Invalid comment author ID.'), array('status' => 400));
}
}
if (isset($request['author_name'])) {
$prepared_comment['comment_author'] = $request['author_name'];
}
if (isset($request['author_email'])) {
$prepared_comment['comment_author_email'] = $request['author_email'];
}
if (isset($request['author_url'])) {
$prepared_comment['comment_author_url'] = $request['author_url'];
}
if (isset($request['author_ip']) && current_user_can('moderate_comments')) {
$prepared_comment['comment_author_IP'] = $request['author_ip'];
} elseif (!empty($_SERVER['REMOTE_ADDR']) && rest_is_ip_address($_SERVER['REMOTE_ADDR'])) {
$prepared_comment['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
} else {
$prepared_comment['comment_author_IP'] = '127.0.0.1';
}
if (!empty($request['author_user_agent'])) {
$prepared_comment['comment_agent'] = $request['author_user_agent'];
} elseif ($request->get_header('user_agent')) {
$prepared_comment['comment_agent'] = $request->get_header('user_agent');
}
if (!empty($request['date'])) {
$date_data = rest_get_date_with_gmt($request['date']);
if (!empty($date_data)) {
list($prepared_comment['comment_date'], $prepared_comment['comment_date_gmt']) = $date_data;
}
} elseif (!empty($request['date_gmt'])) {
$date_data = rest_get_date_with_gmt($request['date_gmt'], true);
if (!empty($date_data)) {
list($prepared_comment['comment_date'], $prepared_comment['comment_date_gmt']) = $date_data;
}
}
/**
* Filters a comment after it is prepared for the database.
*
* Allows modification of the comment right after it is prepared for the database.
*
* @since 4.7.0
*
* @param array $prepared_comment The prepared comment data for `wp_insert_comment`.
* @param WP_REST_Request $request The current request.
*/
return apply_filters('rest_preprocess_comment', $prepared_comment, $request);
}
示例3: get_entities_from_relation
/**
* Gets the collection for given relation object
*
* The same as Read::get_entities_from_model(), except if the relation
* is a HABTM relation, in which case it merges any non-foreign-key fields from
* the join-model-object into the results
*
* @param string $id the ID of the thing we are fetching related stuff from
* @param \EE_Model_Relation_Base $relation
* @param \WP_REST_Request $request
* @return array
*/
public function get_entities_from_relation($id, $relation, $request)
{
$context = $this->validate_context($request->get_param('caps'));
$model = $relation->get_this_model();
$related_model = $relation->get_other_model();
//check if they can access the 1st model object
$query_params = array(array($model->primary_key_name() => $id), 'limit' => 1);
if ($model instanceof \EEM_Soft_Delete_Base) {
$query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params);
}
$restricted_query_params = $query_params;
$restricted_query_params['caps'] = $context;
$this->_set_debug_info('main model query params', $restricted_query_params);
$this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context));
if (!(Capabilities::current_user_has_partial_access_to($related_model, $context) && $model->exists($restricted_query_params))) {
if ($relation instanceof \EE_Belongs_To_Relation) {
$related_model_name_maybe_plural = strtolower($related_model->get_this_model_name());
} else {
$related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name());
}
return new \WP_Error(sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), sprintf(__('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso'), $related_model_name_maybe_plural, $relation->get_this_model()->get_this_model_name(), implode(',', array_keys(Capabilities::get_missing_permissions($related_model, $context)))), array('status' => 403));
}
$query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params());
$query_params[0][$relation->get_this_model()->get_this_model_name() . '.' . $relation->get_this_model()->primary_key_name()] = $id;
$query_params['default_where_conditions'] = 'none';
$query_params['caps'] = $context;
if (!$request->get_header('no_rest_headers')) {
$this->_set_headers_from_query_params($relation->get_other_model(), $query_params);
}
/** @type array $results */
$results = $relation->get_other_model()->get_all_wpdb_results($query_params);
$nice_results = array();
foreach ($results as $result) {
$nice_result = $this->create_entity_from_wpdb_result($relation->get_other_model(), $result, $request);
if ($relation instanceof \EE_HABTM_Relation) {
//put the unusual stuff (properties from the HABTM relation) first, and make sure
//if there are conflicts we prefer the properties from the main model
$join_model_result = $this->create_entity_from_wpdb_result($relation->get_join_model(), $result, $request);
$joined_result = array_merge($nice_result, $join_model_result);
//but keep the meta stuff from the main model
if (isset($nice_result['meta'])) {
$joined_result['meta'] = $nice_result['meta'];
}
$nice_result = $joined_result;
}
$nice_results[] = $nice_result;
}
if ($relation instanceof \EE_Belongs_To_Relation) {
return array_shift($nice_results);
} else {
return $nice_results;
}
}