Пример #1
0
 public static function on_activate()
 {
     global $wpdb;
     if (WebPush_DB::getInstance()->version === get_option('webpush_db_version')) {
         return;
     }
     $table_name = $wpdb->prefix . 'webpush_subscription';
     $sql = 'CREATE TABLE ' . $table_name . ' (
   `id` INT NOT NULL AUTO_INCREMENT,
   `endpoint` VARCHAR(300) NOT NULL,
   `userKey` VARCHAR(300) NOT NULL,
   PRIMARY KEY (`id`),
   UNIQUE (`endpoint`)
 );';
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     dbDelta($sql);
     update_option('webpush_db_version', WebPush_DB::getInstance()->version);
     // Set default options.
     update_option('webpush_title', 'blog_title');
     update_option('webpush_icon', function_exists('get_site_icon_url') ? 'blog_icon' : '');
     update_option('webpush_min_visits', 3);
     update_option('webpush_gcm_key', '');
     update_option('webpush_gcm_sender_id', '');
     update_option('webpush_notification_count', 0);
     update_option('webpush_opened_notification_count', 0);
     $default_triggers = WebPush_Main::get_triggers_by_key_value('enable_by_default', true);
     $default_triggers_keys = array();
     foreach ($default_triggers as $trigger) {
         $default_triggers_keys[] = $trigger['key'];
     }
     update_option('webpush_triggers', $default_triggers_keys);
 }
Пример #2
0
 public function update_check()
 {
     global $wpdb;
     if (self::VERSION === get_option('webpush_db_version')) {
         return;
     }
     $table_name = $wpdb->prefix . 'webpush_subscription';
     $sql = 'CREATE TABLE ' . $table_name . ' (
   `id` INT NOT NULL AUTO_INCREMENT,
   `endpoint` VARCHAR(300) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
   `userKey` VARCHAR(300) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
   `userAuth` BINARY(16) NOT NULL,
   PRIMARY KEY (`id`),
   UNIQUE (`endpoint`)
 );';
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     dbDelta($sql);
     update_option('webpush_db_version', self::VERSION);
     // Set default options.
     add_option('webpush_title', 'blog_title');
     add_option('webpush_icon', function_exists('get_site_icon_url') ? 'blog_icon' : '');
     add_option('webpush_min_visits', -1);
     add_option('webpush_subscription_button', true);
     add_option('webpush_prompt_interval', 3);
     add_option('webpush_gcm_key', '');
     add_option('webpush_gcm_sender_id', '');
     add_option('webpush_generate_manifest', true);
     self::generate_vapid_options();
     add_option('webpush_prompt_count', 0);
     add_option('webpush_accepted_prompt_count', 0);
     add_option('webpush_subscription_button_color', '#005189');
     Mozilla\WP_Serve_File::getInstance()->invalidate_files(array('subscription_button.css', 'bell.svg'));
     $default_triggers = WebPush_Main::get_triggers_by_key_value('enable_by_default', true);
     $default_triggers_keys = array();
     foreach ($default_triggers as $trigger) {
         $default_triggers_keys[] = $trigger['key'];
     }
     add_option('webpush_triggers', $default_triggers_keys);
 }