1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
<?php
defined( 'ABSPATH' ) || exit();
class WC_Braintree_Query {
private $endpoints = array();
public function __construct() {
add_action( 'init', array( $this, 'flush_rewrite_rules' ) );
add_action( 'wp_loaded', array( $this, 'deprecated_query_vars' ) );
add_filter( 'woocommerce_get_query_vars', array( $this, 'get_query_vars' ) );
}
public function initialize_endpoints() {
$this->endpoints = array(
'subscriptions' => braintree()->subscription_settings->get_option( 'subscriptions_endpoint' ),
'view-subscription' => braintree()->subscription_settings->get_option( 'view_subscription_endpoint' ),
'change-payment-method' => braintree()->subscription_settings->get_option( 'change_payment_method_endpoint' ),
'cancel-subscription' => 'cancel-subscripion',
);
foreach ( $this->endpoints as $endpoint => $value ) {
add_filter( 'woocommerce_endpoint_' . $endpoint . '_title', array( $this, 'endpoint_title' ), 10, 2 );
}
}
public function flush_rewrite_rules() {
if ( 'yes' === get_option( 'woocommerce_queue_flush_rewrite_rules' ) ) {
WC()->query->init_query_vars();
WC()->query->add_endpoints();
flush_rewrite_rules();
}
}
public function endpoint_title( $title, $endpoint ) {
global $wp;
switch ( $endpoint ) {
case 'subscriptions':
$title = __( 'My Subscriptions', 'woo-payment-gateway' );
break;
case 'view-subscription':
$title = sprintf( __( 'Subscription #%1$s', 'woo-payment-gateway' ), $wp->query_vars['view-subscription'] );
break;
case 'change-payment-method':
$title = __( 'Change Payment Method', 'woo-payment-gateway' );
break;
}
return $title;
}
public function parse_request() {
global $wp;
}
public function get_endpoints() {
return apply_filters( 'wcs_braintree_get_endpoints', $this->endpoints );
}
public function get_query_vars( $vars = array() ) {
if ( empty( $this->endpoints ) ) {
$this->initialize_endpoints();
}
return array_merge( $vars, $this->get_endpoints() );
}
public function deprecated_query_vars() {
if ( WC()->query ) {
WC()->query->query_vars = array_merge( WC()->query->query_vars, $this->get_query_vars() );
WC()->query->add_endpoints();
}
}
}
new WC_Braintree_Query();