function wp_stream_reports_intervals_html() { $date = WP_Stream_Reports_Date_Interval::get_instance(); // Default interval $default = array('key' => 'all-time', 'start' => '', 'end' => ''); $user_interval = WP_Stream_Reports_Settings::get_user_options('interval', $default); $save_interval_url = add_query_arg(array_merge(array('action' => 'wp_stream_reports_save_interval'), WP_Stream_Reports::$nonce), admin_url('admin-ajax.php')); include WP_STREAM_REPORTS_VIEW_DIR . 'intervals.php'; }
/** * Handle ajax saving of time intervals */ public function save_interval() { $interval = array('key' => wp_stream_filter_input(INPUT_GET, 'key', FILTER_SANITIZE_STRING, array('default' => '')), 'start' => wp_stream_filter_input(INPUT_GET, 'start', FILTER_SANITIZE_STRING, array('default' => '')), 'end' => wp_stream_filter_input(INPUT_GET, 'end', FILTER_SANITIZE_STRING, array('default' => ''))); // Get predefined interval for validation $avail_intervals = $this->get_predefined_intervals(); if ('' !== $interval['key'] && 'custom' !== $interval['key'] && !isset($avail_intervals[$interval['key']])) { wp_die(esc_html__('That time interval is not available.', 'stream')); } // Only store dates if we are dealing with custom dates and no relative preset if ('custom' !== $interval['key']) { $interval['start'] = ''; $interval['end'] = ''; } WP_Stream_Reports_Settings::update_user_option_and_redirect('interval', $interval); }
/** * Get user option and store it in a static var for easy access * * @param null $key * @param array $default * * @return array */ public static function get_user_options($key = null, $default = array()) { if (empty(self::$user_options)) { self::$user_options = get_user_option(self::get_option_key()); } if (is_null($key)) { // Return empty array if no user option is in DB $output = self::$user_options ?: array(); } else { $output = isset(self::$user_options[$key]) ? self::$user_options[$key] : $default; } return $output; }
protected function get_section($id) { if (empty(self::$sections)) { self::$sections = WP_Stream_Reports_Settings::get_user_options('sections'); } $section = self::$sections[$id]; $section = $this->parse_section($section); $section['key'] = $id; return $section; }
public function migrate_settings() { $sections = self::$sections; foreach ($sections as $key => $args) { switch ($args['data_group']) { case 'action': $sections[$key]['action_id'] = $args['data_type']; break; case 'connector': $sections[$key]['connector_id'] = $args['data_type']; break; case 'context': $sections[$key]['connector_id'] = $this->find_connector_by_context($args['data_type']); $sections[$key]['context_id'] = $args['data_type']; break; case 'other': break; } if (isset($args['selector_type'])) { $sections[$key]['selector_id'] = $args['selector_type']; } unset($sections[$key]['data_group']); unset($sections[$key]['data_type']); unset($sections[$key]['selector_type']); } WP_Stream_Reports_Settings::update_user_option_and_redirect('sections', $sections); }
/** * Admin page callback function, redirects to each respective method based * on $_GET['view'] * * @return void */ public function page() { // Page class $class = 'metabox-holder columns-' . get_current_screen()->get_columns(); $add_url = add_query_arg(array_merge(array('action' => 'wp_stream_reports_add_metabox'), self::$nonce), admin_url('admin-ajax.php')); $sections = WP_Stream_Reports_Settings::get_user_options('sections'); $no_reports = empty($sections); $create_url = add_query_arg(array_merge(array('action' => 'wp_stream_reports_default_reports'), self::$nonce), admin_url('admin-ajax.php')); $no_reports_message = __("There's nothing here! Do you want to <a href=\"%s\">create some reports</a>?", 'stream-reports'); $no_reports_message = sprintf($no_reports_message, $create_url); $view = (object) array('slug' => 'all', 'path' => null); // Avoid throwing Notices by testing the variable if (isset($_GET['view']) && !empty($_GET['view'])) { $view->slug = sanitize_file_name(wp_unslash($_GET['view'])); } // First we check if the file exists in our plugin folder, otherwhise give the user an error if (!file_exists(WP_STREAM_REPORTS_VIEW_DIR . $view->slug . '.php')) { $view->slug = 'error'; } // Define the path for the view we $view->path = WP_STREAM_REPORTS_VIEW_DIR . $view->slug . '.php'; // Execute some actions before including the view, to allow others to hook in here // Use these to do stuff related to the view you are working with do_action('stream-reports-view', $view); do_action("stream-reports-view-{$view->slug}", $view); include_once $view->path; }