本文整理汇总了PHP中wp_clone函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_clone函数的具体用法?PHP wp_clone怎么用?PHP wp_clone使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_clone函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_process_queue
/**
* Get the queue of assets to be minified & concatenated
* Handles dependencies etc.
*
* @return array process_queue. An array of file handles.
*/
protected function get_process_queue()
{
if (empty($this->process_queue)) {
// Use a clone of the current class to avoid conflicts
$_class = wp_clone($this->class);
// Remove from queue if not a registered asset.
foreach ($this->queue as $key => $handle) {
if (!array_key_exists($handle, $_class->registered)) {
unset($this->queue[$key]);
}
}
// If no scripts in the queue have been enqueued, don't process queue at all.
$_class->all_deps($_class->queue);
$intersect = array_intersect($_class->to_do, $this->queue);
if (empty($intersect)) {
return array();
}
// Set up the todos according to our queue - do this to handle dependencies.
$_class->to_do = array();
$_class->all_deps($this->queue);
foreach ($_class->to_do as $key => $handle) {
// If not in queue - skip (eg if is in queue because it is a dependency of another file)
// Skip if no asset path (eg is remote.)
if (!in_array($handle, $this->queue) || false === $this->get_asset_path($handle)) {
continue;
}
$group = $this->get_handle_group($handle);
$this->process_queue[$group][] = $handle;
}
}
return $this->process_queue;
}
示例2: update
public function update(array $new_contact_array)
{
$existing_contact = wp_clone($this);
$new_contact = new KWSContactList($new_contact_array, true);
unset($new_contact->id, $new_contact->status, $new_contact->source, $new_contact->source_details);
foreach ($new_contact as $k => $v) {
$existing_contact->{$k} = $v;
}
return $existing_contact;
}
示例3: update
public function update($new_contact_array)
{
$existing_contact = wp_clone($this);
$new_contact = new KWSContact($new_contact_array, true);
foreach (self::$read_only as $key) {
unset($new_contact->{$key});
}
foreach ($new_contact as $k => $v) {
$existing_contact->{$k} = $v;
}
return $existing_contact;
}
示例4: set
function set($id, $data, $group = 'default', $expire = '')
{
$group = $this->_ensure_group($group);
$data = is_null($data) ? '' : $data;
if (is_object($data)) {
$data = wp_clone($data);
}
if (!isset($this->cache[$group])) {
$this->cache[$group] = array();
}
$this->cache[$group][$id] = $data;
return true;
}
示例5: add_option
/**
* Add a new option.
*
* You do not need to serialize values. If the value needs to be serialized, then
* it will be serialized before it is inserted into the database. Remember,
* resources can not be serialized or added as an option.
*
* You can create options without values and then add values later. Does not
* check whether the option has already been added, but does check that you
* aren't adding a protected WordPress option. Care should be taken to not name
* options the same as the ones which are protected and to not add options
* that were already added.
*
* @package WordPress
* @subpackage Option
* @since 1.0.0
* @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton
*
* @uses do_action() Calls 'add_option' hook before adding the option.
* @uses do_action() Calls 'add_option_$option' and 'added_option' hooks on success.
*
* @param string $option Name of option to add. Expected to not be SQL-escaped.
* @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
* @param mixed $deprecated Optional. Description. Not used anymore.
* @param bool $autoload Optional. Default is enabled. Whether to load the option when WordPress starts up.
* @return null returns when finished.
*/
function add_option($option, $value = '', $deprecated = '', $autoload = 'yes')
{
global $wpdb;
if (!empty($deprecated)) {
_deprecated_argument(__FUNCTION__, '2.3');
}
$option = trim($option);
if (empty($option)) {
return false;
}
wp_protect_special_option($option);
if (is_object($value)) {
$value = wp_clone($value);
}
$value = sanitize_option($option, $value);
// Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
$notoptions = wp_cache_get('notoptions', 'options');
if (!is_array($notoptions) || !isset($notoptions[$option])) {
if (false !== get_option($option)) {
return;
}
}
$_value = $value;
$value = maybe_serialize($value);
$autoload = 'no' === $autoload ? 'no' : 'yes';
do_action('add_option', $option, $_value);
if (!defined('WP_INSTALLING')) {
if ('yes' == $autoload) {
$alloptions = wp_load_alloptions();
$alloptions[$option] = $value;
wp_cache_set('alloptions', $alloptions, 'options');
} else {
wp_cache_set($option, $value, 'options');
}
}
// This option exists now
$notoptions = wp_cache_get('notoptions', 'options');
// yes, again... we need it to be fresh
if (is_array($notoptions) && isset($notoptions[$option])) {
unset($notoptions[$option]);
wp_cache_set('notoptions', $notoptions, 'options');
}
$result = $wpdb->query($wpdb->prepare("INSERT INTO `{$wpdb->options}` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $value, $autoload));
if ($result) {
do_action("add_option_{$option}", $option, $_value);
do_action('added_option', $option, $_value);
return true;
}
return false;
}
示例6: set
/**
* Sets the data contents into the cache
*
* The cache contents is grouped by the $group parameter followed by the
* $id. This allows for duplicate ids in unique groups. Therefore, naming of
* the group should be used with care and should follow normal function
* naming guidelines outside of core WordPress usage.
*
* The $expire parameter is not used, because the cache will automatically
* expire for each time a page is accessed and PHP finishes. The method is
* more for cache plugins which use files.
*
* @since 2.0.0
*
* @param int|string $id What to call the contents in the cache
* @param mixed $data The contents to store in the cache
* @param string $group Where to group the cache contents
* @param int $expire Not Used
* @return bool Always returns true
*/
function set($id, $data, $group = 'default', $expire = '')
{
if (empty($group)) {
$group = 'default';
}
if (NULL === $data) {
$data = '';
}
if (is_object($data)) {
$data = wp_clone($data);
}
$this->cache[$group][$id] = $data;
if (isset($this->non_existant_objects[$group][$id])) {
unset($this->non_existant_objects[$group][$id]);
}
return true;
}
示例7: set_blog_defaults
//.........这里部分代码省略.........
if (!$user) {
continue;
}
// Skip empty user objects
//Insert the user
$wpdb->insert($wpdb->usermeta, (array) $user);
//Check for errors
if (!empty($wpdb->last_error)) {
$error = '<div id="message" class="error"><p>' . sprintf(__('Insertion Error: %s - The template was not applied. (New Blog Templates - While inserting templated users)', $this->localization_domain), $wpdb->last_error) . '</p></div>';
$wpdb->query("ROLLBACK;");
//We've rolled it back and thrown an error, we're done here
restore_current_blog();
wp_die($error);
}
}
if ($postprocess_add_new_user_action) {
add_user_to_blog($blog_id, $user_id, 'administrator');
}
do_action('blog_templates-copy-users', $template, $blog_id, $user_id);
break;
case 'files':
global $wp_filesystem;
$dir_to_copy = $this->_get_files_fs_path($template['blog_id']);
//ABSPATH . 'wp-content/blogs.dir/' . $template['blog_id'] . '/files';
$dir_to_copy = apply_filters('blog_templates-copy-source_directory', $dir_to_copy, $template, $blog_id, $user_id);
$dir_to_copy_into = $this->_get_files_fs_path($blog_id);
//ABSPATH .'wp-content/blogs.dir/' . $blog_id . '/files';
$dir_to_copy_into = apply_filters('blog_templates-copy-target_directory', $dir_to_copy_into, $template, $blog_id, $user_id);
if (is_dir($dir_to_copy)) {
if (wp_mkdir_p($dir_to_copy_into)) {
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
if (isset($wp_filesystem)) {
$orig_filesystem = wp_clone($wp_filesystem);
}
$wp_filesystem = new WP_Filesystem_Direct(false);
if (!defined('FS_CHMOD_DIR')) {
define('FS_CHMOD_DIR', 0755);
}
if (!defined('FS_CHMOD_FILE')) {
define('FS_CHMOD_FILE', 0644);
}
copy_dir($dir_to_copy, $dir_to_copy_into);
unset($wp_filesystem);
if (isset($orig_filesystem)) {
$wp_filesystem = wp_clone($orig_filesystem);
}
if (@file_exists($dir_to_copy_into . '/sitemap.xml')) {
@unlink($dir_to_copy_into . '/sitemap.xml');
}
} else {
$error = '<div id="message" class="error"><p>' . sprintf(__('File System Error: Unable to create directory %s. (New Blog Templates - While copying files)', $this->localization_domain), $dir_to_copy_into) . '</p></div>';
$wpdb->query('ROLLBACK;');
restore_current_blog();
wp_die($error);
}
}
break;
}
}
//Are there any additional tables we need to copy?
/*error_log('Begin Additional Tables code');
echo 'Before additional tables code<br/>';*/
if (isset($template['additional_tables']) && is_array($template['additional_tables'])) {
//echo 'is array<br/>';
foreach ($template['additional_tables'] as $add) {
示例8: set
/**
* Set to the cache
*
* @param string $id
* @param mixed $data
* @param string $group
* @param integer $expire
* @return boolean
*/
function set($id, $data, $group = 'transient', $expire = 0)
{
$key = $this->_get_cache_key($id, $group);
if (is_object($data)) {
$data = wp_clone($data);
}
$fragment_group = $this->_fragment_group($id);
$this->cache[$fragment_group . $group][$key] = $data;
if ($this->_caching && !in_array($group, $this->nonpersistent_groups)) {
$cache = $this->_get_cache(null, $group);
$v = array('content' => $data);
return $cache->set($key, $v, $expire ? $expire : $this->_lifetime, $fragment_group);
}
return true;
}
示例9: inspect_styles
public function inspect_styles()
{
global $wp_styles;
if ($wp_styles) {
$styles = wp_clone($wp_styles);
$styles->all_deps($styles->queue);
$header = array();
// Loop through queue and determine groups of handles & latest modified date
foreach ($styles->to_do as $handle) {
$style_path = parse_url($this->ensure_scheme($wp_styles->registered[$handle]->src));
if ($this->host_match($wp_styles->registered[$handle]->src) && !in_array($wp_styles->registered[$handle]->src, $this->ignore)) {
//is a local script
if (!$this->mergecss || isset($header[count($header) - 1]['handle']) || count($header) == 0 || $header[count($header) - 1]['media'] != $wp_styles->registered[$handle]->args) {
$media = isset($wp_styles->registered[$handle]->args) ? $wp_styles->registered[$handle]->args : 'all';
array_push($header, array('modified' => 0, 'handles' => array(), 'media' => $media));
}
$modified = 0;
if (is_file($this->root . $style_path['path'])) {
$modified = filemtime($this->root . $style_path['path']);
}
array_push($header[count($header) - 1]['handles'], $handle);
if ($modified > $header[count($header) - 1]['modified']) {
$header[count($header) - 1]['modified'] = $modified;
}
} else {
//external script
array_push($header, array('handle' => $handle));
}
}
$done = $styles->done;
//loop through header styles and merge + schedule wpcron
for ($i = 0, $l = count($header); $i < $l; $i++) {
if (!isset($header[$i]['handle'])) {
$done = array_merge($done, $header[$i]['handles']);
$hash = hash('adler32', implode('', $header[$i]['handles']));
$file_path = '/mmr/' . $hash . '-' . $header[$i]['modified'] . '.css';
$full_path = WP_CONTENT_DIR . $file_path;
$min_path = '/mmr/' . $hash . '-' . $header[$i]['modified'] . '.min.css';
$min_exists = file_exists(WP_CONTENT_DIR . $min_path);
if (!file_exists($full_path) && !$min_exists) {
$css = '';
$log = "";
foreach ($header[$i]['handles'] as $handle) {
$style_path = parse_url($this->ensure_scheme($wp_styles->registered[$handle]->src));
$log .= " - " . $handle . " - " . $wp_styles->registered[$handle]->src;
if (substr($style_path['path'], -8) == '.min.css') {
$nomin_path = substr($style_path['path'], 0, -8) . '.css';
if (is_file($this->root . $nomin_path)) {
$style_path['path'] = $nomin_path;
$log .= " - unminified version used";
}
}
$css_contents = file_get_contents($this->root . $style_path['path']);
// Remove the BOM
$css_contents = preg_replace("/^/", '', $css_contents);
//convert relative paths to absolute & ignore data: or absolute paths (starts with /)
$css_contents = preg_replace("/url\\(\\s*['\"]?(?!data:)(?!http)(?![\\/'\"])(.+?)['\"]?\\s*\\)/i", "url(" . dirname($style_path['path']) . "/\$1)", $css_contents);
$css .= $css_contents . "\n";
$log .= "\n";
}
//remove existing out of date files
array_map('unlink', glob(WP_CONTENT_DIR . '/mmr/' . $hash . '-*.css'));
file_put_contents($full_path, $css);
file_put_contents($full_path . '.log', date('c') . " - MERGED:\n" . $log);
wp_clear_scheduled_hook('compress_css', array($full_path));
if ($this->cssmin) {
wp_schedule_single_event(time(), 'compress_css', array($full_path));
}
} else {
file_put_contents($full_path . '.accessed', current_time('timestamp'));
}
if ($min_exists) {
if ($this->http2push && !headers_sent()) {
header('Link: <' . WP_CONTENT_URL . $min_path . '>; rel=preload', false);
}
wp_register_style('header-' . $i, WP_CONTENT_URL . $min_path, false, false, $header[$i]['media']);
} else {
if ($this->http2push && !headers_sent()) {
header('Link: <' . WP_CONTENT_URL . $file_path . '>; rel=preload', false);
}
wp_register_style('header-' . $i, WP_CONTENT_URL . $file_path, false, false, $header[$i]['media']);
}
wp_enqueue_style('header-' . $i);
} else {
//external
wp_enqueue_style($header[$i]['handle']);
}
}
$wp_styles->done = $done;
}
}
示例10: minqueue_helper
/**
* Helper tool for the minifyier
*
* Uses global var $minified_deps (as well as $wp_scritps & $wp_styles)
*/
function minqueue_helper()
{
global $wp_scripts, $wp_styles, $minified_deps;
$styles_enqueued = array();
$scripts_enqueued = array();
// Get the queue of all scripts & styles that should be loaded.
// A bit of a round about way as we need to know those loaded because they are a dependency.
if (!empty($wp_scripts)) {
$scripts = wp_clone($wp_scripts);
$scripts->done = array();
$scripts->to_do = array();
$queue = array_unique(array_merge(array_keys($minified_deps['WP_Scripts']), $scripts->queue));
$scripts->all_deps($queue);
$scripts_enqueued = $scripts->to_do;
}
if (!empty($wp_styles)) {
$styles = wp_clone($wp_styles);
$styles->done = array();
$styles->to_do = array();
$queue = array_unique(array_merge(array_keys($minified_deps['WP_Styles']), $styles->queue));
$styles->all_deps($queue);
$styles_enqueued = $styles->to_do;
}
?>
<div id="minqueue-helper">
<div id="minqueue-helper-inner">
<h2>Enqueued Scripts</h2>
<ul>
<?php
minqueue_helper_list($scripts_enqueued);
?>
</ul>
<h2>Enqueued Styles</h2>
<ul>
<?php
minqueue_helper_list($styles_enqueued, false);
?>
</ul>
<p><a href="<?php
echo add_query_arg('page', 'minqueue', get_admin_url(null, 'options-general.php'));
?>
">Admin Page</a></p>
<h2>Key</h2>
<ul>
<li class="minqueue-group-0">Orange: in header</li>
<li class="minqueue-group-1">Yellow: in footer</li>
</ul>
<p>Files displayed in the order in which they are loaded.</p>
<p>Only visible to admin users.<p>
<p>Remember some scripts are loaded conditionally (on certain pages, or for logged in users etc).</p>
</div>
</div>
<?php
}
示例11: wp_set_comment_status
/**
* Sets the status of a comment.
*
* The 'wp_set_comment_status' action is called after the comment is handled and
* will only be called, if the comment status is either 'hold', 'approve', or
* 'spam'. If the comment status is not in the list, then false is returned and
* if the status is 'delete', then the comment is deleted without calling the
* action.
*
* @since 1.0.0
* @uses wp_transition_comment_status() Passes new and old comment status along with $comment object
*
* @param int $comment_id Comment ID.
* @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'delete'.
* @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false.
* @return bool False on failure or deletion and true on success.
*/
function wp_set_comment_status($comment_id, $comment_status, $wp_error = false)
{
global $wpdb;
$status = '0';
switch ($comment_status) {
case 'hold':
case '0':
$status = '0';
break;
case 'approve':
case '1':
$status = '1';
if (get_option('comments_notify')) {
$comment = get_comment($comment_id);
wp_notify_postauthor($comment_id, $comment->comment_type);
}
break;
case 'spam':
$status = 'spam';
break;
case 'trash':
$status = 'trash';
break;
default:
return false;
}
$comment_old = wp_clone(get_comment($comment_id));
if (!$wpdb->update($wpdb->comments, array('comment_approved' => $status), array('comment_ID' => $comment_id))) {
if ($wp_error) {
return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error);
} else {
return false;
}
}
clean_comment_cache($comment_id);
$comment = get_comment($comment_id);
do_action('wp_set_comment_status', $comment_id, $comment_status);
wp_transition_comment_status($comment_status, $comment_old->comment_approved, $comment);
wp_update_comment_count($comment->comment_post_ID);
return true;
}
示例12: set
/**
* Set to the cache
*
* @param string $id
* @param mixed $data
* @param string $group
* @param integer $expire
* @return boolean
*/
function set($id, $data, $group = 'default', $expire = 0)
{
$key = $this->_get_cache_key($id, $group);
if (is_object($data)) {
$data = wp_clone($data);
}
$this->cache[$key] = $data;
if ($this->_caching && !in_array($group, $this->nonpersistent_groups)) {
$cache =& $this->_get_cache();
return $cache->set($key, $data, $expire ? $expire : $this->_lifetime);
}
return true;
}
示例13: set
/**
* Set to the cache
*
* @param string $id
* @param mixed $data
* @param string $group
* @param integer $expire
* @return boolean
*/
function set($id, $data, $group = 'default', $expire = 0)
{
$key = $this->_get_cache_key($id, $group);
if (is_object($data)) {
$data = wp_clone($data);
}
if (isset($this->cache[$key]) && $this->cache[$key] === $data) {
return true;
}
$this->cache[$key] = $data;
$reason = '';
if ($this->_can_cache2($id, $group, $reason)) {
$cache =& $this->_get_cache();
return $cache->set($key, $data, $expire ? $expire : $this->_lifetime);
}
return true;
}
示例14: set
/**
* Set to the cache
*
* @param string $id
* @param mixed $data
* @param string $group
* @param integer $expire
* @return boolean
*/
function set($id, $data, $group = 'default', $expire = 0)
{
$key = $this->_get_cache_key($id, $group);
if (is_object($data)) {
$data = wp_clone($data);
}
$this->cache[$key] = $data;
if ($this->_caching && !in_array($group, $this->nonpersistent_groups) && $this->_check_can_cache_runtime($group)) {
$cache = $this->_get_cache(null, $group);
if ($id == 'alloptions' && $group == 'options') {
// alloptions are deserialized on the start when some classes are not loaded yet
// so postpone it until requested
foreach ($data as $k => $v) {
if (is_object($v)) {
$data[$k] = serialize($v);
}
}
}
$v = array('content' => $data);
return $cache->set($key, $v, $expire ? $expire : $this->_lifetime);
}
return true;
}
示例15: stats_get_post
function stats_get_post($post)
{
if (!($post = get_post($post))) {
return null;
}
$stats_post = wp_clone($post);
$stats_post->permalink = get_permalink($post);
foreach (array('post_content', 'post_excerpt', 'post_content_filtered', 'post_password') as $do_not_want) {
unset($stats_post->{$do_not_want});
}
return $stats_post;
}