Merge branch 'master' into update/walkers-phpcs

This commit is contained in:
Claudio Sanches 2018-03-12 12:31:57 -03:00
commit 82fec65fa0
38 changed files with 1193 additions and 898 deletions

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* Class WC_Product_CSV_Importer_Controller file.
*
* @package WooCommerce\Admin\Importers
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
@ -10,8 +16,6 @@ if ( ! class_exists( 'WP_Importer' ) ) {
/** /**
* Product importer controller - handles file upload and forms in admin. * Product importer controller - handles file upload and forms in admin.
* *
* @author Automattic
* @category Admin
* @package WooCommerce/Admin/Importers * @package WooCommerce/Admin/Importers
* @version 3.1.0 * @version 3.1.0
*/ */
@ -108,11 +112,13 @@ class WC_Product_CSV_Importer_Controller {
$this->steps = apply_filters( 'woocommerce_product_csv_importer_steps', $default_steps ); $this->steps = apply_filters( 'woocommerce_product_csv_importer_steps', $default_steps );
// phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification
$this->step = isset( $_REQUEST['step'] ) ? sanitize_key( $_REQUEST['step'] ) : current( array_keys( $this->steps ) ); $this->step = isset( $_REQUEST['step'] ) ? sanitize_key( $_REQUEST['step'] ) : current( array_keys( $this->steps ) );
$this->file = isset( $_REQUEST['file'] ) ? wc_clean( $_REQUEST['file'] ) : ''; $this->file = isset( $_REQUEST['file'] ) ? wc_clean( wp_unslash( $_REQUEST['file'] ) ) : '';
$this->update_existing = isset( $_REQUEST['update_existing'] ) ? (bool) $_REQUEST['update_existing'] : false; $this->update_existing = isset( $_REQUEST['update_existing'] ) ? (bool) $_REQUEST['update_existing'] : false;
$this->delimiter = ! empty( $_REQUEST['delimiter'] ) ? wc_clean( $_REQUEST['delimiter'] ) : ','; $this->delimiter = ! empty( $_REQUEST['delimiter'] ) ? wc_clean( wp_unslash( $_REQUEST['delimiter'] ) ) : ',';
$this->map_preferences = isset( $_REQUEST['map_preferences'] ) ? (bool) $_REQUEST['map_preferences'] : false; $this->map_preferences = isset( $_REQUEST['map_preferences'] ) ? (bool) $_REQUEST['map_preferences'] : false;
// phpcs:enable
if ( $this->map_preferences ) { if ( $this->map_preferences ) {
add_filter( 'woocommerce_csv_product_import_mapped_columns', array( $this, 'auto_map_user_preferences' ), 9999 ); add_filter( 'woocommerce_csv_product_import_mapped_columns', array( $this, 'auto_map_user_preferences' ), 9999 );
@ -122,7 +128,7 @@ class WC_Product_CSV_Importer_Controller {
/** /**
* Get the URL for the next step's screen. * Get the URL for the next step's screen.
* *
* @param string step slug (default: current step) * @param string $step slug (default: current step).
* @return string URL for next step if a next step exists. * @return string URL for next step if a next step exists.
* Admin URL if it's the last step. * Admin URL if it's the last step.
* Empty string on failure. * Empty string on failure.
@ -138,7 +144,7 @@ class WC_Product_CSV_Importer_Controller {
return admin_url(); return admin_url();
} }
$step_index = array_search( $step, $keys ); $step_index = array_search( $step, $keys, true );
if ( false === $step_index ) { if ( false === $step_index ) {
return ''; return '';
@ -217,6 +223,7 @@ class WC_Product_CSV_Importer_Controller {
* Dispatch current step and show correct view. * Dispatch current step and show correct view.
*/ */
public function dispatch() { public function dispatch() {
// phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification
if ( ! empty( $_POST['save_step'] ) && ! empty( $this->steps[ $this->step ]['handler'] ) ) { if ( ! empty( $_POST['save_step'] ) && ! empty( $this->steps[ $this->step ]['handler'] ) ) {
call_user_func( $this->steps[ $this->step ]['handler'], $this ); call_user_func( $this->steps[ $this->step ]['handler'], $this );
} }
@ -271,13 +278,16 @@ class WC_Product_CSV_Importer_Controller {
) )
); );
if ( empty( $_POST['file_url'] ) ) { // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- Nonce already verified in WC_Product_CSV_Importer_Controller::upload_form_handler()
$file_url = isset( $_POST['file_url'] ) ? esc_url_raw( wp_unslash( $_POST['file_url'] ) ) : '';
if ( empty( $file_url ) ) {
if ( ! isset( $_FILES['import'] ) ) { if ( ! isset( $_FILES['import'] ) ) {
return new WP_Error( 'woocommerce_product_csv_importer_upload_file_empty', __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.', 'woocommerce' ) ); return new WP_Error( 'woocommerce_product_csv_importer_upload_file_empty', __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.', 'woocommerce' ) );
} }
$filetype = wp_check_filetype( $_FILES['import']['name'], $valid_filetypes ); $filetype = wp_check_filetype( wc_clean( wp_unslash( $_FILES['import']['name'] ) ), $valid_filetypes );
if ( ! in_array( $filetype['type'], $valid_filetypes ) ) { if ( ! in_array( $filetype['type'], $valid_filetypes, true ) ) {
return new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) ); return new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );
} }
@ -285,7 +295,7 @@ class WC_Product_CSV_Importer_Controller {
'test_form' => false, 'test_form' => false,
'mimes' => $valid_filetypes, 'mimes' => $valid_filetypes,
); );
$upload = wp_handle_upload( $_FILES['import'], $overrides ); $upload = wp_handle_upload( wp_unslash( $_FILES['import'] ), $overrides );
if ( isset( $upload['error'] ) ) { if ( isset( $upload['error'] ) ) {
return new WP_Error( 'woocommerce_product_csv_importer_upload_error', $upload['error'] ); return new WP_Error( 'woocommerce_product_csv_importer_upload_error', $upload['error'] );
@ -311,14 +321,15 @@ class WC_Product_CSV_Importer_Controller {
wp_schedule_single_event( time() + DAY_IN_SECONDS, 'importer_scheduled_cleanup', array( $id ) ); wp_schedule_single_event( time() + DAY_IN_SECONDS, 'importer_scheduled_cleanup', array( $id ) );
return $upload['file']; return $upload['file'];
} elseif ( file_exists( ABSPATH . $_POST['file_url'] ) ) { } elseif ( file_exists( ABSPATH . $file_url ) ) {
$filetype = wp_check_filetype( ABSPATH . $_POST['file_url'], $valid_filetypes ); $filetype = wp_check_filetype( ABSPATH . $file_url, $valid_filetypes );
if ( ! in_array( $filetype['type'], $valid_filetypes ) ) { if ( ! in_array( $filetype['type'], $valid_filetypes, true ) ) {
return new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) ); return new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );
} }
return ABSPATH . $_POST['file_url']; return ABSPATH . $file_url;
} }
// phpcs:enable
return new WP_Error( 'woocommerce_product_csv_importer_upload_invalid_file', __( 'Please upload or provide the link to a valid CSV file.', 'woocommerce' ) ); return new WP_Error( 'woocommerce_product_csv_importer_upload_invalid_file', __( 'Please upload or provide the link to a valid CSV file.', 'woocommerce' ) );
} }
@ -365,7 +376,8 @@ class WC_Product_CSV_Importer_Controller {
return; return;
} }
if ( ! empty( $_POST['map_to'] ) ) { // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- Nonce already verified in WC_Admin_Importers::do_ajax_product_import()
if ( ! empty( $_POST['map_from'] ) && ! empty( $_POST['map_to'] ) ) {
$mapping_from = wc_clean( wp_unslash( $_POST['map_from'] ) ); $mapping_from = wc_clean( wp_unslash( $_POST['map_from'] ) );
$mapping_to = wc_clean( wp_unslash( $_POST['map_to'] ) ); $mapping_to = wc_clean( wp_unslash( $_POST['map_to'] ) );
@ -375,6 +387,7 @@ class WC_Product_CSV_Importer_Controller {
wp_redirect( esc_url_raw( $this->get_next_step_link( 'upload' ) ) ); wp_redirect( esc_url_raw( $this->get_next_step_link( 'upload' ) ) );
exit; exit;
} }
// phpcs:enable
wp_localize_script( wp_localize_script(
'wc-product-import', 'wc_product_import_params', array( 'wc-product-import', 'wc_product_import_params', array(
@ -397,11 +410,13 @@ class WC_Product_CSV_Importer_Controller {
* Done step. * Done step.
*/ */
protected function done() { protected function done() {
// phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification
$imported = isset( $_GET['products-imported'] ) ? absint( $_GET['products-imported'] ) : 0; $imported = isset( $_GET['products-imported'] ) ? absint( $_GET['products-imported'] ) : 0;
$updated = isset( $_GET['products-updated'] ) ? absint( $_GET['products-updated'] ) : 0; $updated = isset( $_GET['products-updated'] ) ? absint( $_GET['products-updated'] ) : 0;
$failed = isset( $_GET['products-failed'] ) ? absint( $_GET['products-failed'] ) : 0; $failed = isset( $_GET['products-failed'] ) ? absint( $_GET['products-failed'] ) : 0;
$skipped = isset( $_GET['products-skipped'] ) ? absint( $_GET['products-skipped'] ) : 0; $skipped = isset( $_GET['products-skipped'] ) ? absint( $_GET['products-skipped'] ) : 0;
$errors = array_filter( (array) get_user_option( 'product_import_error_log' ) ); $errors = array_filter( (array) get_user_option( 'product_import_error_log' ) );
// phpcs:enable
include_once dirname( __FILE__ ) . '/views/html-csv-import-done.php'; include_once dirname( __FILE__ ) . '/views/html-csv-import-done.php';
} }
@ -435,7 +450,7 @@ class WC_Product_CSV_Importer_Controller {
include dirname( __FILE__ ) . '/mappings/mappings.php'; include dirname( __FILE__ ) . '/mappings/mappings.php';
/** /*
* @hooked wc_importer_generic_mappings - 10 * @hooked wc_importer_generic_mappings - 10
* @hooked wc_importer_wordpress_mappings - 10 * @hooked wc_importer_wordpress_mappings - 10
* @hooked wc_importer_default_english_mappings - 100 * @hooked wc_importer_default_english_mappings - 100
@ -460,9 +475,13 @@ class WC_Product_CSV_Importer_Controller {
__( 'Stock', 'woocommerce' ) => 'stock_quantity', __( 'Stock', 'woocommerce' ) => 'stock_quantity',
__( 'Backorders allowed?', 'woocommerce' ) => 'backorders', __( 'Backorders allowed?', 'woocommerce' ) => 'backorders',
__( 'Sold individually?', 'woocommerce' ) => 'sold_individually', __( 'Sold individually?', 'woocommerce' ) => 'sold_individually',
/* translators: %s: Weight unit */
sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit ) => 'weight', sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit ) => 'weight',
/* translators: %s: Length unit */
sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit ) => 'length', sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit ) => 'length',
/* translators: %s: Width unit */
sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit ) => 'width', sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit ) => 'width',
/* translators: %s: Height unit */
sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit ) => 'height', sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit ) => 'height',
__( 'Allow customer reviews?', 'woocommerce' ) => 'reviews_allowed', __( 'Allow customer reviews?', 'woocommerce' ) => 'reviews_allowed',
__( 'Purchase note', 'woocommerce' ) => 'purchase_note', __( 'Purchase note', 'woocommerce' ) => 'purchase_note',
@ -490,13 +509,21 @@ class WC_Product_CSV_Importer_Controller {
apply_filters( apply_filters(
'woocommerce_csv_product_import_mapping_special_columns', 'woocommerce_csv_product_import_mapping_special_columns',
array( array(
/* translators: %d: Attribute number */
__( 'Attribute %d name', 'woocommerce' ) => 'attributes:name', __( 'Attribute %d name', 'woocommerce' ) => 'attributes:name',
/* translators: %d: Attribute number */
__( 'Attribute %d value(s)', 'woocommerce' ) => 'attributes:value', __( 'Attribute %d value(s)', 'woocommerce' ) => 'attributes:value',
/* translators: %d: Attribute number */
__( 'Attribute %d visible', 'woocommerce' ) => 'attributes:visible', __( 'Attribute %d visible', 'woocommerce' ) => 'attributes:visible',
/* translators: %d: Attribute number */
__( 'Attribute %d global', 'woocommerce' ) => 'attributes:taxonomy', __( 'Attribute %d global', 'woocommerce' ) => 'attributes:taxonomy',
/* translators: %d: Attribute number */
__( 'Attribute %d default', 'woocommerce' ) => 'attributes:default', __( 'Attribute %d default', 'woocommerce' ) => 'attributes:default',
/* translators: %d: Download number */
__( 'Download %d name', 'woocommerce' ) => 'downloads:name', __( 'Download %d name', 'woocommerce' ) => 'downloads:name',
/* translators: %d: Download number */
__( 'Download %d URL', 'woocommerce' ) => 'downloads:url', __( 'Download %d URL', 'woocommerce' ) => 'downloads:url',
/* translators: %d: Meta number */
__( 'Meta: %s', 'woocommerce' ) => 'meta:', __( 'Meta: %s', 'woocommerce' ) => 'meta:',
) )
) )
@ -571,7 +598,7 @@ class WC_Product_CSV_Importer_Controller {
/** /**
* Get mapping options. * Get mapping options.
* *
* @param string $item Item name * @param string $item Item name.
* @return array * @return array
*/ */
protected function get_mapping_options( $item = '' ) { protected function get_mapping_options( $item = '' ) {

View File

@ -3,9 +3,7 @@
* Tax importer class file * Tax importer class file
* *
* @version 2.3.0 * @version 2.3.0
* @category Admin
* @package WooCommerce/Admin * @package WooCommerce/Admin
* @author WooCommerce
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
@ -19,8 +17,6 @@ if ( ! class_exists( 'WP_Importer' ) ) {
/** /**
* Tax Rates importer - import tax rates and local tax rates into WooCommerce. * Tax Rates importer - import tax rates and local tax rates into WooCommerce.
* *
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/Importers * @package WooCommerce/Admin/Importers
* @version 2.3.0 * @version 2.3.0
*/ */
@ -59,8 +55,7 @@ class WC_Tax_Rate_Importer extends WP_Importer {
*/ */
public function __construct() { public function __construct() {
$this->import_page = 'woocommerce_tax_rate_csv'; $this->import_page = 'woocommerce_tax_rate_csv';
// @codingStandardsIgnoreLine $this->delimiter = empty( $_POST['delimiter'] ) ? ',' : (string) wc_clean( wp_unslash( $_POST['delimiter'] ) ); // WPCS: CSRF ok.
$this->delimiter = empty( $_POST['delimiter'] ) ? ',' : (string) wc_clean( $_POST['delimiter'] );
} }
/** /**
@ -106,7 +101,7 @@ class WC_Tax_Rate_Importer extends WP_Importer {
*/ */
private function import_start() { private function import_start() {
if ( function_exists( 'gc_enable' ) ) { if ( function_exists( 'gc_enable' ) ) {
gc_enable(); gc_enable(); // phpcs:ignore PHPCompatibility.PHP.NewFunctions.gc_enableFound
} }
wc_set_time_limit( 0 ); wc_set_time_limit( 0 );
@ob_flush(); @ob_flush();
@ -138,14 +133,17 @@ class WC_Tax_Rate_Importer extends WP_Importer {
$this->import_start(); $this->import_start();
$loop = 0; $loop = 0;
$handle = fopen( $file, 'r' );
if ( ( $handle = fopen( $file, 'r' ) ) !== false ) { if ( false !== $handle ) {
$header = fgetcsv( $handle, 0, $this->delimiter ); $header = fgetcsv( $handle, 0, $this->delimiter );
if ( 10 === count( $header ) ) { if ( 10 === count( $header ) ) {
while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== false ) { $row = fgetcsv( $handle, 0, $this->delimiter );
while ( false !== $row ) {
list( $country, $state, $postcode, $city, $rate, $name, $priority, $compound, $shipping, $class ) = $row; list( $country, $state, $postcode, $city, $rate, $name, $priority, $compound, $shipping, $class ) = $row;
@ -174,8 +172,8 @@ class WC_Tax_Rate_Importer extends WP_Importer {
// Show Result. // Show Result.
echo '<div class="updated settings-error"><p>'; echo '<div class="updated settings-error"><p>';
/* translators: %s: tax rates count */
printf( printf(
/* translators: %s: tax rates count */
esc_html__( 'Import complete - imported %s tax rates.', 'woocommerce' ), esc_html__( 'Import complete - imported %s tax rates.', 'woocommerce' ),
'<strong>' . absint( $loop ) . '</strong>' '<strong>' . absint( $loop ) . '</strong>'
); );
@ -200,9 +198,10 @@ class WC_Tax_Rate_Importer extends WP_Importer {
* @return bool False if error uploading or invalid file, true otherwise * @return bool False if error uploading or invalid file, true otherwise
*/ */
public function handle_upload() { public function handle_upload() {
// @codingStandardsIgnoreLine // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- Nonce already verified in WC_Tax_Rate_Importer::dispatch()
if ( empty( $_POST['file_url'] ) ) { $file_url = isset( $_POST['file_url'] ) ? esc_url_raw( wp_unslash( $_POST['file_url'] ) ) : '';
if ( empty( $file_url ) ) {
$file = wp_import_handle_upload(); $file = wp_import_handle_upload();
if ( isset( $file['error'] ) ) { if ( isset( $file['error'] ) ) {
@ -210,13 +209,12 @@ class WC_Tax_Rate_Importer extends WP_Importer {
} }
$this->id = absint( $file['id'] ); $this->id = absint( $file['id'] );
// @codingStandardsIgnoreLine } elseif ( file_exists( ABSPATH . $file_url ) ) {
} elseif ( file_exists( ABSPATH . $_POST['file_url'] ) ) { $this->file_url = esc_attr( $file_url );
// @codingStandardsIgnoreLine
$this->file_url = esc_attr( $_POST['file_url'] );
} else { } else {
$this->import_error(); $this->import_error();
} }
// phpcs:enable
return true; return true;
} }
@ -244,6 +242,7 @@ class WC_Tax_Rate_Importer extends WP_Importer {
echo '<div class="narrow">'; echo '<div class="narrow">';
echo '<p>' . esc_html__( 'Hi there! Upload a CSV file containing tax rates to import the contents into your shop. Choose a .csv file to upload, then click "Upload file and import".', 'woocommerce' ) . '</p>'; echo '<p>' . esc_html__( 'Hi there! Upload a CSV file containing tax rates to import the contents into your shop. Choose a .csv file to upload, then click "Upload file and import".', 'woocommerce' ) . '</p>';
/* translators: 1: Link to tax rates sample file */
echo '<p>' . sprintf( esc_html__( 'Tax rates need to be defined with columns in a specific order (10 columns). <a href="%s">Click here to download a sample</a>.', 'woocommerce' ), esc_url( WC()->plugin_url() ) . '/sample-data/sample_tax_rates.csv' ) . '</p>'; echo '<p>' . sprintf( esc_html__( 'Tax rates need to be defined with columns in a specific order (10 columns). <a href="%s">Click here to download a sample</a>.', 'woocommerce' ), esc_url( WC()->plugin_url() ) . '/sample-data/sample_tax_rates.csv' ) . '</p>';
$action = 'admin.php?import=woocommerce_tax_rate_csv&step=1'; $action = 'admin.php?import=woocommerce_tax_rate_csv&step=1';
@ -271,8 +270,8 @@ class WC_Tax_Rate_Importer extends WP_Importer {
<input type="hidden" name="max_file_size" value="<?php echo absint( $bytes ); ?>" /> <input type="hidden" name="max_file_size" value="<?php echo absint( $bytes ); ?>" />
<small> <small>
<?php <?php
/* translators: %s: maximum upload size */
printf( printf(
/* translators: %s: maximum upload size */
esc_html__( 'Maximum size: %s', 'woocommerce' ), esc_html__( 'Maximum size: %s', 'woocommerce' ),
esc_attr( $size ) esc_attr( $size )
); );
@ -307,7 +306,7 @@ class WC_Tax_Rate_Importer extends WP_Importer {
/** /**
* Show import error and quit. * Show import error and quit.
* *
* @param string $message Error messag. * @param string $message Error message.
*/ */
private function import_error( $message = '' ) { private function import_error( $message = '' ) {
echo '<p><strong>' . esc_html__( 'Sorry, there has been an error.', 'woocommerce' ) . '</strong><br />'; echo '<p><strong>' . esc_html__( 'Sorry, there has been an error.', 'woocommerce' ) . '</strong><br />';

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* Default mappings
*
* @package WooCommerce\Admin\Importers
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
@ -23,7 +28,7 @@ function wc_importer_current_locale() {
* Add English mapping placeholders when not using English as current language. * Add English mapping placeholders when not using English as current language.
* *
* @since 3.1.0 * @since 3.1.0
* @param array $mappings * @param array $mappings Importer columns mappings.
* @return array * @return array
*/ */
function wc_importer_default_english_mappings( $mappings ) { function wc_importer_default_english_mappings( $mappings ) {
@ -82,7 +87,7 @@ add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'wc_import
* Add English special mapping placeholders when not using English as current language. * Add English special mapping placeholders when not using English as current language.
* *
* @since 3.1.0 * @since 3.1.0
* @param array $mappings * @param array $mappings Importer columns mappings.
* @return array * @return array
*/ */
function wc_importer_default_special_english_mappings( $mappings ) { function wc_importer_default_special_english_mappings( $mappings ) {

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* Generic mappings
*
* @package WooCommerce\Admin\Importers
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
@ -8,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* Add generic mappings. * Add generic mappings.
* *
* @since 3.1.0 * @since 3.1.0
* @param array $mappings * @param array $mappings Importer columns mappings.
* @return array * @return array
*/ */
function wc_importer_generic_mappings( $mappings ) { function wc_importer_generic_mappings( $mappings ) {

View File

@ -1,6 +1,8 @@
<?php <?php
/** /**
* Load up extra automatic mappings for the CSV importer. * Load up extra automatic mappings for the CSV importer.
*
* @package WooCommerce\Admin\Importers
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* WordPress mappings
*
* @package WooCommerce\Admin\Importers
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
@ -8,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* Add mappings for WordPress tables. * Add mappings for WordPress tables.
* *
* @since 3.1.0 * @since 3.1.0
* @param array $mappings * @param array $mappings Importer columns mappings.
* @return array * @return array
*/ */
function wc_importer_wordpress_mappings( $mappings ) { function wc_importer_wordpress_mappings( $mappings ) {

View File

@ -1,7 +1,10 @@
<?php <?php
/** /**
* Admin View: Importer - Done! * Admin View: Importer - Done!
*
* @package WooCommerce\Admin\Importers
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }

View File

@ -1,7 +1,10 @@
<?php <?php
/** /**
* Admin View: Header * Admin View: Header
*
* @package WooCommerce\Admin\Importers
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }

View File

@ -1,7 +1,10 @@
<?php <?php
/** /**
* Admin View: Header * Admin View: Header
*
* @package WooCommerce\Admin\Importers
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }

View File

@ -2,7 +2,7 @@
/** /**
* Admin View: Importer - CSV mapping * Admin View: Importer - CSV mapping
* *
* @package WooCommerce/Admin * @package WooCommerce\Admin\Importers
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {

View File

@ -1,7 +1,10 @@
<?php <?php
/** /**
* Admin View: Importer - CSV import progress * Admin View: Importer - CSV import progress
*
* @package WooCommerce\Admin\Importers
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }

View File

@ -1,7 +1,10 @@
<?php <?php
/** /**
* Admin View: Steps * Admin View: Steps
*
* @package WooCommerce\Admin\Importers
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
@ -11,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<?php <?php
if ( $step_key === $this->step ) { if ( $step_key === $this->step ) {
$step_class = 'active'; $step_class = 'active';
} elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) { } elseif ( array_search( $this->step, array_keys( $this->steps ), true ) > array_search( $step_key, array_keys( $this->steps ), true ) ) {
$step_class = 'done'; $step_class = 'done';
} }
?> ?>

View File

@ -40,10 +40,10 @@ if ( ! defined( 'ABSPATH' ) ) {
<br> <br>
<small> <small>
<?php <?php
/* translators: %s: maximum upload size */
printf( printf(
/* translators: %s: maximum upload size */
esc_html__( 'Maximum size: %s', 'woocommerce' ), esc_html__( 'Maximum size: %s', 'woocommerce' ),
$size esc_html( $size )
); );
?> ?>
</small> </small>

View File

@ -249,7 +249,7 @@ class WC_Meta_Box_Coupon_Data {
<?php echo wc_help_tip( __( 'Product categories that the coupon will not be applied to, or that cannot be in the cart in order for the "Fixed cart discount" to be applied.', 'woocommerce' ) ); ?> <?php echo wc_help_tip( __( 'Product categories that the coupon will not be applied to, or that cannot be in the cart in order for the "Fixed cart discount" to be applied.', 'woocommerce' ) ); ?>
</p> </p>
</div> </div>
<div class="options_group">'; <div class="options_group">
<?php <?php
// Customers. // Customers.
woocommerce_wp_text_input( woocommerce_wp_text_input(

View File

@ -1,7 +1,12 @@
<?php <?php
/**
* Class WC_Gateway_BACS file.
*
* @package WooCommerce\Gateways
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly exit; // Exit if accessed directly.
} }
/** /**
@ -13,11 +18,14 @@ if ( ! defined( 'ABSPATH' ) ) {
* @extends WC_Payment_Gateway * @extends WC_Payment_Gateway
* @version 2.1.0 * @version 2.1.0
* @package WooCommerce/Classes/Payment * @package WooCommerce/Classes/Payment
* @author WooThemes
*/ */
class WC_Gateway_BACS extends WC_Payment_Gateway { class WC_Gateway_BACS extends WC_Payment_Gateway {
/** @var array Array of locales */ /**
* Array of locales
*
* @var array
*/
public $locale; public $locale;
/** /**
@ -35,13 +43,14 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
$this->init_form_fields(); $this->init_form_fields();
$this->init_settings(); $this->init_settings();
// Define user set variables // Define user set variables.
$this->title = $this->get_option( 'title' ); $this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' ); $this->description = $this->get_option( 'description' );
$this->instructions = $this->get_option( 'instructions' ); $this->instructions = $this->get_option( 'instructions' );
// BACS account fields shown on the thanks page and in emails // BACS account fields shown on the thanks page and in emails.
$this->account_details = get_option( 'woocommerce_bacs_accounts', $this->account_details = get_option(
'woocommerce_bacs_accounts',
array( array(
array( array(
'account_name' => $this->get_option( 'account_name' ), 'account_name' => $this->get_option( 'account_name' ),
@ -54,12 +63,12 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
) )
); );
// Actions // Actions.
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'save_account_details' ) ); add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'save_account_details' ) );
add_action( 'woocommerce_thankyou_bacs', array( $this, 'thankyou_page' ) ); add_action( 'woocommerce_thankyou_bacs', array( $this, 'thankyou_page' ) );
// Customer Emails // Customer Emails.
add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
} }
@ -115,24 +124,24 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
$country = WC()->countries->get_base_country(); $country = WC()->countries->get_base_country();
$locale = $this->get_country_locale(); $locale = $this->get_country_locale();
// Get sortcode label in the $locale array and use appropriate one // Get sortcode label in the $locale array and use appropriate one.
$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' ); $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' );
?> ?>
<tr valign="top"> <tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Account details', 'woocommerce' ); ?>:</th> <th scope="row" class="titledesc"><?php esc_html_e( 'Account details:', 'woocommerce' ); ?></th>
<td class="forminp" id="bacs_accounts"> <td class="forminp" id="bacs_accounts">
<div class="wc_input_table_wrapper"> <div class="wc_input_table_wrapper">
<table class="widefat wc_input_table sortable" cellspacing="0"> <table class="widefat wc_input_table sortable" cellspacing="0">
<thead> <thead>
<tr> <tr>
<th class="sort">&nbsp;</th> <th class="sort">&nbsp;</th>
<th><?php _e( 'Account name', 'woocommerce' ); ?></th> <th><?php esc_html_e( 'Account name', 'woocommerce' ); ?></th>
<th><?php _e( 'Account number', 'woocommerce' ); ?></th> <th><?php esc_html_e( 'Account number', 'woocommerce' ); ?></th>
<th><?php _e( 'Bank name', 'woocommerce' ); ?></th> <th><?php esc_html_e( 'Bank name', 'woocommerce' ); ?></th>
<th><?php echo $sortcode; ?></th> <th><?php echo esc_html( $sortcode ); ?></th>
<th><?php _e( 'IBAN', 'woocommerce' ); ?></th> <th><?php esc_html_e( 'IBAN', 'woocommerce' ); ?></th>
<th><?php _e( 'BIC / Swift', 'woocommerce' ); ?></th> <th><?php esc_html_e( 'BIC / Swift', 'woocommerce' ); ?></th>
</tr> </tr>
</thead> </thead>
<tbody class="accounts"> <tbody class="accounts">
@ -144,12 +153,12 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
echo '<tr class="account"> echo '<tr class="account">
<td class="sort"></td> <td class="sort"></td>
<td><input type="text" value="' . esc_attr( wp_unslash( $account['account_name'] ) ) . '" name="bacs_account_name[' . $i . ']" /></td> <td><input type="text" value="' . esc_attr( wp_unslash( $account['account_name'] ) ) . '" name="bacs_account_name[' . esc_attr( $i ) . ']" /></td>
<td><input type="text" value="' . esc_attr( $account['account_number'] ) . '" name="bacs_account_number[' . $i . ']" /></td> <td><input type="text" value="' . esc_attr( $account['account_number'] ) . '" name="bacs_account_number[' . esc_attr( $i ) . ']" /></td>
<td><input type="text" value="' . esc_attr( wp_unslash( $account['bank_name'] ) ) . '" name="bacs_bank_name[' . $i . ']" /></td> <td><input type="text" value="' . esc_attr( wp_unslash( $account['bank_name'] ) ) . '" name="bacs_bank_name[' . esc_attr( $i ) . ']" /></td>
<td><input type="text" value="' . esc_attr( $account['sort_code'] ) . '" name="bacs_sort_code[' . $i . ']" /></td> <td><input type="text" value="' . esc_attr( $account['sort_code'] ) . '" name="bacs_sort_code[' . esc_attr( $i ) . ']" /></td>
<td><input type="text" value="' . esc_attr( $account['iban'] ) . '" name="bacs_iban[' . $i . ']" /></td> <td><input type="text" value="' . esc_attr( $account['iban'] ) . '" name="bacs_iban[' . esc_attr( $i ) . ']" /></td>
<td><input type="text" value="' . esc_attr( $account['bic'] ) . '" name="bacs_bic[' . $i . ']" /></td> <td><input type="text" value="' . esc_attr( $account['bic'] ) . '" name="bacs_bic[' . esc_attr( $i ) . ']" /></td>
</tr>'; </tr>';
} }
} }
@ -157,7 +166,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
</tbody> </tbody>
<tfoot> <tfoot>
<tr> <tr>
<th colspan="7"><a href="#" class="add button"><?php _e( '+ Add account', 'woocommerce' ); ?></a> <a href="#" class="remove_rows button"><?php _e( 'Remove selected account(s)', 'woocommerce' ); ?></a></th> <th colspan="7"><a href="#" class="add button"><?php esc_html_e( '+ Add account', 'woocommerce' ); ?></a> <a href="#" class="remove_rows button"><?php esc_html_e( 'Remove selected account(s)', 'woocommerce' ); ?></a></th>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
@ -196,14 +205,16 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
$accounts = array(); $accounts = array();
if ( isset( $_POST['bacs_account_name'] ) ) { // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- Nonce verification already handled in WC_Admin_Settings::save()
if ( isset( $_POST['bacs_account_name'] ) && isset( $_POST['bacs_account_number'] ) && isset( $_POST['bacs_bank_name'] )
&& isset( $_POST['bacs_sort_code'] ) && isset( $_POST['bacs_iban'] ) && isset( $_POST['bacs_bic'] ) ) {
$account_names = array_map( 'wc_clean', $_POST['bacs_account_name'] ); $account_names = wc_clean( wp_unslash( $_POST['bacs_account_name'] ) );
$account_numbers = array_map( 'wc_clean', $_POST['bacs_account_number'] ); $account_numbers = wc_clean( wp_unslash( $_POST['bacs_account_number'] ) );
$bank_names = array_map( 'wc_clean', $_POST['bacs_bank_name'] ); $bank_names = wc_clean( wp_unslash( $_POST['bacs_bank_name'] ) );
$sort_codes = array_map( 'wc_clean', $_POST['bacs_sort_code'] ); $sort_codes = wc_clean( wp_unslash( $_POST['bacs_sort_code'] ) );
$ibans = array_map( 'wc_clean', $_POST['bacs_iban'] ); $ibans = wc_clean( wp_unslash( $_POST['bacs_iban'] ) );
$bics = array_map( 'wc_clean', $_POST['bacs_bic'] ); $bics = wc_clean( wp_unslash( $_POST['bacs_bic'] ) );
foreach ( $account_names as $i => $name ) { foreach ( $account_names as $i => $name ) {
if ( ! isset( $account_names[ $i ] ) ) { if ( ! isset( $account_names[ $i ] ) ) {
@ -220,20 +231,20 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
); );
} }
} }
// phpcs:enable
update_option( 'woocommerce_bacs_accounts', $accounts ); update_option( 'woocommerce_bacs_accounts', $accounts );
} }
/** /**
* Output for the order received page. * Output for the order received page.
* *
* @param int $order_id * @param int $order_id Order ID.
*/ */
public function thankyou_page( $order_id ) { public function thankyou_page( $order_id ) {
if ( $this->instructions ) { if ( $this->instructions ) {
echo wpautop( wptexturize( wp_kses_post( $this->instructions ) ) ); echo wp_kses_post( wpautop( wptexturize( wp_kses_post( $this->instructions ) ) ) );
} }
$this->bank_details( $order_id ); $this->bank_details( $order_id );
@ -242,15 +253,15 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
/** /**
* Add content to the WC emails. * Add content to the WC emails.
* *
* @param WC_Order $order * @param WC_Order $order Order object.
* @param bool $sent_to_admin * @param bool $sent_to_admin Sent to admin.
* @param bool $plain_text * @param bool $plain_text Email format: plain text or HTML.
*/ */
public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
if ( ! $sent_to_admin && 'bacs' === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) { if ( ! $sent_to_admin && 'bacs' === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) {
if ( $this->instructions ) { if ( $this->instructions ) {
echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL; echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
} }
$this->bank_details( $order->get_id() ); $this->bank_details( $order->get_id() );
} }
@ -260,7 +271,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
/** /**
* Get bank details and place into a list format. * Get bank details and place into a list format.
* *
* @param int $order_id * @param int $order_id Order ID.
*/ */
private function bank_details( $order_id = '' ) { private function bank_details( $order_id = '' ) {
@ -268,14 +279,14 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
return; return;
} }
// Get order and store in $order // Get order and store in $order.
$order = wc_get_order( $order_id ); $order = wc_get_order( $order_id );
// Get the order country and country $locale // Get the order country and country $locale.
$country = $order->get_billing_country(); $country = $order->get_billing_country();
$locale = $this->get_country_locale(); $locale = $this->get_country_locale();
// Get sortcode label in the $locale array and use appropriate one // Get sortcode label in the $locale array and use appropriate one.
$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' ); $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' );
$bacs_accounts = apply_filters( 'woocommerce_bacs_accounts', $this->account_details ); $bacs_accounts = apply_filters( 'woocommerce_bacs_accounts', $this->account_details );
@ -293,8 +304,9 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
$account_html .= '<ul class="wc-bacs-bank-details order_details bacs_details">' . PHP_EOL; $account_html .= '<ul class="wc-bacs-bank-details order_details bacs_details">' . PHP_EOL;
// BACS account fields shown on the thanks page and in emails // BACS account fields shown on the thanks page and in emails.
$account_fields = apply_filters( 'woocommerce_bacs_account_fields', array( $account_fields = apply_filters(
'woocommerce_bacs_account_fields', array(
'bank_name' => array( 'bank_name' => array(
'label' => __( 'Bank', 'woocommerce' ), 'label' => __( 'Bank', 'woocommerce' ),
'value' => $bacs_account->bank_name, 'value' => $bacs_account->bank_name,
@ -315,7 +327,8 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
'label' => __( 'BIC', 'woocommerce' ), 'label' => __( 'BIC', 'woocommerce' ),
'value' => $bacs_account->bic, 'value' => $bacs_account->bic,
), ),
), $order_id ); ), $order_id
);
foreach ( $account_fields as $field_key => $field ) { foreach ( $account_fields as $field_key => $field ) {
if ( ! empty( $field['value'] ) ) { if ( ! empty( $field['value'] ) ) {
@ -328,7 +341,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
} }
if ( $has_details ) { if ( $has_details ) {
echo '<section class="woocommerce-bacs-bank-details"><h2 class="wc-bacs-bank-details-heading">' . __( 'Our bank details', 'woocommerce' ) . '</h2>' . PHP_EOL . $account_html . '</section>'; echo '<section class="woocommerce-bacs-bank-details"><h2 class="wc-bacs-bank-details-heading">' . esc_html__( 'Our bank details', 'woocommerce' ) . '</h2>' . wp_kses_post( PHP_EOL . $account_html ) . '</section>';
} }
} }
@ -337,7 +350,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
/** /**
* Process the payment and return the result. * Process the payment and return the result.
* *
* @param int $order_id * @param int $order_id Order ID.
* @return array * @return array
*/ */
public function process_payment( $order_id ) { public function process_payment( $order_id ) {
@ -345,19 +358,19 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
$order = wc_get_order( $order_id ); $order = wc_get_order( $order_id );
if ( $order->get_total() > 0 ) { if ( $order->get_total() > 0 ) {
// Mark as on-hold (we're awaiting the payment) // Mark as on-hold (we're awaiting the payment).
$order->update_status( 'on-hold', __( 'Awaiting BACS payment', 'woocommerce' ) ); $order->update_status( 'on-hold', __( 'Awaiting BACS payment', 'woocommerce' ) );
} else { } else {
$order->payment_complete(); $order->payment_complete();
} }
// Reduce stock levels // Reduce stock levels.
wc_reduce_stock_levels( $order_id ); wc_reduce_stock_levels( $order_id );
// Remove cart // Remove cart.
WC()->cart->empty_cart(); WC()->cart->empty_cart();
// Return thankyou redirect // Return thankyou redirect.
return array( return array(
'result' => 'success', 'result' => 'success',
'redirect' => $this->get_return_url( $order ), 'redirect' => $this->get_return_url( $order ),
@ -374,8 +387,9 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
if ( empty( $this->locale ) ) { if ( empty( $this->locale ) ) {
// Locale information to be used - only those that are not 'Sort Code' // Locale information to be used - only those that are not 'Sort Code'.
$this->locale = apply_filters( 'woocommerce_get_bacs_locale', array( $this->locale = apply_filters(
'woocommerce_get_bacs_locale', array(
'AU' => array( 'AU' => array(
'sortcode' => array( 'sortcode' => array(
'label' => __( 'BSB', 'woocommerce' ), 'label' => __( 'BSB', 'woocommerce' ),
@ -416,7 +430,8 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
'label' => __( 'Branch code', 'woocommerce' ), 'label' => __( 'Branch code', 'woocommerce' ),
), ),
), ),
) ); )
);
} }

View File

@ -1,7 +1,12 @@
<?php <?php
/**
* Class WC_Gateway_Cheque file.
*
* @package WooCommerce\Gateways
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly exit; // Exit if accessed directly.
} }
/** /**
@ -13,7 +18,6 @@ if ( ! defined( 'ABSPATH' ) ) {
* @extends WC_Payment_Gateway * @extends WC_Payment_Gateway
* @version 2.1.0 * @version 2.1.0
* @package WooCommerce/Classes/Payment * @package WooCommerce/Classes/Payment
* @author WooThemes
*/ */
class WC_Gateway_Cheque extends WC_Payment_Gateway { class WC_Gateway_Cheque extends WC_Payment_Gateway {
@ -31,16 +35,16 @@ class WC_Gateway_Cheque extends WC_Payment_Gateway {
$this->init_form_fields(); $this->init_form_fields();
$this->init_settings(); $this->init_settings();
// Define user set variables // Define user set variables.
$this->title = $this->get_option( 'title' ); $this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' ); $this->description = $this->get_option( 'description' );
$this->instructions = $this->get_option( 'instructions' ); $this->instructions = $this->get_option( 'instructions' );
// Actions // Actions.
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
add_action( 'woocommerce_thankyou_cheque', array( $this, 'thankyou_page' ) ); add_action( 'woocommerce_thankyou_cheque', array( $this, 'thankyou_page' ) );
// Customer Emails // Customer Emails.
add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
} }
@ -85,7 +89,7 @@ class WC_Gateway_Cheque extends WC_Payment_Gateway {
*/ */
public function thankyou_page() { public function thankyou_page() {
if ( $this->instructions ) { if ( $this->instructions ) {
echo wpautop( wptexturize( $this->instructions ) ); echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) );
} }
} }
@ -93,20 +97,20 @@ class WC_Gateway_Cheque extends WC_Payment_Gateway {
* Add content to the WC emails. * Add content to the WC emails.
* *
* @access public * @access public
* @param WC_Order $order * @param WC_Order $order Order object.
* @param bool $sent_to_admin * @param bool $sent_to_admin Sent to admin.
* @param bool $plain_text * @param bool $plain_text Email format: plain text or HTML.
*/ */
public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
if ( $this->instructions && ! $sent_to_admin && 'cheque' === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) { if ( $this->instructions && ! $sent_to_admin && 'cheque' === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) {
echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL; echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
} }
} }
/** /**
* Process the payment and return the result. * Process the payment and return the result.
* *
* @param int $order_id * @param int $order_id Order ID.
* @return array * @return array
*/ */
public function process_payment( $order_id ) { public function process_payment( $order_id ) {
@ -114,19 +118,19 @@ class WC_Gateway_Cheque extends WC_Payment_Gateway {
$order = wc_get_order( $order_id ); $order = wc_get_order( $order_id );
if ( $order->get_total() > 0 ) { if ( $order->get_total() > 0 ) {
// Mark as on-hold (we're awaiting the cheque) // Mark as on-hold (we're awaiting the cheque).
$order->update_status( 'on-hold', _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) ); $order->update_status( 'on-hold', _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) );
} else { } else {
$order->payment_complete(); $order->payment_complete();
} }
// Reduce stock levels // Reduce stock levels.
wc_reduce_stock_levels( $order_id ); wc_reduce_stock_levels( $order_id );
// Remove cart // Remove cart.
WC()->cart->empty_cart(); WC()->cart->empty_cart();
// Return thankyou redirect // Return thankyou redirect.
return array( return array(
'result' => 'success', 'result' => 'success',
'redirect' => $this->get_return_url( $order ), 'redirect' => $this->get_return_url( $order ),

View File

@ -1,4 +1,10 @@
<?php <?php
/**
* Class WC_Payment_Gateway_CC file.
*
* @package WooCommerce\Gateways
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
@ -8,13 +14,13 @@ if ( ! defined( 'ABSPATH' ) ) {
* *
* @since 2.6.0 * @since 2.6.0
* @package WooCommerce/Classes * @package WooCommerce/Classes
* @author WooThemes
*/ */
class WC_Payment_Gateway_CC extends WC_Payment_Gateway { class WC_Payment_Gateway_CC extends WC_Payment_Gateway {
/** /**
* Builds our payment fields area - including tokenization fields for logged * Builds our payment fields area - including tokenization fields for logged
* in users, and the actual payment fields. * in users, and the actual payment fields.
*
* @since 2.6.0 * @since 2.6.0
*/ */
public function payment_fields() { public function payment_fields() {
@ -34,7 +40,7 @@ class WC_Payment_Gateway_CC extends WC_Payment_Gateway {
* Gateways which support tokenization do not require names - we don't want the data to post to the server. * Gateways which support tokenization do not require names - we don't want the data to post to the server.
* *
* @since 2.6.0 * @since 2.6.0
* @param string $name * @param string $name Field name.
* @return string * @return string
*/ */
public function field_name( $name ) { public function field_name( $name ) {
@ -43,6 +49,7 @@ class WC_Payment_Gateway_CC extends WC_Payment_Gateway {
/** /**
* Outputs fields for entering credit card information. * Outputs fields for entering credit card information.
*
* @since 2.6.0 * @since 2.6.0
*/ */
public function form() { public function form() {
@ -77,7 +84,7 @@ class WC_Payment_Gateway_CC extends WC_Payment_Gateway {
<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
<?php <?php
foreach ( $fields as $field ) { foreach ( $fields as $field ) {
echo $field; echo $field; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
} }
?> ?>
<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
@ -86,7 +93,7 @@ class WC_Payment_Gateway_CC extends WC_Payment_Gateway {
<?php <?php
if ( $this->supports( 'credit_card_form_cvc_on_saved_method' ) ) { if ( $this->supports( 'credit_card_form_cvc_on_saved_method' ) ) {
echo '<fieldset>' . $cvc_field . '</fieldset>'; echo '<fieldset>' . $cvc_field . '</fieldset>'; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
} }
} }
} }

View File

@ -1,20 +1,26 @@
<?php <?php
/**
* Class WC_Payment_Gateway_eCheck file.
*
* @package WooCommerce\Gateways
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
/** /**
* eCheck Payment Gateway * Class for eCheck Payment Gateway
* *
* @since 2.6.0 * @since 2.6.0
* @package WooCommerce/Classes * @package WooCommerce/Classes
* @author WooThemes
*/ */
class WC_Payment_Gateway_eCheck extends WC_Payment_Gateway { class WC_Payment_Gateway_ECheck extends WC_Payment_Gateway {
/** /**
* Builds our payment fields area - including tokenization fields for logged * Builds our payment fields area - including tokenization fields for logged
* in users, and the actual payment fields. * in users, and the actual payment fields.
*
* @since 2.6.0 * @since 2.6.0
*/ */
public function payment_fields() { public function payment_fields() {
@ -30,6 +36,7 @@ class WC_Payment_Gateway_eCheck extends WC_Payment_Gateway {
/** /**
* Outputs fields for entering eCheck information. * Outputs fields for entering eCheck information.
*
* @since 2.6.0 * @since 2.6.0
*/ */
public function form() { public function form() {
@ -53,11 +60,12 @@ class WC_Payment_Gateway_eCheck extends WC_Payment_Gateway {
<?php do_action( 'woocommerce_echeck_form_start', $this->id ); ?> <?php do_action( 'woocommerce_echeck_form_start', $this->id ); ?>
<?php <?php
foreach ( $fields as $field ) { foreach ( $fields as $field ) {
echo $field; echo $field; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
} }
?> ?>
<?php do_action( 'woocommerce_echeck_form_end', $this->id ); ?> <?php do_action( 'woocommerce_echeck_form_end', $this->id ); ?>
<div class="clear"></div> <div class="clear"></div>
</fieldset><?php </fieldset>
<?php
} }
} }

View File

@ -1,7 +1,12 @@
<?php <?php
/**
* Class WC_Gateway_COD file.
*
* @package WooCommerce\Gateways
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly exit; // Exit if accessed directly.
} }
/** /**
@ -13,7 +18,6 @@ if ( ! defined( 'ABSPATH' ) ) {
* @extends WC_Payment_Gateway * @extends WC_Payment_Gateway
* @version 2.1.0 * @version 2.1.0
* @package WooCommerce/Classes/Payment * @package WooCommerce/Classes/Payment
* @author WooThemes
*/ */
class WC_Gateway_COD extends WC_Payment_Gateway { class WC_Gateway_COD extends WC_Payment_Gateway {
@ -21,14 +25,14 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
* Constructor for the gateway. * Constructor for the gateway.
*/ */
public function __construct() { public function __construct() {
// Setup general properties // Setup general properties.
$this->setup_properties(); $this->setup_properties();
// Load the settings // Load the settings.
$this->init_form_fields(); $this->init_form_fields();
$this->init_settings(); $this->init_settings();
// Get settings // Get settings.
$this->title = $this->get_option( 'title' ); $this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' ); $this->description = $this->get_option( 'description' );
$this->instructions = $this->get_option( 'instructions' ); $this->instructions = $this->get_option( 'instructions' );
@ -39,7 +43,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) ); add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) );
add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'change_payment_complete_order_status' ), 10, 3 ); add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'change_payment_complete_order_status' ), 10, 3 );
// Customer Emails // Customer Emails.
add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
} }
@ -124,7 +128,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
$order = null; $order = null;
$needs_shipping = false; $needs_shipping = false;
// Test if shipping is needed first // Test if shipping is needed first.
if ( WC()->cart && WC()->cart->needs_shipping() ) { if ( WC()->cart && WC()->cart->needs_shipping() ) {
$needs_shipping = true; $needs_shipping = true;
} elseif ( is_page( wc_get_page_id( 'checkout' ) ) && 0 < get_query_var( 'order-pay' ) ) { } elseif ( is_page( wc_get_page_id( 'checkout' ) ) && 0 < get_query_var( 'order-pay' ) ) {
@ -132,7 +136,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
$order = wc_get_order( $order_id ); $order = wc_get_order( $order_id );
// Test if order needs shipping. // Test if order needs shipping.
if ( 0 < sizeof( $order->get_items() ) ) { if ( 0 < count( $order->get_items() ) ) {
foreach ( $order->get_items() as $item ) { foreach ( $order->get_items() as $item ) {
$_product = $item->get_product(); $_product = $item->get_product();
if ( $_product && $_product->needs_shipping() ) { if ( $_product && $_product->needs_shipping() ) {
@ -145,7 +149,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
$needs_shipping = apply_filters( 'woocommerce_cart_needs_shipping', $needs_shipping ); $needs_shipping = apply_filters( 'woocommerce_cart_needs_shipping', $needs_shipping );
// Virtual order, with virtual disabled // Virtual order, with virtual disabled.
if ( ! $this->enable_for_virtual && ! $needs_shipping ) { if ( ! $this->enable_for_virtual && ! $needs_shipping ) {
return false; return false;
} }
@ -153,10 +157,11 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
// Only apply if all packages are being shipped via chosen method, or order is virtual. // Only apply if all packages are being shipped via chosen method, or order is virtual.
if ( ! empty( $this->enable_for_methods ) && $needs_shipping ) { if ( ! empty( $this->enable_for_methods ) && $needs_shipping ) {
$chosen_shipping_methods = array(); $chosen_shipping_methods = array();
$chosen_shipping_methods_session = WC()->session->get( 'chosen_shipping_methods' );
if ( is_object( $order ) ) { if ( is_object( $order ) ) {
$chosen_shipping_methods = array_unique( array_map( 'wc_get_string_before_colon', $order->get_shipping_methods() ) ); $chosen_shipping_methods = array_unique( array_map( 'wc_get_string_before_colon', $order->get_shipping_methods() ) );
} elseif ( $chosen_shipping_methods_session = WC()->session->get( 'chosen_shipping_methods' ) ) { } elseif ( $chosen_shipping_methods_session ) {
$chosen_shipping_methods = array_unique( array_map( 'wc_get_string_before_colon', $chosen_shipping_methods_session ) ); $chosen_shipping_methods = array_unique( array_map( 'wc_get_string_before_colon', $chosen_shipping_methods_session ) );
} }
@ -172,26 +177,26 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
/** /**
* Process the payment and return the result. * Process the payment and return the result.
* *
* @param int $order_id * @param int $order_id Order ID.
* @return array * @return array
*/ */
public function process_payment( $order_id ) { public function process_payment( $order_id ) {
$order = wc_get_order( $order_id ); $order = wc_get_order( $order_id );
if ( $order->get_total() > 0 ) { if ( $order->get_total() > 0 ) {
// Mark as processing or on-hold (payment won't be taken until delivery) // Mark as processing or on-hold (payment won't be taken until delivery).
$order->update_status( apply_filters( 'woocommerce_cod_process_payment_order_status', $order->has_downloadable_item() ? 'on-hold' : 'processing', $order ), __( 'Payment to be made upon delivery.', 'woocommerce' ) ); $order->update_status( apply_filters( 'woocommerce_cod_process_payment_order_status', $order->has_downloadable_item() ? 'on-hold' : 'processing', $order ), __( 'Payment to be made upon delivery.', 'woocommerce' ) );
} else { } else {
$order->payment_complete(); $order->payment_complete();
} }
// Reduce stock levels // Reduce stock levels.
wc_reduce_stock_levels( $order_id ); wc_reduce_stock_levels( $order_id );
// Remove cart // Remove cart.
WC()->cart->empty_cart(); WC()->cart->empty_cart();
// Return thankyou redirect // Return thankyou redirect.
return array( return array(
'result' => 'success', 'result' => 'success',
'redirect' => $this->get_return_url( $order ), 'redirect' => $this->get_return_url( $order ),
@ -203,7 +208,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
*/ */
public function thankyou_page() { public function thankyou_page() {
if ( $this->instructions ) { if ( $this->instructions ) {
echo wpautop( wptexturize( $this->instructions ) ); echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) );
} }
} }
@ -211,9 +216,9 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
* Change payment complete order status to completed for COD orders. * Change payment complete order status to completed for COD orders.
* *
* @since 3.1.0 * @since 3.1.0
* @param string $status * @param string $status Current order status.
* @param int $order_id * @param int $order_id Order ID.
* @param WC_Order $order * @param WC_Order|false $order Order object.
* @return string * @return string
*/ */
public function change_payment_complete_order_status( $status, $order_id = 0, $order = false ) { public function change_payment_complete_order_status( $status, $order_id = 0, $order = false ) {
@ -227,13 +232,13 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
* Add content to the WC emails. * Add content to the WC emails.
* *
* @access public * @access public
* @param WC_Order $order * @param WC_Order $order Order object.
* @param bool $sent_to_admin * @param bool $sent_to_admin Sent to admin.
* @param bool $plain_text * @param bool $plain_text Email format: plain text or HTML.
*/ */
public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
if ( $this->instructions && ! $sent_to_admin && $this->id === $order->get_payment_method() ) { if ( $this->instructions && ! $sent_to_admin && $this->id === $order->get_payment_method() ) {
echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL; echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
} }
} }
} }

View File

@ -8,7 +8,6 @@
* @extends WC_Payment_Gateway * @extends WC_Payment_Gateway
* @version 2.3.0 * @version 2.3.0
* @package WooCommerce/Classes/Payment * @package WooCommerce/Classes/Payment
* @author WooThemes
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
@ -20,10 +19,18 @@ if ( ! defined( 'ABSPATH' ) ) {
*/ */
class WC_Gateway_Paypal extends WC_Payment_Gateway { class WC_Gateway_Paypal extends WC_Payment_Gateway {
/** @var bool Whether or not logging is enabled */ /**
* Whether or not logging is enabled
*
* @var bool
*/
public static $log_enabled = false; public static $log_enabled = false;
/** @var WC_Logger Logger instance */ /**
* Logger instance
*
* @var WC_Logger
*/
public static $log = false; public static $log = false;
/** /**
@ -34,6 +41,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
$this->has_fields = false; $this->has_fields = false;
$this->order_button_text = __( 'Proceed to PayPal', 'woocommerce' ); $this->order_button_text = __( 'Proceed to PayPal', 'woocommerce' );
$this->method_title = __( 'PayPal', 'woocommerce' ); $this->method_title = __( 'PayPal', 'woocommerce' );
/* translators: %s: Link to WC system status page */
$this->method_description = sprintf( __( 'PayPal Standard sends customers to PayPal to enter their payment information. PayPal IPN requires fsockopen/cURL support to update order statuses after payment. Check the <a href="%s">system status</a> page for more details.', 'woocommerce' ), admin_url( 'admin.php?page=wc-status' ) ); $this->method_description = sprintf( __( 'PayPal Standard sends customers to PayPal to enter their payment information. PayPal IPN requires fsockopen/cURL support to update order statuses after payment. Check the <a href="%s">system status</a> page for more details.', 'woocommerce' ), admin_url( 'admin.php?page=wc-status' ) );
$this->supports = array( $this->supports = array(
'products', 'products',
@ -56,6 +64,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
self::$log_enabled = $this->debug; self::$log_enabled = $this->debug;
if ( $this->testmode ) { if ( $this->testmode ) {
/* translators: %s: Link to PayPal sandbox testing guide page */
$this->description .= ' ' . sprintf( __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the <a href="%s">PayPal Sandbox Testing Guide</a> for more details.', 'woocommerce' ), 'https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/' ); $this->description .= ' ' . sprintf( __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the <a href="%s">PayPal Sandbox Testing Guide</a> for more details.', 'woocommerce' ), 'https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/' );
$this->description = trim( $this->description ); $this->description = trim( $this->description );
} }
@ -68,11 +77,11 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
if ( ! $this->is_valid_for_use() ) { if ( ! $this->is_valid_for_use() ) {
$this->enabled = 'no'; $this->enabled = 'no';
} else { } else {
include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-paypal-ipn-handler.php' ); include_once dirname( __FILE__ ) . '/includes/class-wc-gateway-paypal-ipn-handler.php';
new WC_Gateway_Paypal_IPN_Handler( $this->testmode, $this->receiver_email ); new WC_Gateway_Paypal_IPN_Handler( $this->testmode, $this->receiver_email );
if ( $this->identity_token ) { if ( $this->identity_token ) {
include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-paypal-pdt-handler.php' ); include_once dirname( __FILE__ ) . '/includes/class-wc-gateway-paypal-pdt-handler.php';
new WC_Gateway_Paypal_PDT_Handler( $this->testmode, $this->identity_token ); new WC_Gateway_Paypal_PDT_Handler( $this->testmode, $this->identity_token );
} }
} }
@ -82,8 +91,8 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
* Logging method. * Logging method.
* *
* @param string $message Log message. * @param string $message Log message.
* @param string $level Optional. Default 'info'. * @param string $level Optional. Default 'info'. Possible values:
* emergency|alert|critical|error|warning|notice|info|debug * emergency|alert|critical|error|warning|notice|info|debug.
*/ */
public static function log( $message, $level = 'info' ) { public static function log( $message, $level = 'info' ) {
if ( self::$log_enabled ) { if ( self::$log_enabled ) {
@ -96,6 +105,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
/** /**
* Get gateway icon. * Get gateway icon.
*
* @return string * @return string
*/ */
public function get_icon() { public function get_icon() {
@ -113,7 +123,8 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
/** /**
* Get the link for an icon based on country. * Get the link for an icon based on country.
* @param string $country *
* @param string $country Country two letter code.
* @return string * @return string
*/ */
protected function get_icon_url( $country ) { protected function get_icon_url( $country ) {
@ -121,9 +132,9 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
$home_counties = array( 'BE', 'CZ', 'DK', 'HU', 'IT', 'JP', 'NL', 'NO', 'ES', 'SE', 'TR', 'IN' ); $home_counties = array( 'BE', 'CZ', 'DK', 'HU', 'IT', 'JP', 'NL', 'NO', 'ES', 'SE', 'TR', 'IN' );
$countries = array( 'DZ', 'AU', 'BH', 'BQ', 'BW', 'CA', 'CN', 'CW', 'FI', 'FR', 'DE', 'GR', 'HK', 'ID', 'JO', 'KE', 'KW', 'LU', 'MY', 'MA', 'OM', 'PH', 'PL', 'PT', 'QA', 'IE', 'RU', 'BL', 'SX', 'MF', 'SA', 'SG', 'SK', 'KR', 'SS', 'TW', 'TH', 'AE', 'GB', 'US', 'VN' ); $countries = array( 'DZ', 'AU', 'BH', 'BQ', 'BW', 'CA', 'CN', 'CW', 'FI', 'FR', 'DE', 'GR', 'HK', 'ID', 'JO', 'KE', 'KW', 'LU', 'MY', 'MA', 'OM', 'PH', 'PL', 'PT', 'QA', 'IE', 'RU', 'BL', 'SX', 'MF', 'SA', 'SG', 'SK', 'KR', 'SS', 'TW', 'TH', 'AE', 'GB', 'US', 'VN' );
if ( in_array( $country, $home_counties ) ) { if ( in_array( $country, $home_counties, true ) ) {
return $url . '/webapps/mpp/home'; return $url . '/webapps/mpp/home';
} elseif ( in_array( $country, $countries ) ) { } elseif ( in_array( $country, $countries, true ) ) {
return $url . '/webapps/mpp/paypal-popup'; return $url . '/webapps/mpp/paypal-popup';
} else { } else {
return $url . '/cgi-bin/webscr?cmd=xpt/Marketing/general/WIPaypal-outside'; return $url . '/cgi-bin/webscr?cmd=xpt/Marketing/general/WIPaypal-outside';
@ -138,62 +149,62 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
*/ */
protected function get_icon_image( $country ) { protected function get_icon_image( $country ) {
switch ( $country ) { switch ( $country ) {
case 'US' : case 'US':
case 'NZ' : case 'NZ':
case 'CZ' : case 'CZ':
case 'HU' : case 'HU':
case 'MY' : case 'MY':
$icon = 'https://www.paypalobjects.com/webstatic/mktg/logo/AM_mc_vs_dc_ae.jpg'; $icon = 'https://www.paypalobjects.com/webstatic/mktg/logo/AM_mc_vs_dc_ae.jpg';
break; break;
case 'TR' : case 'TR':
$icon = 'https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_paypal_odeme_secenekleri.jpg'; $icon = 'https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_paypal_odeme_secenekleri.jpg';
break; break;
case 'GB' : case 'GB':
$icon = 'https://www.paypalobjects.com/webstatic/mktg/Logo/AM_mc_vs_ms_ae_UK.png'; $icon = 'https://www.paypalobjects.com/webstatic/mktg/Logo/AM_mc_vs_ms_ae_UK.png';
break; break;
case 'MX' : case 'MX':
$icon = array( $icon = array(
'https://www.paypal.com/es_XC/Marketing/i/banner/paypal_visa_mastercard_amex.png', 'https://www.paypal.com/es_XC/Marketing/i/banner/paypal_visa_mastercard_amex.png',
'https://www.paypal.com/es_XC/Marketing/i/banner/paypal_debit_card_275x60.gif', 'https://www.paypal.com/es_XC/Marketing/i/banner/paypal_debit_card_275x60.gif',
); );
break; break;
case 'FR' : case 'FR':
$icon = 'https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_paypal_moyens_paiement_fr.jpg'; $icon = 'https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_paypal_moyens_paiement_fr.jpg';
break; break;
case 'AU' : case 'AU':
$icon = 'https://www.paypalobjects.com/webstatic/en_AU/mktg/logo/Solutions-graphics-1-184x80.jpg'; $icon = 'https://www.paypalobjects.com/webstatic/en_AU/mktg/logo/Solutions-graphics-1-184x80.jpg';
break; break;
case 'DK' : case 'DK':
$icon = 'https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_PayPal_betalingsmuligheder_dk.jpg'; $icon = 'https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_PayPal_betalingsmuligheder_dk.jpg';
break; break;
case 'RU' : case 'RU':
$icon = 'https://www.paypalobjects.com/webstatic/ru_RU/mktg/business/pages/logo-center/AM_mc_vs_dc_ae.jpg'; $icon = 'https://www.paypalobjects.com/webstatic/ru_RU/mktg/business/pages/logo-center/AM_mc_vs_dc_ae.jpg';
break; break;
case 'NO' : case 'NO':
$icon = 'https://www.paypalobjects.com/webstatic/mktg/logo-center/banner_pl_just_pp_319x110.jpg'; $icon = 'https://www.paypalobjects.com/webstatic/mktg/logo-center/banner_pl_just_pp_319x110.jpg';
break; break;
case 'CA' : case 'CA':
$icon = 'https://www.paypalobjects.com/webstatic/en_CA/mktg/logo-image/AM_mc_vs_dc_ae.jpg'; $icon = 'https://www.paypalobjects.com/webstatic/en_CA/mktg/logo-image/AM_mc_vs_dc_ae.jpg';
break; break;
case 'HK' : case 'HK':
$icon = 'https://www.paypalobjects.com/webstatic/en_HK/mktg/logo/AM_mc_vs_dc_ae.jpg'; $icon = 'https://www.paypalobjects.com/webstatic/en_HK/mktg/logo/AM_mc_vs_dc_ae.jpg';
break; break;
case 'SG' : case 'SG':
$icon = 'https://www.paypalobjects.com/webstatic/en_SG/mktg/Logos/AM_mc_vs_dc_ae.jpg'; $icon = 'https://www.paypalobjects.com/webstatic/en_SG/mktg/Logos/AM_mc_vs_dc_ae.jpg';
break; break;
case 'TW' : case 'TW':
$icon = 'https://www.paypalobjects.com/webstatic/en_TW/mktg/logos/AM_mc_vs_dc_ae.jpg'; $icon = 'https://www.paypalobjects.com/webstatic/en_TW/mktg/logos/AM_mc_vs_dc_ae.jpg';
break; break;
case 'TH' : case 'TH':
$icon = 'https://www.paypalobjects.com/webstatic/en_TH/mktg/Logos/AM_mc_vs_dc_ae.jpg'; $icon = 'https://www.paypalobjects.com/webstatic/en_TH/mktg/Logos/AM_mc_vs_dc_ae.jpg';
break; break;
case 'JP' : case 'JP':
$icon = 'https://www.paypal.com/ja_JP/JP/i/bnr/horizontal_solution_4_jcb.gif'; $icon = 'https://www.paypal.com/ja_JP/JP/i/bnr/horizontal_solution_4_jcb.gif';
break; break;
case 'IN' : case 'IN':
$icon = 'https://www.paypalobjects.com/webstatic/mktg/logo/AM_mc_vs_dc_ae.jpg'; $icon = 'https://www.paypalobjects.com/webstatic/mktg/logo/AM_mc_vs_dc_ae.jpg';
break; break;
default : default:
$icon = WC_HTTPS::force_https_url( WC()->plugin_url() . '/includes/gateways/paypal/assets/images/paypal.png' ); $icon = WC_HTTPS::force_https_url( WC()->plugin_url() . '/includes/gateways/paypal/assets/images/paypal.png' );
break; break;
} }
@ -202,10 +213,18 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
/** /**
* Check if this gateway is enabled and available in the user's country. * Check if this gateway is enabled and available in the user's country.
*
* @return bool * @return bool
*/ */
public function is_valid_for_use() { public function is_valid_for_use() {
return in_array( get_woocommerce_currency(), apply_filters( 'woocommerce_paypal_supported_currencies', array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ) ) ); return in_array(
get_woocommerce_currency(),
apply_filters(
'woocommerce_paypal_supported_currencies',
array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' )
),
true
);
} }
/** /**
@ -219,7 +238,11 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
parent::admin_options(); parent::admin_options();
} else { } else {
?> ?>
<div class="inline error"><p><strong><?php _e( 'Gateway disabled', 'woocommerce' ); ?></strong>: <?php _e( 'PayPal does not support your store currency.', 'woocommerce' ); ?></p></div> <div class="inline error">
<p>
<strong><?php esc_html_e( 'Gateway disabled', 'woocommerce' ); ?></strong>: <?php esc_html_e( 'PayPal does not support your store currency.', 'woocommerce' ); ?>
</p>
</div>
<?php <?php
} }
} }
@ -228,12 +251,13 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
* Initialise Gateway Settings Form Fields. * Initialise Gateway Settings Form Fields.
*/ */
public function init_form_fields() { public function init_form_fields() {
$this->form_fields = include( 'includes/settings-paypal.php' ); $this->form_fields = include 'includes/settings-paypal.php';
} }
/** /**
* Get the transaction URL. * Get the transaction URL.
* @param WC_Order $order *
* @param WC_Order $order Order object.
* @return string * @return string
*/ */
public function get_transaction_url( $order ) { public function get_transaction_url( $order ) {
@ -247,11 +271,12 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
/** /**
* Process the payment and return the result. * Process the payment and return the result.
* @param int $order_id *
* @param int $order_id Order ID.
* @return array * @return array
*/ */
public function process_payment( $order_id ) { public function process_payment( $order_id ) {
include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-paypal-request.php' ); include_once dirname( __FILE__ ) . '/includes/class-wc-gateway-paypal-request.php';
$order = wc_get_order( $order_id ); $order = wc_get_order( $order_id );
$paypal_request = new WC_Gateway_Paypal_Request( $this ); $paypal_request = new WC_Gateway_Paypal_Request( $this );
@ -264,7 +289,8 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
/** /**
* Can the order be refunded via PayPal? * Can the order be refunded via PayPal?
* @param WC_Order $order *
* @param WC_Order $order Order object.
* @return bool * @return bool
*/ */
public function can_refund_order( $order ) { public function can_refund_order( $order ) {
@ -275,7 +301,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
* Init the API class and set the username/password etc. * Init the API class and set the username/password etc.
*/ */
protected function init_api() { protected function init_api() {
include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-paypal-api-handler.php' ); include_once dirname( __FILE__ ) . '/includes/class-wc-gateway-paypal-api-handler.php';
WC_Gateway_Paypal_API_Handler::$api_username = $this->testmode ? $this->get_option( 'sandbox_api_username' ) : $this->get_option( 'api_username' ); WC_Gateway_Paypal_API_Handler::$api_username = $this->testmode ? $this->get_option( 'sandbox_api_username' ) : $this->get_option( 'api_username' );
WC_Gateway_Paypal_API_Handler::$api_password = $this->testmode ? $this->get_option( 'sandbox_api_password' ) : $this->get_option( 'api_password' ); WC_Gateway_Paypal_API_Handler::$api_password = $this->testmode ? $this->get_option( 'sandbox_api_password' ) : $this->get_option( 'api_password' );
@ -285,9 +311,10 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
/** /**
* Process a refund if supported. * Process a refund if supported.
* @param int $order_id *
* @param float $amount * @param int $order_id Order ID.
* @param string $reason * @param float $amount Refund amount.
* @param string $reason Refund reason.
* @return bool|WP_Error * @return bool|WP_Error
*/ */
public function process_refund( $order_id, $amount = null, $reason = '' ) { public function process_refund( $order_id, $amount = null, $reason = '' ) {
@ -309,21 +336,23 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
$this->log( 'Refund Result: ' . wc_print_r( $result, true ) ); $this->log( 'Refund Result: ' . wc_print_r( $result, true ) );
switch ( strtolower( $result->ACK ) ) { switch ( strtolower( $result->ACK ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
case 'success': case 'success':
case 'successwithwarning': case 'successwithwarning':
$order->add_order_note( sprintf( __( 'Refunded %1$s - Refund ID: %2$s', 'woocommerce' ), $result->GROSSREFUNDAMT, $result->REFUNDTRANSACTIONID ) ); $order->add_order_note(
/* translators: 1: Refund amount, 2: Refund ID */
sprintf( __( 'Refunded %1$s - Refund ID: %2$s', 'woocommerce' ), $result->GROSSREFUNDAMT, $result->REFUNDTRANSACTIONID ) // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
);
return true; return true;
break;
} }
return isset( $result->L_LONGMESSAGE0 ) ? new WP_Error( 'error', $result->L_LONGMESSAGE0 ) : false; return isset( $result->L_LONGMESSAGE0 ) ? new WP_Error( 'error', $result->L_LONGMESSAGE0 ) : false; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
} }
/** /**
* Capture payment when the order is changed from on-hold to complete or processing * Capture payment when the order is changed from on-hold to complete or processing
* *
* @param int $order_id * @param int $order_id Order ID.
*/ */
public function capture_payment( $order_id ) { public function capture_payment( $order_id ) {
$order = wc_get_order( $order_id ); $order = wc_get_order( $order_id );
@ -334,24 +363,29 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
if ( is_wp_error( $result ) ) { if ( is_wp_error( $result ) ) {
$this->log( 'Capture Failed: ' . $result->get_error_message(), 'error' ); $this->log( 'Capture Failed: ' . $result->get_error_message(), 'error' );
/* translators: %s: Paypal gateway error message */
$order->add_order_note( sprintf( __( 'Payment could not captured: %s', 'woocommerce' ), $result->get_error_message() ) ); $order->add_order_note( sprintf( __( 'Payment could not captured: %s', 'woocommerce' ), $result->get_error_message() ) );
return; return;
} }
$this->log( 'Capture Result: ' . wc_print_r( $result, true ) ); $this->log( 'Capture Result: ' . wc_print_r( $result, true ) );
// phpcs:disable WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
if ( ! empty( $result->PAYMENTSTATUS ) ) { if ( ! empty( $result->PAYMENTSTATUS ) ) {
switch ( $result->PAYMENTSTATUS ) { switch ( $result->PAYMENTSTATUS ) {
case 'Completed' : case 'Completed':
/* translators: 1: Amount, 2: Authorization ID, 3: Transaction ID */
$order->add_order_note( sprintf( __( 'Payment of %1$s was captured - Auth ID: %2$s, Transaction ID: %3$s', 'woocommerce' ), $result->AMT, $result->AUTHORIZATIONID, $result->TRANSACTIONID ) ); $order->add_order_note( sprintf( __( 'Payment of %1$s was captured - Auth ID: %2$s, Transaction ID: %3$s', 'woocommerce' ), $result->AMT, $result->AUTHORIZATIONID, $result->TRANSACTIONID ) );
update_post_meta( $order->get_id(), '_paypal_status', $result->PAYMENTSTATUS ); update_post_meta( $order->get_id(), '_paypal_status', $result->PAYMENTSTATUS );
update_post_meta( $order->get_id(), '_transaction_id', $result->TRANSACTIONID ); update_post_meta( $order->get_id(), '_transaction_id', $result->TRANSACTIONID );
break; break;
default : default:
/* translators: 1: Authorization ID, 2: Payment status */
$order->add_order_note( sprintf( __( 'Payment could not captured - Auth ID: %1$s, Status: %2$s', 'woocommerce' ), $result->AUTHORIZATIONID, $result->PAYMENTSTATUS ) ); $order->add_order_note( sprintf( __( 'Payment could not captured - Auth ID: %1$s, Status: %2$s', 'woocommerce' ), $result->AUTHORIZATIONID, $result->PAYMENTSTATUS ) );
break; break;
} }
} }
// phpcs:enable
} }
} }
@ -362,7 +396,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
*/ */
public function admin_scripts() { public function admin_scripts() {
$screen = get_current_screen(); $screen = get_current_screen();
$screen_id = $screen ? $screen->id: ''; $screen_id = $screen ? $screen->id : '';
if ( 'woocommerce_page_wc-settings' !== $screen_id ) { if ( 'woocommerce_page_wc-settings' !== $screen_id ) {
return; return;

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* Class WC_Gateway_Paypal_API_Handler file.
*
* @package WooCommerce\Gateways
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
@ -6,27 +11,45 @@ if ( ! defined( 'ABSPATH' ) ) {
/** /**
* Handles Refunds and other API requests such as capture. * Handles Refunds and other API requests such as capture.
*
* @since 3.0.0 * @since 3.0.0
*/ */
class WC_Gateway_Paypal_API_Handler { class WC_Gateway_Paypal_API_Handler {
/** @var string API Username */ /**
* API Username
*
* @var string
*/
public static $api_username; public static $api_username;
/** @var string API Password */ /**
* API Password
*
* @var string
*/
public static $api_password; public static $api_password;
/** @var string API Signature */ /**
* API Signature
*
* @var string
*/
public static $api_signature; public static $api_signature;
/** @var bool Sandbox */ /**
* Sandbox
*
* @var bool
*/
public static $sandbox = false; public static $sandbox = false;
/** /**
* Get capture request args. * Get capture request args.
* See https://developer.paypal.com/docs/classic/api/merchant/DoCapture_API_Operation_NVP/. * See https://developer.paypal.com/docs/classic/api/merchant/DoCapture_API_Operation_NVP/.
* @param WC_Order $order *
* @param float $amount * @param WC_Order $order Order object.
* @param float $amount Amount.
* @return array * @return array
*/ */
public static function get_capture_request( $order, $amount = null ) { public static function get_capture_request( $order, $amount = null ) {
@ -46,9 +69,10 @@ class WC_Gateway_Paypal_API_Handler {
/** /**
* Get refund request args. * Get refund request args.
* @param WC_Order $order *
* @param float $amount * @param WC_Order $order Order object.
* @param string $reason * @param float $amount Refund amount.
* @param string $reason Refund reason.
* @return array * @return array
*/ */
public static function get_refund_request( $order, $amount = null, $reason = '' ) { public static function get_refund_request( $order, $amount = null, $reason = '' ) {
@ -72,8 +96,9 @@ class WC_Gateway_Paypal_API_Handler {
/** /**
* Capture an authorization. * Capture an authorization.
* @param WC_Order $order *
* @param float $amount * @param WC_Order $order Order object.
* @param float $amount Amount.
* @return object Either an object of name value pairs for a success, or a WP_ERROR object. * @return object Either an object of name value pairs for a success, or a WP_ERROR object.
*/ */
public static function do_capture( $order, $amount = null ) { public static function do_capture( $order, $amount = null ) {
@ -103,9 +128,10 @@ class WC_Gateway_Paypal_API_Handler {
/** /**
* Refund an order via PayPal. * Refund an order via PayPal.
* @param WC_Order $order *
* @param float $amount * @param WC_Order $order Order object.
* @param string $reason * @param float $amount Refund amount.
* @param string $reason Refund reason.
* @return object Either an object of name value pairs for a success, or a WP_ERROR object. * @return object Either an object of name value pairs for a success, or a WP_ERROR object.
*/ */
public static function refund_transaction( $order, $amount = null, $reason = '' ) { public static function refund_transaction( $order, $amount = null, $reason = '' ) {
@ -136,12 +162,32 @@ class WC_Gateway_Paypal_API_Handler {
/** /**
* Here for backwards compatibility. * Here for backwards compatibility.
*
* @since 3.0.0 * @since 3.0.0
*/ */
class WC_Gateway_Paypal_Refund extends WC_Gateway_Paypal_API_Handler { class WC_Gateway_Paypal_Refund extends WC_Gateway_Paypal_API_Handler {
/**
* Get refund request args. Proxy to WC_Gateway_Paypal_API_Handler::get_refund_request().
*
* @param WC_Order $order Order object.
* @param float $amount Refund amount.
* @param string $reason Refund reason.
*
* @return array
*/
public static function get_request( $order, $amount = null, $reason = '' ) { public static function get_request( $order, $amount = null, $reason = '' ) {
return self::get_refund_request( $order, $amount, $reason ); return self::get_refund_request( $order, $amount, $reason );
} }
/**
* Process an order refund.
*
* @param WC_Order $order Order object.
* @param float $amount Refund amount.
* @param string $reason Refund reason.
* @param bool $sandbox Whether to use sandbox mode or not.
* @return object Either an object of name value pairs for a success, or a WP_ERROR object.
*/
public static function refund_order( $order, $amount = null, $reason = '', $sandbox = false ) { public static function refund_order( $order, $amount = null, $reason = '', $sandbox = false ) {
if ( $sandbox ) { if ( $sandbox ) {
self::$sandbox = $sandbox; self::$sandbox = $sandbox;

View File

@ -1,24 +1,33 @@
<?php <?php
/**
* Class WC_Gateway_Paypal_PDT_Handler file.
*
* @package WooCommerce\Gateways
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
include_once( dirname( __FILE__ ) . '/class-wc-gateway-paypal-response.php' ); require_once dirname( __FILE__ ) . '/class-wc-gateway-paypal-response.php';
/** /**
* Handle PDT Responses from PayPal. * Handle PDT Responses from PayPal.
*/ */
class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response { class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response {
/** @var string identity_token for PDT support */ /**
* Identity token for PDT support
*
* @var string
*/
protected $identity_token; protected $identity_token;
/** /**
* Constructor. * Constructor.
* *
* @param bool $sandbox * @param bool $sandbox Whether to use sandbox mode or not.
* @param string $identity_token * @param string $identity_token Identity token for PDT support.
*/ */
public function __construct( $sandbox = false, $identity_token = '' ) { public function __construct( $sandbox = false, $identity_token = '' ) {
add_action( 'woocommerce_thankyou_paypal', array( $this, 'check_response' ) ); add_action( 'woocommerce_thankyou_paypal', array( $this, 'check_response' ) );
@ -48,7 +57,7 @@ class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response {
// Post back to get a response. // Post back to get a response.
$response = wp_safe_remote_post( $this->sandbox ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $pdt ); $response = wp_safe_remote_post( $this->sandbox ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $pdt );
if ( is_wp_error( $response ) || strpos( $response['body'], "SUCCESS" ) !== 0 ) { if ( is_wp_error( $response ) || strpos( $response['body'], 'SUCCESS' ) !== 0 ) {
return false; return false;
} }
@ -57,7 +66,7 @@ class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response {
$transaction_results = array(); $transaction_results = array();
foreach ( $transaction_result as $line ) { foreach ( $transaction_result as $line ) {
$line = explode( "=", $line ); $line = explode( '=', $line );
$transaction_results[ $line[0] ] = isset( $line[1] ) ? $line[1] : ''; $transaction_results[ $line[0] ] = isset( $line[1] ) ? $line[1] : '';
} }
@ -78,12 +87,14 @@ class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response {
return; return;
} }
$order_id = wc_clean( stripslashes( $_REQUEST['cm'] ) ); $order_id = wc_clean( wp_unslash( $_REQUEST['cm'] ) );
$status = wc_clean( strtolower( stripslashes( $_REQUEST['st'] ) ) ); $status = wc_clean( strtolower( wp_unslash( $_REQUEST['st'] ) ) ); // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized
$amount = wc_clean( stripslashes( $_REQUEST['amt'] ) ); $amount = wc_clean( wp_unslash( $_REQUEST['amt'] ) ); // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput.InputNotValidated
$transaction = wc_clean( stripslashes( $_REQUEST['tx'] ) ); $transaction = wc_clean( wp_unslash( $_REQUEST['tx'] ) );
if ( ! ( $order = $this->get_paypal_order( $order_id ) ) || ! $order->has_status( 'pending' ) ) { $order = $this->get_paypal_order( $order_id );
if ( ! $order || ! $order->has_status( 'pending' ) ) {
return false; return false;
} }
@ -96,8 +107,9 @@ class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response {
update_post_meta( $order->get_id(), '_transaction_id', $transaction ); update_post_meta( $order->get_id(), '_transaction_id', $transaction );
if ( 'completed' === $status ) { if ( 'completed' === $status ) {
if ( $order->get_total() != $amount ) { if ( $order->get_total() !== $amount ) {
WC_Gateway_Paypal::log( 'Payment error: Amounts do not match (amt ' . $amount . ')', 'error' ); WC_Gateway_Paypal::log( 'Payment error: Amounts do not match (amt ' . $amount . ')', 'error' );
/* translators: 1: Payment amount */
$this->payment_on_hold( $order, sprintf( __( 'Validation error: PayPal amounts do not match (amt %s).', 'woocommerce' ), $amount ) ); $this->payment_on_hold( $order, sprintf( __( 'Validation error: PayPal amounts do not match (amt %s).', 'woocommerce' ), $amount ) );
} else { } else {
$this->payment_complete( $order, $transaction, __( 'PDT payment completed', 'woocommerce' ) ); $this->payment_complete( $order, $transaction, __( 'PDT payment completed', 'woocommerce' ) );
@ -123,6 +135,7 @@ class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response {
if ( 'authorization' === $transaction_result['pending_reason'] ) { if ( 'authorization' === $transaction_result['pending_reason'] ) {
$this->payment_on_hold( $order, __( 'Payment authorized. Change payment status to processing or complete to capture funds.', 'woocommerce' ) ); $this->payment_on_hold( $order, __( 'Payment authorized. Change payment status to processing or complete to capture funds.', 'woocommerce' ) );
} else { } else {
/* translators: 1: Pending reason */
$this->payment_on_hold( $order, sprintf( __( 'Payment pending (%s).', 'woocommerce' ), $transaction_result['pending_reason'] ) ); $this->payment_on_hold( $order, sprintf( __( 'Payment pending (%s).', 'woocommerce' ), $transaction_result['pending_reason'] ) );
} }
} }

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* Class WC_Gateway_Paypal_Request file.
*
* @package WooCommerce\Gateways
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
@ -11,25 +16,29 @@ class WC_Gateway_Paypal_Request {
/** /**
* Stores line items to send to PayPal. * Stores line items to send to PayPal.
*
* @var array * @var array
*/ */
protected $line_items = array(); protected $line_items = array();
/** /**
* Pointer to gateway making the request. * Pointer to gateway making the request.
*
* @var WC_Gateway_Paypal * @var WC_Gateway_Paypal
*/ */
protected $gateway; protected $gateway;
/** /**
* Endpoint for requests from PayPal. * Endpoint for requests from PayPal.
*
* @var string * @var string
*/ */
protected $notify_url; protected $notify_url;
/** /**
* Constructor. * Constructor.
* @param WC_Gateway_Paypal $gateway *
* @param WC_Gateway_Paypal $gateway Paypal gateway object.
*/ */
public function __construct( $gateway ) { public function __construct( $gateway ) {
$this->gateway = $gateway; $this->gateway = $gateway;
@ -38,8 +47,9 @@ class WC_Gateway_Paypal_Request {
/** /**
* Get the PayPal request URL for an order. * Get the PayPal request URL for an order.
* @param WC_Order $order *
* @param bool $sandbox * @param WC_Order $order Order object.
* @param bool $sandbox Whether to use sandbox mode or not.
* @return string * @return string
*/ */
public function get_request_url( $order, $sandbox = false ) { public function get_request_url( $order, $sandbox = false ) {
@ -57,8 +67,8 @@ class WC_Gateway_Paypal_Request {
/** /**
* Limit length of an arg. * Limit length of an arg.
* *
* @param string $string * @param string $string Argument to limit.
* @param integer $limit * @param integer $limit Limit size in characters.
* @return string * @return string
*/ */
protected function limit_length( $string, $limit = 127 ) { protected function limit_length( $string, $limit = 127 ) {
@ -70,13 +80,15 @@ class WC_Gateway_Paypal_Request {
/** /**
* Get PayPal Args for passing to PP. * Get PayPal Args for passing to PP.
* @param WC_Order $order *
* @param WC_Order $order Order object.
* @return array * @return array
*/ */
protected function get_paypal_args( $order ) { protected function get_paypal_args( $order ) {
WC_Gateway_Paypal::log( 'Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url ); WC_Gateway_Paypal::log( 'Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url );
return apply_filters( 'woocommerce_paypal_args', array_merge( return apply_filters(
'woocommerce_paypal_args', array_merge(
array( array(
'cmd' => '_cart', 'cmd' => '_cart',
'business' => $this->gateway->get_option( 'email' ), 'business' => $this->gateway->get_option( 'email' ),
@ -92,7 +104,12 @@ class WC_Gateway_Paypal_Request {
'paymentaction' => $this->gateway->get_option( 'paymentaction' ), 'paymentaction' => $this->gateway->get_option( 'paymentaction' ),
'bn' => 'WooThemes_Cart', 'bn' => 'WooThemes_Cart',
'invoice' => $this->limit_length( $this->gateway->get_option( 'invoice_prefix' ) . $order->get_order_number(), 127 ), 'invoice' => $this->limit_length( $this->gateway->get_option( 'invoice_prefix' ) . $order->get_order_number(), 127 ),
'custom' => json_encode( array( 'order_id' => $order->get_id(), 'order_key' => $order->get_order_key() ) ), 'custom' => wp_json_encode(
array(
'order_id' => $order->get_id(),
'order_key' => $order->get_order_key(),
)
),
'notify_url' => $this->limit_length( $this->notify_url, 255 ), 'notify_url' => $this->limit_length( $this->notify_url, 255 ),
'first_name' => $this->limit_length( $order->get_billing_first_name(), 32 ), 'first_name' => $this->limit_length( $order->get_billing_first_name(), 32 ),
'last_name' => $this->limit_length( $order->get_billing_last_name(), 64 ), 'last_name' => $this->limit_length( $order->get_billing_last_name(), 64 ),
@ -107,16 +124,18 @@ class WC_Gateway_Paypal_Request {
$this->get_phone_number_args( $order ), $this->get_phone_number_args( $order ),
$this->get_shipping_args( $order ), $this->get_shipping_args( $order ),
$this->get_line_item_args( $order ) $this->get_line_item_args( $order )
), $order ); ), $order
);
} }
/** /**
* Get phone number args for paypal request. * Get phone number args for paypal request.
* @param WC_Order $order *
* @param WC_Order $order Order object.
* @return array * @return array
*/ */
protected function get_phone_number_args( $order ) { protected function get_phone_number_args( $order ) {
if ( in_array( $order->get_billing_country(), array( 'US', 'CA' ) ) ) { if ( in_array( $order->get_billing_country(), array( 'US', 'CA' ), true ) ) {
$phone_number = str_replace( array( '(', '-', ' ', ')', '.' ), '', $order->get_billing_phone() ); $phone_number = str_replace( array( '(', '-', ' ', ')', '.' ), '', $order->get_billing_phone() );
$phone_number = ltrim( $phone_number, '+1' ); $phone_number = ltrim( $phone_number, '+1' );
$phone_args = array( $phone_args = array(
@ -134,17 +153,18 @@ class WC_Gateway_Paypal_Request {
/** /**
* Get shipping args for paypal request. * Get shipping args for paypal request.
* @param WC_Order $order *
* @param WC_Order $order Order object.
* @return array * @return array
*/ */
protected function get_shipping_args( $order ) { protected function get_shipping_args( $order ) {
$shipping_args = array(); $shipping_args = array();
if ( 'yes' == $this->gateway->get_option( 'send_shipping' ) ) { if ( 'yes' === $this->gateway->get_option( 'send_shipping' ) ) {
$shipping_args['address_override'] = $this->gateway->get_option( 'address_override' ) === 'yes' ? 1 : 0; $shipping_args['address_override'] = $this->gateway->get_option( 'address_override' ) === 'yes' ? 1 : 0;
$shipping_args['no_shipping'] = 0; $shipping_args['no_shipping'] = 0;
// If we are sending shipping, send shipping address instead of billing // If we are sending shipping, send shipping address instead of billing.
$shipping_args['first_name'] = $this->limit_length( $order->get_shipping_first_name(), 32 ); $shipping_args['first_name'] = $this->limit_length( $order->get_shipping_first_name(), 32 );
$shipping_args['last_name'] = $this->limit_length( $order->get_shipping_last_name(), 64 ); $shipping_args['last_name'] = $this->limit_length( $order->get_shipping_last_name(), 64 );
$shipping_args['address1'] = $this->limit_length( $order->get_shipping_address_1(), 100 ); $shipping_args['address1'] = $this->limit_length( $order->get_shipping_address_1(), 100 );
@ -162,7 +182,8 @@ class WC_Gateway_Paypal_Request {
/** /**
* Get line item args for paypal request. * Get line item args for paypal request.
* @param WC_Order $order *
* @param WC_Order $order Order object.
* @return array * @return array
*/ */
protected function get_line_item_args( $order ) { protected function get_line_item_args( $order ) {
@ -185,17 +206,17 @@ class WC_Gateway_Paypal_Request {
if ( $order->get_shipping_total() > 0 && $order->get_shipping_total() < 999.99 && $this->number_format( $order->get_shipping_total() + $order->get_shipping_tax(), $order ) !== $this->number_format( $order->get_total(), $order ) ) { if ( $order->get_shipping_total() > 0 && $order->get_shipping_total() < 999.99 && $this->number_format( $order->get_shipping_total() + $order->get_shipping_tax(), $order ) !== $this->number_format( $order->get_total(), $order ) ) {
$line_item_args['shipping_1'] = $this->number_format( $order->get_shipping_total(), $order ); $line_item_args['shipping_1'] = $this->number_format( $order->get_shipping_total(), $order );
} elseif ( $order->get_shipping_total() > 0 ) { } elseif ( $order->get_shipping_total() > 0 ) {
/* translators: %s: Order shipping method */
$this->add_line_item( sprintf( __( 'Shipping via %s', 'woocommerce' ), $order->get_shipping_method() ), 1, $this->number_format( $order->get_shipping_total(), $order ) ); $this->add_line_item( sprintf( __( 'Shipping via %s', 'woocommerce' ), $order->get_shipping_method() ), 1, $this->number_format( $order->get_shipping_total(), $order ) );
} }
$line_item_args = array_merge( $line_item_args, $this->get_line_items() ); $line_item_args = array_merge( $line_item_args, $this->get_line_items() );
} else {
/** /**
* Send order as a single item. * Send order as a single item.
* *
* For shipping, we longer use shipping_1 because paypal ignores it if *any* shipping rules are within paypal, and paypal ignores anything over 5 digits (999.99 is the max). * For shipping, we longer use shipping_1 because paypal ignores it if *any* shipping rules are within paypal, and paypal ignores anything over 5 digits (999.99 is the max).
*/ */
} else {
$this->delete_line_items(); $this->delete_line_items();
@ -209,6 +230,7 @@ class WC_Gateway_Paypal_Request {
if ( $order->get_shipping_total() > 0 && $order->get_shipping_total() < 999.99 && $this->number_format( $order->get_shipping_total() + $order->get_shipping_tax(), $order ) !== $this->number_format( $order->get_total(), $order ) ) { if ( $order->get_shipping_total() > 0 && $order->get_shipping_total() < 999.99 && $this->number_format( $order->get_shipping_total() + $order->get_shipping_tax(), $order ) !== $this->number_format( $order->get_total(), $order ) ) {
$line_item_args['shipping_1'] = $this->number_format( $order->get_shipping_total() + $order->get_shipping_tax(), $order ); $line_item_args['shipping_1'] = $this->number_format( $order->get_shipping_total() + $order->get_shipping_tax(), $order );
} elseif ( $order->get_shipping_total() > 0 ) { } elseif ( $order->get_shipping_total() > 0 ) {
/* translators: %s: Order shipping method */
$this->add_line_item( sprintf( __( 'Shipping via %s', 'woocommerce' ), $order->get_shipping_method() ), 1, $this->number_format( $order->get_shipping_total() + $order->get_shipping_tax(), $order ) ); $this->add_line_item( sprintf( __( 'Shipping via %s', 'woocommerce' ), $order->get_shipping_method() ), 1, $this->number_format( $order->get_shipping_total() + $order->get_shipping_tax(), $order ) );
} }
@ -220,7 +242,8 @@ class WC_Gateway_Paypal_Request {
/** /**
* Get order item names as a string. * Get order item names as a string.
* @param WC_Order $order *
* @param WC_Order $order Order object.
* @return string * @return string
*/ */
protected function get_order_item_names( $order ) { protected function get_order_item_names( $order ) {
@ -228,13 +251,17 @@ class WC_Gateway_Paypal_Request {
foreach ( $order->get_items() as $item ) { foreach ( $order->get_items() as $item ) {
$item_name = $item->get_name(); $item_name = $item->get_name();
$item_meta = strip_tags( wc_display_item_meta( $item, array( $item_meta = strip_tags(
'before' => "", wc_display_item_meta(
'separator' => ", ", $item, array(
'after' => "", 'before' => '',
'separator' => ', ',
'after' => '',
'echo' => false, 'echo' => false,
'autop' => false, 'autop' => false,
) ) ); )
)
);
if ( $item_meta ) { if ( $item_meta ) {
$item_name .= ' (' . $item_meta . ')'; $item_name .= ' (' . $item_meta . ')';
@ -248,19 +275,24 @@ class WC_Gateway_Paypal_Request {
/** /**
* Get order item names as a string. * Get order item names as a string.
* @param WC_Order $order *
* @param array $item * @param WC_Order $order Order object.
* @param WC_Order_Item $item Order item object.
* @return string * @return string
*/ */
protected function get_order_item_name( $order, $item ) { protected function get_order_item_name( $order, $item ) {
$item_name = $item->get_name(); $item_name = $item->get_name();
$item_meta = strip_tags( wc_display_item_meta( $item, array( $item_meta = strip_tags(
'before' => "", wc_display_item_meta(
'separator' => ", ", $item, array(
'after' => "", 'before' => '',
'separator' => ', ',
'after' => '',
'echo' => false, 'echo' => false,
'autop' => false, 'autop' => false,
) ) ); )
)
);
if ( $item_meta ) { if ( $item_meta ) {
$item_name .= ' (' . $item_meta . ')'; $item_name .= ' (' . $item_meta . ')';
@ -285,14 +317,15 @@ class WC_Gateway_Paypal_Request {
/** /**
* Get line items to send to paypal. * Get line items to send to paypal.
* @param WC_Order $order *
* @param WC_Order $order Order object.
* @return bool * @return bool
*/ */
protected function prepare_line_items( $order ) { protected function prepare_line_items( $order ) {
$this->delete_line_items(); $this->delete_line_items();
$calculated_total = 0; $calculated_total = 0;
// Products // Products.
foreach ( $order->get_items( array( 'line_item', 'fee' ) ) as $item ) { foreach ( $order->get_items( array( 'line_item', 'fee' ) ) as $item ) {
if ( 'fee' === $item['type'] ) { if ( 'fee' === $item['type'] ) {
$item_line_total = $this->number_format( $item['line_total'], $order ); $item_line_total = $this->number_format( $item['line_total'], $order );
@ -312,7 +345,7 @@ class WC_Gateway_Paypal_Request {
} }
// Check for mismatched totals. // Check for mismatched totals.
if ( $this->number_format( $calculated_total + $order->get_total_tax() + $this->round( $order->get_shipping_total(), $order ) - $this->round( $order->get_total_discount(), $order ), $order ) != $this->number_format( $order->get_total(), $order ) ) { if ( $this->number_format( $calculated_total + $order->get_total_tax() + $this->round( $order->get_shipping_total(), $order ) - $this->round( $order->get_total_discount(), $order ), $order ) !== $this->number_format( $order->get_total(), $order ) ) {
return false; return false;
} }
@ -321,25 +354,28 @@ class WC_Gateway_Paypal_Request {
/** /**
* Add PayPal Line Item. * Add PayPal Line Item.
* @param string $item_name *
* @param int $quantity * @param string $item_name Item name.
* @param float $amount * @param int $quantity Item quantity.
* @param string $item_number * @param float $amount Amount.
* @param string $item_number Item number.
* @return bool successfully added or not * @return bool successfully added or not
*/ */
protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
$index = ( sizeof( $this->line_items ) / 4 ) + 1; $index = ( count( $this->line_items ) / 4 ) + 1;
if ( $amount < 0 || $index > 9 ) { if ( $amount < 0 || $index > 9 ) {
return false; return false;
} }
$item = apply_filters( 'woocommerce_paypal_line_item', array( $item = apply_filters(
'woocommerce_paypal_line_item', array(
'item_name' => html_entity_decode( wc_trim_string( $item_name ? $item_name : __( 'Item', 'woocommerce' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), 'item_name' => html_entity_decode( wc_trim_string( $item_name ? $item_name : __( 'Item', 'woocommerce' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
'quantity' => (int) $quantity, 'quantity' => (int) $quantity,
'amount' => wc_float_to_string( (float) $amount ), 'amount' => wc_float_to_string( (float) $amount ),
'item_number' => $item_number, 'item_number' => $item_number,
), $item_name, $quantity, $amount, $item_number ); ), $item_name, $quantity, $amount, $item_number
);
$this->line_items[ 'item_name_' . $index ] = $this->limit_length( $item['item_name'], 127 ); $this->line_items[ 'item_name_' . $index ] = $this->limit_length( $item['item_name'], 127 );
$this->line_items[ 'quantity_' . $index ] = $item['quantity']; $this->line_items[ 'quantity_' . $index ] = $item['quantity'];
@ -351,8 +387,9 @@ class WC_Gateway_Paypal_Request {
/** /**
* Get the state to send to paypal. * Get the state to send to paypal.
* @param string $cc *
* @param string $state * @param string $cc Country two letter code.
* @param string $state State code.
* @return string * @return string
*/ */
protected function get_paypal_state( $cc, $state ) { protected function get_paypal_state( $cc, $state ) {
@ -371,11 +408,12 @@ class WC_Gateway_Paypal_Request {
/** /**
* Check if currency has decimals. * Check if currency has decimals.
* @param string $currency *
* @param string $currency Currency to check.
* @return bool * @return bool
*/ */
protected function currency_has_decimals( $currency ) { protected function currency_has_decimals( $currency ) {
if ( in_array( $currency, array( 'HUF', 'JPY', 'TWD' ) ) ) { if ( in_array( $currency, array( 'HUF', 'JPY', 'TWD' ), true ) ) {
return false; return false;
} }
@ -384,8 +422,9 @@ class WC_Gateway_Paypal_Request {
/** /**
* Round prices. * Round prices.
* @param double $price *
* @param WC_Order $order * @param double $price Price to round.
* @param WC_Order $order Order object.
* @return double * @return double
*/ */
protected function round( $price, $order ) { protected function round( $price, $order ) {
@ -400,8 +439,9 @@ class WC_Gateway_Paypal_Request {
/** /**
* Format prices. * Format prices.
* @param float|int $price *
* @param WC_Order $order * @param float|int $price Price to format.
* @param WC_Order $order Order object.
* @return string * @return string
*/ */
protected function number_format( $price, $order ) { protected function number_format( $price, $order ) {

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* Class WC_Gateway_Paypal_Response file.
*
* @package WooCommerce\Gateways
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
@ -9,27 +14,34 @@ if ( ! defined( 'ABSPATH' ) ) {
*/ */
abstract class WC_Gateway_Paypal_Response { abstract class WC_Gateway_Paypal_Response {
/** @var bool Sandbox mode */ /**
* Sandbox mode
*
* @var bool
*/
protected $sandbox = false; protected $sandbox = false;
/** /**
* Get the order from the PayPal 'Custom' variable. * Get the order from the PayPal 'Custom' variable.
* @param string $raw_custom JSON Data passed back by PayPal *
* @param string $raw_custom JSON Data passed back by PayPal.
* @return bool|WC_Order object * @return bool|WC_Order object
*/ */
protected function get_paypal_order( $raw_custom ) { protected function get_paypal_order( $raw_custom ) {
// We have the data in the correct format, so get the order. // We have the data in the correct format, so get the order.
if ( ( $custom = json_decode( $raw_custom ) ) && is_object( $custom ) ) { $custom = wp_json_decode( $raw_custom );
if ( $custom && is_object( $custom ) ) {
$order_id = $custom->order_id; $order_id = $custom->order_id;
$order_key = $custom->order_key; $order_key = $custom->order_key;
// Nothing was found.
} else { } else {
// Nothing was found.
WC_Gateway_Paypal::log( 'Order ID and key were not found in "custom".', 'error' ); WC_Gateway_Paypal::log( 'Order ID and key were not found in "custom".', 'error' );
return false; return false;
} }
if ( ! $order = wc_get_order( $order_id ) ) { $order = wc_get_order( $order_id );
if ( ! $order ) {
// We have an invalid $order_id, probably because invoice_prefix has changed. // We have an invalid $order_id, probably because invoice_prefix has changed.
$order_id = wc_get_order_id_by_order_key( $order_key ); $order_id = wc_get_order_id_by_order_key( $order_key );
$order = wc_get_order( $order_id ); $order = wc_get_order( $order_id );
@ -45,9 +57,10 @@ abstract class WC_Gateway_Paypal_Response {
/** /**
* Complete order, add transaction ID and note. * Complete order, add transaction ID and note.
* @param WC_Order $order *
* @param string $txn_id * @param WC_Order $order Order object.
* @param string $note * @param string $txn_id Transaction ID.
* @param string $note Payment note.
*/ */
protected function payment_complete( $order, $txn_id = '', $note = '' ) { protected function payment_complete( $order, $txn_id = '', $note = '' ) {
$order->add_order_note( $note ); $order->add_order_note( $note );
@ -56,8 +69,9 @@ abstract class WC_Gateway_Paypal_Response {
/** /**
* Hold order and add note. * Hold order and add note.
* @param WC_Order $order *
* @param string $reason * @param WC_Order $order Order object.
* @param string $reason Reason why the payment is on hold.
*/ */
protected function payment_on_hold( $order, $reason = '' ) { protected function payment_on_hold( $order, $reason = '' ) {
$order->update_status( 'on-hold', $reason ); $order->update_status( 'on-hold', $reason );

View File

@ -101,12 +101,14 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
} }
// Create customer // Create customer
$customer = Simplify_Customer::createCustomer( array( $customer = Simplify_Customer::createCustomer(
array(
'token' => $cart_token, 'token' => $cart_token,
'email' => $order->get_billing_email(), 'email' => $order->get_billing_email(),
'name' => trim( $order->get_formatted_billing_full_name() ), 'name' => trim( $order->get_formatted_billing_full_name() ),
'reference' => $order->get_id(), 'reference' => $order->get_id(),
) ); )
);
if ( is_object( $customer ) && '' != $customer->id ) { if ( is_object( $customer ) && '' != $customer->id ) {
$this->save_subscription_meta( $order->get_id(), $customer->id ); $this->save_subscription_meta( $order->get_id(), $customer->id );
@ -194,12 +196,14 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
} }
// Create customer // Create customer
$customer = Simplify_Customer::createCustomer( array( $customer = Simplify_Customer::createCustomer(
array(
'token' => $cart_token, 'token' => $cart_token,
'email' => $order->get_billing_email(), 'email' => $order->get_billing_email(),
'name' => trim( $order->get_formatted_billing_full_name() ), 'name' => trim( $order->get_formatted_billing_full_name() ),
'reference' => $order->get_id(), 'reference' => $order->get_id(),
) ); )
);
if ( is_object( $customer ) && '' != $customer->id ) { if ( is_object( $customer ) && '' != $customer->id ) {
$customer_id = wc_clean( $customer->id ); $customer_id = wc_clean( $customer->id );
@ -241,7 +245,6 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
'redirect' => '', 'redirect' => '',
); );
} }
} else { } else {
return parent::process_standard_payments( $order, $cart_token ); return parent::process_standard_payments( $order, $cart_token );
} }
@ -261,12 +264,11 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
if ( 'standard' == $this->mode && ( $this->order_contains_subscription( $order->get_id() ) || ( function_exists( 'wcs_is_subscription' ) && wcs_is_subscription( $order_id ) ) ) ) { if ( 'standard' == $this->mode && ( $this->order_contains_subscription( $order->get_id() ) || ( function_exists( 'wcs_is_subscription' ) && wcs_is_subscription( $order_id ) ) ) ) {
return $this->process_subscription( $order, $cart_token ); return $this->process_subscription( $order, $cart_token );
// Processing pre-order
} elseif ( 'standard' == $this->mode && $this->order_contains_pre_order( $order->get_id() ) ) { } elseif ( 'standard' == $this->mode && $this->order_contains_pre_order( $order->get_id() ) ) {
// Processing pre-order.
return $this->process_pre_order( $order, $cart_token ); return $this->process_pre_order( $order, $cart_token );
// Processing regular product
} else { } else {
// Processing regular product.
return parent::process_payment( $order_id ); return parent::process_payment( $order_id );
} }
} }
@ -299,13 +301,15 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
try { try {
// Charge the customer // Charge the customer
$payment = Simplify_Payment::createPayment( array( $payment = Simplify_Payment::createPayment(
array(
'amount' => $amount * 100, // In cents. 'amount' => $amount * 100, // In cents.
'customer' => $customer_id, 'customer' => $customer_id,
'description' => sprintf( __( '%1$s - Order #%2$s', 'woocommerce' ), esc_html( get_bloginfo( 'name', 'display' ) ), $order->get_order_number() ), 'description' => sprintf( __( '%1$s - Order #%2$s', 'woocommerce' ), esc_html( get_bloginfo( 'name', 'display' ) ), $order->get_order_number() ),
'currency' => strtoupper( get_woocommerce_currency() ), 'currency' => strtoupper( get_woocommerce_currency() ),
'reference' => $order->get_id(), 'reference' => $order->get_id(),
) ); )
);
} catch ( Exception $e ) { } catch ( Exception $e ) {
@ -440,13 +444,15 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
} }
// Charge the customer // Charge the customer
$payment = Simplify_Payment::createPayment( array( $payment = Simplify_Payment::createPayment(
array(
'amount' => $order->get_total() * 100, // In cents. 'amount' => $order->get_total() * 100, // In cents.
'customer' => $customer_id, 'customer' => $customer_id,
'description' => trim( substr( $pre_order_name, 0, 1024 ) ), 'description' => trim( substr( $pre_order_name, 0, 1024 ) ),
'currency' => strtoupper( get_woocommerce_currency() ), 'currency' => strtoupper( get_woocommerce_currency() ),
'reference' => $order->get_id(), 'reference' => $order->get_id(),
) ); )
);
if ( 'APPROVED' == $payment->paymentStatus ) { if ( 'APPROVED' == $payment->paymentStatus ) {
// Payment complete // Payment complete

View File

@ -74,7 +74,7 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway_CC {
*/ */
protected function init_simplify_sdk() { protected function init_simplify_sdk() {
// Include lib // Include lib
require_once( dirname( __FILE__ ) . '/includes/Simplify.php' ); require_once dirname( __FILE__ ) . '/includes/Simplify.php';
Simplify::$publicKey = $this->public_key; Simplify::$publicKey = $this->public_key;
Simplify::$privateKey = $this->private_key; Simplify::$privateKey = $this->private_key;
@ -301,7 +301,8 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway_CC {
wp_enqueue_script( 'simplify-commerce', 'https://www.simplify.com/commerce/v1/simplify.js', array( 'jquery' ), WC_VERSION, true ); wp_enqueue_script( 'simplify-commerce', 'https://www.simplify.com/commerce/v1/simplify.js', array( 'jquery' ), WC_VERSION, true );
wp_enqueue_script( 'wc-simplify-commerce', WC()->plugin_url() . '/includes/gateways/simplify-commerce/assets/js/simplify-commerce.js', array( 'simplify-commerce', 'wc-credit-card-form' ), WC_VERSION, true ); wp_enqueue_script( 'wc-simplify-commerce', WC()->plugin_url() . '/includes/gateways/simplify-commerce/assets/js/simplify-commerce.js', array( 'simplify-commerce', 'wc-credit-card-form' ), WC_VERSION, true );
wp_localize_script( 'wc-simplify-commerce', 'Simplify_commerce_params', array( wp_localize_script(
'wc-simplify-commerce', 'Simplify_commerce_params', array(
'key' => $this->public_key, 'key' => $this->public_key,
'card.number' => __( 'Card number', 'woocommerce' ), 'card.number' => __( 'Card number', 'woocommerce' ),
'card.expMonth' => __( 'Expiry month', 'woocommerce' ), 'card.expMonth' => __( 'Expiry month', 'woocommerce' ),
@ -309,7 +310,8 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway_CC {
'is_invalid' => __( 'is invalid', 'woocommerce' ), 'is_invalid' => __( 'is invalid', 'woocommerce' ),
'mode' => $this->mode, 'mode' => $this->mode,
'is_ssl' => is_ssl(), 'is_ssl' => is_ssl(),
) ); )
);
} }
public function add_payment_method() { public function add_payment_method() {
@ -356,11 +358,13 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway_CC {
$customer = Simplify_Customer::findCustomer( $customer_token->get_token() ); // get updated customer with new set card $customer = Simplify_Customer::findCustomer( $customer_token->get_token() ); // get updated customer with new set card
$token = $customer_token; $token = $customer_token;
} else { } else {
$customer = Simplify_Customer::createCustomer( array( $customer = Simplify_Customer::createCustomer(
array(
'token' => $cart_token, 'token' => $cart_token,
'email' => $customer_info['email'], 'email' => $customer_info['email'],
'name' => $customer_info['name'], 'name' => $customer_info['name'],
) ); )
);
$token = new WC_Payment_Token_CC(); $token = new WC_Payment_Token_CC();
$token->set_token( $customer->id ); $token->set_token( $customer->id );
} }
@ -615,7 +619,8 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway_CC {
* @return array * @return array
*/ */
protected function get_hosted_payments_args( $order ) { protected function get_hosted_payments_args( $order ) {
$args = apply_filters( 'woocommerce_simplify_commerce_hosted_args', array( $args = apply_filters(
'woocommerce_simplify_commerce_hosted_args', array(
'sc-key' => $this->public_key, 'sc-key' => $this->public_key,
'amount' => $order->get_total() * 100, 'amount' => $order->get_total() * 100,
'reference' => $order->get_id(), 'reference' => $order->get_id(),
@ -630,7 +635,8 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway_CC {
'address-zip' => $order->get_billing_postcode(), 'address-zip' => $order->get_billing_postcode(),
'address-country' => $order->get_billing_country(), 'address-country' => $order->get_billing_country(),
'operation' => 'create.token', 'operation' => 'create.token',
), $order->get_id() ); ), $order->get_id()
);
return $args; return $args;
} }
@ -726,12 +732,14 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway_CC {
try { try {
$payment_id = get_post_meta( $order_id, '_transaction_id', true ); $payment_id = get_post_meta( $order_id, '_transaction_id', true );
$refund = Simplify_Refund::createRefund( array( $refund = Simplify_Refund::createRefund(
array(
'amount' => $amount * 100, // In cents. 'amount' => $amount * 100, // In cents.
'payment' => $payment_id, 'payment' => $payment_id,
'reason' => $reason, 'reason' => $reason,
'reference' => $order_id, 'reference' => $order_id,
) ); )
);
if ( 'APPROVED' == $refund->paymentStatus ) { if ( 'APPROVED' == $refund->paymentStatus ) {
return true; return true;

View File

@ -1,19 +1,17 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Shopping Cart Widget. * Shopping Cart Widget.
* *
* Displays shopping cart widget. * Displays shopping cart widget.
* *
* @author WooThemes
* @category Widgets
* @package WooCommerce/Widgets * @package WooCommerce/Widgets
* @version 2.3.0 * @version 2.3.0
* @extends WC_Widget */
defined( 'ABSPATH' ) || exit;
/**
* Widget cart class.
*/ */
class WC_Widget_Cart extends WC_Widget { class WC_Widget_Cart extends WC_Widget {
@ -22,7 +20,7 @@ class WC_Widget_Cart extends WC_Widget {
*/ */
public function __construct() { public function __construct() {
$this->widget_cssclass = 'woocommerce widget_shopping_cart'; $this->widget_cssclass = 'woocommerce widget_shopping_cart';
$this->widget_description = __( "Display the customer shopping cart.", 'woocommerce' ); $this->widget_description = __( 'Display the customer shopping cart.', 'woocommerce' );
$this->widget_id = 'woocommerce_widget_cart'; $this->widget_id = 'woocommerce_widget_cart';
$this->widget_name = __( 'Cart', 'woocommerce' ); $this->widget_name = __( 'Cart', 'woocommerce' );
$this->settings = array( $this->settings = array(
@ -46,8 +44,8 @@ class WC_Widget_Cart extends WC_Widget {
* *
* @see WP_Widget * @see WP_Widget
* *
* @param array $args * @param array $args Arguments.
* @param array $instance * @param array $instance Widget instance.
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
if ( apply_filters( 'woocommerce_widget_cart_is_hidden', is_cart() || is_checkout() ) ) { if ( apply_filters( 'woocommerce_widget_cart_is_hidden', is_cart() || is_checkout() ) ) {
@ -62,7 +60,7 @@ class WC_Widget_Cart extends WC_Widget {
echo '<div class="hide_cart_widget_if_empty">'; echo '<div class="hide_cart_widget_if_empty">';
} }
// Insert cart widget placeholder - code in woocommerce.js will update this on page load // Insert cart widget placeholder - code in woocommerce.js will update this on page load.
echo '<div class="widget_shopping_cart_content"></div>'; echo '<div class="widget_shopping_cart_content"></div>';
if ( $hide_if_empty ) { if ( $hide_if_empty ) {

View File

@ -1,17 +1,15 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Layered Navigation Filters Widget. * Layered Navigation Filters Widget.
* *
* @author WooThemes
* @category Widgets
* @package WooCommerce/Widgets * @package WooCommerce/Widgets
* @version 2.3.0 * @version 2.3.0
* @extends WC_Widget */
defined( 'ABSPATH' ) || exit;
/**
* Widget layered nav filters.
*/ */
class WC_Widget_Layered_Nav_Filters extends WC_Widget { class WC_Widget_Layered_Nav_Filters extends WC_Widget {
@ -38,8 +36,8 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
* Output widget. * Output widget.
* *
* @see WP_Widget * @see WP_Widget
* @param array $args * @param array $args Arguments.
* @param array $instance * @param array $instance Widget instance.
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
if ( ! is_shop() && ! is_product_taxonomy() ) { if ( ! is_shop() && ! is_product_taxonomy() ) {
@ -47,9 +45,9 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
} }
$_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes(); $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();
$min_price = isset( $_GET['min_price'] ) ? wc_clean( $_GET['min_price'] ) : 0; $min_price = isset( $_GET['min_price'] ) ? wc_clean( wp_unslash( $_GET['min_price'] ) ) : 0; // WPCS: input var ok, CSRF ok.
$max_price = isset( $_GET['max_price'] ) ? wc_clean( $_GET['max_price'] ) : 0; $max_price = isset( $_GET['max_price'] ) ? wc_clean( wp_unslash( $_GET['max_price'] ) ) : 0; // WPCS: input var ok, CSRF ok.
$rating_filter = isset( $_GET['rating_filter'] ) ? array_filter( array_map( 'absint', explode( ',', $_GET['rating_filter'] ) ) ) : array(); $rating_filter = isset( $_GET['rating_filter'] ) ? array_filter( array_map( 'absint', explode( ',', wp_unslash( $_GET['rating_filter'] ) ) ) ) : array(); // WPCS: sanitization ok, input var ok, CSRF ok.
$base_link = $this->get_current_page_url(); $base_link = $this->get_current_page_url();
if ( 0 < count( $_chosen_attributes ) || 0 < $min_price || 0 < $max_price || ! empty( $rating_filter ) ) { if ( 0 < count( $_chosen_attributes ) || 0 < $min_price || 0 < $max_price || ! empty( $rating_filter ) ) {
@ -58,22 +56,23 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
echo '<ul>'; echo '<ul>';
// Attributes // Attributes.
if ( ! empty( $_chosen_attributes ) ) { if ( ! empty( $_chosen_attributes ) ) {
foreach ( $_chosen_attributes as $taxonomy => $data ) { foreach ( $_chosen_attributes as $taxonomy => $data ) {
foreach ( $data['terms'] as $term_slug ) { foreach ( $data['terms'] as $term_slug ) {
if ( ! $term = get_term_by( 'slug', $term_slug, $taxonomy ) ) { $term = get_term_by( 'slug', $term_slug, $taxonomy );
if ( ! $term ) {
continue; continue;
} }
$filter_name = 'filter_' . sanitize_title( str_replace( 'pa_', '', $taxonomy ) ); $filter_name = 'filter_' . sanitize_title( str_replace( 'pa_', '', $taxonomy ) );
$current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( $_GET[ $filter_name ] ) ) : array(); $current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( wp_unslash( $_GET[ $filter_name ] ) ) ) : array(); // WPCS: input var ok, CSRF ok.
$current_filter = array_map( 'sanitize_title', $current_filter ); $current_filter = array_map( 'sanitize_title', $current_filter );
$new_filter = array_diff( $current_filter, array( $term_slug ) ); $new_filter = array_diff( $current_filter, array( $term_slug ) );
$link = remove_query_arg( array( 'add-to-cart', $filter_name ), $base_link ); $link = remove_query_arg( array( 'add-to-cart', $filter_name ), $base_link );
if ( sizeof( $new_filter ) > 0 ) { if ( count( $new_filter ) > 0 ) {
$link = add_query_arg( $filter_name, implode( ',', $new_filter ), $link ); $link = add_query_arg( $filter_name, implode( ',', $new_filter ), $link );
} }
@ -84,18 +83,22 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
if ( $min_price ) { if ( $min_price ) {
$link = remove_query_arg( 'min_price', $base_link ); $link = remove_query_arg( 'min_price', $base_link );
echo '<li class="chosen"><a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . sprintf( __( 'Min %s', 'woocommerce' ), wc_price( $min_price ) ) . '</a></li>'; /* translators: %s: minimum price */
echo '<li class="chosen"><a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . sprintf( __( 'Min %s', 'woocommerce' ), wc_price( $min_price ) ) . '</a></li>'; // WPCS: XSS ok.
} }
if ( $max_price ) { if ( $max_price ) {
$link = remove_query_arg( 'max_price', $base_link ); $link = remove_query_arg( 'max_price', $base_link );
echo '<li class="chosen"><a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . sprintf( __( 'Max %s', 'woocommerce' ), wc_price( $max_price ) ) . '</a></li>'; /* translators: %s: maximum price */
echo '<li class="chosen"><a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . sprintf( __( 'Max %s', 'woocommerce' ), wc_price( $max_price ) ) . '</a></li>'; // WPCS: XSS ok.
} }
if ( ! empty( $rating_filter ) ) { if ( ! empty( $rating_filter ) ) {
foreach ( $rating_filter as $rating ) { foreach ( $rating_filter as $rating ) {
$link_ratings = implode( ',', array_diff( $rating_filter, array( $rating ) ) ); $link_ratings = implode( ',', array_diff( $rating_filter, array( $rating ) ) );
$link = $link_ratings ? add_query_arg( 'rating_filter', $link_ratings ) : remove_query_arg( 'rating_filter', $base_link ); $link = $link_ratings ? add_query_arg( 'rating_filter', $link_ratings ) : remove_query_arg( 'rating_filter', $base_link );
/* translators: %s: rating */
echo '<li class="chosen"><a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . sprintf( esc_html__( 'Rated %s out of 5', 'woocommerce' ), esc_html( $rating ) ) . '</a></li>'; echo '<li class="chosen"><a rel="nofollow" aria-label="' . esc_attr__( 'Remove filter', 'woocommerce' ) . '" href="' . esc_url( $link ) . '">' . sprintf( esc_html__( 'Rated %s out of 5', 'woocommerce' ), esc_html( $rating ) ) . '</a></li>';
} }
} }

View File

@ -3,20 +3,13 @@
* Layered nav widget * Layered nav widget
* *
* @package WooCommerce/Widgets * @package WooCommerce/Widgets
* @version 2.6.0
*/ */
if ( ! defined( 'ABSPATH' ) ) { defined( 'ABSPATH' ) || exit;
exit;
}
/** /**
* Layered Navigation Widget. * Widget layered nav class.
*
* @author WooThemes
* @category Widgets
* @package WooCommerce/Widgets
* @version 2.6.0
* @extends WC_Widget
*/ */
class WC_Widget_Layered_Nav extends WC_Widget { class WC_Widget_Layered_Nav extends WC_Widget {
@ -133,16 +126,16 @@ class WC_Widget_Layered_Nav extends WC_Widget {
$orderby = wc_attribute_orderby( $taxonomy ); $orderby = wc_attribute_orderby( $taxonomy );
switch ( $orderby ) { switch ( $orderby ) {
case 'name' : case 'name':
$get_terms_args['orderby'] = 'name'; $get_terms_args['orderby'] = 'name';
$get_terms_args['menu_order'] = false; $get_terms_args['menu_order'] = false;
break; break;
case 'id' : case 'id':
$get_terms_args['orderby'] = 'id'; $get_terms_args['orderby'] = 'id';
$get_terms_args['order'] = 'ASC'; $get_terms_args['order'] = 'ASC';
$get_terms_args['menu_order'] = false; $get_terms_args['menu_order'] = false;
break; break;
case 'menu_order' : case 'menu_order':
$get_terms_args['menu_order'] = 'ASC'; $get_terms_args['menu_order'] = 'ASC';
break; break;
} }
@ -154,10 +147,10 @@ class WC_Widget_Layered_Nav extends WC_Widget {
} }
switch ( $orderby ) { switch ( $orderby ) {
case 'name_num' : case 'name_num':
usort( $terms, '_wc_get_product_terms_name_num_usort_callback' ); usort( $terms, '_wc_get_product_terms_name_num_usort_callback' );
break; break;
case 'parent' : case 'parent':
usort( $terms, '_wc_get_product_terms_parent_usort_callback' ); usort( $terms, '_wc_get_product_terms_parent_usort_callback' );
break; break;
} }
@ -232,6 +225,8 @@ class WC_Widget_Layered_Nav extends WC_Widget {
$_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes(); $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();
$taxonomy_filter_name = str_replace( 'pa_', '', $taxonomy ); $taxonomy_filter_name = str_replace( 'pa_', '', $taxonomy );
$taxonomy_label = wc_attribute_label( $taxonomy ); $taxonomy_label = wc_attribute_label( $taxonomy );
/* translators: %s: taxonomy name */
$any_label = apply_filters( 'woocommerce_layered_nav_any_label', sprintf( __( 'Any %s', 'woocommerce' ), $taxonomy_label ), $taxonomy_label, $taxonomy ); $any_label = apply_filters( 'woocommerce_layered_nav_any_label', sprintf( __( 'Any %s', 'woocommerce' ), $taxonomy_label ), $taxonomy_label, $taxonomy );
$multiple = 'or' === $query_type; $multiple = 'or' === $query_type;
$current_values = isset( $_chosen_attributes[ $taxonomy ]['terms'] ) ? $_chosen_attributes[ $taxonomy ]['terms'] : array(); $current_values = isset( $_chosen_attributes[ $taxonomy ]['terms'] ) ? $_chosen_attributes[ $taxonomy ]['terms'] : array();
@ -254,7 +249,7 @@ class WC_Widget_Layered_Nav extends WC_Widget {
} }
// Get count based on current view. // Get count based on current view.
$option_is_set = in_array( $term->slug, $current_values ); $option_is_set = in_array( $term->slug, $current_values, true );
$count = isset( $term_counts[ $term->term_id ] ) ? $term_counts[ $term->term_id ] : 0; $count = isset( $term_counts[ $term->term_id ] ) ? $term_counts[ $term->term_id ] : 0;
// Only show options with count > 0. // Only show options with count > 0.
@ -281,7 +276,8 @@ class WC_Widget_Layered_Nav extends WC_Widget {
echo wc_query_string_form_fields( null, array( 'filter_' . $taxonomy_filter_name, 'query_type_' . $taxonomy_filter_name ), '', true ); // @codingStandardsIgnoreLine echo wc_query_string_form_fields( null, array( 'filter_' . $taxonomy_filter_name, 'query_type_' . $taxonomy_filter_name ), '', true ); // @codingStandardsIgnoreLine
echo '</form>'; echo '</form>';
wc_enqueue_js( " wc_enqueue_js(
"
// Update value on change. // Update value on change.
jQuery( '.dropdown_layered_nav_" . esc_js( $taxonomy_filter_name ) . "' ).change( function() { jQuery( '.dropdown_layered_nav_" . esc_js( $taxonomy_filter_name ) . "' ).change( function() {
var slug = jQuery( this ).val(); var slug = jQuery( this ).val();
@ -310,7 +306,8 @@ class WC_Widget_Layered_Nav extends WC_Widget {
}; };
wc_layered_nav_select(); wc_layered_nav_select();
} }
" ); "
);
} }
return $found; return $found;
@ -361,7 +358,8 @@ class WC_Widget_Layered_Nav extends WC_Widget {
. $tax_query_sql['where'] . $meta_query_sql['where'] . . $tax_query_sql['where'] . $meta_query_sql['where'] .
'AND terms.term_id IN (' . implode( ',', array_map( 'absint', $term_ids ) ) . ')'; 'AND terms.term_id IN (' . implode( ',', array_map( 'absint', $term_ids ) ) . ')';
if ( $search = WC_Query::get_main_search_query_sql() ) { $search = WC_Query::get_main_search_query_sql();
if ( $search ) {
$query['where'] .= ' AND ' . $search; $query['where'] .= ' AND ' . $search;
} }
@ -401,7 +399,7 @@ class WC_Widget_Layered_Nav extends WC_Widget {
foreach ( $terms as $term ) { foreach ( $terms as $term ) {
$current_values = isset( $_chosen_attributes[ $taxonomy ]['terms'] ) ? $_chosen_attributes[ $taxonomy ]['terms'] : array(); $current_values = isset( $_chosen_attributes[ $taxonomy ]['terms'] ) ? $_chosen_attributes[ $taxonomy ]['terms'] : array();
$option_is_set = in_array( $term->slug, $current_values ); $option_is_set = in_array( $term->slug, $current_values, true );
$count = isset( $term_counts[ $term->term_id ] ) ? $term_counts[ $term->term_id ] : 0; $count = isset( $term_counts[ $term->term_id ] ) ? $term_counts[ $term->term_id ] : 0;
// Skip the term for the current archive. // Skip the term for the current archive.
@ -417,10 +415,10 @@ class WC_Widget_Layered_Nav extends WC_Widget {
} }
$filter_name = 'filter_' . sanitize_title( str_replace( 'pa_', '', $taxonomy ) ); $filter_name = 'filter_' . sanitize_title( str_replace( 'pa_', '', $taxonomy ) );
$current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( wp_unslash( $_GET[ $filter_name ] ) ) ) : array(); $current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( wp_unslash( $_GET[ $filter_name ] ) ) ) : array(); // WPCS: input var ok, CSRF ok.
$current_filter = array_map( 'sanitize_title', $current_filter ); $current_filter = array_map( 'sanitize_title', $current_filter );
if ( ! in_array( $term->slug, $current_filter ) ) { if ( ! in_array( $term->slug, $current_filter, true ) ) {
$current_filter[] = $term->slug; $current_filter[] = $term->slug;
} }

View File

@ -1,19 +1,17 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Price Filter Widget and related functions. * Price Filter Widget and related functions.
* *
* Generates a range slider to filter products by price. * Generates a range slider to filter products by price.
* *
* @author WooThemes
* @category Widgets
* @package WooCommerce/Widgets * @package WooCommerce/Widgets
* @version 2.3.0 * @version 2.3.0
* @extends WC_Widget */
defined( 'ABSPATH' ) || exit;
/**
* Widget price filter class.
*/ */
class WC_Widget_Price_Filter extends WC_Widget { class WC_Widget_Price_Filter extends WC_Widget {
@ -36,13 +34,15 @@ class WC_Widget_Price_Filter extends WC_Widget {
wp_register_script( 'accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array( 'jquery' ), '0.4.2' ); wp_register_script( 'accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array( 'jquery' ), '0.4.2' );
wp_register_script( 'wc-jquery-ui-touchpunch', WC()->plugin_url() . '/assets/js/jquery-ui-touch-punch/jquery-ui-touch-punch' . $suffix . '.js', array( 'jquery-ui-slider' ), WC_VERSION, true ); wp_register_script( 'wc-jquery-ui-touchpunch', WC()->plugin_url() . '/assets/js/jquery-ui-touch-punch/jquery-ui-touch-punch' . $suffix . '.js', array( 'jquery-ui-slider' ), WC_VERSION, true );
wp_register_script( 'wc-price-slider', WC()->plugin_url() . '/assets/js/frontend/price-slider' . $suffix . '.js', array( 'jquery-ui-slider', 'wc-jquery-ui-touchpunch', 'accounting' ), WC_VERSION, true ); wp_register_script( 'wc-price-slider', WC()->plugin_url() . '/assets/js/frontend/price-slider' . $suffix . '.js', array( 'jquery-ui-slider', 'wc-jquery-ui-touchpunch', 'accounting' ), WC_VERSION, true );
wp_localize_script( 'wc-price-slider', 'woocommerce_price_slider_params', array( wp_localize_script(
'wc-price-slider', 'woocommerce_price_slider_params', array(
'currency_format_num_decimals' => 0, 'currency_format_num_decimals' => 0,
'currency_format_symbol' => get_woocommerce_currency_symbol(), 'currency_format_symbol' => get_woocommerce_currency_symbol(),
'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ), 'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ),
'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ), 'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ),
'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), 'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ),
) ); )
);
if ( is_customize_preview() ) { if ( is_customize_preview() ) {
wp_enqueue_script( 'wc-price-slider' ); wp_enqueue_script( 'wc-price-slider' );
@ -56,8 +56,8 @@ class WC_Widget_Price_Filter extends WC_Widget {
* *
* @see WP_Widget * @see WP_Widget
* *
* @param array $args * @param array $args Arguments.
* @param array $instance * @param array $instance Widget instance.
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
global $wp; global $wp;
@ -89,8 +89,8 @@ class WC_Widget_Price_Filter extends WC_Widget {
$form_action = preg_replace( '%\/page/[0-9]+%', '', home_url( trailingslashit( $wp->request ) ) ); $form_action = preg_replace( '%\/page/[0-9]+%', '', home_url( trailingslashit( $wp->request ) ) );
} }
$min_price = isset( $_GET['min_price'] ) ? esc_attr( $_GET['min_price'] ) : apply_filters( 'woocommerce_price_filter_widget_min_amount', $min ); $min_price = isset( $_GET['min_price'] ) ? wc_clean( wp_unslash( $_GET['min_price'] ) ) : apply_filters( 'woocommerce_price_filter_widget_min_amount', $min ); // WPCS: input var ok, CSRF ok.
$max_price = isset( $_GET['max_price'] ) ? esc_attr( $_GET['max_price'] ) : apply_filters( 'woocommerce_price_filter_widget_max_amount', $max ); $max_price = isset( $_GET['max_price'] ) ? wc_clean( wp_unslash( $_GET['max_price'] ) ) : apply_filters( 'woocommerce_price_filter_widget_max_amount', $max ); // WPCS: input var ok, CSRF ok.
echo '<form method="get" action="' . esc_url( $form_action ) . '"> echo '<form method="get" action="' . esc_url( $form_action ) . '">
<div class="price_slider_wrapper"> <div class="price_slider_wrapper">
@ -106,13 +106,14 @@ class WC_Widget_Price_Filter extends WC_Widget {
<div class="clear"></div> <div class="clear"></div>
</div> </div>
</div> </div>
</form>'; </form>'; // WPCS: XSS ok.
$this->widget_end( $args ); $this->widget_end( $args );
} }
/** /**
* Get filtered min price for current products. * Get filtered min price for current products.
*
* @return int * @return int
*/ */
protected function get_filtered_price() { protected function get_filtered_price() {
@ -150,10 +151,11 @@ class WC_Widget_Price_Filter extends WC_Widget {
AND price_meta.meta_value > '' "; AND price_meta.meta_value > '' ";
$sql .= $tax_query_sql['where'] . $meta_query_sql['where']; $sql .= $tax_query_sql['where'] . $meta_query_sql['where'];
if ( $search = WC_Query::get_main_search_query_sql() ) { $search = WC_Query::get_main_search_query_sql();
if ( $search ) {
$sql .= ' AND ' . $search; $sql .= ' AND ' . $search;
} }
return $wpdb->get_row( $sql ); return $wpdb->get_row( $sql ); // WPCS: unprepared SQL ok.
} }
} }

View File

@ -2,15 +2,11 @@
/** /**
* Product Categories Widget * Product Categories Widget
* *
* @author Automattic
* @category Widgets
* @package WooCommerce/Widgets * @package WooCommerce/Widgets
* @version 2.3.0 * @version 2.3.0
*/ */
if ( ! defined( 'ABSPATH' ) ) { defined( 'ABSPATH' ) || exit;
exit;
}
/** /**
* Product categories widget class. * Product categories widget class.
@ -136,10 +132,14 @@ class WC_Widget_Product_Categories extends WC_Widget {
$this->cat_ancestors = get_ancestors( $this->current_cat->term_id, 'product_cat' ); $this->cat_ancestors = get_ancestors( $this->current_cat->term_id, 'product_cat' );
} elseif ( is_singular( 'product' ) ) { } elseif ( is_singular( 'product' ) ) {
$terms = wc_get_product_terms( $post->ID, 'product_cat', apply_filters( 'woocommerce_product_categories_widget_product_terms_args', array( $terms = wc_get_product_terms(
$post->ID, 'product_cat', apply_filters(
'woocommerce_product_categories_widget_product_terms_args', array(
'orderby' => 'parent', 'orderby' => 'parent',
'order' => 'DESC', 'order' => 'DESC',
) ) ); )
)
);
if ( $terms ) { if ( $terms ) {
$main_term = apply_filters( 'woocommerce_product_categories_widget_main_term', $terms[0], $terms ); $main_term = apply_filters( 'woocommerce_product_categories_widget_main_term', $terms[0], $terms );
@ -176,7 +176,8 @@ class WC_Widget_Product_Categories extends WC_Widget {
// Gather siblings of ancestors. // Gather siblings of ancestors.
if ( $this->cat_ancestors ) { if ( $this->cat_ancestors ) {
foreach ( $this->cat_ancestors as $ancestor ) { foreach ( $this->cat_ancestors as $ancestor ) {
$include = array_merge( $include, get_terms( $include = array_merge(
$include, get_terms(
'product_cat', 'product_cat',
array( array(
'fields' => 'ids', 'fields' => 'ids',
@ -184,7 +185,8 @@ class WC_Widget_Product_Categories extends WC_Widget {
'hierarchical' => false, 'hierarchical' => false,
'hide_empty' => false, 'hide_empty' => false,
) )
) ); )
);
} }
} }
} else { } else {
@ -198,7 +200,7 @@ class WC_Widget_Product_Categories extends WC_Widget {
'hide_empty' => false, 'hide_empty' => false,
) )
); );
} // End if(). }
$list_args['include'] = implode( ',', $include ); $list_args['include'] = implode( ',', $include );
$dropdown_args['include'] = $list_args['include']; $dropdown_args['include'] = $list_args['include'];
@ -213,19 +215,26 @@ class WC_Widget_Product_Categories extends WC_Widget {
$list_args['depth'] = 1; $list_args['depth'] = 1;
$list_args['child_of'] = 0; $list_args['child_of'] = 0;
$list_args['hierarchical'] = 1; $list_args['hierarchical'] = 1;
} // End if(). }
$this->widget_start( $args, $instance ); $this->widget_start( $args, $instance );
if ( $dropdown ) { if ( $dropdown ) {
wc_product_dropdown_categories( apply_filters( 'woocommerce_product_categories_widget_dropdown_args', wp_parse_args( $dropdown_args, array( wc_product_dropdown_categories(
apply_filters(
'woocommerce_product_categories_widget_dropdown_args', wp_parse_args(
$dropdown_args, array(
'show_count' => $count, 'show_count' => $count,
'hierarchical' => $hierarchical, 'hierarchical' => $hierarchical,
'show_uncategorized' => 0, 'show_uncategorized' => 0,
'orderby' => $orderby, 'orderby' => $orderby,
'selected' => $this->current_cat ? $this->current_cat->slug : '', 'selected' => $this->current_cat ? $this->current_cat->slug : '',
) ) ) ); )
wc_enqueue_js( " )
)
);
wc_enqueue_js(
"
jQuery( '.dropdown_product_cat' ).change( function() { jQuery( '.dropdown_product_cat' ).change( function() {
if ( jQuery(this).val() != '' ) { if ( jQuery(this).val() != '' ) {
var this_page = ''; var this_page = '';
@ -238,11 +247,12 @@ class WC_Widget_Product_Categories extends WC_Widget {
location.href = this_page; location.href = this_page;
} }
}); });
" ); "
);
} else { } else {
include_once( WC()->plugin_path() . '/includes/walkers/class-wc-product-cat-list-walker.php' ); include_once WC()->plugin_path() . '/includes/walkers/class-wc-product-cat-list-walker.php';
$list_args['walker'] = new WC_Product_Cat_List_Walker; $list_args['walker'] = new WC_Product_Cat_List_Walker();
$list_args['title_li'] = ''; $list_args['title_li'] = '';
$list_args['pad_counts'] = 1; $list_args['pad_counts'] = 1;
$list_args['show_option_none'] = __( 'No product categories exist.', 'woocommerce' ); $list_args['show_option_none'] = __( 'No product categories exist.', 'woocommerce' );
@ -255,7 +265,7 @@ class WC_Widget_Product_Categories extends WC_Widget {
wp_list_categories( apply_filters( 'woocommerce_product_categories_widget_args', $list_args ) ); wp_list_categories( apply_filters( 'woocommerce_product_categories_widget_args', $list_args ) );
echo '</ul>'; echo '</ul>';
} // End if(). }
$this->widget_end( $args ); $this->widget_end( $args );
} }

View File

@ -1,17 +1,15 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Product Search Widget. * Product Search Widget.
* *
* @author WooThemes
* @category Widgets
* @package WooCommerce/Widgets * @package WooCommerce/Widgets
* @version 2.3.0 * @version 2.3.0
* @extends WC_Widget */
defined( 'ABSPATH' ) || exit;
/**
* Widget product search class.
*/ */
class WC_Widget_Product_Search extends WC_Widget { class WC_Widget_Product_Search extends WC_Widget {
@ -39,8 +37,8 @@ class WC_Widget_Product_Search extends WC_Widget {
* *
* @see WP_Widget * @see WP_Widget
* *
* @param array $args * @param array $args Arguments.
* @param array $instance * @param array $instance Widget instance.
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
$this->widget_start( $args, $instance ); $this->widget_start( $args, $instance );

View File

@ -1,17 +1,17 @@
<?php <?php
/**
* Tag Cloud Widget.
*
* @package WooCommerce/Widgets
* @version 3.4.0
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
/** /**
* Tag Cloud Widget. * Widget product tag cloud
*
* @author WooThemes
* @category Widgets
* @package WooCommerce/Widgets
* @version 2.3.0
* @extends WC_Widget
*/ */
class WC_Widget_Product_Tag_Cloud extends WC_Widget { class WC_Widget_Product_Tag_Cloud extends WC_Widget {
@ -39,11 +39,11 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget {
* *
* @see WP_Widget * @see WP_Widget
* *
* @param array $args * @param array $args Arguments.
* @param array $instance * @param array $instance Widget instance.
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
$current_taxonomy = $this->_get_current_taxonomy( $instance ); $current_taxonomy = $this->get_current_taxonomy( $instance );
if ( empty( $instance['title'] ) ) { if ( empty( $instance['title'] ) ) {
$taxonomy = get_taxonomy( $current_taxonomy ); $taxonomy = get_taxonomy( $current_taxonomy );
@ -54,10 +54,14 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget {
echo '<div class="tagcloud">'; echo '<div class="tagcloud">';
wp_tag_cloud( apply_filters( 'woocommerce_product_tag_cloud_widget_args', array( wp_tag_cloud(
apply_filters(
'woocommerce_product_tag_cloud_widget_args', array(
'taxonomy' => $current_taxonomy, 'taxonomy' => $current_taxonomy,
'topic_count_text_callback' => array( $this, '_topic_count_text' ), 'topic_count_text_callback' => array( $this, 'topic_count_text' ),
) ) ); )
)
);
echo '</div>'; echo '</div>';
@ -67,22 +71,50 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget {
/** /**
* Return the taxonomy being displayed. * Return the taxonomy being displayed.
* *
* @param object $instance * @param object $instance Widget instance.
* @return string * @return string
*/ */
public function _get_current_taxonomy( $instance ) { public function get_current_taxonomy( $instance ) {
return 'product_tag'; return 'product_tag';
} }
/** /**
* Returns topic count text. * Returns topic count text.
* *
* @since 2.6.0 * @since 3.4.0
* @param int $count * @param int $count Count text.
* @return string * @return string
*/ */
public function _topic_count_text( $count ) { public function topic_count_text( $count ) {
/* translators: %s: product count */ /* translators: %s: product count */
return sprintf( _n( '%s product', '%s products', $count, 'woocommerce' ), number_format_i18n( $count ) ); return sprintf( _n( '%s product', '%s products', $count, 'woocommerce' ), number_format_i18n( $count ) );
} }
// Ignore whole block to avoid warnings about PSR2.Methods.MethodDeclaration.Underscore violation.
// @codingStandardsIgnoreStart
/**
* Return the taxonomy being displayed.
*
* @deprecated 3.4.0
* @param object $instance Widget instance.
* @return string
*/
public function _get_current_taxonomy( $instance ) {
wc_deprecated_function( '_get_current_taxonomy', '3.4.0', 'WC_Widget_Product_Tag_Cloud->get_current_taxonomy' );
return $this->get_current_taxonomy( $instance );
}
/**
* Returns topic count text.
*
* @deprecated 3.4.0
* @since 2.6.0
* @param int $count Count text.
* @return string
*/
public function _topic_count_text( $count ) {
wc_deprecated_function( '_topic_count_text', '3.4.0', 'WC_Widget_Product_Tag_Cloud->topic_count_text' );
return $this->topic_count_text( $count );
}
// @codingStandardsIgnoreEnd
} }

View File

@ -1,17 +1,15 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* List products. One widget to rule them all. * List products. One widget to rule them all.
* *
* @author WooThemes
* @category Widgets
* @package WooCommerce/Widgets * @package WooCommerce/Widgets
* @version 3.3.0 * @version 3.3.0
* @extends WC_Widget */
defined( 'ABSPATH' ) || exit;
/**
* Widget products.
*/ */
class WC_Widget_Products extends WC_Widget { class WC_Widget_Products extends WC_Widget {
@ -84,8 +82,9 @@ class WC_Widget_Products extends WC_Widget {
/** /**
* Query the products and return them. * Query the products and return them.
* @param array $args *
* @param array $instance * @param array $args Arguments.
* @param array $instance Widget instance.
* @return WP_Query * @return WP_Query
*/ */
public function get_products( $args, $instance ) { public function get_products( $args, $instance ) {
@ -105,7 +104,7 @@ class WC_Widget_Products extends WC_Widget {
'tax_query' => array( 'tax_query' => array(
'relation' => 'AND', 'relation' => 'AND',
), ),
); ); // WPCS: slow query ok.
if ( empty( $instance['show_hidden'] ) ) { if ( empty( $instance['show_hidden'] ) ) {
$query_args['tax_query'][] = array( $query_args['tax_query'][] = array(
@ -134,18 +133,18 @@ class WC_Widget_Products extends WC_Widget {
'terms' => $product_visibility_term_ids['outofstock'], 'terms' => $product_visibility_term_ids['outofstock'],
'operator' => 'NOT IN', 'operator' => 'NOT IN',
), ),
); ); // WPCS: slow query ok.
} }
switch ( $show ) { switch ( $show ) {
case 'featured' : case 'featured':
$query_args['tax_query'][] = array( $query_args['tax_query'][] = array(
'taxonomy' => 'product_visibility', 'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id', 'field' => 'term_taxonomy_id',
'terms' => $product_visibility_term_ids['featured'], 'terms' => $product_visibility_term_ids['featured'],
); );
break; break;
case 'onsale' : case 'onsale':
$product_ids_on_sale = wc_get_product_ids_on_sale(); $product_ids_on_sale = wc_get_product_ids_on_sale();
$product_ids_on_sale[] = 0; $product_ids_on_sale[] = 0;
$query_args['post__in'] = $product_ids_on_sale; $query_args['post__in'] = $product_ids_on_sale;
@ -153,18 +152,18 @@ class WC_Widget_Products extends WC_Widget {
} }
switch ( $orderby ) { switch ( $orderby ) {
case 'price' : case 'price':
$query_args['meta_key'] = '_price'; $query_args['meta_key'] = '_price'; // WPCS: slow query ok.
$query_args['orderby'] = 'meta_value_num'; $query_args['orderby'] = 'meta_value_num';
break; break;
case 'rand' : case 'rand':
$query_args['orderby'] = 'rand'; $query_args['orderby'] = 'rand';
break; break;
case 'sales' : case 'sales':
$query_args['meta_key'] = 'total_sales'; $query_args['meta_key'] = 'total_sales'; // WPCS: slow query ok.
$query_args['orderby'] = 'meta_value_num'; $query_args['orderby'] = 'meta_value_num';
break; break;
default : default:
$query_args['orderby'] = 'date'; $query_args['orderby'] = 'date';
} }
@ -176,8 +175,8 @@ class WC_Widget_Products extends WC_Widget {
* *
* @see WP_Widget * @see WP_Widget
* *
* @param array $args * @param array $args Arguments.
* @param array $instance * @param array $instance Widget instance.
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
if ( $this->get_cached_widget( $args ) ) { if ( $this->get_cached_widget( $args ) ) {
@ -186,7 +185,8 @@ class WC_Widget_Products extends WC_Widget {
ob_start(); ob_start();
if ( ( $products = $this->get_products( $args, $instance ) ) && $products->have_posts() ) { $products = $this->get_products( $args, $instance );
if ( $products && $products->have_posts() ) {
$this->widget_start( $args, $instance ); $this->widget_start( $args, $instance );
echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' ) ); echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' ) );
@ -208,6 +208,6 @@ class WC_Widget_Products extends WC_Widget {
wp_reset_postdata(); wp_reset_postdata();
echo $this->cache_widget( $args, ob_get_clean() ); echo $this->cache_widget( $args, ob_get_clean() ); // WPCS: XSS ok.
} }
} }

View File

@ -1,18 +1,15 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Rating Filter Widget and related functions. * Rating Filter Widget and related functions.
* *
*
* @author WooThemes
* @category Widgets
* @package WooCommerce/Widgets * @package WooCommerce/Widgets
* @version 2.6.0 * @version 2.6.0
* @extends WC_Widget */
defined( 'ABSPATH' ) || exit;
/**
* Widget rating filter class.
*/ */
class WC_Widget_Rating_Filter extends WC_Widget { class WC_Widget_Rating_Filter extends WC_Widget {
@ -36,7 +33,8 @@ class WC_Widget_Rating_Filter extends WC_Widget {
/** /**
* Count products after other filters have occurred by adjusting the main query. * Count products after other filters have occurred by adjusting the main query.
* @param int $rating *
* @param int $rating Rating.
* @return int * @return int
*/ */
protected function get_filtered_product_count( $rating ) { protected function get_filtered_product_count( $rating ) {
@ -73,20 +71,20 @@ class WC_Widget_Rating_Filter extends WC_Widget {
$sql .= " WHERE {$wpdb->posts}.post_type = 'product' AND {$wpdb->posts}.post_status = 'publish' "; $sql .= " WHERE {$wpdb->posts}.post_type = 'product' AND {$wpdb->posts}.post_status = 'publish' ";
$sql .= $tax_query_sql['where'] . $meta_query_sql['where']; $sql .= $tax_query_sql['where'] . $meta_query_sql['where'];
if ( $search = WC_Query::get_main_search_query_sql() ) { $search = WC_Query::get_main_search_query_sql();
if ( $search ) {
$sql .= ' AND ' . $search; $sql .= ' AND ' . $search;
} }
return absint( $wpdb->get_var( $sql ) ); return absint( $wpdb->get_var( $sql ) ); // WPCS: unprepared SQL ok.
} }
/** /**
* widget function. * Widget function.
* *
* @see WP_Widget * @see WP_Widget
* * @param array $args Arguments.
* @param array $args * @param array $instance Widget instance.
* @param array $instance
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
if ( ! is_shop() && ! is_product_taxonomy() ) { if ( ! is_shop() && ! is_product_taxonomy() ) {
@ -100,7 +98,7 @@ class WC_Widget_Rating_Filter extends WC_Widget {
ob_start(); ob_start();
$found = false; $found = false;
$rating_filter = isset( $_GET['rating_filter'] ) ? array_filter( array_map( 'absint', explode( ',', $_GET['rating_filter'] ) ) ) : array(); $rating_filter = isset( $_GET['rating_filter'] ) ? array_filter( array_map( 'absint', explode( ',', wp_unslash( $_GET['rating_filter'] ) ) ) ) : array(); // WPCS: input var ok, CSRF ok, sanitization ok.
$this->widget_start( $args, $instance ); $this->widget_start( $args, $instance );
@ -114,18 +112,18 @@ class WC_Widget_Rating_Filter extends WC_Widget {
$found = true; $found = true;
$link = $this->get_current_page_url(); $link = $this->get_current_page_url();
if ( in_array( $rating, $rating_filter ) ) { if ( in_array( $rating, $rating_filter, true ) ) {
$link_ratings = implode( ',', array_diff( $rating_filter, array( $rating ) ) ); $link_ratings = implode( ',', array_diff( $rating_filter, array( $rating ) ) );
} else { } else {
$link_ratings = implode( ',', array_merge( $rating_filter, array( $rating ) ) ); $link_ratings = implode( ',', array_merge( $rating_filter, array( $rating ) ) );
} }
$class = in_array( $rating, $rating_filter ) ? 'wc-layered-nav-rating chosen' : 'wc-layered-nav-rating'; $class = in_array( $rating, $rating_filter, true ) ? 'wc-layered-nav-rating chosen' : 'wc-layered-nav-rating';
$link = apply_filters( 'woocommerce_rating_filter_link', $link_ratings ? add_query_arg( 'rating_filter', $link_ratings ) : remove_query_arg( 'rating_filter' ) ); $link = apply_filters( 'woocommerce_rating_filter_link', $link_ratings ? add_query_arg( 'rating_filter', $link_ratings ) : remove_query_arg( 'rating_filter' ) );
$rating_html = wc_get_star_rating_html( $rating ); $rating_html = wc_get_star_rating_html( $rating );
$count_html = esc_html( apply_filters( 'woocommerce_rating_filter_count', "({$count})", $count, $rating ) ); $count_html = esc_html( apply_filters( 'woocommerce_rating_filter_count', "({$count})", $count, $rating ) );
printf( '<li class="%s"><a href="%s"><span class="star-rating">%s</span> %s</a></li>', esc_attr( $class ), esc_url( $link ), $rating_html, $count_html ); printf( '<li class="%s"><a href="%s"><span class="star-rating">%s</span> %s</a></li>', esc_attr( $class ), esc_url( $link ), $rating_html, $count_html ); // WPCS: XSS ok.
} }
echo '</ul>'; echo '</ul>';
@ -135,7 +133,7 @@ class WC_Widget_Rating_Filter extends WC_Widget {
if ( ! $found ) { if ( ! $found ) {
ob_end_clean(); ob_end_clean();
} else { } else {
echo ob_get_clean(); echo ob_get_clean(); // WPCS: XSS ok.
} }
} }
} }

View File

@ -1,17 +1,15 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Recent Reviews Widget. * Recent Reviews Widget.
* *
* @author WooThemes
* @category Widgets
* @package WooCommerce/Widgets * @package WooCommerce/Widgets
* @version 2.3.0 * @version 2.3.0
* @extends WC_Widget */
defined( 'ABSPATH' ) || exit;
/**
* Widget recent reviews class.
*/ */
class WC_Widget_Recent_Reviews extends WC_Widget { class WC_Widget_Recent_Reviews extends WC_Widget {
@ -46,9 +44,8 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
* Output widget. * Output widget.
* *
* @see WP_Widget * @see WP_Widget
* * @param array $args Arguments.
* @param array $args * @param array $instance Widget instance.
* @param array $instance
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
global $comments, $comment; global $comments, $comment;
@ -60,7 +57,15 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
ob_start(); ob_start();
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std']; $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std'];
$comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product', 'parent' => 0 ) ); $comments = get_comments(
array(
'number' => $number,
'status' => 'approve',
'post_status' => 'publish',
'post_type' => 'product',
'parent' => 0,
)
); // WPCS: override ok.
if ( $comments ) { if ( $comments ) {
$this->widget_start( $args, $instance ); $this->widget_start( $args, $instance );
@ -77,12 +82,12 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
echo '<li><a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">'; echo '<li><a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">';
echo $_product->get_image() . wp_kses_post( $_product->get_name() ) . '</a>'; echo $_product->get_image() . wp_kses_post( $_product->get_name() ) . '</a>'; // WPCS: XSS ok.
echo $rating_html; echo $rating_html; // WPCS: XSS ok.
/* translators: %s: review author */ /* translators: %s: review author */
echo '<span class="reviewer">' . sprintf( esc_html__( 'by %s', 'woocommerce' ), get_comment_author() ) . '</span>'; echo '<span class="reviewer">' . sprintf( esc_html__( 'by %s', 'woocommerce' ), get_comment_author() ) . '</span>'; // WPCS: XSS ok.
echo '</li>'; echo '</li>';
} }
@ -94,7 +99,7 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
$content = ob_get_clean(); $content = ob_get_clean();
echo $content; echo $content; // WPCS: XSS ok.
$this->cache_widget( $args, $content ); $this->cache_widget( $args, $content );
} }

View File

@ -1,17 +1,15 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Recent Products Widget. * Recent Products Widget.
* *
* @author WooThemes
* @category Widgets
* @package WooCommerce/Widgets * @package WooCommerce/Widgets
* @version 3.3.0 * @version 3.3.0
* @extends WC_Widget */
defined( 'ABSPATH' ) || exit;
/**
* Widget recently viewed.
*/ */
class WC_Widget_Recently_Viewed extends WC_Widget { class WC_Widget_Recently_Viewed extends WC_Widget {
@ -46,13 +44,11 @@ class WC_Widget_Recently_Viewed extends WC_Widget {
* Output widget. * Output widget.
* *
* @see WP_Widget * @see WP_Widget
* * @param array $args Arguments.
* @param array $args * @param array $instance Widget instance.
* @param array $instance
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
$viewed_products = ! empty( $_COOKIE['woocommerce_recently_viewed'] ) ? (array) explode( '|', wp_unslash( $_COOKIE['woocommerce_recently_viewed'] ) ) : array(); // @codingStandardsIgnoreLine
$viewed_products = ! empty( $_COOKIE['woocommerce_recently_viewed'] ) ? (array) explode( '|', $_COOKIE['woocommerce_recently_viewed'] ) : array();
$viewed_products = array_reverse( array_filter( array_map( 'absint', $viewed_products ) ) ); $viewed_products = array_reverse( array_filter( array_map( 'absint', $viewed_products ) ) );
if ( empty( $viewed_products ) ) { if ( empty( $viewed_products ) ) {
@ -80,7 +76,7 @@ class WC_Widget_Recently_Viewed extends WC_Widget {
'terms' => 'outofstock', 'terms' => 'outofstock',
'operator' => 'NOT IN', 'operator' => 'NOT IN',
), ),
); ); // WPCS: slow query ok.
} }
$r = new WP_Query( apply_filters( 'woocommerce_recently_viewed_products_widget_query_args', $query_args ) ); $r = new WP_Query( apply_filters( 'woocommerce_recently_viewed_products_widget_query_args', $query_args ) );
@ -109,6 +105,6 @@ class WC_Widget_Recently_Viewed extends WC_Widget {
$content = ob_get_clean(); $content = ob_get_clean();
echo $content; echo $content; // WPCS: XSS ok.
} }
} }

View File

@ -1,18 +1,16 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Top Rated Products Widget. * Top Rated Products Widget.
* Gets and displays top rated products in an unordered list. * Gets and displays top rated products in an unordered list.
* *
* @author WooThemes
* @category Widgets
* @package WooCommerce/Widgets * @package WooCommerce/Widgets
* @version 3.3.0 * @version 3.3.0
* @extends WC_Widget */
defined( 'ABSPATH' ) || exit;
/**
* Widget top rated products class.
*/ */
class WC_Widget_Top_Rated_Products extends WC_Widget { class WC_Widget_Top_Rated_Products extends WC_Widget {
@ -47,9 +45,8 @@ class WC_Widget_Top_Rated_Products extends WC_Widget {
* Output widget. * Output widget.
* *
* @see WP_Widget * @see WP_Widget
* * @param array $args Arguments.
* @param array $args * @param array $instance Widget instance.
* @param array $instance
*/ */
public function widget( $args, $instance ) { public function widget( $args, $instance ) {
@ -71,7 +68,7 @@ class WC_Widget_Top_Rated_Products extends WC_Widget {
'order' => 'DESC', 'order' => 'DESC',
'meta_query' => WC()->query->get_meta_query(), 'meta_query' => WC()->query->get_meta_query(),
'tax_query' => WC()->query->get_tax_query(), 'tax_query' => WC()->query->get_tax_query(),
); ); // WPCS: slow query ok.
$r = new WP_Query( $query_args ); $r = new WP_Query( $query_args );
@ -100,7 +97,7 @@ class WC_Widget_Top_Rated_Products extends WC_Widget {
$content = ob_get_clean(); $content = ob_get_clean();
echo $content; echo $content; // WPCS: XSS ok.
$this->cache_widget( $args, $content ); $this->cache_widget( $args, $content );
} }