Esempio n. 1
0
 /**
  * Handles live updates for Stream Post List
  *
  * @action heartbeat_recieved
  *
  * @param array $response Response to be sent to heartbeat tick
  * @param array $data     Data from heartbeat send
  *
  * @return array Data sent to heartbeat tick
  */
 public function heartbeat_received($response, $data)
 {
     // Only fire when Stream is requesting a live update
     if (!isset($data['wp-stream-heartbeat'])) {
         return $response;
     }
     $enable_stream_update = 'off' !== $this->plugin->admin->get_user_meta(get_current_user_id(), $this->user_meta_key);
     // Register list table
     $this->list_table = new WP_Stream_List_Table(array('screen' => 'toplevel_page_' . $this->plugin->admin->records_page_slug));
     $this->list_table->prepare_items();
     $total_items = isset($this->list_table->_pagination_args['total_items']) ? $this->list_table->_pagination_args['total_items'] : null;
     $total_pages = isset($this->list_table->_pagination_args['total_pages']) ? $this->list_table->_pagination_args['total_pages'] : null;
     if (isset($data['wp-stream-heartbeat']) && isset($total_items)) {
         $response['total_items'] = $total_items;
         $response['total_items_i18n'] = sprintf(_n('1 item', '%s items', $total_items), number_format_i18n($total_items));
     }
     if (isset($data['wp-stream-heartbeat']) && 'live-update' === $data['wp-stream-heartbeat'] && $enable_stream_update) {
         if (!empty($data['wp-stream-heartbeat'])) {
             if (isset($total_pages)) {
                 $response['total_pages'] = $total_pages;
                 $response['total_pages_i18n'] = number_format_i18n($total_pages);
                 $query_args = json_decode($data['wp-stream-heartbeat-query'], true);
                 $query_args['paged'] = $total_pages;
                 $response['last_page_link'] = add_query_arg($query_args, admin_url('admin.php'));
             } else {
                 $response['total_pages'] = 0;
             }
         }
         $response['wp-stream-heartbeat'] = $this->live_update($response, $data);
     } else {
         $response['log'] = 'fail';
     }
     return $response;
 }
Esempio n. 2
0
 /**
  * Render the admin page
  */
 public function handle_page()
 {
     global $wpdb;
     require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
     require_once dirname(__FILE__) . '/class-list-table.php';
     echo '<div class="wrap">';
     echo '<div>';
     $query_args = array('action' => 'pantheon_clear_session', 'nonce' => wp_create_nonce('pantheon_clear_session'), 'session' => 'all');
     if ($wpdb->get_var("SELECT COUNT(session_id) FROM {$wpdb->pantheon_sessions}")) {
         echo '<a class="button pantheon-clear-all-sessions" style="float:right; margin-top: 9px;" href="' . esc_url(add_query_arg($query_args, admin_url('admin-ajax.php'))) . '">' . esc_html__('Clear All', 'pantheon-sessions') . '</a>';
     }
     echo '<h2>' . esc_html__('Pantheon Sessions', 'pantheon-sessions') . '</h2>';
     if (isset($_GET['message']) && in_array($_GET['message'], array('delete-all-session', 'delete-session'))) {
         if ('delete-all-session' === $_GET['message']) {
             $message = __('Cleared all sessions.', 'pantheon-sessions');
         } else {
             if ('delete-session' === $_GET['message']) {
                 $message = __('Session cleared.', 'pantheon-sessions');
             }
         }
         echo '<div id="message" class="updated"><p>' . esc_html($message) . '</p></div>';
     }
     echo '</div>';
     $wp_list_table = new List_Table();
     $wp_list_table->prepare_items();
     $wp_list_table->display();
     echo '</div>';
     add_action('admin_footer', array($this, 'action_admin_footer'));
 }