Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Admin/API
File: OnboardingTasks.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* REST API Onboarding Tasks Controller
[2] Fix | Delete
*
[3] Fix | Delete
* Handles requests to complete various onboarding tasks.
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
namespace Automattic\WooCommerce\Admin\API;
[7] Fix | Delete
[8] Fix | Delete
use Automattic\WooCommerce\Enums\ProductStatus;
[9] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Onboarding\OnboardingIndustries;
[10] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Onboarding\OnboardingProfile;
[11] Fix | Delete
use Automattic\WooCommerce\Admin\Features\Features;
[12] Fix | Delete
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
[13] Fix | Delete
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\DeprecatedExtendedTask;
[14] Fix | Delete
[15] Fix | Delete
defined( 'ABSPATH' ) || exit;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Onboarding Tasks Controller.
[19] Fix | Delete
*
[20] Fix | Delete
* @internal
[21] Fix | Delete
* @extends WC_REST_Data_Controller
[22] Fix | Delete
*/
[23] Fix | Delete
class OnboardingTasks extends \WC_REST_Data_Controller {
[24] Fix | Delete
/**
[25] Fix | Delete
* Endpoint namespace.
[26] Fix | Delete
*
[27] Fix | Delete
* @var string
[28] Fix | Delete
*/
[29] Fix | Delete
protected $namespace = 'wc-admin';
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Route base.
[33] Fix | Delete
*
[34] Fix | Delete
* @var string
[35] Fix | Delete
*/
[36] Fix | Delete
protected $rest_base = 'onboarding/tasks';
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Duration to millisecond mapping.
[40] Fix | Delete
*
[41] Fix | Delete
* @var array
[42] Fix | Delete
*/
[43] Fix | Delete
protected $duration_to_ms = array(
[44] Fix | Delete
'day' => DAY_IN_SECONDS * 1000,
[45] Fix | Delete
'hour' => HOUR_IN_SECONDS * 1000,
[46] Fix | Delete
'week' => WEEK_IN_SECONDS * 1000,
[47] Fix | Delete
);
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Register routes.
[51] Fix | Delete
*/
[52] Fix | Delete
public function register_routes() {
[53] Fix | Delete
register_rest_route(
[54] Fix | Delete
$this->namespace,
[55] Fix | Delete
'/' . $this->rest_base . '/import_sample_products',
[56] Fix | Delete
array(
[57] Fix | Delete
array(
[58] Fix | Delete
'methods' => \WP_REST_Server::CREATABLE,
[59] Fix | Delete
'callback' => array( $this, 'import_sample_products' ),
[60] Fix | Delete
'permission_callback' => array( $this, 'create_products_permission_check' ),
[61] Fix | Delete
),
[62] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[63] Fix | Delete
)
[64] Fix | Delete
);
[65] Fix | Delete
[66] Fix | Delete
register_rest_route(
[67] Fix | Delete
$this->namespace,
[68] Fix | Delete
'/' . $this->rest_base . '/create_homepage',
[69] Fix | Delete
array(
[70] Fix | Delete
array(
[71] Fix | Delete
'methods' => \WP_REST_Server::CREATABLE,
[72] Fix | Delete
'callback' => array( $this, 'create_homepage' ),
[73] Fix | Delete
'permission_callback' => array( $this, 'create_pages_permission_check' ),
[74] Fix | Delete
),
[75] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[76] Fix | Delete
)
[77] Fix | Delete
);
[78] Fix | Delete
[79] Fix | Delete
register_rest_route(
[80] Fix | Delete
$this->namespace,
[81] Fix | Delete
'/' . $this->rest_base . '/create_product_from_template',
[82] Fix | Delete
array(
[83] Fix | Delete
array(
[84] Fix | Delete
'methods' => \WP_REST_Server::CREATABLE,
[85] Fix | Delete
'callback' => array( $this, 'create_product_from_template' ),
[86] Fix | Delete
'permission_callback' => array( $this, 'create_products_permission_check' ),
[87] Fix | Delete
'args' => array_merge(
[88] Fix | Delete
$this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
[89] Fix | Delete
array(
[90] Fix | Delete
'template_name' => array(
[91] Fix | Delete
'required' => true,
[92] Fix | Delete
'type' => 'string',
[93] Fix | Delete
'description' => __( 'Product template name.', 'woocommerce' ),
[94] Fix | Delete
),
[95] Fix | Delete
)
[96] Fix | Delete
),
[97] Fix | Delete
),
[98] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[99] Fix | Delete
)
[100] Fix | Delete
);
[101] Fix | Delete
[102] Fix | Delete
register_rest_route(
[103] Fix | Delete
$this->namespace,
[104] Fix | Delete
'/' . $this->rest_base,
[105] Fix | Delete
array(
[106] Fix | Delete
array(
[107] Fix | Delete
'methods' => \WP_REST_Server::READABLE,
[108] Fix | Delete
'callback' => array( $this, 'get_tasks' ),
[109] Fix | Delete
'permission_callback' => array( $this, 'get_tasks_permission_check' ),
[110] Fix | Delete
'args' => array(
[111] Fix | Delete
'ids' => array(
[112] Fix | Delete
'description' => __( 'Optional parameter to get only specific task lists by id.', 'woocommerce' ),
[113] Fix | Delete
'type' => 'array',
[114] Fix | Delete
'sanitize_callback' => 'wp_parse_slug_list',
[115] Fix | Delete
'validate_callback' => 'rest_validate_request_arg',
[116] Fix | Delete
'items' => array(
[117] Fix | Delete
'enum' => TaskLists::get_list_ids(),
[118] Fix | Delete
'type' => 'string',
[119] Fix | Delete
),
[120] Fix | Delete
),
[121] Fix | Delete
),
[122] Fix | Delete
),
[123] Fix | Delete
array(
[124] Fix | Delete
'methods' => \WP_REST_Server::CREATABLE,
[125] Fix | Delete
'callback' => array( $this, 'get_tasks' ),
[126] Fix | Delete
'permission_callback' => array( $this, 'get_tasks_permission_check' ),
[127] Fix | Delete
'args' => $this->get_task_list_params(),
[128] Fix | Delete
),
[129] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[130] Fix | Delete
)
[131] Fix | Delete
);
[132] Fix | Delete
[133] Fix | Delete
register_rest_route(
[134] Fix | Delete
$this->namespace,
[135] Fix | Delete
'/' . $this->rest_base . '/(?P<id>[a-z0-9_\-]+)/hide',
[136] Fix | Delete
array(
[137] Fix | Delete
array(
[138] Fix | Delete
'methods' => \WP_REST_Server::EDITABLE,
[139] Fix | Delete
'callback' => array( $this, 'hide_task_list' ),
[140] Fix | Delete
'permission_callback' => array( $this, 'hide_task_list_permission_check' ),
[141] Fix | Delete
),
[142] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[143] Fix | Delete
)
[144] Fix | Delete
);
[145] Fix | Delete
[146] Fix | Delete
register_rest_route(
[147] Fix | Delete
$this->namespace,
[148] Fix | Delete
'/' . $this->rest_base . '/(?P<id>[a-z0-9_\-]+)/unhide',
[149] Fix | Delete
array(
[150] Fix | Delete
array(
[151] Fix | Delete
'methods' => \WP_REST_Server::EDITABLE,
[152] Fix | Delete
'callback' => array( $this, 'unhide_task_list' ),
[153] Fix | Delete
'permission_callback' => array( $this, 'hide_task_list_permission_check' ),
[154] Fix | Delete
),
[155] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[156] Fix | Delete
)
[157] Fix | Delete
);
[158] Fix | Delete
[159] Fix | Delete
register_rest_route(
[160] Fix | Delete
$this->namespace,
[161] Fix | Delete
'/' . $this->rest_base . '/(?P<id>[a-z0-9_\-]+)/dismiss',
[162] Fix | Delete
array(
[163] Fix | Delete
array(
[164] Fix | Delete
'methods' => \WP_REST_Server::EDITABLE,
[165] Fix | Delete
'callback' => array( $this, 'dismiss_task' ),
[166] Fix | Delete
'permission_callback' => array( $this, 'get_tasks_permission_check' ),
[167] Fix | Delete
),
[168] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[169] Fix | Delete
)
[170] Fix | Delete
);
[171] Fix | Delete
[172] Fix | Delete
register_rest_route(
[173] Fix | Delete
$this->namespace,
[174] Fix | Delete
'/' . $this->rest_base . '/(?P<id>[a-z0-9_\-]+)/undo_dismiss',
[175] Fix | Delete
array(
[176] Fix | Delete
array(
[177] Fix | Delete
'methods' => \WP_REST_Server::EDITABLE,
[178] Fix | Delete
'callback' => array( $this, 'undo_dismiss_task' ),
[179] Fix | Delete
'permission_callback' => array( $this, 'get_tasks_permission_check' ),
[180] Fix | Delete
),
[181] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[182] Fix | Delete
)
[183] Fix | Delete
);
[184] Fix | Delete
[185] Fix | Delete
register_rest_route(
[186] Fix | Delete
$this->namespace,
[187] Fix | Delete
'/' . $this->rest_base . '/(?P<id>[a-z0-9_-]+)/snooze',
[188] Fix | Delete
array(
[189] Fix | Delete
'args' => array(
[190] Fix | Delete
'duration' => array(
[191] Fix | Delete
'description' => __( 'Time period to snooze the task.', 'woocommerce' ),
[192] Fix | Delete
'type' => 'string',
[193] Fix | Delete
'validate_callback' => function( $param, $request, $key ) {
[194] Fix | Delete
return in_array( $param, array_keys( $this->duration_to_ms ), true );
[195] Fix | Delete
},
[196] Fix | Delete
),
[197] Fix | Delete
'task_list_id' => array(
[198] Fix | Delete
'description' => __( 'Optional parameter to query specific task list.', 'woocommerce' ),
[199] Fix | Delete
'type' => 'string',
[200] Fix | Delete
),
[201] Fix | Delete
),
[202] Fix | Delete
array(
[203] Fix | Delete
'methods' => \WP_REST_Server::CREATABLE,
[204] Fix | Delete
'callback' => array( $this, 'snooze_task' ),
[205] Fix | Delete
'permission_callback' => array( $this, 'snooze_task_permissions_check' ),
[206] Fix | Delete
),
[207] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[208] Fix | Delete
)
[209] Fix | Delete
);
[210] Fix | Delete
[211] Fix | Delete
register_rest_route(
[212] Fix | Delete
$this->namespace,
[213] Fix | Delete
'/' . $this->rest_base . '/(?P<id>[a-z0-9_\-]+)/action',
[214] Fix | Delete
array(
[215] Fix | Delete
array(
[216] Fix | Delete
'methods' => \WP_REST_Server::EDITABLE,
[217] Fix | Delete
'callback' => array( $this, 'action_task' ),
[218] Fix | Delete
'permission_callback' => array( $this, 'get_tasks_permission_check' ),
[219] Fix | Delete
),
[220] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[221] Fix | Delete
)
[222] Fix | Delete
);
[223] Fix | Delete
[224] Fix | Delete
register_rest_route(
[225] Fix | Delete
$this->namespace,
[226] Fix | Delete
'/' . $this->rest_base . '/(?P<id>[a-z0-9_\-]+)/undo_snooze',
[227] Fix | Delete
array(
[228] Fix | Delete
array(
[229] Fix | Delete
'methods' => \WP_REST_Server::EDITABLE,
[230] Fix | Delete
'callback' => array( $this, 'undo_snooze_task' ),
[231] Fix | Delete
'permission_callback' => array( $this, 'snooze_task_permissions_check' ),
[232] Fix | Delete
),
[233] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[234] Fix | Delete
)
[235] Fix | Delete
);
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* Check if a given request has access to create a product.
[240] Fix | Delete
*
[241] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[242] Fix | Delete
* @return WP_Error|boolean
[243] Fix | Delete
*/
[244] Fix | Delete
public function create_products_permission_check( $request ) {
[245] Fix | Delete
if ( ! wc_rest_check_post_permissions( 'product', 'create' ) ) {
[246] Fix | Delete
return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
return true;
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
/**
[253] Fix | Delete
* Check if a given request has access to create a product.
[254] Fix | Delete
*
[255] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[256] Fix | Delete
* @return WP_Error|boolean
[257] Fix | Delete
*/
[258] Fix | Delete
public function create_pages_permission_check( $request ) {
[259] Fix | Delete
if ( ! wc_rest_check_post_permissions( 'page', 'create' ) || ! current_user_can( 'manage_options' ) ) {
[260] Fix | Delete
return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create new pages.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
return true;
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
/**
[267] Fix | Delete
* Check if a given request has access to manage woocommerce.
[268] Fix | Delete
*
[269] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[270] Fix | Delete
* @return WP_Error|boolean
[271] Fix | Delete
*/
[272] Fix | Delete
public function get_tasks_permission_check( $request ) {
[273] Fix | Delete
if ( ! current_user_can( 'manage_woocommerce' ) ) {
[274] Fix | Delete
return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to retrieve onboarding tasks.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
return true;
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
/**
[281] Fix | Delete
* Check if a given request has permission to hide task lists.
[282] Fix | Delete
*
[283] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[284] Fix | Delete
* @return WP_Error|boolean
[285] Fix | Delete
*/
[286] Fix | Delete
public function hide_task_list_permission_check( $request ) {
[287] Fix | Delete
if ( ! current_user_can( 'manage_woocommerce' ) ) {
[288] Fix | Delete
return new \WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you are not allowed to hide task lists.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
return true;
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
/**
[295] Fix | Delete
* Check if a given request has access to manage woocommerce.
[296] Fix | Delete
*
[297] Fix | Delete
* @deprecated 7.8.0 snooze task is deprecated.
[298] Fix | Delete
*
[299] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[300] Fix | Delete
* @return WP_Error|boolean
[301] Fix | Delete
*/
[302] Fix | Delete
public function snooze_task_permissions_check( $request ) {
[303] Fix | Delete
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '7.8.0' );
[304] Fix | Delete
[305] Fix | Delete
if ( ! current_user_can( 'manage_woocommerce' ) ) {
[306] Fix | Delete
return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to snooze onboarding tasks.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
return true;
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
/**
[313] Fix | Delete
* Import sample products from given CSV path.
[314] Fix | Delete
*
[315] Fix | Delete
* @param string $csv_file CSV file path.
[316] Fix | Delete
* @return WP_Error|WP_REST_Response
[317] Fix | Delete
*/
[318] Fix | Delete
public static function import_sample_products_from_csv( $csv_file ) {
[319] Fix | Delete
include_once WC_ABSPATH . 'includes/import/class-wc-product-csv-importer.php';
[320] Fix | Delete
[321] Fix | Delete
if ( file_exists( $csv_file ) && class_exists( 'WC_Product_CSV_Importer' ) ) {
[322] Fix | Delete
// Override locale so we can return mappings from WooCommerce in English language stores.
[323] Fix | Delete
add_filter( 'locale', '__return_false', 9999 );
[324] Fix | Delete
$importer_class = apply_filters( 'woocommerce_product_csv_importer_class', 'WC_Product_CSV_Importer' );
[325] Fix | Delete
$args = array(
[326] Fix | Delete
'parse' => true,
[327] Fix | Delete
'mapping' => self::get_header_mappings( $csv_file ),
[328] Fix | Delete
);
[329] Fix | Delete
$args = apply_filters( 'woocommerce_product_csv_importer_args', $args, $importer_class );
[330] Fix | Delete
[331] Fix | Delete
$importer = new $importer_class( $csv_file, $args );
[332] Fix | Delete
$import = $importer->import();
[333] Fix | Delete
return $import;
[334] Fix | Delete
} else {
[335] Fix | Delete
return new \WP_Error( 'woocommerce_rest_import_error', __( 'Sorry, the sample products data file was not found.', 'woocommerce' ) );
[336] Fix | Delete
}
[337] Fix | Delete
}
[338] Fix | Delete
[339] Fix | Delete
/**
[340] Fix | Delete
* Import sample products from WooCommerce sample CSV.
[341] Fix | Delete
*
[342] Fix | Delete
* @internal
[343] Fix | Delete
* @return WP_Error|WP_REST_Response
[344] Fix | Delete
*/
[345] Fix | Delete
public static function import_sample_products() {
[346] Fix | Delete
$sample_csv_file = Features::is_enabled( 'experimental-fashion-sample-products' ) ? WC_ABSPATH . 'sample-data/experimental_fashion_sample_9_products.csv' :
[347] Fix | Delete
WC_ABSPATH . 'sample-data/experimental_sample_9_products.csv';
[348] Fix | Delete
[349] Fix | Delete
$import = self::import_sample_products_from_csv( $sample_csv_file );
[350] Fix | Delete
return rest_ensure_response( $import );
[351] Fix | Delete
}
[352] Fix | Delete
[353] Fix | Delete
/**
[354] Fix | Delete
* Creates a product from a template name passed in through the template_name param.
[355] Fix | Delete
*
[356] Fix | Delete
* @internal
[357] Fix | Delete
* @param WP_REST_Request $request Request data.
[358] Fix | Delete
* @return WP_REST_Response|WP_Error
[359] Fix | Delete
*/
[360] Fix | Delete
public static function create_product_from_template( $request ) {
[361] Fix | Delete
$template_name = basename( $request->get_param( 'template_name' ) );
[362] Fix | Delete
$template_path = __DIR__ . '/Templates/' . $template_name . '_product.csv';
[363] Fix | Delete
$template_path = apply_filters( 'woocommerce_product_template_csv_file_path', $template_path, $template_name );
[364] Fix | Delete
[365] Fix | Delete
$import = self::import_sample_products_from_csv( $template_path );
[366] Fix | Delete
[367] Fix | Delete
if ( is_wp_error( $import ) || ! is_array( $import['imported'] ) || 0 === count( $import['imported'] ) ) {
[368] Fix | Delete
return new \WP_Error(
[369] Fix | Delete
'woocommerce_rest_product_creation_error',
[370] Fix | Delete
/* translators: %s is template name */
[371] Fix | Delete
__( 'Sorry, creating the product with template failed.', 'woocommerce' ),
[372] Fix | Delete
array( 'status' => 500 )
[373] Fix | Delete
);
[374] Fix | Delete
}
[375] Fix | Delete
$product = wc_get_product( $import['imported'][0] );
[376] Fix | Delete
$product->set_status( ProductStatus::AUTO_DRAFT );
[377] Fix | Delete
$product->save();
[378] Fix | Delete
[379] Fix | Delete
return rest_ensure_response(
[380] Fix | Delete
array(
[381] Fix | Delete
'id' => $product->get_id(),
[382] Fix | Delete
)
[383] Fix | Delete
);
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
[387] Fix | Delete
/**
[388] Fix | Delete
* Get header mappings from CSV columns.
[389] Fix | Delete
*
[390] Fix | Delete
* @internal
[391] Fix | Delete
* @param string $file File path.
[392] Fix | Delete
* @return array Mapped headers.
[393] Fix | Delete
*/
[394] Fix | Delete
public static function get_header_mappings( $file ) {
[395] Fix | Delete
include_once WC_ABSPATH . 'includes/admin/importers/mappings/mappings.php';
[396] Fix | Delete
[397] Fix | Delete
$importer_class = apply_filters( 'woocommerce_product_csv_importer_class', 'WC_Product_CSV_Importer' );
[398] Fix | Delete
$importer = new $importer_class( $file, array() );
[399] Fix | Delete
$raw_headers = $importer->get_raw_keys();
[400] Fix | Delete
$default_columns = wc_importer_default_english_mappings( array() );
[401] Fix | Delete
$special_columns = wc_importer_default_special_english_mappings( array() );
[402] Fix | Delete
[403] Fix | Delete
$headers = array();
[404] Fix | Delete
foreach ( $raw_headers as $key => $field ) {
[405] Fix | Delete
$index = $field;
[406] Fix | Delete
$headers[ $index ] = $field;
[407] Fix | Delete
[408] Fix | Delete
if ( isset( $default_columns[ $field ] ) ) {
[409] Fix | Delete
$headers[ $index ] = $default_columns[ $field ];
[410] Fix | Delete
} else {
[411] Fix | Delete
foreach ( $special_columns as $regex => $special_key ) {
[412] Fix | Delete
if ( preg_match( self::sanitize_special_column_name_regex( $regex ), $field, $matches ) ) {
[413] Fix | Delete
$headers[ $index ] = $special_key . $matches[1];
[414] Fix | Delete
break;
[415] Fix | Delete
}
[416] Fix | Delete
}
[417] Fix | Delete
}
[418] Fix | Delete
}
[419] Fix | Delete
[420] Fix | Delete
return $headers;
[421] Fix | Delete
}
[422] Fix | Delete
[423] Fix | Delete
/**
[424] Fix | Delete
* Sanitize special column name regex.
[425] Fix | Delete
*
[426] Fix | Delete
* @internal
[427] Fix | Delete
* @param string $value Raw special column name.
[428] Fix | Delete
* @return string
[429] Fix | Delete
*/
[430] Fix | Delete
public static function sanitize_special_column_name_regex( $value ) {
[431] Fix | Delete
return '/' . str_replace( array( '%d', '%s' ), '(.*)', trim( quotemeta( $value ) ) ) . '/';
[432] Fix | Delete
}
[433] Fix | Delete
[434] Fix | Delete
/**
[435] Fix | Delete
* Returns a valid cover block with an image, if one exists, or background as a fallback.
[436] Fix | Delete
*
[437] Fix | Delete
* @internal
[438] Fix | Delete
* @param array $image Image to use for the cover block. Should contain a media ID and image URL.
[439] Fix | Delete
* @return string Block content.
[440] Fix | Delete
*/
[441] Fix | Delete
private static function get_homepage_cover_block( $image ) {
[442] Fix | Delete
$shop_url = get_permalink( wc_get_page_id( 'shop' ) );
[443] Fix | Delete
if ( ! empty( $image['url'] ) && ! empty( $image['id'] ) ) {
[444] Fix | Delete
return '<!-- wp:cover {"url":"' . esc_url( $image['url'] ) . '","id":' . intval( $image['id'] ) . ',"dimRatio":0} -->
[445] Fix | Delete
<div class="wp-block-cover" style="background-image:url(' . esc_url( $image['url'] ) . ')"><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"' . __( 'Write title…', 'woocommerce' ) . '","textColor":"white","fontSize":"large"} -->
[446] Fix | Delete
<p class="has-text-align-center has-large-font-size">' . __( 'Welcome to the store', 'woocommerce' ) . '</p>
[447] Fix | Delete
<!-- /wp:paragraph -->
[448] Fix | Delete
[449] Fix | Delete
<!-- wp:paragraph {"align":"center","textColor":"white"} -->
[450] Fix | Delete
<p class="has-text-color has-text-align-center">' . __( 'Write a short welcome message here', 'woocommerce' ) . '</p>
[451] Fix | Delete
<!-- /wp:paragraph -->
[452] Fix | Delete
[453] Fix | Delete
<!-- wp:buttons {"layout":{"type":"flex","justifyContent":"center"}} -->
[454] Fix | Delete
<div class="wp-block-buttons"><!-- wp:button -->
[455] Fix | Delete
<div class="wp-block-button"><a class="wp-block-button__link" href="' . esc_url( $shop_url ) . '">' . __( 'Go shopping', 'woocommerce' ) . '</a></div>
[456] Fix | Delete
<!-- /wp:button --></div>
[457] Fix | Delete
<!-- /wp:buttons --></div></div>
[458] Fix | Delete
<!-- /wp:cover -->';
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
return '<!-- wp:cover {"dimRatio":0} -->
[462] Fix | Delete
<div class="wp-block-cover"><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"' . __( 'Write title…', 'woocommerce' ) . '","textColor":"white","fontSize":"large"} -->
[463] Fix | Delete
<p class="has-text-color has-text-align-center has-large-font-size">' . __( 'Welcome to the store', 'woocommerce' ) . '</p>
[464] Fix | Delete
<!-- /wp:paragraph -->
[465] Fix | Delete
[466] Fix | Delete
<!-- wp:paragraph {"align":"center","textColor":"white"} -->
[467] Fix | Delete
<p class="has-text-color has-text-align-center">' . __( 'Write a short welcome message here', 'woocommerce' ) . '</p>
[468] Fix | Delete
<!-- /wp:paragraph -->
[469] Fix | Delete
[470] Fix | Delete
<!-- wp:buttons {"layout":{"type":"flex","justifyContent":"center"}} -->
[471] Fix | Delete
<div class="wp-block-buttons"><!-- wp:button -->
[472] Fix | Delete
<div class="wp-block-button"><a class="wp-block-button__link" href="' . esc_url( $shop_url ) . '">' . __( 'Go shopping', 'woocommerce' ) . '</a></div>
[473] Fix | Delete
<!-- /wp:button --></div>
[474] Fix | Delete
<!-- /wp:buttons --></div></div>
[475] Fix | Delete
<!-- /wp:cover -->';
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
/**
[479] Fix | Delete
* Returns a valid media block with an image, if one exists, or a uninitialized media block the user can set.
[480] Fix | Delete
*
[481] Fix | Delete
* @internal
[482] Fix | Delete
* @param array $image Image to use for the cover block. Should contain a media ID and image URL.
[483] Fix | Delete
* @param string $align If the image should be aligned to the left or right.
[484] Fix | Delete
* @return string Block content.
[485] Fix | Delete
*/
[486] Fix | Delete
private static function get_homepage_media_block( $image, $align = 'left' ) {
[487] Fix | Delete
$media_position = 'right' === $align ? '"mediaPosition":"right",' : '';
[488] Fix | Delete
$css_class = 'right' === $align ? ' has-media-on-the-right' : '';
[489] Fix | Delete
[490] Fix | Delete
if ( ! empty( $image['url'] ) && ! empty( $image['id'] ) ) {
[491] Fix | Delete
return '<!-- wp:media-text {' . $media_position . '"mediaId":' . intval( $image['id'] ) . ',"mediaType":"image"} -->
[492] Fix | Delete
<div class="wp-block-media-text alignwide' . $css_class . '""><figure class="wp-block-media-text__media"><img src="' . esc_url( $image['url'] ) . '" alt="" class="wp-image-' . intval( $image['id'] ) . '"/></figure><div class="wp-block-media-text__content"><!-- wp:paragraph {"placeholder":"' . __( 'Content…', 'woocommerce' ) . '","fontSize":"large"} -->
[493] Fix | Delete
<p class="has-large-font-size"></p>
[494] Fix | Delete
<!-- /wp:paragraph --></div></div>
[495] Fix | Delete
<!-- /wp:media-text -->';
[496] Fix | Delete
}
[497] Fix | Delete
[498] Fix | Delete
return '<!-- wp:media-text {' . $media_position . '} -->
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function