Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Draft to Post
- Plugin URI: http://www.yakupgovler.com
- Description: Taslak yazılarınızı belirli aralıklarla yayımlar.
- Author: Yakup Gövler
- Version: 1.0
- Author URI: http://www.yakupgovler.com
- */
- function yg_d2p_options_page() {
- add_options_page('Draft to Publish Settings', 'Draft to Publish', 10, __FILE__, 'yg_d2p_options');
- }
- add_action('admin_menu', 'yg_d2p_options_page');
- function yg_is_d2p_activated () {
- $crons = _get_cron_array();
- if ( !empty($crons) ) {
- foreach ( $crons as $timestamp => $cron ) {
- if (isset($cron['yg_publish'])) {
- return true;
- }
- }
- }
- return false;
- }
- function yg_d2p_save_settings() {
- if ($_POST['submit']) {
- $activate = (bool) ($_POST['activate']);
- $pt = esc_attr($_POST['post_type']);
- $error = false;
- if (!($pt=='draft' || $pt=='pending')) $error = true;
- $delay = (int) $_POST['delay'];
- if (!($delay==999 || $delay >= 5 && $delay <= 300)) $error=true;
- $cats = str_replace(' ', '', esc_attr($_POST['cats']));
- $order = esc_attr($_POST['order']);
- if (!($order == 'ASC' || $order == 'DESC' || $order == 'RAND')) $error=true;
- if (!$error) {
- $options = array('activate'=>$activate, 'delay'=>$delay, 'post_type'=>$pt, 'cats'=>$cats, 'order'=>$order);
- if (!update_option('yg_d2p_options', $options)) add_option('yg_d2p_options', $options);
- if ($delay == 999) $delay = mt_rand(60, 180);
- wp_clear_scheduled_hook('yg_publish');
- if ($activate) wp_schedule_single_event(time() + $delay*60, 'yg_publish', array());
- ?>
- <div id="message" class="updated fade"><p><strong>Ayarlar kaydedildi. <?php if ($activate) echo "Eklenti Aktifleştirildi!"; else echo "Eklenti Pasifleştirildi!"; ?></strong></p></div>
- <?php
- }
- }
- }
- function yg_d2p_options() {
- if ($_POST['submit']) {
- check_admin_referer( 'd2p_options' );
- yg_d2p_save_settings();
- }
- $options = get_option('yg_d2p_options');
- $activate = (bool) $options['activate'];
- $delay = (int) $options['delay'];
- $post_type = esc_attr($options['post_type']);
- $cats = esc_attr($options['cats']);
- $order = esc_attr($options['order']);
- $delays = array(5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 180, 240, 300);
- ?>
- <div class="wrap">
- <div id="icon-edit-pages" class="icon32"><br /></div>
- <h2>Draft to Publish Settings</h2>
- <form method="post" action="">
- <?php wp_nonce_field('d2p_options'); ?>
- <table class="form-table">
- <tr valign="top">
- <th scope="row">
- Eklentinin Şu anki Durumu</th>
- <td><?php
- if (yg_is_d2p_activated ()) echo "<strong>Aktif</strong>"; else echo "<strong>Pasif</strong>";
- ?>
- </td>
- </tr>
- <tr valign="top">
- <th scope="row">
- <label for="post_type">Eklentiyi Aktifleştir</label></th>
- <td><input type="checkbox" name="activate" id="activate" value="1" <?php checked( $activate ); ?> />
- </td>
- </tr>
- <tr valign="top">
- <th scope="row">
- <label for="post_type">Yayımlanacak yazı türü</label></th>
- <td><select name="post_type" id="post_type">
- <option value="draft" <?php if ($post_type=='draft') echo " selected = 'selected'";?>><?php esc_attr_e('Draft') ?></option>
- <option value="pending" <?php if ($post_type=='pending') echo " selected = 'selected'";?>><?php esc_attr_e('Kontrol Bekleyen') ?></option>
- </select>
- </td>
- </tr>
- <tr valign="top">
- <th scope="row">
- <label for="delay">Yazıları şu gecikmeyle yayımla</label></th>
- <td>
- <select name="delay" id="delay">
- <?php
- foreach ($delays as $d) {
- $selected = '';
- if ($delay == $d) $selected = " selected='selected'";
- echo '<option value="' . $d . '" '. $selected . '>' . $d . '</option>'."\n";
- }
- ?>
- <option value="999" <?php if ($delay==999) echo " selected='selected'"?>><?php esc_attr_e('Random') ?> *</option>
- </select> dakika
- <br />
- <small>(* Rastgele seçiminde gecikme en az 60, en fazla 180 dakikadır.)</small>
- </td>
- </tr>
- <tr valign="top">
- <th scope="row">
- <label for="cats">Yazıların alınacağı kategoriler </label></th>
- <td><input type="text" name="cats" id="cats" value="<?php echo $cats;?>" /><br />
- <small>(Kategorilerin ID'lerini virgül ile ayırarak yazınız. Örn: 5,8,17)</small>
- </td>
- </tr>
- <tr valign="top">
- <th scope="row">
- <label for="order">Yazıları yayımlama sırası</label></th>
- <td>
- <select name="order" id="order">
- <option value="ASC"<?php if ($order=='ASC') echo " selected='selected'"?>>Eskiden Yeniye Doğru</option>
- <option value="DESC"<?php if ($order=='DESC') echo " selected='selected'"?>>Yeniden Eskiye Doğru</option>
- <option value="RAND"<?php if ($order=='RAND') echo " selected='selected'"?>>Rastgele</option>
- </select><br />
- <small>(Sıralamalar ID tabanlı olup, veritabanına kayıt sırası takip edilir. Yazı tarihi gözardı edilir.)</small>
- </td>
- </tr>
- </table>
- <input type="submit" name="submit" class="button-primary" id="delay" value="<?php esc_attr_e('Save Changes') ?>" />
- </form>
- <?php
- }
- function yg_draft_to_publish($postt='') {
- global $wpdb;
- $options = get_option('yg_d2p_options');
- $activate = (bool) $options['activate'];
- $delay = (int) $options['delay'];
- if ($delay == 999) $delay = mt_rand(60, 180);
- $post_type = esc_attr($options['post_type']);
- if ($post_type != 'pending') $post_type = 'draft';
- $cats = esc_attr($options['cats']);
- $order = esc_attr($options['order']);
- if ($order == 'RAND') {$orderby = 'rand'; $order='';}else{ $orderby = 'ID';}
- if ($order != '' && $order != 'DESC') $order = 'ASC';
- $args = array(
- 'category' => $cats,
- 'post_type' => 'post',
- 'post_status' => $post_type,
- 'numberposts' => 1,
- 'orderby' =>$orderby,
- 'order' => $order
- );
- $post = get_posts($args);
- if ($post) {
- //$post = $wpdb->get_results("select * FROM $wpdb->posts WHERE post_status='draft' AND post_type='post' ORDER BY ID ASC LIMIT 1");
- $post_id = $post[0]->ID;
- $postarr = array('ID' => $post_id, 'post_status' => 'publish', 'post_date' => current_time('mysql'), 'post_date_gmt' => current_time('mysql', 1));
- wp_update_post($postarr);
- wp_schedule_single_event(time() + $delay * 60, 'yg_publish', array());
- } /*else{
- add_action('admin_notices', 'yg_d2p_notice');
- }*/
- }
- /*
- function yg_d2p_notice() {
- echo '<div class="error"><p>';
- echo '<strong>Uyarı:</strong>: Yayımlanacak yazı bulunamadığından, Draft to Publish eklentisi<br />tarafından yazıların yayımlanması durduruldu.';
- echo '</p></div>';
- }
- */
- add_action('yg_publish', 'yg_draft_to_publish', 10, 1);
- register_activation_hook(__FILE__,'yg_draft2publish_install');
- register_deactivation_hook(__FILE__,'yg_draft2publish_uninstall');
- // Install plugin
- function yg_draft2publish_install() {
- $options = array('activate'=>0, 'delay'=>30, 'post_type'=>'draft', 'cats'=>'', 'order'=>'ASC');
- add_option('yg_d2p_options', $options);
- }
- // Uninstall plugin
- function yg_draft2publish_uninstall() {
- wp_clear_scheduled_hook('yg_publish');
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment