Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/staggs/admin/class-staggs-about.php
+++ b/staggs/admin/class-staggs-about.php
@@ -104,7 +104,7 @@
<div class="step-content">
<h3><?php esc_attr_e( 'Build your configurable product', 'staggs' ); ?></h3>
<p><?php esc_attr_e( 'The configurable products consists of the attributes, displayed in various ways using the attribute view templates.', 'staggs' ); ?></p>
- <?php if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) : ?>
+ <?php if ( staggs_is_woocommerce_active() ) : ?>
<a href="<?php echo esc_url( admin_url( '/post-new.php?post_type=product' ) ); ?>"><?php esc_attr_e( 'Add a new configurable product', 'staggs' ); ?></a>
<?php else : ?>
<a href="<?php echo esc_url( admin_url( '/post-new.php?post_type=sgg_product' ) ); ?>"><?php esc_attr_e( 'Add a new configurable product', 'staggs' ); ?></a>
--- a/staggs/admin/class-staggs-acf-fields.php
+++ b/staggs/admin/class-staggs-acf-fields.php
@@ -53,7 +53,7 @@
require STAGGS_BASE . '/admin/fields/acf/theme.php';
require STAGGS_BASE . '/admin/fields/acf/block.php';
- if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
+ if ( ! staggs_is_woocommerce_active() ) {
require STAGGS_BASE . '/admin/fields/acf/product.php';
}
--- a/staggs/admin/class-staggs-admin.php
+++ b/staggs/admin/class-staggs-admin.php
@@ -206,11 +206,12 @@
public function check_acf_pro_installation() {
// Decline button clicked.
if ( ! get_option( 'sgg_acf_pro_active' ) ) {
- if ( isset( $_GET['action'] ) && $_GET['action'] === 'decline-acf' ) {
+ if ( isset( $_GET['action'] ) && 'decline-acf' === $_GET['action'] && current_user_can( 'manage_options' )
+ && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'staggs_acf_action' ) ) {
update_option( 'sgg_acf_pro_active', 'disabled' );
}
- if ( isset( $_GET['migrate'] ) && 'success' === esc_attr( $_GET['migrate'] ) ) {
+ if ( isset( $_GET['migrate'] ) && 'success' === sanitize_text_field( wp_unslash( $_GET['migrate'] ) ) ) {
?>
<div class="notice notice-success is-dismissible">
<p><?php esc_attr_e( 'Migrate successful! Your Staggs admin fields now consist of ACF fields. Enjoy!', 'staggs' ); ?></p>
@@ -222,7 +223,7 @@
return;
}
- if ( esc_attr( $_GET['post_type'] ) !== 'sgg_attribute' && esc_attr( $_GET['post_type'] ) !== 'sgg_theme' ) {
+ if ( sanitize_key( $_GET['post_type'] ) !== 'sgg_attribute' && sanitize_key( $_GET['post_type'] ) !== 'sgg_theme' ) {
return;
}
@@ -249,14 +250,15 @@
?>
</p>
<div class="notice-buttons">
- <a href="<?php echo esc_url( admin_url( 'edit.php?post_type=sgg_attribute&page=dashboard&action=migrate-acf' ) ); ?>" class="button button-primary"><?php esc_attr_e( 'Migrate to ACF fields', 'staggs' ); ?></a>
- <a href="<?php echo esc_url( admin_url( 'edit.php?post_type=sgg_attribute&page=dashboard&action=decline-acf' ) ); ?>" class="button"><?php esc_attr_e( 'No thanks', 'staggs' ); ?></a>
+ <a href="<?php echo esc_url( wp_nonce_url( admin_url( 'edit.php?post_type=sgg_attribute&page=dashboard&action=migrate-acf' ), 'staggs_acf_action' ) ); ?>" class="button button-primary"><?php esc_attr_e( 'Migrate to ACF fields', 'staggs' ); ?></a>
+ <a href="<?php echo esc_url( wp_nonce_url( admin_url( 'edit.php?post_type=sgg_attribute&page=dashboard&action=decline-acf' ), 'staggs_acf_action' ) ); ?>" class="button"><?php esc_attr_e( 'No thanks', 'staggs' ); ?></a>
</div>
</div>
</div>
<?php
// Migrate button clicked.
- if ( isset( $_GET['action'] ) && $_GET['action'] === 'migrate-acf' ) {
+ if ( isset( $_GET['action'] ) && 'migrate-acf' === $_GET['action'] && current_user_can( 'manage_options' )
+ && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'staggs_acf_action' ) ) {
define( 'STAGGS_ACF', '1' );
define( 'STAGGS_RUN_MIGRATE', '1' );
@@ -354,7 +356,7 @@
)
);
- if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
+ if ( ! staggs_is_woocommerce_active() ) {
$actions[] = array(
'url' => admin_url( 'edit.php?post_type=sgg_product' ),
'type' => 'sgg_product',
--- a/staggs/admin/class-staggs-analytics-table.php
+++ b/staggs/admin/class-staggs-analytics-table.php
@@ -83,7 +83,7 @@
array_multisort($keys, $sort, $product_rows);
}
- set_transient( 'staggs_total_results', $product_rows );
+ set_transient( 'staggs_total_results', $product_rows, HOUR_IN_SECONDS );
// Pagination.
$offset = ($page_number - 1) * $per_page;
@@ -234,7 +234,7 @@
);
}
- set_transient( 'staggs_analytics_order_' . $order->get_id(), $order_item_rows );
+ set_transient( 'staggs_analytics_order_' . $order->get_id(), $order_item_rows, DAY_IN_SECONDS );
}
endforeach;
--- a/staggs/admin/class-staggs-analytics.php
+++ b/staggs/admin/class-staggs-analytics.php
@@ -41,7 +41,7 @@
* @since 1.3.4
*/
public function register_sub_menu() {
- if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
+ if ( staggs_is_woocommerce_active() ) {
$hook = add_submenu_page(
'edit.php?post_type=sgg_attribute',
__( 'Analytics', 'staggs' ),
@@ -250,7 +250,7 @@
if ( isset( $query ) && $query->is_main_query() ) {
if ( $query->is_admin && $pagenow == 'edit.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'shop_order' && isset( $_GET['order_ids'] ) && '' !== $_GET['order_ids'] ) {
- $order_ids = esc_attr( explode( ',', $_GET['order_ids'] ) );
+ $order_ids = array_filter( array_map( 'absint', explode( ',', sanitize_text_field( wp_unslash( $_GET['order_ids'] ) ) ) ) );
$query->set( 'post__in', $order_ids );
}
}
--- a/staggs/admin/class-staggs-dashboard.php
+++ b/staggs/admin/class-staggs-dashboard.php
@@ -96,7 +96,7 @@
</a>
</div>
<div class="staggs-page-list-item">
- <?php if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) : ?>
+ <?php if ( staggs_is_woocommerce_active() ) : ?>
<a href="<?php echo esc_url( admin_url( '/edit.php?post_type=product' ) ); ?>">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M5 22h14a2 2 0 0 0 2-2V9a1 1 0 0 0-1-1h-3v-.777c0-2.609-1.903-4.945-4.5-5.198A5.005 5.005 0 0 0 7 7v1H4a1 1 0 0 0-1 1v11a2 2 0 0 0 2 2zm12-12v2h-2v-2h2zM9 7c0-1.654 1.346-3 3-3s3 1.346 3 3v1H9V7zm-2 3h2v2H7v-2z"></path></svg>
<?php esc_attr_e( 'Manage products', 'staggs' ); ?>
@@ -126,7 +126,7 @@
<?php esc_attr_e( 'Manage templates', 'staggs' ); ?>
</a>
</div>
- <?php if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) : ?>
+ <?php if ( staggs_is_woocommerce_active() ) : ?>
<div class="staggs-page-list-item">
<a href="<?php echo esc_url( admin_url( '/edit.php?post_type=sgg_attribute&page=analytics' ) ); ?>">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12 2C6.486 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.514 2 12 2zm7.931 9H13V4.069A8.008 8.008 0 0 1 19.931 11zM4 12c0-4.072 3.061-7.436 7-7.931V12a.996.996 0 0 0 .111.438c.015.03.022.063.041.093l4.202 6.723A7.949 7.949 0 0 1 12 20c-4.411 0-8-3.589-8-8zm13.052 6.196L13.805 13h6.126a7.992 7.992 0 0 1-2.879 5.196z"></path></svg>
@@ -174,7 +174,7 @@
</div>
</div>
</div>
- <?php if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) : ?>
+ <?php if ( staggs_is_woocommerce_active() ) : ?>
<div class="staggs-page-column">
<div class="staggs-page-article<?php echo esc_attr( $pro_class ); ?>">
<h3><?php esc_attr_e( 'WooCommerce linked options', 'staggs' ); ?><span><?php echo esc_attr( $pro_label ); ?></span></h3>
@@ -221,7 +221,7 @@
<p><?php esc_attr_e( 'Control the appearance of your configurators', 'staggs' ); ?></p>
<div class="staggs-page-row">
- <?php if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) : ?>
+ <?php if ( staggs_is_woocommerce_active() ) : ?>
<div class="staggs-page-column">
<div class="staggs-page-article">
<h3><?php esc_attr_e( 'Configurator shortcode display', 'staggs' ); ?></h3>
--- a/staggs/admin/fields/acf/settings.php
+++ b/staggs/admin/fields/acf/settings.php
@@ -1782,7 +1782,7 @@
),
);
-if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
+if ( ! staggs_is_woocommerce_active() ) {
array_merge(
$setting_fields,
array(
--- a/staggs/admin/fields/carbon/settings.php
+++ b/staggs/admin/fields/carbon/settings.php
@@ -21,7 +21,7 @@
Field::make( 'separator', 'sgg_setting_price_tab_label', __( 'Price settings', 'staggs' ) ),
);
-if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
+if ( ! staggs_is_woocommerce_active() ) {
array_push( $price_fields,
Field::make( 'select', 'sgg_price_currency_pos', __( 'Currency position', 'staggs' ) )
->set_help_text( __( 'Select the position of the currency symbol', 'staggs' ) )
--- a/staggs/includes/class-staggs-attribute.php
+++ b/staggs/includes/class-staggs-attribute.php
@@ -611,12 +611,17 @@
{
global $wpdb;
- $file_name = esc_attr(basename($image_url));
+ $file_name = sanitize_file_name(basename($image_url));
$wp_filetype = wp_check_filetype($file_name, null);
- $image_name = str_replace( '.' . $wp_filetype['ext'], '', $file_name);
+ $image_name = $wp_filetype['ext'] ? preg_replace( '/.' . preg_quote( $wp_filetype['ext'], '/' ) . '$/', '', $file_name ) : $file_name;
- $query = sprintf("SELECT `ID` FROM %s WHERE `post_type`='attachment' AND (`post_name`='%s' OR `guid`='%s')", $wpdb->posts, $image_name, $image_url);
- $image_id = intval($wpdb->get_var($query));
+ $image_id = (int) $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND ( post_name = %s OR guid = %s ) LIMIT 1",
+ $image_name,
+ $image_url
+ )
+ );
if (0 === (int) $image_id && $image_url) {
try {
$image_id = self::download_image( $image_url );
@@ -641,15 +646,35 @@
require_once ABSPATH . 'wp-admin/includes/image.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
- $filename = basename($imageurl);
+ $imageurl = esc_url_raw( $imageurl, array( 'http', 'https' ) );
+ if ( ! $imageurl ) {
+ throw new Exception( 'Invalid image URL' );
+ }
+
+ // Only images may be imported.
+ $filename = sanitize_file_name( basename( wp_parse_url( $imageurl, PHP_URL_PATH ) ) );
+ $checked = wp_check_filetype( $filename );
+ if ( ! $checked['ext'] || 0 !== strpos( (string) $checked['type'], 'image/' ) ) {
+ throw new Exception( 'Invalid image type' );
+ }
+
$uploaddir = wp_upload_dir();
- $uploadfile = $uploaddir['path'] . '/' . $filename;
-
- $data = wp_remote_get($imageurl);
+ $filename = wp_unique_filename( $uploaddir['path'], $filename );
+ $uploadfile = $uploaddir['path'] . '/' . $filename;
+
+ // wp_safe_remote_get refuses requests to internal hosts (SSRF protection).
+ $data = wp_safe_remote_get( $imageurl, array( 'timeout' => 20, 'limit_response_size' => 20 * MB_IN_BYTES ) );
if ( is_wp_error( $data ) ) {
throw new Exception( esc_attr( $data->get_error_message() ) );
}
- $contents = $data['body'];
+ $contents = wp_remote_retrieve_body( $data );
+
+ // The downloaded bytes must really be an image (SVG is not detected by getimagesize, check its markup instead).
+ $is_svg = 'svg' === strtolower( (string) $checked['ext'] );
+ $is_image = $is_svg ? ( false !== stripos( $contents, '<svg' ) ) : (bool) @getimagesizefromstring( $contents );
+ if ( 200 !== (int) wp_remote_retrieve_response_code( $data ) || '' === $contents || ! $is_image ) {
+ throw new Exception( 'Downloaded file is not a valid image' );
+ }
if ( ! $wp_filesystem ) {
WP_Filesystem();
--- a/staggs/includes/class-staggs-cron.php
+++ b/staggs/includes/class-staggs-cron.php
@@ -32,7 +32,7 @@
}
if ( ! wp_next_scheduled( 'staggs_cleanup_garbage_files' ) ) {
- wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'staggs_cleanup_garbage_files');
+ wp_schedule_event( time(), 'hourly', 'staggs_cleanup_garbage_files');
}
}
@@ -56,6 +56,10 @@
if ('json' !== $fileInfo->getExtension()) {
continue; // Only remove saved configuration JSON files.
}
+
+ if (0 === strpos($fileInfo->getFilename(), 'keep-')) {
+ continue; // Permanent configurations (wishlist items, order PDF links).
+ }
if ($fileInfo->isFile() && time() - $fileInfo->getCTime() >= $timecheck) {
unlink($fileInfo->getRealPath());
--- a/staggs/includes/class-staggs-safe-eval.php
+++ b/staggs/includes/class-staggs-safe-eval.php
@@ -0,0 +1,281 @@
+<?php
+
+/**
+ * Safe evaluation of price formulas.
+ *
+ * Replaces eval() for formulas. Supports the PHP expression subset that formulas can
+ * contain once all keys are replaced by numbers: arithmetic (+ - * / % **), comparison,
+ * logical operators and the ternary operator, with PHP's own type semantics.
+ * Anything else (function calls, variables, statements, ...) evaluates to 0.
+ *
+ * @package Staggs
+ * @subpackage Staggs/includes
+ * @since 3.3.0
+ */
+
+if ( ! defined( 'ABSPATH' ) ) exit;
+
+if ( ! class_exists( 'Staggs_Safe_Eval' ) ) {
+
+ class Staggs_Safe_Eval {
+
+ private $tokens = array();
+ private $pos = 0;
+ private $count = 0;
+ private $depth = 0;
+ private $skip = 0; // > 0 while parsing a branch PHP would not evaluate (short-circuit / ternary).
+
+ /**
+ * Evaluate an expression. Returns 0 for invalid expressions.
+ *
+ * @param string|int|float $expression Expression.
+ * @return int|float
+ */
+ public static function run( $expression ) {
+ if ( is_int( $expression ) || is_float( $expression ) ) {
+ return $expression;
+ }
+
+ $expression = preg_replace( '/s+/', '', (string) $expression );
+ if ( '' === $expression || strlen( $expression ) > 2000 ) {
+ return 0;
+ }
+
+ $matched = preg_match_all( '/d+.?d*|.d+|===|!==|==|!=|<=|>=|&&||||**|[-+*/%()<>!?:]/', $expression, $matches );
+ if ( ! $matched || implode( '', $matches[0] ) !== $expression ) {
+ return 0;
+ }
+
+ $parser = new self();
+ $parser->tokens = $matches[0];
+ $parser->count = count( $parser->tokens );
+
+ try {
+ $result = $parser->ternary();
+ if ( $parser->pos !== $parser->count ) {
+ return 0;
+ }
+ } catch ( Exception $e ) {
+ return 0;
+ }
+
+ if ( is_bool( $result ) ) {
+ return (int) $result;
+ }
+
+ return ( is_finite( $result ) ) ? $result : 0;
+ }
+
+ /**
+ * Error in an expression. Fatal for the whole formula, except in a branch PHP would not
+ * have evaluated anyway (then the value is irrelevant).
+ */
+ private function fail() {
+ if ( $this->skip > 0 ) {
+ return 0;
+ }
+ throw new Exception( 'Invalid expression' );
+ }
+
+ private function peek() {
+ return $this->pos < $this->count ? $this->tokens[ $this->pos ] : null;
+ }
+
+ private function accept( $token ) {
+ if ( $this->peek() === $token ) {
+ $this->pos++;
+ return true;
+ }
+ return false;
+ }
+
+ private function ternary() {
+ $condition = $this->logical_or();
+
+ if ( $this->accept( '?' ) ) {
+ if ( $this->accept( ':' ) ) {
+ // Short ternary: a ?: b.
+ $this->skip += $condition ? 1 : 0;
+ $else = $this->ternary();
+ $this->skip -= $condition ? 1 : 0;
+ return $condition ?: $else;
+ }
+ $this->skip += $condition ? 0 : 1;
+ $then = $this->ternary();
+ $this->skip -= $condition ? 0 : 1;
+ if ( ! $this->accept( ':' ) ) {
+ throw new Exception( 'Expected :' );
+ }
+ $this->skip += $condition ? 1 : 0;
+ $else = $this->ternary();
+ $this->skip -= $condition ? 1 : 0;
+ return $condition ? $then : $else;
+ }
+
+ return $condition;
+ }
+
+ private function logical_or() {
+ $value = $this->logical_and();
+ while ( $this->accept( '||' ) ) {
+ $this->skip += $value ? 1 : 0;
+ $rhs = $this->logical_and();
+ $this->skip -= $value ? 1 : 0;
+ $value = ( $value || $rhs );
+ }
+ return $value;
+ }
+
+ private function logical_and() {
+ $value = $this->equality();
+ while ( $this->accept( '&&' ) ) {
+ $this->skip += $value ? 0 : 1;
+ $rhs = $this->equality();
+ $this->skip -= $value ? 0 : 1;
+ $value = ( $value && $rhs );
+ }
+ return $value;
+ }
+
+ private function equality() {
+ $value = $this->comparison();
+ while ( in_array( $this->peek(), array( '==', '!=', '===', '!==' ), true ) ) {
+ $op = $this->tokens[ $this->pos++ ];
+ $rhs = $this->comparison();
+ switch ( $op ) {
+ case '==':
+ $value = ( $value == $rhs );
+ break;
+ case '!=':
+ $value = ( $value != $rhs );
+ break;
+ case '===':
+ $value = ( $value === $rhs );
+ break;
+ default:
+ $value = ( $value !== $rhs );
+ }
+ }
+ return $value;
+ }
+
+ private function comparison() {
+ $value = $this->additive();
+ while ( in_array( $this->peek(), array( '<', '<=', '>', '>=' ), true ) ) {
+ $op = $this->tokens[ $this->pos++ ];
+ $rhs = $this->additive();
+ switch ( $op ) {
+ case '<':
+ $value = ( $value < $rhs );
+ break;
+ case '<=':
+ $value = ( $value <= $rhs );
+ break;
+ case '>':
+ $value = ( $value > $rhs );
+ break;
+ default:
+ $value = ( $value >= $rhs );
+ }
+ }
+ return $value;
+ }
+
+ private function additive() {
+ $value = $this->multiplicative();
+ while ( in_array( $this->peek(), array( '+', '-' ), true ) ) {
+ $op = $this->tokens[ $this->pos++ ];
+ $rhs = $this->multiplicative();
+ $value = ( '+' === $op ) ? ( $value + $rhs ) : ( $value - $rhs );
+ }
+ return $value;
+ }
+
+ private function multiplicative() {
+ $value = $this->unary();
+ while ( in_array( $this->peek(), array( '*', '/', '%' ), true ) ) {
+ $op = $this->tokens[ $this->pos++ ];
+ $rhs = $this->unary();
+ if ( '*' === $op ) {
+ $value = $value * $rhs;
+ } elseif ( '/' === $op ) {
+ if ( 0 == $rhs ) {
+ $value = $this->fail(); // Division by zero.
+ continue;
+ }
+ $value = $value / $rhs;
+ } else {
+ if ( 0 === (int) $rhs ) {
+ $value = $this->fail(); // Modulo by zero.
+ continue;
+ }
+ $value = (int) $value % (int) $rhs;
+ }
+ }
+ return $value;
+ }
+
+ private function unary() {
+ if ( $this->accept( '!' ) ) {
+ return ! $this->unary();
+ }
+ if ( $this->accept( '-' ) ) {
+ return -$this->unary();
+ }
+ if ( $this->accept( '+' ) ) {
+ return +$this->unary();
+ }
+ return $this->power();
+ }
+
+ private function power() {
+ $base = $this->primary();
+ if ( $this->accept( '**' ) ) {
+ $exponent = $this->unary(); // Right associative, binds tighter than unary on its left.
+ return @( $base ** $exponent ); // 0 ** -n gives INF (with a deprecation notice on newer PHP).
+ }
+ return $base;
+ }
+
+ private function primary() {
+ $token = $this->peek();
+ if ( null === $token ) {
+ throw new Exception( 'Unexpected end' );
+ }
+
+ if ( '(' === $token ) {
+ if ( ++$this->depth > 50 ) {
+ throw new Exception( 'Too deep' );
+ }
+ $this->pos++;
+ $value = $this->ternary();
+ if ( ! $this->accept( ')' ) ) {
+ throw new Exception( 'Expected )' );
+ }
+ $this->depth--;
+ return $value;
+ }
+
+ if ( is_numeric( $token ) ) {
+ $this->pos++;
+ return 0 + $token; // int or float, like PHP's own parser.
+ }
+
+ throw new Exception( 'Unexpected token' );
+ }
+ }
+}
+
+if ( ! function_exists( 'staggs_safe_eval' ) ) {
+ /**
+ * Safely evaluate a price formula without using eval().
+ *
+ * @since 3.3.0
+ *
+ * @param string|int|float $expression Arithmetic expression.
+ * @return int|float
+ */
+ function staggs_safe_eval( $expression ) {
+ return Staggs_Safe_Eval::run( $expression );
+ }
+}
--- a/staggs/includes/class-staggs.php
+++ b/staggs/includes/class-staggs.php
@@ -304,7 +304,7 @@
$this->loader->add_action( 'carbon_fields_register_fields', $plugin_fields, 'sgg_appearance_page_options' );
$this->loader->add_action( 'carbon_fields_register_fields', $plugin_fields, 'sgg_init_product_configurator_options' );
- if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
+ if ( ! staggs_is_woocommerce_active() ) {
$this->loader->add_action( 'carbon_fields_register_fields', $plugin_fields, 'sgg_product_fields' );
}
}
@@ -326,7 +326,7 @@
$this->loader->add_action( 'save_post_sgg_product', $plugin_attribute, 'clear_builder_transients' );
$this->loader->add_action( 'save_post_product', $plugin_attribute, 'clear_builder_transients' );
- if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
+ if ( ! staggs_is_woocommerce_active() ) {
/**
* Product configurator hooks.
@@ -496,6 +496,8 @@
$this->loader->add_filter( 'woocommerce_order_item_thumbnail', $plugin_cart, 'replace_product_image_in_order_emails', 20, 2 );
$this->loader->add_action( 'woocommerce_thankyou', $plugin_cart, 'delete_images_on_thankyou_page', 20, 1 );
+ $this->loader->add_action( 'woocommerce_checkout_order_processed', $plugin_cart, 'create_as_image_cleanup_action', 20, 1 );
+ $this->loader->add_action( 'sgg_delete_order_images', $plugin_cart, 'delete_order_images', 10, 1 );
$this->loader->add_action( 'woocommerce_checkout_create_order_line_item', $plugin_cart, 'staggs_save_order_meta', 20, 4 );
$this->loader->add_action( 'woocommerce_checkout_update_order_meta', $plugin_cart, 'staggs_update_order_meta', 20, 1 );
--- a/staggs/includes/staggs-functions.php
+++ b/staggs/includes/staggs-functions.php
@@ -12,6 +12,8 @@
if ( ! defined( 'ABSPATH' ) ) exit;
+require_once __DIR__ . '/class-staggs-safe-eval.php';
+
if ( ! function_exists( 'staggs_write_file' ) ) {
/**
* Write contents to a file and enforce standard WordPress file permissions.
@@ -93,6 +95,76 @@
}
}
+if ( ! function_exists( 'staggs_get_storage_dir' ) ) {
+ /**
+ * Get (and prepare) the directory used to store configurator files.
+ * Adds an empty index file so the directory can not be listed.
+ *
+ * @since 3.3.0
+ */
+ function staggs_get_storage_dir() {
+ $upload_dir = wp_get_upload_dir();
+ $save_path = apply_filters( 'staggs_image_save_dir', $upload_dir['basedir'] . '/staggs' );
+
+ if ( ! file_exists( $save_path ) ) {
+ staggs_mkdir( $save_path );
+ }
+
+ if ( is_dir( $save_path ) && is_writable( $save_path ) ) {
+ $index = trailingslashit( $save_path ) . 'index.php';
+ if ( ! file_exists( $index ) ) {
+ @file_put_contents( $index, "<?phpn// Silence is golden.n" );
+ }
+ }
+
+ return $save_path;
+ }
+}
+
+if ( ! function_exists( 'staggs_url_to_storage_path' ) ) {
+ /**
+ * Convert a URL of a file inside the staggs storage folder to its absolute
+ * path. Returns false when the URL does not point to an existing regular
+ * file located directly inside the storage folder.
+ *
+ * @since 3.3.0
+ */
+ function staggs_url_to_storage_path( $url ) {
+ if ( ! is_string( $url ) || '' === $url ) {
+ return false;
+ }
+
+ $url = strtok( $url, '?#' );
+ $dir = realpath( staggs_get_storage_dir() );
+ if ( ! $dir ) {
+ return false;
+ }
+
+ $name = wp_basename( rawurldecode( $url ) );
+ if ( '' === $name || '.' === $name[0] || false !== strpos( $name, "