define_constants();
$this->hooks();
do_action( 'pqc_loaded' );
}
/**
* Define constant if not already set.
*
* @param string $name
* @param string|bool $value
* @since 1.6
*/
private function define( $name, $value )
{
if ( ! defined( $name ) ) define( $name, $value );
}
/**
* Define PQC Constants.
*/
private function define_constants()
{
require_once( ABSPATH.'wp-admin/includes/plugin.php' );
global $wpdb;
$plugin_data = get_plugin_data( __FILE__ );
$this->define( 'PQC_URL', plugin_dir_url( __FILE__ ) );
$this->define( 'PQC_PATH', plugin_dir_path( __FILE__ ) );
$this->define( 'PQC_PLUGIN', plugin_basename( __FILE__ ) );
$this->define( 'PQC_NAME', $plugin_data['Name'] );
$this->define( 'PQC_VERSION', $plugin_data['Version'] );
$this->define( 'PQC_AUTHOR', $plugin_data['Author'] );
$this->define( 'PQC_AUTHOR_URI', $plugin_data['AuthorURI'] );
$this->define( 'PQC_PHANES_API_URI', 'https://phanes.co/' );
$this->define( 'PQC_API_PHANES_URI', 'https://api.phanes.co/' );
$this->define( 'PQC_SETTING_PAGE', 'admin.php?page=pqc-settings-page' );
$this->define( 'PQC_SETTING_OPTIONS', 'pqc-options' );
$this->define( 'PQC_MATERIALS_TABLE', $wpdb->prefix . 'pqc_materials' );
$this->define( 'PQC_ORDERS_TABLE', $wpdb->prefix . 'pqc_orders' );
$this->define( 'PQC_DATA_TABLE', $wpdb->prefix . 'pqc_data' );
$this->define( 'PQC_UPLOAD_SHORTCODE', 'pqc_upload' );
$this->define( 'PQC_CART_SHORTCODE', 'pqc_cart' );
$this->define( 'PQC_CHECKOUT_SHORTCODE', 'pqc_checkout' );
$this->define( 'PQC_ORDERS_SHORTCODE', 'pqc_orders' );
$this->define( 'PQC_CONTENT_DIR', WP_CONTENT_DIR . "/uploads/pqc/" );
$this->define( 'PQC_CONTENT_URL', WP_CONTENT_URL . "/uploads/pqc/" );
$this->define( 'PQC_REQUIRES_WP', '4.1' );
}
/**
* Hook into actions and filters.
* @since 1.6
*/
private function hooks()
{
add_action( 'init', array( $this, 'plugin_check' ), 1);
add_action( 'init', array( $this, 'init' ), 1);
add_action( 'plugins_loaded', array( $this, 'i18n' ), 0 );
add_filter( "plugin_action_links_" . PQC_PLUGIN, array( $this, 'plugin_links' ) );
add_action( 'wp_head', array( $this, 'js_detection' ), 0 );
add_filter( 'query_vars', array( $this, 'add_query_vars' ) );
add_filter( 'rewrite_rules_array', array( $this, 'add_rewrite_rules' ) );
}
/**
* Check Plugin Requirements
* @since 1.0
*/
public function plugin_check()
{
if ( ! version_compare( $GLOBALS['wp_version'], PQC_REQUIRES_WP, '>=' ) ) {
$this->add_notice(
sprintf(
__( '%s plugin requires a
newer version
of WordPress to work properly.', 'pqc'
),
PQC_NAME
), 'error', false
);
$this->plugin_inactive = true;
}
if ( version_compare( get_option( 'pqc-version' ), PQC_VERSION, '<' ) )
$this->run_setup();
if (
! get_option( PQC_SETTING_OPTIONS, false ) ||
! $this->table_exist( PQC_DATA_TABLE ) ||
! $this->table_exist( PQC_MATERIALS_TABLE )
) {
if (
get_option( 'pqc-version', 'not exist' ) == 'not exist' ||
get_option( 'pqc-version' ) != PQC_VERSION
) {
if ( is_admin() && current_user_can( 'manage_options' ) ) $this->run_setup();
$this->plugin_inactive = false;
} else {
$notice = $this->add_notice(
sprintf(
__( '%s needs some setup.
Run setup', 'pqc'
),
PQC_NAME,
add_query_arg( 'pqc-setup', 'setup' )
), 'error', false
);
$this->plugin_inactive = true;
}
}
}
/**
* Initialize the plugin
* @since 1.0
*/
public function init()
{
// Before init action.
do_action( 'before_pqc_init' );
// Init check
$this->init_check();
// Load GLOBAL Variables
$this->globals();
// Add Default Materials, if no material
$this->insert_default_materials();
// Remove Expired Files if we have any
$this->remove_expired_files();
// Include/Require Files
$this->includes();
// Init action.
do_action( 'pqc_init' );
}
/**
* Do the Init method check
* @since 1.6
*
*/
private function init_check()
{
if (
isset( $_REQUEST['pqc-setup'] ) &&
$_REQUEST['pqc-setup'] == 'setup' &&
is_admin() &&
current_user_can( 'manage_options' )
) { $this->run_setup(); }
if ( $this->plugin_inactive ) return;
if (
isset( $_REQUEST['pqc-setup'] ) &&
$_REQUEST['pqc-setup'] == 'complete' &&
is_admin() &&
current_user_can( 'manage_options' )
) {
$this->add_notice(
sprintf(
__( 'Thank you for using %s.
Setup is complete.', 'pqc'
),
PQC_NAME
), 'updated pqc-inner-notice'
);
}
}
/**
* PQC GLOBAL Variables
* @since 1.1.1
*/
private function globals()
{
$sections = array(
'checkout_options' => array(
'label' => 'Checkout Options',
'callback' => array( 'PQC_Admin', 'checkout_section' ),
),
'paypal' => array(
'label' => 'PayPal',
'callback' => array( 'PQC_Admin', 'paypal_section' ),
),
'stripe' => array(
'label' => 'Stripe',
'callback' => array( 'PQC_Admin', 'stripe_section' ),
),
);
$payment_options = array();
if ( pqc_is_paypal_ready( true ) ) {
$payment_options['paypal'] = array(
'label' => 'PayPal
',
'callback' => array(
'url' => PQC_PATH . 'core/paypal.php',
'start' => array( 'PQC_PayPal', 'payment_start' ),
'end' => array( 'PQC_PayPal', 'payment_end' )
),
'desc' => __( 'Pay via PayPal; you can pay with your credit card if you don’t have a PayPal account.', 'pqc' ),
);
}
if ( pqc_is_stripe_ready( true ) ) {
$payment_options['stripe'] = array(
'label' => 'Stripe
',
'callback' => array(
'url' => PQC_PATH . 'core/stripe.php',
'start' => array( 'PQC_Stripe', 'payment_start' ),
'end' => array( 'PQC_Stripe', 'payment_end' )
),
'desc' => __( 'Pay via Stripe; Pay with your credit card.', 'pqc' ),
);
}
$tabs = array(
// General Tab
'general' => array(
'label' => __( 'General', 'pqc' ),
'callback' => array( 'PQC_Admin', 'general_tab' ),
),
// Checkout Tab
'checkout' => array(
'label' => __( 'Checkout', 'pqc' ),
'callback' => array( 'PQC_Admin', 'checkout_section' ),
'sections' => $sections + apply_filters( 'pqc_checkout_settings_sections', array() ),
),
);
$GLOBALS['pqc_settings_tabs'] = $tabs + apply_filters( 'pqc_settings_tabs', array() );
$GLOBALS['pqc_payment_options'] = $payment_options + apply_filters( 'pqc_payment_options', array() );
$GLOBALS['pqc_getting_started_tabs'] = array(
'start' => __( 'Getting Started', 'pqc' ),
'about' => __( 'About', 'pqc' ),
);
}
/**
* Loads reqiured files
* @since 1.6
*/
protected function includes()
{
require_once PQC_PATH . 'core/admin.php';
if ( $this->plugin_inactive ) return;
require_once PQC_PATH . 'core/public.php';
}
/**
* Add query vars
* @since 1.0
* @param mixed $args
*/
public function add_query_vars( array $args ) : array
{
array_push( $args, 'order_id', 'order_status', 'payment_method'/*, 'order_action'*/ );
$flush = get_option( 'pqc-rewrite-flush' );
if ( $flush != 1 ) {
$this->flush_rewrite_rules();
update_option( 'pqc-rewrite-flush', 1 );
}
return $args;
}
/**
* Add rewrite rules
* @since 1.0
* @param mixed $rules
*/
public function add_rewrite_rules( array $rules ) : array
{
$new_rules = array(
'pqc-checkout/(processing|complete)/([a-z]+)/?$' => 'index.php?pagename=pqc-checkout&order_status=$matches[1]&payment_method=$matches[2]',
// 'pqc-orders/(view-order)/([0-9]+)/?$' => 'index.php?pagename=pqc-orders&order_action=$matches[1]&order_id=$matches[2]',
);
$rules = $new_rules + $rules;
return $rules;
}
/**
* Add Notice
* @since 1.0
* @param mixed $msg The message to display
* @param mixed $class The css class of notice, Accepts "updated and error".
*/
public function add_notice( string $msg, string $class, bool $dismiss = true, bool $echo = false )
{
if ( ! is_admin() ) return;
$dismiss_icon = $dismiss ?
'' : '';
$notice = '
' . $msg . '
' . $dismiss_icon . '