/** * Removes comment ID from the comment cache. * * @since 0.0.1 * * @param int|array $ids Comment ID or array of comment IDs to remove from cache */ function clean_comment_cache($ids) { foreach ((array) $ids as $id) { hq_cache_delete($id, 'comment'); } hq_cache_set('last_changed', microtime(), 'comment'); }
/** * Updates the user's password with a new encrypted one. * * For integration with other applications, this function can be overwritten to * instead use the other package password checking algorithm. * * Please note: This function should be used sparingly and is really only meant for single-time * application. Leveraging this improperly in a plugin or theme could result in an endless loop * of password resets if precautions are not taken to ensure it does not execute on every page load. * * @since 0.0.1 * * @global hqdb $hqdb HiveQueen database abstraction object. * * @param string $password The plaintext new user password * @param int $user_id User ID */ function hq_set_password($password, $user_id) { global $hqdb; $hash = hq_hash_password($password); $hqdb->update($hqdb->users, array('user_pass' => $hash, 'user_activation_key' => ''), array('ID' => $user_id)); hq_cache_delete($user_id, 'users'); }
/** * @access public */ public function flush_widget_cache() { hq_cache_delete('widget_recent_comments', 'widget'); }
/** * Purge the cached results of get_calendar. * * @see get_calendar * @since 0.0.1 */ function delete_get_calendar_cache() { hq_cache_delete('get_calendar', 'calendar'); }
/** * Populate network settings. * * @since 0.0.1 * * @global hqdb $hqdb * @global object $current_site * @global int $hq_db_version * @global HQ_Rewrite $hq_rewrite * * @param int $network_id ID of network to populate. * @return bool|HQ_Error True on success, or HQ_Error on warning (with the install otherwise successful, * so the error code must be checked) or failure. */ function populate_network($network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false) { global $hqdb, $current_site, $hq_db_version, $hq_rewrite; $errors = new HQ_Error(); if ('' == $domain) { $errors->add('empty_domain', __('You must provide a domain name.')); } if ('' == $site_name) { $errors->add('empty_sitename', __('You must provide a name for your network of sites.')); } // Check for network collision. if ($network_id == $hqdb->get_var($hqdb->prepare("SELECT id FROM {$hqdb->site} WHERE id = %d", $network_id))) { $errors->add('siteid_exists', __('The network already exists.')); } $site_user = get_user_by('email', $email); if (!is_email($email)) { $errors->add('invalid_email', __('You must provide a valid e-mail address.')); } if ($errors->get_error_code()) { return $errors; } // Set up site tables. $template = get_option('template'); $stylesheet = get_option('stylesheet'); $allowed_themes = array($stylesheet => true); if ($template != $stylesheet) { $allowed_themes[$template] = true; } if (HQ_DEFAULT_THEME != $stylesheet && HQ_DEFAULT_THEME != $template) { $allowed_themes[HQ_DEFAULT_THEME] = true; } if (1 == $network_id) { $hqdb->insert($hqdb->site, array('domain' => $domain, 'path' => $path)); $network_id = $hqdb->insert_id; } else { $hqdb->insert($hqdb->site, array('domain' => $domain, 'path' => $path, 'id' => $network_id)); } hq_cache_delete('networks_have_paths', 'site-options'); //TODO: no multisite //if ( !is_multisite() ) { $site_admins = array($site_user->user_login); $users = get_users(array('fields' => array('ID', 'user_login'))); if ($users) { foreach ($users as $user) { if (is_super_admin($user->ID) && !in_array($user->user_login, $site_admins)) { $site_admins[] = $user->user_login; } } } //} else { // $site_admins = get_site_option( 'site_admins' ); //} /* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */ $welcome_email = __('Howdy USERNAME, Your new SITE_NAME site has been successfully set up at: BLOG_URL You can log in to the administrator account with the following information: Username: USERNAME Password: PASSWORD Log in here: BLOG_URLhq-login.php We hope you enjoy your new site. Thanks! --The Team @ SITE_NAME'); $misc_exts = array('jpg', 'jpeg', 'png', 'gif', 'mov', 'avi', 'mpg', '3gp', '3g2', 'midi', 'mid', 'pdf', 'doc', 'ppt', 'odt', 'pptx', 'docx', 'pps', 'ppsx', 'xls', 'xlsx', 'key'); $audio_exts = hq_get_audio_extensions(); $video_exts = hq_get_video_extensions(); $upload_filetypes = array_unique(array_merge($misc_exts, $audio_exts, $video_exts)); $sitemeta = array('site_name' => $site_name, 'admin_email' => $site_user->user_email, 'admin_user_id' => $site_user->ID, 'registration' => 'none', 'upload_filetypes' => implode(' ', $upload_filetypes), 'blog_upload_space' => 100, 'fileupload_maxk' => 1500, 'site_admins' => $site_admins, 'allowedthemes' => $allowed_themes, 'illegal_names' => array('www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files'), 'hqmu_upgrade_site' => $hq_db_version, 'welcome_email' => $welcome_email, 'first_post' => __('Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!'), 'siteurl' => get_option('siteurl') . '/', 'add_new_users' => '0', 'upload_space_check_disabled' => '1', 'subdomain_install' => intval($subdomain_install), 'global_terms_enabled' => global_terms_enabled() ? '1' : '0', 'ms_files_rewriting' => '0', 'initial_db_version' => get_option('initial_db_version'), 'active_sitewide_plugins' => array(), 'HQLANG' => get_locale()); if (!$subdomain_install) { $sitemeta['illegal_names'][] = 'blog'; } /** * Filter meta for a network on creation. * * @since 0.0.1 * * @param array $sitemeta Associative array of network meta keys and values to be inserted. * @param int $network_id ID of network to populate. */ $sitemeta = apply_filters('populate_network_meta', $sitemeta, $network_id); $insert = ''; foreach ($sitemeta as $meta_key => $meta_value) { if (is_array($meta_value)) { $meta_value = serialize($meta_value); } if (!empty($insert)) { $insert .= ', '; } $insert .= $hqdb->prepare("( %d, %s, %s)", $network_id, $meta_key, $meta_value); } $hqdb->query("INSERT INTO {$hqdb->sitemeta} ( site_id, meta_key, meta_value ) VALUES " . $insert); /* * When upgrading from single to multisite, assume the current site will * become the main site of the network. When using populate_network() * to create another network in an existing multisite environment, skip * these steps since the main site of the new network has not yet been * created. */ //TODO: no multisite //if ( ! is_multisite() ) { $current_site = new stdClass(); $current_site->domain = $domain; $current_site->path = $path; $current_site->site_name = ucfirst($domain); $hqdb->insert($hqdb->blogs, array('site_id' => $network_id, 'blog_id' => 1, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql'))); $current_site->blog_id = $blog_id = $hqdb->insert_id; update_user_meta($site_user->ID, 'source_domain', $domain); update_user_meta($site_user->ID, 'primary_blog', $blog_id); if ($subdomain_install) { $hq_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/'); } else { $hq_rewrite->set_permalink_structure('/blog/%year%/%monthnum%/%day%/%postname%/'); } flush_rewrite_rules(); if (!$subdomain_install) { return true; } $vhost_ok = false; $errstr = ''; $hostname = substr(md5(time()), 0, 6) . '.' . $domain; // Very random hostname! $page = hq_remote_get('http://' . $hostname, array('timeout' => 5, 'httpversion' => '1.1')); if (is_hq_error($page)) { $errstr = $page->get_error_message(); } elseif (200 == hq_remote_retrieve_response_code($page)) { $vhost_ok = true; } if (!$vhost_ok) { $msg = '<p><strong>' . __('Warning! Wildcard DNS may not be configured correctly!') . '</strong></p>'; $msg .= '<p>' . sprintf(__('The installer attempted to contact a random hostname (<code>%1$s</code>) on your domain.'), $hostname); if (!empty($errstr)) { $msg .= ' ' . sprintf(__('This resulted in an error message: %s'), '<code>' . $errstr . '</code>'); } $msg .= '</p>'; $msg .= '<p>' . __('To use a subdomain configuration, you must have a wildcard entry in your DNS. This usually means adding a <code>*</code> hostname record pointing at your web server in your DNS configuration tool.') . '</p>'; $msg .= '<p>' . __('You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message.') . '</p>'; return new HQ_Error('no_wildcard_dns', $msg); } //} return true; }
/** * Delete a site transient. * * @since 0.0.1 * * @param string $transient Transient name. Expected to not be SQL-escaped. * @return bool True if successful, false otherwise */ function delete_site_transient($transient) { /** * Fires immediately before a specific site transient is deleted. * * The dynamic portion of the hook name, `$transient`, refers to the transient name. * * @since 0.0.1 * * @param string $transient Transient name. */ do_action('delete_site_transient_' . $transient, $transient); if (hq_using_ext_object_cache()) { $result = hq_cache_delete($transient, 'site-transient'); } else { $option_timeout = '_site_transient_timeout_' . $transient; $option = '_site_transient_' . $transient; $result = delete_site_option($option); if ($result) { delete_site_option($option_timeout); } } if ($result) { /** * Fires after a transient is deleted. * * @since 0.0.1 * * @param string $transient Deleted transient name. */ do_action('deleted_site_transient', $transient); } return $result; }
/** * Hook for managing future post transitions to published. * * @since 0.0.1 * @access private * * @see hq_clear_scheduled_hook() * @global hqdb $hqdb HiveQueen database abstraction object. * * @param string $new_status New post status. * @param string $old_status Previous post status. * @param HQ_Post $post Post object. */ function _transition_post_status($new_status, $old_status, $post) { global $hqdb; if ($old_status != 'publish' && $new_status == 'publish') { // Reset GUID if transitioning to publish and it is empty. if ('' == get_the_guid($post->ID)) { $hqdb->update($hqdb->posts, array('guid' => get_permalink($post->ID)), array('ID' => $post->ID)); } /** * Fires when a post's status is transitioned from private to published. * * @since 0.0.1 * @deprecated 2.3.0 Use 'private_to_publish' instead. * * @param int $post_id Post ID. */ do_action('private_to_published', $post->ID); } // If published posts changed clear the lastpostmodified cache. if ('publish' == $new_status || 'publish' == $old_status) { foreach (array('server', 'gmt', 'blog') as $timezone) { hq_cache_delete("lastpostmodified:{$timezone}", 'timeinfo'); hq_cache_delete("lastpostdate:{$timezone}", 'timeinfo'); } } if ($new_status !== $old_status) { hq_cache_delete(_count_posts_cache_key($post->post_type), 'counts'); hq_cache_delete(_count_posts_cache_key($post->post_type, 'readable'), 'counts'); } // Always clears the hook in case the post status bounced from future to draft. hq_clear_scheduled_hook('publish_future_post', array($post->ID)); }
/** * Clears the Plugins cache used by get_plugins() and by default, the Plugin Update cache. * * @since 0.0.1 * * @param bool $clear_update_cache Whether to clear the Plugin updates cache */ function hq_clean_plugins_cache($clear_update_cache = true) { if ($clear_update_cache) { delete_site_transient('update_plugins'); } hq_cache_delete('plugins', 'plugins'); }