/**
  * 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);
 }
 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);
 }
Exemple #3
0
 /**
  * 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);
     }
 }
 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);
 }
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));
    }
}
Exemple #6
0
 /**
  * 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);
 }
 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;
 }
Exemple #8
0
 /**
  * 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);
 }
Exemple #9
0
 /**
  * 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;
 }
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));
    }
}
Exemple #11
0
 /**
  * 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;
 }
/**
 * 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));
}
 /**
  * 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&')));
     }
 }
Exemple #14
0
 /**
  * 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.');
 }
 /**
  * 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);
 }
 /**
  * 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';
     }
     $response = array('general' => stats_get_from_restapi());
     switch ($range) {
         case 'day':
             $response['day'] = stats_get_from_restapi(array(), 'visits?unit=day&quantity=30');
             break;
         case 'week':
             $response['week'] = stats_get_from_restapi(array(), 'visits?unit=week&quantity=14');
             break;
         case 'month':
             $response['month'] = stats_get_from_restapi(array(), 'visits?unit=month&quantity=12&');
             break;
     }
     return rest_ensure_response($response);
 }
 /**
  * Gets the one model object with the specified id for the specified model
  * @param \EEM_Base $model
  * @param \WP_REST_Request $request
  * @return array
  */
 public function get_entity_from_model($model, $request)
 {
     $query_params = array(array($model->primary_key_name() => $request->get_param('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'] = $this->validate_context($request->get_param('caps'));
     $this->_set_debug_info('model query params', $restricted_query_params);
     $model_rows = $model->get_all_wpdb_results($restricted_query_params);
     if (!empty($model_rows)) {
         return $this->create_entity_from_wpdb_result($model, array_shift($model_rows), $request->get_param('include'), $this->validate_context($request->get_param('caps')));
     } else {
         //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities
         $lowercase_model_name = strtolower($model->get_this_model_name());
         $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params);
         if (!empty($model_rows_found_sans_restrictions)) {
             //you got shafted- it existed but we didn't want to tell you!
             return new \WP_Error('rest_user_cannot_read', sprintf(__('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), strtolower($model->get_this_model_name()), Capabilities::get_missing_permissions_string($model, $this->validate_context($request->get_param('caps')))), array('status' => 403));
         } else {
             //it's not you. It just doesn't exist
             return new \WP_Error(sprintf('rest_%s_invalid_id', $lowercase_model_name), sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), array('status' => 404));
         }
     }
 }
Exemple #18
0
 /**
  * Get stats for a group
  *
  * @since 0.4.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  * @return \WP_Error|\WP_REST_Response
  */
 public function get_stats($request)
 {
     $url = $request->get_url_params();
     $id = helpers::v('id', $url, 0);
     $group = group::read($id);
     if (!is_array($group)) {
         if (is_wp_error($group)) {
             return $group;
         }
         return ingot_rest_response(['message' => esc_html__('No group found', 'ingot')]);
     }
     $obj = new \ingot\testing\object\group($group);
     $stats = $obj->get_stats();
     if ('admin' == $request->get_param('context')) {
         $names = $obj->names();
         if (!empty($stats['variants']) && !empty($names['variants'])) {
             foreach ($names['variants'] as $v_id => $name) {
                 if (isset($stats['variants'][$v_id])) {
                     $stats['variants'][$v_id] = (array) $stats['variants'][$v_id];
                     $stats['variants'][$v_id]['name'] = $name;
                     $stats['variants'][$v_id] = (object) $stats['variants'][$v_id];
                 }
             }
         }
         $stats['names'] = $names;
     }
     return ingot_rest_response($stats, 200);
 }
Exemple #19
0
 /**
  * Get price of a product
  *
  * @since 1.1.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  * @return \WP_Error|\WP_REST_Response
  */
 public function get_price($request)
 {
     $price = price::get_price($request->get_param('plugin'), $request->get_url_params()['id']);
     return ingot_rest_response(['price' => $price]);
 }
Exemple #20
0
 /**
  * Create a response
  *
  * @since 0.2.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  * @param array $settings Optional. Current settings. If not used current settings will be queried
  *
  * @return \WP_Error|\WP_REST_Response
  */
 protected function response($request, $settings = array())
 {
     if (empty($settings)) {
         foreach (array_keys($this->args()) as $setting) {
             $settings[$setting] = \ingot\testing\crud\settings::read($setting);
         }
     }
     if ('admin' == $request->get_param('context')) {
         $valid = false;
         if (ingot_sl_check_license(false)) {
             $valid = true;
         }
         $settings['license_valid'] = (int) $valid;
     }
     return rest_ensure_response($settings);
 }
Exemple #21
0
 /**
  * Update groups associated with a post
  *
  * @since 1.0.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  * @return \WP_Error|\WP_REST_Response
  */
 public function update_posts($request)
 {
     $url = $request->get_url_params();
     $post_id = (int) helpers::v('id', $url, 0);
     $post = get_post($post_id);
     if (!is_a($post, 'WP_POST')) {
         return ingot_rest_response(['message' => esc_html__('No group found', 'ingot')]);
     }
     $obj = new posts($post);
     $obj->add($request->get_param('group_ids'));
     return ingot_rest_response($obj->get_groups());
 }
 /**
  * Delete a single Shipping Zone.
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_REST_Request|WP_Error
  */
 public function delete_item($request)
 {
     $zone = $this->get_zone($request->get_param('id'));
     if (is_wp_error($zone)) {
         return $zone;
     }
     $force = $request['force'];
     $response = $this->get_item($request);
     if ($force) {
         $zone->delete();
     } else {
         return new WP_Error('rest_trash_not_supported', __('Shipping zones do not support trashing.'), array('status' => 501));
     }
     return $response;
 }
Exemple #23
0
 /**
  * Page search
  *
  * @since 1.1.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  * @param array $settings Optional. Current settings. If not used current settings will be queried
  *
  * @return \WP_Error|\WP_REST_Response
  */
 public function page_search($request)
 {
     $posts = [];
     if (!empty($request->get_param('search'))) {
         $query = new \WP_Query(['s' => $request->get_param('search'), 'post_type' => 'page']);
         if ($query->have_posts()) {
             $_posts = array_combine(wp_list_pluck($query->posts, 'ID'), wp_list_pluck($query->posts, 'post_title'));
             foreach ($_posts as $id => $title) {
                 $posts[$id] = ['id' => $id, 'title' => $title];
             }
         }
     }
     return ingot_rest_response($posts);
 }