예제 #1
0
 public static function get_instance()
 {
     if (!self::$_instance) {
         // If the single instance hasn't been set, set it now
         self::$_instance = new self();
     }
     return self::$_instance;
 }
예제 #2
0
 /**
  * Setup admin for the plugin.
  **/
 public function admin_setup()
 {
     require_once LEYKA_PLUGIN_DIR . 'inc/leyka-class-options-allocator.php';
     require_once LEYKA_PLUGIN_DIR . 'inc/leyka-render-settings.php';
     require_once LEYKA_PLUGIN_DIR . 'inc/leyka-admin.php';
     require_once LEYKA_PLUGIN_DIR . 'inc/leyka-donations-export.php';
     Leyka_Admin_Setup::get_instance();
 }
예제 #3
0
 /** Initialize the plugin by setting localization, filters, and administration functions. */
 private function __construct()
 {
     if (!get_option('leyka_permalinks_flushed')) {
         function leyka_flush_rewrite_rules()
         {
             flush_rewrite_rules(false);
             update_option('leyka_permalinks_flushed', 1);
         }
         add_action('init', 'leyka_flush_rewrite_rules');
     }
     // By default, we'll assume some errors in the payment form, so redirect will get us back to it:
     $this->_payment_form_redirect_url = wp_get_referer();
     // Load public-facing style sheet and JavaScript:
     add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
     // wp_footer
     add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
     // wp_footer
     add_action('init', array($this, 'register_post_types'), 1);
     add_action('init', array($this, 'register_user_capabilities'), 1);
     if (!session_id()) {
         add_action('init', 'session_start', -2);
     }
     if (is_admin()) {
         require_once LEYKA_PLUGIN_DIR . 'inc/leyka-class-options-allocator.php';
         require_once LEYKA_PLUGIN_DIR . 'inc/leyka-render-settings.php';
         require_once LEYKA_PLUGIN_DIR . 'inc/leyka-admin.php';
         require_once LEYKA_PLUGIN_DIR . 'inc/leyka-donations-export.php';
         Leyka_Admin_Setup::get_instance();
     }
     add_action('admin_bar_menu', array($this, 'leyka_add_toolbar_menu'), 999);
     /** Service URLs handler: */
     add_action('parse_request', function () {
         // Callback URLs are: some-website.org/leyka/service/{gateway_id}/{action_name}/
         // For ex., some-website.org/leyka/service/yandex/check_order/
         $request = $_SERVER['REQUEST_URI'];
         //$request->request;
         if (stristr($request, 'leyka/service') !== FALSE) {
             // Leyka service URL
             $request = explode('leyka/service', $_SERVER['REQUEST_URI']);
             $request = explode('/', trim($request[1], '/'));
             // $request[0] - Payment method's ID, $request[1] - service action:
             do_action('leyka_service_call-' . $request[0], $request[1]);
             exit;
         }
     });
     /** Embed campaign URL handler: */
     add_filter('template_include', function ($template) {
         if (is_main_query() && is_singular(Leyka_Campaign_Management::$post_type) && !empty($_GET['embed'])) {
             $new_template = leyka_get_current_template_data(false, 'embed_' . $_GET['embed'], true);
             if ($new_template && !empty($new_template['file'])) {
                 $template = $new_template['file'];
             }
         }
         return $template;
     }, 100);
     add_action('template_redirect', array($this, 'gateway_redirect_page'), 1, 1);
     $this->apply_formatting_filters();
     // Internal formatting filters
     //        new Non_existing_class; /** @todo */
     /** Currency rates auto refreshment: */
     if (leyka_options()->opt('auto_refresh_currency_rates')) {
         if (!wp_next_scheduled('refresh_currencies_rates')) {
             wp_schedule_event(time(), 'daily', 'refresh_currencies_rates');
         }
         add_action('refresh_currencies_rates', array($this, 'do_currencies_rates_refresh'));
         // Just in case:
         if (!leyka_options()->opt('currency_rur2usd') || !leyka_options()->opt('currency_rur2eur')) {
             $this->do_currency_rates_refresh();
         }
     } else {
         wp_clear_scheduled_hook('refresh_currencies_rates');
     }
     do_action('leyka_initiated');
 }