version ); } /** * Unserializing instances of this class is forbidden. * @since 1.6 */ public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'pqc' ), $this->version ); } /** * PQC Constructor * @since 1.0 */ public function __construct() { $this->set_attributes(); add_action( 'plugins_loaded', [ $this, 'i18n' ], 0 ); add_action( 'init', [ $this, '__check' ], 1); add_action( 'init', [ $this, 'includes' ], 2); do_action( 'pqc_loaded' ); } /** * Define attributes. */ private function set_attributes() { require_once ABSPATH . 'wp-admin/includes/plugin.php'; $plugin = get_plugin_data( __FILE__ ); $this->host = 'https://phanes3dp.com'; $this->name = $plugin['Name']; $this->slug = $plugin['TextDomain']; $this->version = $plugin['Version']; $this->author = $plugin['Author']; $this->author_uri = $plugin['AuthorURI']; $this->theme_uri = $plugin['PluginURI']; $this->basename = plugin_basename( __FILE__ ); $this->path = plugin_dir_path( __FILE__ ); $this->uri = plugin_dir_url( __FILE__ ); } /** * Internationalization * */ public function i18n() { load_plugin_textdomain( 'pqc', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } /** * 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( $msg, $class, $dismiss = true, $echo = false ) { if ( ! is_admin() ) return; $dismiss = ( $dismiss === true ) ? '' : ''; $notice = '

' . $msg . '

' . $dismiss . '
'; if ( $echo === true ) echo $notice; else self::$_notice .= $notice; } /** * Check Requirements * @since 1.0 */ public function __check() { if ( ! version_compare( $GLOBALS['wp_version'], self::REQUIRES_WP, '>=' ) ) { $this->add_notice( sprintf( __( '%s plugin requires a newer version of WordPress to work properly.', 'pqc' ), $this->name ), 'error', false ); $this->inactive = true; } $version = get_option( 'pqc-version', 'none' ); $options = get_option( 'pqc-options', [] ); if ( $version == 'none' || version_compare( $version, $this->version, '<' ) || ( isset( $_REQUEST['pqc-setup'] ) && $_REQUEST['pqc-setup'] == 'setup' ) ) $this->run_setup(); if ( isset( $_REQUEST['pqc-setup'] ) && $_REQUEST['pqc-setup'] == 'complete' ) { $this->add_notice( sprintf( __( 'Thank you for using %s. Setup is complete.', 'pqc' ), $this->name ), 'updated pqc-inner-notice' ); } if ( empty( $options ) ) { $this->add_notice( sprintf( __( 'Add your Merchant ID and Access Token for %s here.', 'pqc' ), $this->name, admin_url( 'admin.php?page=pqc' ) ), 'updated pqc-inner-notice' ); } } /** * Loads required files * * @since 1.6 */ public function includes() { /** * Require the backend */ require_once $this->path . 'core/backend.php'; /** * Require the frontend */ require_once $this->path . 'core/frontend.php'; // Assign the loaded classes. $backend = new Backend; $frontend = new Frontend; } /** * Returns the option given the key * * @param string $key */ public function get_option( $key = null ) { $options = wp_parse_args( (array) get_option( 'pqc-options' ), [ 'merchant_id' => '', 'access_token' => '', ] ); return empty( $key ) ? to_object( $options ) : ( isset($options[$key]) ? $options[$key] : '' ); } /** * Run Setup * @since 1.0 */ public function run_setup() { if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) return; $p3dpmvwp = (array) maybe_unserialize( get_option( 'p3dpmvwp' ) ); if ( ! empty( $p3dpmvwp ) ) { update_option( 'pqc-options', $p3dpmvwp ); delete_option( 'p3dpmvwp' ); } update_option( 'pqc-version', $this->version ); exit( wp_redirect( admin_url( 'admin.php?page=pqc' ) ) ); } } } namespace { // Global namepsace $GLOBALS['pqc'] = new PQC\PQC; function PQC() { return $GLOBALS['pqc']; } if (! function_exists('to_object')) : /** * Force argument to object */ function to_object( $arg ) { $decode = @json_decode( $arg ); return $decode == null ? (object) json_decode( json_encode( $arg ) ) : $decode; } endif; if (! function_exists('to_array')) : /** * Force argument to array */ function to_array( $arg ) { $decode = @json_decode( $arg, true ); return $decode == null ? (array) json_decode( json_encode( $arg ), true ) : (array) $decode; } endif; }