Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Admin/API
File: Notes.php
* @param WP_REST_Request $request Full data about the request.
[500] Fix | Delete
* @return WP_Error|bool
[501] Fix | Delete
*/
[502] Fix | Delete
public function update_items_permissions_check( $request ) {
[503] Fix | Delete
if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
[504] Fix | Delete
return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
[505] Fix | Delete
}
[506] Fix | Delete
return true;
[507] Fix | Delete
}
[508] Fix | Delete
[509] Fix | Delete
/**
[510] Fix | Delete
* Prepare a path or query for serialization to the client.
[511] Fix | Delete
*
[512] Fix | Delete
* @param string $query The query, path, or URL to transform.
[513] Fix | Delete
* @return string A fully formed URL.
[514] Fix | Delete
*/
[515] Fix | Delete
public function prepare_query_for_response( $query ) {
[516] Fix | Delete
if ( empty( $query ) ) {
[517] Fix | Delete
return $query;
[518] Fix | Delete
}
[519] Fix | Delete
if ( 'https://' === substr( $query, 0, 8 ) ) {
[520] Fix | Delete
return $query;
[521] Fix | Delete
}
[522] Fix | Delete
if ( 'http://' === substr( $query, 0, 7 ) ) {
[523] Fix | Delete
return $query;
[524] Fix | Delete
}
[525] Fix | Delete
if ( '?' === substr( $query, 0, 1 ) ) {
[526] Fix | Delete
return admin_url( 'admin.php' . $query );
[527] Fix | Delete
}
[528] Fix | Delete
[529] Fix | Delete
return admin_url( $query );
[530] Fix | Delete
}
[531] Fix | Delete
[532] Fix | Delete
/**
[533] Fix | Delete
* Maybe add a nonce to a URL.
[534] Fix | Delete
*
[535] Fix | Delete
* @link https://codex.wordpress.org/WordPress_Nonces
[536] Fix | Delete
*
[537] Fix | Delete
* @param string $url The URL needing a nonce.
[538] Fix | Delete
* @param string $action The nonce action.
[539] Fix | Delete
* @param string $name The nonce name.
[540] Fix | Delete
* @return string A fully formed URL.
[541] Fix | Delete
*/
[542] Fix | Delete
private function maybe_add_nonce_to_url( string $url, string $action = '', string $name = '' ) : string {
[543] Fix | Delete
if ( empty( $action ) ) {
[544] Fix | Delete
return $url;
[545] Fix | Delete
}
[546] Fix | Delete
[547] Fix | Delete
if ( empty( $name ) ) {
[548] Fix | Delete
// Default parameter name.
[549] Fix | Delete
$name = '_wpnonce';
[550] Fix | Delete
}
[551] Fix | Delete
[552] Fix | Delete
return add_query_arg( $name, wp_create_nonce( $action ), $url );
[553] Fix | Delete
}
[554] Fix | Delete
[555] Fix | Delete
/**
[556] Fix | Delete
* Prepare a note object for serialization.
[557] Fix | Delete
*
[558] Fix | Delete
* @param array $data Note data.
[559] Fix | Delete
* @param WP_REST_Request $request Request object.
[560] Fix | Delete
* @return WP_REST_Response $response Response data.
[561] Fix | Delete
*/
[562] Fix | Delete
public function prepare_item_for_response( $data, $request ) {
[563] Fix | Delete
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
[564] Fix | Delete
$data = $this->add_additional_fields_to_object( $data, $request );
[565] Fix | Delete
$data['date_created_gmt'] = wc_rest_prepare_date_response( $data['date_created'] );
[566] Fix | Delete
$data['date_created'] = wc_rest_prepare_date_response( $data['date_created'], false );
[567] Fix | Delete
$data['date_reminder_gmt'] = wc_rest_prepare_date_response( $data['date_reminder'] );
[568] Fix | Delete
$data['date_reminder'] = wc_rest_prepare_date_response( $data['date_reminder'], false );
[569] Fix | Delete
$data['title'] = stripslashes( $data['title'] );
[570] Fix | Delete
$data['content'] = stripslashes( $data['content'] );
[571] Fix | Delete
$data['is_snoozable'] = (bool) $data['is_snoozable'];
[572] Fix | Delete
$data['is_deleted'] = (bool) $data['is_deleted'];
[573] Fix | Delete
$data['is_read'] = (bool) $data['is_read'];
[574] Fix | Delete
foreach ( (array) $data['actions'] as $key => $value ) {
[575] Fix | Delete
$data['actions'][ $key ]->label = stripslashes( $data['actions'][ $key ]->label );
[576] Fix | Delete
$data['actions'][ $key ]->url = $this->maybe_add_nonce_to_url(
[577] Fix | Delete
$this->prepare_query_for_response( $data['actions'][ $key ]->query ),
[578] Fix | Delete
(string) $data['actions'][ $key ]->nonce_action,
[579] Fix | Delete
(string) $data['actions'][ $key ]->nonce_name
[580] Fix | Delete
);
[581] Fix | Delete
$data['actions'][ $key ]->status = stripslashes( $data['actions'][ $key ]->status );
[582] Fix | Delete
}
[583] Fix | Delete
$data = $this->filter_response_by_context( $data, $context );
[584] Fix | Delete
[585] Fix | Delete
// Wrap the data in a response object.
[586] Fix | Delete
$response = rest_ensure_response( $data );
[587] Fix | Delete
$response->add_links(
[588] Fix | Delete
array(
[589] Fix | Delete
'self' => array(
[590] Fix | Delete
'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $data['id'] ) ),
[591] Fix | Delete
),
[592] Fix | Delete
'collection' => array(
[593] Fix | Delete
'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
[594] Fix | Delete
),
[595] Fix | Delete
)
[596] Fix | Delete
);
[597] Fix | Delete
/**
[598] Fix | Delete
* Filter a note returned from the API.
[599] Fix | Delete
*
[600] Fix | Delete
* Allows modification of the note data right before it is returned.
[601] Fix | Delete
*
[602] Fix | Delete
* @param WP_REST_Response $response The response object.
[603] Fix | Delete
* @param array $data The original note.
[604] Fix | Delete
* @param WP_REST_Request $request Request used to generate the response.
[605] Fix | Delete
* @since 3.9.0
[606] Fix | Delete
*/
[607] Fix | Delete
return apply_filters( 'woocommerce_rest_prepare_note', $response, $data, $request );
[608] Fix | Delete
}
[609] Fix | Delete
[610] Fix | Delete
[611] Fix | Delete
/**
[612] Fix | Delete
* Track opened emails.
[613] Fix | Delete
*
[614] Fix | Delete
* @param WP_REST_Request $request Request object.
[615] Fix | Delete
*/
[616] Fix | Delete
public function track_opened_email( $request ) {
[617] Fix | Delete
$note = NotesRepository::get_note( $request->get_param( 'note_id' ) );
[618] Fix | Delete
if ( ! $note ) {
[619] Fix | Delete
return;
[620] Fix | Delete
}
[621] Fix | Delete
[622] Fix | Delete
NotesRepository::record_tracks_event_with_user( $request->get_param( 'user_id' ), 'email_note_opened', array( 'note_name' => $note->get_name() ) );
[623] Fix | Delete
}
[624] Fix | Delete
[625] Fix | Delete
/**
[626] Fix | Delete
* Get the query params for collections.
[627] Fix | Delete
*
[628] Fix | Delete
* @return array
[629] Fix | Delete
*/
[630] Fix | Delete
public function get_collection_params() {
[631] Fix | Delete
$params = array();
[632] Fix | Delete
$params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
[633] Fix | Delete
$params['order'] = array(
[634] Fix | Delete
'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
[635] Fix | Delete
'type' => 'string',
[636] Fix | Delete
'default' => 'desc',
[637] Fix | Delete
'enum' => array( 'asc', 'desc' ),
[638] Fix | Delete
'validate_callback' => 'rest_validate_request_arg',
[639] Fix | Delete
);
[640] Fix | Delete
$params['orderby'] = array(
[641] Fix | Delete
'description' => __( 'Sort collection by object attribute.', 'woocommerce' ),
[642] Fix | Delete
'type' => 'string',
[643] Fix | Delete
'default' => 'date',
[644] Fix | Delete
'enum' => array(
[645] Fix | Delete
'note_id',
[646] Fix | Delete
'date',
[647] Fix | Delete
'type',
[648] Fix | Delete
'title',
[649] Fix | Delete
'status',
[650] Fix | Delete
),
[651] Fix | Delete
'validate_callback' => 'rest_validate_request_arg',
[652] Fix | Delete
);
[653] Fix | Delete
$params['page'] = array(
[654] Fix | Delete
'description' => __( 'Current page of the collection.', 'woocommerce' ),
[655] Fix | Delete
'type' => 'integer',
[656] Fix | Delete
'default' => 1,
[657] Fix | Delete
'sanitize_callback' => 'absint',
[658] Fix | Delete
'validate_callback' => 'rest_validate_request_arg',
[659] Fix | Delete
'minimum' => 1,
[660] Fix | Delete
);
[661] Fix | Delete
$params['per_page'] = array(
[662] Fix | Delete
'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
[663] Fix | Delete
'type' => 'integer',
[664] Fix | Delete
'default' => 10,
[665] Fix | Delete
'minimum' => 1,
[666] Fix | Delete
'maximum' => 100,
[667] Fix | Delete
'sanitize_callback' => 'absint',
[668] Fix | Delete
'validate_callback' => 'rest_validate_request_arg',
[669] Fix | Delete
);
[670] Fix | Delete
$params['type'] = array(
[671] Fix | Delete
'description' => __( 'Type of note.', 'woocommerce' ),
[672] Fix | Delete
'type' => 'array',
[673] Fix | Delete
'sanitize_callback' => 'wp_parse_slug_list',
[674] Fix | Delete
'validate_callback' => 'rest_validate_request_arg',
[675] Fix | Delete
'items' => array(
[676] Fix | Delete
'enum' => Note::get_allowed_types(),
[677] Fix | Delete
'type' => 'string',
[678] Fix | Delete
),
[679] Fix | Delete
);
[680] Fix | Delete
$params['status'] = array(
[681] Fix | Delete
'description' => __( 'Status of note.', 'woocommerce' ),
[682] Fix | Delete
'type' => 'array',
[683] Fix | Delete
'sanitize_callback' => 'wp_parse_slug_list',
[684] Fix | Delete
'validate_callback' => 'rest_validate_request_arg',
[685] Fix | Delete
'items' => array(
[686] Fix | Delete
'enum' => Note::get_allowed_statuses(),
[687] Fix | Delete
'type' => 'string',
[688] Fix | Delete
),
[689] Fix | Delete
);
[690] Fix | Delete
$params['source'] = array(
[691] Fix | Delete
'description' => __( 'Source of note.', 'woocommerce' ),
[692] Fix | Delete
'type' => 'array',
[693] Fix | Delete
'sanitize_callback' => 'wp_parse_list',
[694] Fix | Delete
'validate_callback' => 'rest_validate_request_arg',
[695] Fix | Delete
'items' => array(
[696] Fix | Delete
'type' => 'string',
[697] Fix | Delete
),
[698] Fix | Delete
);
[699] Fix | Delete
return $params;
[700] Fix | Delete
}
[701] Fix | Delete
[702] Fix | Delete
/**
[703] Fix | Delete
* Get the note's schema, conforming to JSON Schema.
[704] Fix | Delete
*
[705] Fix | Delete
* @return array
[706] Fix | Delete
*/
[707] Fix | Delete
public function get_item_schema() {
[708] Fix | Delete
$schema = array(
[709] Fix | Delete
'$schema' => 'http://json-schema.org/draft-04/schema#',
[710] Fix | Delete
'title' => 'note',
[711] Fix | Delete
'type' => 'object',
[712] Fix | Delete
'properties' => array(
[713] Fix | Delete
'id' => array(
[714] Fix | Delete
'description' => __( 'ID of the note record.', 'woocommerce' ),
[715] Fix | Delete
'type' => 'integer',
[716] Fix | Delete
'context' => array( 'view' ),
[717] Fix | Delete
'readonly' => true,
[718] Fix | Delete
),
[719] Fix | Delete
'name' => array(
[720] Fix | Delete
'description' => __( 'Name of the note.', 'woocommerce' ),
[721] Fix | Delete
'type' => 'string',
[722] Fix | Delete
'context' => array( 'view', 'edit' ),
[723] Fix | Delete
'readonly' => true,
[724] Fix | Delete
),
[725] Fix | Delete
'type' => array(
[726] Fix | Delete
'description' => __( 'The type of the note (e.g. error, warning, etc.).', 'woocommerce' ),
[727] Fix | Delete
'type' => 'string',
[728] Fix | Delete
'context' => array( 'view', 'edit' ),
[729] Fix | Delete
'readonly' => true,
[730] Fix | Delete
),
[731] Fix | Delete
'locale' => array(
[732] Fix | Delete
'description' => __( 'Locale used for the note title and content.', 'woocommerce' ),
[733] Fix | Delete
'type' => 'string',
[734] Fix | Delete
'context' => array( 'view', 'edit' ),
[735] Fix | Delete
'readonly' => true,
[736] Fix | Delete
),
[737] Fix | Delete
'title' => array(
[738] Fix | Delete
'description' => __( 'Title of the note.', 'woocommerce' ),
[739] Fix | Delete
'type' => 'string',
[740] Fix | Delete
'context' => array( 'view', 'edit' ),
[741] Fix | Delete
'readonly' => true,
[742] Fix | Delete
),
[743] Fix | Delete
'content' => array(
[744] Fix | Delete
'description' => __( 'Content of the note.', 'woocommerce' ),
[745] Fix | Delete
'type' => 'string',
[746] Fix | Delete
'context' => array( 'view', 'edit' ),
[747] Fix | Delete
'readonly' => true,
[748] Fix | Delete
),
[749] Fix | Delete
'content_data' => array(
[750] Fix | Delete
'description' => __( 'Content data for the note. JSON string. Available for re-localization.', 'woocommerce' ),
[751] Fix | Delete
'type' => 'string',
[752] Fix | Delete
'context' => array( 'view', 'edit' ),
[753] Fix | Delete
'readonly' => true,
[754] Fix | Delete
),
[755] Fix | Delete
'status' => array(
[756] Fix | Delete
'description' => __( 'The status of the note (e.g. unactioned, actioned).', 'woocommerce' ),
[757] Fix | Delete
'type' => 'string',
[758] Fix | Delete
'context' => array( 'view', 'edit' ),
[759] Fix | Delete
),
[760] Fix | Delete
'source' => array(
[761] Fix | Delete
'description' => __( 'Source of the note.', 'woocommerce' ),
[762] Fix | Delete
'type' => 'string',
[763] Fix | Delete
'context' => array( 'view', 'edit' ),
[764] Fix | Delete
'readonly' => true,
[765] Fix | Delete
),
[766] Fix | Delete
'date_created' => array(
[767] Fix | Delete
'description' => __( 'Date the note was created.', 'woocommerce' ),
[768] Fix | Delete
'type' => 'string',
[769] Fix | Delete
'context' => array( 'view', 'edit' ),
[770] Fix | Delete
'readonly' => true,
[771] Fix | Delete
),
[772] Fix | Delete
'date_created_gmt' => array(
[773] Fix | Delete
'description' => __( 'Date the note was created (GMT).', 'woocommerce' ),
[774] Fix | Delete
'type' => 'string',
[775] Fix | Delete
'context' => array( 'view', 'edit' ),
[776] Fix | Delete
'readonly' => true,
[777] Fix | Delete
),
[778] Fix | Delete
'date_reminder' => array(
[779] Fix | Delete
'description' => __( 'Date after which the user should be reminded of the note, if any.', 'woocommerce' ),
[780] Fix | Delete
'type' => 'string',
[781] Fix | Delete
'context' => array( 'view', 'edit' ),
[782] Fix | Delete
'readonly' => true, // @todo Allow date_reminder to be updated.
[783] Fix | Delete
),
[784] Fix | Delete
'date_reminder_gmt' => array(
[785] Fix | Delete
'description' => __( 'Date after which the user should be reminded of the note, if any (GMT).', 'woocommerce' ),
[786] Fix | Delete
'type' => 'string',
[787] Fix | Delete
'context' => array( 'view', 'edit' ),
[788] Fix | Delete
'readonly' => true,
[789] Fix | Delete
),
[790] Fix | Delete
'is_snoozable' => array(
[791] Fix | Delete
'description' => __( 'Whether or not a user can request to be reminded about the note.', 'woocommerce' ),
[792] Fix | Delete
'type' => 'boolean',
[793] Fix | Delete
'context' => array( 'view', 'edit' ),
[794] Fix | Delete
'readonly' => true,
[795] Fix | Delete
),
[796] Fix | Delete
'actions' => array(
[797] Fix | Delete
'description' => __( 'An array of actions, if any, for the note.', 'woocommerce' ),
[798] Fix | Delete
'type' => 'array',
[799] Fix | Delete
'context' => array( 'view', 'edit' ),
[800] Fix | Delete
'readonly' => true,
[801] Fix | Delete
),
[802] Fix | Delete
'layout' => array(
[803] Fix | Delete
'description' => __( 'The layout of the note (e.g. banner, thumbnail, plain).', 'woocommerce' ),
[804] Fix | Delete
'type' => 'string',
[805] Fix | Delete
'context' => array( 'view', 'edit' ),
[806] Fix | Delete
'readonly' => true,
[807] Fix | Delete
),
[808] Fix | Delete
'image' => array(
[809] Fix | Delete
'description' => __( 'The image of the note, if any.', 'woocommerce' ),
[810] Fix | Delete
'type' => 'string',
[811] Fix | Delete
'context' => array( 'view', 'edit' ),
[812] Fix | Delete
'readonly' => true,
[813] Fix | Delete
),
[814] Fix | Delete
'is_deleted' => array(
[815] Fix | Delete
'description' => __( 'Registers whether the note is deleted or not', 'woocommerce' ),
[816] Fix | Delete
'type' => 'boolean',
[817] Fix | Delete
'context' => array( 'view', 'edit' ),
[818] Fix | Delete
'readonly' => true,
[819] Fix | Delete
),
[820] Fix | Delete
'is_read' => array(
[821] Fix | Delete
'description' => __( 'Registers whether the note is read or not', 'woocommerce' ),
[822] Fix | Delete
'type' => 'boolean',
[823] Fix | Delete
'context' => array( 'view', 'edit' ),
[824] Fix | Delete
'readonly' => true,
[825] Fix | Delete
),
[826] Fix | Delete
),
[827] Fix | Delete
);
[828] Fix | Delete
return $this->add_additional_fields_schema( $schema );
[829] Fix | Delete
}
[830] Fix | Delete
}
[831] Fix | Delete
[832] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function