Пример #1
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'));
     add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
     // Post types:
     add_action('init', array($this, 'register_post_types'), 9);
     // User roles and capabilities:
     add_action('init', array($this, 'register_user_capabilities'));
     if (!session_id()) {
         add_action('init', 'session_start', -2);
     }
     if (is_admin() && current_user_can('leyka_manage_donations')) {
         $this->admin_setup();
     }
     if (current_user_can('leyka_manage_donations')) {
         add_action('admin_bar_menu', array($this, 'leyka_add_toolbar_menu'), 999);
     }
     /** Service URLs handler: */
     add_action('parse_request', function ($request) {
         // 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');
 }
 function get_hidden_fields($campaign_id = null)
 {
     global $post;
     if ($campaign_id == null) {
         $campaign_id = $post->ID;
     }
     $campaign = new Leyka_Campaign($campaign_id);
     $template = leyka_get_current_template_data();
     $hiddens = apply_filters('leyka_hidden_donation_form_fields', array('leyka_template_id' => $template['id'], 'leyka_campaign_id' => (int) $campaign_id, 'leyka_ga_campaign_title' => esc_attr($campaign->payment_title)), $this);
     $out = wp_nonce_field('leyka_payment_form', '_wpnonce', true, false);
     foreach ($hiddens as $key => $value) {
         $out .= "<input type='hidden' name='" . esc_attr($key) . "' value='" . esc_attr($value) . "' />";
     }
     return $out;
 }
 function get_hidden_fields($campaign = null)
 {
     if ($campaign) {
         $campaign = leyka_get_validated_campaign($campaign);
     } else {
         if (!is_singular(Leyka_Campaign_Management::$post_type)) {
             return false;
         }
         $campaign = new Leyka_Campaign(get_post());
     }
     $template = leyka_get_current_template_data();
     $hiddens = apply_filters('leyka_hidden_donation_form_fields', array('leyka_template_id' => $template['id'], 'leyka_campaign_id' => $campaign->id, 'leyka_ga_campaign_title' => esc_attr($campaign->payment_title)), $this);
     $out = wp_nonce_field('leyka_payment_form', '_wpnonce', true, false);
     foreach ($hiddens as $key => $value) {
         $out .= "<input type='hidden' name='" . esc_attr($key) . "' value='" . esc_attr($value) . "' />";
     }
     return $out;
 }