Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Admin/API
File: MarketingChannels.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* REST API MarketingChannels Controller
[2] Fix | Delete
*
[3] Fix | Delete
* Handles requests to /marketing/channels.
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
namespace Automattic\WooCommerce\Admin\API;
[7] Fix | Delete
[8] Fix | Delete
use Automattic\WooCommerce\Admin\Marketing\MarketingChannelInterface;
[9] Fix | Delete
use Automattic\WooCommerce\Admin\Marketing\MarketingChannels as MarketingChannelsService;
[10] Fix | Delete
use WC_REST_Controller;
[11] Fix | Delete
use WP_Error;
[12] Fix | Delete
use WP_REST_Request;
[13] Fix | Delete
use WP_REST_Response;
[14] Fix | Delete
[15] Fix | Delete
defined( 'ABSPATH' ) || exit;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* MarketingChannels Controller.
[19] Fix | Delete
*
[20] Fix | Delete
* @internal
[21] Fix | Delete
* @extends WC_REST_Controller
[22] Fix | Delete
* @since x.x.x
[23] Fix | Delete
*/
[24] Fix | Delete
class MarketingChannels extends WC_REST_Controller {
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Endpoint namespace.
[28] Fix | Delete
*
[29] Fix | Delete
* @var string
[30] Fix | Delete
*/
[31] Fix | Delete
protected $namespace = 'wc-admin';
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Route base.
[35] Fix | Delete
*
[36] Fix | Delete
* @var string
[37] Fix | Delete
*/
[38] Fix | Delete
protected $rest_base = 'marketing/channels';
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Register routes.
[42] Fix | Delete
*/
[43] Fix | Delete
public function register_routes() {
[44] Fix | Delete
register_rest_route(
[45] Fix | Delete
$this->namespace,
[46] Fix | Delete
'/' . $this->rest_base,
[47] Fix | Delete
array(
[48] Fix | Delete
array(
[49] Fix | Delete
'methods' => \WP_REST_Server::READABLE,
[50] Fix | Delete
'callback' => array( $this, 'get_items' ),
[51] Fix | Delete
'permission_callback' => array( $this, 'get_items_permissions_check' ),
[52] Fix | Delete
),
[53] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[54] Fix | Delete
)
[55] Fix | Delete
);
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Check whether a given request has permission to view marketing channels.
[60] Fix | Delete
*
[61] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[62] Fix | Delete
*
[63] Fix | Delete
* @return WP_Error|boolean
[64] Fix | Delete
*/
[65] Fix | Delete
public function get_items_permissions_check( $request ) {
[66] Fix | Delete
if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
[67] Fix | Delete
return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
return true;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Return installed marketing channels.
[75] Fix | Delete
*
[76] Fix | Delete
* @param WP_REST_Request $request Request data.
[77] Fix | Delete
*
[78] Fix | Delete
* @return WP_Error|WP_REST_Response
[79] Fix | Delete
*/
[80] Fix | Delete
public function get_items( $request ) {
[81] Fix | Delete
/**
[82] Fix | Delete
* MarketingChannels class.
[83] Fix | Delete
*
[84] Fix | Delete
* @var MarketingChannelsService $marketing_channels_service
[85] Fix | Delete
*/
[86] Fix | Delete
$marketing_channels_service = wc_get_container()->get( MarketingChannelsService::class );
[87] Fix | Delete
[88] Fix | Delete
$channels = $marketing_channels_service->get_registered_channels();
[89] Fix | Delete
[90] Fix | Delete
$responses = [];
[91] Fix | Delete
foreach ( $channels as $item ) {
[92] Fix | Delete
$response = $this->prepare_item_for_response( $item, $request );
[93] Fix | Delete
$responses[] = $this->prepare_response_for_collection( $response );
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
return rest_ensure_response( $responses );
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Prepares the item for the REST response.
[101] Fix | Delete
*
[102] Fix | Delete
* @param MarketingChannelInterface $item WordPress representation of the item.
[103] Fix | Delete
* @param WP_REST_Request $request Request object.
[104] Fix | Delete
*
[105] Fix | Delete
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
[106] Fix | Delete
*/
[107] Fix | Delete
public function prepare_item_for_response( $item, $request ) {
[108] Fix | Delete
$data = [
[109] Fix | Delete
'slug' => $item->get_slug(),
[110] Fix | Delete
'is_setup_completed' => $item->is_setup_completed(),
[111] Fix | Delete
'settings_url' => $item->get_setup_url(),
[112] Fix | Delete
'name' => $item->get_name(),
[113] Fix | Delete
'description' => $item->get_description(),
[114] Fix | Delete
'product_listings_status' => $item->get_product_listings_status(),
[115] Fix | Delete
'errors_count' => $item->get_errors_count(),
[116] Fix | Delete
'icon' => $item->get_icon_url(),
[117] Fix | Delete
];
[118] Fix | Delete
[119] Fix | Delete
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
[120] Fix | Delete
$data = $this->add_additional_fields_to_object( $data, $request );
[121] Fix | Delete
$data = $this->filter_response_by_context( $data, $context );
[122] Fix | Delete
[123] Fix | Delete
return rest_ensure_response( $data );
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
/**
[127] Fix | Delete
* Retrieves the item's schema, conforming to JSON Schema.
[128] Fix | Delete
*
[129] Fix | Delete
* @return array Item schema data.
[130] Fix | Delete
*/
[131] Fix | Delete
public function get_item_schema() {
[132] Fix | Delete
$schema = [
[133] Fix | Delete
'$schema' => 'http://json-schema.org/draft-04/schema#',
[134] Fix | Delete
'title' => 'marketing_channel',
[135] Fix | Delete
'type' => 'object',
[136] Fix | Delete
'properties' => [
[137] Fix | Delete
'slug' => [
[138] Fix | Delete
'description' => __( 'Unique identifier string for the marketing channel extension, also known as the plugin slug.', 'woocommerce' ),
[139] Fix | Delete
'type' => 'string',
[140] Fix | Delete
'context' => [ 'view' ],
[141] Fix | Delete
'readonly' => true,
[142] Fix | Delete
],
[143] Fix | Delete
'name' => [
[144] Fix | Delete
'description' => __( 'Name of the marketing channel.', 'woocommerce' ),
[145] Fix | Delete
'type' => 'string',
[146] Fix | Delete
'context' => [ 'view' ],
[147] Fix | Delete
'readonly' => true,
[148] Fix | Delete
],
[149] Fix | Delete
'description' => [
[150] Fix | Delete
'description' => __( 'Description of the marketing channel.', 'woocommerce' ),
[151] Fix | Delete
'type' => 'string',
[152] Fix | Delete
'context' => [ 'view' ],
[153] Fix | Delete
'readonly' => true,
[154] Fix | Delete
],
[155] Fix | Delete
'icon' => [
[156] Fix | Delete
'description' => __( 'Path to the channel icon.', 'woocommerce' ),
[157] Fix | Delete
'type' => 'string',
[158] Fix | Delete
'context' => [ 'view' ],
[159] Fix | Delete
'readonly' => true,
[160] Fix | Delete
],
[161] Fix | Delete
'is_setup_completed' => [
[162] Fix | Delete
'type' => 'boolean',
[163] Fix | Delete
'description' => __( 'Whether or not the marketing channel is set up.', 'woocommerce' ),
[164] Fix | Delete
'context' => [ 'view' ],
[165] Fix | Delete
'readonly' => true,
[166] Fix | Delete
],
[167] Fix | Delete
'settings_url' => [
[168] Fix | Delete
'description' => __( 'URL to the settings page, or the link to complete the setup/onboarding if the channel has not been set up yet.', 'woocommerce' ),
[169] Fix | Delete
'type' => 'string',
[170] Fix | Delete
'context' => [ 'view' ],
[171] Fix | Delete
'readonly' => true,
[172] Fix | Delete
],
[173] Fix | Delete
'product_listings_status' => [
[174] Fix | Delete
'description' => __( 'Status of the marketing channel\'s product listings.', 'woocommerce' ),
[175] Fix | Delete
'type' => 'string',
[176] Fix | Delete
'context' => [ 'view' ],
[177] Fix | Delete
'readonly' => true,
[178] Fix | Delete
],
[179] Fix | Delete
'errors_count' => [
[180] Fix | Delete
'description' => __( 'Number of channel issues/errors (e.g. account-related errors, product synchronization issues, etc.).', 'woocommerce' ),
[181] Fix | Delete
'type' => 'string',
[182] Fix | Delete
'context' => [ 'view' ],
[183] Fix | Delete
'readonly' => true,
[184] Fix | Delete
],
[185] Fix | Delete
],
[186] Fix | Delete
];
[187] Fix | Delete
[188] Fix | Delete
return $this->add_additional_fields_schema( $schema );
[189] Fix | Delete
}
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function