本文整理汇总了PHP中wp_stream_filter_input函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_stream_filter_input函数的具体用法?PHP wp_stream_filter_input怎么用?PHP wp_stream_filter_input使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_stream_filter_input函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export
public static function export()
{
if (!wp_verify_nonce(wp_stream_filter_input(INPUT_GET, 'stream_notifications_nonce'), 'stream-notifications-nonce')) {
wp_die(__('Invalid nonce, go back and try again.', 'stream-notifications'));
}
$args = array('type' => 'notification_rule', 'ignore_context' => true, 'posts_per_page' => -1, 'order' => 'asc');
$query = wp_stream_query($args);
$items = array();
$cached = get_transient('stream-notification-rules');
foreach ($query as $rule) {
$rule = new WP_Stream_Notification_Rule($rule->ID);
$rule->ID = null;
$items[] = $rule->to_array();
}
$json = json_encode($items);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="stream-notification-rules_' . current_time('timestamp', 1) . '.json"');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . strlen($json));
echo $json;
// xss ok
die;
}
示例2: log
/**
* Log handler
*
* @param $connector
* @param string $message sprintf-ready error message string
* @param array $args sprintf (and extra) arguments to use
* @param int $object_id Target object id
* @param array $contexts Contexts of the action
* @param int $user_id User responsible for the action
*
* @internal param string $action Action performed (stream_action)
* @return int
*/
public function log($connector, $message, $args, $object_id, $contexts, $user_id = null)
{
global $wpdb;
if (is_null($user_id)) {
$user_id = get_current_user_id();
}
require_once WP_STREAM_INC_DIR . 'class-wp-stream-author.php';
$user = new WP_User($user_id);
$roles = get_option($wpdb->get_blog_prefix() . 'user_roles');
if (!isset($args['author_meta'])) {
$args['author_meta'] = array('user_email' => $user->user_email, 'display_name' => defined('WP_CLI') && empty($user->display_name) ? 'WP-CLI' : $user->display_name, 'user_login' => $user->user_login, 'user_role_label' => !empty($user->roles) ? $roles[$user->roles[0]]['name'] : null, 'agent' => WP_Stream_Author::get_current_agent());
if (defined('WP_CLI') && function_exists('posix_getuid')) {
$uid = posix_getuid();
$user_info = posix_getpwuid($uid);
$args['author_meta']['system_user_id'] = $uid;
$args['author_meta']['system_user_name'] = $user_info['name'];
}
}
// Remove meta with null values from being logged
$meta = array_filter($args, function ($var) {
return !is_null($var);
});
$recordarr = array('object_id' => $object_id, 'site_id' => is_multisite() ? get_current_site()->id : 1, 'blog_id' => apply_filters('blog_id_logged', is_network_admin() ? 0 : get_current_blog_id()), 'author' => $user_id, 'author_role' => !empty($user->roles) ? $user->roles[0] : null, 'created' => current_time('mysql', 1), 'summary' => vsprintf($message, $args), 'parent' => self::$instance->prev_record, 'connector' => $connector, 'contexts' => $contexts, 'meta' => $meta, 'ip' => wp_stream_filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP));
$record_id = WP_Stream_DB::get_instance()->insert($recordarr);
return $record_id;
}
示例3: save_interval
/**
* 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);
}
示例4: get_filter_value_by_id
/**
* @action wp_ajax_wp_stream_get_filter_value_by_id
*/
public static function get_filter_value_by_id()
{
$filter = wp_stream_filter_input(INPUT_POST, 'filter');
switch ($filter) {
case 'author':
$id = wp_stream_filter_input(INPUT_POST, 'id');
if ($id === '0') {
$value = 'WP-CLI';
break;
}
$user = get_userdata($id);
if (!$user || is_wp_error($user)) {
$value = '';
} else {
$value = $user->display_name;
}
break;
default:
$value = '';
}
echo json_encode($value);
wp_die();
}
示例5: process_migrate_action
/**
* Ajax callback for processing migrate actions
*
* Break down the total number of records found into reasonably-sized chunks
* and send each of those chunks to the Stream API
*
* Drops the legacy Stream data from the DB once the API has consumed everything
*
* @action wp_ajax_wp_stream_migrate_action
* @return void
*/
public static function process_migrate_action()
{
$action = wp_stream_filter_input(INPUT_POST, 'migrate_action');
$nonce = wp_stream_filter_input(INPUT_POST, 'nonce');
if (!wp_verify_nonce($nonce, 'wp_stream_migrate-' . absint(get_current_blog_id()) . absint(get_current_user_id()))) {
return;
}
set_time_limit(0);
// Just in case, this could take a while for some
if ('migrate' === $action) {
self::migrate_notification_rules();
$records = self::get_records(self::$limit);
if (!$records) {
// If all the records are gone, clean everything up
self::drop_legacy_data();
wp_send_json_success(__('Migration complete!', 'stream'));
}
$response = self::send_records($records);
if (true === $response) {
// Delete the records that were just sent to the API successfully
self::delete_records(self::$_records);
wp_send_json_success('migrate');
} else {
if (isset($response['body']['message']) && !empty($response['body']['message'])) {
$body = json_decode($response['body'], true);
$message = $body['message'];
} elseif (isset($response['response']['message']) && !empty($response['response']['message'])) {
$message = $response['response']['message'];
} else {
$message = __('An unknown error occurred during migration.', 'stream');
}
wp_send_json_error(sprintf(__('%s Please try again later or contact support.', 'stream'), esc_html($message)));
}
}
if ('delay' === $action) {
set_transient(self::MIGRATE_DELAY_TRANSIENT, "Don't nag me, bro", HOUR_IN_SECONDS * 3);
wp_send_json_success(__("OK, we'll remind you again in a few hours.", 'stream'));
}
if ('delete' === $action) {
$success_message = __('All existing records have been deleted from the database.', 'stream');
if (!is_multisite()) {
// If this is a single-site install, force delete everything
self::drop_legacy_data(true, true);
wp_send_json_success($success_message);
} else {
// If multisite, only delete records for this site - this will take longer
$records = self::get_record_ids(self::$limit);
if (!$records) {
// If all the records are gone, clean everything up
self::drop_legacy_data();
wp_send_json_success($success_message);
} else {
self::delete_records($records);
wp_send_json_success('delete');
}
}
}
die;
}
示例6: feed_template
/**
* Output for Stream Records as a feed.
*
* @return xml
*/
public static function feed_template()
{
$die_title = esc_html__('Access Denied', 'stream');
$die_message = sprintf('<h1>%s</h1><p>%s</p>', $die_title, esc_html__("You don't have permission to view this feed, please contact your site Administrator.", 'stream'));
$query_var = is_network_admin() ? self::FEED_NETWORK_QUERY_VAR : self::FEED_QUERY_VAR;
$args = array('meta_key' => self::USER_FEED_OPTION_KEY, 'meta_value' => wp_stream_filter_input(INPUT_GET, self::FEED_KEY_QUERY_VAR), 'number' => 1);
$user = get_users($args);
if (empty($user)) {
wp_die($die_message, $die_title);
}
if (!is_super_admin($user[0]->ID)) {
$roles = isset($user[0]->roles) ? (array) $user[0]->roles : array();
if (self::$is_network_feed) {
wp_die($die_message, $die_title);
}
if (!$roles || !array_intersect($roles, WP_Stream_Settings::$options['general_role_access'])) {
wp_die($die_message, $die_title);
}
}
$blog_id = self::$is_network_feed ? null : get_current_blog_id();
$args = array('blog_id' => $blog_id, 'records_per_page' => wp_stream_filter_input(INPUT_GET, 'records_per_page', FILTER_SANITIZE_NUMBER_INT), 'search' => wp_stream_filter_input(INPUT_GET, 'search'), 'object_id' => wp_stream_filter_input(INPUT_GET, 'object_id', FILTER_SANITIZE_NUMBER_INT), 'ip' => wp_stream_filter_input(INPUT_GET, 'ip', FILTER_VALIDATE_IP), 'author' => wp_stream_filter_input(INPUT_GET, 'author', FILTER_SANITIZE_NUMBER_INT), 'author_role' => wp_stream_filter_input(INPUT_GET, 'author_role'), 'date' => wp_stream_filter_input(INPUT_GET, 'date'), 'date_from' => wp_stream_filter_input(INPUT_GET, 'date_from'), 'date_to' => wp_stream_filter_input(INPUT_GET, 'date_to'), 'record__in' => wp_stream_filter_input(INPUT_GET, 'record__in'), 'order' => wp_stream_filter_input(INPUT_GET, 'order'), 'orderby' => wp_stream_filter_input(INPUT_GET, 'orderby'), 'fields' => wp_stream_filter_input(INPUT_GET, 'fields'));
$records = wp_stream_query($args);
$latest_record = isset($records[0]->created) ? $records[0]->created : null;
$records_admin_url = add_query_arg(array('page' => WP_Stream_Admin::RECORDS_PAGE_SLUG), admin_url(WP_Stream_Admin::ADMIN_PARENT_PAGE));
$latest_link = null;
if (isset($records[0]->ID)) {
$latest_link = add_query_arg(array('record__in' => $records[0]->ID), $records_admin_url);
}
$domain = parse_url($records_admin_url, PHP_URL_HOST);
$format = wp_stream_filter_input(INPUT_GET, self::FEED_TYPE_QUERY_VAR);
if ('atom' === $format) {
require_once WP_STREAM_INC_DIR . 'feeds/atom.php';
} elseif ('json' === $format) {
require_once WP_STREAM_INC_DIR . 'feeds/json.php';
} else {
require_once WP_STREAM_INC_DIR . 'feeds/rss-2.0.php';
}
exit;
}
示例7: callback_transition_post_status
/**
* Log Order major status changes ( creating / updating / trashing )
*
* @action transition_post_status
*
* @param string $new
* @param string $old
* @param \WP_Post $post
*/
public function callback_transition_post_status($new, $old, $post)
{
// Only track orders
if ('shop_order' !== $post->post_type) {
return;
}
// Don't track customer actions
if (!is_admin()) {
return;
}
// Don't track minor status change actions
if (in_array(wp_stream_filter_input(INPUT_GET, 'action'), array('mark_processing', 'mark_on-hold', 'mark_completed')) || defined('DOING_AJAX')) {
return;
}
// Don't log updates when more than one happens at the same time
if ($post->ID === $this->order_update_logged) {
return;
}
if (in_array($new, array('auto-draft', 'draft', 'inherit'))) {
return;
} elseif ('auto-draft' === $old && 'publish' === $new) {
$message = esc_html_x('%s created', 'Order title', 'stream');
$action = 'created';
} elseif ('trash' === $new) {
$message = esc_html_x('%s trashed', 'Order title', 'stream');
$action = 'trashed';
} elseif ('trash' === $old && 'publish' === $new) {
$message = esc_html_x('%s restored from the trash', 'Order title', 'stream');
$action = 'untrashed';
} else {
$message = esc_html_x('%s updated', 'Order title', 'stream');
}
if (empty($action)) {
$action = 'updated';
}
$order = new \WC_Order($post->ID);
$order_title = esc_html__('Order number', 'stream') . ' ' . esc_html($order->get_order_number());
$order_type_name = esc_html__('order', 'stream');
$this->log($message, array('post_title' => $order_title, 'singular_name' => $order_type_name, 'new_status' => $new, 'old_status' => $old, 'revision_id' => null), $post->ID, $post->post_type, $action);
$this->order_update_logged = $post->ID;
}
示例8: callback_pre_set_site_transient_update_plugins
/**
* @todo Core needs a delete_plugin hook
* @todo This does not work in WP-CLI
*/
public static function callback_pre_set_site_transient_update_plugins($value)
{
if (!wp_stream_filter_input(INPUT_POST, 'verify-delete') || !($plugins_to_delete = get_option('wp_stream_plugins_to_delete'))) {
return $value;
}
foreach ($plugins_to_delete as $plugin => $data) {
$name = $data['Name'];
$network_wide = $data['Network'] ? __('network wide', 'stream') : '';
self::log(__('"%s" plugin deleted', 'stream'), compact('name', 'plugin', 'network_wide'), null, 'plugins', 'deleted');
}
delete_option('wp_stream_plugins_to_delete');
return $value;
}
示例9: get_filter_value_by_id
/**
* @action wp_ajax_wp_stream_get_filter_value_by_id
*/
public function get_filter_value_by_id()
{
$filter = wp_stream_filter_input(INPUT_POST, 'filter');
switch ($filter) {
case 'user_id':
$id = wp_stream_filter_input(INPUT_POST, 'id');
if ('0' === $id) {
$value = 'WP-CLI';
break;
}
$user = get_userdata($id);
if (!$user || is_wp_error($user)) {
$value = '';
} else {
$value = $user->display_name;
}
break;
default:
$value = '';
}
echo wp_stream_json_encode($value);
// xss ok
if (defined('WP_STREAM_TESTS') && WP_STREAM_TESTS) {
return;
}
die;
}
示例10: actions
/**
* @action load-edit.php
*/
public function actions()
{
if (!isset($_REQUEST['action']) || !isset($_REQUEST['post_type']) || WP_Stream_Notifications_Post_Type::POSTTYPE !== wp_stream_filter_input(INPUT_GET, 'post_type')) {
return;
}
$action = $_REQUEST['action'];
$request = isset($_REQUEST['post']) ? is_array($_REQUEST['post']) ? $_REQUEST['post'] : explode(',', $_REQUEST['post']) : isset($_REQUEST['id']) ? array($_REQUEST['id']) : array();
$ids = array_map('absint', $request);
if (empty($action) || empty($ids)) {
return;
}
if (in_array($action, array('publish', 'unpublish'))) {
$status = 'publish' === $action ? 'publish' : 'draft';
foreach ($ids as $id) {
wp_update_post(array('ID' => $id, 'post_status' => $status));
}
wp_safe_redirect(add_query_arg(array('updated' => count($ids)), remove_query_arg(array('action', 'action2', 'id', 'ids', 'post', '_wp_http_referer', 'post_status', 'mode', 'm'))));
exit;
// Without this, the page displays the weird 'Are you sure you want this?'
}
}
示例11: get_stream
public function get_stream()
{
// Filters
$allowed_params = array('connector', 'context', 'action', 'author', 'author_role', 'object_id', 'search', 'date', 'date_from', 'date_to', 'record__in', 'blog_id', 'ip');
$sections = isset($_POST['sections']) ? maybe_unserialize(base64_decode($_POST['sections'])) : array();
if (!is_array($sections)) {
$sections = array();
}
//return $sections;
$other_tokens = isset($_POST['other_tokens']) ? maybe_unserialize(base64_decode($_POST['other_tokens'])) : array();
if (!is_array($other_tokens)) {
$other_tokens = array();
}
//return $other_tokens;
unset($_POST['sections']);
unset($_POST['other_tokens']);
$args = array();
foreach ($allowed_params as $param) {
if (self::$mainwpChildReports) {
$paramval = mainwp_wp_stream_filter_input(INPUT_POST, $param);
} else {
$paramval = wp_stream_filter_input(INPUT_POST, $param);
}
if ($paramval || '0' === $paramval) {
$args[$param] = $paramval;
}
}
foreach ($args as $arg => $val) {
if (!in_array($arg, $allowed_params)) {
unset($args[$arg]);
}
}
// to fix bug
$exclude_connector_posts = true;
if (isset($sections['body']) && isset($sections['body']['section_token']) && is_array($sections['body']['section_token'])) {
foreach ($sections['body']['section_token'] as $sec) {
if (strpos($sec, "[section.posts") !== false) {
$exclude_connector_posts = false;
break;
}
}
}
if ($exclude_connector_posts) {
if (isset($sections['header']) && isset($sections['header']['section_token']) && is_array($sections['header']['section_token'])) {
foreach ($sections['header']['section_token'] as $sec) {
if (strpos($sec, "[section.posts") !== false) {
$exclude_connector_posts = false;
break;
}
}
}
}
if ($exclude_connector_posts) {
if (isset($sections['footer']) && isset($sections['footer']['section_token']) && is_array($sections['footer']['section_token'])) {
foreach ($sections['footer']['section_token'] as $sec) {
if (strpos($sec, "[section.posts") !== false) {
$exclude_connector_posts = false;
break;
}
}
}
}
if ($exclude_connector_posts) {
if (isset($other_tokens['body']) && is_array($other_tokens['body'])) {
foreach ($other_tokens['body'] as $sec) {
if (strpos($sec, "[post.") !== false) {
$exclude_connector_posts = false;
break;
}
}
}
}
if ($exclude_connector_posts) {
if (isset($other_tokens['header']) && is_array($other_tokens['header'])) {
foreach ($other_tokens['header'] as $sec) {
if (strpos($sec, "[post.") !== false) {
$exclude_connector_posts = false;
break;
}
}
}
}
if ($exclude_connector_posts) {
if (isset($other_tokens['footer']) && is_array($other_tokens['footer'])) {
foreach ($other_tokens['footer'] as $sec) {
if (strpos($sec, "[post.") !== false) {
$exclude_connector_posts = false;
break;
}
}
}
}
if ($exclude_connector_posts) {
$args['connector__not_in'] = array('posts');
}
///// end fix /////
$args['action__not_in'] = array('login');
// fix for Stream 3
if (3 !== self::$streamVersionNumber) {
$args['fields'] = 'with-meta';
//.........这里部分代码省略.........
示例12: get_edition_data
/**
* @action load-theme-editor.php
*/
public static function get_edition_data()
{
if ('POST' !== $_SERVER['REQUEST_METHOD']) {
return;
}
if ('update' !== wp_stream_filter_input(INPUT_POST, 'action')) {
return;
}
$theme_slug = wp_stream_filter_input(INPUT_POST, 'theme') ? wp_stream_filter_input(INPUT_POST, 'theme') : get_stylesheet();
$theme = wp_get_theme($theme_slug);
if (!$theme->exists() || $theme->errors() && 'theme_no_stylesheet' === $theme->errors()->get_error_code()) {
return;
}
$allowed_files = $theme->get_files('php', 1);
$style_files = $theme->get_files('css');
$allowed_files['style.css'] = $style_files['style.css'];
$file = wp_stream_filter_input(INPUT_POST, 'file');
if (empty($file)) {
$file_name = 'style.css';
$file_path = $allowed_files['style.css'];
} else {
$file_name = $file;
$file_path = sprintf('%s/%s', $theme->get_stylesheet_directory(), $file_name);
}
$file_contents_before = file_get_contents($file_path);
self::$edited_file = compact('file_name', 'file_path', 'file_contents_before', 'theme');
}
示例13: get_plugin_data
/**
* Retrieve plugin data needed for the log message
*
* @param string $slug The plugin file base name (e.g. akismet/akismet.php)
* @return mixed $output Compacted variables
*/
public static function get_plugin_data($slug)
{
$base = null;
$name = null;
$slug = current(explode('/', $slug));
$file_name = wp_stream_filter_input(INPUT_POST, 'file');
$file_path = WP_PLUGIN_DIR . '/' . $file_name;
$file_contents_before = file_get_contents($file_path);
$plugins = get_plugins();
foreach ($plugins as $key => $plugin_data) {
if (0 === strpos($key, $slug)) {
$base = $key;
$name = $plugin_data['Name'];
break;
}
}
$file_name = str_ireplace(trailingslashit($slug), '', $file_name);
$slug = !empty($base) ? $base : $slug;
$output = compact('file_name', 'file_path', 'file_contents_before', 'slug', 'name');
return $output;
}
示例14: settings_form_description
/**
* Add a description to each of the Settings pages in the Network Admin
*
* @param $description
*
* @return string
*/
function settings_form_description($description)
{
if (!is_network_admin()) {
return;
}
$current_page = wp_stream_filter_input(INPUT_GET, 'page');
switch ($current_page) {
case self::NETWORK_SETTINGS_PAGE_SLUG:
$description = __('These settings apply to all sites on the network.', 'stream');
break;
case self::DEFAULT_SETTINGS_PAGE_SLUG:
$description = __('These default settings will apply to new sites created on the network. These settings do not alter existing sites.', 'stream');
break;
}
return $description;
}
示例15: settings_form_description
/**
* Add a description to each of the Settings pages in the Network Admin
*
* @param $description
*
* @return string
*/
public function settings_form_description($description)
{
if (!is_network_admin()) {
return '';
}
$current_page = wp_stream_filter_input(INPUT_GET, 'page');
switch ($current_page) {
case $this->network_settings_page_slug:
$description = __('These settings apply to all sites on the network.', 'stream');
break;
case $this->default_settings_page_slug:
$description = __('These default settings will apply to new sites created on the network. These settings do not alter existing sites.', 'stream');
break;
}
return $description;
}