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

PHP : File upload using Rest API in ShairePoint

To upload the file in share point we are using auth-client service for authentication and through that, we will have access token which will help us to communicate to the Sharepoint

1. Register the app into SharePoint.

· Navigate to https://your_site_name.com/_layouts/15/appregnew.aspx or https://your_site_name.sharepoint.com/sites/sitename/_layouts/15/appregnew.aspx
· Click Generate for Client Id and Client Secret. Continue reading

PHP : Get all Timezones

<?php

$tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL);

foreach($tzlist as $val){

$date = new DateTime(date(‘Y-m-d H:i:s’), new DateTimeZone($val));
$tz[] = $date->format(‘P’);
echo $val .” == “. $date->format(‘P’);

}

//print_r(array_unique($tz));

$date = new DateTime(date(‘Y/m/j H:i:s’), new DateTimeZone(‘Asia/Kolkata’));
echo $date->format(‘Y/m/j H:i:sP’) . “<br/>”;

$timezone  = “+05:30”;
echo gmdate(“Y/m/j H:i:s”, time() + 3600*($timezone+date(“I”)));

ZF2 : get HTML of View

protected function hasGridPdfRequest() {
$param = $this->params()->fromQuery(‘pdf’, “”);

if (trim($param) == “download”) {
$session = new \Zend\Session\Container(‘session’);

$viewRenderer = $this->getServiceLocator()->get(‘Zend\View\Renderer\RendererInterface’);
$layoutViewModel = $this->layout();
$layoutViewModel->setTemplate(‘layout/pdflayout’);
$route = ConstantFunction::getCurrentRoute();
$data = array();

if (isset($session->gridpdf[$route][‘sql’]) && trim($session->gridpdf[$route][‘sql’]) != “”) {
$connection = $this->getEntityManager()->getConnection();
$sql = isset($session->gridpdf[$route][‘sql’]) ? $session->gridpdf[$route][‘sql’] : “”;
$param = !empty($session->gridpdf[$route][‘param’]) ? $session->gridpdf[$route][‘param’] : array();
$data = $connection->executeQuery($sql, $param)->fetchAll();
}
$viewModel = new ViewModel(array(
‘data’ => $data
));

$viewModel->setTemplate($this->pdfPath);

//            $layoutViewModel->setVariables(array(
//                ‘content’ => $viewRenderer->render($viewModel),
//            ));
//
//            $htmlOutput = $viewRenderer->render($layoutViewModel);
$htmlOutput = $viewRenderer->render($viewModel);
return $this->downloadPdf($htmlOutput);
}

REGEX : ZIP CODES

$ZIPREG=array(
    "US"=>"^\d{5}([\-]?\d{4})?$",
    "UK"=>"^(GIR|[A-Z]\d[A-Z\d]??|[A-Z]{2}\d[A-Z\d]??)[ ]??(\d[A-Z]{2})$",
    "DE"=>"\b((?:0[1-46-9]\d{3})|(?:[1-357-9]\d{4})|(?:[4][0-24-9]\d{3})|(?:[6][013-9]\d{3}))\b",
    "CA"=>"^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$",
    "FR"=>"^(F-)?((2[A|B])|[0-9]{2})[0-9]{3}$",
    "IT"=>"^(V-|I-)?[0-9]{5}$",
    "AU"=>"^(0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2})$",
    "NL"=>"^[1-9][0-9]{3}\s?([a-zA-Z]{2})?$",
    "ES"=>"^([1-9]{2}|[0-9][1-9]|[1-9][0-9])[0-9]{3}$",
    "DK"=>"^([D|d][K|k]( |-))?[1-9]{1}[0-9]{3}$",
    "SE"=>"^(s-|S-){0,1}[0-9]{3}\s?[0-9]{2}$",
    "BE"=>"^[1-9]{1}[0-9]{3}$",
    "IN"=>"^\d{6}$"
);

Continue reading

Posted in PHP