Changeset 1659976
- Timestamp:
- 05/18/2017 08:49:00 AM (9 years ago)
- Location:
- post-status-scheduler/trunk
- Files:
-
- 7 edited
-
classes/event.php (modified) (1 diff)
-
classes/scheduler.php (modified) (1 diff)
-
classes/settings.php (modified) (1 diff)
-
languages/post-status-scheduler-sv_SE.mo (modified) (previous)
-
languages/post-status-scheduler-sv_SE.pot (modified) (3 diffs)
-
post-status-scheduler.php (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
post-status-scheduler/trunk/classes/event.php
r1038771 r1659976 1 1 <?php 2 2 3 /** 4 * Event 5 * 6 * This class is a container class for the scheduled event 7 * 8 * @author Andreas Färnstrand <andreas@farnstranddev.se> 9 */ 10 11 namespace post_status_scheduler; 12 13 class Event { 14 15 // Contains all the event properties 16 protected $data; 17 18 19 /** 20 * __construct 21 * 22 * Init the event with the post's meta data 23 */ 24 public function __construct( $post_id ) { 25 26 $this->id = $post_id; 27 28 // Load the event post 29 $this->post = get_post( $post_id ); 30 31 // Load the event date 32 $this->date = get_post_meta( $post_id, 'scheduler_date', true ); 33 34 // Get all scheduler postmeta data 35 $check_status = get_post_meta( $post_id, 'scheduler_check_status', true ); 36 $this->check_status = !empty( $check_status ) ? true : false; 37 38 $this->status = get_post_meta( $post_id, 'scheduler_status', true ); 39 40 // Get check category meta 41 $check_category = get_post_meta( $post_id, 'scheduler_check_category', true ); 42 $this->check_category = !empty( $check_category ) ? true : false; 43 44 // Get the category action - used by old versions 45 $this->category_action = get_post_meta( $post_id, 'scheduler_category_action', true ); 46 47 // Get the activated categories 48 // For some reason I seem to have to unserialize some meta data sometimes. 49 // This is a check to make sure it is an unserialized array 50 $tmp_categories = get_post_meta( $post_id, 'scheduler_category', true ); 51 if( is_string( $tmp_categories ) ) $tmp_categories = unserialize( $tmp_categories ); 52 $this->category = $tmp_categories; 53 54 // Get if we need to check meta data 55 $check_meta = get_post_meta( $post_id, 'scheduler_check_meta', true ); 56 $this->check_meta = !empty( $check_meta ) ? true : false; 57 $this->meta_key = get_post_meta( $post_id, 'scheduler_meta_key', true ); 58 59 // Get email notify 60 $email_notify = get_post_meta( $post_id, 'scheduler_email_notify', true ); 61 $this->email_notify = !empty( $email_notify ) ? $email_notify : false; 62 63 } 64 65 66 /** 67 * save 68 * 69 * Save the scheduler postmeta 70 */ 71 public function save() { 72 73 update_post_meta( $this->id, 'scheduler_date', $this->date ); 74 75 // Post status 76 update_post_meta( $this->id, 'scheduler_check_status', $this->check_status ); 77 update_post_meta( $this->id, 'scheduler_status', $this->status ); 78 79 // post category 80 update_post_meta( $this->id, 'scheduler_check_category', $this->check_category ); 81 82 // Add categories 83 update_post_meta( $this->id, 'scheduler_category_action', $this->category_action ); 84 update_post_meta( $this->id, 'scheduler_category', $this->category ); 85 86 // post meta 87 update_post_meta( $this->id, 'scheduler_check_meta', $this->check_meta ); 88 update_post_meta( $this->id, 'scheduler_meta_key', $this->meta_key ); 89 90 // Email notification 91 if( isset( $this->email_notify ) && $this->email_notify == true ) { 92 update_post_meta( $this->id, 'scheduler_email_notify', true ); 93 } else { 94 update_post_meta( $this->id, 'scheduler_email_notify', false ); 95 } 96 97 } 98 99 100 /** 101 * delete 102 * 103 * Delete all meta data for gven post 104 * 105 * @param integer $post_id 106 */ 107 public static function delete( $post_id ) { 108 109 // Remove post meta 110 delete_post_meta( $post_id, 'scheduler_date' ); 111 112 // post status 113 delete_post_meta( $post_id, 'scheduler_check_status' ); 114 delete_post_meta( $post_id, 'scheduler_status' ); 115 116 // Legacy code for old versions of plugin 117 delete_post_meta( $post_id, 'scheduler_category_action' ); 118 delete_post_meta( $post_id, 'scheduler_category' ); 119 120 // post categories 121 delete_post_meta( $post_id, 'scheduler_check_category' ); 122 delete_post_meta( $post_id, 'scheduler_category_action_add' ); 123 delete_post_meta( $post_id, 'scheduler_category_add' ); 124 delete_post_meta( $post_id, 'scheduler_category_action_remove' ); 125 delete_post_meta( $post_id, 'scheduler_category_remove' ); 126 127 // post meta 128 delete_post_meta( $post_id, 'scheduler_check_meta' ); 129 delete_post_meta( $post_id, 'scheduler_meta_key' ); 130 131 // Email notification 132 delete_post_meta( $post_id, 'scheduler_email_notify' ); 133 134 } 135 136 137 /** 138 * __get 139 * 140 * Automagical get function for object 141 * Returns the requested property if exists 142 * 143 * @param string $key 144 * 145 * @return $value|null 146 */ 147 public function __get( $key ) { 148 return isset( $this->data[$key] ) ? $this->data[$key] : null; 149 } 150 151 152 /** 153 * __set 154 * 155 * Automagical set function for object 156 * Sets the property to the given value 157 * 158 * @param $key The property to set 159 * @param $value The value to set the property with 160 */ 161 public function __set( $key, $value ) { 162 $this->data[$key] = $value; 163 } 164 165 166 /** 167 * __isset 168 * 169 * Automagical isset function for object 170 * 171 * @param string $value 172 * 173 * @return boolean 174 */ 175 public function __isset( $value ) { 176 return isset( $this->data[$value] ); 177 } 178 179 180 } 3 /** 4 * Event 5 * 6 * This class is a container class for the scheduled event 7 * 8 * @author Andreas Färnstrand <andreas@farnstranddev.se> 9 */ 10 11 namespace post_status_scheduler; 12 13 class Event { 14 15 // Contains all the event properties 16 protected $data; 17 18 19 /** 20 * __construct 21 * 22 * Init the event with the post's meta data 23 */ 24 public function __construct( $post_id ) { 25 26 $this->id = $post_id; 27 28 // Load the event post 29 $this->post = get_post( $post_id ); 30 31 // Load the event date 32 $this->date = get_post_meta( $post_id, 'scheduler_date', true ); 33 34 // Get all scheduler postmeta data 35 $check_status = get_post_meta( $post_id, 'scheduler_check_status', true ); 36 $this->check_status = ! empty( $check_status ) ? true : false; 37 38 $this->status = get_post_meta( $post_id, 'scheduler_status', true ); 39 40 // Get check category meta 41 $check_category = get_post_meta( $post_id, 'scheduler_check_category', true ); 42 $this->check_category = ! empty( $check_category ) ? true : false; 43 44 // Get the category action - used by old versions 45 $this->category_action = get_post_meta( $post_id, 'scheduler_category_action', true ); 46 47 // Get the activated categories 48 // For some reason I seem to have to unserialize some meta data sometimes. 49 // This is a check to make sure it is an unserialized array 50 $tmp_categories = get_post_meta( $post_id, 'scheduler_category', true ); 51 if ( is_string( $tmp_categories ) ) { 52 $tmp_categories = unserialize( $tmp_categories ); 53 } 54 $this->category = $tmp_categories; 55 56 // Get if we need to check meta data 57 $check_meta = get_post_meta( $post_id, 'scheduler_check_meta', true ); 58 $this->check_meta = ! empty( $check_meta ) ? true : false; 59 $this->meta_key = get_post_meta( $post_id, 'scheduler_meta_key', true ); 60 61 // Get if we need to unstick post 62 $unstick = get_post_meta( $post_id, 'scheduler_unstick', true ); 63 $this->unstick = ! empty( $unstick ) ? true : false; 64 65 // Get if we need to unstick post 66 $stick = get_post_meta( $post_id, 'scheduler_stick', true ); 67 $this->stick = ! empty( $stick ) ? true : false; 68 69 // Get email notify 70 $email_notify = get_post_meta( $post_id, 'scheduler_email_notify', true ); 71 $this->email_notify = ! empty( $email_notify ) ? $email_notify : false; 72 73 } 74 75 76 /** 77 * save 78 * 79 * Save the scheduler postmeta 80 */ 81 public function save() { 82 83 update_post_meta( $this->id, 'scheduler_date', $this->date ); 84 85 // Post status 86 update_post_meta( $this->id, 'scheduler_check_status', $this->check_status ); 87 update_post_meta( $this->id, 'scheduler_status', $this->status ); 88 89 // post category 90 update_post_meta( $this->id, 'scheduler_check_category', $this->check_category ); 91 92 // Add categories 93 update_post_meta( $this->id, 'scheduler_category_action', $this->category_action ); 94 update_post_meta( $this->id, 'scheduler_category', $this->category ); 95 96 // post meta 97 update_post_meta( $this->id, 'scheduler_check_meta', $this->check_meta ); 98 update_post_meta( $this->id, 'scheduler_meta_key', $this->meta_key ); 99 100 if ( $this->unstick === true ) { 101 update_post_meta( $this->id, 'scheduler_unstick', $this->unstick ); 102 } else { 103 delete_post_meta( $this->id, 'scheduler_unstick' ); 104 } 105 106 if ( $this->stick === true ) { 107 update_post_meta( $this->id, 'scheduler_stick', $this->stick ); 108 } else { 109 delete_post_meta( $this->id, 'scheduler_stick' ); 110 } 111 112 // Email notification 113 if ( isset( $this->email_notify ) && $this->email_notify == true ) { 114 update_post_meta( $this->id, 'scheduler_email_notify', true ); 115 } else { 116 update_post_meta( $this->id, 'scheduler_email_notify', false ); 117 } 118 119 } 120 121 122 /** 123 * delete 124 * 125 * Delete all meta data for gven post 126 * 127 * @param integer $post_id 128 */ 129 public static function delete( $post_id ) { 130 131 // Remove post meta 132 delete_post_meta( $post_id, 'scheduler_date' ); 133 134 // post status 135 delete_post_meta( $post_id, 'scheduler_check_status' ); 136 delete_post_meta( $post_id, 'scheduler_status' ); 137 138 // Legacy code for old versions of plugin 139 delete_post_meta( $post_id, 'scheduler_category_action' ); 140 delete_post_meta( $post_id, 'scheduler_category' ); 141 142 // post categories 143 delete_post_meta( $post_id, 'scheduler_check_category' ); 144 delete_post_meta( $post_id, 'scheduler_category_action_add' ); 145 delete_post_meta( $post_id, 'scheduler_category_add' ); 146 delete_post_meta( $post_id, 'scheduler_category_action_remove' ); 147 delete_post_meta( $post_id, 'scheduler_category_remove' ); 148 149 // post meta 150 delete_post_meta( $post_id, 'scheduler_check_meta' ); 151 delete_post_meta( $post_id, 'scheduler_meta_key' ); 152 153 // Email notification 154 delete_post_meta( $post_id, 'scheduler_email_notify' ); 155 156 // Unstick 157 delete_post_meta( $post_id, 'scheduler_unstick' ); 158 delete_post_meta( $post_id, 'scheduler_stick' ); 159 160 } 161 162 163 /** 164 * __get 165 * 166 * Automagical get function for object 167 * Returns the requested property if exists 168 * 169 * @param string $key 170 * 171 * @return $value|null 172 */ 173 public function __get( $key ) { 174 return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null; 175 } 176 177 178 /** 179 * __set 180 * 181 * Automagical set function for object 182 * Sets the property to the given value 183 * 184 * @param $key The property to set 185 * @param $value The value to set the property with 186 */ 187 public function __set( $key, $value ) { 188 $this->data[ $key ] = $value; 189 } 190 191 192 /** 193 * __isset 194 * 195 * Automagical isset function for object 196 * 197 * @param string $value 198 * 199 * @return boolean 200 */ 201 public function __isset( $value ) { 202 return isset( $this->data[ $value ] ); 203 } 204 205 206 } 181 207 182 208 -
post-status-scheduler/trunk/classes/scheduler.php
r1658384 r1659976 1 1 <?php 2 2 3 /** 4 * This plugin adds capabilites to set an unpublishing date 5 * for post types set in the modules settings page. It also 6 * gives the possibility to set the new post status directly 7 * on the post. 8 * You can add or remove a category and also remove postmeta 9 * on the scheduled timestamp. 10 * 11 * @author Andreas Färnstrand <andreas@farnstranddev.se> 12 * 13 */ 14 15 namespace post_status_scheduler; 16 17 require_once( 'event.php' ); 18 require_once( 'taxonomy.php' ); 19 require_once( 'email.php' ); 20 21 use \post_status_scheduler\Event as Event; 22 use \post_status_scheduler\Taxonomy as Taxonomy; 23 use \post_status_scheduler\Settings as Settings; 24 use \post_status_scheduler\Email as Email; 25 26 if( !defined( 'POST_STATUS_SCHEDULER_TEXTDOMAIN' ) ) define( 'POST_STATUS_SCHEDULER_TEXTDOMAIN', 'post-status-scheduler' ); 27 28 class Scheduler { 29 30 private $options = array(); 31 32 /** 33 * Constructor - Add hooks 34 */ 35 public function __construct() { 36 37 global $pagenow; 38 39 // Load translations 40 add_action( 'plugins_loaded', array( $this , 'load_translations') ); 41 42 // Add the action used for unpublishing posts 43 add_action( 'schedule_post_status_change', array( $this, 'schedule_post_status_change' ), 10, 1 ); 44 45 // Remove any scheduled changes for post on deletion or trash post 46 add_action( 'delete_post', array( $this, 'remove_schedule' ) ); 47 add_action( 'wp_trash_post', array( $this, 'remove_schedule' ) ); 48 49 50 if( is_admin() ) { 51 52 $this->options = Settings::get_options(); 53 54 if( !is_array( $this->options ) ) { 55 $this->options = array(); 56 } 57 58 // Add html to publish meta box 59 add_action( 'post_submitbox_misc_actions', array( $this, 'scheduler_admin_callback' ) ); 60 61 // Add scripts 62 add_action( 'admin_enqueue_scripts', array( $this, 'add_plugin_resources' ) ); 63 64 // Hook into save post 65 add_action( 'save_post', array( $this, 'save' ) ); 66 67 // Get saved options 68 $scheduler_options = $this->options; 69 $scheduler_options = isset( $scheduler_options['allowed_posttypes'] ) ? $scheduler_options['allowed_posttypes'] : null; 70 71 // If this is a list of post types then we add columns 72 if( isset( $pagenow ) && $pagenow == 'edit.php' ) { 73 74 if( isset( $this->options['extra_column_enabled'] ) && $this->options['extra_column_enabled'] == true ) { 75 76 // Set the post type to post if it is not in address field 77 if( !isset( $_GET['post_type'] ) ) { 78 79 $post_type = 'post'; 80 81 } else { 82 83 $post_type = $_GET['post_type']; 84 85 } 86 87 // Is this post type set to have unpublishing options? 88 if( isset( $post_type ) && is_array( $scheduler_options ) && in_array( $post_type, $scheduler_options ) ) { 89 90 foreach( $scheduler_options as $type ) { 91 92 // Add new columns 93 add_filter( 'manage_'.$type.'_posts_columns', array( $this, 'add_column' ) ); 94 // Set column content 95 add_action( 'manage_'.$type.'_posts_custom_column', array( $this, 'custom_column' ), 10, 2); 96 // Register column as sortable 97 add_filter( "manage_edit-".$type."_sortable_columns", array( $this, 'register_sortable' ) ); 98 99 } 100 101 // The request to use as orderby 102 add_filter( 'request', array( $this, 'orderby' ) ); 103 104 } 105 106 } 107 108 } 109 110 } 111 112 } 113 114 115 /** 116 * load_translations 117 * 118 * Load the correct plugin translation file 119 */ 120 public function load_translations() { 121 122 load_plugin_textdomain( 'post-status-scheduler', false, POST_STATUS_SCHEDULER_TEXTDOMAIN_PATH ); 123 124 } 125 126 127 /** 128 * remove_schedule 129 * 130 * Remove a scheduled event. Used by the hook 131 * 132 * @param int $post_id 133 */ 134 public function remove_schedule( $post_id ) { 135 136 Scheduler::unschedule( $post_id ); 137 138 } 139 140 141 /** 142 * Implements hook save_post 143 * 144 * @param int $post_id 145 */ 146 public function save( $post_id ) { 147 148 global $post, $typenow, $post_type; 149 150 if( !current_user_can( 'edit_post', $post_id ) ) return $post_id; 151 if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id; 152 if( !isset( $this->options ) ) return $post_id; 153 154 // Get the valid post types set in options page 155 $scheduler_options = !empty( $this->options['allowed_posttypes'] ) ? $this->options['allowed_posttypes'] : array(); 156 157 // Abort if not a valid post type 158 if( !in_array( $post_type, $scheduler_options ) ) return $post_id; 159 160 // Abort if post is not an object 161 if ( ! is_object( $post ) ) return $post_id; 162 163 // Add filter for developers to modify the received post data 164 $postdata = apply_filters( 'post_status_scheduler_before_save', array( $post->ID, $_POST ) ); 165 $postdata = $postdata[1]; 166 167 // Setup data 168 $date = isset( $postdata['scheduler']['date'] ) && strlen( $postdata['scheduler']['date'] ) == 10 ? $postdata['scheduler']['date'] : null; 169 $time = isset( $postdata['scheduler']['time'] ) && strlen( $postdata['scheduler']['time'] ) == 5 ? $postdata['scheduler']['time'] : null; 170 171 // Create a new event container 172 $event = new Event( $post_id ); 173 174 $event->check_status = isset( $postdata['scheduler']['post-status-check'] ) ? true : false; 175 $event->status = isset( $postdata['scheduler']['status'] ) ? $postdata['scheduler']['status'] : null; 176 177 // Categories 178 $event->check_category = isset( $postdata['scheduler']['category-check'] ) ? true : false; 179 180 // Adding categories 181 $event->category_action = isset( $postdata['scheduler']['category-action'] ) ? true : false; 182 $event->category = isset( $postdata['scheduler']['category'] ) ? $postdata['scheduler']['category'] : array(); 183 184 $event->check_meta = isset( $postdata['scheduler']['postmeta-check'] ) ? true : false; 185 $event->meta_key = isset( $postdata['scheduler']['meta_key'] ) ? $postdata['scheduler']['meta_key'] : null; 186 187 $event->email_notify = isset( $postdata['scheduler']['email-notify'] ) ? true : false; 188 189 // Check if there is an old timestamp to clear away 190 //$old_timestamp = get_post_meta( $post->ID, 'post_status_scheduler_date', true ); 191 $old_timestamp = Scheduler::previous_schedule( $post->ID ); 192 193 // Is there a timestamp to save? 194 if( !empty( $date ) && !empty( $time ) && isset( $postdata['scheduler']['use'] ) ) { 195 196 if( !$new_timestamp = Scheduler::create_timestamp( $date, $time ) ) { 197 198 return $post_id; 199 200 } 201 202 // Remove old scheduled event and post meta tied to the post 203 if( isset( $old_timestamp ) ) { 204 205 Scheduler::unschedule( $post->ID ); 206 Event::delete( $post->ID ); 207 208 } 209 210 211 if( !$gmt = Scheduler::check_gmt_against_system_time( $new_timestamp ) ) return $post_id; 212 213 // Clear old scheduled time if there is one 214 Scheduler::unschedule( $post->ID ); 215 216 // Schedule a new event 217 $scheduling_result = wp_schedule_single_event( $gmt, 'schedule_post_status_change', array( $post->ID ) ); 218 $scheduling_result = isset( $scheduling_result ) && $scheduling_result == false ? false : true; 219 220 // Update the post meta tied to the post 221 if( $scheduling_result ) { 222 223 $event->date = $new_timestamp; 224 $event->save(); 225 226 apply_filters( 'post_status_scheduler_after_scheduling_success', $post->ID ); 227 228 } else { 229 230 apply_filters( 'post_status_scheduler_after_scheduling_error', $post->ID ); 231 232 } 233 234 } else { 235 236 // Clear the scheduled event and remove all post meta if 237 // user removed the scheduling 238 if( isset( $old_timestamp ) ) { 239 240 Scheduler::unschedule( $post->ID ); 241 242 // Remove post meta 243 Event::delete( $post->ID ); 244 245 } 246 247 } 248 249 } 250 251 252 /** 253 * This is the actual function that executes upon 254 * hook execution 255 * 256 * @param $post_id 257 */ 258 public function schedule_post_status_change( $post_id ) { 259 260 // Get all scheduler postmeta data 261 $event = new Event( $post_id ); 262 263 $valid_statuses = array_keys( Scheduler::post_statuses() ); 264 265 // Add a filter for developers to change the flow 266 $filter_result = apply_filters( 'post_status_scheduler_before_execution', array( 'status' => $event->status, 'valid_statuses' => $valid_statuses ), $post_id ); 267 $scheduler_status = $filter_result['status']; 268 $valid_statuses = $filter_result['valid_statuses']; 269 270 $executed_events = array(); 271 272 if( $event->check_status ) { 273 274 // Execute the scheduled status change 275 if( in_array( $event->status, $valid_statuses ) ) { 276 277 switch( $event->status ) { 278 case 'draft': 279 case 'pending': 280 case 'private': 281 wp_update_post( array( 'ID' => $post_id, 'post_status' => $event->status ) ); 282 break; 283 case 'trash': 284 wp_delete_post( $post_id ); 285 break; 286 case 'deleted': // Delete without first moving to trash 287 wp_delete_post( $post_id, true ); 288 break; 289 default: 290 break; 291 } 292 293 // Add the executed event 294 $executed_events []= 'check_status'; 295 296 } 297 298 } 299 300 // If user just wish to remove a post meta 301 if( $event->check_meta ) { 302 303 if( !empty( $event->meta_key ) ) { 304 delete_post_meta( $post_id, $event->meta_key ); 305 306 // Add the executed event 307 $executed_events []= 'check_meta'; 308 } 309 310 } 311 312 313 // Add and remove categories 314 if( $event->check_category ) { 315 316 if( is_array( $event->category ) ) { 317 318 if( count( $event->category ) > 0 ) { 319 320 // Reset all categories 321 Taxonomy::reset_all_terms( $post_id ); 322 323 foreach( $event->category as $scheduler_cat ) { 324 325 $scheduler_category_splits = explode( '_', $scheduler_cat ); 326 if( count( $scheduler_category_splits ) >= 2 ) { 327 328 // Get the category id 329 $scheduler_category_to_add = array_shift( $scheduler_category_splits ); 330 // Get the taxonomy of the category 331 $scheduler_category_taxonomy = implode( '_', $scheduler_category_splits ); 332 333 // If this a tag and not a category than we need to get the term 334 // data and set the term by name and not id. 335 if( !is_taxonomy_hierarchical( $scheduler_category_taxonomy ) ) { 336 337 $term_data = get_term_by( 'id', $scheduler_category_to_add, $scheduler_category_taxonomy ); 338 $scheduler_category_to_add = $term_data->name; 339 340 } 341 342 // Update the categories 343 Taxonomy::set_terms( $post_id, array( $scheduler_category_to_add ), $scheduler_category_taxonomy, true ); 344 345 // Add the executed event 346 $executed_events []= 'check_category'; 347 348 } 349 350 } 351 352 } 353 354 } else { // This is here for legacy reasons, versions <= 0.2.1 355 356 if( is_string( $event->category ) && strlen( $event->category ) > 0 ) { 357 358 if( !empty( $event->category_action ) ) { 359 360 $scheduler_category_splits = explode( '_', $event->category ); 361 if( count( $scheduler_category_splits ) >= 2 ) { 362 363 // Get the category id 364 $scheduler_category = array_shift( $scheduler_category_splits ); 365 366 // Get the taxonomy of the category 367 $scheduler_category_taxonomy = implode( '_', $scheduler_category_splits ); 368 369 if( $scheduler_category_action == 'add' ) { 370 371 Taxonomy::set_terms( $post_id, array( $scheduler_category ), $scheduler_category_taxonomy, true ); 372 373 } else if( $event->category_action == 'remove' ) { 374 375 $categories = Taxonomy::get_terms( $post_id, $scheduler_category_taxonomy ); 376 $new_categories = array(); 377 378 if( count( $categories ) > 0 ) { 379 380 foreach( $categories as $key => $category ) { 381 382 array_push( $new_categories, $category->term_id ); 383 384 } 385 386 } 387 388 $position = array_search( $scheduler_category, $new_categories ); 389 unset( $new_categories[$position] ); 390 391 Taxonomy::set_terms( $post_id, $new_categories, $scheduler_category_taxonomy ); 392 393 // Add the executed event 394 $executed_events []= 'check_category'; 395 396 } 397 398 } 399 400 } 401 402 } 403 404 } 405 406 } 407 408 // Log the execution time on the post 409 Scheduler::log_run( $post_id ); 410 411 // Remove post meta 412 Event::delete( $post_id ); 413 414 $options = Settings::get_options(); 415 416 // Checkto see if we should send an email notification 417 //if( isset( $options['notification_email_enabled'] ) && $options['notification_email_enabled'] == true ) { 418 419 // Is the email notification checked on this event 420 if( isset( $event->email_notify ) && $event->email_notify == true ) { 421 422 if( is_object( $event->post ) ) { 423 424 Email::update_notification( $event->post ); 425 426 } 427 428 } 429 430 //} 431 432 apply_filters( 'post_status_scheduler_after_execution', array( 'status' => $scheduler_status, 'valid_statuses' => $valid_statuses ), $post_id ); 433 434 } 435 436 437 /** 438 * Add scripts and stylesheets to the page 439 * 440 * @param string $hook 441 */ 442 public function add_plugin_resources( $hook ) { 443 444 $current_screen = get_current_screen(); 445 446 if( in_array( $hook, array( 'post.php', 'post-new.php' ) ) && isset( $this->options['allowed_posttypes'] ) && in_array( $current_screen->post_type, $this->options['allowed_posttypes'] ) ) { 447 448 wp_enqueue_script( 'jquery-timepicker-js', POST_STATUS_SCHEDULER_PLUGIN_PATH . 'js/jquery.ui.timepicker.js', array( 'jquery', 'jquery-ui-core' ), false, true ); 449 wp_enqueue_script( 'scheduler-js', POST_STATUS_SCHEDULER_PLUGIN_PATH . 'js/scheduler.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-datepicker' ), false, true ); 450 wp_enqueue_style( array( 'dashicons' ) ); 451 452 wp_register_style('jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css'); 453 wp_enqueue_style( 'jquery-ui' ); 454 455 wp_register_style('jquery-timepicker-css', POST_STATUS_SCHEDULER_PLUGIN_PATH . 'css/jquery.ui.timepicker.css' ); 456 wp_enqueue_style( 'jquery-timepicker-css' ); 457 458 wp_enqueue_style( 'scheduler-style', POST_STATUS_SCHEDULER_PLUGIN_PATH . 'css/scheduler.css' ); 459 460 // Add filter so developers can add their own assets 461 apply_filters( 'post_status_scheduler_plugin_resources', POST_STATUS_SCHEDULER_PLUGIN_PATH ); 462 463 } 464 465 } 466 467 468 /** 469 * Logic and HTML for outputting the 470 * data on the admin post type edit page 471 */ 472 public function scheduler_admin_callback() { 473 474 global $post, $post_type; 475 476 $event = new Event( $post->ID ); 477 478 // Get valid post types set in module settings page 479 $allowed_posttypes = isset( $this->options['allowed_posttypes'] ) ? $this->options['allowed_posttypes'] : array(); 480 // Check if there are any meta keys to be shown 481 $meta_keys = isset( $this->options['meta_keys'] ) ? $this->options['meta_keys'] : array(); 482 // Check if email notification is set 483 $use_notification = isset( $this->options['email_notification'] ) ? true : false; 484 485 $categories = Taxonomy::get_posttype_terms( $post_type ); 486 487 $post_categories = Taxonomy::get_all_terms( $post->ID ); 488 $post_categories = Taxonomy::setup_post_terms( $post_categories, $categories ); 489 490 // Do not show HTML if there are no valid post types or current edit page is not for a valid post type 491 if( count( $allowed_posttypes ) && in_array( $post_type, $allowed_posttypes ) ) { 492 493 $date = $event->date; 494 $status = $event->status; 495 496 $date = isset( $date ) && strlen( $date ) > 0 ? date( 'Y-m-d H:i', $date ) : null; 497 $dates = explode( ' ', $date ); 498 499 $date = isset( $dates[0] ) ? $dates[0] : null; 500 $time = isset( $dates[1] ) ? $dates[1] : null; 501 502 $status = !empty( $status ) ? $status : null; 503 504 // Set a couple of attributes on html 505 $checked = !empty( $date ) ? ' checked="checked" ' : ''; 506 $show = empty( $date ) ? ' style="display: none;" ' : ''; 507 508 $scheduler_check_status_checked = ( $event->check_status ) ? ' checked="checked" ' : ''; 509 $scheduler_check_status_show = ( !$event->check_status ) ? ' style="display: none;" ' : ''; 510 511 $scheduler_check_category_checked = ( $event->check_category ) ? ' checked="checked" ' : ''; 512 $scheduler_check_category_show = ( !$event->check_category ) ? ' style="display: none;" ' : ''; 513 514 $scheduler_check_meta_checked = ( $event->check_meta ) ? ' checked="checked" ' : ''; 515 $scheduler_check_meta_show = ( !$event->check_meta ) ? ' style="display: none;" ' : ''; 516 517 // Write the HTML 518 echo '<div class="misc-pub-section misc-pub-section-last" id="scheduler-wrapper"> 3 /** 4 * This plugin adds capabilites to set an unpublishing date 5 * for post types set in the modules settings page. It also 6 * gives the possibility to set the new post status directly 7 * on the post. 8 * You can add or remove a category and also remove postmeta 9 * on the scheduled timestamp. 10 * 11 * @author Andreas Färnstrand <andreas@farnstranddev.se> 12 * 13 */ 14 15 namespace post_status_scheduler; 16 17 require_once( 'event.php' ); 18 require_once( 'taxonomy.php' ); 19 require_once( 'email.php' ); 20 21 use \post_status_scheduler\Event as Event; 22 use \post_status_scheduler\Taxonomy as Taxonomy; 23 use \post_status_scheduler\Settings as Settings; 24 use \post_status_scheduler\Email as Email; 25 26 if ( ! defined( 'POST_STATUS_SCHEDULER_TEXTDOMAIN' ) ) { 27 define( 'POST_STATUS_SCHEDULER_TEXTDOMAIN', 'post-status-scheduler' ); 28 } 29 30 class Scheduler { 31 32 private $options = array(); 33 34 /** 35 * Constructor - Add hooks 36 */ 37 public function __construct() { 38 39 global $pagenow; 40 41 // Load translations 42 add_action( 'plugins_loaded', array( $this, 'load_translations' ) ); 43 44 // Add the action used for unpublishing posts 45 add_action( 'schedule_post_status_change', array( $this, 'schedule_post_status_change' ), 10, 1 ); 46 47 // Remove any scheduled changes for post on deletion or trash post 48 add_action( 'delete_post', array( $this, 'remove_schedule' ) ); 49 add_action( 'wp_trash_post', array( $this, 'remove_schedule' ) ); 50 51 52 if ( is_admin() ) { 53 54 $this->options = Settings::get_options(); 55 56 if ( ! is_array( $this->options ) ) { 57 $this->options = array(); 58 } 59 60 // Add html to publish meta box 61 add_action( 'post_submitbox_misc_actions', array( $this, 'scheduler_admin_callback' ) ); 62 63 // Add scripts 64 add_action( 'admin_enqueue_scripts', array( $this, 'add_plugin_resources' ) ); 65 66 // Hook into save post 67 add_action( 'save_post', array( $this, 'save' ) ); 68 69 // Get saved options 70 $scheduler_options = $this->options; 71 $scheduler_options = isset( $scheduler_options['allowed_posttypes'] ) ? $scheduler_options['allowed_posttypes'] : null; 72 73 // If this is a list of post types then we add columns 74 if ( isset( $pagenow ) && $pagenow == 'edit.php' ) { 75 76 if ( isset( $this->options['extra_column_enabled'] ) && $this->options['extra_column_enabled'] == true ) { 77 78 // Set the post type to post if it is not in address field 79 if ( ! isset( $_GET['post_type'] ) ) { 80 81 $post_type = 'post'; 82 83 } else { 84 85 $post_type = $_GET['post_type']; 86 87 } 88 89 // Is this post type set to have unpublishing options? 90 if ( isset( $post_type ) && is_array( $scheduler_options ) && in_array( $post_type, $scheduler_options ) ) { 91 92 foreach ( $scheduler_options as $type ) { 93 94 // Add new columns 95 add_filter( 'manage_' . $type . '_posts_columns', array( $this, 'add_column' ) ); 96 // Set column content 97 add_action( 'manage_' . $type . '_posts_custom_column', array( 98 $this, 99 'custom_column' 100 ), 10, 2 ); 101 // Register column as sortable 102 add_filter( "manage_edit-" . $type . "_sortable_columns", array( 103 $this, 104 'register_sortable' 105 ) ); 106 107 } 108 109 // The request to use as orderby 110 add_filter( 'request', array( $this, 'orderby' ) ); 111 112 } 113 114 } 115 116 } 117 118 } 119 120 } 121 122 123 /** 124 * load_translations 125 * 126 * Load the correct plugin translation file 127 */ 128 public function load_translations() { 129 130 load_plugin_textdomain( 'post-status-scheduler', false, POST_STATUS_SCHEDULER_TEXTDOMAIN_PATH ); 131 132 } 133 134 135 /** 136 * remove_schedule 137 * 138 * Remove a scheduled event. Used by the hook 139 * 140 * @param int $post_id 141 */ 142 public function remove_schedule( $post_id ) { 143 144 Scheduler::unschedule( $post_id ); 145 146 } 147 148 149 /** 150 * Implements hook save_post 151 * 152 * @param int $post_id 153 */ 154 public function save( $post_id ) { 155 156 global $post, $typenow, $post_type; 157 158 if ( ! current_user_can( 'edit_post', $post_id ) ) { 159 return $post_id; 160 } 161 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 162 return $post_id; 163 } 164 if ( ! isset( $this->options ) ) { 165 return $post_id; 166 } 167 168 // Get the valid post types set in options page 169 $scheduler_options = ! empty( $this->options['allowed_posttypes'] ) ? $this->options['allowed_posttypes'] : array(); 170 171 // Abort if not a valid post type 172 if ( ! in_array( $post_type, $scheduler_options ) ) { 173 return $post_id; 174 } 175 176 // Abort if post is not an object 177 if ( ! is_object( $post ) ) { 178 return $post_id; 179 } 180 181 // Add filter for developers to modify the received post data 182 $postdata = apply_filters( 'post_status_scheduler_before_save', array( $post->ID, $_POST ) ); 183 $postdata = $postdata[1]; 184 185 // Setup data 186 $date = isset( $postdata['scheduler']['date'] ) && strlen( $postdata['scheduler']['date'] ) == 10 ? $postdata['scheduler']['date'] : null; 187 $time = isset( $postdata['scheduler']['time'] ) && strlen( $postdata['scheduler']['time'] ) == 5 ? $postdata['scheduler']['time'] : null; 188 189 // Create a new event container 190 $event = new Event( $post_id ); 191 192 $event->check_status = isset( $postdata['scheduler']['post-status-check'] ) ? true : false; 193 $event->status = isset( $postdata['scheduler']['status'] ) ? $postdata['scheduler']['status'] : null; 194 195 // Categories 196 $event->check_category = isset( $postdata['scheduler']['category-check'] ) ? true : false; 197 198 // Adding categories 199 $event->category_action = isset( $postdata['scheduler']['category-action'] ) ? true : false; 200 $event->category = isset( $postdata['scheduler']['category'] ) ? $postdata['scheduler']['category'] : array(); 201 202 $event->check_meta = isset( $postdata['scheduler']['postmeta-check'] ) ? true : false; 203 $event->meta_key = isset( $postdata['scheduler']['meta_key'] ) ? $postdata['scheduler']['meta_key'] : null; 204 205 $event->email_notify = isset( $postdata['scheduler']['email-notify'] ) ? true : false; 206 207 if ( $event->stick === true ) { 208 $event->stick = isset( $postdata['scheduler']['sticky-check'] ) ? true : false; 209 } elseif ( $event->unstick === true ) { 210 $event->unstick = isset( $postdata['scheduler']['sticky-check'] ) ? true : false; 211 } else { 212 213 if ( is_sticky( $post_id ) ) { 214 $event->unstick = true; 215 } else { 216 $event->stick = true; 217 } 218 219 } 220 221 222 // Check if there is an old timestamp to clear away 223 //$old_timestamp = get_post_meta( $post->ID, 'post_status_scheduler_date', true ); 224 $old_timestamp = Scheduler::previous_schedule( $post->ID ); 225 226 // Is there a timestamp to save? 227 if ( ! empty( $date ) && ! empty( $time ) && isset( $postdata['scheduler']['use'] ) ) { 228 229 if ( ! $new_timestamp = Scheduler::create_timestamp( $date, $time ) ) { 230 231 return $post_id; 232 233 } 234 235 // Remove old scheduled event and post meta tied to the post 236 if ( isset( $old_timestamp ) ) { 237 238 Scheduler::unschedule( $post->ID ); 239 Event::delete( $post->ID ); 240 241 } 242 243 244 if ( ! $gmt = Scheduler::check_gmt_against_system_time( $new_timestamp ) ) { 245 return $post_id; 246 } 247 248 // Clear old scheduled time if there is one 249 Scheduler::unschedule( $post->ID ); 250 251 // Schedule a new event 252 $scheduling_result = wp_schedule_single_event( $gmt, 'schedule_post_status_change', array( $post->ID ) ); 253 $scheduling_result = isset( $scheduling_result ) && $scheduling_result == false ? false : true; 254 255 // Update the post meta tied to the post 256 if ( $scheduling_result ) { 257 258 $event->date = $new_timestamp; 259 $event->save(); 260 261 apply_filters( 'post_status_scheduler_after_scheduling_success', $post->ID ); 262 263 } else { 264 265 apply_filters( 'post_status_scheduler_after_scheduling_error', $post->ID ); 266 267 } 268 269 } else { 270 271 // Clear the scheduled event and remove all post meta if 272 // user removed the scheduling 273 if ( isset( $old_timestamp ) ) { 274 275 Scheduler::unschedule( $post->ID ); 276 277 // Remove post meta 278 Event::delete( $post->ID ); 279 280 } 281 282 } 283 284 } 285 286 287 /** 288 * This is the actual function that executes upon 289 * hook execution 290 * 291 * @param $post_id 292 */ 293 public function schedule_post_status_change( $post_id ) { 294 295 // Get all scheduler postmeta data 296 $event = new Event( $post_id ); 297 298 $valid_statuses = array_keys( Scheduler::post_statuses() ); 299 300 // Add a filter for developers to change the flow 301 $filter_result = apply_filters( 'post_status_scheduler_before_execution', array( 302 'status' => $event->status, 303 'valid_statuses' => $valid_statuses 304 ), $post_id ); 305 $scheduler_status = $filter_result['status']; 306 $valid_statuses = $filter_result['valid_statuses']; 307 308 $executed_events = array(); 309 310 if ( $event->check_status ) { 311 312 // Execute the scheduled status change 313 if ( in_array( $event->status, $valid_statuses ) ) { 314 315 switch ( $event->status ) { 316 case 'draft': 317 case 'pending': 318 case 'private': 319 wp_update_post( array( 'ID' => $post_id, 'post_status' => $event->status ) ); 320 break; 321 case 'trash': 322 wp_delete_post( $post_id ); 323 break; 324 case 'deleted': // Delete without first moving to trash 325 wp_delete_post( $post_id, true ); 326 break; 327 default: 328 break; 329 } 330 331 // Add the executed event 332 $executed_events [] = 'check_status'; 333 334 } 335 336 } 337 338 339 if ( $event->unstick ) { 340 341 if ( is_sticky( $post_id ) ) { 342 343 unstick_post( $post_id ); 344 345 } 346 347 } 348 349 if ( $event->stick ) { 350 351 if ( ! is_sticky( $post_id ) ) { 352 353 stick_post( $post_id ); 354 355 } 356 357 } 358 359 360 // If user just wish to remove a post meta 361 if ( $event->check_meta ) { 362 363 if ( ! empty( $event->meta_key ) ) { 364 delete_post_meta( $post_id, $event->meta_key ); 365 366 // Add the executed event 367 $executed_events [] = 'check_meta'; 368 } 369 370 } 371 372 373 // Add and remove categories 374 if ( $event->check_category ) { 375 376 if ( is_array( $event->category ) ) { 377 378 if ( count( $event->category ) > 0 ) { 379 380 // Reset all categories 381 Taxonomy::reset_all_terms( $post_id ); 382 383 foreach ( $event->category as $scheduler_cat ) { 384 385 $scheduler_category_splits = explode( '_', $scheduler_cat ); 386 if ( count( $scheduler_category_splits ) >= 2 ) { 387 388 // Get the category id 389 $scheduler_category_to_add = array_shift( $scheduler_category_splits ); 390 // Get the taxonomy of the category 391 $scheduler_category_taxonomy = implode( '_', $scheduler_category_splits ); 392 393 // If this a tag and not a category than we need to get the term 394 // data and set the term by name and not id. 395 if ( ! is_taxonomy_hierarchical( $scheduler_category_taxonomy ) ) { 396 397 $term_data = get_term_by( 'id', $scheduler_category_to_add, $scheduler_category_taxonomy ); 398 $scheduler_category_to_add = $term_data->name; 399 400 } 401 402 // Update the categories 403 Taxonomy::set_terms( $post_id, array( $scheduler_category_to_add ), $scheduler_category_taxonomy, true ); 404 405 // Add the executed event 406 $executed_events [] = 'check_category'; 407 408 } 409 410 } 411 412 } 413 414 } else { // This is here for legacy reasons, versions <= 0.2.1 415 416 if ( is_string( $event->category ) && strlen( $event->category ) > 0 ) { 417 418 if ( ! empty( $event->category_action ) ) { 419 420 $scheduler_category_splits = explode( '_', $event->category ); 421 if ( count( $scheduler_category_splits ) >= 2 ) { 422 423 // Get the category id 424 $scheduler_category = array_shift( $scheduler_category_splits ); 425 426 // Get the taxonomy of the category 427 $scheduler_category_taxonomy = implode( '_', $scheduler_category_splits ); 428 429 if ( $scheduler_category_action == 'add' ) { 430 431 Taxonomy::set_terms( $post_id, array( $scheduler_category ), $scheduler_category_taxonomy, true ); 432 433 } else if ( $event->category_action == 'remove' ) { 434 435 $categories = Taxonomy::get_terms( $post_id, $scheduler_category_taxonomy ); 436 $new_categories = array(); 437 438 if ( count( $categories ) > 0 ) { 439 440 foreach ( $categories as $key => $category ) { 441 442 array_push( $new_categories, $category->term_id ); 443 444 } 445 446 } 447 448 $position = array_search( $scheduler_category, $new_categories ); 449 unset( $new_categories[ $position ] ); 450 451 Taxonomy::set_terms( $post_id, $new_categories, $scheduler_category_taxonomy ); 452 453 // Add the executed event 454 $executed_events [] = 'check_category'; 455 456 } 457 458 } 459 460 } 461 462 } 463 464 } 465 466 } 467 468 // Log the execution time on the post 469 Scheduler::log_run( $post_id ); 470 471 // Remove post meta 472 Event::delete( $post_id ); 473 474 $options = Settings::get_options(); 475 476 // Checkto see if we should send an email notification 477 //if( isset( $options['notification_email_enabled'] ) && $options['notification_email_enabled'] == true ) { 478 479 // Is the email notification checked on this event 480 if ( isset( $event->email_notify ) && $event->email_notify == true ) { 481 482 if ( is_object( $event->post ) ) { 483 484 Email::update_notification( $event->post ); 485 486 } 487 488 } 489 490 //} 491 492 apply_filters( 'post_status_scheduler_after_execution', array( 493 'status' => $scheduler_status, 494 'valid_statuses' => $valid_statuses 495 ), $post_id ); 496 497 } 498 499 500 /** 501 * Add scripts and stylesheets to the page 502 * 503 * @param string $hook 504 */ 505 public function add_plugin_resources( $hook ) { 506 507 $current_screen = get_current_screen(); 508 509 if ( in_array( $hook, array( 510 'post.php', 511 'post-new.php' 512 ) ) && isset( $this->options['allowed_posttypes'] ) && in_array( $current_screen->post_type, $this->options['allowed_posttypes'] ) 513 ) { 514 515 wp_enqueue_script( 'jquery-timepicker-js', POST_STATUS_SCHEDULER_PLUGIN_PATH . 'js/jquery.ui.timepicker.js', array( 516 'jquery', 517 'jquery-ui-core' 518 ), false, true ); 519 wp_enqueue_script( 'scheduler-js', POST_STATUS_SCHEDULER_PLUGIN_PATH . 'js/scheduler.js', array( 520 'jquery', 521 'jquery-ui-core', 522 'jquery-ui-datepicker' 523 ), false, true ); 524 wp_enqueue_style( array( 'dashicons' ) ); 525 526 wp_register_style( 'jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css' ); 527 wp_enqueue_style( 'jquery-ui' ); 528 529 wp_register_style( 'jquery-timepicker-css', POST_STATUS_SCHEDULER_PLUGIN_PATH . 'css/jquery.ui.timepicker.css' ); 530 wp_enqueue_style( 'jquery-timepicker-css' ); 531 532 wp_enqueue_style( 'scheduler-style', POST_STATUS_SCHEDULER_PLUGIN_PATH . 'css/scheduler.css' ); 533 534 // Add filter so developers can add their own assets 535 apply_filters( 'post_status_scheduler_plugin_resources', POST_STATUS_SCHEDULER_PLUGIN_PATH ); 536 537 } 538 539 } 540 541 542 /** 543 * Logic and HTML for outputting the 544 * data on the admin post type edit page 545 */ 546 public function scheduler_admin_callback() { 547 548 global $post, $post_type; 549 550 $event = new Event( $post->ID ); 551 552 // Get valid post types set in module settings page 553 $allowed_posttypes = isset( $this->options['allowed_posttypes'] ) ? $this->options['allowed_posttypes'] : array(); 554 // Get the sticky posttypes selected in settings 555 $sticky_posttypes = isset( $this->options['sticky_posttypes'] ) ? $this->options['sticky_posttypes'] : array(); 556 557 // Check if there are any meta keys to be shown 558 $meta_keys = isset( $this->options['meta_keys'] ) ? $this->options['meta_keys'] : array(); 559 // Check if email notification is set 560 $use_notification = isset( $this->options['email_notification'] ) ? true : false; 561 562 $categories = Taxonomy::get_posttype_terms( $post_type ); 563 564 $post_categories = Taxonomy::get_all_terms( $post->ID ); 565 $post_categories = Taxonomy::setup_post_terms( $post_categories, $categories ); 566 567 // Do not show HTML if there are no valid post types or current edit page is not for a valid post type 568 if ( count( $allowed_posttypes ) && in_array( $post_type, $allowed_posttypes ) ) { 569 570 $date = $event->date; 571 $status = $event->status; 572 573 $date = isset( $date ) && strlen( $date ) > 0 ? date( 'Y-m-d H:i', $date ) : null; 574 $dates = explode( ' ', $date ); 575 576 $date = isset( $dates[0] ) ? $dates[0] : null; 577 $time = isset( $dates[1] ) ? $dates[1] : null; 578 579 $status = ! empty( $status ) ? $status : null; 580 581 // Set a couple of attributes on html 582 $checked = ! empty( $date ) ? ' checked="checked" ' : ''; 583 $show = empty( $date ) ? ' style="display: none;" ' : ''; 584 585 $scheduler_check_status_checked = ( $event->check_status ) ? ' checked="checked" ' : ''; 586 $scheduler_check_status_show = ( ! $event->check_status ) ? ' style="display: none;" ' : ''; 587 588 $scheduler_check_category_checked = ( $event->check_category ) ? ' checked="checked" ' : ''; 589 $scheduler_check_category_show = ( ! $event->check_category ) ? ' style="display: none;" ' : ''; 590 591 $scheduler_check_meta_checked = ( $event->check_meta ) ? ' checked="checked" ' : ''; 592 $scheduler_check_meta_show = ( ! $event->check_meta ) ? ' style="display: none;" ' : ''; 593 594 // Write the HTML 595 echo '<div class="misc-pub-section misc-pub-section-last" id="scheduler-wrapper"> 519 596 <span id="timestamp" class="calendar-link before">' 520 . '<label> ' . __( 'Schedule Status Change', POST_STATUS_SCHEDULER_TEXTDOMAIN ) . '</label> <input type="checkbox" id="scheduler-use" name="scheduler[use]" ' . $checked . ' /><br />' 521 . '<div id="scheduler-settings" ' . $show . ' >' 522 . '<label>' . __( 'Date', POST_STATUS_SCHEDULER_TEXTDOMAIN ) . '</label> ' 523 . '<input type="text" id="schedulerdate" name="scheduler[date]" value="' .$date. '" maxlengt="10" readonly="true" /> ' 524 . '<label>' . __( 'Time', POST_STATUS_SCHEDULER_TEXTDOMAIN ) . '</label> ' 525 . '<input type="text" id="schedulertime" name="scheduler[time]" value="' . $time . '" maxlength="5" readonly="true" /><br /><br />' 526 527 // Post Status 528 . '<input type="checkbox" name="scheduler[post-status-check]" id="scheduler-status" ' . $scheduler_check_status_checked . ' /> ' . __( 'Change status', 'post-status-scheduler' ) . '<br />' 529 . '<div id="scheduler-status-box" ' . $scheduler_check_status_show . ' >' 530 . '<label>' . __( 'Set status to', POST_STATUS_SCHEDULER_TEXTDOMAIN ) . '</label> ' 531 . '<select name="scheduler[status]" style="width: 98%;">'; 532 533 foreach( Scheduler::post_statuses() as $key => $value ) { 534 535 echo sprintf( '<option value="%s" ' . selected( $status, $key ) . ' >%s</option>', $key, $value ); 536 537 } 538 echo '</select><br />' 539 . '</div>'; 540 541 542 // Categories and tags 543 if( count( $categories ) > 0 ) { 544 545 echo '<input type="checkbox" name="scheduler[category-check]" id="scheduler-category" ' . $scheduler_check_category_checked . ' /> ' . __( 'Change categories and tags', 'post-status-scheduler' ) . '<br />' 546 .'<div id="scheduler-category-box" ' . $scheduler_check_category_show . '>'; 547 echo __( 'The post will have the following categories on scheduled time', POST_STATUS_SCHEDULER_TEXTDOMAIN ); 548 echo '<select name="scheduler[category][]" multiple size="5">'; 549 550 // Need this for legacy reasons. Used to be a string, versions <= 0.2.1 551 if( is_string( $event->category ) ) { 552 553 if( $event->category_action == 'add' ) { 554 555 if( !in_array( $event->category, $post_categories ) ) array_push( $post_categories, $event->category ); 556 557 558 } else if( $event->category_action == 'remove' ) { 559 560 if( ( $key = array_search( $event->category, $post_categories ) ) !== false ) { 561 562 unset( $post_categories[$key] ); 563 564 } else if( in_array( $category->term_id.'_'.$category->taxonomy, $post_categories ) ) { 565 566 $selected = ' selected="selected" '; 567 568 } 569 570 } 571 572 } 573 574 // Get the options set for categories and tags 575 $categories_and_tags = !empty( $this->options['categories_and_tags'] ) ? $this->options['categories_and_tags'] : 'both'; 576 577 // Loop categories and check if selected 578 if( $categories_and_tags == 'both' || $categories_and_tags == 'categories' ) { 579 echo sprintf( '<optgroup label="%s">', __('Categories', 'post-status-scheduler')); 580 foreach ($categories['categories'] as $category) { 581 582 if (is_array($event->category)) { 583 584 $selected = in_array($category->term_id . '_' . $category->taxonomy, $event->category) ? ' selected="selected" ' : ''; 585 586 } else { 587 588 $selected = in_array($category->term_id . '_' . $category->taxonomy, $post_categories) ? ' selected="selected" ' : ''; 589 590 } 591 592 echo sprintf('<option value="%s"%s>%s</option>', $category->term_id . '_' . $category->taxonomy, $selected, $category->name); 593 594 } 595 echo '</optgroup>'; 596 597 } 598 599 600 if( $categories_and_tags == 'both' || $categories_and_tags == 'tags' ) { 601 echo sprintf( '<optgroup label="%s">', __('Tags', 'post-status-scheduler')); 602 foreach ($categories['tags'] as $category) { 603 604 if (is_array($event->category)) { 605 606 $selected = in_array($category->term_id . '_' . $category->taxonomy, $event->category) ? ' selected="selected" ' : ''; 607 608 } else { 609 610 $selected = in_array($category->term_id . '_' . $category->taxonomy, $post_categories) ? ' selected="selected" ' : ''; 611 612 } 613 614 echo sprintf('<option value="%s"%s>%s</option>', $category->term_id . '_' . $category->taxonomy, $selected, $category->name); 615 616 } 617 echo '</optgroup>'; 618 } 619 620 echo '</select></div>'; 621 622 } 623 624 // Meta keys 625 if( count( $meta_keys ) > 0 ) { 626 echo '<input type="checkbox" name="scheduler[postmeta-check]" id="scheduler-postmeta" ' . $scheduler_check_meta_checked . ' /> ' . __( 'Remove postmeta', POST_STATUS_SCHEDULER_TEXTDOMAIN ) . '<br />' 627 .'<div id="scheduler-postmeta-box" ' . $scheduler_check_meta_show . ' >' 628 . '<select name="scheduler[meta_key]">'; 629 630 if( count( $meta_keys ) > 0 ) { 631 foreach( $meta_keys as $meta_key ) { 632 633 echo sprintf( '<option value="%s">%s</option>', $meta_key, $meta_key ); 634 635 } 636 } 637 638 echo '</select>' 639 . '</div>'; 640 } 641 642 // Email notification option 643 if( isset( $this->options['notification_email_enabled'] ) && $this->options['notification_email_enabled'] == true ) { 644 645 echo '<hr />'; 646 647 if( isset( $event->email_notify ) && $event->email_notify == true ) { 648 $email_notify_checked = ' checked="checked" '; 649 } else { 650 $email_notify_checked = ''; 651 } 652 653 // The checkbox for sending a notification email to author 654 echo '<input type="checkbox" id="scheduler-email-notification" name="scheduler[email-notify]" disabled="" ' . $email_notify_checked . '/> ' . __( 'Send email notification on change', POST_STATUS_SCHEDULER_TEXTDOMAIN ); 655 echo '<p class="description">(' . get_the_author_meta( 'user_email', $post->post_author ) . ')</p>'; 656 } 657 echo '</div>' 658 .'</span></div>'; 659 660 } 661 662 } 663 664 665 /** 666 * Add a column to the default columnsarray 667 * 668 * @param array $columns 669 * 670 * @return array $columns 671 */ 672 public function add_column( $columns ) { 673 674 $new_columns = array(); 675 676 foreach( $columns as $key => $value ) { 677 if( $key == 'date' ) { 678 679 $new_columns['scheduler_date'] = __( 'Scheduled date', POST_STATUS_SCHEDULER_TEXTDOMAIN ); 680 681 } 682 683 $new_columns[$key] = $value; 684 } 685 686 return $new_columns; 687 } 688 689 690 /** 691 * Set the column content 692 * 693 * @param string $columnname 694 * @param integer $postid 695 * 696 * @return string $columncontent 697 */ 698 public function custom_column( $column_name, $post_id ) { 699 700 if( $column_name == 'scheduler_date' ) { 701 702 $meta_data = get_post_meta( $post_id, 'scheduler_date', true ); 703 $meta_data = isset( $meta_data ) ? $meta_data : null; 704 705 if( isset( $meta_data ) && strlen( $meta_data ) > 0 ) { 706 $date = date( 'Y-m-d H:i', $meta_data ); 707 } else { 708 $date = ''; 709 } 710 711 $column_content = $date; 712 echo $column_content; 713 } 714 715 } 716 717 718 /** 719 * Register the column as a sortable 720 * 721 * @param array $columns 722 * 723 * @return array $columns 724 */ 725 public function register_sortable( $columns ) { 726 727 // Register the column and the query var which is used when sorting 728 $columns['scheduler_date'] = 'scheduler_date'; 729 730 return $columns; 731 732 } 733 734 735 /** 736 * The query to use for sorting 737 * 738 * @param array vars 739 * 740 * @return array $vars 741 */ 742 public function orderby( $vars ) { 743 744 if ( isset( $vars['orderby'] ) && 'scheduler_date' == $vars['orderby'] ) { 745 $vars = array_merge( $vars, array( 746 'meta_key' => 'scheduler_date', 747 'orderby' => 'meta_value' 748 )); 749 } 750 751 return $vars; 752 753 } 754 755 756 /* ---------------- STATIC FUNCTIONS --------------------- */ 757 758 759 /** 760 * check_gmt_against_system_time 761 * 762 * @param integer $new_timestamp 763 * 764 * @return integer $gmt; 765 */ 766 public static function check_gmt_against_system_time( $new_timestamp ) { 767 768 // Get the current system time to compare with the new scheduler timestamp 769 $system_time = microtime( true ); 770 $gmt = get_gmt_from_date( date( 'Y-m-d H:i:s', $new_timestamp ),'U'); 771 772 // The gmt needs to be bigger than the current system time 773 if( $gmt <= $system_time ) return false; 774 775 return $gmt; 776 777 } 778 779 780 /** 781 * create_timestamp 782 * 783 * Create a new timestamp from given date and time 784 * 785 * @param string $date 786 * @param string $time 787 * 788 * @return boolen|integer 789 */ 790 public static function create_timestamp( $date, $time ) { 791 792 $timestamp = strtotime( $date . ' ' . $time . ':00' ); 793 794 //Abort if not a valid timestamp 795 if( !isset( $timestamp ) || !is_int( $timestamp ) ) return false; 796 797 return $timestamp; 798 799 } 800 801 802 /** 803 * previous_schedule 804 * 805 * Return a previously scheduled time for this post 806 * 807 * @param $post_id 808 * 809 * @return string 810 */ 811 public static function previous_schedule( $post_id ) { 812 813 return get_post_meta( $post_id, 'post_status_scheduler_date', true ); 814 815 } 816 817 818 /** 819 * list_meta_keys 820 * 821 * Get all meta keys in postmeta table 822 * 823 * @return array 824 */ 825 public static function list_meta_keys() { 826 827 global $wpdb; 828 829 $result = array(); 830 $keys = $wpdb->get_results( "SELECT DISTINCT(meta_key) FROM $wpdb->postmeta ORDER BY meta_key ASC" ); 831 832 if( count( $keys ) > 0 ) { 833 834 foreach( $keys as $key_result ) { 835 array_push( $result, $key_result->meta_key ); 836 } 837 838 } 839 840 return $result; 841 842 } 843 844 845 /** 846 * unschedule 847 * 848 * Unschedule a scheduled change 849 * 850 * @param int $post_id 851 */ 852 public static function unschedule( $post_id ) { 853 854 wp_clear_scheduled_hook( 'schedule_post_status_change', array( $post_id ) ); 855 856 } 857 858 859 /** 860 * log_run 861 * 862 * Log the time for the scheduled execution on the post 863 * 864 * @param int $post_id 865 */ 866 public static function log_run( $post_id ) { 867 868 update_post_meta( $post_id, 'scheduler_unpublished', current_time( 'timestamp' ) ); 869 870 } 871 872 873 874 /** 875 * post_statuses 876 * 877 * Get the valid post stauses to use 878 * 879 * @return array 880 */ 881 public static function post_statuses() { 882 883 // All valid post statuses to choose from 884 return array( 885 'draft' => __( 'Draft', POST_STATUS_SCHEDULER_TEXTDOMAIN ), 886 'pending' => __( 'Pending', POST_STATUS_SCHEDULER_TEXTDOMAIN ), 887 'private' => __( 'Private', POST_STATUS_SCHEDULER_TEXTDOMAIN ), 888 'trash' => __( 'Trashbin', POST_STATUS_SCHEDULER_TEXTDOMAIN ), 889 'deleted' => __( 'Delete (forced)', POST_STATUS_SCHEDULER_TEXTDOMAIN ), 890 ); 891 892 } 893 894 895 } 597 . '<label> ' . __( 'Schedule Status Change', POST_STATUS_SCHEDULER_TEXTDOMAIN ) . '</label> <input type="checkbox" id="scheduler-use" name="scheduler[use]" ' . $checked . ' /><br />' 598 . '<div id="scheduler-settings" ' . $show . ' >' 599 . '<label>' . __( 'Date', POST_STATUS_SCHEDULER_TEXTDOMAIN ) . '</label> ' 600 . '<input type="text" id="schedulerdate" name="scheduler[date]" value="' . $date . '" maxlengt="10" readonly="true" /> ' 601 . '<label>' . __( 'Time', POST_STATUS_SCHEDULER_TEXTDOMAIN ) . '</label> ' 602 . '<input type="text" id="schedulertime" name="scheduler[time]" value="' . $time . '" maxlength="5" readonly="true" /><br /><br />' 603 604 // Post Status 605 . '<input type="checkbox" name="scheduler[post-status-check]" id="scheduler-status" ' . $scheduler_check_status_checked . ' /> ' . __( 'Change status', 'post-status-scheduler' ) . '<br />' 606 . '<div id="scheduler-status-box" ' . $scheduler_check_status_show . ' >' 607 . '<label>' . __( 'Set status to', POST_STATUS_SCHEDULER_TEXTDOMAIN ) . '</label> ' 608 . '<select name="scheduler[status]" style="width: 98%;">'; 609 610 foreach ( Scheduler::post_statuses() as $key => $value ) { 611 612 echo sprintf( '<option value="%s" ' . selected( $status, $key ) . ' >%s</option>', $key, $value ); 613 614 } 615 echo '</select><br />' 616 . '</div>'; 617 618 // Sticky posts 619 if ( in_array( $post->post_type, $sticky_posttypes ) ) { 620 621 $scheduler_sticky_checked = ( $event->unstick === true || $event->stick === true ) ? 'checked="checked"' : ''; 622 623 if ( $event->stick === true ) { 624 $sticky_option_text = __( 'Stick', 'post-status-scheduler' ); 625 } elseif ( $event->unstick === true ) { 626 $sticky_option_text = __( 'Unstick', 'post_status_scheduler' ); 627 } elseif ( is_sticky( $post->ID ) ) { 628 $sticky_option_text = __( 'Unstick', 'post-status-scheduler' ); 629 } else { 630 $sticky_option_text = __( 'Stick', 'post_status_scheduler' ); 631 } 632 633 echo '<input type="checkbox" name="scheduler[sticky-check]" id="scheduler-sticky" ' . $scheduler_sticky_checked . ' /> ' . $sticky_option_text . '<br />'; 634 635 } 636 637 638 // Categories and tags 639 if ( count( $categories ) > 0 ) { 640 641 echo '<input type="checkbox" name="scheduler[category-check]" id="scheduler-category" ' . $scheduler_check_category_checked . ' /> ' . __( 'Change categories and tags', 'post-status-scheduler' ) . '<br />' 642 . '<div id="scheduler-category-box" ' . $scheduler_check_category_show . '>'; 643 echo __( 'The post will have the following categories on scheduled time', POST_STATUS_SCHEDULER_TEXTDOMAIN ); 644 echo '<select name="scheduler[category][]" multiple size="5">'; 645 646 // Need this for legacy reasons. Used to be a string, versions <= 0.2.1 647 if ( is_string( $event->category ) ) { 648 649 if ( $event->category_action == 'add' ) { 650 651 if ( ! in_array( $event->category, $post_categories ) ) { 652 array_push( $post_categories, $event->category ); 653 } 654 655 656 } else if ( $event->category_action == 'remove' ) { 657 658 if ( ( $key = array_search( $event->category, $post_categories ) ) !== false ) { 659 660 unset( $post_categories[ $key ] ); 661 662 } else if ( in_array( $category->term_id . '_' . $category->taxonomy, $post_categories ) ) { 663 664 $selected = ' selected="selected" '; 665 666 } 667 668 } 669 670 } 671 672 // Get the options set for categories and tags 673 $categories_and_tags = ! empty( $this->options['categories_and_tags'] ) ? $this->options['categories_and_tags'] : 'both'; 674 675 // Loop categories and check if selected 676 if ( $categories_and_tags == 'both' || $categories_and_tags == 'categories' ) { 677 echo sprintf( '<optgroup label="%s">', __( 'Categories', 'post-status-scheduler' ) ); 678 foreach ( $categories['categories'] as $category ) { 679 680 if ( is_array( $event->category ) ) { 681 682 $selected = in_array( $category->term_id . '_' . $category->taxonomy, $event->category ) ? ' selected="selected" ' : ''; 683 684 } else { 685 686 $selected = in_array( $category->term_id . '_' . $category->taxonomy, $post_categories ) ? ' selected="selected" ' : ''; 687 688 } 689 690 echo sprintf( '<option value="%s"%s>%s</option>', $category->term_id . '_' . $category->taxonomy, $selected, $category->name ); 691 692 } 693 echo '</optgroup>'; 694 695 } 696 697 698 if ( $categories_and_tags == 'both' || $categories_and_tags == 'tags' ) { 699 echo sprintf( '<optgroup label="%s">', __( 'Tags', 'post-status-scheduler' ) ); 700 foreach ( $categories['tags'] as $category ) { 701 702 if ( is_array( $event->category ) ) { 703 704 $selected = in_array( $category->term_id . '_' . $category->taxonomy, $event->category ) ? ' selected="selected" ' : ''; 705 706 } else { 707 708 $selected = in_array( $category->term_id . '_' . $category->taxonomy, $post_categories ) ? ' selected="selected" ' : ''; 709 710 } 711 712 echo sprintf( '<option value="%s"%s>%s</option>', $category->term_id . '_' . $category->taxonomy, $selected, $category->name ); 713 714 } 715 echo '</optgroup>'; 716 } 717 718 echo '</select></div>'; 719 720 } 721 722 // Meta keys 723 if ( count( $meta_keys ) > 0 ) { 724 echo '<input type="checkbox" name="scheduler[postmeta-check]" id="scheduler-postmeta" ' . $scheduler_check_meta_checked . ' /> ' . __( 'Remove postmeta', POST_STATUS_SCHEDULER_TEXTDOMAIN ) . '<br />' 725 . '<div id="scheduler-postmeta-box" ' . $scheduler_check_meta_show . ' >' 726 . '<select name="scheduler[meta_key]">'; 727 728 if ( count( $meta_keys ) > 0 ) { 729 foreach ( $meta_keys as $meta_key ) { 730 731 echo sprintf( '<option value="%s">%s</option>', $meta_key, $meta_key ); 732 733 } 734 } 735 736 echo '</select>' 737 . '</div>'; 738 } 739 740 741 // Email notification option 742 if ( isset( $this->options['notification_email_enabled'] ) && $this->options['notification_email_enabled'] == true ) { 743 744 echo '<hr />'; 745 746 if ( isset( $event->email_notify ) && $event->email_notify == true ) { 747 $email_notify_checked = ' checked="checked" '; 748 } else { 749 $email_notify_checked = ''; 750 } 751 752 // The checkbox for sending a notification email to author 753 echo '<input type="checkbox" id="scheduler-email-notification" name="scheduler[email-notify]" disabled="" ' . $email_notify_checked . '/> ' . __( 'Send email notification on change', POST_STATUS_SCHEDULER_TEXTDOMAIN ); 754 echo '<p class="description">(' . get_the_author_meta( 'user_email', $post->post_author ) . ')</p>'; 755 } 756 echo '</div>' 757 . '</span></div>'; 758 759 } 760 761 } 762 763 764 /** 765 * Add a column to the default columnsarray 766 * 767 * @param array $columns 768 * 769 * @return array $columns 770 */ 771 public function add_column( $columns ) { 772 773 $new_columns = array(); 774 775 foreach ( $columns as $key => $value ) { 776 if ( $key == 'date' ) { 777 778 $new_columns['scheduler_date'] = __( 'Scheduled date', POST_STATUS_SCHEDULER_TEXTDOMAIN ); 779 780 } 781 782 $new_columns[ $key ] = $value; 783 } 784 785 return $new_columns; 786 } 787 788 789 /** 790 * Set the column content 791 * 792 * @param string $columnname 793 * @param integer $postid 794 * 795 * @return string $columncontent 796 */ 797 public function custom_column( $column_name, $post_id ) { 798 799 if ( $column_name == 'scheduler_date' ) { 800 801 $meta_data = get_post_meta( $post_id, 'scheduler_date', true ); 802 $meta_data = isset( $meta_data ) ? $meta_data : null; 803 804 if ( isset( $meta_data ) && strlen( $meta_data ) > 0 ) { 805 $date = date( 'Y-m-d H:i', $meta_data ); 806 } else { 807 $date = ''; 808 } 809 810 $column_content = $date; 811 echo $column_content; 812 } 813 814 } 815 816 817 /** 818 * Register the column as a sortable 819 * 820 * @param array $columns 821 * 822 * @return array $columns 823 */ 824 public function register_sortable( $columns ) { 825 826 // Register the column and the query var which is used when sorting 827 $columns['scheduler_date'] = 'scheduler_date'; 828 829 return $columns; 830 831 } 832 833 834 /** 835 * The query to use for sorting 836 * 837 * @param array vars 838 * 839 * @return array $vars 840 */ 841 public function orderby( $vars ) { 842 843 if ( isset( $vars['orderby'] ) && 'scheduler_date' == $vars['orderby'] ) { 844 $vars = array_merge( $vars, array( 845 'meta_key' => 'scheduler_date', 846 'orderby' => 'meta_value' 847 ) ); 848 } 849 850 return $vars; 851 852 } 853 854 855 /* ---------------- STATIC FUNCTIONS --------------------- */ 856 857 858 /** 859 * check_gmt_against_system_time 860 * 861 * @param integer $new_timestamp 862 * 863 * @return integer $gmt; 864 */ 865 public static function check_gmt_against_system_time( $new_timestamp ) { 866 867 // Get the current system time to compare with the new scheduler timestamp 868 $system_time = microtime( true ); 869 $gmt = get_gmt_from_date( date( 'Y-m-d H:i:s', $new_timestamp ), 'U' ); 870 871 // The gmt needs to be bigger than the current system time 872 if ( $gmt <= $system_time ) { 873 return false; 874 } 875 876 return $gmt; 877 878 } 879 880 881 /** 882 * create_timestamp 883 * 884 * Create a new timestamp from given date and time 885 * 886 * @param string $date 887 * @param string $time 888 * 889 * @return boolen|integer 890 */ 891 public static function create_timestamp( $date, $time ) { 892 893 $timestamp = strtotime( $date . ' ' . $time . ':00' ); 894 895 //Abort if not a valid timestamp 896 if ( ! isset( $timestamp ) || ! is_int( $timestamp ) ) { 897 return false; 898 } 899 900 return $timestamp; 901 902 } 903 904 905 /** 906 * previous_schedule 907 * 908 * Return a previously scheduled time for this post 909 * 910 * @param $post_id 911 * 912 * @return string 913 */ 914 public static function previous_schedule( $post_id ) { 915 916 return get_post_meta( $post_id, 'post_status_scheduler_date', true ); 917 918 } 919 920 921 /** 922 * list_meta_keys 923 * 924 * Get all meta keys in postmeta table 925 * 926 * @return array 927 */ 928 public static function list_meta_keys() { 929 930 global $wpdb; 931 932 $result = array(); 933 $keys = $wpdb->get_results( "SELECT DISTINCT(meta_key) FROM $wpdb->postmeta ORDER BY meta_key ASC" ); 934 935 if ( count( $keys ) > 0 ) { 936 937 foreach ( $keys as $key_result ) { 938 array_push( $result, $key_result->meta_key ); 939 } 940 941 } 942 943 return $result; 944 945 } 946 947 948 /** 949 * unschedule 950 * 951 * Unschedule a scheduled change 952 * 953 * @param int $post_id 954 */ 955 public static function unschedule( $post_id ) { 956 957 wp_clear_scheduled_hook( 'schedule_post_status_change', array( $post_id ) ); 958 959 } 960 961 962 /** 963 * log_run 964 * 965 * Log the time for the scheduled execution on the post 966 * 967 * @param int $post_id 968 */ 969 public static function log_run( $post_id ) { 970 971 update_post_meta( $post_id, 'scheduler_unpublished', current_time( 'timestamp' ) ); 972 973 } 974 975 976 /** 977 * post_statuses 978 * 979 * Get the valid post stauses to use 980 * 981 * @return array 982 */ 983 public static function post_statuses() { 984 985 // All valid post statuses to choose from 986 return array( 987 'draft' => __( 'Draft', POST_STATUS_SCHEDULER_TEXTDOMAIN ), 988 'pending' => __( 'Pending', POST_STATUS_SCHEDULER_TEXTDOMAIN ), 989 'private' => __( 'Private', POST_STATUS_SCHEDULER_TEXTDOMAIN ), 990 'trash' => __( 'Trashbin', POST_STATUS_SCHEDULER_TEXTDOMAIN ), 991 'deleted' => __( 'Delete (forced)', POST_STATUS_SCHEDULER_TEXTDOMAIN ), 992 ); 993 994 } 995 996 997 } 896 998 897 999 ?> -
post-status-scheduler/trunk/classes/settings.php
r1447443 r1659976 1 1 <?php 2 2 3 /** 4 * Settings 5 * 6 * Settings class for the plugin Post Status Scheduler 7 * 8 * @author Andreas Färnstrand <andreas@farnstranddev.se> 9 * 10 * @todo Configure disallowed posttypes 11 */ 12 13 namespace post_status_scheduler; 14 15 class Settings { 16 17 /** 18 * Holds the values to be used in the fields callbacks 19 */ 20 private $options; 21 private $disallowed_posttypes = array(); 22 23 /** 24 * Start up 25 */ 26 public function __construct() { 27 28 // Add posttypes not allowed here 29 // This should probably be a config of some kind 30 $this->disallowed_posttypes = array( 'attachment' ); 31 32 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 33 add_action( 'admin_init', array( $this, 'page_init' ) ); 34 35 } 36 37 /** 38 * Add options page 39 */ 40 public function add_plugin_page() { 41 42 add_options_page( 43 'Settings Admin', 44 __( 'Post Status Scheduler', 'post-status-scheduler' ), 45 'manage_options', 46 'post-status-scheduler', 47 array( $this, 'create_admin_page' ) 48 ); 49 50 } 51 52 /** 53 * Options page callback 54 */ 55 public function create_admin_page() { 56 57 // Set class property 58 $this->options = get_option( 'post_status_scheduler' ); 59 ?> 60 <div class="wrap"> 61 <?php screen_icon(); ?> 62 <h2><?php _e( 'Post Status Scheduler', 'post-status-scheduler' ); ?></h2> 63 <form method="post" action="options.php"> 64 <?php 65 // This prints out all hidden setting fields 66 settings_fields( 'posttypes_group' ); 67 do_settings_sections( 'post-status-scheduler' ); 68 submit_button(); 69 ?> 70 </form> 71 </div> 72 <?php 73 74 } 75 76 /** 77 * Register and add settings 78 */ 79 public function page_init() { 80 81 register_setting( 82 'posttypes_group', // Option group 83 'post_status_scheduler', //Option name 84 array( $this, 'sanitize' ) // Sanitize 85 ); 86 87 /* SECTION POSTTYPES */ 88 89 add_settings_section( 90 'posttypes', // ID 91 __( 'Post Types and meta keys', 'post-status-scheduler' ), // Title 92 array( $this, 'print_section_info' ), // Callback 93 'post-status-scheduler' // Page 94 ); 95 96 add_settings_field( 97 'allowed_posttypes', // ID 98 __( 'Check the post types you wish to display the Scheduler on', 'post-status-scheduler' ), // Title 99 array( $this, 'allowed_posttypes_callback' ), // Callback 100 'post-status-scheduler', // Page 101 'posttypes' // Section 102 ); 103 104 add_settings_field( 105 'meta_keys', // ID 106 __( 'Mark allowed meta fields to be shown as removable', 'post-status-scheduler' ), // Title 107 array( $this, 'metafield_callback' ), // Callback 108 'post-status-scheduler', // Page 109 'posttypes' // Section 110 ); 111 112 add_settings_field( 113 'categories_and_tags', // ID 114 __('Enable showing of both categories and tags or just one of them', 'post-status-scheduler'), // Title 115 array( $this, 'categories_and_tags_callback' ), // Callback 116 'post-status-scheduler', // Page 117 'posttypes' // Section 118 ); 119 120 121 /* SECTION NOTIFICATION EMAIL */ 122 123 add_settings_section( 124 'notifications', // ID 125 __( 'Notification', 'post-status-scheduler' ), // Title 126 array( $this, 'print_notification_section_info' ), // Callback 127 'post-status-scheduler' // Page 128 ); 129 130 add_settings_field( 131 'notification_email_enabled', // ID 132 __( 'Enable email notification option', 'post-status-scheduler' ), // Title 133 array( $this, 'notification_email_enabled_callback' ), // Callback 134 'post-status-scheduler', // Page 135 'notifications' // Section 136 ); 137 138 139 /* SECTION EXTRA COLUMN ON EDIT PAGE */ 140 141 add_settings_section( 142 'column', // ID 143 __( 'Extra column', 'post-status-scheduler' ), // Title 144 array( $this, 'print_column_section_info' ), // Callback 145 'post-status-scheduler' // Page 146 ); 147 148 add_settings_field( 149 'extra_column_enabled', // ID 150 __( 'Enable extra column on posttype edit page', 'post-status-scheduler' ), // Title 151 array( $this, 'extra_column_enabled_callback' ), // Callback 152 'post-status-scheduler', // Page 153 'column' // Section 154 ); 155 156 } 157 158 159 /** 160 * Sanitize each setting field as needed 161 * 162 * @param array $input Contains all settings fields as array keys 163 */ 164 public function sanitize( $input ) { 165 166 $new_input = array(); 167 if( isset( $input['allowed_posttypes'] ) ) { 168 169 if( count( $input['allowed_posttypes'] ) > 0 ) { 170 171 foreach( $input['allowed_posttypes'] as $key => $post_type ) { 172 173 $new_input['allowed_posttypes'][$key] = esc_attr( $post_type ); 174 175 } 176 177 } 178 179 } 180 181 if( isset( $input['meta_keys'] ) ) { 182 183 if( count( $input['meta_keys'] ) > 0 ) { 184 185 foreach( $input['meta_keys'] as $key => $meta_key ) { 186 187 $new_input['meta_keys'][$key] = esc_attr( $meta_key ); 188 189 } 190 191 } 192 193 } 194 195 if( isset( $input['categories_and_tags'] ) ) { 196 197 $new_input['categories_and_tags'] = $input['categories_and_tags']; 198 199 } 200 201 if( isset( $input['notification_email_enabled'] ) ) { 202 203 $new_input['notification_email_enabled'] = true; 204 205 } 206 207 if( isset( $input['extra_column_enabled'] ) ) { 208 209 $new_input['extra_column_enabled'] = true; 210 211 } 212 213 return $new_input; 214 215 } 216 217 218 /** 219 * Print the Section text 220 */ 221 public function print_section_info() { 222 223 print __( 'Enter your settings below:', 'post-status-scheduler' ); 224 225 } 226 227 228 /** 229 * Print the Section text 230 */ 231 public function print_notification_section_info() { 232 233 print __( 'Enabling this option makes it possible to send an email notification to the post author on a scheduled change execution.', 'post-status-scheduler' ); 234 235 } 236 237 238 /** 239 * Print the Section text 240 */ 241 public function print_column_section_info() { 242 243 print __( 'Settings for adding extra column "Scheduled date" on edit page. This column will only be displayed on posttypes that are allowed for scheduling', 'post-status-scheduler' ); 244 245 } 246 247 248 /** 249 * id_number_callback 250 * 251 * Callback for the posttypes allowed 252 */ 253 public function allowed_posttypes_callback() { 254 255 // Get all valid public post types 256 $post_types = get_post_types(); 257 258 $options = get_option( 'post_status_scheduler' ); 259 260 if( count( $post_types ) > 0 ) { 261 262 foreach( $post_types as $post_type ) { 263 264 if( !in_array( $post_type, $this->disallowed_posttypes ) ) { 265 266 $checked = ''; 267 if( isset( $options['allowed_posttypes'] ) && is_array( $options['allowed_posttypes'] ) && count( $options['allowed_posttypes'] ) > 0 ) { 268 if( in_array( $post_type, $options['allowed_posttypes'] ) ) { 269 270 $checked = 'checked="checked"'; 271 272 } 273 } 274 275 echo sprintf( '<input type="checkbox" name="post_status_scheduler[allowed_posttypes][%s]" value="%s" %s /> %s<br />', esc_attr( $post_type ), esc_attr( $post_type ), $checked, esc_attr( $post_type ) ); 276 277 } 278 279 } 280 281 } 282 283 } 284 285 286 /** 287 * metafield_callback 288 * 289 * Callback for the meta_keys allowed settings 290 */ 291 public function metafield_callback() { 292 global $wpdb; 293 294 $result = array(); 295 $keys = $wpdb->get_results( "SELECT DISTINCT(meta_key) FROM $wpdb->postmeta ORDER BY meta_key ASC" ); 296 297 if( count( $keys ) > 0 ) { 298 299 foreach( $keys as $key_result ) { 300 array_push( $result, $key_result->meta_key ); 301 } 302 303 } 304 305 $options = get_option( 'post_status_scheduler' ); 306 $chosen_meta_keys = isset( $options['meta_keys'] ) ? $options['meta_keys'] : array(); 307 308 ?> 309 <select name="post_status_scheduler[meta_keys][]" multiple> 310 <?php 311 foreach( $result as $key_name ) { 312 $selected = ''; 313 if( in_array( $key_name, $chosen_meta_keys ) ) { 314 $selected = ' selected="selected" '; 315 } 316 echo sprintf( '<option value="%s" %s >%s</option>', $key_name, $selected, $key_name ); 317 } 318 319 ?> 320 </select> 321 <?php 322 323 324 } 325 326 327 public function categories_and_tags_callback() { 328 $options = self::get_options(); 329 $enabled = !empty( $options['categories_and_tags'] ) ? $options['categories_and_tags'] : 'both'; 330 ?> 331 332 333 334 <input type="radio" id="categories_and_tags_both" name="post_status_scheduler[categories_and_tags]" value="both" <?php checked( $enabled, 'both' ); ?> /> 335 <label for="categories_and_tags_both"><?php _e( 'Both', 'post-status-scheduler' ); ?></label><br /> 336 337 <input type="radio" id="categories_and_tags_categories" name="post_status_scheduler[categories_and_tags]" value="categories" <?php checked( $enabled, 'categories' ); ?> /> 338 <label for="categories_and_tags_categories"><?php _e( 'Categories', 'post-status-scheduler' ); ?></label><br /> 339 340 <input type="radio" id="categories_and_tags_tags" name="post_status_scheduler[categories_and_tags]" value="tags" <?php checked( $enabled, 'tags' ); ?> /> 341 <label for="categories_and_tags_tags"><?php _e( 'Tags', 'post-status-scheduler' ); ?></label> 342 <?php 343 } 344 345 346 /** 347 * notification_email_enabled_callback 348 * 349 * Callback for the enabling of notification option 350 */ 351 public function notification_email_enabled_callback() { 352 353 $options = self::get_options(); 354 $enabled = !empty( $options['notification_email_enabled'] ) && $options['notification_email_enabled'] == true ? $options['notification_email_enabled'] : false; 355 ?> 356 357 <input type="checkbox" name="post_status_scheduler[notification_email_enabled]" <?php checked( $enabled, true ); ?> /> 358 359 <?php 360 } 361 362 363 /** 364 * notification_email_enabled_callback 365 * 366 * Callback for the enabling of notification option 367 */ 368 public function extra_column_enabled_callback() { 369 370 $options = self::get_options(); 371 $enabled = !empty( $options['extra_column_enabled'] ) && $options['extra_column_enabled'] == true ? $options['extra_column_enabled'] : false; 372 ?> 373 374 <input type="checkbox" name="post_status_scheduler[extra_column_enabled]" <?php checked( $enabled, true ); ?> /> 375 376 <?php 377 } 378 379 380 public static function get_options() { 381 382 return get_option('post_status_scheduler'); 383 384 } 385 386 } 3 /** 4 * Settings 5 * 6 * Settings class for the plugin Post Status Scheduler 7 * 8 * @author Andreas Färnstrand <andreas@farnstranddev.se> 9 * 10 * @todo Configure disallowed posttypes 11 */ 12 13 namespace post_status_scheduler; 14 15 class Settings { 16 17 /** 18 * Holds the values to be used in the fields callbacks 19 */ 20 private $options; 21 private $disallowed_posttypes = array(); 22 23 /** 24 * Start up 25 */ 26 public function __construct() { 27 28 // Add posttypes not allowed here 29 // This should probably be a config of some kind 30 $this->disallowed_posttypes = array( 'attachment' ); 31 32 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 33 add_action( 'admin_init', array( $this, 'page_init' ) ); 34 35 } 36 37 /** 38 * Add options page 39 */ 40 public function add_plugin_page() { 41 42 add_options_page( 43 'Settings Admin', 44 __( 'Post Status Scheduler', 'post-status-scheduler' ), 45 'manage_options', 46 'post-status-scheduler', 47 array( $this, 'create_admin_page' ) 48 ); 49 50 } 51 52 /** 53 * Options page callback 54 */ 55 public function create_admin_page() { 56 57 // Set class property 58 $this->options = get_option( 'post_status_scheduler' ); 59 ?> 60 <div class="wrap"> 61 <?php screen_icon(); ?> 62 <h2><?php _e( 'Post Status Scheduler', 'post-status-scheduler' ); ?></h2> 63 <form method="post" action="options.php"> 64 <?php 65 // This prints out all hidden setting fields 66 settings_fields( 'posttypes_group' ); 67 do_settings_sections( 'post-status-scheduler' ); 68 submit_button(); 69 ?> 70 </form> 71 </div> 72 <?php 73 74 } 75 76 /** 77 * Register and add settings 78 */ 79 public function page_init() { 80 81 register_setting( 82 'posttypes_group', // Option group 83 'post_status_scheduler', //Option name 84 array( $this, 'sanitize' ) // Sanitize 85 ); 86 87 /* SECTION POSTTYPES */ 88 89 add_settings_section( 90 'posttypes', // ID 91 __( 'Post Types and meta keys', 'post-status-scheduler' ), // Title 92 array( $this, 'print_section_info' ), // Callback 93 'post-status-scheduler' // Page 94 ); 95 96 add_settings_field( 97 'allowed_posttypes', // ID 98 __( 'Check the post types you wish to display the Scheduler on', 'post-status-scheduler' ), // Title 99 array( $this, 'allowed_posttypes_callback' ), // Callback 100 'post-status-scheduler', // Page 101 'posttypes' // Section 102 ); 103 104 add_settings_field( 105 'sticky_posttypes', 106 __( 'Check the post types you wish Stick/Unstick functionality on. Normally only post.', 'post-status-scheduler' ), 107 array( $this, 'sticky_posttypes_callback' ), 108 'post-status-scheduler', 109 'posttypes' 110 ); 111 112 add_settings_field( 113 'meta_keys', // ID 114 __( 'Mark allowed meta fields to be shown as removable', 'post-status-scheduler' ), // Title 115 array( $this, 'metafield_callback' ), // Callback 116 'post-status-scheduler', // Page 117 'posttypes' // Section 118 ); 119 120 add_settings_field( 121 'categories_and_tags', // ID 122 __( 'Enable showing of both categories and tags or just one of them', 'post-status-scheduler' ), // Title 123 array( $this, 'categories_and_tags_callback' ), // Callback 124 'post-status-scheduler', // Page 125 'posttypes' // Section 126 ); 127 128 129 /* SECTION NOTIFICATION EMAIL */ 130 131 add_settings_section( 132 'notifications', // ID 133 __( 'Notification', 'post-status-scheduler' ), // Title 134 array( $this, 'print_notification_section_info' ), // Callback 135 'post-status-scheduler' // Page 136 ); 137 138 add_settings_field( 139 'notification_email_enabled', // ID 140 __( 'Enable email notification option', 'post-status-scheduler' ), // Title 141 array( $this, 'notification_email_enabled_callback' ), // Callback 142 'post-status-scheduler', // Page 143 'notifications' // Section 144 ); 145 146 147 /* SECTION EXTRA COLUMN ON EDIT PAGE */ 148 149 add_settings_section( 150 'column', // ID 151 __( 'Extra column', 'post-status-scheduler' ), // Title 152 array( $this, 'print_column_section_info' ), // Callback 153 'post-status-scheduler' // Page 154 ); 155 156 add_settings_field( 157 'extra_column_enabled', // ID 158 __( 'Enable extra column on posttype edit page', 'post-status-scheduler' ), // Title 159 array( $this, 'extra_column_enabled_callback' ), // Callback 160 'post-status-scheduler', // Page 161 'column' // Section 162 ); 163 164 } 165 166 167 /** 168 * Sanitize each setting field as needed 169 * 170 * @param array $input Contains all settings fields as array keys 171 */ 172 public function sanitize( $input ) { 173 174 $new_input = array(); 175 if ( isset( $input['allowed_posttypes'] ) ) { 176 177 if ( count( $input['allowed_posttypes'] ) > 0 ) { 178 179 foreach ( $input['allowed_posttypes'] as $key => $post_type ) { 180 181 $new_input['allowed_posttypes'][ $key ] = esc_attr( $post_type ); 182 183 } 184 185 } 186 187 } 188 189 if ( isset( $input['sticky_posttypes'] ) ) { 190 191 if ( count( $input['sticky_posttypes'] ) > 0 ) { 192 193 foreach ( $input['sticky_posttypes'] as $key => $post_type ) { 194 195 $new_input['sticky_posttypes'][ $key ] = esc_attr( $post_type ); 196 197 } 198 199 } 200 201 } 202 203 if ( isset( $input['meta_keys'] ) ) { 204 205 if ( count( $input['meta_keys'] ) > 0 ) { 206 207 foreach ( $input['meta_keys'] as $key => $meta_key ) { 208 209 $new_input['meta_keys'][ $key ] = esc_attr( $meta_key ); 210 211 } 212 213 } 214 215 } 216 217 if ( isset( $input['categories_and_tags'] ) ) { 218 219 $new_input['categories_and_tags'] = $input['categories_and_tags']; 220 221 } 222 223 if ( isset( $input['notification_email_enabled'] ) ) { 224 225 $new_input['notification_email_enabled'] = true; 226 227 } 228 229 if ( isset( $input['extra_column_enabled'] ) ) { 230 231 $new_input['extra_column_enabled'] = true; 232 233 } 234 235 return $new_input; 236 237 } 238 239 240 /** 241 * Print the Section text 242 */ 243 public function print_section_info() { 244 245 print __( 'Enter your settings below:', 'post-status-scheduler' ); 246 247 } 248 249 250 /** 251 * Print the Section text 252 */ 253 public function print_notification_section_info() { 254 255 print __( 'Enabling this option makes it possible to send an email notification to the post author on a scheduled change execution.', 'post-status-scheduler' ); 256 257 } 258 259 260 /** 261 * Print the Section text 262 */ 263 public function print_column_section_info() { 264 265 print __( 'Settings for adding extra column "Scheduled date" on edit page. This column will only be displayed on posttypes that are allowed for scheduling', 'post-status-scheduler' ); 266 267 } 268 269 270 /** 271 * id_number_callback 272 * 273 * Callback for the posttypes allowed 274 */ 275 public function allowed_posttypes_callback() { 276 277 // Get all valid public post types 278 $post_types = get_post_types(); 279 280 $options = get_option( 'post_status_scheduler' ); 281 282 if ( count( $post_types ) > 0 ) { 283 284 foreach ( $post_types as $post_type ) { 285 286 if ( ! in_array( $post_type, $this->disallowed_posttypes ) ) { 287 288 $checked = ''; 289 if ( isset( $options['allowed_posttypes'] ) && is_array( $options['allowed_posttypes'] ) && count( $options['allowed_posttypes'] ) > 0 ) { 290 if ( in_array( $post_type, $options['allowed_posttypes'] ) ) { 291 292 $checked = 'checked="checked"'; 293 294 } 295 } 296 297 echo sprintf( '<input type="checkbox" name="post_status_scheduler[allowed_posttypes][%s]" value="%s" %s /> %s<br />', esc_attr( $post_type ), esc_attr( $post_type ), $checked, esc_attr( $post_type ) ); 298 299 } 300 301 } 302 303 } 304 305 } 306 307 308 public function sticky_posttypes_callback() { 309 310 // Get all valid public post types 311 $post_types = get_post_types(); 312 $options = get_option( 'post_status_scheduler' ); 313 314 if ( count( $post_types ) > 0 ) { 315 316 foreach ( $post_types as $post_type ) { 317 318 if ( ! in_array( $post_type, $this->disallowed_posttypes ) ) { 319 320 $checked = ''; 321 if ( isset( $options['sticky_posttypes'] ) && is_array( $options['sticky_posttypes'] ) && count( $options['sticky_posttypes'] ) > 0 ) { 322 if ( in_array( $post_type, $options['sticky_posttypes'] ) ) { 323 324 $checked = 'checked="checked"'; 325 326 } 327 } 328 329 echo sprintf( '<input type="checkbox" name="post_status_scheduler[sticky_posttypes][%s]" value="%s" %s /> %s<br />', esc_attr( $post_type ), esc_attr( $post_type ), $checked, esc_attr( $post_type ) ); 330 331 } 332 333 } 334 335 } 336 337 } 338 339 340 /** 341 * metafield_callback 342 * 343 * Callback for the meta_keys allowed settings 344 */ 345 public function metafield_callback() { 346 global $wpdb; 347 348 $result = array(); 349 $keys = $wpdb->get_results( "SELECT DISTINCT(meta_key) FROM $wpdb->postmeta ORDER BY meta_key ASC" ); 350 351 if ( count( $keys ) > 0 ) { 352 353 foreach ( $keys as $key_result ) { 354 array_push( $result, $key_result->meta_key ); 355 } 356 357 } 358 359 $options = get_option( 'post_status_scheduler' ); 360 $chosen_meta_keys = isset( $options['meta_keys'] ) ? $options['meta_keys'] : array(); 361 362 ?> 363 <select name="post_status_scheduler[meta_keys][]" multiple> 364 <?php 365 foreach ( $result as $key_name ) { 366 $selected = ''; 367 if ( in_array( $key_name, $chosen_meta_keys ) ) { 368 $selected = ' selected="selected" '; 369 } 370 echo sprintf( '<option value="%s" %s >%s</option>', $key_name, $selected, $key_name ); 371 } 372 373 ?> 374 </select> 375 <?php 376 377 378 } 379 380 381 public function categories_and_tags_callback() { 382 $options = self::get_options(); 383 $enabled = ! empty( $options['categories_and_tags'] ) ? $options['categories_and_tags'] : 'both'; 384 ?> 385 386 387 <input type="radio" id="categories_and_tags_both" name="post_status_scheduler[categories_and_tags]" 388 value="both" <?php checked( $enabled, 'both' ); ?> /> 389 <label for="categories_and_tags_both"><?php _e( 'Both', 'post-status-scheduler' ); ?></label><br/> 390 391 <input type="radio" id="categories_and_tags_categories" name="post_status_scheduler[categories_and_tags]" 392 value="categories" <?php checked( $enabled, 'categories' ); ?> /> 393 <label for="categories_and_tags_categories"><?php _e( 'Categories', 'post-status-scheduler' ); ?></label><br/> 394 395 <input type="radio" id="categories_and_tags_tags" name="post_status_scheduler[categories_and_tags]" 396 value="tags" <?php checked( $enabled, 'tags' ); ?> /> 397 <label for="categories_and_tags_tags"><?php _e( 'Tags', 'post-status-scheduler' ); ?></label> 398 <?php 399 } 400 401 402 /** 403 * notification_email_enabled_callback 404 * 405 * Callback for the enabling of notification option 406 */ 407 public function notification_email_enabled_callback() { 408 409 $options = self::get_options(); 410 $enabled = ! empty( $options['notification_email_enabled'] ) && $options['notification_email_enabled'] == true ? $options['notification_email_enabled'] : false; 411 ?> 412 413 <input type="checkbox" 414 name="post_status_scheduler[notification_email_enabled]" <?php checked( $enabled, true ); ?> /> 415 416 <?php 417 } 418 419 420 /** 421 * notification_email_enabled_callback 422 * 423 * Callback for the enabling of notification option 424 */ 425 public function extra_column_enabled_callback() { 426 427 $options = self::get_options(); 428 $enabled = ! empty( $options['extra_column_enabled'] ) && $options['extra_column_enabled'] == true ? $options['extra_column_enabled'] : false; 429 ?> 430 431 <input type="checkbox" name="post_status_scheduler[extra_column_enabled]" <?php checked( $enabled, true ); ?> /> 432 433 <?php 434 } 435 436 437 public static function get_options() { 438 439 return get_option( 'post_status_scheduler' ); 440 441 } 442 443 } 387 444 388 445 ?> -
post-status-scheduler/trunk/languages/post-status-scheduler-sv_SE.pot
r1447443 r1659976 1 #, fuzzy 1 2 msgid "" 2 3 msgstr "" 3 4 "Project-Id-Version: post-status-scheduler\n" 4 "POT-Creation-Date: 201 6-07-01 21:50+0200\n"5 "POT-Creation-Date: 2017-05-18 10:10+0200\n" 5 6 "PO-Revision-Date: 2016-07-01 21:55+0200\n" 6 7 "Last-Translator: Andeas Färnstrand <andreas@farnstranddev.se>\n" … … 10 11 "Content-Type: text/plain; charset=UTF-8\n" 11 12 "Content-Transfer-Encoding: 8bit\n" 12 "X-Generator: Poedit 1.8.8\n"13 "X-Generator: Poedit 2.0.1\n" 13 14 "X-Poedit-KeywordsList: __;_e\n" 14 15 "X-Poedit-Basepath: ..\n" … … 17 18 #: classes/email.php:25 18 19 msgid "Post Status Scheduler update" 19 msgstr " Uppdatering Post Status Scheduler"20 msgstr "" 20 21 21 22 #: classes/email.php:33 22 23 msgid "A scheduled update has been executed at" 23 msgstr " En schemalagd ändring har blivit exekverad"24 msgstr "" 24 25 25 26 #: classes/email.php:33 26 27 msgid "on your post" 27 msgstr " på din post"28 msgstr "" 28 29 29 30 #: classes/email.php:34 30 31 msgid "Regards" 31 msgstr " Hälsningar"32 msgstr "" 32 33 33 #: classes/scheduler.php:5 1734 #: classes/scheduler.php:561 34 35 msgid "Schedule Status Change" 35 msgstr " Schemalägg statusändring"36 msgstr "" 36 37 37 #: classes/scheduler.php:5 1938 #: classes/scheduler.php:563 38 39 msgid "Date" 39 msgstr " Datum"40 msgstr "" 40 41 41 #: classes/scheduler.php:5 2142 #: classes/scheduler.php:565 42 43 msgid "Time" 43 msgstr " Tid"44 msgstr "" 44 45 45 #: classes/scheduler.php:5 2546 #: classes/scheduler.php:569 46 47 msgid "Change status" 47 msgstr " Ändra status"48 msgstr "" 48 49 49 #: classes/scheduler.php:5 2750 #: classes/scheduler.php:571 50 51 msgid "Set status to" 51 msgstr " Ändra status till"52 msgstr "" 52 53 53 #: classes/scheduler.php:542 54 #: classes/scheduler.php:588 classes/scheduler.php:594 55 msgid "Stick" 56 msgstr "" 57 58 #: classes/scheduler.php:590 classes/scheduler.php:592 59 msgid "Unstick" 60 msgstr "" 61 62 #: classes/scheduler.php:607 54 63 msgid "Change categories and tags" 55 msgstr " Ändra kategorier och taggar"64 msgstr "" 56 65 57 #: classes/scheduler.php: 54466 #: classes/scheduler.php:609 58 67 msgid "The post will have the following categories on scheduled time" 59 msgstr " Följande kategorier kommer att sättas vid schemalagd tid"68 msgstr "" 60 69 61 #: classes/scheduler.php: 576 classes/settings.php:33870 #: classes/scheduler.php:641 classes/settings.php:392 62 71 msgid "Categories" 63 msgstr " Kategorier"72 msgstr "" 64 73 65 #: classes/scheduler.php: 598 classes/settings.php:34174 #: classes/scheduler.php:665 classes/settings.php:395 66 75 msgid "Tags" 67 msgstr " Taggar"76 msgstr "" 68 77 69 #: classes/scheduler.php:6 2378 #: classes/scheduler.php:690 70 79 msgid "Remove postmeta" 71 msgstr " Ta bort postmeta"80 msgstr "" 72 81 73 #: classes/scheduler.php: 65182 #: classes/scheduler.php:720 74 83 msgid "Send email notification on change" 75 msgstr " Skicka epostnotifiering vid ändring"84 msgstr "" 76 85 77 #: classes/scheduler.php: 67686 #: classes/scheduler.php:745 78 87 msgid "Scheduled date" 79 msgstr " Schemalagt datum"88 msgstr "" 80 89 81 #: classes/scheduler.php: 88290 #: classes/scheduler.php:951 82 91 msgid "Draft" 83 msgstr " Utkast"92 msgstr "" 84 93 85 #: classes/scheduler.php: 88394 #: classes/scheduler.php:952 86 95 msgid "Pending" 87 msgstr " Väntar på granskning"96 msgstr "" 88 97 89 #: classes/scheduler.php: 88498 #: classes/scheduler.php:953 90 99 msgid "Private" 91 msgstr " Privat"100 msgstr "" 92 101 93 #: classes/scheduler.php: 885102 #: classes/scheduler.php:954 94 103 msgid "Trashbin" 95 msgstr " Papperskorg"104 msgstr "" 96 105 97 #: classes/scheduler.php: 886106 #: classes/scheduler.php:955 98 107 msgid "Delete (forced)" 99 msgstr " Radera (tvingad)"108 msgstr "" 100 109 101 110 #: classes/settings.php:44 classes/settings.php:62 102 111 msgid "Post Status Scheduler" 103 msgstr " Post Status Scheduler"112 msgstr "" 104 113 105 114 #: classes/settings.php:91 106 115 msgid "Post Types and meta keys" 107 msgstr " Posttyper och metakeys"116 msgstr "" 108 117 109 118 #: classes/settings.php:98 110 119 msgid "Check the post types you wish to display the Scheduler on" 111 msgstr " Kryssa i de posttyper som du vill visa schemaläggaren på"120 msgstr "" 112 121 113 122 #: classes/settings.php:106 114 msgid "Mark allowed meta fields to be shown as removable" 115 msgstr "Märk de metafält som skall vara valbara för borttagning" 123 msgid "" 124 "Check the post types you wish Stick/Unstick functionality on. Normally only " 125 "post." 126 msgstr "" 116 127 117 128 #: classes/settings.php:114 129 msgid "Mark allowed meta fields to be shown as removable" 130 msgstr "" 131 132 #: classes/settings.php:122 118 133 msgid "Enable showing of both categories and tags or just one of them" 119 msgstr " Aktivera visning av både kategorier och taggar eller bara en av dem"134 msgstr "" 120 135 121 #: classes/settings.php:1 25136 #: classes/settings.php:133 122 137 msgid "Notification" 123 msgstr " Notifikation"138 msgstr "" 124 139 125 #: classes/settings.php:1 32140 #: classes/settings.php:140 126 141 msgid "Enable email notification option" 127 msgstr " Aktivera epostnotifiering"142 msgstr "" 128 143 129 #: classes/settings.php:1 43144 #: classes/settings.php:151 130 145 msgid "Extra column" 131 msgstr " Extra kolumn"146 msgstr "" 132 147 133 #: classes/settings.php:15 0148 #: classes/settings.php:158 134 149 msgid "Enable extra column on posttype edit page" 135 msgstr " Aktivera extrakolumn på posttypens listsida"150 msgstr "" 136 151 137 #: classes/settings.php:2 23152 #: classes/settings.php:245 138 153 msgid "Enter your settings below:" 139 msgstr " Ange inställningar nedan:"154 msgstr "" 140 155 141 #: classes/settings.php:2 33156 #: classes/settings.php:255 142 157 msgid "" 143 158 "Enabling this option makes it possible to send an email notification to the " 144 159 "post author on a scheduled change execution." 145 160 msgstr "" 146 "Aktivering av detta alternativ gör det möjligt att skicka en "147 "epostnotifiering till inläggsförfattaren när en schemalagd ändring "148 "inträffar."149 161 150 #: classes/settings.php:2 43162 #: classes/settings.php:265 151 163 msgid "" 152 164 "Settings for adding extra column \"Scheduled date\" on edit page. This " 153 165 "column will only be displayed on posttypes that are allowed for scheduling" 154 166 msgstr "" 155 "Inställningar för att lägga till en extrakolumn \"Schemalagt datum\" på "156 "listsida. Kolumnen visas bara på posttyper som är tillåtna för "157 "schemaläggning"158 167 159 #: classes/settings.php:3 35168 #: classes/settings.php:389 160 169 msgid "Both" 161 msgstr " Bägge"170 msgstr "" 162 171 163 172 #~ msgid "Change categories" -
post-status-scheduler/trunk/post-status-scheduler.php
r1658384 r1659976 2 2 3 3 4 /* 5 Plugin Name: Post Status Scheduler 6 Description: Change status, category or postmeta of any post type at a scheduled timestamp. 7 Version: 1.2.11 8 Author: Andreas Färnstrand <andreas@farnstranddev.se> 9 Author URI: http://www.farnstranddev.se 10 Text Domain: post-status-scheduler 11 */ 12 13 14 /* Copyright 2014 Andreas Färnstrand (email : andreas@farnstranddev.se) 15 16 This program is free software; you can redistribute it and/or modify 17 it under the terms of the GNU General Public License, version 2, as 18 published by the Free Software Foundation. 19 20 This program is distributed in the hope that it will be useful, 21 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 GNU General Public License for more details. 24 25 You should have received a copy of the GNU General Public License 26 along with this program; if not, write to the Free Software 27 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 4 /* 5 Plugin Name: Post Status Scheduler 6 Description: Change status, category or postmeta of any post type at a scheduled timestamp. 7 Version: 1.3.0 8 Author: Andreas Färnstrand <andreas@farnstranddev.se> 9 Author URI: http://www.farnstranddev.se 10 Text Domain: post-status-scheduler 28 11 */ 29 12 30 // Exit if accessed directly31 if ( !defined( 'ABSPATH' ) ) exit;32 13 33 use post_status_scheduler as post_status_scheduler; 14 /* Copyright 2014 Andreas Färnstrand (email : andreas@farnstranddev.se) 34 15 35 if( !class_exists( 'Post_Status_Scheduler' ) ) { 16 This program is free software; you can redistribute it and/or modify 17 it under the terms of the GNU General Public License, version 2, as 18 published by the Free Software Foundation. 36 19 37 require_once 'classes/settings.php'; 38 require_once 'classes/scheduler.php'; 39 require_once 'classes/shortcode.php'; 20 This program is distributed in the hope that it will be useful, 21 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 GNU General Public License for more details. 40 24 41 if( !defined( 'POST_STATUS_SCHEDULER_PLUGIN_PATH' ) ) define( 'POST_STATUS_SCHEDULER_PLUGIN_PATH', plugin_dir_url( __FILE__ ) );42 if( !defined( 'POST_STATUS_SCHEDULER_TEXTDOMAIN' ) ) define( 'POST_STATUS_SCHEDULER_TEXTDOMAIN', 'post-status-scheduler' );43 if( !defined( 'POST_STATUS_SCHEDULER_TEXTDOMAIN_PATH' ) ) define( 'POST_STATUS_SCHEDULER_TEXTDOMAIN_PATH', dirname( plugin_basename( __FILE__) ) .'/languages' );44 if( !defined( 'POST_STATUS_SCHEDULER_VERSION' ) ) define( 'POST_STATUS_SCHEDULER_VERSION', '1.2.11' ); 25 You should have received a copy of the GNU General Public License 26 along with this program; if not, write to the Free Software 27 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 28 */ 45 29 46 // Create a new scheduler instance 47 $pss = new \post_status_scheduler\Scheduler(); 30 // Exit if accessed directly 31 if ( ! defined( 'ABSPATH' ) ) { 32 exit; 33 } 48 34 49 // Create a new settings instance 50 if( is_admin() ) { 51 $settings = new \post_status_scheduler\Settings(); 52 } 35 use post_status_scheduler as post_status_scheduler; 53 36 54 // Create shortcodes 55 $pss_shortcodes = new \post_status_scheduler\Shortcode(); 37 if ( ! class_exists( 'Post_Status_Scheduler' ) ) { 56 38 57 } 39 require_once 'classes/settings.php'; 40 require_once 'classes/scheduler.php'; 41 require_once 'classes/shortcode.php'; 42 43 if ( ! defined( 'POST_STATUS_SCHEDULER_PLUGIN_PATH' ) ) { 44 define( 'POST_STATUS_SCHEDULER_PLUGIN_PATH', plugin_dir_url( __FILE__ ) ); 45 } 46 if ( ! defined( 'POST_STATUS_SCHEDULER_TEXTDOMAIN' ) ) { 47 define( 'POST_STATUS_SCHEDULER_TEXTDOMAIN', 'post-status-scheduler' ); 48 } 49 if ( ! defined( 'POST_STATUS_SCHEDULER_TEXTDOMAIN_PATH' ) ) { 50 define( 'POST_STATUS_SCHEDULER_TEXTDOMAIN_PATH', dirname( plugin_basename( __FILE__ ) ) . '/languages' ); 51 } 52 if ( ! defined( 'POST_STATUS_SCHEDULER_VERSION' ) ) { 53 define( 'POST_STATUS_SCHEDULER_VERSION', '1.3.0' ); 54 } 55 56 // Create a new scheduler instance 57 $pss = new \post_status_scheduler\Scheduler(); 58 59 // Create a new settings instance 60 if ( is_admin() ) { 61 $settings = new \post_status_scheduler\Settings(); 62 } 63 64 // Create shortcodes 65 $pss_shortcodes = new \post_status_scheduler\Shortcode(); 66 67 } 58 68 59 69 -
post-status-scheduler/trunk/readme.txt
r1658384 r1659976 4 4 Requires at least: 3.9 5 5 Tested up to: 4.7.3 6 Stable tag: 1. 2.116 Stable tag: 1.3.0 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 53 53 == Changelog == 54 54 55 = 1.3.0 = 56 * New feature to schedule sticky posts or schedule unsticking of post. 57 55 58 = 1.2.11 = 56 59 * Fixed bug on when creating new posts and no previous post object exists. … … 99 102 == Upgrade Notice == 100 103 104 = 1.3.0 = 105 * If you wish to have the possibility to schedule sticky posts or unsticking of sticky posts then 1.3.0 is for you. 106 101 107 = 1.2.11 = 102 108 * Now loads jquery ui through https.
Note: See TracChangeset
for help on using the changeset viewer.