Advertisement
Guest User

Untitled

a guest
Nov 26th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 58.85 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Post Expirator
  4. Plugin URI: http://wordpress.org/extend/plugins/post-expirator/
  5. 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.
  6. Author: Aaron Axelsen
  7. Version: 2.1.4
  8. Author URI: http://postexpirator.tuxdocs.net/
  9. Translation: Thierry (http://palijn.info)
  10. Text Domain: post-expirator
  11. */
  12.  
  13. /* Load translation, if it exists */
  14. function postExpirator_init() {
  15.     $plugin_dir = basename(dirname(__FILE__));
  16.     load_plugin_textdomain( 'post-expirator', null, $plugin_dir.'/languages/' );
  17. }
  18. add_action('plugins_loaded', 'postExpirator_init');
  19.  
  20. // Default Values
  21. define('POSTEXPIRATOR_VERSION','2.1.1');
  22. define('POSTEXPIRATOR_DATEFORMAT',__('l F jS, Y','post-expirator'));
  23. define('POSTEXPIRATOR_TIMEFORMAT',__('g:ia','post-expirator'));
  24. define('POSTEXPIRATOR_FOOTERCONTENTS',__('Post expires at EXPIRATIONTIME on EXPIRATIONDATE','post-expirator'));
  25. define('POSTEXPIRATOR_FOOTERSTYLE','font-style: italic;');
  26. define('POSTEXPIRATOR_FOOTERDISPLAY','0');
  27. define('POSTEXPIRATOR_DEBUGDEFAULT','0');
  28. define('POSTEXPIRATOR_EXPIREDEFAULT','null');
  29.  
  30. function postExpirator_plugin_action_links($links, $file) {
  31.     $this_plugin = basename(plugin_dir_url(__FILE__)) . '/post-expirator.php';
  32.     if($file == $this_plugin) {
  33.         $links[] = '<a href="options-general.php?page=post-expirator">' . __('Settings', 'post-expirator') . '</a>';
  34.     }
  35.     return $links;
  36. }
  37. add_filter('plugin_action_links', 'postExpirator_plugin_action_links', 10, 2);
  38.  
  39. /**
  40.  * Add admin notice hook if cron schedule needs to be reset
  41.  */
  42. function postExpirationAdminNotice() {
  43.     // Currently not used
  44. }
  45. add_action('admin_notices','postExpirationAdminNotice');
  46.  
  47. /**
  48.  * adds an 'Expires' column to the post display table.
  49.  */
  50. function expirationdate_add_column ($columns,$type) {
  51.     $defaults = get_option('expirationdateDefaults'.ucfirst($type));
  52.     if (!isset($defaults['activeMetaBox']) || $defaults['activeMetaBox'] == 'active') {
  53.         $columns['expirationdate'] = __('Expires','post-expirator');
  54.     }
  55.     return $columns;
  56. }
  57. add_filter ('manage_posts_columns', 'expirationdate_add_column', 10, 2);
  58.  
  59. /**
  60.  * adds an 'Expires' column to the page display table.
  61.  */
  62. function expirationdate_add_column_page ($columns) {
  63.     $defaults = get_option('expirationdateDefaultsPage');
  64.     if (!isset($defaults['activeMetaBox']) || $defaults['activeMetaBox'] == 'active') {
  65.         $columns['expirationdate'] = __('Expires','post-expirator');
  66.     }
  67.     return $columns;
  68. }
  69. add_filter ('manage_pages_columns', 'expirationdate_add_column_page');
  70.  
  71. /**
  72.  * fills the 'Expires' column of the post display table.
  73.  */
  74. function expirationdate_show_value ($column_name) {
  75.     global $post;
  76.     $id = $post->ID;
  77.     if ($column_name === 'expirationdate') {
  78.         $ed = get_post_meta($id,'_expiration-date',true);
  79.             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'));
  80.     }
  81. }
  82. add_action ('manage_posts_custom_column', 'expirationdate_show_value');
  83. add_action ('manage_pages_custom_column', 'expirationdate_show_value');
  84.  
  85. /**
  86.  * Adds hooks to get the meta box added to pages and custom post types
  87.  */
  88. function expirationdate_meta_custom() {
  89.     $custom_post_types = get_post_types();
  90.     array_push($custom_post_types,'page');
  91.     foreach ($custom_post_types as $t) {
  92.         $defaults = get_option('expirationdateDefaults'.ucfirst($t));
  93.         if (!isset($defaults['activeMetaBox']) || $defaults['activeMetaBox'] == 'active') {
  94.             add_meta_box('expirationdatediv', __('Post Expirator','post-expirator'), 'expirationdate_meta_box', $t, 'side', 'core');
  95.         }
  96.     }
  97. }
  98. add_action ('add_meta_boxes','expirationdate_meta_custom');
  99.  
  100. /**
  101.  * Actually adds the meta box
  102.  */
  103. function expirationdate_meta_box($post) {
  104.     // Get default month
  105.     $expirationdatets = get_post_meta($post->ID,'_expiration-date',true);
  106.     $firstsave = get_post_meta($post->ID,'_expiration-date-status',true);
  107.     $default = '';
  108.     $expireType = '';
  109.     $defaults = get_option('expirationdateDefaults'.ucfirst($post->post_type));
  110.     if (empty($expirationdatets)) {
  111.         $default = get_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
  112.         if ($default == 'null') {
  113.             $defaultmonth   =   date_i18n('m');
  114.             $defaultday     =   date_i18n('d');
  115.             $defaulthour    =   date_i18n('H');
  116.             $defaultyear    =   date_i18n('Y');
  117.             $defaultminute  =   date_i18n('i');
  118.  
  119.         } elseif ($default == 'custom') {
  120.             $custom = get_option('expirationdateDefaultDateCustom');
  121.             if ($custom === false) $ts = time();
  122.             else {
  123.                 $tz = get_option('timezone_string');
  124.                 if ( $tz ) date_default_timezone_set( $tz );
  125.                
  126.                 $ts = time() + (strtotime($custom) - time());
  127.                
  128.                 if ( $tz ) date_default_timezone_set('UTC');
  129.             }
  130.             $defaultmonth   =   get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'m');
  131.             $defaultday     =   get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'d');
  132.             $defaultyear    =   get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'Y');;
  133.             $defaulthour    =   get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'H');
  134.             $defaultminute  =   get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'i');
  135.         }
  136.  
  137.         $enabled = '';
  138.         $disabled = ' disabled="disabled"';
  139.         $categories = get_option('expirationdateCategoryDefaults');
  140.  
  141.         if (isset($defaults['expireType'])) {
  142.             $expireType = $defaults['expireType'];
  143.         }
  144.  
  145.         if (isset($defaults['autoEnable']) && ($firstsave !== 'saved') && ($defaults['autoEnable'] === true || $defaults['autoEnable'] == 1)) {
  146.             $enabled = ' checked="checked"';
  147.             $disabled='';
  148.         }
  149.     } else {
  150.         $defaultmonth   =   get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'m');
  151.         $defaultday     =   get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'d');
  152.         $defaultyear    =   get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'Y');
  153.         $defaulthour    =   get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'H');
  154.         $defaultminute  =   get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'i');
  155.         $enabled    =   ' checked="checked"';
  156.         $disabled   =   '';
  157.         $opts       =   get_post_meta($post->ID,'_expiration-date-options',true);
  158.         if (isset($opts['expireType'])) {
  159.                     $expireType = $opts['expireType'];
  160.         }
  161.         $categories = isset($opts['category']) ? $opts['category'] : false;
  162.     }
  163.  
  164.     $rv = array();
  165.     $rv[] = '<p><input type="checkbox" name="enable-expirationdate" id="enable-expirationdate" value="checked"'.$enabled.' onclick="expirationdate_ajax_add_meta(\'enable-expirationdate\')" />';
  166.     $rv[] = '<label for="enable-expirationdate">'.__('Enable Post Expiration','post-expirator').'</label></p>';
  167.  
  168.     if ($default == 'publish') {
  169.         $rv[] = '<em>'.__('The published date/time will be used as the expiration value','post-expirator').'</em><br/>';
  170.     } else {
  171.         $rv[] = '<table><tr>';
  172.         $rv[] = '<th style="text-align: left;">'.__('Year','post-expirator').'</th>';
  173.         $rv[] = '<th style="text-align: left;">'.__('Month','post-expirator').'</th>';
  174.         $rv[] = '<th style="text-align: left;">'.__('Day','post-expirator').'</th>';
  175.         $rv[] = '</tr><tr>';
  176.         $rv[] = '<td>';
  177.         $rv[] = '<select name="expirationdate_year" id="expirationdate_year"'.$disabled.'>';
  178.         $currentyear = date('Y');
  179.    
  180.         if ($defaultyear < $currentyear) $currentyear = $defaultyear;
  181.  
  182.         for($i = $currentyear; $i < $currentyear + 8; $i++) {
  183.             if ($i == $defaultyear)
  184.                 $selected = ' selected="selected"';
  185.             else
  186.                 $selected = '';
  187.             $rv[] = '<option'.$selected.'>'.($i).'</option>';
  188.         }
  189.         $rv[] = '</select>';
  190.         $rv[] = '</td><td>';
  191.         $rv[] = '<select name="expirationdate_month" id="expirationdate_month"'.$disabled.'>';
  192.  
  193.         for($i = 1; $i <= 12; $i++) {
  194.             if ($defaultmonth == date_i18n('m',mktime(0, 0, 0, $i, 1, date_i18n('Y'))))
  195.                 $selected = ' selected="selected"';
  196.             else
  197.                 $selected = '';
  198.             $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>';
  199.         }
  200.  
  201.         $rv[] = '</select>';     
  202.         $rv[] = '</td><td>';
  203.         $rv[] = '<input type="text" id="expirationdate_day" name="expirationdate_day" value="'.$defaultday.'" size="2"'.$disabled.' />,';
  204.         $rv[] = '</td></tr><tr>';
  205.         $rv[] = '<th style="text-align: left;"></th>';
  206.         $rv[] = '<th style="text-align: left;">'.__('Hour','post-expirator').'('.date_i18n('T',mktime(0, 0, 0, $i, 1, date_i18n('Y'))).')</th>';
  207.         $rv[] = '<th style="text-align: left;">'.__('Minute','post-expirator').'</th>';
  208.         $rv[] = '</tr><tr>';
  209.         $rv[] = '<td>@</td><td>';
  210.         $rv[] = '<select name="expirationdate_hour" id="expirationdate_hour"'.$disabled.'>';
  211.  
  212.         for($i = 1; $i <= 24; $i++) {
  213.             if ($defaulthour == date_i18n('H',mktime($i, 0, 0, date_i18n('n'), date_i18n('j'), date_i18n('Y'))))
  214.                 $selected = ' selected="selected"';
  215.             else
  216.                 $selected = '';
  217.             $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>';
  218.         }
  219.  
  220.         $rv[] = '</select></td><td>';
  221.         $rv[] = '<input type="text" id="expirationdate_minute" name="expirationdate_minute" value="'.$defaultminute.'" size="2"'.$disabled.' />';
  222.         $rv[] = '</td></tr></table>';
  223.     }
  224.     $rv[] = '<input type="hidden" name="expirationdate_formcheck" value="true" />';
  225.     echo implode("\n",$rv);
  226.  
  227.     echo '<br/>'.__('How to expire','post-expirator').': ';
  228.     echo _postExpiratorExpireType(array('type' => $post->post_type, 'name'=>'expirationdate_expiretype','selected'=>$expireType,'disabled'=>$disabled,'onchange' => 'expirationdate_toggle_category(this)'));
  229.     echo '<br/>';
  230.  
  231.     if ($post->post_type != 'page') {
  232.         //if (isset($expireType) && ($expireType == 'category' || $expireType == 'category-add' || $expireType == 'category-remove')) {
  233.         //  $catdisplay = 'block';
  234.         //} else {
  235.             $catdisplay = 'none';
  236.         //}
  237.         echo '<div id="expired-category-selection" style="display: '.$catdisplay.'">';
  238.         echo '<br/>'.__('Expiration Categories','post-expirator').':<br/>';
  239.  
  240.         echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
  241.         echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
  242.         $walker = new Walker_PostExpirator_Category_Checklist();
  243.         if (!empty($disabled)) $walker->setDisabled();
  244.         $taxonomies = get_object_taxonomies($post->post_type,'object');
  245.             $taxonomies = wp_filter_object_list($taxonomies, array('hierarchical' => true));
  246.         if (sizeof($taxonomies) == 0) {
  247.             echo '<p>'.__('You must assign a heirarchical taxonomy to this post type to use this feature.','post-expirator').'</p>';
  248.         } elseif (sizeof($taxonomies) > 1 && !isset($defaults['taxonomy'])) {
  249.             echo '<p>'.__('More than 1 heirachical taxonomy detected.  You must assign a default taxonomy on the settings screen.','post-expirator').'</p>';
  250.         } else {
  251.             $keys = array_keys($taxonomies);
  252.             $taxonomy = isset($defaults['taxonomy']) ? $defaults['taxonomy'] : $keys[0];
  253.             wp_terms_checklist(0, array( 'taxonomy' => $taxonomy, 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );
  254.             echo '<input type="hidden" name="taxonomy-heirarchical" value="'.$taxonomy.'" />';
  255.         }
  256.         echo '</ul>';
  257.         echo '</div>';
  258.         if (isset($taxonomy))
  259.         echo '<p class="post-expirator-taxonomy-name">'.__('Taxonomy Name','post-expirator').': '.$taxonomy.'</p>';
  260.         echo '</div>';
  261.     }
  262.     echo '<div id="expirationdate_ajax_result"></div>';
  263. }
  264.  
  265. /**
  266.  * Add's ajax javascript
  267.  */
  268. function expirationdate_js_admin_header() {
  269.     // Define custom JavaScript function
  270.     ?>
  271. <script type="text/javascript">
  272. //<![CDATA[
  273. function expirationdate_ajax_add_meta(expireenable) {
  274.     var expire = document.getElementById(expireenable);
  275.  
  276.     if (expire.checked == true) {
  277.         var enable = 'true';
  278.         if (document.getElementById('expirationdate_month')) {
  279.             document.getElementById('expirationdate_month').disabled = false;
  280.             document.getElementById('expirationdate_day').disabled = false;
  281.             document.getElementById('expirationdate_year').disabled = false;
  282.             document.getElementById('expirationdate_hour').disabled = false;
  283.             document.getElementById('expirationdate_minute').disabled = false;
  284.         }
  285.         document.getElementById('expirationdate_expiretype').disabled = false;
  286.         var cats = document.getElementsByName('expirationdate_category[]');
  287.         var max = cats.length;
  288.         for (var i=0; i<max; i++) {
  289.             cats[i].disabled = '';
  290.         }
  291.     } else {
  292.         if (document.getElementById('expirationdate_month')) {
  293.             document.getElementById('expirationdate_month').disabled = true;
  294.             document.getElementById('expirationdate_day').disabled = true;
  295.             document.getElementById('expirationdate_year').disabled = true;
  296.             document.getElementById('expirationdate_hour').disabled = true;
  297.             document.getElementById('expirationdate_minute').disabled = true;
  298.         }
  299.         document.getElementById('expirationdate_expiretype').disabled = true;
  300.         var cats = document.getElementsByName('expirationdate_category[]');
  301.         var max = cats.length;
  302.         for (var i=0; i<max; i++) {
  303.             cats[i].disabled = 'disable';
  304.         }
  305.         var enable = 'false';
  306.     }
  307.    
  308.     return true;
  309. }
  310. function expirationdate_toggle_category(id) {
  311.     if (id.options[id.selectedIndex].value == 'category') {
  312.         jQuery('#expired-category-selection').show();
  313.     } else if (id.options[id.selectedIndex].value == 'category-add') {
  314.         jQuery('#expired-category-selection').show(); //TEMP   
  315.     } else if (id.options[id.selectedIndex].value == 'category-remove') {
  316.         jQuery('#expired-category-selection').show(); //TEMP
  317.     } else {
  318.         jQuery('#expired-category-selection').hide();
  319.     }
  320. }
  321. function expirationdate_toggle_defaultdate(id) {
  322.     if (id.options[id.selectedIndex].value == 'custom') {
  323.         jQuery('#expired-custom-container').show();
  324.     } else {
  325.         jQuery('#expired-custom-container').hide();
  326.     }
  327.  
  328. }
  329. //]]>
  330. </script>
  331. <?php
  332. }
  333. add_action('admin_head', 'expirationdate_js_admin_header' );
  334.  
  335. /**
  336.  * Get correct URL (HTTP or HTTPS)
  337.  */
  338. function expirationdate_get_blog_url() {
  339.     if (is_multisite())
  340.         echo network_home_url('/');
  341.     else
  342.             echo home_url('/');
  343. }
  344.  
  345. /**
  346.  * Called when post is saved - stores expiration-date meta value
  347.  */
  348. function expirationdate_update_post_meta($id) {
  349.     // don't run the echo if this is an auto save
  350.     if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
  351.         return;
  352.  
  353.     // don't run the echo if the function is called for saving revision.
  354.         $posttype = get_post_type($id);
  355.     if ( $posttype == 'revision' )
  356.         return;
  357.  
  358.     if (!isset($_POST['expirationdate_formcheck']))
  359.         return;
  360.  
  361.     if (isset($_POST['enable-expirationdate'])) {
  362.             $default = get_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
  363.         if ($default == 'publish') {
  364.                 $month   = intval($_POST['mm']);
  365.                 $day     = intval($_POST['jj']);
  366.                 $year    = intval($_POST['aa']);
  367.                 $hour    = intval($_POST['hh']);
  368.                 $minute  = intval($_POST['mn']);
  369.         } else {
  370.                 $month   = intval($_POST['expirationdate_month']);
  371.                 $day     = intval($_POST['expirationdate_day']);
  372.                 $year    = intval($_POST['expirationdate_year']);
  373.                 $hour    = intval($_POST['expirationdate_hour']);
  374.                 $minute  = intval($_POST['expirationdate_minute']);
  375.         }
  376.         $category = isset($_POST['expirationdate_category']) ? $_POST['expirationdate_category'] : 0;
  377.  
  378.         $opts = array();
  379.         $ts = get_gmt_from_date("$year-$month-$day $hour:$minute:0",'U');
  380.  
  381.         // Schedule/Update Expiration
  382.         $opts['expireType'] = $_POST['expirationdate_expiretype'];
  383.         $opts['id'] = $id;
  384.  
  385.         if ($opts['expireType'] == 'category' || $opts['expireType'] == 'category-add' || $opts['expireType'] == 'category-remove') {
  386.                 if (isset($category) && !empty($category)) {
  387.                 if (!empty($category)) {
  388.                     $opts['category'] = $category;
  389.                     $opts['categoryTaxonomy'] = $_POST['taxonomy-heirarchical'];
  390.                 }
  391.             }
  392.         }
  393.    
  394.         _scheduleExpiratorEvent($id,$ts,$opts);
  395.     } else {
  396.         _unscheduleExpiratorEvent($id);
  397.     }
  398. }
  399. add_action('save_post','expirationdate_update_post_meta');
  400.  
  401. function _scheduleExpiratorEvent($id,$ts,$opts) {
  402.         $debug = postExpiratorDebug(); //check for/load debug
  403.  
  404.     if (wp_next_scheduled('postExpiratorExpire',array($id)) !== false) {
  405.         wp_clear_scheduled_hook('postExpiratorExpire',array($id)); //Remove any existing hooks
  406.         if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> EXISTING FOUND - UNSCHEDULED'));
  407.     }
  408.        
  409.     wp_schedule_single_event($ts,'postExpiratorExpire',array($id));
  410.     if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> SCHEDULED at '.date_i18n('r',$ts).' '.'('.$ts.') with options '.print_r($opts,true)));
  411.  
  412.     // Update Post Meta
  413.         update_post_meta($id, '_expiration-date', $ts);
  414.         update_post_meta($id, '_expiration-date-options', $opts);
  415.     update_post_meta($id, '_expiration-date-status','saved');
  416. }
  417.  
  418. function _unscheduleExpiratorEvent($id) {
  419.         $debug = postExpiratorDebug(); // check for/load debug
  420.     delete_post_meta($id, '_expiration-date');
  421.     delete_post_meta($id, '_expiration-date-options');
  422.  
  423.     // Delete Scheduled Expiration
  424.     if (wp_next_scheduled('postExpiratorExpire',array($id)) !== false) {
  425.         wp_clear_scheduled_hook('postExpiratorExpire',array($id)); //Remove any existing hooks
  426.         if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> UNSCHEDULED'));
  427.     }
  428.     update_post_meta($id, '_expiration-date-status','saved');
  429. }
  430.  
  431. /**
  432.  * The new expiration function, to work with single scheduled events.
  433.  *
  434.  * This was designed to hopefully be more flexible for future tweaks/modifications to the architecture.
  435.  *
  436.  * @param array $opts - options to pass into the expiration process, in key/value format
  437.  */
  438. function postExpiratorExpire($id) {
  439.         $debug = postExpiratorDebug(); //check for/load debug
  440.  
  441.     if (empty($id)) {
  442.         if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => 'No Post ID found - exiting'));
  443.         return false;
  444.     }
  445.  
  446.     if (is_null(get_post($id))) {
  447.         if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> Post does not exist - exiting'));
  448.         return false;
  449.     }
  450.  
  451.     $postoptions = get_post_meta($id,'_expiration-date-options',true);
  452.     extract($postoptions);
  453.  
  454.     // Check for default expire only if not passed in
  455.     if (empty($expireType)) {
  456.         $posttype = get_post_type($id);
  457.         if ($posttype == 'page') {
  458.             $expireType = strtolower(get_option('expirationdateExpiredPageStatus',POSTEXPIRATOR_PAGESTATUS));
  459.         } elseif ($posttype == 'post') {
  460.             $expireType = strtolower(get_option('expirationdateExpiredPostStatus','Draft'));
  461.         } else {
  462.             $expireType = apply_filters('postexpirator_custom_posttype_expire', $expireType, $posttype); //hook to set defaults for custom post types
  463.         }
  464.     }
  465.  
  466.     // Remove KSES - wp_cron runs as an unauthenticated user, which will by default trigger kses filtering,
  467.     // even if the post was published by a admin user.  It is fairly safe here to remove the filter call since
  468.     // we are only changing the post status/meta information and not touching the content.
  469.     kses_remove_filters();
  470.  
  471.     // Do Work
  472.     if ($expireType == 'draft') {
  473.         if (wp_update_post(array('ID' => $id, 'post_status' => 'draft')) == 0) {
  474.             if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  475.         } else {
  476.             if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  477.         }
  478.     } elseif ($expireType == 'private') {
  479.         if (wp_update_post(array('ID' => $id, 'post_status' => 'private')) == 0) {
  480.             if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  481.         } else {
  482.             if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  483.         }
  484.     } elseif ($expireType == 'delete') {
  485.         if (wp_delete_post($id) === false) {
  486.             if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  487.         } else {
  488.             if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  489.         }
  490.     } elseif ($expireType == 'category') {
  491.         if (!empty($category)) {
  492.             if (!isset($categoryTaxonomy) || $categoryTaxonomy == 'category') {
  493.                 if (wp_update_post(array('ID' => $id, 'post_category' => $category)) == 0) {
  494.                     if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  495.                 } else {
  496.                     if (POSTEXPIRATOR_DEBUG) {
  497.                         $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  498.                         $debug->save(array('message' => $id.' -> CATEGORIES REPLACED '.print_r(_postExpiratorGetCatNames($category),true)));
  499.                         $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
  500.                     }
  501.                 }
  502.             } else {
  503.                 $terms = array_map('intval', $category);
  504.                 if (is_wp_error(wp_set_object_terms($id,$terms,$categoryTaxonomy,false))) {
  505.                     if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  506.                 } else {
  507.                     if (POSTEXPIRATOR_DEBUG) {
  508.                         $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  509.                         $debug->save(array('message' => $id.' -> CATEGORIES REPLACED '.print_r(_postExpiratorGetCatNames($category),true)));
  510.                         $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
  511.                     }
  512.                 }
  513.             }
  514.         } else {
  515.             if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> CATEGORIES MISSING '.$expireType.' '.print_r($postoptions,true)));
  516.         }
  517.     } elseif ($expireType == 'category-add') {
  518.         if (!empty($category)) {
  519.             if (!isset($categoryTaxonomy) || $categoryTaxonomy == 'category') {
  520.                 $cats = wp_get_post_categories($id);
  521.                 $merged = array_merge($cats,$category);
  522.                 if (wp_update_post(array('ID' => $id, 'post_category' => $merged)) == 0) {
  523.                     if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  524.                 } else {
  525.                     if (POSTEXPIRATOR_DEBUG) {
  526.                         $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  527.                         $debug->save(array('message' => $id.' -> CATEGORIES ADDED '.print_r(_postExpiratorGetCatNames($category),true)));
  528.                         $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($merged),true)));
  529.                     }
  530.                 }
  531.             } else {
  532.                 $terms = array_map('intval', $category);
  533.                 if (is_wp_error(wp_set_object_terms($id,$terms,$categoryTaxonomy,true))) {
  534.                     if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
  535.                 } else {
  536.                     if (POSTEXPIRATOR_DEBUG) {
  537.                         $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
  538.                         $debug->save(array('message' => $id.' -> CATEGORIES ADDED '.print_r(_postExpiratorGetCatNames($category),true)));
  539.                         $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
  540.                     }
  541.                 }              
  542.             }
  543.         } else {
  544.             if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> CATEGORIES MISSING '.$expireType.' '.print_r($postoptions,true)));
  545.         }
  546.     } elseif ($expireType == 'category-remove') {
  547.         $tag = "registration closed";
  548.         wp_set_object_terms( $id, array($tag), 'post_tag', false );        
  549.     }
  550. }
  551. add_action('postExpiratorExpire','postExpiratorExpire');
  552.  
  553. function _postExpiratorGetCatNames($cats) {
  554.     $out = array();
  555.     foreach ($cats as $cat) {
  556.         $out[$cat] = get_the_category_by_id($cat);
  557.     }
  558.     return $out;
  559. }  
  560.  
  561. /**
  562.  * Build the menu for the options page
  563.  */
  564. function postExpiratorMenuTabs($tab) {
  565.         echo '<p>';
  566.     if (empty($tab)) $tab = 'general';
  567.         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> | ';
  568.         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> | ';
  569.         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> | ';
  570.     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>';
  571.         echo '</p><hr/>';
  572. }
  573.  
  574. /**
  575.  *
  576.  */
  577. function postExpiratorMenu() {
  578.         $tab = isset($_GET['tab']) ? $_GET['tab'] : '';
  579.  
  580.     echo '<div class="wrap">';
  581.         echo '<h2>'.__('Post Expirator Options','post-expirator').'</h2>';
  582.  
  583.     postExpiratorMenuTabs($tab);
  584.     if (empty($tab) || $tab == 'general') {
  585.         postExpiratorMenuGeneral();
  586.     } elseif ($tab == 'defaults') {
  587.         postExpiratorMenuDefaults();
  588.     } elseif ($tab == 'diagnostics') {
  589.         postExpiratorMenuDiagnostics();
  590.     } elseif ($tab == 'viewdebug') {
  591.         postExpiratorMenuViewdebug();
  592.     }
  593.     echo '</div>';
  594. }
  595.  
  596. /**
  597.  * Hook's to add plugin page menu
  598.  */
  599. function postExpiratorPluginMenu() {
  600.     add_submenu_page('options-general.php',__('Post Expirator Options','post-expirator'),__('Post Expirator','post-expirator'),'manage_options',basename(__FILE__),'postExpiratorMenu');
  601. }
  602. add_action('admin_menu', 'postExpiratorPluginMenu');
  603.  
  604. /**
  605.  * Show the Expiration Date options page
  606.  */
  607. function postExpiratorMenuGeneral() {
  608.     if (isset($_POST['expirationdateSave']) && $_POST['expirationdateSave']) {
  609.         if ( !isset($_POST['_postExpiratorMenuGeneral_nonce']) || !wp_verify_nonce($_POST['_postExpiratorMenuGeneral_nonce'],'postExpiratorMenuGeneral') ) {
  610.             print 'Form Validation Failure: Sorry, your nonce did not verify.';
  611.             exit;
  612.         } else {
  613.             //Filter Content
  614.             $_POST = filter_input_array(INPUT_POST,FILTER_SANITIZE_STRING);
  615.  
  616.             update_option('expirationdateDefaultDateFormat',$_POST['expired-default-date-format']);
  617.             update_option('expirationdateDefaultTimeFormat',$_POST['expired-default-time-format']);
  618.             update_option('expirationdateDisplayFooter',$_POST['expired-display-footer']);
  619.             update_option('expirationdateFooterContents',$_POST['expired-footer-contents']);
  620.             update_option('expirationdateFooterStyle',$_POST['expired-footer-style']);
  621.             if (isset($_POST['expirationdate_category'])) update_option('expirationdateCategoryDefaults',$_POST['expirationdate_category']);
  622.             update_option('expirationdateDefaultDate',$_POST['expired-default-expiration-date']);
  623.             if ($_POST['expired-custom-expiration-date']) update_option('expirationdateDefaultDateCustom',$_POST['expired-custom-expiration-date']);
  624.                     echo "<div id='message' class='updated fade'><p>";
  625.                     _e('Saved Options!','post-expirator');
  626.                     echo "</p></div>";
  627.         }
  628.     }
  629.  
  630.     // Get Option
  631.     $expirationdateDefaultDateFormat = get_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT);
  632.     $expirationdateDefaultTimeFormat = get_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT);
  633.     $expireddisplayfooter = get_option('expirationdateDisplayFooter',POSTEXPIRATOR_FOOTERDISPLAY);
  634.     $expirationdateFooterContents = get_option('expirationdateFooterContents',POSTEXPIRATOR_FOOTERCONTENTS);
  635.     $expirationdateFooterStyle = get_option('expirationdateFooterStyle',POSTEXPIRATOR_FOOTERSTYLE);
  636.     $expirationdateDefaultDate = get_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
  637.     $expirationdateDefaultDateCustom = get_option('expirationdateDefaultDateCustom');
  638.  
  639.     $categories = get_option('expirationdateCategoryDefaults');
  640.  
  641.     $expireddisplayfooterenabled = '';
  642.     $expireddisplayfooterdisabled = '';
  643.     if ($expireddisplayfooter == 0)
  644.         $expireddisplayfooterdisabled = 'checked="checked"';
  645.     else if ($expireddisplayfooter == 1)
  646.         $expireddisplayfooterenabled = 'checked="checked"';
  647.     ?>
  648.     <p>
  649.     <?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'); ?>
  650.     </p>
  651.     <p>
  652.     <?php _e('Valid [postexpirator] attributes:','post-expirator'); ?>
  653.     <ul>
  654.         <li><?php _e('type - defaults to full - valid options are full,date,time','post-expirator');?></li>
  655.         <li><?php _e('dateformat - format set here will override the value set on the settings page','post-expirator');?></li>
  656.         <li><?php _e('timeformat - format set here will override the value set on the settings page','post-expirator');?></li>
  657.     </ul>
  658.     </p>
  659.     <form method="post" id="expirationdate_save_options">
  660.         <?php wp_nonce_field('postExpiratorMenuGeneral','_postExpiratorMenuGeneral_nonce'); ?>
  661.         <h3><?php _e('Defaults','post-expirator'); ?></h3>
  662.         <table class="form-table">
  663.             <tr valign-"top">
  664.                 <th scope="row"><label for="expired-default-date-format"><?php _e('Date Format:','post-expirator');?></label></th>
  665.                 <td>
  666.                     <input type="text" name="expired-default-date-format" id="expired-default-date-format" value="<?php echo $expirationdateDefaultDateFormat ?>" size="25" /> (<?php echo date_i18n("$expirationdateDefaultDateFormat") ?>)
  667.                     <br/>
  668.                     <?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'); ?>
  669.                 </td>
  670.             </tr>
  671.             <tr valign-"top">
  672.                 <th scope="row"><label for="expired-default-time-format"><?php _e('Time Format:','post-expirator');?></label></th>
  673.                 <td>
  674.                     <input type="text" name="expired-default-time-format" id="expired-default-time-format" value="<?php echo $expirationdateDefaultTimeFormat ?>" size="25" /> (<?php echo date_i18n("$expirationdateDefaultTimeFormat") ?>)
  675.                     <br/>
  676.                     <?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'); ?>
  677.                 </td>
  678.             </tr>
  679.             <tr valign-"top">
  680.                 <th scope="row"><label for="expired-default-expiration-date"><?php _e('Default Date/Time Duration:','post-expirator');?></label></th>
  681.                 <td>
  682.                     <select name="expired-default-expiration-date" id="expired-default-expiration-date" onchange="expirationdate_toggle_defaultdate(this)">
  683.                         <option value="null" <?php echo ($expirationdateDefaultDate == 'null') ? ' selected="selected"' : ''; ?>><?php _e('None','post-expirator');?></option>
  684.                         <option value="custom" <?php echo ($expirationdateDefaultDate == 'custom') ? ' selected="selected"' : ''; ?>><?php _e('Custom','post-expirator');?></option>
  685.                         <option value="publish" <?php echo ($expirationdateDefaultDate == 'publish') ? ' selected="selected"' : ''; ?>><?php _e('Post/Page Publish Time','post-expirator');?></option>
  686.                     </select>
  687.                     <br/>
  688.                     <?php _e('Set the default expiration date to be used when creating new posts and pages.  Defaults to none.','post-expirator'); ?>
  689.                     <?php $show = ($expirationdateDefaultDate == 'custom') ? 'block' : 'none'; ?>
  690.                     <div id="expired-custom-container" style="display: <?php echo $show; ?>;">
  691.                     <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" />
  692.                     <br/>
  693.                     <?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'); ?>
  694.                     </div>
  695.                 </td>
  696.             </tr>
  697.         </table>
  698.         <h3><?php _e('Category Expiration','post-expirator');?></h3>
  699.         <table class="form-table">
  700.             <tr valign-"top">
  701.                 <th scope="row"><?php _e('Default Expiration Category','post-expirator');?>:</th>
  702.                 <td>
  703.         <?php
  704.                 echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
  705.                 echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
  706.                 $walker = new Walker_PostExpirator_Category_Checklist();
  707.                 wp_terms_checklist(0, array( 'taxonomy' => 'category', 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );
  708.                 echo '</ul>';
  709.                 echo '</div>';
  710.         ?>
  711.                     <br/>
  712.                     <?php _e("Set's the default expiration category for the post.",'post-expirator');?>
  713.                 </td>
  714.             </tr>
  715.         </table>
  716.  
  717.         <h3><?php _e('Post Footer Display','post-expirator');?></h3>
  718.         <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>
  719.         <table class="form-table">
  720.             <tr valign-"top">
  721.                 <th scope="row"><?php _e('Show in post footer?','post-expirator');?></th>
  722.                 <td>
  723.                     <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>
  724.                     <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>
  725.                     <br/>
  726.                     <?php _e('This will enable or disable displaying the post expiration date in the post footer.','post-expirator');?>
  727.                 </td>
  728.             </tr>
  729.             <tr valign-"top">
  730.                 <th scope="row"><label for="expired-footer-contents"><?php _e('Footer Contents:','post-expirator');?></label></th>
  731.                 <td>
  732.                     <textarea id="expired-footer-contents" name="expired-footer-contents" rows="3" cols="50"><?php echo $expirationdateFooterContents; ?></textarea>
  733.                     <br/>
  734.                     <?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');?>
  735.                     <ul>
  736.                         <li>EXPIRATIONFULL -> <?php echo date_i18n("$expirationdateDefaultDateFormat $expirationdateDefaultTimeFormat") ?></li>
  737.                         <li>EXPIRATIONDATE -> <?php echo date_i18n("$expirationdateDefaultDateFormat") ?></li>
  738.                         <li>EXPIRATIONTIME -> <?php echo date_i18n("$expirationdateDefaultTimeFormat") ?></li>
  739.                     </ul>
  740.                 </td>
  741.             </tr>
  742.             <tr valign-"top">
  743.                 <th scope="row"><label for="expired-footer-style"><?php _e('Footer Style:','post-expirator');?></label></th>
  744.                 <td>
  745.                     <input type="text" name="expired-footer-style" id="expired-footer-style" value="<?php echo $expirationdateFooterStyle ?>" size="25" />
  746.                     (<span style="<?php echo $expirationdateFooterStyle ?>"><?php _e('This post will expire on','post-expirator');?> <?php echo date_i18n("$expirationdateDefaultDateFormat $expirationdateDefaultTimeFormat"); ?></span>)
  747.                     <br/>
  748.                     <?php _e('The inline css which will be used to style the footer text.','post-expirator');?>
  749.                 </td>
  750.             </tr>
  751.         </table>
  752.         <p class="submit">
  753.             <input type="submit" name="expirationdateSave" class="button-primary" value="<?php _e('Save Changes','post-expirator');?>" />
  754.         </p>
  755.     </form>
  756.     <?php
  757. }
  758.  
  759. function postExpiratorMenuDefaults() {
  760.     $debug = postExpiratorDebug();
  761.     $types = get_post_types(array('public' => true, '_builtin' => false));
  762.     array_unshift($types,'post','page');
  763.  
  764.     if (isset($_POST['expirationdateSaveDefaults'])) {
  765.         if ( !isset($_POST['_postExpiratorMenuDefaults_nonce']) || !wp_verify_nonce($_POST['_postExpiratorMenuDefaults_nonce'],'postExpiratorMenuDefaults') ) {
  766.             print 'Form Validation Failure: Sorry, your nonce did not verify.';
  767.             exit;
  768.         } else {
  769.             //Filter Content
  770.                         $_POST = filter_input_array(INPUT_POST,FILTER_SANITIZE_STRING);
  771.  
  772.             $defaults = array();
  773.             foreach ($types as $type) {
  774.                 if (isset($_POST['expirationdate_expiretype-'.$type])) {
  775.                     $defaults[$type]['expireType'] = $_POST['expirationdate_expiretype-'.$type];
  776.                 }
  777.                 if (isset($_POST['expirationdate_autoenable-'.$type])) {
  778.                     $defaults[$type]['autoEnable'] = intval($_POST['expirationdate_autoenable-'.$type]);
  779.                 }
  780.                 if (isset($_POST['expirationdate_taxonomy-'.$type])) {
  781.                     $defaults[$type]['taxonomy'] = $_POST['expirationdate_taxonomy-'.$type];
  782.                 }
  783.                 if (isset($_POST['expirationdate_activemeta-'.$type])) {
  784.                     $defaults[$type]['activeMetaBox'] = $_POST['expirationdate_activemeta-'.$type];
  785.                 }
  786.  
  787.                 //Save Settings
  788.                         update_option('expirationdateDefaults'.ucfirst($type),$defaults[$type]);       
  789.             }
  790.                     echo "<div id='message' class='updated fade'><p>";
  791.                     _e('Saved Options!','post-expirator');
  792.                     echo "</p></div>";
  793.         }
  794.     }
  795.  
  796.     ?>
  797.         <form method="post">
  798.                 <?php wp_nonce_field('postExpiratorMenuDefaults','_postExpiratorMenuDefaults_nonce'); ?>
  799.                 <h3><?php _e('Default Expiration Values','post-expirator');?></h3>
  800.         <p>
  801.         <?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'); ?>
  802.         </p>
  803.         <?php
  804.         foreach ($types as $type) {
  805.             $defaults = get_option('expirationdateDefaults'.ucfirst($type));
  806.             if (isset($defaults['autoEnable']) && $defaults['autoEnable'] == 1) {
  807.                 $expiredautoenabled = 'checked = "checked"';
  808.                 $expiredautodisabled = '';
  809.             } else {
  810.                 $expiredautoenabled = '';
  811.                 $expiredautodisabled = 'checked = "checked"';
  812.             }
  813.             if (isset($defaults['activeMetaBox']) && $defaults['activeMetaBox'] == 'inactive') {
  814.                 $expiredactivemetaenabled = '';
  815.                 $expiredactivemetadisabled = 'checked = "checked"';
  816.             } else {
  817.                 $expiredactivemetaenabled = 'checked = "checked"';
  818.                 $expiredactivemetadisabled = '';
  819.             }
  820.             print '<h4>Expiration values for: '.$type.'</h4>';
  821.             ?>
  822.             <table class="form-table">
  823.                 <tr valign-"top">
  824.                     <th scope="row"><label for="expirationdate_activemeta-<?php echo $type ?>"><?php _e('Active:','post-expirator');?></label></th>
  825.                     <td>
  826.                         <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>
  827.                         <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>
  828.                         <br/>
  829.                         <?php _e('Select whether the post expirator meta box is active for this post type.','post-expirator');?>
  830.                     </td>
  831.                 </tr>
  832.                 <tr valign-"top">
  833.                     <th scope="row"><label for="expirationdate_expiretype-<?php echo $type ?>"><?php _e('How to expire:','post-expirator'); ?></label></th>
  834.                     <td>
  835.                         <?php echo _postExpiratorExpireType(array('name'=>'expirationdate_expiretype-'.$type,'selected' => $defaults['expireType'])); ?>
  836.                         </select>  
  837.                         <br/>
  838.                         <?php _e('Select the default expire action for the post type.','post-expirator');?>
  839.                     </td>
  840.                 </tr>
  841.                 <tr valign-"top">
  842.                     <th scope="row"><label for="expirationdate_autoenable-<?php echo $type ?>"><?php _e('Auto-Enable?','post-expirator');?></label></th>
  843.                     <td>
  844.                         <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>
  845.                         <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>
  846.                         <br/>
  847.                         <?php _e('Select whether the post expirator is enabled for all new posts.','post-expirator');?>
  848.                     </td>
  849.                 </tr>
  850.                 <tr valign-"top">
  851.                     <th scope="row"><label for="expirationdate_taxonomy-<?php echo $type ?>"><?php _e('Taxonomy (hierarchical):','post-expirator'); ?></label></th>
  852.                     <td>
  853.                         <?php echo _postExpiratorTaxonomy(array('type' => $type, 'name'=>'expirationdate_taxonomy-'.$type,'selected' => $defaults['taxonomy'])); ?>
  854.                         </select>  
  855.                         <br/>
  856.                         <?php _e('Select the hierarchical taxonomy to be used for "category" based expiration.','post-expirator');?>
  857.                     </td>
  858.                 </tr>
  859.             </table>
  860.             <?php
  861.         }
  862.         ?>
  863.                 <p class="submit">
  864.                         <input type="submit" name="expirationdateSaveDefaults" class="button-primary" value="<?php _e('Save Changes','post-expirator');?>" />
  865.                 </p>
  866.         </form>
  867.     <?php
  868. }
  869.  
  870. function postExpiratorMenuDiagnostics() {
  871.     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  872.         if ( !isset($_POST['_postExpiratorMenuDiagnostics_nonce']) || !wp_verify_nonce($_POST['_postExpiratorMenuDiagnostics_nonce'],'postExpiratorMenuDiagnostics') ) {
  873.             print 'Form Validation Failure: Sorry, your nonce did not verify.';
  874.             exit;
  875.         }
  876.         if (isset($_POST['debugging-disable'])) {
  877.             update_option('expirationdateDebug',0);
  878.                     echo "<div id='message' class='updated fade'><p>"; _e('Debugging Disabled','post-expirator'); echo "</p></div>";
  879.         } elseif (isset($_POST['debugging-enable'])) {
  880.             update_option('expirationdateDebug',1);
  881.                     echo "<div id='message' class='updated fade'><p>"; _e('Debugging Enabled','post-expirator'); echo "</p></div>";
  882.         } elseif (isset($_POST['purge-debug'])) {
  883.             require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php');
  884.             $debug = new postExpiratorDebug();
  885.             $debug->purge();
  886.                     echo "<div id='message' class='updated fade'><p>"; _e('Debugging Table Emptied','post-expirator'); echo "</p></div>";
  887.         }
  888.     }
  889.  
  890.     $debug = postExpiratorDebug();
  891.     ?>
  892.         <form method="post" id="postExpiratorMenuUpgrade">
  893.                 <?php wp_nonce_field('postExpiratorMenuDiagnostics','_postExpiratorMenuDiagnostics_nonce'); ?>
  894.                 <h3><?php _e('Advanced Diagnostics','post-expirator');?></h3>
  895.                 <table class="form-table">     
  896.                         <tr valign-"top">
  897.                                 <th scope="row"><label for="postexpirator-log"><?php _e('Post Expirator Debug Logging:','post-expirator');?></label></th>
  898.                                 <td>
  899.                     <?php
  900.                     if (POSTEXPIRATOR_DEBUG) {
  901.                         echo __('Status: Enabled','post-expirator').'<br/>';
  902.                         echo '<input type="submit" class="button" name="debugging-disable" id="debugging-disable" value="'.__('Disable Debugging','post-expirator').'" />';
  903.                     } else {
  904.                         echo __('Status: Disabled','post-expirator').'<br/>';
  905.                         echo '<input type="submit" class="button" name="debugging-enable" id="debugging-enable" value="'.__('Enable Debugging','post-expirator').'" />';
  906.                     }
  907.                     ?>
  908.                                         <br/>
  909.                     <a href="<?php echo admin_url('options-general.php?page=post-expirator.php&tab=viewdebug') ?>">View Debug Logs</a>
  910.                                 </td>
  911.                         </tr>
  912.                         <tr valign-"top">
  913.                                 <th scope="row"><?php _e('Purge Debug Log:','post-expirator');?></th>
  914.                                 <td>
  915.                     <input type="submit" class="button" name="purge-debug" id="purge-debug" value="<?php _e('Purge Debug Log','post-expirator');?>" />
  916.                 </td>
  917.             </tr/>
  918.                         <tr valign-"top">
  919.                                 <th scope="row"><?php _e('WP-Cron Status:','post-expirator');?></th>
  920.                                 <td>
  921.                     <?php
  922.                     if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON === true) {
  923.                         _e('DISABLED','post-expirator');
  924.                     } else {
  925.                         _e('ENABLED - OK','post-expirator');
  926.                     }
  927.                     ?>
  928.                 </td>
  929.             </tr/>
  930.                         <tr valign-"top">
  931.                                 <th scope="row"><label for="cron-schedule"><?php _e('Current Cron Schedule:','post-expirator');?></label></th>
  932.                                 <td>
  933.                     <?php _e('The below table will show all currently scheduled cron events with the next run time.','post-expirator');?><br/>
  934.                    
  935.                     <table>
  936.                         <tr>
  937.                             <th style="width: 200px;"><?php _e('Date','post-expirator');?></th>
  938.                             <th style="width: 200px;"><?php _e('Event','post-expirator');?></th>
  939.                             <th style="width: 500px;"><?php _e('Arguments / Schedule','post-expirator');?></th>
  940.                         </tr>
  941.                     <?php
  942.                     $cron = _get_cron_array();
  943.                     foreach ($cron as $key=>$value) {
  944.                         foreach ($value as $eventkey=>$eventvalue) {
  945.                         print '<tr>';
  946.                         print '<td>'.date_i18n('r',$key).'</td>';
  947.                         print '<td>'.$eventkey.'</td>';
  948.                         $arrkey = array_keys($eventvalue);
  949.                         print '<td>';
  950.                         foreach ($arrkey as $eventguid) {
  951.                             print '<table><tr>';                   
  952.                             if (empty($eventvalue[$eventguid]['args'])) {
  953.                                 print '<td>No Arguments</td>';
  954.                             } else {
  955.                                 print '<td>';
  956.                                 $args = array();
  957.                                 foreach ($eventvalue[$eventguid]['args'] as $key=>$value) {
  958.                                     $args[] = "$key => $value";
  959.                                 }
  960.                                 print implode("<br/>\n",$args);
  961.                                 print '</td>';
  962.                             }
  963.                             if (empty($eventvalue[$eventguid]['schedule'])) {
  964.                                 print '<td>'.__('Single Event','post-expirator').'</td>';
  965.                             } else {
  966.                                 print '<td>'.$eventvalue[$eventguid]['schedule'].' ('.$eventvalue[$eventguid]['interval'].')</td>';
  967.                             }
  968.                             print '</tr></table>';
  969.                         }
  970.                         print '</td>';
  971.                         print '</tr>';
  972.                         }
  973.                     }
  974.                     ?>
  975.                     </table>
  976.                                 </td>
  977.                         </tr>
  978.                 </table>
  979.         </form>
  980.     <?php
  981. }
  982.  
  983. function postExpiratorMenuViewdebug() {
  984.     require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php');
  985.     print "<p>".__('Below is a dump of the debugging table, this should be useful for troubleshooting.','post-expirator')."</p>";
  986.     $debug = new postExpiratorDebug();
  987.     $debug->getTable();
  988. }
  989.  
  990. // [postexpirator format="l F jS, Y g:ia" tz="foo"]
  991. function postexpirator_shortcode($atts) {
  992.     global $post;
  993.  
  994.         $expirationdatets = get_post_meta($post->ID,'_expiration-date',true);
  995.     if (empty($expirationdatets))
  996.         return false;
  997.  
  998.     extract(shortcode_atts(array(
  999.         'dateformat' => get_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT),
  1000.         'timeformat' => get_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT),
  1001.         'type' => 'full',
  1002.         'tz' => date('T')
  1003.     ), $atts));
  1004.  
  1005.     if (empty($dateformat)) {
  1006.         global $expirationdateDefaultDateFormat;
  1007.         $dateformat = $expirationdateDefaultDateFormat;    
  1008.     }
  1009.  
  1010.     if (empty($timeformat)) {
  1011.         global $expirationdateDefaultTimeFormat;
  1012.         $timeformat = $expirationdateDefaultTimeFormat;    
  1013.     }
  1014.  
  1015.     if ($type == 'full')
  1016.         $format = $dateformat.' '.$timeformat;
  1017.     else if ($type == 'date')
  1018.         $format = $dateformat;
  1019.     else if ($type == 'time')
  1020.         $format = $timeformat;
  1021.  
  1022.     return get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),$format);
  1023. }
  1024. add_shortcode('postexpirator', 'postexpirator_shortcode');
  1025.  
  1026. function postexpirator_add_footer($text) {
  1027.     global $post;
  1028.  
  1029.     // Check to see if its enabled
  1030.     $displayFooter = get_option('expirationdateDisplayFooter');
  1031.     if ($displayFooter === false || $displayFooter == 0)
  1032.         return $text;
  1033.  
  1034.         $expirationdatets = get_post_meta($post->ID,'_expiration-date',true);
  1035.     if (!is_numeric($expirationdatets))
  1036.         return $text;
  1037.  
  1038.         $dateformat = get_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT);
  1039.         $timeformat = get_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT);
  1040.         $expirationdateFooterContents = get_option('expirationdateFooterContents',POSTEXPIRATOR_FOOTERCONTENTS);
  1041.         $expirationdateFooterStyle = get_option('expirationdateFooterStyle',POSTEXPIRATOR_FOOTERSTYLE);
  1042.    
  1043.     $search = array(
  1044.         'EXPIRATIONFULL',
  1045.         'EXPIRATIONDATE',
  1046.         'EXPIRATIONTIME'
  1047.     );
  1048.     $replace = array(
  1049.         get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),"$dateformat $timeformat"),
  1050.         get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),$dateformat),
  1051.         get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),$timeformat)
  1052.     );
  1053.  
  1054.     $add_to_footer = '<p style="'.$expirationdateFooterStyle.'">'.str_replace($search,$replace,$expirationdateFooterContents).'</p>';
  1055.     return $text.$add_to_footer;
  1056. }
  1057. add_action('the_content','postexpirator_add_footer',0);
  1058.  
  1059. /**
  1060.  * Check for Debug
  1061.  */
  1062. function postExpiratorDebug() {
  1063.     $debug = get_option('expirationdateDebug');
  1064.     if ($debug == 1) {
  1065.         if (!defined('POSTEXPIRATOR_DEBUG')) define('POSTEXPIRATOR_DEBUG',1);
  1066.                 require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php'); // Load Class
  1067.                 return new postExpiratorDebug();
  1068.     } else {
  1069.         if (!defined('POSTEXPIRATOR_DEBUG')) define('POSTEXPIRATOR_DEBUG',0);
  1070.         return false;
  1071.     }
  1072. }
  1073.  
  1074.  
  1075. /**
  1076.  * Add Stylesheet
  1077.  */
  1078. function postexpirator_css() {
  1079.         $myStyleUrl = plugins_url('style.css', __FILE__); // Respects SSL, Style.css is relative to the current file
  1080.         $myStyleFile = WP_PLUGIN_DIR . '/post-expirator/style.css';
  1081.         if ( file_exists($myStyleFile) ) {
  1082.             wp_register_style('postexpirator-css', $myStyleUrl);
  1083.             wp_enqueue_style('postexpirator-css');
  1084.         }
  1085.  
  1086. }
  1087. add_action('admin_init','postexpirator_css');
  1088.  
  1089. /**
  1090.  * Post Expirator Activation/Upgrade
  1091.  */
  1092. function postexpirator_upgrade() {
  1093.  
  1094.     // Check for current version, if not exists, run activation
  1095.     $version = get_option('postexpiratorVersion');
  1096.     if ($version === false) { //not installed, run default activation
  1097.         postexpirator_activate();
  1098.         update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1099.     } else {
  1100.         if (version_compare($version,'1.6.1') == -1) {
  1101.             update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1102.             update_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
  1103.         }
  1104.  
  1105.         if (version_compare($version,'1.6.2') == -1) {
  1106.             update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1107.         }
  1108.  
  1109.         if (version_compare($version,'2.0.0-rc1') == -1) {
  1110.             global $wpdb;
  1111.  
  1112.             // Schedule Events/Migrate Config
  1113.             $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()));
  1114.             foreach ($results as $result) {
  1115.                 wp_schedule_single_event($result->meta_value,'postExpiratorExpire',array($result->post_id));
  1116.                 $opts = array();
  1117.                 $opts['id'] = $result->post_id;
  1118.                 $posttype = get_post_type($result->post_id);
  1119.                     if ($posttype == 'page') {
  1120.                             $opts['expireType'] = strtolower(get_option('expirationdateExpiredPageStatus','Draft'));
  1121.                         } else {
  1122.                                 $opts['expireType'] = strtolower(get_option('expirationdateExpiredPostStatus','Draft'));
  1123.                 }
  1124.  
  1125.                 $cat = get_post_meta($result->post_id,'_expiration-date-category',true);           
  1126.                 if ((isset($cat) && !empty($cat))) {
  1127.                     $opts['category'] = $cat;
  1128.                     $opts['expireType'] = 'category';
  1129.                 }
  1130.                 update_post_meta($result->post_id,'_expiration-date-options',$opts);
  1131.             }
  1132.  
  1133.             // update meta key to new format
  1134.             $wpdb->query($wpdb->prepare("UPDATE $wpdb->postmeta SET meta_key = %s WHERE meta_key = %s",'_expiration-date','expiration-date'));
  1135.  
  1136.             // migrate defaults
  1137.             $pagedefault = get_option('expirationdateExpiredPageStatus');
  1138.             $postdefault = get_option('expirationdateExpiredPostStatus');
  1139.             if ($pagedefault) update_option('expirationdateDefaultsPage',array('expireType' => $pagedefault));
  1140.             if ($postdefault) update_option('expirationdateDefaultsPost',array('expireType' => $postdefault));
  1141.  
  1142.             delete_option('expirationdateCronSchedule');
  1143.             delete_option('expirationdateAutoEnabled');
  1144.             delete_option('expirationdateExpiredPageStatus');
  1145.             delete_option('expirationdateExpiredPostStatus');
  1146.             update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1147.         }
  1148.  
  1149.         if (version_compare($version,'2.0.1') == -1) {
  1150.             // Forgot to do this in 2.0.0
  1151.                 if (is_multisite()) {
  1152.                 global $current_blog;
  1153.                         wp_clear_scheduled_hook('expirationdate_delete_'.$current_blog->blog_id);
  1154.                 } else
  1155.                         wp_clear_scheduled_hook('expirationdate_delete');
  1156.            
  1157.             update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1158.         }
  1159.  
  1160.         if (version_compare($version,'2.1.0') == -1) {
  1161.            
  1162.             update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1163.         }
  1164.  
  1165.         if (version_compare($version,'2.1.1') == -1) {
  1166.            
  1167.             update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
  1168.         }
  1169.     }
  1170. }
  1171. add_action('admin_init','postexpirator_upgrade');
  1172.  
  1173. /**
  1174.  * Called at plugin activation
  1175.  */
  1176. function postexpirator_activate () {
  1177.     if (get_option('expirationdateDefaultDateFormat') === false)    update_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT);
  1178.     if (get_option('expirationdateDefaultTimeFormat') === false)    update_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT);
  1179.     if (get_option('expirationdateFooterContents') === false)   update_option('expirationdateFooterContents',POSTEXPIRATOR_FOOTERCONTENTS);
  1180.     if (get_option('expirationdateFooterStyle') === false)      update_option('expirationdateFooterStyle',POSTEXPIRATOR_FOOTERSTYLE);
  1181.     if (get_option('expirationdateDisplayFooter') === false)    update_option('expirationdateDisplayFooter',POSTEXPIRATOR_FOOTERDISPLAY);
  1182.     if (get_option('expirationdateDebug') === false)        update_option('expirationdateDebug',POSTEXPIRATOR_DEBUGDEFAULT);
  1183.     if (get_option('expirationdateDefaultDate') === false)      update_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
  1184. }
  1185.  
  1186. /**
  1187.  * Called at plugin deactivation
  1188.  */
  1189. function expirationdate_deactivate () {
  1190.     global $current_blog;
  1191.     delete_option('expirationdateExpiredPostStatus');
  1192.     delete_option('expirationdateExpiredPageStatus');
  1193.     delete_option('expirationdateDefaultDateFormat');
  1194.     delete_option('expirationdateDefaultTimeFormat');
  1195.     delete_option('expirationdateDisplayFooter');
  1196.     delete_option('expirationdateFooterContents');
  1197.     delete_option('expirationdateFooterStyle');
  1198.     delete_option('expirationdateCategory');
  1199.     delete_option('expirationdateCategoryDefaults');
  1200.     delete_option('expirationdateDebug');
  1201.     delete_option('postexpiratorVersion');
  1202.     delete_option('expirationdateCronSchedule');
  1203.     delete_option('expirationdateDefaultDate');
  1204.     delete_option('expirationdateDefaultDateCustom');
  1205.     delete_option('expirationdateAutoEnabled');
  1206.     delete_option('expirationdateDefaultsPage');
  1207.     delete_option('expirationdateDefaultsPost');
  1208.     ## what about custom post types? - how to cleanup?
  1209.     if (is_multisite())
  1210.         wp_clear_scheduled_hook('expirationdate_delete_'.$current_blog->blog_id);
  1211.     else
  1212.         wp_clear_scheduled_hook('expirationdate_delete');
  1213.     require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php');
  1214.     $debug = new postExpiratorDebug();
  1215.     $debug->removeDbTable();
  1216. }
  1217. register_deactivation_hook (__FILE__, 'expirationdate_deactivate');
  1218.  
  1219. class Walker_PostExpirator_Category_Checklist extends Walker {
  1220.     var $tree_type = 'category';
  1221.     var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
  1222.  
  1223.     var $disabled = '';
  1224.  
  1225.     function setDisabled() {
  1226.         $this->disabled = 'disabled="disabled"';
  1227.     }
  1228.  
  1229.     function start_lvl(&$output, $depth = 0, $args = array()) {
  1230.         $indent = str_repeat("\t", $depth);
  1231.         $output .= "$indent<ul class='children'>\n";
  1232.     }
  1233.  
  1234.     function end_lvl(&$output, $depth = 0, $args = array()) {
  1235.         $indent = str_repeat("\t", $depth);
  1236.         $output .= "$indent</ul>\n";
  1237.     }
  1238.  
  1239.     function start_el(&$output, $category, $depth = 0, $args = array(), $current_object_id = 0) {
  1240.         extract($args);
  1241.         if ( empty($taxonomy) )
  1242.             $taxonomy = 'category';
  1243.  
  1244.         $name = 'expirationdate_category';
  1245.  
  1246.         $class = in_array( $category->term_id, $popular_cats ) ? ' class="expirator-category"' : '';
  1247.         $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>';
  1248.     }
  1249.    
  1250.     function end_el(&$output, $category, $depth = 0, $args = array()) {
  1251.         $output .= "</li>\n";
  1252.     }
  1253. }
  1254.  
  1255. function _postExpiratorExpireType($opts) {
  1256.     if (empty($opts)) return false;
  1257.  
  1258.     extract($opts);
  1259.     if (!isset($name)) return false;
  1260.     if (!isset($id)) $id = $name;
  1261.     if (!isset($disabled)) $disabled = false;
  1262.     if (!isset($onchange)) $onchange = '';
  1263.     if (!isset($type)) $type = '';
  1264.  
  1265.     $rv = array();
  1266.     $rv[] = '<select name="'.$name.'" id="'.$id.'"'.($disabled == true ? ' disabled="disabled"' : '').' onchange="'.$onchange.'">';
  1267.     //$rv[] = '<option value="draft" '. ($selected == 'draft' ? 'selected="selected"' : '') . '>'.__('Draft','post-expirator').'</option>';
  1268.     //$rv[] = '<option value="delete" '. ($selected == 'delete' ? 'selected="selected"' : '') . '>'.__('Delete','post-expirator').'</option>';
  1269.     //$rv[] = '<option value="private" '. ($selected == 'private' ? 'selected="selected"' : '') . '>'.__('Private','post-expirator').'</option>';
  1270.     if ($type != 'page') {
  1271.         //$rv[] = '<option value="category" '. ($selected == 'category' ? 'selected="selected"' : '') . '>'.__('Category: Replace','post-expirator').'</option>';
  1272.         //$rv[] = '<option value="category-add" '. ($selected == 'category-add' ? 'selected="selected"' : '') . '>'.__('Category: Add','post-expirator').'</option>';
  1273.         $rv[] = '<option value="category-remove" '. ($selected == 'category-remove' ? 'selected="selected"' : '') . '>'.__('Remove tag','post-expirator').'</option>';
  1274.     }
  1275.     $rv[] = '</select>';
  1276.     return implode("<br/>/n",$rv);
  1277. }
  1278.  
  1279. function _postExpiratorTaxonomy($opts) {
  1280.     if (empty($opts)) return false;
  1281.  
  1282.     extract($opts);
  1283.     if (!isset($name)) return false;
  1284.     if (!isset($id)) $id = $name;
  1285.     if (!isset($disabled)) $disabled = false;
  1286.     if (!isset($onchange)) $onchange = '';
  1287.     if (!isset($type)) $type = '';
  1288.  
  1289.     $taxonomies = get_object_taxonomies($type,'object');
  1290.     $taxonomies = wp_filter_object_list($taxonomies, array('hierarchical' => true));
  1291.  
  1292.     if (empty($taxonomies)) $disabled = true;
  1293.  
  1294.     $rv = array();
  1295.         $rv[] = '<select name="'.$name.'" id="'.$id.'"'.($disabled == true ? ' disabled="disabled"' : '').' onchange="'.$onchange.'">';
  1296.     foreach ($taxonomies as $taxonomy) {
  1297.         $rv[] = '<option value="'.$taxonomy->name.'" '. ($selected == $taxonomy->name ? 'selected="selected"' : '') . '>'.$taxonomy->name.'</option>';
  1298.     }
  1299.  
  1300.     $rv[] = '</select>';
  1301.     return implode("<br/>/n",$rv);
  1302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement