/** * Add to cart messages. * * @access public * @param int|array $products * @param bool $show_qty Should qty's be shown? Added in 2.6.0 */ function wc_add_to_cart_message($products, $show_qty = false) { $titles = array(); $count = 0; if (!is_array($products)) { $products = array($products); $show_qty = false; } if (!$show_qty && !is_array($products)) { $products = array_fill_keys(array_values($products), 1); } foreach ($products as $product_id => $qty) { $titles[] = ($qty > 1 ? absint($qty) . ' × ' : '') . sprintf(_x('“%s”', 'Item name in quotes', 'woocommerce'), strip_tags(get_the_title($product_id))); $count += $qty; } $titles = array_filter($titles); $added_text = sprintf(_n('%s has been added to your cart.', '%s have been added to your cart.', $count, 'woocommerce'), wc_format_list_of_items($titles)); // Output success messages if ('yes' === get_option('woocommerce_cart_redirect_after_add')) { $return_to = apply_filters('woocommerce_continue_shopping_redirect', wp_get_raw_referer() ? wp_validate_redirect(wp_get_raw_referer(), false) : wc_get_page_permalink('shop')); $message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', esc_url($return_to), esc_html__('Continue Shopping', 'woocommerce'), esc_html($added_text)); } else { $message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', esc_url(wc_get_page_permalink('cart')), esc_html__('View Cart', 'woocommerce'), esc_html($added_text)); } wc_add_notice(apply_filters('wc_add_to_cart_message', $message, $product_id)); }
/** * Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer. * * Do not use for redirects, use {@see wp_get_referer()} instead. * * @since 2.6.1 * @return string|false Referer URL on success, false on failure. */ function wc_get_raw_referer() { if (function_exists('wp_get_raw_referer')) { return wp_get_raw_referer(); } if (!empty($_REQUEST['_wp_http_referer'])) { return wp_unslash($_REQUEST['_wp_http_referer']); } elseif (!empty($_SERVER['HTTP_REFERER'])) { return wp_unslash($_SERVER['HTTP_REFERER']); } return false; }
/** * Retrieve referer from '_wp_http_referer' or HTTP referer. * * If it's the same as the current request URL, will return false. * * @since 2.0.4 * * @return false|string False on failure. Referer URL on success. */ function wp_get_referer() { if (!function_exists('wp_validate_redirect')) { return false; } $ref = wp_get_raw_referer(); if ($ref && $ref !== wp_unslash($_SERVER['REQUEST_URI']) && $ref !== home_url() . wp_unslash($_SERVER['REQUEST_URI'])) { return wp_validate_redirect($ref, false); } return false; }
/** * @ticket 27152 */ public function test_raw_referer_both() { $_SERVER['HTTP_REFERER'] = addslashes('http://example.com/foo?bar'); $_REQUEST['_wp_http_referer'] = addslashes('http://foo.bar/baz'); $this->assertSame('http://foo.bar/baz', wp_get_raw_referer()); }
/** * Check if request is an create or enable/disable redirection */ function on_admin_init() { $referer = wp_get_raw_referer(); // We only continue if referer contains page=redirection.php if (false === strpos($referer, "page=redirection.php")) { return; } $referer_parsed = parse_url($referer); error_log("-----"); // error_log( SimpleHistory::json_encode( $referer_parsed ) ); error_log(SimpleHistory::json_encode($_REQUEST)); /* Create redirection { "source": "source yo", "match": "url", "red_action": "url", "target": "dest yo", "group_id": "1", "add": "Add Redirection", "group": "0", "action": "red_redirect_add", "_wpnonce": "cdadb5a4ca", "_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php" } */ if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "red_redirect_add") { $this->log_redirection_add($_REQUEST); return; } /* Enable/disable single or multiple direction(s) { "page": "redirection.php", "_wpnonce": "290f261024", "_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php", "action": "enable", or "disable" "id": "0", "paged": "1", "item": [ "3", "2", "1" ], "action2": "-1" } */ if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "enable" && empty($_REQUEST["sub"])) { $this->log_redirection_enable_or_disable($_REQUEST); return; } else { if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "disable" && empty($_REQUEST["sub"])) { $this->log_redirection_enable_or_disable($_REQUEST); return; } } /* Delete item(s) { "page": "redirection.php", "edit": "4", "_wpnonce": "290f261024", "_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php&edit=4", "action": "delete", "id": "0", "paged": "1", "item": [ "6" ], "action2": "-1" } */ if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "delete" && empty($_REQUEST["sub"])) { $this->log_redirection_delete($_REQUEST); return; } /* Options - delete all options and deactivate plugin { "page": "redirection.php", "sub": "options", "_wpnonce": "e2c008ca25", "_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php&sub=options", "delete": "Delete" } */ if (isset($_REQUEST["sub"]) && $_REQUEST["sub"] == "options" && isset($_REQUEST["delete"]) && $_REQUEST["delete"] == "Delete") { $this->log_options_delete_all($_REQUEST); return; } /* Save options { "page": "redirection.php", "sub": "options", "_wpnonce": "8fe9b57662", "_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php&sub=options", "support": "on", "expire_redirect": "7", "expire_404": "7", "monitor_post": "0", "token": "acf88715b12038e3aca1ae1b3d82132a", "auto_target": "", "update": "Update" } */ if (isset($_REQUEST["sub"]) && $_REQUEST["sub"] == "options" && isset($_REQUEST["update"]) && $_REQUEST["update"] == "Update") { $this->log_options_save($_REQUEST); return; } /* Add group { "page": "redirection.php", "sub": "groups", "_wpnonce": "4cac237744", "_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php&sub=groups", "name": "new group yo", "module_id": "1", "add": "Add" } */ if (isset($_REQUEST["sub"]) && $_REQUEST["sub"] == "groups" && isset($_REQUEST["add"]) && $_REQUEST["add"] == "Add") { $this->log_group_add($_REQUEST); return; } /* Delete group(s) { "page": "redirection.php", "sub": "groups", "_wpnonce": "290f261024", "_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php&sub=groups", "action": "-1", "id": "0", "paged": "1", "item": [ "3", "2" ], "action2": "delete" } */ if (isset($_REQUEST["sub"]) && $_REQUEST["sub"] == "groups" && isset($_REQUEST["action"]) && $_REQUEST["action"] == "delete") { $this->log_group_delete($_REQUEST); return; } /* Disable group(s) { "path": "\/wp-admin\/tools.php", "query": "page=redirection.php&sub=groups" } { "page": "redirection.php", "sub": "groups", "_wpnonce": "290f261024", "_wp_http_referer": "\/wp-admin\/tools.php?page=redirection.php&sub=groups", "action": "disable", "id": "0", "paged": "1", "item": [ "1" ], "action2": "-1" } */ if (isset($_REQUEST["sub"]) && $_REQUEST["sub"] == "groups" && isset($_REQUEST["action"]) && $_REQUEST["action"] == "enable") { $this->log_group_enable_or_disable($_REQUEST); return; } else { if (isset($_REQUEST["sub"]) && $_REQUEST["sub"] == "groups" && isset($_REQUEST["action"]) && $_REQUEST["action"] == "disable") { $this->log_group_enable_or_disable($_REQUEST); return; } } }
/** * Since WP 4.5 em_wp_get_referer() returns false if URL is the same. We use it to get a safe referrer url, so we use the new wp_get_raw_referer() argument instead. * @since 5.6.3 * @return string */ function em_wp_get_referer() { if (function_exists('wp_get_raw_referer')) { //do essentially what em_wp_get_referer does, but potentially returning the same url as before return wp_validate_redirect(wp_get_raw_referer(), false); } else { return wp_get_referer(); } }