installed plugin Easy Digital Downloads
version 3.1.0.3
This commit is contained in:
wp-content/plugins/easy-digital-downloads
assets
css
admin
chosen
datepicker.scssdownloads
email-tags.scssextension-manager.scssforms
gateways
general
menu.scssnotifications
orders
promos
reports
style.scsstax-rates
upgrades
variables
vendor
images
edd-cpt-2x.pngedd-cpt.pngedd-cross-hair.pngedd-icon-2x.pngedd-icon.pngedd-logo-pdf.pngedd-logo-white-2x.pngedd-logo.pngedd-logo.svgedd-media.pngedd-peeking.png
icons
icon-arrow-down.pngicon-arrow-up.pngicon-average.pngicon-chevron-down.svgicon-gross.pngicon-megaphone.pngicon-net.pngicon-new-customers.pngicon-top-products.pngiphone.png
loading.giflogo-edd-dark.svgmedia-button.pngpromo
screenshots
17checkout.png17direct.png17quantities.png18-button-colors.png18cart-saving.png20-discount.png20-register-login.png20-sequential.png20-unlimited-downloads.png22-logs.png22-purchased-downloads.png22-purchased-downloads2.png22-quantity.png24-category-earnings.png24-checkout.png24-export.png26-customer.png26-import.png26-refund.pngbundles.pngcustomer-ui.pngedit-download.pngemail-template-21.pnggrid.pngorder-details.pngproduct-earnings.pngproduct-tax.pngpurchase-link.pngtax-rates.png
ui-icons_21759b_256x240.pngui-icons_333333_256x240.pngui-icons_999999_256x240.pngui-icons_cc0000_256x240.pngxit.gifjs
admin
components
advanced-filters
chosen
date-picker
location
notifications
promos
sortable-list
taxonomies
tooltips
user-search
vertical-sections
customers
dashboard
discounts
downloads
index.jsnotes
notices
orders
index.jslist-table.js
order-details
order-overview
_refund.js
collections
index.jsmodels
views
actions.jsbase.jscopy-download-link.jsdialog.jsform-add-order-adjustment.jsform-add-order-discount.jsform-add-order-item.jsno-order-items.jsorder-adjustment.jsorder-adjustments.jsorder-credits.jsorder-discounts-fees.jsorder-item.jsorder-items.jsorder-refund.jsorder-refunds.jsorder-subtotal.jsorder-tax.jsorder-total.jsoverview.jssummary.js
payments
reports
settings
tools
upgrades
frontend
jquery.validate.min.jspackages
paypal-checkout.jsutils
vendor
chartjs.min.jschosen.jquery.min.jsjquery.creditcardvalidator.min.jsjquery.flot.min.jsjquery.flot.pie.min.jsjquery.flot.time.min.jsjquery.payment.min.jsmoment-timezone.min.jsmoment.min.js
wp-polyfill.min.jsincludes
EDD_SL_Plugin_Updater.phpactions.phpedd-blocks.phpmime-types.phpmisc-functions.php
adjustments
admin
add-ons.php
ajax-functions.phpadjustments
admin-actions.phpadmin-bar.phpadmin-deprecated-functions.phpadmin-footer.phpadmin-pages.phpclass-api-keys-table.phpclass-edd-heartbeat.phpclass-edd-notices.phpclass-list-table.phpclass-pass-manager.phpclass-sections.phpcustomers
class-customer-addresses-table.phpclass-customer-email-addresses-table.phpclass-customer-table.phpcustomer-actions.phpcustomer-functions.phpcustomers.php
dashboard-widgets.phpdiscounts
add-discount.phpclass-discount-codes-table.phpcontextual-help.phpdiscount-actions.phpdiscount-codes.phpedit-discount.php
downloads
emails
email-summary
extensions
abstract-extension.phpclass-extension-manager.phpclass-extension-product-data.phpclass-extensions-api.php
product-education
import
class-batch-import-downloads.phpclass-batch-import-payments.phpclass-batch-import.phpimport-actions.phpimport-functions.php
installers
notes
payments
actions.phpadd-order.phpclass-order-sections.phpclass-payments-table.phpclass-refund-items-table.phpcontextual-help.phporders.phppayments-history.phprefunds.phpview-order-details.phpview-refund.php
plugins.phppromos
reporting
class-api-requests-logs-list-table.phpclass-base-logs-list-table.phpclass-categories-reports-table.phpclass-download-reports-table.phpclass-edd-graph.phpclass-edd-pie-graph.phpclass-export-customers.phpclass-export-download-history.phpclass-export-payments.phpclass-export.phpclass-file-downloads-logs-list-table.phpclass-gateway-error-logs-list-table.phpclass-gateways-reports-table.phpclass-reports-sections.phpclass-sales-logs-list-table.phpcontextual-help.php
export
class-batch-export-api-requests.phpclass-batch-export-customers.phpclass-batch-export-downloads.phpclass-batch-export-earnings-report.phpclass-batch-export-file-downloads.phpclass-batch-export-payments.phpclass-batch-export-sales-and-earnings.phpclass-batch-export-sales.phpclass-batch-export-taxed-customers.phpclass-batch-export-taxed-orders.phpclass-batch-export.phpexport-actions.phpexport-functions.php
graphing.phplogs.phpreports-callbacks.phpreports.phpsettings
thickbox.phptools.phptools
class-edd-tools-recount-all-stats.phpclass-edd-tools-recount-customer-stats.phpclass-edd-tools-recount-download-stats.phpclass-edd-tools-recount-single-customer-stats.phpclass-edd-tools-recount-store-earnings.phpclass-edd-tools-reset-stats.phplogs.phptools-actions.php
tracking.phpupgrades
upload-functions.phpviews
notifications.phptmpl-order-actions.phptmpl-order-adjustment-discount.phptmpl-order-adjustment.phptmpl-order-copy-download-link.phptmpl-order-form-add-order-adjustment.phptmpl-order-form-add-order-discount.phptmpl-order-form-add-order-item.phptmpl-order-item.phptmpl-order-no-items.phptmpl-order-refund.phptmpl-order-subtotal.phptmpl-order-tax.phptmpl-order-total.phptmpl-tax-rates-table-add.phptmpl-tax-rates-table-bulk-actions.phptmpl-tax-rates-table-meta.phptmpl-tax-rates-table-row-empty.phptmpl-tax-rates-table-row.php
api
blocks
assets
build
buy-button
cart
checkout
confirmation
downloads
login
order-history
receipt
register
terms
includes
readme.mdviews
checkout
cart
cart-discounts.phpcart-fees.phpcart-footer-row.phpcart-item.phpcart-subtotal.phpcart-taxes.phpcart-total.phpcart.phpmini.php
discount.phplogged-in.phppurchase-form
downloads
forms
orders
credits.phpdiscounts.phpfees.phpguest.phporders.phppagination.phpreceipt-files.phpreceipt-item.phpreceipt-items.phptotals.php
terms.phpcart
checkout
class-base-object.phpclass-component.phpclass-easy-digital-downloads.phpclass-edd-cache-helper.phpclass-edd-cli.phpclass-edd-cron.phpclass-edd-customer-query.phpclass-edd-customer.phpclass-edd-db-customer-meta.phpclass-edd-db-customers.phpclass-edd-db.phpclass-edd-discount.phpclass-edd-download.phpclass-edd-fees.phpclass-edd-html-elements.phpclass-edd-license-handler.phpclass-edd-logging.phpclass-edd-register-meta.phpclass-edd-roles.phpclass-edd-session.phpclass-edd-stats.phpclass-stats.phpclass-structured-data.phpclass-utilities.phpcompat-functions.phpcompat
class-base.phpclass-customer.phpclass-customermeta.phpclass-discount-query.phpclass-discount.phpclass-edd-payment-compat.phpclass-log.phpclass-payment.phpclass-tax.phpclass-template.php
component-functions.phpcountry-functions.phpcurrency
customer-functions.phpcustomers
database
NotificationsDB.phpREADME.md
date-functions.phpdeprecated-functions.phpdeprecated-hooks.phpdiscount-functions.phpdownload-functions.phpengine
class-base.phpclass-column.phpclass-compare.phpclass-date.phpclass-meta.phpclass-query.phpclass-row.phpclass-schema.phpclass-table.php
queries
class-adjustment.phpclass-customer-address.phpclass-customer-email-address.phpclass-customer.phpclass-log-api-request.phpclass-log-file-download.phpclass-log.phpclass-note.phpclass-order-address.phpclass-order-adjustment.phpclass-order-item.phpclass-order-transaction.phpclass-order.php
rows
class-adjustment.phpclass-customer-address.phpclass-customer-email-address.phpclass-customer.phpclass-log-api-request.phpclass-log-file-download.phpclass-log.phpclass-note.phpclass-order-address.phpclass-order-adjustment.phpclass-order-item.phpclass-order-transaction.phpclass-order.php
schemas
class-adjustments.phpclass-customer-addresses.phpclass-customer-email-addresses.phpclass-customers.phpclass-logs-api-requests.phpclass-logs-file-downloads.phpclass-logs.phpclass-notes.phpclass-order-addresses.phpclass-order-adjustments.phpclass-order-items.phpclass-order-transactions.phpclass-orders.php
tables
class-adjustment-meta.phpclass-adjustments.phpclass-customer-addresses.phpclass-customer-email-addresses.phpclass-customer-meta.phpclass-customers.phpclass-log-meta.phpclass-logs-api-request-meta.phpclass-logs-api-requests.phpclass-logs-file-download-meta.phpclass-logs-file-downloads.phpclass-logs.phpclass-note-meta.phpclass-notes.phpclass-order-addresses.phpclass-order-adjustment-meta.phpclass-order-adjustments.phpclass-order-item-meta.phpclass-order-items.phpclass-order-meta.phpclass-order-transactions.phpclass-orders.php
downloads
emails
actions.phpclass-edd-email-tags.phpclass-edd-emails.php
error-tracking.phpemail-summary
class-edd-email-summary-blurb.phpclass-edd-email-summary-cron.phpclass-edd-email-summary.phpedd-email-summary-template.php
functions.phptags-inserter.phptags.phptemplate.phpextensions
formatting.phpgateways
actions.phpamazon-payments.phpfunctions.php
install.phpinterface-edd-exception.phplibs
manual.phppaypal-standard.phppaypal
admin
buy-now.phpcheckout-actions.phpclass-account-status-validator.phpclass-merchant-account.phpclass-paypal-api.phpclass-token.phpdeprecated.phpexceptions
class-api-exception.phpclass-authentication-exception.phpclass-gateway-exception.phpclass-invalid-merchant-details.phpclass-missing-merchant-details.php
functions.phpgateway-filters.phpintegrations.phpipn.phppaypal.phprefunds.phpscripts.phpwebhooks
stripe
apple-developer-merchantid-domain-associationedd-stripe.phppayment-receipt.phpscripts.phptemplate-functions.php
assets
css
build
src
js
includes
admin
admin-actions.phpadmin-filters.phpclass-notices-registry.phpclass-notices.phpnotices.php
card-actions.phpclass-edd-stripe-rate-limiting.phpclass-edd-stripe.phpclass-stripe-api.phpcompat.phpdeprecated.phpelements.phpemails.phpfunctions.phpgateway-actions.phpgateway-filters.phpi18n.phpnotices
reporting
settings.phpsettings
upgrade-functions.phpintegrations
payment-actions.phppayment-methods
buy-now
payment-request
utils
class-registry.php
webhooks.phpexceptions
class-attribute-not-found.phpclass-gateway-exception.phpclass-stripe-api-unmet-requirements.phpclass-stripe-object-not-found.php
interface-static-registry.phpmodal.phpvendor
autoload.php
composer
ClassLoader.phpInstalledVersions.phpLICENSEautoload_classmap.phpautoload_namespaces.phpautoload_psr4.phpautoload_real.phpautoload_static.phpinstalled.jsoninstalled.php
stripe
stripe-php
CHANGELOG.mdCODE_OF_CONDUCT.mdLICENSEMakefileREADME.mdVERSIONbuild.phpcomposer.json
data
init.phplib
Account.phpAccountLink.phpAlipayAccount.php
phpdoc.dist.xmlphpstan-baseline.neonphpstan.neon.distupdate_certs.phpApiOperations
ApiRequestor.phpApiResource.phpApiResponse.phpApplePayDomain.phpApplicationFee.phpApplicationFeeRefund.phpBalance.phpBalanceTransaction.phpBankAccount.phpBaseStripeClient.phpBillingPortal
BitcoinReceiver.phpBitcoinTransaction.phpCapability.phpCard.phpCharge.phpCheckout
Collection.phpCountrySpec.phpCoupon.phpCreditNote.phpCreditNoteLineItem.phpCustomer.phpCustomerBalanceTransaction.phpDiscount.phpDispute.phpEphemeralKey.phpErrorObject.phpEvent.phpException
ApiConnectionException.phpApiErrorException.phpAuthenticationException.phpBadMethodCallException.phpCardException.phpExceptionInterface.phpIdempotencyException.phpInvalidArgumentException.phpInvalidRequestException.php
ExchangeRate.phpFile.phpFileLink.phpOAuth
ExceptionInterface.phpInvalidClientException.phpInvalidGrantException.phpInvalidRequestException.phpInvalidScopeException.phpOAuthErrorException.phpUnknownOAuthErrorException.phpUnsupportedGrantTypeException.phpUnsupportedResponseTypeException.php
PermissionException.phpRateLimitException.phpSignatureVerificationException.phpUnexpectedValueException.phpUnknownApiErrorException.phpHttpClient
Invoice.phpInvoiceItem.phpInvoiceLineItem.phpIssuing
LineItem.phpLoginLink.phpMandate.phpOAuth.phpOAuthErrorObject.phpOrder.phpOrderItem.phpOrderReturn.phpPaymentIntent.phpPaymentMethod.phpPayout.phpPerson.phpPlan.phpPrice.phpProduct.phpPromotionCode.phpRadar
Recipient.phpRecipientTransfer.phpRefund.phpReporting
RequestTelemetry.phpReview.phpSKU.phpService
AbstractService.phpAbstractServiceFactory.phpAccountLinkService.phpAccountService.phpApplePayDomainService.phpApplicationFeeService.phpBalanceService.phpBalanceTransactionService.php
SetupIntent.phpBillingPortal
ChargeService.phpCheckout
CoreServiceFactory.phpCountrySpecService.phpCouponService.phpCreditNoteService.phpCustomerService.phpDisputeService.phpEphemeralKeyService.phpEventService.phpExchangeRateService.phpFileLinkService.phpFileService.phpInvoiceItemService.phpInvoiceService.phpIssuing
AuthorizationService.phpCardService.phpCardholderService.phpDisputeService.phpIssuingServiceFactory.phpTransactionService.php
MandateService.phpOAuthService.phpOrderReturnService.phpOrderService.phpPaymentIntentService.phpPaymentMethodService.phpPayoutService.phpPlanService.phpPriceService.phpProductService.phpPromotionCodeService.phpRadar
RefundService.phpReporting
ReviewService.phpSetupIntentService.phpSigma
SkuService.phpSourceService.phpSubscriptionItemService.phpSubscriptionScheduleService.phpSubscriptionService.phpTaxRateService.phpTerminal
TokenService.phpTopupService.phpTransferService.phpWebhookEndpointService.phpSigma
SingletonApiResource.phpSource.phpSourceTransaction.phpStripe.phpStripeClient.phpStripeClientInterface.phpStripeObject.phpSubscription.phpSubscriptionItem.phpSubscriptionSchedule.phpTaxId.phpTaxRate.phpTerminal
ThreeDSecure.phpToken.phpTopup.phpTransfer.phpTransferReversal.phpUsageRecord.phpUsageRecordSummary.phpUtil
CaseInsensitiveArray.phpDefaultLogger.phpLoggerInterface.phpObjectTypes.phpRandomGenerator.phpRequestOptions.phpSet.phpUtil.php
Webhook.phpWebhookEndpoint.phpWebhookSignature.phplibraries
Carbon.phparray2xml.phpbrowser.phpclass-ArrayToXML.phpclass-persistent-dismissible.phpclass-recursive-arrayaccess.phpclass-wp-session.phpwp-session.php
logs
api-request-log
file-download-log
log
models
notes
orders
classes
class-order-address.phpclass-order-adjustment.phpclass-order-item.phpclass-order-transaction.phpclass-order.phpclass-refund-validator.php
functions
payments
plugin-compatibility.phppost-types.phpprivacy-functions.phpprocess-download.phpprocess-purchase.phpquery-filters.phprefund-functions.phpreports
class-init.phpclass-registry.phpclass-base-object.phpclass-chart-endpoint.phpclass-endpoint-registry.phpclass-endpoint-view-registry.phpclass-endpoint.phpclass-report-registry.phpclass-report.phpclass-table-endpoint.phpclass-tile-endpoint.php
scripts.phpshortcodes.phptax-functions.phptemplate-actions.phptemplate-functions.phptheme-compatibility.phpdata
charts
v2
customers
discounts
downloads
file-downloads
payment-gateways
taxes
exceptions
reports-functions.phptraits
user-functions.phpusers
utils
EnvironmentChecker.phpNotificationImporter.phpclass-date.phpclass-edd-exception.phpclass-registry.phpclass-tokenizer.php
widgets.phpexceptions
interface-error-logger.phpinterface-static-registry.phplanguages
license.txtreadme.txttemplates
account-pending.phpcheckout_cart.phpedd.css
uninstall.phpemails
fonts
history-downloads.phphistory-purchases.phpimages
payment-processing.phpshortcode-content-cart-button.phpshortcode-content-excerpt.phpshortcode-content-full.phpshortcode-content-image.phpshortcode-content-price.phpshortcode-content-title.phpshortcode-download.phpshortcode-login.phpshortcode-profile-editor.phpshortcode-receipt.phpshortcode-register.phpwidget-cart-checkout.phpwidget-cart-empty.phpwidget-cart-item.phpwidget-cart.php@ -0,0 +1,426 @@
|
||||
<?php
|
||||
/**
|
||||
* EDD Session
|
||||
*
|
||||
* This is a wrapper class for WP_Session / PHP $_SESSION and handles the storage of cart items, purchase sessions, etc
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Classes/Session
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.5
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* EDD_Session Class
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class EDD_Session {
|
||||
|
||||
/**
|
||||
* Holds our session data.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
* @since 1.5
|
||||
*/
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* Whether to use PHP $_SESSION or WP_Session.
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
* @since 1.5,1
|
||||
*/
|
||||
private $use_php_sessions = false;
|
||||
|
||||
/**
|
||||
* Session index prefix
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
* @since 2.3
|
||||
*/
|
||||
private $prefix = '';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Defines our WP_Session constants, includes the necessary libraries and
|
||||
* retrieves the WP Session instance.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->use_php_sessions = $this->use_php_sessions();
|
||||
|
||||
if ( $this->use_php_sessions ) {
|
||||
if ( is_multisite() ) {
|
||||
$this->prefix = '_' . get_current_blog_id();
|
||||
}
|
||||
|
||||
// Use PHP SESSION (must be enabled via the EDD_USE_PHP_SESSIONS constant)
|
||||
add_action( 'init', array( $this, 'maybe_start_session' ), -2 );
|
||||
} else {
|
||||
if ( ! $this->should_start_session() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Use WP_Session (default)
|
||||
if ( ! defined( 'WP_SESSION_COOKIE' ) ) {
|
||||
define( 'WP_SESSION_COOKIE', 'edd_wp_session' );
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Recursive_ArrayAccess' ) ) {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/libraries/class-recursive-arrayaccess.php';
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WP_Session' ) ) {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/libraries/class-wp-session.php';
|
||||
require_once EDD_PLUGIN_DIR . 'includes/libraries/wp-session.php';
|
||||
}
|
||||
|
||||
add_filter( 'wp_session_expiration_variant', array( $this, 'set_expiration_variant_time' ), 99999 );
|
||||
add_filter( 'wp_session_expiration', array( $this, 'set_expiration_time' ), 99999 );
|
||||
}
|
||||
|
||||
// Based off our session handling, we need to use different hooks and priorities.
|
||||
if ( empty( $this->session ) && ! $this->use_php_sessions ) {
|
||||
$hook = 'plugins_loaded';
|
||||
$priority = 10;
|
||||
} else {
|
||||
$hook = 'init';
|
||||
$priority = -1;
|
||||
}
|
||||
|
||||
add_action( $hook, array( $this, 'init' ), $priority );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the WP_Session instance.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function init() {
|
||||
if ( $this->use_php_sessions ) {
|
||||
$key = 'edd' . $this->prefix;
|
||||
$this->session = isset( $_SESSION[ $key ] ) && is_array( $_SESSION[ $key ] )
|
||||
? $_SESSION[ $key ]
|
||||
: array();
|
||||
} else {
|
||||
$this->session = WP_Session::get_instance();
|
||||
}
|
||||
|
||||
$use_cookie = $this->use_cart_cookie();
|
||||
$cart = $this->get( 'edd_cart' );
|
||||
$purchase = $this->get( 'edd_purchase' );
|
||||
|
||||
if ( $use_cookie ) {
|
||||
if ( ! empty( $cart ) || ! empty( $purchase ) ) {
|
||||
$this->set_cart_cookie();
|
||||
} else {
|
||||
$this->set_cart_cookie( false );
|
||||
}
|
||||
}
|
||||
|
||||
return $this->session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve session ID.
|
||||
*
|
||||
* @since 1.6
|
||||
*
|
||||
* @return string Session ID
|
||||
*/
|
||||
public function get_id() {
|
||||
return $this->session->session_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a session variable.
|
||||
*
|
||||
* @since 1.5
|
||||
*
|
||||
* @param string $key Session key.
|
||||
* @return mixed Session variable.
|
||||
*/
|
||||
public function get( $key ) {
|
||||
$key = sanitize_key( $key );
|
||||
$return = false;
|
||||
|
||||
if ( isset( $this->session[ $key ] ) && ! empty( $this->session[ $key ] ) ) {
|
||||
preg_match( '/[oO]\s*:\s*\d+\s*:\s*"\s*(?!(?i)(stdClass))/', $this->session[ $key ], $matches );
|
||||
|
||||
if ( ! empty( $matches ) ) {
|
||||
$this->set( $key, null );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( is_numeric( $this->session[ $key ] ) ) {
|
||||
$return = $this->session[ $key ];
|
||||
} else {
|
||||
$maybe_json = json_decode( $this->session[ $key ] );
|
||||
|
||||
// Since json_last_error is PHP 5.3+, we have to rely on a `null` value for failing to parse JSON.
|
||||
if ( is_null( $maybe_json ) ) {
|
||||
$is_serialized = is_serialized( $this->session[ $key ] );
|
||||
if ( $is_serialized ) {
|
||||
$value = @unserialize( $this->session[ $key ] );
|
||||
$this->set( $key, (array) $value );
|
||||
$return = $value;
|
||||
} else {
|
||||
$return = $this->session[ $key ];
|
||||
}
|
||||
} else {
|
||||
$return = json_decode( $this->session[ $key ], true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a session variable.
|
||||
*
|
||||
* @since 1.5
|
||||
*
|
||||
* @param string $key Session key.
|
||||
* @param int|string|array $value Session variable.
|
||||
*
|
||||
* @return mixed Session variable
|
||||
*/
|
||||
public function set( $key, $value ) {
|
||||
$key = sanitize_key( $key );
|
||||
|
||||
if ( is_array( $value ) ) {
|
||||
$this->session[ $key ] = wp_json_encode( $value );
|
||||
} else {
|
||||
$this->session[ $key ] = esc_attr( $value );
|
||||
}
|
||||
|
||||
if ( $this->use_php_sessions ) {
|
||||
$_SESSION[ 'edd' . $this->prefix ] = $this->session;
|
||||
}
|
||||
|
||||
return $this->session[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a cookie to identify whether the cart is empty or not.
|
||||
*
|
||||
* This is for hosts and caching plugins to identify if caching should be disabled.
|
||||
*
|
||||
* @since 1.8
|
||||
*
|
||||
* @param bool $set Whether to set or destroy. Default true.
|
||||
*/
|
||||
public function set_cart_cookie( $set = true ) {
|
||||
|
||||
// Bail if headers already sent.
|
||||
if ( headers_sent() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $set ) {
|
||||
@setcookie( 'edd_items_in_cart', '1', time() + 30 * 60, COOKIEPATH, COOKIE_DOMAIN, is_ssl() );
|
||||
} elseif ( isset( $_COOKIE['edd_items_in_cart'] ) ) {
|
||||
@setcookie( 'edd_items_in_cart', '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN, is_ssl() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the cookie expiration variant time to 23 hours.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 3.0 Set default value of $exp parameter to 1 as it is unused.
|
||||
*
|
||||
* @param int $exp Default expiration (1 hour).
|
||||
* @return int Cookie expiration variant time.
|
||||
*/
|
||||
public function set_expiration_variant_time( $exp = 1 ) {
|
||||
return HOUR_IN_SECONDS * 23;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the cookie expiration time to 24 hours.
|
||||
*
|
||||
* @since 1.9
|
||||
* @since 3.0 Set default value of $exp parameter to 1 as it is unused.
|
||||
*
|
||||
* @param int $exp Default expiration (1 hour).
|
||||
* @return int Cookie expiration time.
|
||||
*/
|
||||
public function set_expiration_time( $exp = 1 ) {
|
||||
return HOUR_IN_SECONDS * 24;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new session if one hasn't started yet.
|
||||
*
|
||||
* Checks to see if the server supports PHP sessions
|
||||
* or if the EDD_USE_PHP_SESSIONS constant is defined
|
||||
*
|
||||
* @since 2.1
|
||||
* @return bool $ret True if we are using PHP sessions, false otherwise.
|
||||
*/
|
||||
public function use_php_sessions() {
|
||||
|
||||
// Set default return value to false.
|
||||
$ret = false;
|
||||
|
||||
// If the database variable is already set, no need to run autodetection.
|
||||
$edd_use_php_sessions = (bool) get_option( 'edd_use_php_sessions' );
|
||||
|
||||
if ( ! $edd_use_php_sessions ) {
|
||||
|
||||
// Attempt to detect if the server supports PHP sessions
|
||||
if ( function_exists( 'session_start' ) ) {
|
||||
$this->set( 'edd_use_php_sessions', 1 );
|
||||
|
||||
if ( $this->get( 'edd_use_php_sessions' ) ) {
|
||||
$ret = true;
|
||||
|
||||
// Set the database option
|
||||
update_option( 'edd_use_php_sessions', true );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$ret = $edd_use_php_sessions;
|
||||
}
|
||||
|
||||
// Enable or disable PHP Sessions based on the EDD_USE_PHP_SESSIONS constant.
|
||||
if ( defined( 'EDD_USE_PHP_SESSIONS' ) && EDD_USE_PHP_SESSIONS ) {
|
||||
$ret = true;
|
||||
} else if ( defined( 'EDD_USE_PHP_SESSIONS' ) && ! EDD_USE_PHP_SESSIONS ) {
|
||||
$ret = false;
|
||||
}
|
||||
|
||||
// Filter & return.
|
||||
return (bool) apply_filters( 'edd_use_php_sessions', $ret );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a user has set the EDD_USE_CART_COOKIE.
|
||||
*
|
||||
* @since 2.5
|
||||
*
|
||||
* @return bool If the store should use the edd_items_in_cart cookie to help avoid caching
|
||||
*/
|
||||
public function use_cart_cookie() {
|
||||
|
||||
// Set default return value to true.
|
||||
$ret = true;
|
||||
|
||||
if ( defined( 'EDD_USE_CART_COOKIE' ) && ! EDD_USE_CART_COOKIE ) {
|
||||
$ret = false;
|
||||
}
|
||||
|
||||
// Filter & return.
|
||||
return (bool) apply_filters( 'edd_use_cart_cookie', $ret );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if we should start sessions.
|
||||
*
|
||||
* @since 2.5.11
|
||||
*
|
||||
* @return bool True if sessions should start, false otherwise.
|
||||
*/
|
||||
public function should_start_session() {
|
||||
|
||||
// Set default return value to true.
|
||||
$start_session = true;
|
||||
|
||||
if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
|
||||
$blacklist = $this->get_blacklist();
|
||||
$uri = ltrim( $_SERVER['REQUEST_URI'], '/' );
|
||||
$uri = untrailingslashit( $uri );
|
||||
|
||||
if ( in_array( $uri, $blacklist, true ) ) {
|
||||
$start_session = false;
|
||||
}
|
||||
|
||||
if ( false !== strpos( $uri, 'feed=' ) ) {
|
||||
$start_session = false;
|
||||
}
|
||||
|
||||
// We do not want to start sessions in the admin unless we're processing an ajax request.
|
||||
if ( is_admin() && false === strpos( $uri, 'wp-admin/admin-ajax.php' ) ) {
|
||||
$start_session = false;
|
||||
}
|
||||
|
||||
// Starting sessions while saving the file editor can break the save process, so don't start.
|
||||
if ( false !== strpos( $uri, 'wp_scrape_key' ) ) {
|
||||
$start_session = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter & return.
|
||||
return (bool) apply_filters( 'edd_start_session', $start_session );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the URI blacklist.
|
||||
*
|
||||
* These are the URIs where we never start sessions.
|
||||
*
|
||||
* @since 2.5.11
|
||||
*
|
||||
* @return array URI blacklist.
|
||||
*/
|
||||
public function get_blacklist() {
|
||||
$blacklist = apply_filters( 'edd_session_start_uri_blacklist', array(
|
||||
'feed',
|
||||
'feed/rss',
|
||||
'feed/rss2',
|
||||
'feed/rdf',
|
||||
'feed/atom',
|
||||
'comments/feed'
|
||||
) );
|
||||
|
||||
// Look to see if WordPress is in a sub folder or this is a network site that uses sub folders
|
||||
$folder = str_replace( network_home_url(), '', get_site_url() );
|
||||
|
||||
if ( ! empty( $folder ) ) {
|
||||
foreach ( $blacklist as $path ) {
|
||||
$blacklist[] = $folder . '/' . $path;
|
||||
}
|
||||
}
|
||||
|
||||
return $blacklist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new session if one hasn't started yet.
|
||||
*
|
||||
* @since 2.1.3
|
||||
*/
|
||||
public function maybe_start_session() {
|
||||
|
||||
// Bail if should not start session.
|
||||
if ( ! $this->should_start_session() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail if headers already sent.
|
||||
if ( headers_sent() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Start if old version of PHP & no session ID exists.
|
||||
if ( version_compare( PHP_VERSION, '5.4', '<' ) && ! session_id() ) {
|
||||
session_start();
|
||||
|
||||
// Start if modern PHP and session-status is not active.
|
||||
} elseif ( defined( 'PHP_SESSION_ACTIVE' ) && ( session_status() !== PHP_SESSION_ACTIVE ) ) {
|
||||
session_start();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user