rebase on oct-10-2023

This commit is contained in:
Rachit Bhargava
2023-10-10 17:23:21 -04:00
parent d37566ffb6
commit d096058d7d
4789 changed files with 254611 additions and 307223 deletions

View File

@@ -253,6 +253,7 @@ class ArrayUtil {
return true;
}
$diff[ $key ] = $value;
continue;
}
$new_diff = self::deep_assoc_array_diff( $value, $array2[ $key ], $strict );
if ( ! empty( $new_diff ) ) {

View File

@@ -135,6 +135,39 @@ final class OrderUtil {
return wc_get_container()->get( PageController::class )->get_new_page_url();
}
/**
* Check if the current admin screen is an order list table.
*
* @param string $order_type Optional. The order type to check for. Default shop_order.
*
* @return bool
*/
public static function is_order_list_table_screen( $order_type = 'shop_order' ) : bool {
return wc_get_container()->get( PageController::class )->is_order_screen( $order_type, 'list' );
}
/**
* Check if the current admin screen is for editing an order.
*
* @param string $order_type Optional. The order type to check for. Default shop_order.
*
* @return bool
*/
public static function is_order_edit_screen( $order_type = 'shop_order' ) : bool {
return wc_get_container()->get( PageController::class )->is_order_screen( $order_type, 'edit' );
}
/**
* Check if the current admin screen is adding a new order.
*
* @param string $order_type Optional. The order type to check for. Default shop_order.
*
* @return bool
*/
public static function is_new_order_screen( $order_type = 'shop_order' ) : bool {
return wc_get_container()->get( PageController::class )->is_order_screen( $order_type, 'new' );
}
/**
* Get the name of the database table that's currently in use for orders.
*

View File

@@ -65,6 +65,9 @@ class PluginUtil {
*/
public function get_woocommerce_aware_plugins( bool $active_only = false ): array {
if ( is_null( $this->woocommerce_aware_plugins ) ) {
// In case `get_plugins` was called much earlier in the request (before our headers could be injected), we
// invalidate the plugin cache list.
wp_cache_delete( 'plugins', 'plugins' );
$all_plugins = $this->proxy->call_function( 'get_plugins' );
$this->woocommerce_aware_plugins =
@@ -168,4 +171,65 @@ class PluginUtil {
$this->woocommerce_aware_plugins = null;
$this->woocommerce_aware_active_plugins = null;
}
/**
* Util function to generate warning string for incompatible features based on active plugins.
*
* @param string $feature_id Feature id.
* @param array $plugin_feature_info Array of plugin feature info. See FeaturesControllers->get_compatible_plugins_for_feature() for details.
*
* @return string Warning string.
*/
public function generate_incompatible_plugin_feature_warning( string $feature_id, array $plugin_feature_info ) : string {
$feature_warning = '';
$incompatibles = array_merge( $plugin_feature_info['incompatible'], $plugin_feature_info['uncertain'] );
$incompatibles = array_filter( $incompatibles, 'is_plugin_active' );
$incompatible_count = count( $incompatibles );
if ( $incompatible_count > 0 ) {
if ( 1 === $incompatible_count ) {
/* translators: %s = printable plugin name */
$feature_warning = sprintf( __( '⚠ 1 Incompatible plugin detected (%s).', 'woocommerce' ), $this->get_plugin_name( $incompatibles[0] ) );
} elseif ( 2 === $incompatible_count ) {
$feature_warning = sprintf(
/* translators: %1\$s, %2\$s = printable plugin names */
__( '⚠ 2 Incompatible plugins detected (%1$s and %2$s).', 'woocommerce' ),
$this->get_plugin_name( $incompatibles[0] ),
$this->get_plugin_name( $incompatibles[1] )
);
} else {
$feature_warning = sprintf(
/* translators: %1\$s, %2\$s = printable plugin names, %3\$d = plugins count */
_n(
'⚠ Incompatible plugins detected (%1$s, %2$s and %3$d other).',
'⚠ Incompatible plugins detected (%1$s and %2$s plugins and %3$d others).',
$incompatible_count - 2,
'woocommerce'
),
$this->get_plugin_name( $incompatibles[0] ),
$this->get_plugin_name( $incompatibles[1] ),
$incompatible_count - 2
);
}
$incompatible_plugins_url = add_query_arg(
array(
'plugin_status' => 'incompatible_with_feature',
'feature_id' => $feature_id,
),
admin_url( 'plugins.php' )
);
$extra_desc_tip = '<br>' . sprintf(
/* translators: %1$s opening link tag %2$s closing link tag. */
__( '%1$sView and manage%2$s', 'woocommerce' ),
'<a href="' . esc_url( $incompatible_plugins_url ) . '">',
'</a>'
);
$feature_warning .= $extra_desc_tip;
}
return $feature_warning;
}
}

View File

@@ -104,4 +104,33 @@ final class StringUtil {
public static function is_null_or_whitespace( ?string $value ) {
return is_null( $value ) || '' === $value || ctype_space( $value );
}
/**
* Convert an array of values to a list suitable for a SQL "IN" statement
* (so comma separated and delimited by parenthesis).
* e.g.: [1,2,3] --> (1,2,3)
*
* @param array $values The values to convert.
* @return string A parenthesized and comma-separated string generated from the values.
* @throws \InvalidArgumentException Empty values array passed.
*/
public static function to_sql_list( array $values ) {
if ( empty( $values ) ) {
throw new \InvalidArgumentException( self::class_name_without_namespace( __CLASS__ ) . '::' . __FUNCTION__ . ': the values array is empty' );
}
return '(' . implode( ',', $values ) . ')';
}
/**
* Get the name of a class without the namespace.
*
* @param string $class_name The full class name.
* @return string The class name without the namespace.
*/
public static function class_name_without_namespace( string $class_name ) {
// A '?:' would convert this to a one-liner, but WP coding standards disallow these :shrug:.
$result = substr( strrchr( $class_name, '\\' ), 1 );
return $result ? $result : $class_name;
}
}