Pengirim: Piranhamas
<?php
/**
* Plugin Name: Auto Blogspot Poster Advanced PRO
* Description: Mengirim postingan WordPress ke Blogspot via email dengan pengaturan di dashboard.
* Version: 1.2
* Author: Agoes
*/
// Prevent direct access
defined('ABSPATH') or exit;
// Hook untuk inisialisasi plugin
add_action('init', 'blogspot_poster_init');
function blogspot_poster_init() {
// Pastikan fungsi wp_mail tersedia
if (!function_exists('wp_mail')) {
add_action('admin_notices', function() {
echo '<div class="error notice"><p>Auto Blogspot Poster: wp_mail function tidak tersedia!</p></div>';
});
return;
}
}
// Buat menu di Dashboard
add_action('admin_menu', 'blogspot_poster_add_menu');
function blogspot_poster_add_menu() {
add_menu_page(
'Auto Blogspot Poster',
'Blogspot Poster',
'manage_options',
'blogspot-poster',
'blogspot_poster_settings_page',
'dashicons-email-alt'
);
}
// Halaman pengaturan plugin
function blogspot_poster_settings_page() {
// Handle form submission
if (isset($_POST['save_blogspot_settings']) && wp_verify_nonce($_POST['blogspot_nonce'], 'save_blogspot_settings')) {
$emails = sanitize_textarea_field($_POST['blogspot_emails']);
$sender_email = sanitize_email($_POST['sender_email']);
$sender_name = sanitize_text_field($_POST['sender_name']);
$auto_send = isset($_POST['auto_send']) ? 1 : 0;
update_option('blogspot_emails_list', $emails);
update_option('blogspot_sender_email', $sender_email);
update_option('blogspot_sender_name', $sender_name);
update_option('blogspot_auto_send', $auto_send);
echo '<div class="updated notice is-dismissible"><p>Pengaturan berhasil disimpan!</p></div>';
}
// Handle test email
if (isset($_POST['send_test_email']) && wp_verify_nonce($_POST['blogspot_nonce'], 'save_blogspot_settings')) {
$test_result = blogspot_send_test_email();
if ($test_result) {
echo '<div class="updated notice is-dismissible"><p>Test email berhasil dikirim!</p></div>';
} else {
echo '<div class="error notice is-dismissible"><p>Test email gagal dikirim. Periksa pengaturan email server.</p></div>';
}
}
// Get saved options
$saved_emails = get_option('blogspot_emails_list', '');
$sender_email = get_option('blogspot_sender_email', get_option('admin_email'));
$sender_name = get_option('blogspot_sender_name', get_bloginfo('name'));
$auto_send = get_option('blogspot_auto_send', 1);
?>
<div class="wrap">
<h1>Auto Blogspot Poster Settings</h1>
<form method="post" action="">
<?php wp_nonce_field('save_blogspot_settings', 'blogspot_nonce'); ?>
<table class="form-table">
<tr>
<th scope="row">
<label for="blogspot_emails">Email Blogspot</label>
</th>
<td>
<textarea name="blogspot_emails" id="blogspot_emails" rows="8" cols="50" class="large-text"><?php echo esc_textarea($saved_emails); ?></textarea>
<p class="description">Masukkan email Blogspot untuk posting (satu email per baris). Format: namauser.namablog@blogger.com</p>
</td>
</tr>
<tr>
<th scope="row">
<label for="sender_email">Email Pengirim</label>
</th>
<td>
<input type="email" name="sender_email" id="sender_email" value="<?php echo esc_attr($sender_email); ?>" class="regular-text" required />
<p class="description">Email pengirim (harus email yang valid dan dikonfigurasi di server)</p>
</td>
</tr>
<tr>
<th scope="row">
<label for="sender_name">Nama Pengirim</label>
</th>
<td>
<input type="text" name="sender_name" id="sender_name" value="<?php echo esc_attr($sender_name); ?>" class="regular-text" />
<p class="description">Nama yang akan muncul sebagai pengirim email</p>
</td>
</tr>
<tr>
<th scope="row">
<label for="auto_send">Auto Send</label>
</th>
<td>
<input type="checkbox" name="auto_send" id="auto_send" value="1" <?php checked($auto_send, 1); ?> />
<label for="auto_send">Kirim otomatis saat post dipublikasi</label>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" name="save_blogspot_settings" class="button button-primary" value="Simpan Pengaturan" />
<input type="submit" name="send_test_email" class="button button-secondary" value="Kirim Test Email" style="margin-left: 10px;" />
</p>
</form>
<hr>
<h2>Cara Penggunaan</h2>
<ol>
<li>Dapatkan email posting Blogspot di dashboard Blogger â†' Settings â†' Email</li>
<li>Format email biasanya: <code>namauser.namablog@blogger.com</code></li>
<li>Masukkan email tersebut di field "Email Blogspot" (satu email per baris untuk multiple blog)</li>
<li>Pastikan email pengirim sudah dikonfigurasi dengan benar di server hosting</li>
<li>Test email terlebih dahulu sebelum mengaktifkan auto send</li>
</ol>
<h3>Troubleshooting</h3>
<ul>
<li><strong>Email tidak terkirim:</strong> Periksa konfigurasi SMTP server hosting</li>
<li><strong>Email masuk spam:</strong> Gunakan email pengirim yang sama domain dengan website</li>
<li><strong>Post tidak muncul di Blogspot:</strong> Periksa email Blogspot apakah benar dan aktif</li>
</ul>
</div>
<?php
}
// Function untuk test email
function blogspot_send_test_email() {
$emails_raw = get_option('blogspot_emails_list', '');
if (empty($emails_raw)) {
return false;
}
$emails = array_filter(array_map('trim', explode("\n", $emails_raw)));
$sender_email = get_option('blogspot_sender_email', get_option('admin_email'));
$sender_name = get_option('blogspot_sender_name', get_bloginfo('name'));
$title = 'Test Email dari ' . get_bloginfo('name');
$body = '
<h2>Test Email - Auto Blogspot Poster</h2>
<p>Ini adalah test email dari plugin Auto Blogspot Poster.</p>
<p>Website: ' . get_bloginfo('url') . '</p>
<p>Waktu: ' . current_time('mysql') . '</p>
<p>Jika Anda menerima email ini, berarti konfigurasi email sudah benar.</p>
<hr>
<p><em>Dikirim otomatis dari WordPress - Auto Blogspot Poster Plugin</em></p>
';
$headers = array(
'Content-Type: text/html; charset=UTF-8',
'From: ' . $sender_name . ' <' . $sender_email . '>',
'Reply-To: ' . $sender_email
);
$success = false;
foreach ($emails as $to) {
if (is_email($to)) {
$result = wp_mail($to, $title, $body, $headers);
if ($result) {
$success = true;
}
}
}
return $success;
}
// Multiple hooks untuk memastikan auto-send bekerja
add_action('publish_post', 'blogspot_auto_send_on_publish', 10, 2);
add_action('transition_post_status', 'blogspot_auto_send_transition', 10, 3);
function blogspot_auto_send_on_publish($post_ID, $post) {
// Debug log
if (WP_DEBUG) {
error_log('publish_post hook triggered for post ID: ' . $post_ID);
}
// Cek apakah auto send diaktifkan
if (!get_option('blogspot_auto_send', 1)) {
if (WP_DEBUG) {
error_log('Auto send disabled');
}
return;
}
// Cek post status dan type
if ($post->post_status !== 'publish' || $post->post_type !== 'post') {
if (WP_DEBUG) {
error_log('Post status: ' . $post->post_status . ', Post type: ' . $post->post_type);
}
return;
}
// Cek apakah sudah pernah dikirim (untuk menghindari duplicate)
$already_sent = get_post_meta($post_ID, '_blogspot_auto_sent', true);
if ($already_sent) {
if (WP_DEBUG) {
error_log('Post already sent to blogspot');
}
return;
}
// Mark as sent untuk menghindari duplicate
update_post_meta($post_ID, '_blogspot_auto_sent', '1');
if (WP_DEBUG) {
error_log('Sending post to blogspot: ' . $post_ID);
}
// Kirim langsung tanpa delay
auto_send_to_blogspot_advanced($post_ID);
}
function blogspot_auto_send_transition($new_status, $old_status, $post) {
// Debug log
if (WP_DEBUG) {
error_log('transition_post_status hook: ' . $old_status . ' -> ' . $new_status . ' for post ID: ' . $post->ID);
}
// Cek apakah auto send diaktifkan
if (!get_option('blogspot_auto_send', 1)) {
return;
}
// Hanya kirim untuk post yang baru dipublikasi (dari draft/pending ke publish)
if ($new_status !== 'publish' || $old_status === 'publish') {
return;
}
// Hanya untuk post type 'post'
if ($post->post_type !== 'post') {
return;
}
// Cek apakah sudah pernah dikirim
$already_sent = get_post_meta($post->ID, '_blogspot_auto_sent', true);
if ($already_sent) {
return;
}
// Mark as sent
update_post_meta($post->ID, '_blogspot_auto_sent', '1');
if (WP_DEBUG) {
error_log('Sending post via transition hook: ' . $post->ID);
}
// Kirim langsung
auto_send_to_blogspot_advanced($post->ID);
}
// Hook tambahan untuk published posts (sebagai backup)
add_action('wp_insert_post', 'blogspot_backup_send', 20, 3);
function blogspot_backup_send($post_ID, $post, $update) {
// Hanya untuk post baru yang langsung publish
if ($update || $post->post_status !== 'publish' || $post->post_type !== 'post') {
return;
}
// Cek auto send
if (!get_option('blogspot_auto_send', 1)) {
return;
}
// Cek apakah sudah dikirim
$already_sent = get_post_meta($post_ID, '_blogspot_auto_sent', true);
if ($already_sent) {
return;
}
// Delay sedikit untuk wp_insert_post
wp_schedule_single_event(time() 10, 'blogspot_send_delayed', array($post_ID));
}
// Hook untuk delayed sending
add_action('blogspot_send_delayed', 'auto_send_to_blogspot_advanced');
function auto_send_to_blogspot_advanced($post_ID) {
// Debug log
if (WP_DEBUG) {
error_log('auto_send_to_blogspot_advanced called for post ID: ' . $post_ID);
}
$emails_raw = get_option('blogspot_emails_list', '');
if (empty($emails_raw)) {
if (WP_DEBUG) {
error_log('No blogspot emails configured');
}
return;
}
$emails = array_filter(array_map('trim', explode("\n", $emails_raw)));
if (empty($emails)) {
if (WP_DEBUG) {
error_log('No valid emails found');
}
return;
}
$post = get_post($post_ID);
if (!$post) {
if (WP_DEBUG) {
error_log('Post not found: ' . $post_ID);
}
return;
}
// Pastikan post sudah publish
if ($post->post_status !== 'publish') {
if (WP_DEBUG) {
error_log('Post not published: ' . $post->post_status);
}
return;
}
$title = get_the_title($post_ID);
$content = apply_filters('the_content', $post->post_content);
$permalink = get_permalink($post_ID);
// Get post excerpt
$excerpt = '';
if (!empty($post->post_excerpt)) {
$excerpt = '<p><em>' . esc_html($post->post_excerpt) . '</em></p>';
}
// Get tags
$tags = get_the_tags($post_ID);
$tagList = '';
if ($tags && !is_wp_error($tags)) {
$tagNames = array_map(function($tag) {
return $tag->name;
}, $tags);
$tagList = implode(', ', $tagNames);
}
// Get categories
$categories = get_the_category($post_ID);
$categoryList = '';
if ($categories && !is_wp_error($categories)) {
$catNames = array_map(function($cat) {
return $cat->name;
}, $categories);
$categoryList = implode(', ', $catNames);
}
// Get featured image
$featured_image = '';
if (has_post_thumbnail($post_ID)) {
$image_url = get_the_post_thumbnail_url($post_ID, 'full');
$alt_text = get_post_meta(get_post_thumbnail_id($post_ID), '_wp_attachment_image_alt', true);
$featured_image = '<p><img src="' . esc_url($image_url) . '" alt="' . esc_attr($alt_text) . '" style="max-width:100%; height:auto; display:block; margin: 10px 0;" /></p>';
}
// Build email body
$body = $excerpt . $featured_image . $content;
// Add footer info
$footer = '<hr style="margin: 20px 0; border: none; border-top: 1px solid #ccc;">';
$footer .= '<div style="font-size: 12px; color: #666; margin-top: 15px;">';
$footer .= '<p><strong>Artikel Asli:</strong> <a href="' . esc_url($permalink) . '">' . esc_url($permalink) . '</a></p>';
if (!empty($categoryList)) {
$footer .= '<p><strong>Kategori:</strong> ' . esc_html($categoryList) . '</p>';
}
if (!empty($tagList)) {
$footer .= '<p><strong>Tags:</strong> ' . esc_html($tagList) . '</p>';
}
$footer .= '<p><em>Dikirim otomatis dari ' . get_bloginfo('name') . ' - ' . current_time('d M Y H:i') . '</em></p>';
$footer .= '</div>';
$body .= $footer;
// Email headers
$sender_email = get_option('blogspot_sender_email', get_option('admin_email'));
$sender_name = get_option('blogspot_sender_name', get_bloginfo('name'));
$headers = array(
'Content-Type: text/html; charset=UTF-8',
'From: ' . $sender_name . ' <' . $sender_email . '>',
'Reply-To: ' . $sender_email
);
$success_count = 0;
$total_emails = count($emails);
// Send email to each Blogspot email
foreach ($emails as $to) {
if (is_email($to)) {
$result = wp_mail($to, $title, $body, $headers);
if ($result) {
$success_count ;
}
// Log hasil pengiriman
if (WP_DEBUG) {
error_log('Blogspot email sent to ' . $to . ': ' . ($result ? 'SUCCESS' : 'FAILED'));
}
}
}
// Update post meta untuk tracking
if ($success_count > 0) {
update_post_meta($post_ID, '_blogspot_email_sent', current_time('mysql'));
update_post_meta($post_ID, '_blogspot_send_count', $success_count . '/' . $total_emails);
if (WP_DEBUG) {
error_log('Blogspot emails sent successfully: ' . $success_count . '/' . $total_emails);
}
} else {
if (WP_DEBUG) {
error_log('All blogspot emails failed to send');
}
}
return $success_count > 0;
}
// Add metabox untuk manual send
add_action('add_meta_boxes', 'blogspot_add_metabox');
function blogspot_add_metabox() {
add_meta_box(
'blogspot-poster-metabox',
'Blogspot Poster',
'blogspot_metabox_callback',
'post',
'side',
'default'
);
}
function blogspot_metabox_callback($post) {
$last_sent = get_post_meta($post->ID, '_blogspot_email_sent', true);
$send_count = get_post_meta($post->ID, '_blogspot_send_count', true);
$auto_sent = get_post_meta($post->ID, '_blogspot_auto_sent', true);
echo '<div style="margin-bottom: 10px;">';
if ($last_sent) {
echo '<p><strong>Terakhir dikirim:</strong><br>' . $last_sent;
if ($send_count) {
echo '<br><strong>Status:</strong> ' . $send_count . ' email terkirim';
}
echo '</p>';
}
if ($auto_sent) {
echo '<p><span style="color: green;">âœ" Auto-send sudah dijalankan</span></p>';
} else {
echo '<p><span style="color: orange;">âš Auto-send belum dijalankan</span></p>';
}
// Reset button untuk testing
if ($auto_sent) {
echo '<p><button type="button" onclick="if(confirm('Reset status auto-send untuk testing?')) { document.getElementById('reset_auto_send').value='1'; }" class="button button-small">Reset Auto-Send Status</button></p>';
echo '<input type="hidden" id="reset_auto_send" name="reset_auto_send" value="0" />';
}
echo '</div>';
wp_nonce_field('blogspot_manual_send', 'blogspot_manual_nonce');
echo '<input type="submit" name="blogspot_manual_send" class="button button-secondary" value="Kirim ke Blogspot" style="width: 100%;" />';
echo '<p class="description" style="margin-top: 10px;">Kirim manual post ini ke Blogspot email yang sudah dikonfigurasi.</p>';
// Debug info jika WP_DEBUG aktif
if (WP_DEBUG && current_user_can('administrator')) {
echo '<hr><small><strong>Debug Info:</strong><br>';
echo 'Post Status: ' . $post->post_status . '<br>';
echo 'Post Type: ' . $post->post_type . '<br>';
echo 'Auto Send Setting: ' . (get_option('blogspot_auto_send', 1) ? 'Enabled' : 'Disabled') . '<br>';
$emails = get_option('blogspot_emails_list', '');
echo 'Emails Configured: ' . (empty($emails) ? 'No' : 'Yes') . '<br>';
echo '</small>';
}
}
// Handle manual send
add_action('save_post', 'blogspot_handle_manual_send');
function blogspot_handle_manual_send($post_id) {
// Handle reset auto-send status
if (isset($_POST['reset_auto_send']) && $_POST['reset_auto_send'] == '1') {
delete_post_meta($post_id, '_blogspot_auto_sent');
delete_post_meta($post_id, '_blogspot_email_sent');
delete_post_meta($post_id, '_blogspot_send_count');
add_action('admin_notices', function() {
echo '<div class="updated notice is-dismissible"><p>Status auto-send telah direset!</p></div>';
});
return;
}
// Handle manual send
if (!isset($_POST['blogspot_manual_send']) || !wp_verify_nonce($_POST['blogspot_manual_nonce'], 'blogspot_manual_send')) {
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!current_user_can('edit_post', $post_id)) {
return;
}
// Send immediately
$result = auto_send_to_blogspot_advanced($post_id);
// Add admin notice
if ($result) {
add_action('admin_notices', function() {
echo '<div class="updated notice is-dismissible"><p>Post telah berhasil dikirim ke Blogspot!</p></div>';
});
} else {
add_action('admin_notices', function() {
echo '<div class="error notice is-dismissible"><p>Gagal mengirim post ke Blogspot. Periksa konfigurasi email.</p></div>';
});
}
}
Contact:
No Tlp: 0881036414823
Email: digembok.2024@gmail.com
Website: https://stempelmurahpekanbaru.blogspot.com/
Pasang Iklan Baris
Pasang iklan Anda Disini, Otomatis Secara Serentak Tampil Di Banyak Situs Iklan Kami Lainnya:
Pasang Iklan
Bintang Jasa Amanah
