/** * * * @see WP_List_Table::::single_row_columns() * @param array $item A singular item (one full row's worth of data) * @return string Text to be placed inside the column <td> (movie title only) */ function column_title($item) { $notification_id = array_search($item->ID, get_option(SI_Notifications::NOTIFICATIONS_OPTION_NAME, array())); $name = $notification_id ? SI_Notifications::$notifications[$notification_id]['name'] : si__('Unassigned'); $notification = SI_Notification::get_instance($item->ID); $status = $notification->get_disabled() ? '<span style="color:red">' . si__('disabled') . '</span>' : '<span>' . si__('active') . '</span>'; //Build row actions $actions = array('edit' => sprintf('<a href="%s">Edit</a>', get_edit_post_link($item->ID))); //Return the title contents return sprintf('%1$s <span style="color:silver">(status: %2$s)</span>%3$s', $name, $status, $this->row_actions($actions)); }
/** * Get notification instance. * @param string $notification the slug for the notification * @return SI_Notification/false */ public static function get_notification_instance($notification) { if (isset(self::$notifications[$notification])) { $notifications = get_option(self::NOTIFICATIONS_OPTION_NAME); if (isset($notifications[$notification])) { $notification_id = $notifications[$notification]; $notification = SI_Notification::get_instance($notification_id); if ($notification != null) { $post = $notification->get_post(); // Don't return the notification if isn't published (excludes deleted, draft, and future posts) if ('publish' == $post->post_status) { return $notification; } } } } return null; // return null and not a boolean for the sake of validity checks elsewhere }
public static function load_templates() { $notifications = apply_filters('sprout_notifications', array()); foreach ($notifications as $notification_id => $data) { // Find existing notification $notification = SI_Notifications_Control::get_notification_instance($notification_id); // Delete all the existing notifications if (is_a($notification, 'SI_Notification')) { wp_delete_post($notification->get_id(), true); } // Create new notification with new content $post_id = wp_insert_post(array('post_status' => 'publish', 'post_type' => SI_Notification::POST_TYPE, 'post_title' => $data['default_title'], 'post_content' => self::notification_content($notification_id))); $notification = SI_Notification::get_instance($post_id); SI_Notifications_Control::save_meta_box_notification_submit($post_id, $notification->get_post(), array(), $notification_id); // Don't allow for a notification to enabled if specifically shouldn't if (isset($data['always_disabled']) && $data['always_disabled']) { $notification->set_disabled('TRUE'); } update_option(SI_Notifications_Control::EMAIL_FORMAT, 'HTML'); } }