/**
  * Load our classes, actions/filters, only if our big brother is activated.
  * GO GO GO!
  *
  * @return void
  */
 public function load()
 {
     add_action('all_admin_notices', array($this, 'admin_notices'));
     // Load settings
     require_once WP_STREAM_REPORTS_INC_DIR . 'class-wp-stream-reports-settings.php';
     add_action('init', array('WP_Stream_Reports_Settings', 'load'), 9);
     // Load date interval
     require_once WP_STREAM_CLASS_DIR . 'class-wp-stream-date-interval.php';
     require_once WP_STREAM_REPORTS_INC_DIR . 'class-wp-stream-reports-date-interval.php';
     add_action('init', array('WP_Stream_Reports_Date_Interval', 'get_instance'));
     // Load metaboxes and charts
     require_once WP_STREAM_REPORTS_INC_DIR . 'class-wp-stream-reports-meta-boxes.php';
     require_once WP_STREAM_REPORTS_INC_DIR . 'class-wp-stream-reports-charts.php';
     add_action('init', array('WP_Stream_Reports_Metaboxes', 'get_instance'), 12);
     // Load template tags
     require_once WP_STREAM_REPORTS_INC_DIR . 'template-tags.php';
     // Register new submenu
     add_action('network_admin_menu', array($this, 'register_menu'), 11);
     if (WP_Stream::is_connected() || WP_Stream::is_development_mode()) {
         add_action('admin_menu', array($this, 'register_menu'), 11);
     }
     self::$disallow_access = apply_filters('wp_stream_reports_disallow_site_access', false);
     // Register and enqueue the administration scripts
     add_action('admin_enqueue_scripts', array($this, 'register_ui_assets'), 20);
     add_action('admin_print_scripts', array($this, 'dequeue_media_conflicts'), 9999);
 }
Beispiel #2
0
 /**
  * Check is menu is present in menu array
  */
 public function test_register_menu()
 {
     do_action('admin_menu');
     global $menu, $submenu;
     //Check main menu
     $this->assertTrue(in_array('wp_stream', reset($menu)));
     if (WP_Stream::is_connected() || WP_Stream::is_development_mode()) {
         //Check submenu
         $this->assertTrue(in_array('wp_stream_settings', $submenu['wp_stream'][1]));
     }
 }
 /**
  * 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 Matcher
     include_once WP_STREAM_NOTIFICATIONS_INC_DIR . 'class-wp-stream-notifications-matcher.php';
     $this->matcher = new WP_Stream_Notifications_Matcher();
 }
 /**
  * Add a specific body class to all Stream admin screens
  *
  * @filter admin_body_class
  *
  * @param  string $classes
  *
  * @return string $classes
  */
 public static function admin_body_class($classes)
 {
     if (self::is_stream_screen()) {
         $classes .= sprintf(' %s ', self::ADMIN_BODY_CLASS);
         if (WP_Stream::is_connected() || WP_Stream::is_development_mode()) {
             $classes .= ' wp_stream_connected ';
         } else {
             $classes .= ' wp_stream_disconnected ';
         }
         if (WP_Stream_API::is_restricted()) {
             $classes .= ' wp_stream_restricted ';
         }
     }
     $settings_pages = array(self::SETTINGS_PAGE_SLUG);
     if (isset($_GET['page']) && in_array($_GET['page'], $settings_pages)) {
         $classes .= sprintf(' %s ', self::SETTINGS_PAGE_SLUG);
     }
     return $classes;
 }
    public static function render_stream_page()
    {
        $page_title = __('Stream Records', 'stream');
        self::$list_table->prepare_items();
        echo '<div class="wrap">';
        if (is_network_admin()) {
            $sites_connected = count(WP_Stream_Network::get_instance()->connected_sites);
            $site_count = '';
            if ($sites_connected > 0) {
                $site_count = sprintf(_n(' (1 site)', ' (%d sites)', $sites_connected, 'stream'), $sites_connected);
            }
            printf('<h2>%s%s</h2>', __('Stream Records', 'stream'), $site_count);
            // xss ok
        } else {
            printf('<h2>%s</h2>', __('Stream Records', 'stream'));
            // xss ok
        }
        if (is_network_admin() && !$sites_connected && !WP_Stream::is_development_mode()) {
            wp_enqueue_style('wp-stream-connect', WP_STREAM_URL . 'ui/css/connect.css', array(), WP_Stream::VERSION);
            ?>
			<div id="stream-message" class="updated stream-network-connect stream-connect" style="display:block !important;">
				<div class="stream-message-container">
					<div class="stream-message-text">
							<h4><?php 
            _e('Get started with Stream for Multisite!', 'stream');
            ?>
</h4>
							<p><?php 
            _e('Welcome to your Network Stream! Each site on your network must be connected individually by an admin on that site for it to show here.', 'stream');
            ?>
</p>
					</div>
				</div>
			</div>
			<?php 
        } elseif (is_network_admin()) {
            // TO DO: Add support for a network wide API Key. Until then, show this notice.
            ?>
			<div id="stream-message" class="error stream-network-connect stream-connect" style="display:block !important;">
				<div class="stream-message-container">
					<div class="stream-message-text">
							<h4><?php 
            _e('Stream for Multisite is coming soon!', 'stream');
            ?>
</h4>
							<p><?php 
            _e('Access to all the Stream feeds in your network is currently disabled.', 'stream');
            ?>
</p>
					</div>
				</div>
			</div>
			<?php 
        } else {
            self::$list_table->display();
        }
        echo '</div>';
    }
 /**
  * Helper function to query the marketplace API via wp_remote_request.
  *
  * @param string The url to access.
  * @param string The method of the request.
  * @param array  The headers sent during the request.
  * @param bool   Allow API calls to be cached.
  * @param int    Set transient expiration in seconds.
  *
  * @return object The results of the wp_remote_request request.
  */
 protected function remote_request($url = '', $args = array(), $allow_cache = true, $expiration = 300)
 {
     if (empty($url)) {
         return false;
     }
     $defaults = array('headers' => array(), 'method' => 'GET', 'body' => '', 'sslverify' => true);
     $this->count++;
     $args = wp_parse_args($args, $defaults);
     $args['headers']['Stream-Site-API-Key'] = $this->api_key;
     $args['headers']['Accept-Version'] = $this->api_version;
     $args['headers']['Content-Type'] = 'application/json';
     if (WP_Stream::is_development_mode()) {
         $args['blocking'] = true;
     }
     add_filter('http_api_transports', array(__CLASS__, 'http_api_transport_priority'), 10, 3);
     $transient = 'wp_stream_' . md5($url);
     if ('GET' === $args['method'] && $allow_cache) {
         if (false === ($request = get_transient($transient))) {
             $request = wp_remote_request($url, $args);
             set_transient($transient, $request, $expiration);
         }
     } else {
         $request = wp_remote_request($url, $args);
     }
     remove_filter('http_api_transports', array(__CLASS__, 'http_api_transport_priority'), 10);
     // Return early if the request is non blocking
     if (isset($args['blocking']) && false === $args['blocking']) {
         return true;
     }
     if (!is_wp_error($request)) {
         $data = apply_filters('wp_stream_api_request_data', json_decode($request['body']), $url, $args);
         // Loose comparison needed
         if (200 == $request['response']['code'] || 201 == $request['response']['code']) {
             return $data;
         } else {
             // Disconnect if unauthorized or no longer exists, loose comparison needed
             if (403 == $request['response']['code'] || 410 == $request['response']['code']) {
                 WP_Stream_Admin::remove_api_authentication();
             }
             $this->errors['errors']['http_code'] = $request['response']['code'];
         }
         if (isset($data->error)) {
             $this->errors['errors']['api_error'] = $data->error;
         }
     } else {
         $this->errors['errors']['remote_request_error'] = $request->get_error_message();
         WP_Stream::notice(sprintf('<strong>%s</strong> %s.', __('Stream API Error.', 'stream'), $this->errors['errors']['remote_request_error']));
     }
     if (!empty($this->errors)) {
         delete_transient($transient);
     }
     return false;
 }