/** * Public constructor */ public static function load() { // User and role caps add_filter('user_has_cap', array(__CLASS__, '_filter_user_caps'), 10, 4); add_filter('role_has_cap', array(__CLASS__, '_filter_role_caps'), 10, 3); if (WP_Stream_API::is_restricted()) { return; } // Add Reports settings tab to Stream settings add_filter('wp_stream_settings_option_fields', array(__CLASS__, '_register_settings')); }
public static function save_api_authentication() { $home_url = str_ireplace(array('http://', 'https://'), '', home_url()); $connect_nonce_name = 'stream_connect_site-' . sanitize_key($home_url); if (!isset($_GET['api_key']) || !isset($_GET['site_uuid'])) { wp_die('There was a problem connecting to Stream. Please try again later.', 'stream'); } if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], $connect_nonce_name)) { wp_die('Doing it wrong.', 'stream'); } WP_Stream::$api->site_uuid = wp_stream_filter_input(INPUT_GET, 'site_uuid'); WP_Stream::$api->api_key = wp_stream_filter_input(INPUT_GET, 'api_key'); // Verify the API Key and Site UUID $site = WP_Stream::$api->get_site(); WP_Stream_API::$restricted = !isset($site->plan->type) || 'free' === $site->plan->type ? 1 : 0; if (!isset($site->site_id)) { wp_die('There was a problem verifying your site with Stream. Please try again later.', 'stream'); } if (!WP_Stream_API::$restricted) { WP_Stream_Notifications::$instance->on_activation(); } update_option(WP_Stream_API::SITE_UUID_OPTION_KEY, WP_Stream::$api->site_uuid); update_option(WP_Stream_API::API_KEY_OPTION_KEY, WP_Stream::$api->api_key); update_option(WP_Stream_API::RESTRICTED_OPTION_KEY, WP_Stream_API::$restricted); do_action('wp_stream_site_connected', WP_Stream::$api->site_uuid, WP_Stream::$api->api_key, get_current_blog_id()); $redirect_url = add_query_arg(array('page' => self::RECORDS_PAGE_SLUG, 'message' => 'connected'), admin_url(self::ADMIN_PARENT_PAGE)); wp_redirect($redirect_url); exit; }
/** * Apply list actions, and load our list-table object * * @action load-edit.php * * @return void */ public function load_list_table() { global $typenow; if (self::POSTTYPE !== $typenow || WP_Stream_API::is_restricted(true)) { return; } require_once WP_STREAM_NOTIFICATIONS_INC_DIR . 'class-wp-stream-notifications-list-table.php'; WP_Stream_Notifications_List_Table::get_instance(); }
public function load_page() { if (WP_Stream_API::is_restricted()) { add_action('in_admin_header', array(__CLASS__, 'in_admin_header')); return; } if (is_admin() && WP_Stream_Reports_Settings::is_first_visit()) { $this->setup_user(); } $this->existing_records = $this->get_existing_records(); // Add screen option for chart height add_filter('screen_settings', array($this, 'chart_height_display'), 10, 2); // Enqueue all core scripts required for this page to work add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); // Add all metaboxes foreach (self::$sections as $key => $section) { $delete_url = add_query_arg(array_merge(array('action' => 'wp_stream_reports_delete_metabox', 'key' => $key), WP_Stream_Reports::$nonce), admin_url('admin-ajax.php')); // Configure button $configure = sprintf('<span class="postbox-title-action"> <a href="javascript:void(0);" class="edit-box open-box">%3$s</a> </span> <span class="postbox-title-action postbox-delete-action"> <a href="%1$s"> %2$s </a> </span>', esc_url($delete_url), esc_html__('Delete', 'stream'), esc_html__('Configure', 'stream')); // Parse default argument $section = $this->parse_section($section); // Set the key for template use $section['key'] = $key; $section['generated_title'] = $this->get_generated_title($section); // Generate the title automatically if not already set $title = empty($section['title']) ? $section['generated_title'] : $section['title']; // Add the actual metabox add_meta_box(self::META_PREFIX . $key, sprintf('<span class="title">%s</span>%s', esc_html($title), $configure), array($this, 'metabox_content'), WP_Stream_Reports::$screen_id, $section['context'], $section['priority'], $section); } }
/** * Get the details for a specific site. * * @param array Returns specified fields only. * @param bool Allow API calls to be cached. * @param int Set transient expiration in seconds. * * @return mixed */ public function get_site($fields = array(), $allow_cache = true, $expiration = 30) { if (!$this->site_uuid) { return false; } $params = array(); if (!empty($fields)) { $params['fields'] = implode(',', $fields); } $url = $this->request_url(sprintf('/sites/%s', urlencode($this->site_uuid)), $params); $args = array('method' => 'GET'); $site = $this->remote_request($url, $args, $allow_cache, $expiration); if ($site && !is_wp_error($site)) { $is_restricted = !isset($site->plan->type) || 'free' === $site->plan->type ? 1 : 0; if (self::$restricted !== (bool) $is_restricted) { self::$restricted = $is_restricted; update_option(self::RESTRICTED_OPTION_KEY, $is_restricted); } } return $site; }
/** * Load our classes, actions/filters, only if our big brother is activated. * GO GO GO! * * @return void */ public function load() { if (!apply_filters('wp_stream_notifications_disallow_site_access', false) && (WP_Stream::is_connected() || WP_Stream::is_development_mode())) { add_action('admin_menu', array($this, 'register_menu'), 11); } // Load settings, enabling extensions to hook in require_once WP_STREAM_NOTIFICATIONS_INC_DIR . 'class-wp-stream-notifications-settings.php'; add_action('init', array('WP_Stream_Notifications_Settings', 'load'), 9); if (WP_Stream_API::is_restricted()) { add_action('in_admin_header', array(__CLASS__, 'in_admin_header')); return; } // Include all adapters include_once WP_STREAM_NOTIFICATIONS_INC_DIR . 'class-wp-stream-notifications-adapter.php'; $adapters = array('email', 'push', 'sms'); foreach ($adapters as $adapter) { include WP_STREAM_NOTIFICATIONS_INC_DIR . 'adapters/class-wp-stream-notifications-adapter-' . $adapter . '.php'; } // Load network class if (is_multisite()) { require_once WP_STREAM_NOTIFICATIONS_INC_DIR . 'class-wp-stream-notifications-network.php'; $this->network = new WP_Stream_Notifications_Network(); if (WP_Stream_Network::is_network_activated()) { add_action('network_admin_menu', array($this, 'register_menu'), 11); } // Allow Stream to override the admin_menu creation if on multisite add_filter('wp_stream_notifications_disallow_site_access', array('WP_Stream_Network', 'disable_admin_access')); } // Load Matcher include_once WP_STREAM_NOTIFICATIONS_INC_DIR . 'class-wp-stream-notifications-matcher.php'; $this->matcher = new WP_Stream_Notifications_Matcher(); }