Created
June 18, 2013 20:54
-
-
Save tylerdigital/5809265 to your computer and use it in GitHub Desktop.
A rough plugin for adding action tags to Jetpack's Post By Email. Note, these only get executed when clicking publish/update in the wp-admin currently. This is a project for personal use, any my needs were to publish a draft by email quickly, and then publish via the web interface. Some additional work would be necessary to have the tags execute…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Post By Email Customizations | |
Plugin URI: http://tylerdigital.com | |
Description: Handle Jetpack Post By Email – featured images, post formats, post content | |
Version: 1.0 | |
Author: Tyler Digital | |
Author URI: http://tylerdigital.com | |
*/ | |
/** | |
* Copyright (c) 2013 Tyler Digital. All rights reserved. | |
* | |
* Released under the GPL license | |
* http://www.opensource.org/licenses/gpl-license.php | |
* | |
* This is an add-on for WordPress | |
* http://wordpress.org/ | |
* | |
* ********************************************************************** | |
* This program is free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 2 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* ********************************************************************** | |
*/ | |
if ( !defined( 'ABSPATH' ) ) exit; | |
add_action( 'save_post', 'td_auto_featured_image' ); | |
function td_auto_featured_image( $post_id ) { | |
if ( ! get_post_status( $post_id=='publish' ) ) return false; | |
if ( !has_tag( 'auto-thumb', $post_id ) ) return false; | |
if ( has_post_thumbnail( $post_id ) ) return false; | |
if ( wp_is_post_revision( $post_id ) ) return false; | |
// unhook this function so it doesn't loop infinitely | |
remove_action('save_post', 'td_auto_featured_image'); | |
$post_tags = wp_get_post_tags( $post_id ); | |
foreach ( $post_tags as $key => $post_tag ) { | |
if ( $post_tag->name!='auto-thumb' && $post_tag->slug!='auto-thumb' ) { | |
$new_post_tags[] = $post_tag->name; | |
} | |
} | |
$args = array( | |
'numberposts' => 1, | |
'order' => 'ASC', // DESC for the last image | |
'post_mime_type' => 'image', | |
'post_parent' => $post_id, | |
'post_status' => NULL, | |
'post_type' => 'attachment' | |
); | |
$attached_image = get_children( $args ); | |
if ( $attached_image ) { | |
foreach ( $attached_image as $attachment_id => $attachment ) | |
if ( set_post_thumbnail( $post_id, $attachment_id ) ) { | |
wp_set_post_tags( $post_id, $new_post_tags ); | |
break; | |
} | |
} | |
// re-hook this function | |
add_action('save_post', 'td_auto_featured_image'); | |
} | |
add_action( 'save_post', 'td_clear_post_content' ); | |
function td_clear_post_content( $post_id ) { | |
if ( ! get_post_status( $post_id=='publish' ) ) return false; | |
if ( ! has_tag( 'clear-content', $post_id ) ) return false; | |
if ( wp_is_post_revision( $post_id ) ) return false; | |
// unhook this function so it doesn't loop infinitely | |
remove_action('save_post', 'td_clear_post_content'); | |
$post_tags = wp_get_post_tags( $post_id ); | |
foreach ( $post_tags as $key => $post_tag ) { | |
if ( $post_tag->name!='clear-content' && $post_tag->slug!='clear-content' ) { | |
$new_post_tags[] = $post_tag->name; | |
} | |
} | |
if ( wp_update_post( array( | |
'ID' => $post_id, | |
'post_content' => '', | |
) ) ) wp_set_post_tags( $post_id, $new_post_tags ); | |
// re-hook this function | |
add_action('save_post', 'td_clear_post_content'); | |
} | |
add_action( 'save_post', 'td_post_format_image' ); | |
function td_post_format_image( $post_id ) { | |
if ( ! get_post_status( $post_id=='publish' ) ) return false; | |
if ( ! has_tag( 'format-image', $post_id ) ) return false; | |
if ( wp_is_post_revision( $post_id ) ) return false; | |
// unhook this function so it doesn't loop infinitely | |
remove_action('save_post', 'td_post_format_image'); | |
$post_tags = wp_get_post_tags( $post_id ); | |
foreach ( $post_tags as $key => $post_tag ) { | |
if ( $post_tag->name!='format-image' && $post_tag->slug!='format-image' ) { | |
$new_post_tags[] = $post_tag->name; | |
} | |
} | |
if ( set_post_format( $post_id, 'image' ) ) wp_set_post_tags( $post_id, $new_post_tags ); | |
// re-hook this function | |
add_action('save_post', 'td_post_format_image'); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment