Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 82.27 KB | None | 0 0
  1.  
  2. application/x-httpd-php post-expirator.php ( PHP script text )
  3. <?php
  4. /*
  5. Plugin Name: Post Expirator
  6. Plugin URI: http://wordpress.org/extend/plugins/post-expirator/
  7. Description: Allows you to add an expiration date (minute) to posts which you can configure to either delete the post, change it to a draft, or update the post categories at expiration time.
  8. Author: Aaron Axelsen
  9. Version: 2.3.1.1
  10. Author URI: http://postexpirator.tuxdocs.net/
  11. Text Domain: post-expirator
  12. */
  13.  
  14. /* Load translation, if it exists */
  15. function postExpirator_init() {
  16. $plugin_dir = basename(dirname(__FILE__));
  17. load_plugin_textdomain( 'post-expirator', null, $plugin_dir.'/languages/' );
  18. }
  19. add_action('plugins_loaded', 'postExpirator_init');
  20.  
  21. // Default Values
  22. define('POSTEXPIRATOR_VERSION','2.3.1.1');
  23. define('POSTEXPIRATOR_DATEFORMAT',__('l F jS, Y','post-expirator'));
  24. define('POSTEXPIRATOR_TIMEFORMAT',__('g:ia','post-expirator'));
  25. define('POSTEXPIRATOR_FOOTERCONTENTS',__('Post expires at EXPIRATIONTIME on EXPIRATIONDATE','post-expirator'));
  26. define('POSTEXPIRATOR_FOOTERSTYLE','font-style: italic;');
  27. define('POSTEXPIRATOR_FOOTERDISPLAY','0');
  28. define('POSTEXPIRATOR_EMAILNOTIFICATION','0');
  29. define('POSTEXPIRATOR_EMAILNOTIFICATIONADMINS','0');
  30. define('POSTEXPIRATOR_DEBUGDEFAULT','0');
  31. define('POSTEXPIRATOR_EXPIREDEFAULT','null');
  32.  
  33. function postExpirator_plugin_action_links($links, $file) {
  34. $this_plugin = basename(plugin_dir_url(__FILE__)) . '/post-expirator.php';
  35. if($file == $this_plugin) {
  36. $links[] = '<a href="options-general.php?page=post-expirator">' . __('Settings', 'post-expirator') . '</a>';
  37. }
  38. return $links;
  39. }
  40. add_filter('plugin_action_links', 'postExpirator_plugin_action_links', 10, 2);
  41.  
  42. /**
  43. * Add admin notice hook if cron schedule needs to be reset
  44. */
  45. add_action('admin_notices','postExpirationAdminNotice');
  46. function postExpirationAdminNotice() {
  47. // Check if WP-Cron is Enabled
  48. #if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON === true) {
  49. # $class = 'notice notice-error';
  50. # $message = __( 'POST EXPIRATOR ERROR: WP-Cron is disabled on this server. This plugin requires WP-Cron and will not function until it is corrected.','post-expirator');
  51. # $message .= '<br/><br/>' . __( ' If you have manually configured cron click here to dismiss this message.', 'post-expirator' );
  52. # printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), $message );
  53. #}
  54. }
  55.  
  56. /**
  57. * adds an 'Expires' column to the post display table.
  58. */
  59. add_filter ('manage_posts_columns', 'expirationdate_add_column', 10, 2);
  60. function expirationdate_add_column ($columns,$type) {
  61. $defaults = get_option('expirationdateDefaults'.ucfirst($type));
  62. if (!isset($defaults['activeMetaBox']) || $defaults['activeMetaBox'] == 'active') {
  63. $columns['expirationdate'] = __('Expires','post-expirator');
  64. }
  65. return $columns;
  66. }
  67.  
  68. add_action( 'init', 'init_managesortablecolumns', 100 );
  69. function init_managesortablecolumns (){
  70. $post_types = get_post_types(array('public'=>true));
  71. foreach( $post_types as $post_type ){
  72. add_filter( 'manage_edit-' . $post_type . '_sortable_columns', 'expirationdate_sortable_column' );
  73. }
  74. }
  75. function expirationdate_sortable_column($columns) {
  76. $columns['expirationdate'] = 'expirationdate';
  77. return $columns;
  78. }
  79.  
  80. add_action( 'pre_get_posts', 'my_expirationdate_orderby' );
  81. function my_expirationdate_orderby( $query ) {
  82. if( ! is_admin() )
  83. return;
  84.  
  85. $orderby = $query->get( 'orderby');
  86.  
  87. if( 'expirationdate' == $orderby ) {
  88. $query->set('meta_query',array(
  89. 'relation' => 'OR',
  90. array(
  91. 'key' => '_expiration-date',
  92. 'compare' => 'EXISTS'
  93. ),
  94. array(
  95. 'key' => '_expiration-date',
  96. 'compare' => 'NOT EXISTS',
  97. 'value' => ''
  98. )
  99. ));
  100. $query->set('orderby','meta_value_num');
  101. }
  102. }
  103.  
  104. /**
  105. * adds an 'Expires' column to the page display table.
  106. */
  107. add_filter ('manage_pages_columns', 'expirationdate_add_column_page');
  108. function expirationdate_add_column_page ($columns) {
  109. $defaults = get_option('expirationdateDefaultsPage');
  110. if (!isset($defaults['activeMetaBox']) || $defaults['activeMetaBox'] == 'active') {
  111. $columns['expirationdate'] = __('Expires','post-expirator');
  112. }
  113. return $columns;
  114. }
  115.  
  116. /**
  117. * fills the 'Expires' column of the post display table.
  118. */
  119. add_action ('manage_posts_custom_column', 'expirationdate_show_value');
  120. add_action ('manage_pages_custom_column', 'expirationdate_show_value');
  121. function expirationdate_show_value ($column_name) {
  122. global $post;
  123. $id = $post->ID;
  124. if ($column_name === 'expirationdate') {
  125. $ed = get_post_meta($id,'_expiration-date',true);
  126. echo ($ed ? get_date_from_gmt(gmdate('Y-m-d H:i:s',$ed),get_option('date_format').' '.get_option('time_format')) : __("Never",'post-expirator'));
  127.  
  128. //Values for Quick Edit
  129. if ($ed) {
  130. $year = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ed),'Y');
  131. $month = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ed),'m');
  132. $day = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ed),'d');
  133. $hour = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ed),'H');
  134. $minute = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ed),'i');
  135. echo '<span id="expirationdate_year-'.$id.'" style="display: none;">'.$year.'</span>';
  136. echo '<span id="expirationdate_month-'.$id.'" style="display: none;">'.$month.'</span>';
  137. echo '<span id="expirationdate_day-'.$id.'" style="display: none;">'.$day.'</span>';
  138. echo '<span id="expirationdate_hour-'.$id.'" style="display: none;">'.$hour.'</span>';
  139. echo '<span id="expirationdate_minute-'.$id.'" style="display: none;">'.$minute.'</span>';
  140. echo '<span id="expirationdate_enabled-'.$id.'" style="display: none;">true</span>';
  141. } else {
  142. echo '<span id="expirationdate_year-'.$id.'" style="display: none;">'.date('Y').'</span>';
  143. echo '<span id="expirationdate_month-'.$id.'" style="display: none;">'.date('m').'</span>';
  144. echo '<span id="expirationdate_day-'.$id.'" style="display: none;">'.date('d').'</span>';
  145. echo '<span id="expirationdate_hour-'.$id.'" style="display: none;">'.date('H').'</span>';
  146. echo '<span id="expirationdate_minute-'.$id.'" style="display: none;">'.date('i').'</span>';
  147. echo '<span id="expirationdate_enabled-'.$id.'" style="display: none;">false</span>';
  148. }
  149. }
  150. }
  151.  
  152.  
  153. add_action( 'quick_edit_custom_box', 'display_expirationdate_quickedit', 10, 2 );
  154. function display_expirationdate_quickedit( $column_name, $post_type ) {
  155. if ($column_name != 'expirationdate') return;
  156. ?>
  157. <div style="clear:both"></div>
  158. <fieldset class="inline-edit-col-left post-expirator-quickedit">
  159. <div class="inline-edit-col">
  160. <div class="inline-edit-group">
  161. <span class="title">Post Expirator</span>
  162. <p><input name="enable-expirationdate" type="checkbox" /><span class="title">Enable Post Expiration</span></p>
  163. <fieldset class="inline-edit-date">
  164. <legend><span class="title">Expires</span></legend>
  165. <div class="timestamp-wrap">
  166. <label><span class="screen-reader-text">Month</span>
  167. <select name="expirationdate_month">
  168. <option value="01" data-text="Jan">01-Jan</option>
  169. <option value="02" data-text="Feb">02-Feb</option>
  170. <option value="03" data-text="Mar">03-Mar</option>
  171. <option value="04" data-text="Apr">04-Apr</option>
  172. <option value="05" data-text="May">05-May</option>
  173. <option value="06" data-text="Jun">06-Jun</option>
  174. <option value="07" data-text="Jul">07-Jul</option>
  175. <option value="08" data-text="Aug">08-Aug</option>
  176. <option value="09" data-text="Sep">09-Sep</option>
  177. <option value="10" data-text="Oct">10-Oct</option>
  178. <option value="11" data-text="Nov">11-Nov</option>
  179. <option value="12" data-text="Dec">12-Dec</option>
  180. </select>
  181. </label>
  182. <label><span class="screen-reader-text">Day</span>
  183. <input name="expirationdate_day" value="" size="2" maxlength="2" autocomplete="off" type="text"></label>,
  184. <label><span class="screen-reader-text">Year</span>
  185. <input name="expirationdate_year" value="" size="4" maxlength="4" autocomplete="off" type="text"></label> @
  186. <label><span class="screen-reader-text">Hour</span>
  187. <input name="expirationdate_hour" value="" size="2" maxlength="2" autocomplete="off" type="text"></label>:
  188. <label><span class="screen-reader-text">Minute</span>
  189. <input name="expirationdate_minute" value="" size="2" maxlength="2" autocomplete="off" type="text"></label></div>
  190. <input name="expirationdate_quickedit" value="true" type="hidden"/>
  191. </fieldset>
  192. </div>
  193. </div>
  194. </fieldset>
  195. <?php
  196.  
  197. }
  198.  
  199. add_action( 'bulk_edit_custom_box', 'display_expirationdate_bulkedit', 10, 2 );
  200. function display_expirationdate_bulkedit( $column_name, $post_type ) {
  201. if ($column_name != 'expirationdate') return;
  202. ?>
  203. <div style="clear:both"></div>
  204. <div class="inline-edit-col post-expirator-quickedit">
  205. <div class="inline-edit-col">
  206. <div class="inline-edit-group">
  207. <span class="title"><?php echo __('Post Expirator: Will only update expiration date if already configured on post.','post-expirator'); ?></span>
  208. <fieldset class="inline-edit-date">
  209. <legend><span class="title">Expires</span></legend>
  210. <div class="timestamp-wrap">
  211. <label><span class="screen-reader-text">Month</span>
  212. <select name="expirationdate_month">
  213. <option value="false">- No Change -</option>
  214. <option value="01" data-text="Jan">01-Jan</option>
  215. <option value="02" data-text="Feb">02-Feb</option>
  216. <option value="03" data-text="Mar">03-Mar</option>
  217. <option value="04" data-text="Apr">04-Apr</option>
  218. <option value="05" data-text="May">05-May</option>
  219. <option value="06" data-text="Jun">06-Jun</option>
  220. <option value="07" data-text="Jul">07-Jul</option>
  221. <option value="08" data-text="Aug">08-Aug</option>
  222. <option value="09" data-text="Sep">09-Sep</option>
  223. <option value="10" data-text="Oct">10-Oct</option>
  224. <option value="11" data-text="Nov">11-Nov</option>
  225. <option value="12" data-text="Dec">12-Dec</option>
  226. </select>
  227. </label>
  228. <label><span class="screen-reader-text">Day</span>
  229. <input name="expirationdate_day" placeholder="Day" value="" size="2" maxlength="2" autocomplete="off" type="text"></label>,
  230. <label><span class="screen-reader-text">Year</span>
  231. <input name="expirationdate_year" placeholder="Year" value="" size="4" maxlength="4" autocomplete="off" type="text"></label> @
  232. <label><span class="screen-reader-text">Hour</span>
  233. <input name="expirationdate_hour" placeholder="Hour" value="" size="2" maxlength="2" autocomplete="off" type="text"></label>:
  234. <label><span class="screen-reader-text">Minute</span>
  235. <input name="expirationdate_minute" placeholder="Min" value="" size="2" maxlength="2" autocomplete="off" type="text"></label></div>
  236. <input name="expirationdate_quickedit" value="true" type="hidden"/>
  237. </fieldset>
  238. </div>
  239. </div>
  240. </div>
  241. <?php
  242.  
  243. }
  244.  
  245. /**
  246. * Adds hooks to get the meta box added to pages and custom post types
  247. */
  248. function expirationdate_meta_custom() {
  249. $custom_post_types = get_post_types();
  250. array_push($custom_post_types,'page');
  251. foreach ($custom_post_types as $t) {
  252. $defaults = get_option('expirationdateDefaults'.ucfirst($t));
  253. if (!isset($defaults['activeMetaBox']) || $defaults['activeMetaBox'] == 'active') {
  254. add_meta_box('expirationdatediv', __('Post Expiration','post-expirator'), 'expirationdate_meta_box', $t, 'side', 'core');
  255. }
  256. }
  257. }
  258. add_action ('add_meta_boxes','expirationdate_meta_custom');
  259.  
  260. /**
  261. * Actually adds the meta box
  262. */
  263. function expirationdate_meta_box($post) {
  264. // Get default month
  265. $expirationdatets = get_post_meta($post->ID,'_expiration-date',true);
  266. $firstsave = get_post_meta($post->ID,'_expiration-date-status',true);
  267. $default = '';
  268. $expireType = '';
  269. $defaults = get_option('expirationdateDefaults'.ucfirst($post->post_type));
  270. if (empty($expirationdatets)) {
  271. $default = get_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
  272. if ($default == 'null') {
  273. $defaultmonth = date_i18n('m');
  274. $defaultday = date_i18n('d');
  275. $defaulthour = date_i18n('H');
  276. $defaultyear = date_i18n('Y');
  277. $defaultminute = date_i18n('i');
  278.  
  279. } elseif ($default == 'custom') {
  280. $custom = get_option('expirationdateDefaultDateCustom');
  281. if ($custom === false) $ts = time();
  282. else {
  283. $tz = get_option('timezone_string');
  284. if ( $tz ) date_default_timezone_set( $tz );
  285. $ts = time() + (strtotime($custom) - time());
  286. if ( $tz ) date_default_timezone_set('UTC');
  287. }
  288. $defaultmonth = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'m');
  289. $defaultday = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'d');
  290. $defaultyear = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'Y');;
  291. $defaulthour = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'H');
  292. $defaultminute = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'i');
  293. }
  294.  
  295. $enabled = '';
  296. $disabled = ' disabled="disabled"';
  297. $categories = get_option('expirationdateCategoryDefaults');
  298.  
  299. if (isset($defaults['expireType'])) {
  300. $expireType = $defaults['expireType'];
  301. }
  302.  
  303. if (isset($defaults['autoEnable']) && ($firstsave !== 'saved') && ($defaults['autoEnable'] === true || $defaults['autoEnable'] == 1)) {
  304. $enabled = ' checked="checked"';
  305. $disabled='';
  306. }
  307. } else {
  308. $defaultmonth = get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'m');
  309. $defaultday = get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'d');
  310. $defaultyear = get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'Y');
  311. $defaulthour = get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'H');
  312. $defaultminute = get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'i');
  313. $enabled = ' checked="checked"';
  314. $disabled = '';
  315. $opts = get_post_meta($post->ID,'_expiration-date-options',true);
  316. if (isset($opts['expireType'])) {
  317. $expireType = $opts['expireType'];
  318. }
  319. $categories = isset($opts['category']) ? $opts['category'] : false;
  320. }
  321.  
  322. $rv = array();
  323.  
  324. $rv[] = '<p><input type="checkbox" name="enable-expirationdate" id="enable-expirationdate" value="checked"'.$enabled.' onclick="expirationdate_ajax_add_meta(\'enable-expirationdate\')" />';
  325. $rv[] = '<label for="enable-expirationdate">'.__('Enable Post Expiration','post-expirator').'</label></p>';
  326.  
  327. if ($default == 'publish') {
  328. $rv[] = '<em>'.__('The published date/time will be used as the expiration value','post-expirator').'</em><br/>';
  329. } else {
  330. $rv[] = '<table><tr>';
  331. $rv[] = '<th style="text-align: left;">'.__('Year','post-expirator').'</th>';
  332. $rv[] = '<th style="text-align: left;">'.__('Month','post-expirator').'</th>';
  333. $rv[] = '<th style="text-align: left;">'.__('Day','post-expirator').'</th>';
  334. $rv[] = '</tr><tr>';
  335. $rv[] = '<td>';
  336. $rv[] = '<select name="expirationdate_year" id="expirationdate_year"'.$disabled.'>';
  337. $currentyear = date('Y');
  338.  
  339. if ($defaultyear < $currentyear) $currentyear = $defaultyear;
  340.  
  341. for($i = $currentyear; $i < $currentyear + 9; $i++) {
  342. if ($i == $defaultyear)
  343. $selected = ' selected="selected"';
  344. else
  345. $selected = '';
  346. $rv[] = '<option'.$selected.'>'.($i).'</option>';
  347. }
  348. $rv[] = '</select>';
  349. $rv[] = '</td><td>';
  350. $rv[] = '<select name="expirationdate_month" id="expirationdate_month"'.$disabled.'>';
  351.  
  352. for($i = 1; $i <= 12; $i++) {
  353. if ($defaultmonth == date_i18n('m',mktime(0, 0, 0, $i, 1, date_i18n('Y'))))
  354. $selected = ' selected="selected"';
  355. else
  356. $selected = '';
  357. $rv[] = '<option value="'.date_i18n('m',mktime(0, 0, 0, $i, 1, date_i18n('Y'))).'"'.$selected.'>'.date_i18n('F',mktime(0, 0, 0, $i, 1, date_i18n('Y'))).'</option>';
  358. }
  359.  
  360. $rv[] = '</select>';
  361. $rv[] = '</td><td>';
  362. $rv[] = '<input type="text" id="expirationdate_day" name="expirationdate_day" value="'.$defaultday.'" size="2"'.$disabled.' />,';
  363. $rv[] = '</td></tr><tr>';
  364. $rv[] = '<th style="text-align: left;"></th>';
  365. $rv[] = '<th style="text-align: left;">'.__('Hour','post-expirator').'('.date_i18n('T',mktime(0, 0, 0, $i, 1, date_i18n('Y'))).')</th>';
  366. $rv[] = '<th style="text-align: left;">'.__('Minute','post-expirator').'</th>';
  367. $rv[] = '</tr><tr>';
  368. $rv[] = '<td>@</td><td>';
  369. $rv[] = '<select name="expirationdate_hour" id="expirationdate_hour"'.$disabled.'>';
  370.  
  371. for($i = 1; $i <= 24; $i++) {
  372. if ($defaulthour == date_i18n('H',mktime($i, 0, 0, date_i18n('n'), date_i18n('j'), date_i18n('Y'))))
  373. $selected = ' selected="selected"';
  374. else
  375. $selected = '';
  376. $rv[] = '<option value="'.date_i18n('H',mktime($i, 0, 0, date_i18n('n'), date_i18n('j'), date_i18n('Y'))).'"'.$selected.'>'.date_i18n('H',mktime($i, 0, 0, date_i18n('n'), date_i18n('j'), date_i18n('Y'))).'</option>';
  377. }
  378.  
  379. $rv[] = '</select></td><td>';
  380. $rv[] = '<input type="text" id="expirationdate_minute" name="expirationdate_minute" value="'.$defaultminute.'" size="2"'.$disabled.' />';
  381. $rv[] = '</td></tr></table>';
  382. }
  383. $rv[] = '<input type="hidden" name="expirationdate_formcheck" value="true" />';
  384. echo implode("\n",$rv);
  385.  
  386. echo '<br/>'.__('How to expire','post-expirator').': ';
  387. echo _postExpiratorExpireType(array('type' => $post->post_type, 'name'=>'expirationdate_expiretype','selected'=>$expireType,'disabled'=>$disabled,'onchange' => 'expirationdate_toggle_category(this)'));
  388. echo '<br/>';
  389.  
  390. if ($post->post_type != 'page') {
  391. if (isset($expireType) && ($expireType == 'category' || $expireType == 'category-add' || $expireType == 'category-remove')) {
  392. $catdisplay = 'block';
  393. } else {
  394. $catdisplay = 'none';
  395. }
  396. echo '<div id="expired-category-selection" style="display: '.$catdisplay.'">';
  397. echo '<br/>'.__('Expiration Categories','post-expirator').':<br/>';
  398.  
  399. echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
  400. echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
  401. $walker = new Walker_PostExpirator_Category_Checklist();
  402. if (!empty($disabled)) $walker->setDisabled();
  403. $taxonomies = get_object_taxonomies($post->post_type,'object');
  404. $taxonomies = wp_filter_object_list($taxonomies, array('hierarchical' => true));
  405. if (sizeof($taxonomies) == 0) {
  406. echo '<p>'.__('You must assign a heirarchical taxonomy to this post type to use this feature.','post-expirator').'</p>';
  407. } elseif (sizeof($taxonomies) > 1 && !isset($defaults['taxonomy'])) {
  408. echo '<p>'.__('More than 1 heirachical taxonomy detected. You must assign a default taxonomy on the settings screen.','post-expirator').'</p>';
  409. } else {
  410. $keys = array_keys($taxonomies);
  411. $taxonomy = isset($defaults['taxonomy']) ? $defaults['taxonomy'] : $keys[0];
  412. wp_terms_checklist(0, array( 'taxonomy' => $taxonomy, 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );
  413. echo '<input type="hidden" name="taxonomy-heirarchical" value="'.$taxonomy.'" />';
  414. }
  415. echo '</ul>';
  416. echo '</div>';
  417. if (isset($taxonomy))
  418. echo '<p class="post-expirator-taxonomy-name">'.__('Taxonomy Name','post-expirator').': '.$taxonomy.'</p>';
  419. echo '</div>';
  420. }
  421. echo '<div id="expirationdate_ajax_result"></div></div>';
  422. }
  423.  
  424. /**
  425. * Add's ajax javascript
  426. */
  427. function expirationdate_js_admin_header() {
  428. // Define custom JavaScript function
  429. ?>
  430. <script type="text/javascript">
  431. //<![CDATA[
  432. function expirationdate_ajax_add_meta(expireenable) {
  433. var expire = document.getElementById(expireenable);
  434.  
  435. if (expire.checked == true) {
  436. var enable = 'true';
  437. if (document.getElementById('expirationdate_month')) {
  438. document.getElementById('expirationdate_month').disabled = false;
  439. document.getElementById('expirationdate_day').disabled = false;
  440. document.getElementById('expirationdate_year').disabled = false;
  441. document.getElementById('expirationdate_hour').disabled = false;
  442. document.getElementById('expirationdate_minute').disabled = false;
  443. }
  444. document.getElementById('expirationdate_expiretype').disabled = false;
  445. var cats = document.getElementsByName('expirationdate_category[]');
  446. var max = cats.length;
  447. for (var i=0; i<max; i++) {
  448. cats[i].disabled = '';
  449. }
  450. } else {
  451. if (document.getElementById('expirationdate_month')) {
  452. document.getElementById('expirationdate_month').disabled = true;
  453. document.getElementById('expirationdate_day').disabled = true;
  454. document.getElementById('expirationdate_year').disabled = true;
  455. document.getElementById('expirationdate_hour').disabled = true;
  456. document.getElementById('expirationdate_minute').disabled = true;
  457. }
  458. document.getElementById('expirationdate_expiretype').disabled = true;
  459. var cats = document.getElementsByName('expirationdate_category[]');
  460. var max = cats.length;
  461. for (var i=0; i<max; i++) {
  462. cats[i].disabled = 'disable';
  463. }
  464. var enable = 'false';
  465. }
  466. return true;
  467. }
  468. function expirationdate_toggle_category(id) {
  469. if (id.options[id.selectedIndex].value == 'category') {
  470. jQuery('#expired-category-selection').show();
  471. } else if (id.options[id.selectedIndex].value == 'category-add') {
  472. jQuery('#expired-category-selection').show(); //TEMP
  473. } else if (id.options[id.selectedIndex].value == 'category-remove') {
  474. jQuery('#expired-category-selection').show(); //TEMP
  475. } else {
  476. jQuery('#expired-category-selection').hide();
  477. }
  478. }
  479. function expirationdate_toggle_defaultdate(id) {
  480. if (id.options[id.selectedIndex].value == 'custom') {
  481. jQuery('#expired-custom-container').show();
  482. } else {
  483. jQuery('#expired-custom-container').hide();
  484. }
  485.  
  486. }
  487. //]]>
  488. </script>
  489. <?php
  490. }
  491. add_action('admin_head', 'expirationdate_js_admin_header' );
  492.  
  493. /**
  494. * Get correct URL (HTTP or HTTPS)
  495. */
  496. function expirationdate_get_blog_url() {
  497. if (is_multisite())
  498. echo network_home_url('/');
  499. else
  500. echo home_url('/');
  501. }
  502.  
  503. /**
  504. * Called when post is saved - stores expiration-date meta value
  505. */
  506. add_action('save_post','expirationdate_update_post_meta');
  507. function expirationdate_update_post_meta($id) {
  508. // don't run the echo if this is an auto save
  509. if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
  510. return;
  511.  
  512. // don't run the echo if the function is called for saving revision.
  513. $posttype = get_post_type($id);
  514. if ( $posttype == 'revision' )
  515. return;
  516.  
  517. if (!isset($_POST['expirationdate_quickedit'])) {
  518. if (!isset($_POST['expirationdate_formcheck']))
  519. return;
  520. }
  521.  
  522. if (isset($_POST['enable-expirationdate'])) {
  523. $default = get_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
  524. if ($default == 'publish') {
  525. $month = intval($_POST['mm']);
  526. $day = intval($_POST['jj']);
  527. $year = intval($_POST['aa']);
  528. $hour = intval($_POST['hh']);
  529. $minute = intval($_POST['mn']);
  530. } else {
  531. $month = intval($_POST['expirationdate_month']);
  532. $day = intval($_POST['expirationdate_day']);
  533. $year = intval($_POST['expirationdate_year']);
  534. $hour = intval($_POST['expirationdate_hour']);
  535. $minute = intval($_POST['expirationdate_minute']);
  536. }
  537. $category = isset($_POST['expirationdate_category']) ? $_POST['expirationdate_category'] : 0;
  538.  
  539. $ts = get_gmt_from_date("$year-$month-$day $hour:$minute:0",'U');
  540.  
  541. if (isset($_POST['expirationdate_quickedit'])) {
  542. $ed = get_post_meta($id,'_expiration-date',true);
  543. if ($ed) {
  544. $opts = get_post_meta($id, '_expiration-date-options', true);
  545. }
  546. } else {
  547. $opts = array();
  548.  
  549. // Schedule/Update Expiration
  550. $opts['expireType'] = $_POST['expirationdate_expiretype'];
  551. $opts['id'] = $id;
  552.  
  553. if ($opts['expireType'] == 'category' || $opts['expireType'] == 'category-add' || $opts['expireType'] == 'category-remove') {
  554. if (isset($category) && !empty($category)) {
  555. if (!empty($category)) {
  556. $opts['category'] = $category;
  557. $opts['categoryTaxonomy'] = $_POST['taxonomy-heirarchical'];
  558. }
  559. }
  560. }
  561. }
  562. _scheduleExpiratorEvent($id,$ts,$opts);
  563. } else {
  564. _unscheduleExpiratorEvent($id);
  565. }
  566. }
  567.  
  568. function _scheduleExpiratorEvent($id,$ts,$opts) {
  569. $debug = postExpiratorDebug(); //check for/load debug
  570.  
  571. do_action('postexpiratior_schedule',$id,$ts,$opts); // allow custom actions
  572.  
  573. if (wp_next_scheduled('postExpiratorExpire',array($id)) !== false) {
  574. wp_clear_scheduled_hook('postExpiratorExpire',array($id)); //Remove any existing hooks
  575. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> EXISTING FOUND - UNSCHEDULED'));
  576. }
  577.  
  578. wp_schedule_single_event($ts,'postExpiratorExpire',array($id));
  579. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> SCHEDULED at '.date_i18n('r',$ts).' '.'('.$ts.') with options '.print_r($opts,true)));
  580.  
  581. // Update Post Meta
  582. update_post_meta($id, '_expiration-date', $ts);
  583. update_post_meta($id, '_expiration-date-options', $opts);
  584. update_post_meta($id, '_expiration-date-status','saved');
  585. }
  586.  
  587. function _unscheduleExpiratorEvent($id) {
  588. $debug = postExpiratorDebug(); // check for/load debug
  589.  
  590. do_action('postexpiratior_unschedule',$id); // allow custom actions
  591.  
  592. delete_post_meta($id, '_expiration-date');
  593. delete_post_meta($id, '_expiration-date-options');
  594.  
  595. // Delete Scheduled Expiration
  596. if (wp_next_scheduled('postExpiratorExpire',array($id)) !== false) {
  597. wp_clear_scheduled_hook('postExpiratorExpire',array($id)); //Remove any existing hooks
  598. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> UNSCHEDULED'));
  599. }
  600. update_post_meta($id, '_expiration-date-status','saved');
  601. }
  602.  
  603. /**
  604. * The new expiration function, to work with single scheduled events.
  605. *
  606. * This was designed to hopefully be more flexible for future tweaks/modifications to the architecture.
  607. *
  608. * @param array $opts - options to pass into the expiration process, in key/value format
  609. */
  610. function postExpiratorExpire($id) {
  611. $debug = postExpiratorDebug(); //check for/load debug
  612.  
  613. if (empty($id)) {
  614. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => 'No Post ID found - exiting'));
  615. return false;
  616. }
  617.  
  618. if (is_null(get_post($id))) {
  619. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> Post does not exist - exiting'));
  620. return false;
  621. }
  622.  
  623. $posttype = get_post_type($id);
  624. $posttitle = get_the_title($id);
  625. $postlink = get_post_permalink($id);
  626.  
  627. $postoptions = get_post_meta($id,'_expiration-date-options',true);
  628. extract($postoptions);
  629. $ed = get_post_meta($id,'_expiration-date',true);
  630.  
  631. // Check for default expire only if not passed in
  632. if (empty($expireType)) {
  633. $posttype = get_post_type($id);
  634. if ($posttype == 'page') {
  635. $expireType = strtolower(get_option('expirationdateExpiredPageStatus',POSTEXPIRATOR_PAGESTATUS));
  636. } elseif ($posttype == 'post') {
  637. $expireType = strtolower(get_option('expirationdateExpiredPostStatus','Draft'));
  638. } else {
  639. $expireType = apply_filters('postexpirator_custom_posttype_expire', $expireType, $posttype); //hook to set defaults for custom post types
  640. }
  641. }
  642.  
  643. // Remove KSES - wp_cron runs as an unauthenticated user, which will by default trigger kses filtering,
  644. // even if the post was published by a admin user. It is fairly safe here to remove the filter call since
  645. // we are only changing the post status/meta information and not touching the content.
  646. kses_remove_filters();
  647.  
  648. // Do Work
  649. if ($expireType == 'draft') {
  650. if (wp_update_post(array('ID' => $id, 'post_status' => 'draft')) == 0) {
  651. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  652. } else {
  653. $emailBody = sprintf( __( '%s (%s) has expired at %s. Post status has been successfully changed to "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##',strtoupper($expireType) );
  654. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  655. }
  656. } elseif ($expireType == 'private') {
  657. if (wp_update_post(array('ID' => $id, 'post_status' => 'private')) == 0) {
  658. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  659. } else {
  660. $emailBody = sprintf( __( '%s (%s) has expired at %s. Post status has been successfully changed to "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##',strtoupper($expireType) );
  661. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  662. }
  663. } elseif ($expireType == 'delete') {
  664. if (wp_delete_post($id) === false) {
  665. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  666. } else {
  667. $emailBody = sprintf( __( '%s (%s) has expired at %s. Post status has been successfully changed to "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##',strtoupper($expireType) );
  668. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  669. }
  670. } elseif ($expireType == 'trash') {
  671. if (wp_trash_post($id) === false) {
  672. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  673. } else {
  674. $emailBody = sprintf( __( '%s (%s) has expired at %s. Post status has been successfully changed to "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##',strtoupper($expireType) );
  675. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  676. }
  677. } elseif ($expireType == 'stick') {
  678. if (stick_post($id) === false) {
  679. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  680. } else {
  681. $emailBody = sprintf( __( '%s (%s) has expired at %s. Post "%s" status has been successfully set.', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','STICKY' );
  682. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  683. }
  684. } elseif ($expireType == 'unstick') {
  685. if (unstick_post($id) === false) {
  686. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  687. } else {
  688. $emailBody = sprintf( __( '%s (%s) has expired at %s. Post "%s" status has been successfully removed.', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','STICKY' );
  689. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  690. }
  691. } elseif ($expireType == 'category') {
  692. if (!empty($category)) {
  693. if (!isset($categoryTaxonomy) || $categoryTaxonomy == 'category') {
  694. if (wp_update_post(array('ID' => $id, 'post_category' => $category)) == 0) {
  695. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  696. } else {
  697. $emailBody = sprintf( __( '%s (%s) has expired at %s. Post "%s" have now been set to "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','CATEGORIES', implode(',',_postExpiratorGetCatNames($category)));
  698. if (POSTEXPIRATOR_DEBUG) {
  699. $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  700. $debug->save(array('message' => $id.' -> CATEGORIES REPLACED '.print_r(_postExpiratorGetCatNames($category),true)));
  701. $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
  702. }
  703. }
  704. } else {
  705. $terms = array_map('intval', $category);
  706. if (is_wp_error(wp_set_object_terms($id,$terms,$categoryTaxonomy,false))) {
  707. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  708. } else {
  709. $emailBody = sprintf( __( '%s (%s) has expired at %s. Post "%s" have now been set to "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','CATEGORIES', implode(',',_postExpiratorGetCatNames($category)));
  710. if (POSTEXPIRATOR_DEBUG) {
  711. $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  712. $debug->save(array('message' => $id.' -> CATEGORIES REPLACED '.print_r(_postExpiratorGetCatNames($category),true)));
  713. $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
  714. }
  715. }
  716. }
  717. } else {
  718. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> CATEGORIES MISSING '.$expireType.' '.print_r($postoptions,true)));
  719. }
  720. } elseif ($expireType == 'category-add') {
  721. if (!empty($category)) {
  722. if (!isset($categoryTaxonomy) || $categoryTaxonomy == 'category') {
  723. $cats = wp_get_post_categories($id);
  724. $merged = array_merge($cats,$category);
  725. if (wp_update_post(array('ID' => $id, 'post_category' => $merged)) == 0) {
  726. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  727. } else {
  728. $emailBody = sprintf( __( '%s (%s) has expired at %s. The following post "%s" have now been added: "%s". The full list of categories on the post are: "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','CATEGORIES', implode(',',_postExpiratorGetCatNames($category)),implode(',',_postExpiratorGetCatNames($merged)));
  729. if (POSTEXPIRATOR_DEBUG) {
  730. $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  731. $debug->save(array('message' => $id.' -> CATEGORIES ADDED '.print_r(_postExpiratorGetCatNames($category),true)));
  732. $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($merged),true)));
  733. }
  734. }
  735. } else {
  736. $terms = array_map('intval', $category);
  737. if (is_wp_error(wp_set_object_terms($id,$terms,$categoryTaxonomy,true))) {
  738. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  739. } else {
  740. $emailBody = sprintf( __( '%s (%s) has expired at %s. The following post "%s" have now been added: "%s". The full list of categories on the post are: "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','CATEGORIES', implode(',',_postExpiratorGetCatNames($category)),implode(',',_postExpiratorGetCatNames($merged)));
  741. if (POSTEXPIRATOR_DEBUG) {
  742. $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  743. $debug->save(array('message' => $id.' -> CATEGORIES ADDED '.print_r(_postExpiratorGetCatNames($category),true)));
  744. $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
  745. }
  746. }
  747. }
  748. } else {
  749. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> CATEGORIES MISSING '.$expireType.' '.print_r($postoptions,true)));
  750. }
  751. } elseif ($expireType == 'category-remove') {
  752. if (!empty($category)) {
  753. if (!isset($categoryTaxonomy) || $categoryTaxonomy == 'category') {
  754. $cats = wp_get_post_categories($id);
  755. $merged = array();
  756. foreach ($cats as $cat) {
  757. if (!in_array($cat,$category)) {
  758. $merged[] = $cat;
  759. }
  760. }
  761. if (wp_update_post(array('ID' => $id, 'post_category' => $merged)) == 0) {
  762. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  763. } else {
  764. $emailBody = sprintf( __( '%s (%s) has expired at %s. The following post "%s" have now been removed: "%s". The full list of categories on the post are: "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','CATEGORIES', implode(',',_postExpiratorGetCatNames($category)),implode(',',_postExpiratorGetCatNames($merged)));
  765. if (POSTEXPIRATOR_DEBUG) {
  766. $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  767. $debug->save(array('message' => $id.' -> CATEGORIES REMOVED '.print_r(_postExpiratorGetCatNames($category),true)));
  768. $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($merged),true)));
  769. }
  770. }
  771. } else {
  772. $terms = wp_get_object_terms($id, $categoryTaxonomy, array('fields' => 'ids'));
  773. $merged = array();
  774. foreach ($terms as $term) {
  775. if (!in_array($term,$category)) {
  776. $merged[] = $term;
  777. }
  778. }
  779. $terms = array_map('intval', $merged);
  780. if (is_wp_error(wp_set_object_terms($id,$terms,$categoryTaxonomy,false))) {
  781. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  782. } else {
  783. $emailBody = sprintf( __( '%s (%s) has expired at %s. The following post "%s" have now been removed: "%s". The full list of categories on the post are: "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','CATEGORIES', implode(',',_postExpiratorGetCatNames($category)),implode(',',_postExpiratorGetCatNames($merged)));
  784. if (POSTEXPIRATOR_DEBUG) {
  785. $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  786. $debug->save(array('message' => $id.' -> CATEGORIES REMOVED '.print_r(_postExpiratorGetCatNames($category),true)));
  787. $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
  788. }
  789. }
  790. }
  791. } else {
  792. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> CATEGORIES MISSING '.$expireType.' '.print_r($postoptions,true)));
  793. }
  794. }
  795.  
  796. //Process Email
  797. $emailenabled = get_option('expirationdateEmailNotification',POSTEXPIRATOR_EMAILNOTIFICATION);
  798. if ($emailenabled == 1 && isset($emailBody)) {
  799. $subj = sprintf( __('Post Expiration Complete "%s"', 'post-expirator'), $posttitle);
  800. $emailBody = str_replace( "##POSTTITLE##", $posttitle, $emailBody );
  801. $emailBody = str_replace( "##POSTLINK##", $postlink, $emailBody );
  802. $emailBody = str_replace( "##EXPIRATIONDATE##", get_date_from_gmt(gmdate('Y-m-d H:i:s',$ed),get_option('date_format').' '.get_option('time_format')), $emailBody );
  803.  
  804. $emails = array();
  805. // Get Blog Admins
  806. $emailadmins = get_option('expirationdateEmailNotificationAdmins',POSTEXPIRATOR_EMAILNOTIFICATIONADMINS);
  807. if ($emailadmins == 1) {
  808. $blogusers = get_users('role=Administrator');
  809. foreach ($blogusers as $user) {
  810. $emails[] = $user->user_email;
  811. }
  812. }
  813.  
  814. // Get Global Notification Emails
  815. $emaillist = get_option('expirationdateEmailNotificationList');
  816. if (!empty($emaillist)) {
  817. $vals = explode(',',$emaillist);
  818. foreach ($vals as $val) {
  819. $emails[] = trim($val);
  820. }
  821. }
  822.  
  823. // Get Post Type Notification Emails
  824. $defaults = get_option('expirationdateDefaults'.ucfirst($posttype));
  825. if (isset($defaults['emailnotification']) && !empty($defaults['emailnotification'])) {
  826. $vals = explode(',',$defaults['emailnotification']);
  827. foreach ($vals as $val) {
  828. $emails[] = trim($val);
  829. }
  830. }
  831.  
  832. // Send Emails
  833. foreach ($emails as $email) {
  834. if (wp_mail($email, sprintf(__('[%s] %s'), get_option('blogname'), $subj), $emailBody)) {
  835. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> EXPIRATION EMAIL SENT ('.$email.')'));
  836. } else {
  837. if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> EXPIRATION EMAIL FAILED ('.$email.')'));
  838. }
  839. }
  840. }
  841.  
  842. }
  843. add_action('postExpiratorExpire','postExpiratorExpire');
  844.  
  845. function _postExpiratorGetCatNames($cats) {
  846. $out = array();
  847. foreach ($cats as $cat) {
  848. $out[$cat] = get_the_category_by_id($cat);
  849. }
  850. return $out;
  851. }
  852.  
  853. /**
  854. * Build the menu for the options page
  855. */
  856. function postExpiratorMenuTabs($tab) {
  857. echo '<p>';
  858. if (empty($tab)) $tab = 'general';
  859. echo '<a href="'.admin_url('options-general.php?page=post-expirator.php&tab=general').'"'.($tab == 'general' ? ' style="font-weight: bold; text-decoration:none;"' : '').'>'.__('General Settings','post-expirator').'</a> | ';
  860. echo '<a href="'.admin_url('options-general.php?page=post-expirator.php&tab=defaults').'"'.($tab == 'defaults' ? ' style="font-weight: bold; text-decoration:none;"' : '').'>'.__('Defaults','post-expirator').'</a> | ';
  861. echo '<a href="'.admin_url('options-general.php?page=post-expirator.php&tab=diagnostics').'"'.($tab == 'diagnostics' ? ' style="font-weight: bold; text-decoration:none;"' : '').'>'.__('Diagnostics','post-expirator').'</a> | ';
  862. echo '<a href="'.admin_url('options-general.php?page=post-expirator.php&tab=viewdebug').'"'.($tab == 'viewdebug' ? ' style="font-weight: bold; text-decoration:none;"' : '').'>'.__('View Debug Logs','post-expirator').'</a>';
  863. echo '</p><hr/>';
  864. }
  865.  
  866. /**
  867. *
  868. */
  869. function postExpiratorMenu() {
  870. $tab = isset($_GET['tab']) ? $_GET['tab'] : '';
  871.  
  872. echo '<div class="wrap">';
  873. echo '<h2>'.__('Post Expirator Options','post-expirator').'</h2>';
  874.  
  875. postExpiratorMenuTabs($tab);
  876. if (empty($tab) || $tab == 'general') {
  877. postExpiratorMenuGeneral();
  878. } elseif ($tab == 'defaults') {
  879. postExpiratorMenuDefaults();
  880. } elseif ($tab == 'diagnostics') {
  881. postExpiratorMenuDiagnostics();
  882. } elseif ($tab == 'viewdebug') {
  883. postExpiratorMenuViewdebug();
  884. }
  885. echo '</div>';
  886. }
  887.  
  888. /**
  889. * Hook's to add plugin page menu
  890. */
  891. function postExpiratorPluginMenu() {
  892. add_submenu_page('options-general.php',__('Post Expirator Options','post-expirator'),__('Post Expirator','post-expirator'),'manage_options',basename(__FILE__),'postExpiratorMenu');
  893. }
  894. add_action('admin_menu', 'postExpiratorPluginMenu');
  895.  
  896. /**
  897. * Show the Expiration Date options page
  898. */
  899. function postExpiratorMenuGeneral() {
  900. if (isset($_POST['expirationdateSave']) && $_POST['expirationdateSave']) {
  901. if ( !isset($_POST['_postExpiratorMenuGeneral_nonce']) || !wp_verify_nonce($_POST['_postExpiratorMenuGeneral_nonce'],'postExpiratorMenuGeneral') ) {
  902. print 'Form Validation Failure: Sorry, your nonce did not verify.';
  903. exit;
  904. } else {
  905. //Filter Content
  906. $_POST = filter_input_array(INPUT_POST,FILTER_SANITIZE_STRING);
  907.  
  908. update_option('expirationdateDefaultDateFormat',$_POST['expired-default-date-format']);
  909. update_option('expirationdateDefaultTimeFormat',$_POST['expired-default-time-format']);
  910. update_option('expirationdateDisplayFooter',$_POST['expired-display-footer']);
  911. update_option('expirationdateEmailNotification',$_POST['expired-email-notification']);
  912. update_option('expirationdateEmailNotificationAdmins',$_POST['expired-email-notification-admins']);
  913. update_option('expirationdateEmailNotificationList',trim($_POST['expired-email-notification-list']));
  914. update_option('expirationdateFooterContents',$_POST['expired-footer-contents']);
  915. update_option('expirationdateFooterStyle',$_POST['expired-footer-style']);
  916. if (isset($_POST['expirationdate_category'])) update_option('expirationdateCategoryDefaults',$_POST['expirationdate_category']);
  917. update_option('expirationdateDefaultDate',$_POST['expired-default-expiration-date']);
  918. if ($_POST['expired-custom-expiration-date']) update_option('expirationdateDefaultDateCustom',$_POST['expired-custom-expiration-date']);
  919. echo "<div id='message' class='updated fade'><p>";
  920. _e('Saved Options!','post-expirator');
  921. echo "</p></div>";
  922. }
  923. }
  924.  
  925. // Get Option
  926. $expirationdateDefaultDateFormat = get_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT);
  927. $expirationdateDefaultTimeFormat = get_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT);
  928. $expireddisplayfooter = get_option('expirationdateDisplayFooter',POSTEXPIRATOR_FOOTERDISPLAY);
  929. $expiredemailnotification = get_option('expirationdateEmailNotification',POSTEXPIRATOR_EMAILNOTIFICATION);
  930. $expiredemailnotificationadmins = get_option('expirationdateEmailNotificationAdmins',POSTEXPIRATOR_EMAILNOTIFICATIONADMINS);
  931. $expiredemailnotificationlist = get_option('expirationdateEmailNotificationList','');
  932. $expirationdateFooterContents = get_option('expirationdateFooterContents',POSTEXPIRATOR_FOOTERCONTENTS);
  933. $expirationdateFooterStyle = get_option('expirationdateFooterStyle',POSTEXPIRATOR_FOOTERSTYLE);
  934. $expirationdateDefaultDate = get_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
  935. $expirationdateDefaultDateCustom = get_option('expirationdateDefaultDateCustom');
  936.  
  937. $categories = get_option('expirationdateCategoryDefaults');
  938.  
  939. $expireddisplayfooterenabled = '';
  940. $expireddisplayfooterdisabled = '';
  941. if ($expireddisplayfooter == 0)
  942. $expireddisplayfooterdisabled = 'checked="checked"';
  943. else if ($expireddisplayfooter == 1)
  944. $expireddisplayfooterenabled = 'checked="checked"';
  945.  
  946. $expiredemailnotificationenabled = '';
  947. $expiredemailnotificationdisabled = '';
  948. if ($expiredemailnotification == 0)
  949. $expiredemailnotificationdisabled = 'checked="checked"';
  950. else if ($expiredemailnotification == 1)
  951. $expiredemailnotificationenabled = 'checked="checked"';
  952.  
  953. $expiredemailnotificationadminsenabled = '';
  954. $expiredemailnotificationadminsdisabled = '';
  955. if ($expiredemailnotificationadmins == 0)
  956. $expiredemailnotificationadminsdisabled = 'checked="checked"';
  957. else if ($expiredemailnotificationadmins == 1)
  958. $expiredemailnotificationadminsenabled = 'checked="checked"';
  959. ?>
  960. <p>
  961. <?php _e('The post expirator plugin sets a custom meta value, and then optionally allows you to select if you want the post changed to a draft status or deleted when it expires.','post-expirator'); ?>
  962. </p>
  963. <p>
  964. <?php _e('Valid [postexpirator] attributes:','post-expirator'); ?>
  965. <ul>
  966. <li><?php _e('type - defaults to full - valid options are full,date,time','post-expirator');?></li>
  967. <li><?php _e('dateformat - format set here will override the value set on the settings page','post-expirator');?></li>
  968. <li><?php _e('timeformat - format set here will override the value set on the settings page','post-expirator');?></li>
  969. </ul>
  970. </p>
  971. <form method="post" id="expirationdate_save_options">
  972. <?php wp_nonce_field('postExpiratorMenuGeneral','_postExpiratorMenuGeneral_nonce'); ?>
  973. <h3><?php _e('Defaults','post-expirator'); ?></h3>
  974. <table class="form-table">
  975. <tr valign="top">
  976. <th scope="row"><label for="expired-default-date-format"><?php _e('Date Format:','post-expirator');?></label></th>
  977. <td>
  978. <input type="text" name="expired-default-date-format" id="expired-default-date-format" value="<?php echo $expirationdateDefaultDateFormat ?>" size="25" /> (<?php echo date_i18n("$expirationdateDefaultDateFormat") ?>)
  979. <br/>
  980. <?php _e('The default format to use when displaying the expiration date within a post using the [postexpirator] shortcode or within the footer. For information on valid formatting options, see: <a href="http://us2.php.net/manual/en/function.date.php" target="_blank">PHP Date Function</a>.','post-expirator'); ?>
  981. </td>
  982. </tr>
  983. <tr valign="top">
  984. <th scope="row"><label for="expired-default-time-format"><?php _e('Time Format:','post-expirator');?></label></th>
  985. <td>
  986. <input type="text" name="expired-default-time-format" id="expired-default-time-format" value="<?php echo $expirationdateDefaultTimeFormat ?>" size="25" /> (<?php echo date_i18n("$expirationdateDefaultTimeFormat") ?>)
  987. <br/>
  988. <?php _e('The default format to use when displaying the expiration time within a post using the [postexpirator] shortcode or within the footer. For information on valid formatting options, see: <a href="http://us2.php.net/manual/en/function.date.php" target="_blank">PHP Date Function</a>.','post-expirator'); ?>
  989. </td>
  990. </tr>
  991. <tr valign="top">
  992. <th scope="row"><label for="expired-default-expiration-date"><?php _e('Default Date/Time Duration:','post-expirator');?></label></th>
  993. <td>
  994. <select name="expired-default-expiration-date" id="expired-default-expiration-date" onchange="expirationdate_toggle_defaultdate(this)">
  995. <option value="null" <?php echo ($expirationdateDefaultDate == 'null') ? ' selected="selected"' : ''; ?>><?php _e('None','post-expirator');?></option>
  996. <option value="custom" <?php echo ($expirationdateDefaultDate == 'custom') ? ' selected="selected"' : ''; ?>><?php _e('Custom','post-expirator');?></option>
  997. <option value="publish" <?php echo ($expirationdateDefaultDate == 'publish') ? ' selected="selected"' : ''; ?>><?php _e('Post/Page Publish Time','post-expirator');?></option>
  998. </select>
  999. <br/>
  1000. <?php _e('Set the default expiration date to be used when creating new posts and pages. Defaults to none.','post-expirator'); ?>
  1001. <?php $show = ($expirationdateDefaultDate == 'custom') ? 'block' : 'none'; ?>
  1002. <div id="expired-custom-container" style="display: <?php echo $show; ?>;">
  1003. <br/><label for="expired-custom-expiration-date">Custom:</label> <input type="text" value="<?php echo $expirationdateDefaultDateCustom; ?>" name="expired-custom-expiration-date" id="expired-custom-expiration-date" />
  1004. <br/>
  1005. <?php _e('Set the custom value to use for the default expiration date. For information on formatting, see <a href="http://php.net/manual/en/function.strtotime.php">PHP strtotime function</a>. For example, you could enter "+1 month" or "+1 week 2 days 4 hours 2 seconds" or "next Thursday."','post-expirator'); ?>
  1006. </div>
  1007. </td>
  1008. </tr>
  1009. </table>
  1010. <h3><?php _e('Category Expiration','post-expirator');?></h3>
  1011. <table class="form-table">
  1012. <tr valign="top">
  1013. <th scope="row"><?php _e('Default Expiration Category','post-expirator');?>:</th>
  1014. <td>
  1015. <?php
  1016. echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
  1017. echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
  1018. $walker = new Walker_PostExpirator_Category_Checklist();
  1019. wp_terms_checklist(0, array( 'taxonomy' => 'category', 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );
  1020. echo '</ul>';
  1021. echo '</div>';
  1022. ?>
  1023. <br/>
  1024. <?php _e("Set's the default expiration category for the post.",'post-expirator');?>
  1025. </td>
  1026. </tr>
  1027. </table>
  1028.  
  1029. <h3><?php _e('Expiration Email Notification','post-expirator');?></h3>
  1030. <p><?php _e('Whenever a post expires, an email can be sent to alert users of the expiration.','post-expirator');?></p>
  1031. <table class="form-table">
  1032. <tr valign="top">
  1033. <th scope="row"><?php _e('Enable Email Notification?','post-expirator');?></th>
  1034. <td>
  1035. <input type="radio" name="expired-email-notification" id="expired-email-notification-true" value="1" <?php echo $expiredemailnotificationenabled ?>/> <label for="expired-email-notification-true"><?php _e('Enabled','post-expirator');?></label>
  1036. <br/>
  1037. <input type="radio" name="expired-email-notification" id="expired-email-notification-false" value="0" <?php echo $expiredemailnotificationdisabled ?>/> <label for="expired-email-notification-false"><?php _e('Disabled','post-expirator');?></label>
  1038. <br/>
  1039. <?php _e('This will enable or disable the send of email notification on post expiration.','post-expirator');?>
  1040. </td>
  1041. </tr>
  1042. <tr valign="top">
  1043. <th scope="row"><?php _e('Include Blog Administrators?','post-expirator');?></th>
  1044. <td>
  1045. <input type="radio" name="expired-email-notification-admins" id="expired-email-notification-admins-true" value="1" <?php echo $expiredemailnotificationadminsenabled ?>/> <label for="expired-email-notification-admins-true"><?php _e('Enabled','post-expirator');?></label>
  1046. <br/>
  1047. <input type="radio" name="expired-email-notification-admins" id="expired-email-notification-admins-false" value="0" <?php echo $expiredemailnotificationadminsdisabled ?>/> <label for="expired-email-notification-admins-false"><?php _e('Disabled','post-expirator');?></label>
  1048. <br/>
  1049. <?php _e('This will include all users with the role of "Administrator" in the post expiration email.','post-expirator');?>
  1050. </td>
  1051. </tr>
  1052. <tr valign="top">
  1053. <th scope="row"><label for="expired-email-notification-list"><?php _e('Who to notify:','post-expirator'); ?></label></th>
  1054. <td>
  1055. <input class="large-text" type="text" name="expired-email-notification-list" id="expired-email-notification-list" value="<?php echo $expiredemailnotificationlist ?>" />
  1056. <br/>
  1057. <?php _e('Enter a comma seperate list of emails that you would like to be notified when the post expires. This will be applied to ALL post types. You can set post type specific emails on the Defaults tab.','post-expirator');?>
  1058. </td>
  1059. </tr>
  1060. </table>
  1061.  
  1062. <h3><?php _e('Post Footer Display','post-expirator');?></h3>
  1063. <p><?php _e('Enabling this below will display the expiration date automatically at the end of any post which is set to expire.','post-expirator');?></p>
  1064. <table class="form-table">
  1065. <tr valign="top">
  1066. <th scope="row"><?php _e('Show in post footer?','post-expirator');?></th>
  1067. <td>
  1068. <input type="radio" name="expired-display-footer" id="expired-display-footer-true" value="1" <?php echo $expireddisplayfooterenabled ?>/> <label for="expired-display-footer-true"><?php _e('Enabled','post-expirator');?></label>
  1069. <br/>
  1070. <input type="radio" name="expired-display-footer" id="expired-display-footer-false" value="0" <?php echo $expireddisplayfooterdisabled ?>/> <label for="expired-display-footer-false"><?php _e('Disabled','post-expirator');?></label>
  1071. <br/>
  1072. <?php _e('This will enable or disable displaying the post expiration date in the post footer.','post-expirator');?>
  1073. </td>
  1074. </tr>
  1075. <tr valign="top">
  1076. <th scope="row"><label for="expired-footer-contents"><?php _e('Footer Contents:','post-expirator');?></label></th>
  1077. <td>
  1078. <textarea id="expired-footer-contents" name="expired-footer-contents" rows="3" cols="50"><?php echo $expirationdateFooterContents; ?></textarea>
  1079. <br/>
  1080. <?php _e('Enter the text you would like to appear at the bottom of every post that will expire. The following placeholders will be replaced with the post expiration date in the following format:','post-expirator');?>
  1081. <ul>
  1082. <li>EXPIRATIONFULL -> <?php echo date_i18n("$expirationdateDefaultDateFormat $expirationdateDefaultTimeFormat") ?></li>
  1083. <li>EXPIRATIONDATE -> <?php echo date_i18n("$expirationdateDefaultDateFormat") ?></li>
  1084. <li>EXPIRATIONTIME -> <?php echo date_i18n("$expirationdateDefaultTimeFormat") ?></li>
  1085. </ul>
  1086. </td>
  1087. </tr>
  1088. <tr valign="top">
  1089. <th scope="row"><label for="expired-footer-style"><?php _e('Footer Style:','post-expirator');?></label></th>
  1090. <td>
  1091. <input type="text" name="expired-footer-style" id="expired-footer-style" value="<?php echo $expirationdateFooterStyle ?>" size="25" />
  1092. (<span style="<?php echo $expirationdateFooterStyle ?>"><?php _e('This post will expire on','post-expirator');?> <?php echo date_i18n("$expirationdateDefaultDateFormat $expirationdateDefaultTimeFormat"); ?></span>)
  1093. <br/>
  1094. <?php _e('The inline css which will be used to style the footer text.','post-expirator');?>
  1095. </td>
  1096. </tr>
  1097. </table>
  1098. <p class="submit">
  1099. <input type="submit" name="expirationdateSave" class="button-primary" value="<?php _e('Save Changes','post-expirator');?>" />
  1100. </p>
  1101. </form>
  1102. <?php
  1103. }
  1104.  
  1105. function postExpiratorMenuDefaults() {
  1106. $debug = postExpiratorDebug();
  1107. $types = get_post_types(array('public' => true, '_builtin' => false));
  1108. array_unshift($types,'post','page');
  1109.  
  1110. if (isset($_POST['expirationdateSaveDefaults'])) {
  1111. if ( !isset($_POST['_postExpiratorMenuDefaults_nonce']) || !wp_verify_nonce($_POST['_postExpiratorMenuDefaults_nonce'],'postExpiratorMenuDefaults') ) {
  1112. print 'Form Validation Failure: Sorry, your nonce did not verify.';
  1113. exit;
  1114. } else {
  1115. //Filter Content
  1116. $_POST = filter_input_array(INPUT_POST,FILTER_SANITIZE_STRING);
  1117.  
  1118. $defaults = array();
  1119. foreach ($types as $type) {
  1120. if (isset($_POST['expirationdate_expiretype-'.$type])) {
  1121. $defaults[$type]['expireType'] = $_POST['expirationdate_expiretype-'.$type];
  1122. }
  1123. if (isset($_POST['expirationdate_autoenable-'.$type])) {
  1124. $defaults[$type]['autoEnable'] = intval($_POST['expirationdate_autoenable-'.$type]);
  1125. }
  1126. if (isset($_POST['expirationdate_taxonomy-'.$type])) {
  1127. $defaults[$type]['taxonomy'] = $_POST['expirationdate_taxonomy-'.$type];
  1128. }
  1129. if (isset($_POST['expirationdate_activemeta-'.$type])) {
  1130. $defaults[$type]['activeMetaBox'] = $_POST['expirationdate_activemeta-'.$type];
  1131. }
  1132. $defaults[$type]['emailnotification'] = trim($_POST['expirationdate_emailnotification-'.$type]);
  1133.  
  1134. //Save Settings
  1135. update_option('expirationdateDefaults'.ucfirst($type),$defaults[$type]);
  1136. }
  1137. echo "<div id='message' class='updated fade'><p>";
  1138. _e('Saved Options!','post-expirator');
  1139. echo "</p></div>";
  1140. }
  1141. }
  1142.  
  1143. ?>
  1144. <form method="post">
  1145. <?php wp_nonce_field('postExpiratorMenuDefaults','_postExpiratorMenuDefaults_nonce'); ?>
  1146. <h3><?php _e('Default Expiration Values','post-expirator');?></h3>
  1147. <p>
  1148. <?php _e('Use the values below to set the default actions/values to be used for each for the corresponding post types. These values can all be overwritten when creating/editing the post/page.','post-expirator'); ?>
  1149. </p>
  1150. <?php
  1151. foreach ($types as $type) {
  1152. echo "<fieldset style='border: 1px solid black; border-radius: 6px; padding: 0px 12px; margin-bottom: 20px;'>";
  1153. echo "<legend>Post Type: $type</legend>";
  1154. $defaults = get_option('expirationdateDefaults'.ucfirst($type));
  1155.  
  1156. if (isset($defaults['autoEnable']) && $defaults['autoEnable'] == 1) {
  1157. $expiredautoenabled = 'checked = "checked"';
  1158. $expiredautodisabled = '';
  1159. } else {
  1160. $expiredautoenabled = '';
  1161. $expiredautodisabled = 'checked = "checked"';
  1162. }
  1163. if (isset($defaults['activeMetaBox']) && $defaults['activeMetaBox'] == 'inactive') {
  1164. $expiredactivemetaenabled = '';
  1165. $expiredactivemetadisabled = 'checked = "checked"';
  1166. } else {
  1167. $expiredactivemetaenabled = 'checked = "checked"';
  1168. $expiredactivemetadisabled = '';
  1169. }
  1170. if (!isset($defaults['taxonomy'])) {
  1171. $defaults['taxonomy'] = false;
  1172. }
  1173. ?>
  1174. <table class="form-table">
  1175. <tr valign="top">
  1176. <th scope="row"><label for="expirationdate_activemeta-<?php echo $type ?>"><?php _e('Active:','post-expirator');?></label></th>
  1177. <td>
  1178. <input type="radio" name="expirationdate_activemeta-<?php echo $type ?>" id="expirationdate_activemeta-true-<?php echo $type ?>" value="active" <?php echo $expiredactivemetaenabled ?>/> <label for="expired-active-meta-true"><?php _e('Active','post-expirator');?></label>
  1179. <br/>
  1180. <input type="radio" name="expirationdate_activemeta-<?php echo $type ?>" id="expirationdate_activemeta-false-<?php echo $type ?>" value="inactive" <?php echo $expiredactivemetadisabled ?>/> <label for="expired-active-meta-false"><?php _e('Inactive','post-expirator');?></label>
  1181. <br/>
  1182. <?php _e('Select whether the post expirator meta box is active for this post type.','post-expirator');?>
  1183. </td>
  1184. </tr>
  1185. <tr valign="top">
  1186. <th scope="row"><label for="expirationdate_expiretype-<?php echo $type ?>"><?php _e('How to expire:','post-expirator'); ?></label></th>
  1187. <td>
  1188. <?php echo _postExpiratorExpireType(array('name'=>'expirationdate_expiretype-'.$type,'selected' => $defaults['expireType'])); ?>
  1189. </select>
  1190. <br/>
  1191. <?php _e('Select the default expire action for the post type.','post-expirator');?>
  1192. </td>
  1193. </tr>
  1194. <tr valign="top">
  1195. <th scope="row"><label for="expirationdate_autoenable-<?php echo $type ?>"><?php _e('Auto-Enable?','post-expirator');?></label></th>
  1196. <td>
  1197. <input type="radio" name="expirationdate_autoenable-<?php echo $type ?>" id="expirationdate_autoenable-true-<?php echo $type ?>" value="1" <?php echo $expiredautoenabled ?>/> <label for="expired-auto-enable-true"><?php _e('Enabled','post-expirator');?></label>
  1198. <br/>
  1199. <input type="radio" name="expirationdate_autoenable-<?php echo $type ?>" id="expirationdate_autoenable-false-<?php echo $type ?>" value="0" <?php echo $expiredautodisabled ?>/> <label for="expired-auto-enable-false"><?php _e('Disabled','post-expirator');?></label>
  1200. <br/>
  1201. <?php _e('Select whether the post expirator is enabled for all new posts.','post-expirator');?>
  1202. </td>
  1203. </tr>
  1204. <tr valign="top">
  1205. <th scope="row"><label for="expirationdate_taxonomy-<?php echo $type ?>"><?php _e('Taxonomy (hierarchical):','post-expirator'); ?></label></th>
  1206. <td>
  1207. <?php echo _postExpiratorTaxonomy(array('type' => $type, 'name'=>'expirationdate_taxonomy-'.$type,'selected' => $defaults['taxonomy'])); ?>
  1208. </td>
  1209. </tr>
  1210. <tr valign="top">
  1211. <th scope="row"><label for="expirationdate_emailnotification-<?php echo $type ?>"><?php _e('Who to notify:','post-expirator'); ?></label></th>
  1212. <td>
  1213. <input class="large-text" type="text" name="expirationdate_emailnotification-<?php echo $type ?>" id="expirationdate_emailnotification-<?php echo $type ?>" value="<?php echo $defaults['emailnotification']; ?>" />
  1214. <br/>
  1215. <?php _e('Enter a comma seperate list of emails that you would like to be notified when the post expires.','post-expirator');?>
  1216. </td>
  1217. </tr>
  1218.  
  1219. </table>
  1220. </fieldset>
  1221. <?php
  1222. }
  1223. ?>
  1224. <p class="submit">
  1225. <input type="submit" name="expirationdateSaveDefaults" class="button-primary" value="<?php _e('Save Changes','post-expirator');?>" />
  1226. </p>
  1227. </form>
  1228. <?php
  1229. }
  1230.  
  1231. function postExpiratorMenuDiagnostics() {
  1232. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  1233. if ( !isset($_POST['_postExpiratorMenuDiagnostics_nonce']) || !wp_verify_nonce($_POST['_postExpiratorMenuDiagnostics_nonce'],'postExpiratorMenuDiagnostics') ) {
  1234. print 'Form Validation Failure: Sorry, your nonce did not verify.';
  1235. exit;
  1236. }
  1237. if (isset($_POST['debugging-disable'])) {
  1238. update_option('expirationdateDebug',0);
  1239. echo "<div id='message' class='updated fade'><p>"; _e('Debugging Disabled','post-expirator'); echo "</p></div>";
  1240. } elseif (isset($_POST['debugging-enable'])) {
  1241. update_option('expirationdateDebug',1);
  1242. echo "<div id='message' class='updated fade'><p>"; _e('Debugging Enabled','post-expirator'); echo "</p></div>";
  1243. } elseif (isset($_POST['purge-debug'])) {
  1244. require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php');
  1245. $debug = new postExpiratorDebug();
  1246. $debug->purge();
  1247. echo "<div id='message' class='updated fade'><p>"; _e('Debugging Table Emptied','post-expirator'); echo "</p></div>";
  1248. }
  1249. }
  1250.  
  1251. $debug = postExpiratorDebug();
  1252. ?>
  1253. <form method="post" id="postExpiratorMenuUpgrade">
  1254. <?php wp_nonce_field('postExpiratorMenuDiagnostics','_postExpiratorMenuDiagnostics_nonce'); ?>
  1255. <h3><?php _e('Advanced Diagnostics','post-expirator');?></h3>
  1256. <table class="form-table">
  1257. <tr valign="top">
  1258. <th scope="row"><label for="postexpirator-log"><?php _e('Post Expirator Debug Logging:','post-expirator');?></label></th>
  1259. <td>
  1260. <?php
  1261. if (POSTEXPIRATOR_DEBUG) {
  1262. echo __('Status: Enabled','post-expirator').'<br/>';
  1263. echo '<input type="submit" class="button" name="debugging-disable" id="debugging-disable" value="'.__('Disable Debugging','post-expirator').'" />';
  1264. } else {
  1265. echo __('Status: Disabled','post-expirator').'<br/>';
  1266. echo '<input type="submit" class="button" name="debugging-enable" id="debugging-enable" value="'.__('Enable Debugging','post-expirator').'" />';
  1267. }
  1268. ?>
  1269. <br/>
  1270. <a href="<?php echo admin_url('options-general.php?page=post-expirator.php&tab=viewdebug') ?>">View Debug Logs</a>
  1271. </td>
  1272. </tr>
  1273. <tr valign="top">
  1274. <th scope="row"><?php _e('Purge Debug Log:','post-expirator');?></th>
  1275. <td>
  1276. <input type="submit" class="button" name="purge-debug" id="purge-debug" value="<?php _e('Purge Debug Log','post-expirator');?>" />
  1277. </td>
  1278. </tr/>
  1279. <tr valign="top">
  1280. <th scope="row"><?php _e('WP-Cron Status:','post-expirator');?></th>
  1281. <td>
  1282. <?php
  1283. if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON === true) {
  1284. _e('DISABLED','post-expirator');
  1285. } else {
  1286. _e('ENABLED - OK','post-expirator');
  1287. }
  1288. ?>
  1289. </td>
  1290. </tr/>
  1291. <tr valign="top">
  1292. <th scope="row"><label for="cron-schedule"><?php _e('Current Cron Schedule:','post-expirator');?></label></th>
  1293. <td>
  1294. <?php _e('The below table will show all currently scheduled cron events with the next run time.','post-expirator');?><br/>
  1295. <table>
  1296. <tr>
  1297. <th style="width: 200px;"><?php _e('Date','post-expirator');?></th>
  1298. <th style="width: 200px;"><?php _e('Event','post-expirator');?></th>
  1299. <th style="width: 500px;"><?php _e('Arguments / Schedule','post-expirator');?></th>
  1300. </tr>
  1301. <?php
  1302. $cron = _get_cron_array();
  1303. foreach ($cron as $key=>$value) {
  1304. foreach ($value as $eventkey=>$eventvalue) {
  1305. print '<tr>';
  1306. print '<td>'.date_i18n('r',$key).'</td>';
  1307. print '<td>'.$eventkey.'</td>';
  1308. $arrkey = array_keys($eventvalue);
  1309. print '<td>';
  1310. foreach ($arrkey as $eventguid) {
  1311. print '<table><tr>';
  1312. if (empty($eventvalue[$eventguid]['args'])) {
  1313. print '<td>No Arguments</td>';
  1314. } else {
  1315. print '<td>';
  1316. $args = array();
  1317. foreach ($eventvalue[$eventguid]['args'] as $key=>$value) {
  1318. $args[] = "$key => $value";
  1319. }
  1320. print implode("<br/>\n",$args);
  1321. print '</td>';
  1322. }
  1323. if (empty($eventvalue[$eventguid]['schedule'])) {
  1324. print '<td>'.__('Single Event','post-expirator').'</td>';
  1325. } else {
  1326. print '<td>'.$eventvalue[$eventguid]['schedule'].' ('.$eventvalue[$eventguid]['interval'].')</td>';
  1327. }
  1328. print '</tr></table>';
  1329. }
  1330. print '</td>';
  1331. print '</tr>';
  1332. }
  1333. }
  1334. ?>
  1335. </table>
  1336. </td>
  1337. </tr>
  1338. </table>
  1339. </form>
  1340. <?php
  1341. }
  1342.  
  1343. function postExpiratorMenuViewdebug() {
  1344. require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php');
  1345. print "<p>".__('Below is a dump of the debugging table, this should be useful for troubleshooting.','post-expirator')."</p>";
  1346. $debug = new postExpiratorDebug();
  1347. $debug->getTable();
  1348. }
  1349.  
  1350. // [postexpirator format="l F jS, Y g:ia" tz="foo"]
  1351. function postexpirator_shortcode($atts) {
  1352. global $post;
  1353.  
  1354. $expirationdatets = get_post_meta($post->ID,'_expiration-date',true);
  1355. if (empty($expirationdatets))
  1356. return false;
  1357.  
  1358. extract(shortcode_atts(array(
  1359. 'dateformat' => get_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT),
  1360. 'timeformat' => get_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT),
  1361. 'type' => 'full',
  1362. 'tz' => date('T')
  1363. ), $atts));
  1364.  
  1365. if (empty($dateformat)) {
  1366. global $expirationdateDefaultDateFormat;
  1367. $dateformat = $expirationdateDefaultDateFormat;
  1368. }
  1369.  
  1370. if (empty($timeformat)) {
  1371. global $expirationdateDefaultTimeFormat;
  1372. $timeformat = $expirationdateDefaultTimeFormat;
  1373. }
  1374.  
  1375. if ($type == 'full')
  1376. $format = $dateformat.' '.$timeformat;
  1377. else if ($type == 'date')
  1378. $format = $dateformat;
  1379. else if ($type == 'time')
  1380. $format = $timeformat;
  1381.  
  1382. return get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),$format);
  1383. }
  1384. add_shortcode('postexpirator', 'postexpirator_shortcode');
  1385.  
  1386. function postexpirator_add_footer($text) {
  1387. global $post;
  1388.  
  1389. // Check to see if its enabled
  1390. $displayFooter = get_option('expirationdateDisplayFooter');
  1391. if ($displayFooter === false || $displayFooter == 0)
  1392. return $text;
  1393.  
  1394. $expirationdatets = get_post_meta($post->ID,'_expiration-date',true);
  1395. if (!is_numeric($expirationdatets))
  1396. return $text;
  1397.  
  1398. $dateformat = get_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT);
  1399. $timeformat = get_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT);
  1400. $expirationdateFooterContents = get_option('expirationdateFooterContents',POSTEXPIRATOR_FOOTERCONTENTS);
  1401. $expirationdateFooterStyle = get_option('expirationdateFooterStyle',POSTEXPIRATOR_FOOTERSTYLE);
  1402.  
  1403. $search = array(
  1404. 'EXPIRATIONFULL',
  1405. 'EXPIRATIONDATE',
  1406. 'EXPIRATIONTIME'
  1407. );
  1408. $replace = array(
  1409. get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),"$dateformat $timeformat"),
  1410. get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),$dateformat),
  1411. get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),$timeformat)
  1412. );
  1413.  
  1414. $add_to_footer = '<p style="'.$expirationdateFooterStyle.'">'.str_replace($search,$replace,$expirationdateFooterContents).'</p>';
  1415. return $text.$add_to_footer;
  1416. }
  1417. add_action('the_content','postexpirator_add_footer',0);
  1418.  
  1419. /**
  1420. * Check for Debug
  1421. */
  1422. function postExpiratorDebug() {
  1423. $debug = get_option('expirationdateDebug');
  1424. if ($debug == 1) {
  1425. if (!defined('POSTEXPIRATOR_DEBUG')) define('POSTEXPIRATOR_DEBUG',1);
  1426. require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php'); // Load Class
  1427. return new postExpiratorDebug();
  1428. } else {
  1429. if (!defined('POSTEXPIRATOR_DEBUG')) define('POSTEXPIRATOR_DEBUG',0);
  1430. return false;
  1431. }
  1432. }
  1433.  
  1434.  
  1435. /**
  1436. * Add Stylesheet
  1437. */
  1438. function postexpirator_css() {
  1439. $myStyleUrl = plugins_url('style.css', __FILE__); // Respects SSL, Style.css is relative to the current file
  1440. $myStyleFile = WP_PLUGIN_DIR . '/post-expirator/style.css';
  1441. if ( file_exists($myStyleFile) ) {
  1442. wp_register_style('postexpirator-css', $myStyleUrl);
  1443. wp_enqueue_style('postexpirator-css');
  1444. }
  1445.  
  1446. }
  1447. add_action('admin_init','postexpirator_css');
  1448.  
  1449. /**
  1450. * Post Expirator Activation/Upgrade
  1451. */
  1452. function postexpirator_upgrade() {
  1453.  
  1454. // Check for current version, if not exists, run activation
  1455. $version = get_option('postexpiratorVersion');
  1456. if ($version === false) { //not installed, run default activation
  1457. postexpirator_activate();
  1458. update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1459. } else {
  1460. if (version_compare($version,'1.6.1') == -1) {
  1461. update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1462. update_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
  1463. }
  1464.  
  1465. if (version_compare($version,'1.6.2') == -1) {
  1466. update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1467. }
  1468.  
  1469. if (version_compare($version,'2.0.0-rc1') == -1) {
  1470. global $wpdb;
  1471.  
  1472. // Schedule Events/Migrate Config
  1473. $results = $wpdb->get_results($wpdb->prepare('select post_id, meta_value from ' . $wpdb->postmeta . ' as postmeta, '.$wpdb->posts.' as posts where postmeta.post_id = posts.ID AND postmeta.meta_key = %s AND postmeta.meta_value >= %d','expiration-date',time()));
  1474. foreach ($results as $result) {
  1475. wp_schedule_single_event($result->meta_value,'postExpiratorExpire',array($result->post_id));
  1476. $opts = array();
  1477. $opts['id'] = $result->post_id;
  1478. $posttype = get_post_type($result->post_id);
  1479. if ($posttype == 'page') {
  1480. $opts['expireType'] = strtolower(get_option('expirationdateExpiredPageStatus','Draft'));
  1481. } else {
  1482. $opts['expireType'] = strtolower(get_option('expirationdateExpiredPostStatus','Draft'));
  1483. }
  1484.  
  1485. $cat = get_post_meta($result->post_id,'_expiration-date-category',true);
  1486. if ((isset($cat) && !empty($cat))) {
  1487. $opts['category'] = $cat;
  1488. $opts['expireType'] = 'category';
  1489. }
  1490. update_post_meta($result->post_id,'_expiration-date-options',$opts);
  1491. }
  1492.  
  1493. // update meta key to new format
  1494. $wpdb->query($wpdb->prepare("UPDATE $wpdb->postmeta SET meta_key = %s WHERE meta_key = %s",'_expiration-date','expiration-date'));
  1495.  
  1496. // migrate defaults
  1497. $pagedefault = get_option('expirationdateExpiredPageStatus');
  1498. $postdefault = get_option('expirationdateExpiredPostStatus');
  1499. if ($pagedefault) update_option('expirationdateDefaultsPage',array('expireType' => $pagedefault));
  1500. if ($postdefault) update_option('expirationdateDefaultsPost',array('expireType' => $postdefault));
  1501.  
  1502. delete_option('expirationdateCronSchedule');
  1503. delete_option('expirationdateAutoEnabled');
  1504. delete_option('expirationdateExpiredPageStatus');
  1505. delete_option('expirationdateExpiredPostStatus');
  1506. update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1507. }
  1508.  
  1509. if (version_compare($version,'2.0.1') == -1) {
  1510. // Forgot to do this in 2.0.0
  1511. if (is_multisite()) {
  1512. global $current_blog;
  1513. wp_clear_scheduled_hook('expirationdate_delete_'.$current_blog->blog_id);
  1514. } else
  1515. wp_clear_scheduled_hook('expirationdate_delete');
  1516.  
  1517. update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1518. }
  1519.  
  1520. if (version_compare($version,'2.1.0') == -1) {
  1521. update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1522. }
  1523.  
  1524. if (version_compare($version,'2.1.1') == -1) {
  1525. update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1526. }
  1527.  
  1528. if (version_compare($version,'2.2.0') == -1) {
  1529. update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1530. }
  1531. if (version_compare($version,'2.2.1') == -1) {
  1532. update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1533. }
  1534. if (version_compare($version,'2.3.0') == -1) {
  1535. update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1536. }
  1537. if (version_compare($version,'2.3.1') == -1) {
  1538. update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1539. }
  1540. if (version_compare($version,'2.3.1.1') == -1) {
  1541. update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1542. }
  1543. }
  1544. }
  1545. add_action('admin_init','postexpirator_upgrade');
  1546.  
  1547. /**
  1548. * Called at plugin activation
  1549. */
  1550. function postexpirator_activate () {
  1551. if (get_option('expirationdateDefaultDateFormat') === false) update_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT);
  1552. if (get_option('expirationdateDefaultTimeFormat') === false) update_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT);
  1553. if (get_option('expirationdateFooterContents') === false) update_option('expirationdateFooterContents',POSTEXPIRATOR_FOOTERCONTENTS);
  1554. if (get_option('expirationdateFooterStyle') === false) update_option('expirationdateFooterStyle',POSTEXPIRATOR_FOOTERSTYLE);
  1555. if (get_option('expirationdateDisplayFooter') === false) update_option('expirationdateDisplayFooter',POSTEXPIRATOR_FOOTERDISPLAY);
  1556. if (get_option('expirationdateDebug') === false) update_option('expirationdateDebug',POSTEXPIRATOR_DEBUGDEFAULT);
  1557. if (get_option('expirationdateDefaultDate') === false) update_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
  1558. }
  1559.  
  1560. /**
  1561. * Called at plugin deactivation
  1562. */
  1563. function expirationdate_deactivate () {
  1564. global $current_blog;
  1565. delete_option('expirationdateExpiredPostStatus');
  1566. delete_option('expirationdateExpiredPageStatus');
  1567. delete_option('expirationdateDefaultDateFormat');
  1568. delete_option('expirationdateDefaultTimeFormat');
  1569. delete_option('expirationdateDisplayFooter');
  1570. delete_option('expirationdateFooterContents');
  1571. delete_option('expirationdateFooterStyle');
  1572. delete_option('expirationdateCategory');
  1573. delete_option('expirationdateCategoryDefaults');
  1574. delete_option('expirationdateDebug');
  1575. delete_option('postexpiratorVersion');
  1576. delete_option('expirationdateCronSchedule');
  1577. delete_option('expirationdateDefaultDate');
  1578. delete_option('expirationdateDefaultDateCustom');
  1579. delete_option('expirationdateAutoEnabled');
  1580. delete_option('expirationdateDefaultsPage');
  1581. delete_option('expirationdateDefaultsPost');
  1582. ## what about custom post types? - how to cleanup?
  1583. if (is_multisite())
  1584. wp_clear_scheduled_hook('expirationdate_delete_'.$current_blog->blog_id);
  1585. else
  1586. wp_clear_scheduled_hook('expirationdate_delete');
  1587. require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php');
  1588. $debug = new postExpiratorDebug();
  1589. $debug->removeDbTable();
  1590. }
  1591. register_deactivation_hook (__FILE__, 'expirationdate_deactivate');
  1592.  
  1593. class Walker_PostExpirator_Category_Checklist extends Walker {
  1594. var $tree_type = 'category';
  1595. var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
  1596.  
  1597. var $disabled = '';
  1598.  
  1599. function setDisabled() {
  1600. $this->disabled = 'disabled="disabled"';
  1601. }
  1602.  
  1603. function start_lvl(&$output, $depth = 0, $args = array()) {
  1604. $indent = str_repeat("\t", $depth);
  1605. $output .= "$indent<ul class='children'>\n";
  1606. }
  1607.  
  1608. function end_lvl(&$output, $depth = 0, $args = array()) {
  1609. $indent = str_repeat("\t", $depth);
  1610. $output .= "$indent</ul>\n";
  1611. }
  1612.  
  1613. function start_el(&$output, $category, $depth = 0, $args = array(), $current_object_id = 0) {
  1614. extract($args);
  1615. if ( empty($taxonomy) )
  1616. $taxonomy = 'category';
  1617.  
  1618. $name = 'expirationdate_category';
  1619.  
  1620. $class = in_array( $category->term_id, $popular_cats ) ? ' class="expirator-category"' : '';
  1621. $output .= "\n<li id='expirator-{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="expirator-in-'.$taxonomy.'-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' '.$this->disabled.'/> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
  1622. }
  1623.  
  1624. function end_el(&$output, $category, $depth = 0, $args = array()) {
  1625. $output .= "</li>\n";
  1626. }
  1627. }
  1628.  
  1629. function _postExpiratorExpireType($opts) {
  1630. if (empty($opts)) return false;
  1631.  
  1632. extract($opts);
  1633. if (!isset($name)) return false;
  1634. if (!isset($id)) $id = $name;
  1635. if (!isset($disabled)) $disabled = false;
  1636. if (!isset($onchange)) $onchange = '';
  1637. if (!isset($type)) $type = '';
  1638.  
  1639. $rv = array();
  1640. $rv[] = '<select name="'.$name.'" id="'.$id.'"'.($disabled == true ? ' disabled="disabled"' : '').' onchange="'.$onchange.'">';
  1641. $rv[] = '<option value="draft" '. ($selected == 'draft' ? 'selected="selected"' : '') . '>'.__('Draft','post-expirator').'</option>';
  1642. $rv[] = '<option value="delete" '. ($selected == 'delete' ? 'selected="selected"' : '') . '>'.__('Delete','post-expirator').'</option>';
  1643. $rv[] = '<option value="trash" '. ($selected == 'trash' ? 'selected="selected"' : '') . '>'.__('Trash','post-expirator').'</option>';
  1644. $rv[] = '<option value="private" '. ($selected == 'private' ? 'selected="selected"' : '') . '>'.__('Private','post-expirator').'</option>';
  1645. $rv[] = '<option value="stick" '. ($selected == 'stick' ? 'selected="selected"' : '') . '>'.__('Stick','post-expirator').'</option>';
  1646. $rv[] = '<option value="unstick" '. ($selected == 'unstick' ? 'selected="selected"' : '') . '>'.__('Unstick','post-expirator').'</option>';
  1647. if ($type != 'page') {
  1648. $rv[] = '<option value="category" '. ($selected == 'category' ? 'selected="selected"' : '') . '>'.__('Category: Replace','post-expirator').'</option>';
  1649. $rv[] = '<option value="category-add" '. ($selected == 'category-add' ? 'selected="selected"' : '') . '>'.__('Category: Add','post-expirator').'</option>';
  1650. $rv[] = '<option value="category-remove" '. ($selected == 'category-remove' ? 'selected="selected"' : '') . '>'.__('Category: Remove','post-expirator').'</option>';
  1651. }
  1652. $rv[] = '</select>';
  1653. return implode("<br/>\n",$rv);
  1654. }
  1655.  
  1656. function _postExpiratorTaxonomy($opts) {
  1657. if (empty($opts)) return false;
  1658.  
  1659. extract($opts);
  1660. if (!isset($name)) return false;
  1661. if (!isset($id)) $id = $name;
  1662. if (!isset($disabled)) $disabled = false;
  1663. if (!isset($onchange)) $onchange = '';
  1664. if (!isset($type)) $type = '';
  1665.  
  1666. $taxonomies = get_object_taxonomies($type,'object');
  1667. $taxonomies = wp_filter_object_list($taxonomies, array('hierarchical' => true));
  1668.  
  1669. if (empty($taxonomies)) $disabled = true;
  1670.  
  1671. $rv = array();
  1672. if ($taxonomies) {
  1673. $rv[] = '<select name="'.$name.'" id="'.$id.'"'.($disabled == true ? ' disabled="disabled"' : '').' onchange="'.$onchange.'">';
  1674. foreach ($taxonomies as $taxonomy) {
  1675. $rv[] = '<option value="'.$taxonomy->name.'" '. ($selected == $taxonomy->name ? 'selected="selected"' : '') . '>'.$taxonomy->name.'</option>';
  1676. }
  1677.  
  1678. $rv[] = '</select>';
  1679. $rv[] = __('Select the hierarchical taxonomy to be used for "category" based expiration.','post-expirator');
  1680. } else {
  1681. $rv[] = 'No taxonomies found for post type.';
  1682. }
  1683. return implode("<br/>\n",$rv);
  1684. }
  1685.  
  1686. add_action( 'admin_print_scripts-edit.php', 'expirationdate_quickedit_javascript' );
  1687. function expirationdate_quickedit_javascript() {
  1688. // if using code as plugin
  1689. wp_enqueue_script( 'manage-wp-posts-using-bulk-quick-edit', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'admin-edit.js', array( 'jquery', 'inline-edit-post' ), '', true );
  1690.  
  1691. }
  1692.  
  1693. /**
  1694. * Receieve AJAX call from bulk edit to process save
  1695. */
  1696. add_action( 'wp_ajax_manage_wp_posts_using_bulk_quick_save_bulk_edit', 'expiration_date_save_bulk_edit' );
  1697. function expiration_date_save_bulk_edit() {
  1698. // we need the post IDs
  1699. $post_ids = ( isset( $_POST[ 'post_ids' ] ) && !empty( $_POST[ 'post_ids' ] ) ) ? $_POST[ 'post_ids' ] : NULL;
  1700.  
  1701. // if we have post IDs
  1702. if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
  1703.  
  1704. // if no change, do nothing
  1705. if ($_POST['expirationdate_month'] == "false") return;
  1706.  
  1707. $month = intval($_POST['expirationdate_month']);
  1708. $day = intval($_POST['expirationdate_day']);
  1709. $year = intval($_POST['expirationdate_year']);
  1710. $hour = intval($_POST['expirationdate_hour']);
  1711. $minute = intval($_POST['expirationdate_minute']);
  1712. $ts = get_gmt_from_date("$year-$month-$day $hour:$minute:0",'U');
  1713.  
  1714. foreach( $post_ids as $post_id ) {
  1715. // Only update posts that already have expiration date set. Ignore Others
  1716. $ed = get_post_meta($post_id,'_expiration-date',true);
  1717. if ($ed) {
  1718. $opts = get_post_meta($post_id, '_expiration-date-options', true);
  1719. #_scheduleExpiratorEvent($post_id,$ts,$opts);
  1720. }
  1721. }
  1722. }
  1723. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement