Changeset 2882680
- Timestamp:
- 03/18/2023 05:04:28 PM (3 years ago)
- Location:
- notify-events/trunk
- Files:
-
- 7 edited
-
models/Alert.php (modified) (6 diffs)
-
models/Channel.php (modified) (1 diff)
-
models/Core.php (modified) (2 diffs)
-
modules/wordpress/tags/Post.php (modified) (1 diff)
-
modules/wordpress/tags/User.php (modified) (1 diff)
-
notify-events.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
notify-events/trunk/models/Alert.php
r2383243 r2882680 6 6 * Class Alert 7 7 * @package notify_events\models 8 * 9 * @property int $id 10 * @property string $type 11 * @property string $title 8 12 */ 9 class Alert 13 class Alert extends PostModel 10 14 { 15 const TYPE_ERROR = 'error'; 16 const TYPE_WARNING = 'warning'; 17 const TYPE_SUCCESS = 'success'; 18 const TYPE_INFO = 'info'; 19 20 const TYPES = [ 21 self::TYPE_ERROR, 22 self::TYPE_WARNING, 23 self::TYPE_SUCCESS, 24 self::TYPE_INFO, 25 ]; 26 27 /** 28 * @inheritDoc 29 */ 30 public static function post_type() 31 { 32 return 'wpne_alert'; 33 } 34 35 /** 36 * @inheritDoc 37 */ 38 public static function fields() 39 { 40 return array_merge(parent::fields(), [ 41 'type', 42 ]); 43 } 44 45 /** 46 * @inheritDoc 47 */ 48 public static function field_assign() 49 { 50 return array_merge(parent::field_assign(), [ 51 'type' => 'post_content', 52 ]); 53 } 54 55 /** 56 * @inheritDoc 57 */ 58 public static function rules() 59 { 60 return array_merge(parent::rules(), [ 61 'type' => [ 62 ['required'], 63 ['strip_tags'], 64 ['trim'], 65 ['in', 'range' => self::TYPES], 66 ], 67 ]); 68 } 69 11 70 /** 12 71 * … … 14 73 public static function display() 15 74 { 16 if (!array_key_exists('_wpne_alert', $_SESSION)) { 17 return; 75 $alerts = self::find(); 76 77 foreach ($alerts as $alert) { 78 echo sprintf('<div class="notice notice-%s is-dismissible"><p>%s</p></div>', esc_attr($alert->type), esc_html($alert->title)); 79 80 $alert->delete(); 18 81 } 82 } 19 83 20 $alert = $_SESSION['_wpne_alert']; 84 /** 85 * @param $type 86 * @param $message 87 * @return void 88 */ 89 protected static function alert($type, $message) 90 { 91 $alert = new self(); 92 $alert->type = $type; 93 $alert->title = $message; 21 94 22 unset($_SESSION['_wpne_alert']); 23 24 echo sprintf('<div class="notice notice-%s is-dismissible"><p>%s</p></div>', esc_attr($alert['type']), esc_html($alert['message'])); 95 $alert->save(); 25 96 } 26 97 … … 30 101 public static function error($message) 31 102 { 32 $_SESSION['_wpne_alert'] = [ 33 'type' => 'error', 34 'message' => $message, 35 ]; 103 self::alert(self::TYPE_ERROR, $message); 36 104 } 37 105 … … 41 109 public static function warning($message) 42 110 { 43 $_SESSION['_wpne_alert'] = [ 44 'type' => 'warning', 45 'message' => $message, 46 ]; 111 self::alert(self::TYPE_WARNING, $message); 47 112 } 48 113 … … 52 117 public static function success($message) 53 118 { 54 $_SESSION['_wpne_alert'] = [ 55 'type' => 'success', 56 'message' => $message, 57 ]; 119 self::alert(self::TYPE_SUCCESS, $message); 58 120 } 59 121 … … 63 125 public static function info($message) 64 126 { 65 $_SESSION['_wpne_alert'] = [ 66 'type' => 'info', 67 'message' => $message, 68 ]; 127 self::alert(self::TYPE_INFO, $message); 69 128 } 70 129 } -
notify-events/trunk/models/Channel.php
r2383243 r2882680 5 5 /** 6 6 * Class Channel 7 * @package notify_events 7 * @package notify_events\models 8 8 * 9 9 * @property int $id -
notify-events/trunk/models/Core.php
r2856139 r2882680 35 35 public function __construct() 36 36 { 37 if (!session_id()) {38 session_start();39 }40 41 37 if (is_admin()) { 42 38 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 39 40 add_action('init', function() { 41 ob_start(); 42 }); 43 43 44 44 add_filter('plugin_action_links', [$this, 'plugin_action_links'], 10, 2); … … 46 46 47 47 add_action('admin_menu', function() { 48 ob_start();49 50 48 add_options_page(__('Notify.Events', WPNE), __('Notify.Events', WPNE), 'manage_options', WPNE, [$this, 'route']); 51 49 }); 50 51 Alert::register_post_type(); 52 52 } 53 53 -
notify-events/trunk/modules/wordpress/tags/Post.php
r2432603 r2882680 34 34 public static function values($post) 35 35 { 36 return[36 $result = [ 37 37 'post-id' => $post->ID, 38 'post-type' => get_post_type_object($post->post_type)->label,39 'post-status' => get_post_status_object($post->post_status)->label,40 38 'post-title' => $post->post_title, 41 39 'post-permalink' => get_post_permalink($post), 42 'post-category' => get_category($post->post_category)->name,43 40 'post-excerpt' => $post->post_excerpt, 44 41 'post-date' => $post->post_date, 45 42 ]; 43 44 $post_type_object = get_post_type_object($post->post_type); 45 46 if ($post_type_object) { 47 $result['post-type'] = $post_type_object->label; 48 } 49 50 $post_status_object = get_post_status_object($post->post_status); 51 52 if ($post_status_object) { 53 $result['post-status'] = $post_status_object->label; 54 } 55 56 $category = isset($post->post_category[0]) ? get_category($post->post_category[0]) : null; 57 58 if ($category) { 59 $result['post-category'] = $category->name; 60 } 61 62 return $result; 46 63 } 47 64 -
notify-events/trunk/modules/wordpress/tags/User.php
r2432603 r2882680 35 35 public static function values($user, $prefix = 'user-') 36 36 { 37 if (!$user) { 38 return []; 39 } 40 37 41 return [ 38 42 $prefix . 'id' => $user->ID, -
notify-events/trunk/notify-events.php
r2856139 r2882680 6 6 Author: Notify.Events 7 7 Author URI: https://notify.events/ 8 Version: 1.3. 28 Version: 1.3.3 9 9 License: GPL-2.0 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
notify-events/trunk/readme.txt
r2856139 r2882680 4 4 Requires at least: 5.3 5 5 Requires PHP: 5.6 6 Tested up to: 6. 1.17 Stable tag: 1.3. 26 Tested up to: 6.2 7 Stable tag: 1.3.3 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.