WordPress : Post publish email

add_action(‘transition_post_status’,’pending_submission_send_email’, 10, 3 );
function pending_submission_send_email( $new_status, $old_status, $post ) {

// Notifiy Admin that Contributor has writen a post
if ($new_status == ‘pending’ && !user_can($post->post_author, ‘publish_posts’)) {

// $pending_submission_email = get_option(‘pending_submission_notification_admin_email’);
$pending_submission_email = get_option(‘admin_email’) ;
$admins = (empty($pending_submission_email)) ? get_option(‘admin_email’) : $pending_submission_email;
$url = get_permalink($post->ID);
$edit_link = get_edit_post_link($post->ID, ”);
$preview_link = get_permalink($post->ID) . ‘&preview=true’;
$username = get_userdata($post->post_author);
$username_last_edit = get_the_modified_author($post->ID);
$post_modified = $post->post_modified;
$subject = ‘New submission pending review: “‘ . $post->post_title . ‘”‘;
$message = ‘A new submission is pending review.’;
$message .= “\r\n\r\n”;
$message .= “Author: $username->user_login\r\n”;
$message .= “Title: $post->post_title\r\n”;
$message .= “Last Edited By: $username_last_edit\r\n”;
$message .= “Last Edited Date: $post->post_modified”;
$message .= “\r\n\r\n”;
$message .= “Edit the submission: $edit_link\r\n”;
$message .= “Preview it: $preview_link”;
$result = wp_mail($admins, $subject, $message);
}

// Notifiy Contributor that Admin has published their post

else if ($old_status == ‘pending’ && $new_status == ‘publish’ && !user_can($post->post_author, ‘publish_posts’)) {
$username = get_userdata($post->post_author);
$url = get_permalink($post->ID);
$subject = “Your submission is now live:” . ” ” . $post->post_title;
$message = ‘”‘ . $post->post_title . ‘”‘ . ” was just published!. \r\n”;
$message .= $url;
$result = wp_mail($username->user_email, $subject, $message);
}
}

ZF2 : Get Prams into view and Layout

Helper

namespace Application\View\Helper;

/**
 * Description of Params
 *
 * @author Ravi Gupta <ravi.gupta@a3logics.in>
 */
use Zend\Mvc\MvcEvent;
use Zend\Stdlib\RequestInterface;
use Zend\View\Helper\AbstractHelper;

class Params extends AbstractHelper
{
 protected $request;
 protected $event;

public function __invoke($param = null, $default = null)
 {
 if ($param === null) {
 return $this;
 }
 return $this->fromRoute($param, $default);
 }

public function __construct(RequestInterface $request, MvcEvent $event)
 {
 $this->request = $request;
 $this->event = $event;
 }

public function fromPost($param = null, $default = null)
 {
 if ($param === null) {
 return $this->request->getPost($param, $default)->toArray();
 }

return $this->request->getPost($param, $default);
 }

public function fromRoute($param = null, $default = null)
 {
 if ($param === null) {
 return $this->event->getRouteMatch()->getParams();
 }

return $this->event->getRouteMatch()->getParam($param, $default);
 }
}

Register Factory to Module.php

 public function getViewHelperConfig()
 {
 return array(
 'factories' => array(
 'Params' => function (\Zend\ServiceManager\ServiceLocatorInterface $helpers){
 $services = $helpers->getServiceLocator();
 $app = $services->get('Application');
 return new View\Helper\Params($app->getRequest(), $app->getMvcEvent());
 }
 ),
 );
 }