Beispiel #1
0
/*****
Version: BYMT 2.1.1
Author: 麦葱 http://maicong.me
*****/
get_header();
?>
<div id="content-wrap">
	<div id="content-main">
		<?php 
if (have_posts()) {
    while (have_posts()) {
        the_post();
        ?>
		<div class="post-single">
			<?php 
        if (is_new_post()) {
            echo '<span class="post-new"></span>';
        } elseif (is_sticky()) {
            echo '<span class="post-sticky"></span>';
        }
        ?>
			<div class="post-header">
				<h2 class="post-title"><?php 
        the_title();
        ?>
</h2>
			</div>
			<div class="post-meta">
			<?php 
        if (!wp_is_mobile()) {
            ?>
 function notify_on_post_update($new_status, $old_status, $post_id)
 {
     // Not a post revision
     if (wp_is_post_revision($post_id)) {
         return;
     }
     // And only if it's published
     if (get_post_status($post_id) == 'publish') {
         // Only look for the author if it's not an attachment, and only
         // tell us about the author if he has a name.
         if (get_post_type($post_id) != 'attachment') {
             if (get_the_modified_author($post_id) != null) {
                 $author = " by " . get_the_modified_author($post_id);
             }
         } else {
             $author = null;
         }
         // Some useful variables for building our messages.
         $post_title = get_the_title($post_id);
         $post_url = get_permalink($post_id);
         $post_type = ucwords(get_post_type($post_id));
         // Building the subject and body depending on whether this is a new post or not.
         if (is_new_post($new_status, $old_status)) {
             $title = "New " . $post_type;
             $short_message = "New " . $post_type . " Added" . ucwords($author);
             $email_body = "A new " . strtolower($post_type) . ", '" . $post_title . "' (" . $post_url . "), has been published" . $author . ".";
         } else {
             $title = "Updated " . $post_type;
             $short_message = $post_type . " Updated" . ucwords($author);
             $email_body = "The " . strtolower($post_type) . " '" . $post_title . "' (" . $post_url . ") has been updated" . $author . ".";
         }
         $subject = get_bloginfo('name') . ': ' . $short_message;
         // Check if it's a Slack Webhook URL
         if (strpos(WPLT_NOTIFY, 'hooks.slack.com') !== false) {
             // Check if we've defined a Slack channel
             $bot_args = array('attachments' => array(0 => array('fallback' => $short_message, 'color' => '#F40101', 'author_name' => $short_message, 'author_link' => $post_url, 'title' => $post_title, 'title_link' => $post_url, 'text' => $post_url)), 'icon_emoji' => ':triangular_flag_on_post:', 'username' => get_bloginfo('name'), 'unfurl_links' => true);
             // Check if we've defined a Slack channel. If we have, slip the
             // channel into our Slack payload.
             if (defined('WPLT_NOTIFY_CHANNEL') && WPLT_NOTIFY_CHANNEL) {
                 $bot_args['channel'] = WPLT_NOTIFY_CHANNEL;
             }
             $payload = array('payload' => json_encode($bot_args));
             // Send the payload to Slack.
             $posting = wp_remote_post(WPLT_NOTIFY, array('body' => $payload));
             // If it's not a Slack Webhook URL, send an email instead.
         } else {
             wp_mail(WPLT_NOTIFY, $subject, $email_body);
         }
     }
     // end if (get_post_status($post_id) == 'publish')
 }