Plugin Directory

Changeset 2882680


Ignore:
Timestamp:
03/18/2023 05:04:28 PM (3 years ago)
Author:
notifyevents
Message:

Bugfix + tested up 6.2

Location:
notify-events/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • notify-events/trunk/models/Alert.php

    r2383243 r2882680  
    66 * Class Alert
    77 * @package notify_events\models
     8 *
     9 * @property int    $id
     10 * @property string $type
     11 * @property string $title
    812 */
    9 class Alert
     13class Alert extends PostModel
    1014{
     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
    1170    /**
    1271     *
     
    1473    public static function display()
    1574    {
    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();
    1881        }
     82    }
    1983
    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;
    2194
    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();
    2596    }
    2697
     
    30101    public static function error($message)
    31102    {
    32         $_SESSION['_wpne_alert'] = [
    33             'type'    => 'error',
    34             'message' => $message,
    35         ];
     103        self::alert(self::TYPE_ERROR, $message);
    36104    }
    37105
     
    41109    public static function warning($message)
    42110    {
    43         $_SESSION['_wpne_alert'] = [
    44             'type'    => 'warning',
    45             'message' => $message,
    46         ];
     111        self::alert(self::TYPE_WARNING, $message);
    47112    }
    48113
     
    52117    public static function success($message)
    53118    {
    54         $_SESSION['_wpne_alert'] = [
    55             'type'    => 'success',
    56             'message' => $message,
    57         ];
     119        self::alert(self::TYPE_SUCCESS, $message);
    58120    }
    59121
     
    63125    public static function info($message)
    64126    {
    65         $_SESSION['_wpne_alert'] = [
    66             'type'    => 'info',
    67             'message' => $message,
    68         ];
     127        self::alert(self::TYPE_INFO, $message);
    69128    }
    70129}
  • notify-events/trunk/models/Channel.php

    r2383243 r2882680  
    55/**
    66 * Class Channel
    7  * @package notify_events
     7 * @package notify_events\models
    88 *
    99 * @property int    $id
  • notify-events/trunk/models/Core.php

    r2856139 r2882680  
    3535    public function __construct()
    3636    {
    37         if (!session_id()) {
    38             session_start();
    39         }
    40 
    4137        if (is_admin()) {
    4238            require_once ABSPATH . 'wp-admin/includes/plugin.php';
     39
     40            add_action('init', function() {
     41                ob_start();
     42            });
    4343
    4444            add_filter('plugin_action_links', [$this, 'plugin_action_links'], 10, 2);
     
    4646
    4747            add_action('admin_menu', function() {
    48                 ob_start();
    49 
    5048                add_options_page(__('Notify.Events', WPNE), __('Notify.Events', WPNE), 'manage_options', WPNE, [$this, 'route']);
    5149            });
     50
     51            Alert::register_post_type();
    5252        }
    5353
  • notify-events/trunk/modules/wordpress/tags/Post.php

    r2432603 r2882680  
    3434    public static function values($post)
    3535    {
    36         return [
     36        $result = [
    3737            '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,
    4038            'post-title'     => $post->post_title,
    4139            'post-permalink' => get_post_permalink($post),
    42             'post-category'  => get_category($post->post_category)->name,
    4340            'post-excerpt'   => $post->post_excerpt,
    4441            'post-date'      => $post->post_date,
    4542        ];
     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;
    4663    }
    4764
  • notify-events/trunk/modules/wordpress/tags/User.php

    r2432603 r2882680  
    3535    public static function values($user, $prefix = 'user-')
    3636    {
     37        if (!$user) {
     38            return [];
     39        }
     40
    3741        return [
    3842            $prefix . 'id'         => $user->ID,
  • notify-events/trunk/notify-events.php

    r2856139 r2882680  
    66Author: Notify.Events
    77Author URI: https://notify.events/
    8 Version: 1.3.2
     8Version: 1.3.3
    99License: GPL-2.0
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • notify-events/trunk/readme.txt

    r2856139 r2882680  
    44Requires at least: 5.3
    55Requires PHP: 5.6
    6 Tested up to: 6.1.1
    7 Stable tag: 1.3.2
     6Tested up to: 6.2
     7Stable tag: 1.3.3
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.