📄 functions.php
字号:
$notify_message = "A new comment on the post #$comment->comment_post_ID \"".stripslashes($post->post_title)."\" is waiting for your approval\r\n\r\n";
$notify_message .= "Author : $comment->comment_author (IP: $comment->comment_author_IP , $comment_author_domain)\r\n";
$notify_message .= "E-mail : $comment->comment_author_email\r\n";
$notify_message .= "URL : $comment->comment_author_url\r\n";
$notify_message .= "Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=$comment->comment_author_IP\r\n";
$notify_message .= "Comment:\r\n".stripslashes($comment->comment_content)."\r\n\r\n";
$notify_message .= "To approve this comment, visit: " . get_settings('siteurl') . "/wp-admin/post.php?action=mailapprovecomment&p=".$comment->comment_post_ID."&comment=$comment_id\r\n";
$notify_message .= "To delete this comment, visit: " . get_settings('siteurl') . "/wp-admin/post.php?action=confirmdeletecomment&p=".$comment->comment_post_ID."&comment=$comment_id\r\n";
$notify_message .= "Currently $comments_waiting comments are waiting for approval. Please visit the moderation panel:\r\n";
$notify_message .= get_settings('siteurl') . "/wp-admin/moderation.php\r\n";
$subject = '[' . stripslashes(get_settings('blogname')) . '] Please approve: "' .stripslashes($post->post_title).'"';
$admin_email = get_settings("admin_email");
$from = "From: $admin_email";
$message_headers = "MIME-Version: 1.0\r\n"
. "$from\r\n"
. "Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\r\n";
@mail($admin_email, $subject, $notify_message, $message_headers);
return true;
}
function start_wp() {
global $post, $id, $postdata, $authordata, $day, $preview, $page, $pages, $multipage, $more, $numpages;
global $pagenow;
if (!$preview) {
$id = $post->ID;
} else {
$id = 0;
$postdata = array (
'ID' => 0,
'Author_ID' => $_GET['preview_userid'],
'Date' => $_GET['preview_date'],
'Content' => $_GET['preview_content'],
'Excerpt' => $_GET['preview_excerpt'],
'Title' => $_GET['preview_title'],
'Category' => $_GET['preview_category'],
'Notify' => 1
);
}
$authordata = get_userdata($post->post_author);
$day = mysql2date('d.m.y', $post->post_date);
$currentmonth = mysql2date('m', $post->post_date);
$numpages = 1;
if (!$page)
$page = 1;
if (isset($p))
$more = 1;
$content = $post->post_content;
if (preg_match('/<!--nextpage-->/', $post->post_content)) {
if ($page > 1)
$more = 1;
$multipage = 1;
$content = stripslashes($post->post_content);
$content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
$content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content);
$content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content);
$pages = explode('<!--nextpage-->', $content);
$numpages = count($pages);
} else {
$pages[0] = stripslashes($post->post_content);
$multipage = 0;
}
return true;
}
function is_new_day() {
global $day, $previousday;
if ($day != $previousday) {
return(1);
} else {
return(0);
}
}
// Filters: these are the core of WP's plugin architecture
function apply_filters($tag, $string) {
global $wp_filter;
if (isset($wp_filter['all'])) {
foreach ($wp_filter['all'] as $priority => $functions) {
if (isset($wp_filter[$tag][$priority]))
$wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], $wp_filter[$tag][$priority]);
else
$wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array());
$wp_filter[$tag][$priority] = array_unique($wp_filter[$tag][$priority]);
}
}
if (isset($wp_filter[$tag])) {
ksort($wp_filter[$tag]);
foreach ($wp_filter[$tag] as $priority => $functions) {
foreach($functions as $function) {
$string = $function($string);
}
}
}
return $string;
}
function add_filter($tag, $function_to_add, $priority = 10) {
global $wp_filter;
// So the format is wp_filter['tag']['array of priorities']['array of functions']
if (!@in_array($function_to_add, $wp_filter[$tag]["$priority"])) {
$wp_filter[$tag]["$priority"][] = $function_to_add;
}
return true;
}
function remove_filter($tag, $function_to_remove, $priority = 10) {
global $wp_filter;
if (@in_array($function_to_remove, $wp_filter[$tag]["$priority"])) {
foreach ($wp_filter[$tag]["$priority"] as $function) {
if ($function_to_remove != $function) {
$new_function_list[] = $function;
}
}
$wp_filter[$tag]["$priority"] = $new_function_list;
}
//die(var_dump($wp_filter));
return true;
}
// The *_action functions are just aliases for the *_filter functions, they take special strings instead of generic content
function do_action($tag, $string) {
return apply_filters($tag, $string);
}
function add_action($tag, $function_to_add, $priority = 10) {
add_filter($tag, $function_to_add, $priority);
}
function remove_action($tag, $function_to_remove, $priority = 10) {
remove_filter($tag, $function_to_remove, $priority);
}
/* rewrite_rules
* Construct rewrite matches and queries from permalink structure.
* matches - The name of the match array to use in the query strings.
* If empty, $1, $2, $3, etc. are used.
* Returns an associate array of matches and queries.
*/
function rewrite_rules($matches = '', $permalink_structure = '') {
function preg_index($number, $matches = '') {
$match_prefix = '$';
$match_suffix = '';
if (! empty($matches)) {
$match_prefix = '$' . $matches . '[';
$match_suffix = ']';
}
return "$match_prefix$number$match_suffix";
}
$rewrite = array();
if (empty($permalink_structure)) {
$permalink_structure = get_settings('permalink_structure');
if (empty($permalink_structure)) {
return $rewrite;
}
}
$rewritecode =
array(
'%year%',
'%monthnum%',
'%day%',
'%hour%',
'%minute%',
'%second%',
'%postname%',
'%post_id%'
);
$rewritereplace =
array(
'([0-9]{4})?',
'([0-9]{1,2})?',
'([0-9]{1,2})?',
'([0-9]{1,2})?',
'([0-9]{1,2})?',
'([0-9]{1,2})?',
'([_0-9a-z-]+)?',
'([0-9]+)?'
);
$queryreplace =
array (
'year=',
'monthnum=',
'day=',
'hour=',
'minute=',
'second=',
'name=',
'p='
);
$match = str_replace('/', '/?', $permalink_structure);
$match = preg_replace('|/[?]|', '', $match, 1);
$match = str_replace($rewritecode, $rewritereplace, $match);
$match = preg_replace('|[?]|', '', $match, 1);
$feedmatch = trailingslashit(str_replace('?/?', '/', $match));
$trackbackmatch = $feedmatch;
preg_match_all('/%.+?%/', $permalink_structure, $tokens);
$query = 'index.php?';
$feedquery = 'wp-feed.php?';
$trackbackquery = 'wp-trackback.php?';
for ($i = 0; $i < count($tokens[0]); ++$i) {
if (0 < $i) {
$query .= '&';
$feedquery .= '&';
$trackbackquery .= '&';
}
$query_token = str_replace($rewritecode, $queryreplace, $tokens[0][$i]) . preg_index($i+1, $matches);
$query .= $query_token;
$feedquery .= $query_token;
$trackbackquery .= $query_token;
}
++$i;
// Add post paged stuff
$match .= '([0-9]+)?/?$';
$query .= '&page=' . preg_index($i, $matches);
// Add post feed stuff
$feedregex = '(feed|rdf|rss|rss2|atom)/?$';
$feedmatch .= $feedregex;
$feedquery .= '&feed=' . preg_index($i, $matches);
// Add post trackback stuff
$trackbackregex = 'trackback/?$';
$trackbackmatch .= $trackbackregex;
// Site feed
$sitefeedmatch = 'feed/?([_0-9a-z-]+)?/?$';
$sitefeedquery = 'wp-feed.php?feed=' . preg_index(1, $matches);
// Site comment feed
$sitecommentfeedmatch = 'comments/feed/?([_0-9a-z-]+)?/?$';
$sitecommentfeedquery = 'wp-feed.php?feed=' . preg_index(1, $matches) . '&withcomments=1';
// Code for nice categories and authors, currently not very flexible
$front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
if ( '' == get_settings('category_base') )
$catmatch = $front . 'category/';
else
$catmatch = get_settings('category_base') . '/';
$catmatch = preg_replace('|^/+|', '', $catmatch);
$catfeedmatch = $catmatch . '(.*)/' . $feedregex;
$catfeedquery = 'wp-feed.php?category_name=' . preg_index(1, $matches) . '&feed=' . preg_index(2, $matches);
$catmatch = $catmatch . '?(.*)';
$catquery = 'index.php?category_name=' . preg_index(1, $matches);
$authormatch = $front . 'author/';
$authormatch = preg_replace('|^/+|', '', $authormatch);
$authorfeedmatch = $authormatch . '(.*)/' . $feedregex;
$authorfeedquery = 'wp-feed.php?author_name=' . preg_index(1, $matches) . '&feed=' . preg_index(2, $matches);
$authormatch = $authormatch . '?(.*)';
$authorquery = 'index.php?author_name=' . preg_index(1, $matches);
$rewrite = array(
$catfeedmatch => $catfeedquery,
$catmatch => $catquery,
$authorfeedmatch => $authorfeedquery,
$authormatch => $authorquery,
$match => $query,
$feedmatch => $feedquery,
$trackbackmatch => $trackbackquery,
$sitefeedmatch => $sitefeedquery,
$sitecommentfeedmatch => $sitecommentfeedquery
);
return $rewrite;
}
function get_posts($args) {
global $wpdb, $tableposts;
parse_str($args, $r);
if (!isset($r['numberposts'])) $r['numberposts'] = 5;
if (!isset($r['offset'])) $r['offset'] = 0;
// The following not implemented yet
if (!isset($r['category'])) $r['category'] = '';
if (!isset($r['orderby'])) $r['orderby'] = '';
if (!isset($r['order'])) $r['order'] = '';
$now = current_time('mysql');
$posts = $wpdb->get_results("SELECT DISTINCT * FROM $tableposts WHERE post_date <= '$now' AND (post_status = 'publish') GROUP BY $tableposts.ID ORDER BY post_date DESC LIMIT " . $r['offset'] . ',' . $r['numberposts']);
return $posts;
}
function check_comment($author, $email, $url, $comment, $user_ip) {
if (1 == get_settings('comment_moderation')) return false; // If moderation is set to manual
if ( (count(explode('http:', $comment)) - 1) >= get_settings('comment_max_links') )
return false; // Check # of external links
if ('' == trim( get_settings('moderation_keys') ) ) return true; // If moderation keys are empty
$words = explode("\n", get_settings('moderation_keys') );
foreach ($words as $word) {
$word = trim($word);
$pattern = "#$word#i";
if ( preg_match($pattern, $author) ) return false;
if ( preg_match($pattern, $email) ) return false;
if ( preg_match($pattern, $url) ) return false;
if ( preg_match($pattern, $comment) ) return false;
if ( preg_match($pattern, $user_ip) ) return false;
}
return true;
}
function wp_head() {
do_action('wp_head', '');
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -