Applied PHPCS To Beta Tester (#39476)
This commit is contained in:
parent
8f147eafb2
commit
4549bc82c5
|
@ -9,8 +9,6 @@ defaults:
|
|||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
env:
|
||||
PHPCS: ./plugins/woocommerce/vendor/bin/phpcs # Run WooCommerce phpcs setup in phpcs-changed instead of default
|
||||
|
||||
permissions: {}
|
||||
|
||||
|
@ -30,6 +28,7 @@ jobs:
|
|||
id: changed-files
|
||||
uses: tj-actions/changed-files@v32
|
||||
with:
|
||||
path: plugins/woocommerce
|
||||
files: |
|
||||
**/*.php
|
||||
|
||||
|
@ -41,6 +40,7 @@ jobs:
|
|||
|
||||
- name: Tool versions
|
||||
if: steps.changed-files.outputs.any_changed == 'true'
|
||||
working-directory: plugins/woocommerce
|
||||
run: |
|
||||
php --version
|
||||
composer --version
|
||||
|
@ -48,6 +48,7 @@ jobs:
|
|||
|
||||
- name: Run PHPCS
|
||||
if: steps.changed-files.outputs.any_changed == 'true'
|
||||
working-directory: plugins/woocommerce
|
||||
run: |
|
||||
HEAD_REF=$(git rev-parse HEAD)
|
||||
git checkout $HEAD_REF
|
||||
|
|
|
@ -20,6 +20,10 @@ jobs:
|
|||
- name: Setup WooCommerce Monorepo
|
||||
uses: ./.github/actions/setup-woocommerce-monorepo
|
||||
|
||||
- name: Lint
|
||||
working-directory: plugins/woocommerce-beta-tester
|
||||
run: composer run phpcs
|
||||
|
||||
- name: Build WooCommerce Beta Tester Zip
|
||||
working-directory: plugins/woocommerce-beta-tester
|
||||
run: pnpm build:zip
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"phpVersion": "7.4",
|
||||
"plugins": [
|
||||
".",
|
||||
"https://downloads.wordpress.org/plugin/woocommerce.zip"
|
||||
]
|
||||
}
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use Automattic\WooCommerce\Admin\Notes\Note;
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
|
@ -6,21 +9,25 @@ register_woocommerce_admin_test_helper_rest_route(
|
|||
'admin_notes_add_note'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Adds an admin note.
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
*/
|
||||
function admin_notes_add_note( $request ) {
|
||||
$note = new Note();
|
||||
$note = new Note();
|
||||
$mock_note_data = get_mock_note_data();
|
||||
$type = $request->get_param( 'type' );
|
||||
$layout = $request->get_param( 'layout' );
|
||||
$type = $request->get_param( 'type' );
|
||||
$layout = $request->get_param( 'layout' );
|
||||
|
||||
$note->set_name( $request->get_param( 'name' ) );
|
||||
$note->set_title( $request->get_param( 'title' ) );
|
||||
$note->set_content( $mock_note_data[ 'content' ] );
|
||||
$note->set_content( $mock_note_data['content'] );
|
||||
$note->set_image( $mock_note_data[ $type ][ $layout ] );
|
||||
$note->set_layout( $layout );
|
||||
$note->set_type( $type );
|
||||
possibly_add_action( $note );
|
||||
|
||||
|
||||
if ( 'email' === $type ) {
|
||||
add_email_note_params( $note );
|
||||
}
|
||||
|
@ -30,6 +37,11 @@ function admin_notes_add_note( $request ) {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an email note parameter.
|
||||
*
|
||||
* @param Note $note The note to add parameters to.
|
||||
*/
|
||||
function add_email_note_params( $note ) {
|
||||
$additional_data = array(
|
||||
'role' => 'administrator',
|
||||
|
@ -37,6 +49,11 @@ function add_email_note_params( $note ) {
|
|||
$note->set_content_data( (object) $additional_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Possibly adds an action to a note.
|
||||
*
|
||||
* @param Note $note The note to check and add an action to.
|
||||
*/
|
||||
function possibly_add_action( $note ) {
|
||||
if ( $note->get_type() === 'info' ) {
|
||||
return;
|
||||
|
@ -48,20 +65,23 @@ function possibly_add_action( $note ) {
|
|||
$note->add_action( $action_name, 'Test action', wc_admin_url() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets mock note data.
|
||||
*/
|
||||
function get_mock_note_data() {
|
||||
$plugin_url = site_url() . '/wp-content/plugins/woocommerce-admin-test-helper/';
|
||||
return array(
|
||||
'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud.',
|
||||
'info' => array(
|
||||
'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud.',
|
||||
'info' => array(
|
||||
'banner' => $plugin_url . 'images/admin-notes/banner.jpg',
|
||||
'thumbnail' => $plugin_url . 'images/admin-notes/thumbnail.jpg',
|
||||
'plain' => ''
|
||||
'plain' => '',
|
||||
),
|
||||
'email' => array(
|
||||
'plain' => $plugin_url . 'images/admin-notes/woocommerce-logo-vector.png'
|
||||
'email' => array(
|
||||
'plain' => $plugin_url . 'images/admin-notes/woocommerce-logo-vector.png',
|
||||
),
|
||||
'update' => array(
|
||||
'plain' => '',
|
||||
),
|
||||
'update' => array(
|
||||
'plain' => ''
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/admin-notes/delete-all-notes/v1',
|
||||
'admin_notes_delete_all_notes'
|
||||
);
|
||||
|
||||
/**
|
||||
* Deletes all admin notes.
|
||||
*/
|
||||
function admin_notes_delete_all_notes() {
|
||||
global $wpdb;
|
||||
|
||||
|
||||
$deleted_note_count = $wpdb->query( "DELETE FROM {$wpdb->prefix}wc_admin_notes" );
|
||||
$deleted_action_count = $wpdb->query( "DELETE FROM {$wpdb->prefix}wc_admin_note_actions" );
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
* @package WC_Beta_Tester
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Register the test helper route.
|
||||
*
|
||||
|
@ -23,7 +25,7 @@ function register_woocommerce_admin_test_helper_rest_route( $route, $callback, $
|
|||
if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
|
||||
return new \WP_Error(
|
||||
'woocommerce_rest_cannot_edit',
|
||||
__( 'Sorry, you cannot perform this action', 'woocommerce' )
|
||||
__( 'Sorry, you cannot perform this action', 'woocommerce-beta-tester' )
|
||||
);
|
||||
}
|
||||
return true;
|
||||
|
@ -52,7 +54,7 @@ require 'tools/disable-wc-email.php';
|
|||
require 'tools/trigger-update-callbacks.php';
|
||||
require 'tracks/class-tracks-debug-log.php';
|
||||
require 'features/features.php';
|
||||
require 'rest-api-filters/rest-api-filters.php';
|
||||
require 'rest-api-filters/class-wca-test-helper-rest-api-filters.php';
|
||||
require 'rest-api-filters/hook.php';
|
||||
require 'live-branches/manifest.php';
|
||||
require 'live-branches/install.php';
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
<?php
|
||||
use Automattic\WooCommerce\Admin\Features\Features;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
const OPTION_NAME_PREFIX = 'wc_admin_helper_feature_values';
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/features/(?P<feature_name>[a-z0-9_\-]+)/toggle',
|
||||
'toggle_feature',
|
||||
array(
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
)
|
||||
);
|
||||
|
@ -27,33 +28,44 @@ register_woocommerce_admin_test_helper_rest_route(
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Toggles a feature.
|
||||
*
|
||||
* @param WP_REST_Request $request Full data about the request.
|
||||
*/
|
||||
function toggle_feature( $request ) {
|
||||
$features = get_features();
|
||||
$custom_feature_values = get_option( OPTION_NAME_PREFIX, array() );
|
||||
$feature_name = $request->get_param( 'feature_name' );
|
||||
$features = get_features();
|
||||
$custom_feature_values = get_option( OPTION_NAME_PREFIX, array() );
|
||||
$feature_name = $request->get_param( 'feature_name' );
|
||||
|
||||
if ( ! isset( $features[$feature_name ]) ) {
|
||||
return new WP_REST_Response( $features, 204 );
|
||||
}
|
||||
|
||||
if ( isset( $custom_feature_values[$feature_name] ) ) {
|
||||
unset( $custom_feature_values[$feature_name] );
|
||||
} else {
|
||||
$custom_feature_values[$feature_name] = ! $features[ $feature_name ];
|
||||
}
|
||||
if ( ! isset( $features[ $feature_name ] ) ) {
|
||||
return new WP_REST_Response( $features, 204 );
|
||||
}
|
||||
|
||||
update_option(OPTION_NAME_PREFIX, $custom_feature_values );
|
||||
if ( isset( $custom_feature_values[ $feature_name ] ) ) {
|
||||
unset( $custom_feature_values[ $feature_name ] );
|
||||
} else {
|
||||
$custom_feature_values[ $feature_name ] = ! $features[ $feature_name ];
|
||||
}
|
||||
|
||||
update_option( OPTION_NAME_PREFIX, $custom_feature_values );
|
||||
return new WP_REST_Response( get_features(), 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all features to their default values.
|
||||
*/
|
||||
function reset_features() {
|
||||
delete_option( OPTION_NAME_PREFIX );
|
||||
return new WP_REST_Response( get_features(), 200 );
|
||||
delete_option( OPTION_NAME_PREFIX );
|
||||
return new WP_REST_Response( get_features(), 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all features.
|
||||
*/
|
||||
function get_features() {
|
||||
if ( function_exists( 'wc_admin_get_feature_config' ) ) {
|
||||
return apply_filters( 'woocommerce_admin_get_feature_config', wc_admin_get_feature_config() );
|
||||
}
|
||||
return array();
|
||||
if ( function_exists( 'wc_admin_get_feature_config' ) ) {
|
||||
return apply_filters( 'woocommerce_admin_get_feature_config', wc_admin_get_feature_config() );
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
<?php // @codingStandardsIgnoreLine I don't know why it thinks the doc comment is missing.
|
||||
<?php
|
||||
/**
|
||||
* REST API endpoints for live branches installation.
|
||||
*
|
||||
* @package WC_Beta_Tester
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
require_once __DIR__ . '/../../includes/class-wc-beta-tester-live-branches-installer.php';
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
|
@ -37,7 +39,7 @@ register_woocommerce_admin_test_helper_rest_route(
|
|||
} else {
|
||||
return new \WP_Error(
|
||||
'woocommerce_rest_cannot_edit',
|
||||
__( 'Sorry, you cannot perform this action', 'woocommerce' )
|
||||
__( 'Sorry, you cannot perform this action', 'woocommerce-beta-tester' )
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
<?php // @codingStandardsIgnoreLine
|
||||
<?php
|
||||
/**
|
||||
* Register REST endpoint for fetching live branches manifest.
|
||||
*
|
||||
* @package WC_Beta_Tester
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
require_once __DIR__ . '/../../includes/class-wc-beta-tester-live-branches-installer.php';
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
<?php
|
||||
|
||||
use function WP_CLI\Utils\esc_like;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/options',
|
||||
'wca_test_helper_get_options',
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
'args' => array(
|
||||
'args' => array(
|
||||
'page' => array(
|
||||
'description' => 'Current page of the collection.',
|
||||
'type' => 'integer',
|
||||
|
@ -32,28 +36,39 @@ register_woocommerce_admin_test_helper_rest_route(
|
|||
'wca_test_helper_delete_option',
|
||||
array(
|
||||
'methods' => 'DELETE',
|
||||
'args' => array(
|
||||
'args' => array(
|
||||
'option_names' => array(
|
||||
'type' => 'string',
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* A helper to delete options.
|
||||
*
|
||||
* @param WP_REST_Request $request The full request data.
|
||||
*/
|
||||
function wca_test_helper_delete_option( $request ) {
|
||||
global $wpdb;
|
||||
$option_names = explode( ',', $request->get_param( 'option_names' ) );
|
||||
$option_names = array_map( function( $option_name ) {
|
||||
return "'" . $option_name . "'";
|
||||
}, $option_names );
|
||||
$option_names = explode( ',', $request->get_param( 'option_names' ) );
|
||||
$option_tokens = implode( ',', array_fill( 0, count( $option_names ), '%s' ) );
|
||||
|
||||
$option_names = implode( ',', $option_names );
|
||||
$query = "delete from {$wpdb->prefix}options where option_name in ({$option_names})";
|
||||
$wpdb->query( $query );
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$wpdb->prefix}options WHERE option_name IN ({$option_tokens})", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
|
||||
...$option_names,
|
||||
)
|
||||
);
|
||||
|
||||
return new WP_REST_RESPONSE( null, 204 );
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper to get options.
|
||||
*
|
||||
* @param WP_REST_Request $request The full request data.
|
||||
*/
|
||||
function wca_test_helper_get_options( $request ) {
|
||||
global $wpdb;
|
||||
|
||||
|
@ -61,18 +76,23 @@ function wca_test_helper_get_options( $request ) {
|
|||
$page = $request->get_param( 'page' );
|
||||
$search = $request->get_param( 'search' );
|
||||
|
||||
$query = "
|
||||
select option_id, option_name, option_value, autoload
|
||||
from {$wpdb->prefix}options
|
||||
";
|
||||
$query = "SELECT option_id, option_name, option_value, autoload FROM {$wpdb->prefix}options";
|
||||
|
||||
if ( $search ) {
|
||||
$query .= "where option_name like '%{$search}%'";
|
||||
$search = $wpdb->esc_like( $search );
|
||||
$query .= ' WHERE option_name LIKE %s';
|
||||
}
|
||||
|
||||
$query .= ' order by option_id desc limit 30';
|
||||
$query .= ' ORDER BY option_id DESC LIMIT %d OFFSET %d';
|
||||
$offset = ( $page - 1 ) * $per_page;
|
||||
|
||||
$options = $wpdb->get_results( $query );
|
||||
if ( $search ) {
|
||||
$query = $wpdb->prepare( $query, $search, $per_page, $offset ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
} else {
|
||||
$query = $wpdb->prepare( $query, $per_page, $offset ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
}
|
||||
|
||||
$options = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
|
||||
return new WP_REST_Response( $options, 200 );
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/rest-api-filters',
|
||||
array( WCA_Test_Helper_Rest_Api_Filters::class, 'create' ),
|
||||
|
@ -52,7 +54,9 @@ register_woocommerce_admin_test_helper_rest_route(
|
|||
)
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Class WCA_Test_Helper_Rest_Api_Filters.
|
||||
*/
|
||||
class WCA_Test_Helper_Rest_Api_Filters {
|
||||
const WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION = 'wc-admin-test-helper-rest-api-filters';
|
||||
|
|
@ -1,52 +1,66 @@
|
|||
<?php
|
||||
|
||||
$filters = get_option(WCA_Test_Helper_Rest_Api_Filters::WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION, [] );
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
$filters = get_option( WCA_Test_Helper_Rest_Api_Filters::WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION, array() );
|
||||
|
||||
/**
|
||||
* Sets an array value using dot notation.
|
||||
*
|
||||
* @param array $array The array to set the value on.
|
||||
* @param string $key The dot notation key to set.
|
||||
* @param mixed $value The value to set.
|
||||
*/
|
||||
function array_dot_set( &$array, $key, $value ) {
|
||||
if ( is_null( $key ) ) {
|
||||
return $array = $value;
|
||||
}
|
||||
if ( is_null( $key ) ) {
|
||||
$array = $value;
|
||||
return $array;
|
||||
}
|
||||
|
||||
$keys = explode('.', $key);
|
||||
$keys = explode( '.', $key );
|
||||
|
||||
while ( count($keys) > 1 ) {
|
||||
$key = array_shift($keys);
|
||||
if (! isset($array[$key]) || ! is_array($array[$key]) ) {
|
||||
$array[$key] = [];
|
||||
}
|
||||
$array = &$array[$key];
|
||||
}
|
||||
$key_count = count( $keys );
|
||||
while ( $key_count > 1 ) {
|
||||
$key = array_shift( $keys );
|
||||
if ( ! isset( $array[ $key ] ) || ! is_array( $array[ $key ] ) ) {
|
||||
$array[ $key ] = array();
|
||||
}
|
||||
$array = &$array[ $key ];
|
||||
|
||||
$array[ array_shift($keys) ] = $value;
|
||||
return $array;
|
||||
--$key_count;
|
||||
}
|
||||
|
||||
$array[ array_shift( $keys ) ] = $value;
|
||||
return $array;
|
||||
}
|
||||
|
||||
add_filter(
|
||||
'rest_request_after_callbacks',
|
||||
function ( $response, array $handler, \WP_REST_Request $request ) use ( $filters ) {
|
||||
if (! $response instanceof \WP_REST_Response ) {
|
||||
return $response;
|
||||
}
|
||||
$route = $request->get_route();
|
||||
$filters = array_filter(
|
||||
$filters, function ( $filter ) use ( $request, $route ) {
|
||||
if ($filter['enabled'] && $filter['endpoint'] == $route ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
'rest_request_after_callbacks',
|
||||
function ( $response, array $handler, \WP_REST_Request $request ) use ( $filters ) {
|
||||
if ( ! $response instanceof \WP_REST_Response ) {
|
||||
return $response;
|
||||
}
|
||||
$route = $request->get_route();
|
||||
$filters = array_filter(
|
||||
$filters,
|
||||
function ( $filter ) use ( $request, $route ) {
|
||||
if ( $filter['enabled'] && $filter['endpoint'] === $route ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
$data = $response->get_data();
|
||||
$data = $response->get_data();
|
||||
|
||||
foreach ( $filters as $filter ) {
|
||||
array_dot_set($data, $filter['dot_notation'], $filter['replacement']);
|
||||
}
|
||||
foreach ( $filters as $filter ) {
|
||||
array_dot_set( $data, $filter['dot_notation'], $filter['replacement'] );
|
||||
}
|
||||
|
||||
$response->set_data($data);
|
||||
$response->set_data( $data );
|
||||
|
||||
return $response;
|
||||
},
|
||||
10,
|
||||
3
|
||||
);
|
||||
return $response;
|
||||
},
|
||||
10,
|
||||
3
|
||||
);
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/tools/delete-all-products/v1',
|
||||
'tools_delete_all_products'
|
||||
);
|
||||
|
||||
/**
|
||||
* A tool to delete all products.
|
||||
*/
|
||||
function tools_delete_all_products() {
|
||||
$query = new \WC_Product_Query();
|
||||
$products = $query->get_products();
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/tools/toggle-emails/v1',
|
||||
'toggle_emails'
|
||||
|
@ -12,32 +15,48 @@ register_woocommerce_admin_test_helper_rest_route(
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* A tool to toggle all WooCommerce emails.
|
||||
*/
|
||||
function toggle_emails() {
|
||||
$emails_disabled = 'yes';
|
||||
if ( $emails_disabled === get_option( 'wc_admin_test_helper_email_disabled', 'no' ) ) {
|
||||
if ( get_option( 'wc_admin_test_helper_email_disabled', 'no' ) === $emails_disabled ) {
|
||||
$emails_disabled = 'no';
|
||||
remove_filter('woocommerce_email_get_option', 'disable_wc_emails' );
|
||||
remove_filter( 'woocommerce_email_get_option', 'disable_wc_emails' );
|
||||
}
|
||||
update_option('wc_admin_test_helper_email_disabled', $emails_disabled );
|
||||
update_option( 'wc_admin_test_helper_email_disabled', $emails_disabled );
|
||||
return new WP_REST_Response( $emails_disabled, 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* A tool to get the status of the WooCommerce emails option.
|
||||
*/
|
||||
function get_email_status() {
|
||||
$emails_disabled = get_option( 'wc_admin_test_helper_email_disabled', 'no' );
|
||||
return new WP_REST_Response( $emails_disabled, 200 );
|
||||
}
|
||||
|
||||
if ( 'yes' === get_option( 'wc_admin_test_helper_email_disabled', 'no' ) ) {
|
||||
add_filter('woocommerce_email_get_option', 'disable_wc_emails' );
|
||||
add_filter( 'woocommerce_email_get_option', 'disable_wc_emails' );
|
||||
add_action( 'woocommerce_email', 'unhook_other_wc_emails' );
|
||||
}
|
||||
|
||||
/**
|
||||
* A hook for filtering the disabling of WooCommerce emails.
|
||||
*
|
||||
* @param string $key The email option key.
|
||||
*/
|
||||
function disable_wc_emails( $key ) {
|
||||
if ( $key === 'enabled' ) {
|
||||
if ( 'enabled' === $key ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unhooks WooCommerce emails.
|
||||
*
|
||||
* @param Object $email The email object.
|
||||
*/
|
||||
function unhook_other_wc_emails( $email ) {
|
||||
remove_action( 'woocommerce_low_stock_notification', array( $email, 'low_stock' ) );
|
||||
remove_action( 'woocommerce_no_stock_notification', array( $email, 'no_stock' ) );
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/tools/run-wc-admin-daily/v1',
|
||||
'tools_run_wc_admin_daily'
|
||||
);
|
||||
|
||||
/**
|
||||
* A tool to run the daily wc-admin cron.
|
||||
*/
|
||||
function tools_run_wc_admin_daily() {
|
||||
do_action('wc_admin_daily');
|
||||
do_action( 'wc_admin_daily' );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/tools/get-cron-list/v1',
|
||||
'tools_get_cron_list',
|
||||
|
@ -11,8 +14,8 @@ register_woocommerce_admin_test_helper_rest_route(
|
|||
'trigger_selected_cron',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'args' => array(
|
||||
'hook' => array(
|
||||
'args' => array(
|
||||
'hook' => array(
|
||||
'description' => 'Name of the cron that will be triggered.',
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
|
@ -26,6 +29,9 @@ register_woocommerce_admin_test_helper_rest_route(
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* A tool to list the crons for WooCommerce Admin.
|
||||
*/
|
||||
function tools_get_cron_list() {
|
||||
$crons = _get_cron_array();
|
||||
$events = array();
|
||||
|
@ -47,6 +53,11 @@ function tools_get_cron_list() {
|
|||
return new WP_REST_Response( $events, 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* A tool to trigger a selected cron.
|
||||
*
|
||||
* @param WP_REST_Request $request The full request data.
|
||||
*/
|
||||
function trigger_selected_cron( $request ) {
|
||||
$hook = $request->get_param( 'hook' );
|
||||
$signature = $request->get_param( 'signature' );
|
||||
|
@ -66,10 +77,13 @@ function trigger_selected_cron( $request ) {
|
|||
return $scheduled;
|
||||
}
|
||||
|
||||
add_filter( 'cron_request', function( array $cron_request ) {
|
||||
$cron_request['url'] = add_query_arg( 'run-cron', 1, $cron_request['url'] );
|
||||
return $cron_request;
|
||||
} );
|
||||
add_filter(
|
||||
'cron_request',
|
||||
function( array $cron_request ) {
|
||||
$cron_request['url'] = add_query_arg( 'run-cron', 1, $cron_request['url'] );
|
||||
return $cron_request;
|
||||
}
|
||||
);
|
||||
|
||||
spawn_cron();
|
||||
sleep( 1 );
|
||||
|
@ -79,6 +93,12 @@ function trigger_selected_cron( $request ) {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a cron event.
|
||||
*
|
||||
* @param string $hook The hook to schedule.
|
||||
* @param array $args The arguments to use for the event.
|
||||
*/
|
||||
function schedule_event( $hook, $args = array() ) {
|
||||
$event = (object) array(
|
||||
'hook' => $hook,
|
||||
|
@ -87,7 +107,8 @@ function schedule_event( $hook, $args = array() ) {
|
|||
'args' => $args,
|
||||
);
|
||||
$crons = (array) _get_cron_array();
|
||||
$key = md5( serialize( $event->args ) );
|
||||
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
|
||||
$key = md5( serialize( $event->args ) );
|
||||
|
||||
$crons[ $event->timestamp ][ $event->hook ][ $key ] = array(
|
||||
'schedule' => $event->schedule,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
use Automattic\WooCommerce\Admin\API\Reports\Cache;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/tools/get-update-versions/v1',
|
||||
|
@ -14,29 +14,37 @@ register_woocommerce_admin_test_helper_rest_route(
|
|||
'trigger_selected_update_callbacks',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'args' => array(
|
||||
'version' => array(
|
||||
'args' => array(
|
||||
'version' => array(
|
||||
'description' => 'Name of the update version',
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
)
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* A tool to get the list of WooCommerce Admin update versions.
|
||||
*/
|
||||
function tools_get_wc_admin_versions() {
|
||||
$db_updates = \WC_Install::get_db_update_callbacks();
|
||||
$db_updates = \WC_Install::get_db_update_callbacks();
|
||||
|
||||
return new WP_REST_Response( array_keys( $db_updates ), 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the selected version update callback.
|
||||
*
|
||||
* @param WP_REST_Request $request The full request data.
|
||||
*/
|
||||
function trigger_selected_update_callbacks( $request ) {
|
||||
$version = $request->get_param( 'version' );
|
||||
if ( ! isset( $version ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$db_updates = \WC_Install::get_db_update_callbacks();
|
||||
$db_updates = \WC_Install::get_db_update_callbacks();
|
||||
$update_callbacks = $db_updates[ $version ];
|
||||
|
||||
foreach ( $update_callbacks as $update_callback ) {
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/tools/trigger-wca-install/v1',
|
||||
'tools_trigger_wca_install'
|
||||
);
|
||||
|
||||
/**
|
||||
* A tool to trigger the WooCommerce install.
|
||||
*/
|
||||
function tools_trigger_wca_install() {
|
||||
\WC_Install::install();
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
* @package WC_Beta_Tester
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Tracks_Debug_Log.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
Significance: patch
|
||||
Type: dev
|
||||
Comment: Added PHPCS and fixed linting errors.
|
||||
|
||||
|
|
@ -30,11 +30,11 @@ class WC_Beta_Tester_Admin_Assets {
|
|||
$version = WC_VERSION;
|
||||
|
||||
// Need admin styles for the modal.
|
||||
wp_register_style( 'wc-beta-tester-admin', WC_Beta_Tester::instance()->plugin_url() . '/assets/css/admin.css', array( 'woocommerce_admin_styles' ) );
|
||||
wp_register_style( 'wc-beta-tester-admin', WC_Beta_Tester::instance()->plugin_url() . '/assets/css/admin.css', array( 'woocommerce_admin_styles' ), WC_BETA_TESTER_VERSION );
|
||||
|
||||
// Register scripts.
|
||||
wp_register_script( 'wc-beta-tester-version-info', WC_Beta_Tester::instance()->plugin_url() . '/assets/js/version-information' . $suffix . '.js', array( 'wc-backbone-modal' ), WC_BETA_TESTER_VERSION );
|
||||
wp_register_script( 'wc-beta-tester-version-picker', WC_Beta_Tester::instance()->plugin_url() . '/assets/js/version-picker' . $suffix . '.js', array( 'wc-backbone-modal' ), WC_BETA_TESTER_VERSION );
|
||||
wp_register_script( 'wc-beta-tester-version-info', WC_Beta_Tester::instance()->plugin_url() . '/assets/js/version-information' . $suffix . '.js', array( 'wc-backbone-modal' ), WC_BETA_TESTER_VERSION, false );
|
||||
wp_register_script( 'wc-beta-tester-version-picker', WC_Beta_Tester::instance()->plugin_url() . '/assets/js/version-picker' . $suffix . '.js', array( 'wc-backbone-modal' ), WC_BETA_TESTER_VERSION, false );
|
||||
|
||||
wp_localize_script(
|
||||
'wc-beta-tester-version-info',
|
||||
|
@ -54,7 +54,7 @@ class WC_Beta_Tester_Admin_Assets {
|
|||
)
|
||||
);
|
||||
|
||||
if ( in_array( $screen_id, array( 'plugins_page_wc-beta-tester', 'plugins_page_wc-beta-tester-version-picker' ) ) ) {
|
||||
if ( in_array( $screen_id, array( 'plugins_page_wc-beta-tester', 'plugins_page_wc-beta-tester-version-picker' ), true ) ) {
|
||||
wp_enqueue_style( 'wc-beta-tester-admin' );
|
||||
wp_enqueue_script( 'wc-beta-tester-version-info' );
|
||||
wp_enqueue_script( 'wc-beta-tester-version-picker' );
|
||||
|
|
|
@ -10,7 +10,7 @@ defined( 'ABSPATH' ) || exit;
|
|||
/**
|
||||
* Settings Class.
|
||||
*/
|
||||
class WC_Beta_Tester_Settings {
|
||||
class WC_Beta_Tester_Channel {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -62,9 +62,9 @@ class WC_Beta_Tester_Settings {
|
|||
* @param array $args Arguments.
|
||||
*/
|
||||
public function update_section_html( $args ) {
|
||||
?>
|
||||
?>
|
||||
<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( 'The following settings allow you to choose which WooCommerce updates to receive on this site, including beta and RC versions not quite ready for production deployment.', 'woocommerce-beta-tester' ); ?></p>
|
||||
<?php
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,7 +134,9 @@ class WC_Beta_Tester_Settings {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( isset( $_GET['settings-updated'] ) ) { // WPCS: input var.
|
||||
// This is just for giving a message, the option form itself will have validated the nonce.
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if ( isset( $_GET['settings-updated'] ) ) {
|
||||
add_settings_error( 'wc-beta-tester-messages', 'wc-beta-tester-message', __( 'Settings Saved', 'woocommerce-beta-tester' ), 'updated' );
|
||||
}
|
||||
|
||||
|
@ -158,4 +160,4 @@ class WC_Beta_Tester_Settings {
|
|||
}
|
||||
}
|
||||
|
||||
new WC_Beta_Tester_Settings();
|
||||
new WC_Beta_Tester_Channel();
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
* @package WC_Beta_Tester
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( ! class_exists( 'WP_CLI_Command' ) ) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -8,36 +8,38 @@
|
|||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* WC_Beta_Tester_Settings_Export Main Class.
|
||||
* WC_Beta_Tester_Import_Export Main Class.
|
||||
*/
|
||||
class WC_Beta_Tester_Import_Export {
|
||||
/**
|
||||
* @var string WordPress ajax hook
|
||||
* The AJAX hook for the class.
|
||||
*/
|
||||
protected const AJAX_HOOK = 'wc_beta_tester_export_settings';
|
||||
|
||||
/**
|
||||
* @var string WordPress nonce action
|
||||
* The security nonce for the class.
|
||||
*/
|
||||
protected const NONCE_ACTION = 'wc-beta-tester-import-settings';
|
||||
|
||||
/**
|
||||
* @var string WordPress import action
|
||||
* The import AJAX action.
|
||||
*/
|
||||
protected const IMPORT_ACTION = 'wc-beta-tester-import';
|
||||
|
||||
/**
|
||||
* @var string WordPress import capability
|
||||
* The capability required to import settings.
|
||||
*/
|
||||
protected const IMPORT_CAP = 'install_plugins';
|
||||
|
||||
/**
|
||||
* @var string WordPress import file name
|
||||
* The filename of the file containing exported settings.
|
||||
*/
|
||||
protected const IMPORT_FILENAME = 'woocommerce-settings-json';
|
||||
|
||||
/**
|
||||
* @var array Import status message
|
||||
* The status message of the import.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $message;
|
||||
|
||||
|
@ -76,29 +78,35 @@ class WC_Beta_Tester_Import_Export {
|
|||
// show error/update messages.
|
||||
if ( ! empty( $this->message ) ) {
|
||||
?>
|
||||
<div class="notice <?php
|
||||
<div class="notice
|
||||
<?php
|
||||
echo ! empty( $this->message['type'] ) ? esc_attr( $this->message['type'] ) : '';
|
||||
?>"><?php echo esc_html( $this->message['message'] ); ?></div>
|
||||
?>
|
||||
"><?php echo esc_html( $this->message['message'] ); ?></div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
|
||||
<p><?php esc_html_e( 'Export your WooCommerce Settings. The export file should not contain any fields that identify your site or reveal secrets (eg. API keys).', 'woocommerce-beta-tester' ); ?></p>
|
||||
<a href="<?php echo esc_url( $export_url ) ?>" class="button-primary"><?php
|
||||
/* translators Export WooCommerce settings button text. */
|
||||
esc_html_e( 'Export WooCommerce Settings', 'woocommerce-beta-tester' );
|
||||
?></a>
|
||||
<a href="<?php echo esc_url( $export_url ); ?>" class="button-primary">
|
||||
<?php
|
||||
/* translators Export WooCommerce settings button text. */
|
||||
esc_html_e( 'Export WooCommerce Settings', 'woocommerce-beta-tester' );
|
||||
?>
|
||||
</a>
|
||||
<hr />
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<?php wp_nonce_field( static::NONCE_ACTION ); ?>
|
||||
<input type="hidden" name="action" value="<?php echo static::IMPORT_ACTION; ?>" />
|
||||
<input type="hidden" name="action" value="<?php echo esc_attr( static::IMPORT_ACTION ); ?>" />
|
||||
<p><?php esc_html_e( 'Import WooCommerce Settings exported with this tool. Some settings like store address, payment gateways, etc. will need to be configured manually.', 'woocommerce-beta-tester' ); ?></p>
|
||||
<button type="submit" class="button-primary"><?php
|
||||
<button type="submit" class="button-primary">
|
||||
<?php
|
||||
/* translators Import WooCommerce settings button text. */
|
||||
esc_html_e( 'Import WooCommerce Settings', 'woocommerce-beta-tester' );
|
||||
?></button>
|
||||
<input type="file" name="<?php echo static::IMPORT_FILENAME; ?>" />
|
||||
?>
|
||||
</button>
|
||||
<input type="file" name="<?php echo esc_attr( static::IMPORT_FILENAME ); ?>" />
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
|
@ -108,7 +116,8 @@ class WC_Beta_Tester_Import_Export {
|
|||
* Export settings in json format.
|
||||
*/
|
||||
public function export_settings() {
|
||||
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], static::NONCE_ACTION ) ) {
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), static::NONCE_ACTION ) ) {
|
||||
header( 'HTTP/1.1 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
@ -128,11 +137,12 @@ class WC_Beta_Tester_Import_Export {
|
|||
* Import settings in json format if submitted.
|
||||
*/
|
||||
public function maybe_import_settings() {
|
||||
if ( empty( $_POST ) || empty( $_POST['action'] ) || $_POST['action'] !== static::IMPORT_ACTION ) {
|
||||
if ( empty( $_POST ) || empty( $_POST['action'] ) || static::IMPORT_ACTION !== $_POST['action'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! wp_verify_nonce( $_POST['_wpnonce'], static::NONCE_ACTION ) ) {
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['_wpnonce'] ), static::NONCE_ACTION ) ) {
|
||||
$this->add_message( __( 'Invalid submission', 'woocommerce-beta-tester' ) );
|
||||
return;
|
||||
}
|
||||
|
@ -142,7 +152,8 @@ class WC_Beta_Tester_Import_Export {
|
|||
return;
|
||||
}
|
||||
|
||||
$tmp_file = $_FILES[ static::IMPORT_FILENAME ]['tmp_name'];
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
$tmp_file = wp_unslash( $_FILES[ static::IMPORT_FILENAME ]['tmp_name'] );
|
||||
if ( empty( $tmp_file ) ) {
|
||||
$this->add_message( __( 'No file uploaded.', 'woocommerce-beta-tester' ) );
|
||||
return;
|
||||
|
@ -153,9 +164,10 @@ class WC_Beta_Tester_Import_Export {
|
|||
return;
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
|
||||
$maybe_json = file_get_contents( $tmp_file );
|
||||
$settings = json_decode( $maybe_json, true );
|
||||
if ( $settings !== null ) {
|
||||
$settings = json_decode( $maybe_json, true );
|
||||
if ( null !== $settings ) {
|
||||
foreach ( $this->get_setting_list() as $option_name ) {
|
||||
if ( ! isset( $settings[ $option_name ] ) ) {
|
||||
continue;
|
||||
|
@ -184,6 +196,7 @@ class WC_Beta_Tester_Import_Export {
|
|||
if ( false === $setting ) {
|
||||
$setting = null;
|
||||
}
|
||||
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
|
||||
$settings[ $option_name ] = is_string( $setting ) ? $setting : serialize( $setting );
|
||||
}
|
||||
}
|
||||
|
@ -199,7 +212,7 @@ class WC_Beta_Tester_Import_Export {
|
|||
protected function add_message( $message, $type = 'error' ) {
|
||||
$this->message = array(
|
||||
'message' => $message,
|
||||
'type' => $type
|
||||
'type' => $type,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -207,7 +220,7 @@ class WC_Beta_Tester_Import_Export {
|
|||
* Get the WooCommerce settings list keys.
|
||||
*/
|
||||
private function get_setting_list() {
|
||||
require_once( dirname(__FILE__ ) . '/wc-beta-tester-settings-list.php');
|
||||
require_once dirname( __FILE__ ) . '/wc-beta-tester-settings-list.php';
|
||||
return wc_beta_tester_setting_list();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,6 @@ class WC_Beta_Tester_Live_Branches {
|
|||
wc_admin_register_page(
|
||||
array(
|
||||
'id' => 'woocommerce-beta-tester-live-branches',
|
||||
// phpcs:disable
|
||||
'title' => __( 'Live Branches', 'woocommerce-beta-tester' ),
|
||||
'path' => '/live-branches',
|
||||
'parent' => 'woocommerce',
|
||||
|
|
|
@ -33,15 +33,16 @@ class WC_Beta_Tester_Version_Picker {
|
|||
* @throws Exception On update error.
|
||||
*/
|
||||
public function handle_version_switch() {
|
||||
if ( ! isset( $_GET['wcbt_switch_to_version'], $_GET['_wpnonce'] ) ) { // WPCS: Input var ok.
|
||||
if ( ! isset( $_GET['wcbt_switch_to_version'], $_GET['_wpnonce'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'wcbt_switch_version_nonce' ) ) { // WPCS: Input var ok, sanitization ok.
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
if ( ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'wcbt_switch_version_nonce' ) ) {
|
||||
wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'woocommerce-beta-tester' ) );
|
||||
}
|
||||
|
||||
$version = isset( $_GET['wcbt_switch_to_version'] ) ? sanitize_text_field( wp_unslash( $_GET['wcbt_switch_to_version'] ) ) : ''; // WPCS: Input var ok, sanitization ok.
|
||||
$version = isset( $_GET['wcbt_switch_to_version'] ) ? sanitize_text_field( wp_unslash( $_GET['wcbt_switch_to_version'] ) ) : '';
|
||||
|
||||
if ( empty( $version ) ) {
|
||||
return;
|
||||
|
@ -58,7 +59,7 @@ class WC_Beta_Tester_Version_Picker {
|
|||
'title' => 'Version switch result',
|
||||
'plugin' => $plugin_name,
|
||||
'version' => $version,
|
||||
'nonce' => wp_unslash( $_GET['_wpnonce'] ), // WPCS: Input var ok, sanitization ok.
|
||||
'nonce' => wp_unslash( $_GET['_wpnonce'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
);
|
||||
|
||||
$skin = new Automatic_Upgrader_Skin( $skin_args );
|
||||
|
@ -128,9 +129,11 @@ class WC_Beta_Tester_Version_Picker {
|
|||
$tags = array_reverse( $tags );
|
||||
$versions_html = '';
|
||||
|
||||
if ( ! empty( $_GET['switched'] ) ) { // WPCS: input var ok, CSRF ok.
|
||||
// The nonce is validated upstream.
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if ( ! empty( $_GET['switched'] ) ) {
|
||||
/* translators: %s: WooCoomerce version */
|
||||
$versions_html .= '<div class="notice notice-success"><p>' . sprintf( esc_html__( 'Successfully switched version to %s.', 'woocommerce-beta-tester' ), esc_html( sanitize_text_field( wp_unslash( $_GET['switched'] ) ) ) ) . '</p></div>'; // WPCS: input var ok, CSRF ok.
|
||||
$versions_html .= '<div class="notice notice-success"><p>' . sprintf( esc_html__( 'Successfully switched version to %s.', 'woocommerce-beta-tester' ), esc_html( sanitize_text_field( wp_unslash( $_GET['switched'] ) ) ) ) . '</p></div>'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
}
|
||||
|
||||
$versions_html .= '<ul class="wcbt-version-list">';
|
||||
|
@ -141,10 +144,10 @@ class WC_Beta_Tester_Version_Picker {
|
|||
foreach ( $tags as $tag_version ) {
|
||||
|
||||
$versions_html .= '<li class="wcbt-version-li">';
|
||||
$versions_html .= '<label><input type="radio" ' . checked( strtolower($tag_version), strtolower($this->current_version), false ) . ' value="' . esc_attr( $tag_version ) . '" name="wcbt_switch_to_version">' . $tag_version;
|
||||
$versions_html .= '<label><input type="radio" ' . checked( strtolower( $tag_version ), strtolower( $this->current_version ), false ) . ' value="' . esc_attr( $tag_version ) . '" name="wcbt_switch_to_version">' . $tag_version;
|
||||
|
||||
// Is this the current version?
|
||||
if ( strcasecmp($tag_version, $this->current_version) === 0 ) {
|
||||
if ( strcasecmp( $tag_version, $this->current_version ) === 0 ) {
|
||||
$versions_html .= '<span class="wcbt-current-version"><strong>' . esc_html__( ' Installed Version', 'woocommerce-beta-tester' ) . '</strong></span>';
|
||||
}
|
||||
|
||||
|
@ -174,7 +177,7 @@ class WC_Beta_Tester_Version_Picker {
|
|||
<h1><?php esc_html_e( 'Available WooCommerce Releases', 'woocommerce-beta-tester' ); ?></h1>
|
||||
<form name="wcbt-select-version" class="wcbt-select-version-form" action="<?php echo esc_attr( admin_url( '/tools.php' ) ); ?>">
|
||||
<div class="wcbt-versions-wrap">
|
||||
<?php echo $this->get_versions_html( $channel ); // WPCS: XSS ok. ?>
|
||||
<?php echo $this->get_versions_html( $channel ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
<div class="wcbt-submit-wrap">
|
||||
<a href="#wcbt-modal-version-switch-confirm" class="button-primary" id="wcbt-modal-version-switch-confirm"><?php esc_html_e( 'Switch version', 'woocommerce-beta-tester' ); ?></a>
|
||||
|
|
|
@ -24,15 +24,15 @@ class WC_Beta_Tester {
|
|||
*
|
||||
* @var WC_Beta_Tester
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*/
|
||||
public static function instance() {
|
||||
self::$_instance = is_null( self::$_instance ) ? new self() : self::$_instance;
|
||||
self::$instance = is_null( self::$instance ) ? new self() : self::$instance;
|
||||
|
||||
return self::$_instance;
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@ defined( 'ABSPATH' ) || exit;
|
|||
<?php
|
||||
$installed_plugins = get_plugins();
|
||||
if ( isset( $installed_plugins['woocommerce/woocommerce.php'] ) ) :
|
||||
?>
|
||||
?>
|
||||
<a href="<?php echo esc_url( wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=woocommerce/woocommerce.php&plugin_status=active' ), 'activate-plugin_woocommerce/woocommerce.php' ) ); ?>" class="button button-primary"><?php esc_html_e( 'Activate WooCommerce', 'woocommerce-beta-tester' ); ?></a>
|
||||
<?php endif; ?>
|
||||
<?php if ( current_user_can( 'deactivate_plugin', 'woocommerce-beta-tester/woocommerce-beta-tester.php' ) ) : ?>
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* List of settings to be exported.
|
||||
* WooCommerce Beta Tester settings list functions.
|
||||
*
|
||||
* @package WC_Beta_Tester
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Gets the list of settings that can be edited.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
function wc_beta_tester_setting_list() {
|
||||
$settings_list = array(
|
||||
'date_format',
|
||||
|
@ -122,7 +131,7 @@ function wc_beta_tester_setting_list() {
|
|||
'woocommerce_trash_pending_orders',
|
||||
'woocommerce_unforce_ssl_checkout',
|
||||
'woocommerce_version',
|
||||
'woocommerce_weight_unit'
|
||||
'woocommerce_weight_unit',
|
||||
);
|
||||
return apply_filters( 'wc_beta_tester_setting_list', $settings_list );
|
||||
}
|
||||
|
|
|
@ -64,6 +64,8 @@
|
|||
"format:js": "wp-scripts format-js",
|
||||
"lint:css": "wp-scripts lint-style",
|
||||
"lint:css:fix": "wp-scripts lint-style --fix",
|
||||
"lint:php": "composer run-script phpcs",
|
||||
"lint:php:fix": "composer run-script phpcbf",
|
||||
"lint:js": "wp-scripts lint-js",
|
||||
"lint:js:fix": "wp-scripts lint-js --fix",
|
||||
"lint:md:docs": "wp-scripts lint-md-docs",
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset name="WooCommerce Beta Tester Coding Standards">
|
||||
<description>WooCommerce Beta Tester PHP_CodeSniffer ruleset.</description>
|
||||
|
||||
<file>./woocommerce-beta-tester.php</file>
|
||||
<file>./includes/</file>
|
||||
<file>./api/</file>
|
||||
|
||||
<!-- Show progress, show the error codes for each message (source). -->
|
||||
<arg value="ps" />
|
||||
|
||||
<!-- Strip the filepaths in reports down to the relevant bit. -->
|
||||
<arg name="basepath" value="./" />
|
||||
|
||||
<!-- Check up to 8 files simultaneously. -->
|
||||
<arg name="parallel" value="8" />
|
||||
|
||||
<!-- Configs -->
|
||||
<config name="minimum_supported_wp_version" value="5.2" />
|
||||
<config name="testVersion" value="7.3-" />
|
||||
|
||||
<!-- Rules -->
|
||||
<rule ref="WooCommerce-Core" />
|
||||
|
||||
<rule ref="WordPress.WP.I18n">
|
||||
<properties>
|
||||
<property name="text_domain" type="array" value="woocommerce-beta-tester" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="WooCommerce.Commenting.CommentHooks.MissingHookComment">
|
||||
<exclude-pattern>includes/</exclude-pattern>
|
||||
<exclude-pattern>api/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Squiz.Commenting.FileComment.Missing">
|
||||
<exclude-pattern>includes/</exclude-pattern>
|
||||
<exclude-pattern>api/</exclude-pattern>
|
||||
</rule>
|
||||
</ruleset>
|
|
@ -0,0 +1,5 @@
|
|||
Significance: patch
|
||||
Type: dev
|
||||
Comment: Added PHPCS and fixed linting errors.
|
||||
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset name="WordPress Coding Standards">
|
||||
<description>WooCommerce dev PHP_CodeSniffer ruleset.</description>
|
||||
|
||||
<file>.</file>
|
||||
|
||||
<!-- Exclude paths -->
|
||||
<exclude-pattern>tests/cli/</exclude-pattern>
|
||||
<exclude-pattern>includes/libraries/</exclude-pattern>
|
||||
<exclude-pattern>includes/legacy/</exclude-pattern>
|
||||
<exclude-pattern>includes/api/legacy/</exclude-pattern>
|
||||
<exclude-pattern>includes/api/v1/</exclude-pattern>
|
||||
<exclude-pattern>includes/class-wc-geo-ip.php</exclude-pattern>
|
||||
<exclude-pattern>includes/wc-deprecated-functions.php</exclude-pattern>
|
||||
<exclude-pattern>*/node_modules/*</exclude-pattern>
|
||||
<exclude-pattern>*/vendor/*</exclude-pattern>
|
||||
<exclude-pattern>lib/</exclude-pattern>
|
||||
|
||||
<!-- Show progress, show the error codes for each message (source). -->
|
||||
<arg value="ps" />
|
||||
|
||||
<!-- Strip the filepaths in reports down to the relevant bit. -->
|
||||
<arg name="basepath" value="./" />
|
||||
|
||||
<!-- Check up to 8 files simultaneously. -->
|
||||
<arg name="parallel" value="8" />
|
||||
|
||||
<!-- Configs -->
|
||||
<config name="minimum_supported_wp_version" value="5.2" />
|
||||
<config name="testVersion" value="7.3-" />
|
||||
|
||||
<!-- Rules -->
|
||||
<rule ref="WooCommerce-Core" />
|
||||
|
||||
<rule ref="WooCommerce.Functions.InternalInjectionMethod">
|
||||
<include-pattern>src/</include-pattern>
|
||||
<include-pattern>tests/php/src/</include-pattern>
|
||||
<properties>
|
||||
<property name="injectionMethod" value="init"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="WordPress.WP.I18n">
|
||||
<properties>
|
||||
<property name="text_domain" type="array" value="woocommerce" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="PHPCompatibility">
|
||||
<exclude-pattern>tests/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents">
|
||||
<exclude-pattern>tests/src</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
|
||||
<exclude-pattern>includes/**/abstract-*.php</exclude-pattern>
|
||||
<exclude-pattern>tests/</exclude-pattern>
|
||||
<exclude-pattern>src/</exclude-pattern>
|
||||
<exclude-pattern>tests/php/src/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Squiz.Classes.ClassFileName">
|
||||
<include-pattern>src/</include-pattern>
|
||||
<include-pattern>tests/php/src/</include-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Squiz.Classes.ValidClassName">
|
||||
<include-pattern>src/</include-pattern>
|
||||
<include-pattern>tests/php/src/</include-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Generic.Commenting">
|
||||
<exclude-pattern>tests/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="PEAR.Functions.FunctionCallSignature.EmptyLine">
|
||||
<exclude-pattern>tests/e2e-tests/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
|
||||
<exclude-pattern>i18n/</exclude-pattern>
|
||||
<exclude-pattern>src/</exclude-pattern>
|
||||
<exclude-pattern>tests/php</exclude-pattern>
|
||||
<exclude-pattern>tests/Tools/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Squiz.Commenting.FileComment.MissingPackageTag">
|
||||
<exclude-pattern>src/</exclude-pattern>
|
||||
<exclude-pattern>tests/php/</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="Squiz.Commenting.FileComment.Missing">
|
||||
<exclude-pattern>src/</exclude-pattern>
|
||||
<exclude-pattern>tests/php/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Squiz.Commenting.FunctionCommentThrowTag.Missing">
|
||||
<exclude-pattern>tests/php/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<rule ref="Squiz.Commenting.FileComment.Missing">
|
||||
<exclude-pattern>tests/php/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- Temporary -->
|
||||
<rule ref="Generic.Arrays.DisallowShortArraySyntax.Found">
|
||||
<exclude-pattern>src/Internal/Admin/</exclude-pattern>
|
||||
<exclude-pattern>src/Admin/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- Temporary -->
|
||||
<rule ref="WooCommerce.Functions.InternalInjectionMethod.MissingFinal">
|
||||
<exclude-pattern>src/Internal/Admin/</exclude-pattern>
|
||||
<exclude-pattern>src/Admin/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- Temporary -->
|
||||
<rule ref="WooCommerce.Functions.InternalInjectionMethod.MissingInternalTag">
|
||||
<exclude-pattern>src/Internal/Admin/</exclude-pattern>
|
||||
<exclude-pattern>src/Admin/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- Temporary -->
|
||||
<rule ref="WordPress.Security.NonceVerification.Recommended">
|
||||
<exclude-pattern>src/Internal/Admin/</exclude-pattern>
|
||||
<exclude-pattern>src/Admin/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- Temporary -->
|
||||
<rule ref="Squiz.Classes.ClassFileName.NoMatch">
|
||||
<exclude-pattern>src/Internal/Admin/</exclude-pattern>
|
||||
<exclude-pattern>src/Admin/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- Temporary -->
|
||||
<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
|
||||
<exclude-pattern>src/Internal/Admin/</exclude-pattern>
|
||||
<exclude-pattern>src/Admin/</exclude-pattern>
|
||||
</rule>
|
||||
</ruleset>
|
|
@ -48,7 +48,7 @@ class Package {
|
|||
*/
|
||||
public static function init() {
|
||||
// Avoid double initialization when the feature plugin is in use.
|
||||
if ( defined( 'WC_ADMIN_VERSION_NUMBER' ) ) {
|
||||
if (defined( 'WC_ADMIN_VERSION_NUMBER' ) ) {
|
||||
self::$active_version = WC_ADMIN_VERSION_NUMBER;
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue