/**
* WP Discord Post Plus
*
* @author WP Tasker
* @license GPL-2.0+
*
* Plugin Name: WP Discord Post Plus
* Plugin URI: https://wp-tasker.com/
* Description: A Discord integration that sends a message on your desired Discord server and channel for every new post published.
* Based on the original plugin WP Discord Post by Nicola Mustone, which is available on the WordPress Directory.
*
* Version: 1.0.3
* Author: WP Tasker
* Author URI: https://wp-tasker.com
* Text Domain: wp-discord-post-plus
*
* WC tested up to: 3.5
*
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
//define version and plugin name
define('WP_DISCORD_POST_PLUS_VERSION', '1.0.3');
define('WP_DISCORD_POST_PLUS_PLUGINNAME', 'WP Discord Post Plus');
/**
* Main class of the plugin WP Discord Post. Handles the bot and the admin settings.
*/
class WP_Discord_Post_Plus {
/**
* The single instance of the class.
*
* @var WP_Discord_Post
*/
protected static $_instance = null;
/**
* The instance of WP_Discord_Post_Post.
*
* @var WP_Discord_Post_Post
*/
public $post = null;
/**
* Main WP_Discord_Post Instance.
*
* Ensures only one instance of WP_Discord_Post is loaded or can be loaded.
*
* @static
* @return WP_Discord_Post - Main instance.
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Cloning is forbidden.
*/
public function __clone() {
doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'wp-discord-post-plus' ), WP_DISCORD_POST_PLUS_VERSION );
}
/**
* Unserializing instances of this class is forbidden.
*/
public function __wakeup() {
doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'wp-discord-post-plus' ), WP_DISCORD_POST_PLUS_VERSION );
}
/**
* Adds the required hooks.
*/
public function __construct() {
require_once 'includes/functions-general.php';
require_once 'includes/class-wp-discord-post-admin.php';
require_once 'includes/class-wp-discord-post-http.php';
require_once 'includes/class-wp-discord-post-formatting.php';
require_once 'includes/class-wp-discord-metabox.php';
if (is_admin()) {
require_once 'includes/class-wp-discord-enqueue-assets.php';
}
$this->post = require_once 'includes/class-wp-discord-post-post.php';
// Zamanlanmış içerikler için de gönderi yapılacak şekilde ayar
add_action( 'publish_post', array( $this, 'send_to_discord_on_publish' ), 10, 2 );
add_action( 'transition_post_status', array( $this, 'send_on_scheduled_post_publish' ), 10, 3 ); // Zamanlanmış içerikler için tetikleme
if ( class_exists( 'WooCommerce' ) ) {
$this->woocommerce = include_once 'includes/class-wp-discord-post-woocommerce.php';
}
$this->load_textdomain();
do_action( 'wp_discord_post_plus_init' );
}
/**
* Loads the plugin localization files.
*/
public function load_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'wp-discord-post-plus' );
load_textdomain( 'wp-discord-post-plus', WP_LANG_DIR . '/wp-discord-post/discord-post-plus-' . $locale . '.mo' );
load_plugin_textdomain( 'wp-discord-post-plus', false, plugin_basename( __DIR__ ) . '/languages' );
}
/**
* Discord'a içerik gönderimi fonksiyonu
*/
public function send_to_discord_on_publish($post_ID, $post) {
// Yayınlanan içerik dışındaki içerikler için çalışmasın
if ($post->post_status != 'publish') return;
// Webhook URL'si
$webhookurl = "YOUR_DISCORD_WEBHOOK_URL"; // Discord Webhook URL'si
$title = $post->post_title;
$url = get_permalink($post_ID);
$message = "**Yeni Yazı Yayınlandı:** " . $title . "\n" . $url;
$json_data = json_encode([
"content" => $message,
"username" => "WordPress Bot"
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
$args = [
"body" => $json_data,
"headers" => [ "Content-Type" => "application/json" ],
"timeout" => 15,
"redirection" => 5,
"blocking" => true,
"method" => "POST"
];
wp_remote_post($webhookurl, $args);
}
/**
* Zamanlanmış içerik yayına alındığında da gönderi yapılacak şekilde fonksiyon ekleme
*/
public function send_on_scheduled_post_publish($new_status, $old_status, $post) {
// Sadece "yayına alınan" (publish) içerikler için gönderi yapılacak
if ( $old_status != 'publish' && $new_status == 'publish' ) {
$this->send_to_discord_on_publish($post->ID, $post);
}
}
}
// Plugin'i başlatma
WP_Discord_Post_Plus::instance();
Warning: Cannot modify header information - headers already sent by (output started at /home/dijithal/htdocs/www.dijithal.com/wp-content/plugins/wp-discord-post.php:1) in /home/dijithal/htdocs/www.dijithal.com/wp-includes/pluggable.php on line 1450
Warning: Cannot modify header information - headers already sent by (output started at /home/dijithal/htdocs/www.dijithal.com/wp-content/plugins/wp-discord-post.php:1) in /home/dijithal/htdocs/www.dijithal.com/wp-includes/pluggable.php on line 1453