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);
}
}

WordPress : Custom roles Users in post author drop down

// Filter to fix the Post Author Dropdown
function author_override( $output ) {
    global $post, $user_ID;

    // return if this isn't the theme author override dropdown
    if (!preg_match('/post_author_override/', $output)) return $output;

    // return if we've already replaced the list (end recursion)
    if (preg_match ('/post_author_override_replaced/', $output)) return $output;

    // replacement call to wp_dropdown_users
      $output = wp_dropdown_users(array(
        'echo' => 0,
        'name' => 'post_author_override_replaced',
        'selected' => empty($post->ID) ? $user_ID : $post->post_author,
        'include_selected' => true
      ));

      // put the original name back
      $output = preg_replace('/post_author_override_replaced/', 'post_author_override', $output);

    return $output;
}
add_filter('wp_dropdown_users', 'author_override');

WordPress : Change _e() tag text

add_filter( ‘gettext’, ‘dikka_child_change_trans_text’, 20, 3 );
function dikka_child_change_trans_text( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case ‘Fields marked with an asterisk (*) must be filled out before submitting.’ :
$translated_text = __( ‘(*) Mandatory Fields’, ‘jobman’ );
break;
}
return $translated_text;
}

PHP : Generate Excel file

<?php

$header = array(‘First Name’,’Last Name’,’About you Description’);

// Create a array having xls information to print. It could be get from database.
$xls_data_to_print = array(
‘0’=>array(
‘first_name’=> ‘John’,
‘last_name’=> ‘Rawal’,
‘about_info’=> ‘He is a great player.’,
),

‘1’=>array(
‘first_name’=> ‘John1’,
‘last_name’=> ‘Rawal1’,
‘about_info’=> ‘He is a great player1.’,
),

);
$xls_content_row = ”;
foreach($xls_data_to_print as $xls_ky => $xls_val){
// Write a code here to generate XLS file with required details.
// Use $xls_val->title OR $xls_val[‘title’] depending array type.
$rows = array();
$rows[]= $xls_val[‘first_name’];
$rows[]= $xls_val[‘last_name’];
$rows[]= $xls_val[‘about_info’];

$xls_content_row .= implode(“\t”, array_values($rows)) . “\r\n”;
}
$xls_content_header = implode(“\t”, array_values($header));
$xls_content = $xls_content_header.”\n”.$xls_content_row;
$filename = ‘Xls_data_list_’.date(“d_m_Y”);
header(“Content-type: text/plain; charset=UTF-8”);
header(“Content-Disposition: attachment; filename=$filename”);
header(“Content-Type: application/vnd.ms-excel”);
header(“Pragma: no-cache”);
header(“Expires: 0”);
print $xls_content;
die();