function email_draft_submission_to_admins($post_id) { $options = get_option('wp-booj'); $post = get_post($post_id); if ($options['use_WpBoojDraftMailer'] == 'on' && $options['WpBoojDraftMailerEmails'] != '') { if (strpos($options['WpBoojDraftMailerEmails'], ',') !== false) { $emails = explode(',', $options['WpBoojDraftMailerEmails']); } else { $emails = $options['WpBoojDraftMailerEmails']; } $post = get_post($post_id); $post_title = get_the_title($post_id); $post_url = get_permalink($post_id); $preview_url = site_url() . '/?p=' . $post->ID . '&preview=true'; $admin_url = site_url() . '/wp-admin/post.php?post=' . $post->ID . '&action=edit'; $subject = 'Blog Draft Has Been Submitted - ' . WpBooj::truncate_by_word($post_title, 50); $message = "New post Pending review:\n\n"; $message .= $post_title . "\n"; $message .= 'By ' . get_the_author_meta('display_name', $post->post_author) . "\n"; $message .= 'Preview Url: ' . $preview_url . "\n"; $message .= 'Admin Url: ' . $admin_url . "\n"; // Send email to admin. wp_mail($emails, $subject, $message); } }
public static function truncate_by_word($string, $length) { $string = WpBooj::removeCode($string); $words = explode(' ', $string); $truncated = ''; $letter_count = 0; foreach ($words as $key => $word) { if ($letter_count < $length) { $truncated = $truncated . $word . ' '; $letter_count = $letter_count + strlen($word); } else { $truncated = substr($truncated, 0, -1); break; } } if (strlen($string) > strlen($truncated)) { $truncated = $truncated . '...'; } return $truncated; }