/** * Record a conversion * * @since 0.4.0 * * @param \WP_REST_Request $request Full data about the request. * @return \WP_Error|\WP_REST_Request */ public function conversion($request) { if (!ingot_is_bot()) { $id = $request->get_param('id'); ingot_register_conversion($id, $request->get_param('ingot_session_ID')); } return ingot_rest_response(['message' => ':)'], 200); }
/** * Prepare response for session data * * @since 0.3.0 * * @access protected * * @param array|\WP_Error $session Session array or error. * * @return \WP_Error|\WP_REST_Response */ protected function response($session) { if (is_wp_error($session)) { return ingot_rest_response($session, 500); } else { return ingot_rest_response($session, 200); } }
/** * 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); }
/** * 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]); }
/** * 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()); }
/** * 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); }