/** * 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; }
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; }
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; }
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; }
/** * 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; }
/** * 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; }
/** * Checks for a template to use, and if it exists, copies the templated settings to the new blog * * @param mixed $blog_id * @param mixed $user_id * * @since 1.0 */ function set_blog_defaults($blog_id, $user_id, $_passed_domain = false, $_passed_path = false, $_passed_site_id = false, $_passed_meta = false) { global $wpdb, $multi_dm; /* Start special Multi-Domain feature */ if (!empty($multi_dm)) { $bloginfo = get_blog_details((int) $blog_id, false); foreach ($multi_dm->domains as $multi_domain) { if (strpos($bloginfo->domain, $multi_domain['domain_name'])) { if (isset($multi_domain['blog_template']) && !empty($this->options['templates'][$multi_domain['blog_template']])) { $default = $this->options['templates'][$multi_domain['blog_template']]; } } } } /* End special Multi-Domain feature */ if (empty($default) && isset($this->options['default']) && is_numeric($this->options['default'])) { // select global default $default = isset($this->options['templates'][$this->options['default']]) ? $this->options['templates'][$this->options['default']] : false; } $template = ''; // Check $_POST first for passed template and use that, if present. // Otherwise, check passed meta from blog signup. // Lastly, apply the default. if (isset($_POST['blog_template']) && is_numeric($_POST['blog_template'])) { //If they've chosen a template, use that. For some reason, when PHP gets 0 as a posted var, it doesn't recognize it as is_numeric, so test for that specifically $template = $this->options['templates'][$_POST['blog_template']]; } else { if ($_passed_meta && isset($_passed_meta['blog_template']) && is_numeric($_passed_meta['blog_template'])) { // Do we have a template in meta? $template = $this->options['templates'][$_passed_meta['blog_template']]; // Why, yes. Yes, we do. Use that. } else { if ($default) { //If they haven't chosen a template, use the default if it exists $template = $default; } } } $template = apply_filters('blog_templates-blog_template', $template, $blog_id, $user_id, $this); if (!$template || 'none' == $template) { return; } //No template, lets leave //Begin the transaction $wpdb->query("BEGIN;"); switch_to_blog($blog_id); //Switch to the blog that was just created //Get the prefixes, so we don't have to worry about regex, or changes to WP's naming conventions $new_prefix = $wpdb->prefix; //Don't forget to get the template blog's prefix switch_to_blog($template['blog_id']); $template_prefix = $wpdb->prefix; //Now, go back to the new blog that was just created restore_current_blog(); foreach ($template['to_copy'] as $value) { switch ($value) { case 'settings': //We can't use the helper functions here, because we need to save some of the settings $exclude_settings = apply_filters('blog_template_exclude_settings', "`option_name` != 'siteurl' AND `option_name` != 'blogname' AND `option_name` != 'admin_email' AND `option_name` != 'new_admin_email' AND `option_name` != 'home' AND `option_name` != 'upload_path' AND `option_name` != 'db_version' AND `option_name` != 'secret' AND `option_name` != 'fileupload_url' AND `option_name` != 'nonce_salt'"); //Delete the current options, except blog-specific options $wpdb->query("DELETE FROM {$wpdb->options} WHERE {$exclude_settings}"); if (!$wpdb->last_error) { //No error. Good! Now copy over the old settings //Switch to the template blog, then grab the settings/plugins/templates values from the template blog switch_to_blog($template['blog_id']); $templated = $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE {$exclude_settings}"); restore_current_blog(); //Switch back to the newly created blog //Now, insert the templated settings into the newly created blog foreach ($templated as $row) { //Make sure none of the options are using wp_X_ convention, and if they are, replace the value with the new blog ID $row->option_name = str_replace($template_prefix, $new_prefix, $row->option_name); if ('sidebars_widgets' != $row->option_name) { /* <-- Added this to prevent unserialize() call choking on badly formatted widgets pickled array */ $row->option_value = str_replace($template_prefix, $new_prefix, $row->option_value); } //To prevent duplicate entry errors, since we're not deleting ALL of the options, there could be an ID collision unset($row->option_id); // For template blogs with deprecated DB schema (WP3.4+) if (!(defined('NBT_TIGHT_ROW_DUPLICATION') && NBT_TIGHT_ROW_DUPLICATION)) { unset($row->blog_id); } // Add further processing for options row $row = apply_filters('blog_templates-copy-options_row', $row, $template, $blog_id, $user_id); if (!$row) { continue; } // Prevent empty row insertion //Insert the row $wpdb->insert($wpdb->options, (array) $row); //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 settings)', $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); } } do_action('blog_templates-copy-options', $template); } else { $error = '<div id="message" class="error"><p>' . sprintf(__('Deletion Error: %s - The template was not applied. (New Blog Templates - While removing auto-generated settings)', $this->localization_domain), $wpdb->last_error) . '</p></div>'; $wpdb->query("ROLLBACK;"); restore_current_blog(); //Switch back to our current blog wp_die($error); } break; case 'posts': $this->clear_table($wpdb->posts); $this->copy_table($template['blog_id'], "posts"); do_action('blog_templates-copy-posts', $template, $blog_id, $user_id); $this->clear_table($wpdb->postmeta); $this->copy_table($template['blog_id'], "postmeta"); do_action('blog_templates-copy-postmeta', $template, $blog_id, $user_id); break; case 'terms': $this->clear_table($wpdb->links); $this->copy_table($template['blog_id'], "links"); do_action('blog_templates-copy-links', $template, $blog_id, $user_id); $this->clear_table($wpdb->terms); $this->copy_table($template['blog_id'], "terms"); do_action('blog_templates-copy-terms', $template, $blog_id, $user_id); $this->clear_table($wpdb->term_relationships); $this->copy_table($template['blog_id'], "term_relationships"); do_action('blog_templates-copy-term_relationships', $template, $blog_id, $user_id); $this->clear_table($wpdb->term_taxonomy); $this->copy_table($template['blog_id'], "term_taxonomy"); do_action('blog_templates-copy-term_taxonomy', $template, $blog_id, $user_id); break; case 'users': //Copy over the users to this blog $users = $wpdb->get_results("SELECT * FROM {$wpdb->usermeta} WHERE user_id != {$user_id} AND meta_key REGEXP '^" . mysql_escape_string($template_prefix) . "[^0-9]'"); if (empty($users)) { continue; } //If there are no users to copy, just leave. We don't want to leave this blog without any users //Delete the auto user from the blog, to prevent duplicates or erroneous users $wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE user_id != {$user_id} AND meta_key LIKE '" . mysql_escape_string($new_prefix) . "%'"); if (!empty($wpdb->last_error)) { $error = '<div id="message" class="error"><p>' . sprintf(__('Deletion Error: %s - The template was not applied. (New Blog Templates - While removing auto-generated 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); } $postprocess_add_new_user_action = false; //Now, insert the templated settings into the newly created blog foreach ($users as $user) { // Check if the user ID from email entered via the New Blog form has been added, and if not, add them after the foreach loop... if (!$postprocess_add_new_user_action && $user->user_id != $user_id) { $postprocess_add_new_user_action = true; } if ($user->user_id == $user_id) { continue; } // Carry on... $user->meta_key = str_replace($template_prefix, $new_prefix, $user->meta_key); unset($user->umeta_id); //Remove the umeta_id field, let it autoincrement // Further user entry processing $user = apply_filters('blog_templates-copy-user_entry', $user, $template, $blog_id, $user_id); 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) { $add = mysql_escape_string($add); //Just in case $result = $wpdb->get_results("SHOW TABLES LIKE '" . str_replace($template_prefix, $new_prefix, $add) . "'", ARRAY_N); if (!empty($result)) { //Is the table present? Clear it, then copy //echo ("table exists: $add<br/>"); $this->clear_table($add); //Copy the DB $this->copy_table($template['blog_id'], str_replace($template_prefix, '', $add)); } else { //The table's not present, add it and copy the data from the old one //echo ('table doesn\'t exist<br/>'); /* -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */ // Changed if (class_exists("m_wpdb")) { $conns = $wpdb->dbh_connections; //$multi_db = $conns['global']['name'] . '.'; unset($conns['global']); $current = current($conns); $current_db = $current['name'] . '.'; $add_table = explode('.', $add); $add_table = $add_table[1]; } else { $multi_db = $current_db = ''; $add_table = $add; } $wpdb->query("CREATE TABLE IF NOT EXISTS {$current_db}" . str_replace($template_prefix, $new_prefix, $add_table) . " LIKE {$add}"); $wpdb->query("INSERT {$current_db}" . str_replace($template_prefix, $new_prefix, $add_table) . " SELECT * FROM {$add}"); // End changed /* -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */ if (!empty($wpdb->last_error)) { $error = '<div id="message" class="error"><p>' . sprintf(__('Insertion Error: %s - The template was not applied. (New Blog Templates - With CREATE TABLE query for Additional Tables)', $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); } } } } //error_log('Finished Successfully'); $wpdb->query("COMMIT;"); //If we get here, everything's fine. Commit the transaction do_action("blog_templates-copy-after_copying", $template, $blog_id, $user_id); restore_current_blog(); //Switch back to our current blog }
/** * 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; }
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; } }
/** * 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 }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
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; }
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 { _e("<span class=\"error\">Was unable to copy images and uploads!</span>", 'acswpmu_trdom'); } } } //reset permalink structure if (!$error) { switch_to_blog($new_blog_id); //_e("Switched from here to $new_blog_id to reset permalinks<br>", 'acswpmu_trdom' ); global $wp_rewrite; $wp_rewrite->init();