Skip to content

Instantly share code, notes, and snippets.

@imath
Created December 23, 2016 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imath/4c8d4151fcb255d6f2eb78b03fb633c8 to your computer and use it in GitHub Desktop.
Save imath/4c8d4151fcb255d6f2eb78b03fb633c8 to your computer and use it in GitHub Desktop.
<?php
/**
* WP Idea Stream Custom
*
* If i'm located in WP_PLUGIN_DIR, WP Idea Stream will load me.
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Notify an admin once the idea's has been saved as 'pending' from the front end.
*/
function wp_idea_stream_custom_notify_admin( $idea_ID = 0, $idea = null ) {
if ( empty( $idea->status ) || empty( $idea->author ) || 'pending' !== $idea->status ) {
return;
}
// Get The blogname
$blogname = wp_specialchars_decode( get_option('blogname' ), ENT_QUOTES );
// Start the message
$message = sprintf( __( 'New pending idea on your site %s:', 'wp-idea-stream-custom' ), $blogname ) . "\r\n\r\n";
$message .= sprintf( __( 'Title: %s', 'wp-idea-stream-custom' ), esc_html( $idea->title ) ) . "\r\n\r\n";
$message .= sprintf( __( 'Moderate: %s', 'wp-idea-stream-custom' ), esc_url_raw( get_edit_post_link( $idea_ID ) ) ) . "\r\n";
// Send the notification
@wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] New pending idea', 'wp-idea-stream-custom' ), $blogname ), $message );
return true;
}
add_action( 'wp_idea_stream_ideas_after_insert_idea', 'wp_idea_stream_custom_notify_admin', 10, 2 );
/**
* Notify an author once the idea's status transitionned from 'pending' to 'publish'
*/
function wp_idea_stream_custom_notify_author( $new_status = '', $old_status = '', $post = null ) {
if ( empty( $post->post_type ) || wp_idea_stream_get_post_type() !== $post->post_type ) {
return;
}
$author = get_user_by( 'id', $post->post_author );
if ( ! $author ) {
return;
}
if ( 'publish' === $new_status && 'pending' === $old_status ) {
// Get The blogname
$blogname = wp_specialchars_decode( get_option('blogname' ), ENT_QUOTES );
// Start the message
$message = sprintf( __( 'A pending idea has been published on the site %s:', 'wp-idea-stream-custom' ), $blogname ) . "\r\n\r\n";
$message .= sprintf( __( 'Title: %s', 'wp-idea-stream-custom' ), esc_html( $post->post_title ) ) . "\r\n\r\n";
$message .= sprintf( __( 'View: %s', 'wp-idea-stream-custom' ), esc_url_raw( wp_idea_stream_ideas_get_idea_permalink( $post->ID ) ) ) . "\r\n";
// Send the notification
@wp_mail( $author->user_email, sprintf( __( '[%s] New published idea', 'wp-idea-stream-custom' ), $blogname ), $message );
}
return true;
}
add_action( 'transition_post_status', 'wp_idea_stream_custom_notify_author', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment