Plugin Directory

Changeset 2349284


Ignore:
Timestamp:
07/30/2020 06:45:49 PM (6 years ago)
Author:
firetree
Message:

Update to version 1.1.0 from GitHub

Location:
hey-notify
Files:
33 added
36 edited
1 copied

Legend:

Unmodified
Added
Removed
  • hey-notify/assets/banner-1544x500-rtl.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • hey-notify/assets/banner-1544x500.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • hey-notify/assets/banner-772x250-rtl.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • hey-notify/assets/banner-772x250.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • hey-notify/assets/icon-128x128.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • hey-notify/assets/icon-256x256.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • hey-notify/tags/1.1.0/hey-notify.php

    r2345565 r2349284  
    44 * Plugin URI: https://heynotifywp.com/
    55 * Description: Get notified when things happen in WordPress.
    6  * Version: 1.0.0
     6 * Version: 1.1.0
    77 * Author: FireTree Design, LLC <info@firetreedesign.com>
    88 * Author URI: https://firetreedesign.com/
     
    1919}
    2020
    21 define( 'HEY_NOTIFY_VERSION', '1.0.0' );
     21define( 'HEY_NOTIFY_VERSION', '1.1.0' );
    2222define( 'HEY_NOTIFY_PLUGIN_FILE', __FILE__ );
    2323define( 'HEY_NOTIFY_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
     
    3636require_once HEY_NOTIFY_PLUGIN_DIR . 'includes/events/post/loader.php';
    3737require_once HEY_NOTIFY_PLUGIN_DIR . 'includes/events/page/loader.php';
     38require_once HEY_NOTIFY_PLUGIN_DIR . 'includes/events/comment/loader.php';
     39require_once HEY_NOTIFY_PLUGIN_DIR . 'includes/events/user/loader.php';
     40require_once HEY_NOTIFY_PLUGIN_DIR . 'includes/events/system/loader.php';
    3841
    3942// Services.
  • hey-notify/tags/1.1.0/includes/class-hook.php

    r2345565 r2349284  
    5656        );
    5757
    58         $new_data = wp_parse_args( $data, $defaults );
     58        $message = \wp_parse_args( $data, $defaults );
    5959
    60         do_action(
    61             'hey_notify_send_message',
    62             array(
    63                 'notification' => $this->notification,
    64                 'subject'      => $new_data['subject'],
    65                 'title'        => $new_data['title'],
    66                 'url'          => $new_data['url'],
    67                 'image'        => $new_data['image'],
    68                 'content'      => $new_data['content'],
    69                 'fields'       => $new_data['fields'],
    70                 'footer'       => $new_data['footer'],
    71             )
     60        $service = \carbon_get_post_meta( $this->notification->ID, 'hey_notify_service' );
     61
     62        \do_action(
     63            "hey_notify_send_message_{$service}",
     64            $message, // Message.
     65            'core', // Trigger.
     66            $this->notification // Data.
    7267        );
    7368    }
  • hey-notify/tags/1.1.0/includes/class-service.php

    r2345565 r2349284  
    1919
    2020    /**
    21      * Class constructor
     21     * Class construct
     22     *
     23     * @return void
    2224     */
    2325    public function __construct() {
    2426        add_filter( 'hey_notify_service_fields', array( $this, 'fields' ), 10 );
    2527        add_filter( 'hey_notify_services_options', array( $this, 'services' ), 10 );
    26         add_action( 'hey_notify_send_message', array( $this, 'send' ), 10, 1 );
    2728    }
    2829
     
    4748    }
    4849
    49     /**
    50      * Send the message
    51      *
    52      * @param array $message Message.
    53      * @return void
    54      */
    55     public function send( $message ) {
    56         // Do something.
    57     }
    58 
    5950}
  • hey-notify/tags/1.1.0/includes/cpt.php

    r2345565 r2349284  
    120120    switch ( $column_name ) {
    121121        case 'service':
    122             $services = \apply_filters( 'hey_notify_services_options', array() );
    123             $service  = \carbon_get_post_meta( $post_id, 'hey_notify_service' );
    124             echo "<img src='" . esc_attr( $services[ $service ] ) . "' style='width: 100px; height: auto;' />";
     122            $services_array = \apply_filters( 'hey_notify_services_options', array() );
     123            $service        = \carbon_get_post_meta( $post_id, 'hey_notify_service' );
     124            foreach ( $services_array as $services ) {
     125                if ( $service === $services['value'] ) {
     126                    echo "<img src='" . esc_attr( $services['image'] ) . "' style='width: 100px; height: auto;' />";
     127                }
     128            }
    125129            break;
    126130        case 'events':
  • hey-notify/tags/1.1.0/includes/events/page/class-page-event.php

    r2345565 r2349284  
    7777        switch ( $event->{$event->type} ) {
    7878            case 'page_draft':
    79                 add_action( 'transition_post_status', array( $hook, 'page_draft' ), 10, 3 );
     79                add_action( 'auto-draft_to_draft', array( $hook, 'page_draft' ), 10, 1 );
    8080                break;
    8181            case 'page_published':
    82                 add_action( 'transition_post_status', array( $hook, 'page_published' ), 10, 3 );
     82                add_action( 'auto-draft_to_publish', array( $hook, 'page_published' ), 10, 1 );
     83                add_action( 'draft_to_publish', array( $hook, 'page_published' ), 10, 1 );
     84                add_action( 'future_to_publish', array( $hook, 'page_published' ), 10, 1 );
     85                add_action( 'pending_to_publish', array( $hook, 'page_published' ), 10, 1 );
    8386                break;
    8487            case 'page_scheduled':
    85                 add_action( 'transition_post_status', array( $hook, 'page_scheduled' ), 10, 3 );
     88                add_action( 'auto-draft_to_future', array( $hook, 'page_scheduled' ), 10, 1 );
     89                add_action( 'draft_to_future', array( $hook, 'page_scheduled' ), 10, 1 );
    8690                break;
    8791            case 'page_pending':
    88                 add_action( 'transition_post_status', array( $hook, 'page_pending' ), 10, 3 );
     92                add_action( 'auto-draft_to_pending', array( $hook, 'page_pending' ), 10, 1 );
     93                add_action( 'draft_to_pending', array( $hook, 'page_pending' ), 10, 1 );
    8994                break;
    9095            case 'page_updated':
    91                 add_action( 'transition_post_status', array( $hook, 'page_updated' ), 10, 3 );
     96                add_action( 'publish_to_publish', array( $hook, 'page_updated' ), 10, 1 );
    9297                break;
    9398            case 'page_trashed':
    94                 add_action( 'transition_post_status', array( $hook, 'page_trashed' ), 10, 3 );
     99                add_action( 'trashed_post', array( $hook, 'page_trashed' ), 10, 1 );
    95100                break;
    96101        }
  • hey-notify/tags/1.1.0/includes/events/page/class-page-hook.php

    r2345565 r2349284  
    2121     * When a page enters a DRAFT state.
    2222     *
    23      * @param string $new_status New status.
    24      * @param string $old_status Old status.
    25      * @param object $post Post object.
    26      * @return void
    27      */
    28     public function page_draft( $new_status, $old_status, $post ) {
    29 
    30         if ( 'page' !== $post->post_type ) {
    31             return;
    32         }
    33 
    34         if ( 'draft' === $old_status ) {
    35             return;
    36         }
    37 
    38         if ( 'draft' !== $new_status ) {
    39             return;
    40         }
    41 
    42         $this->prepare_data( \__( 'Hey, a new page was drafted!', 'hey-notify' ), $post );
     23     * @param object $post Post object.
     24     * @return void
     25     */
     26    public function page_draft( $post ) {
     27
     28        if ( empty( $post ) || ! is_object( $post ) ) {
     29            return;
     30        }
     31
     32        if ( 'page' !== $post->post_type ) {
     33            return;
     34        }
     35
     36        $current_user = \wp_get_current_user();
     37
     38        if ( 0 === $current_user ) {
     39            $subject = \sprintf(
     40                /* translators: %s: Name of the site */
     41                \__( 'Hey, a new page was drafted on %s!', 'hey-notify' ),
     42                \get_bloginfo( 'name' )
     43            );
     44        } else {
     45            $subject = \sprintf(
     46                /* translators: 1: Name of the user 2: Name of the site */
     47                \__( 'Hey, a new page was drafted by %1$s on %2$s!', 'hey-notify' ),
     48                \esc_html( $current_user->display_name ),
     49                \get_bloginfo( 'name' )
     50            );
     51        }
     52
     53        $this->prepare_data( $subject, $post );
    4354    }
    4455
     
    4657     * When a page enters the PUBLISH state.
    4758     *
    48      * @param string $new_status New status.
    49      * @param string $old_status Old status.
    50      * @param object $post Post object.
    51      * @return void
    52      */
    53     public function page_published( $new_status, $old_status, $post ) {
    54 
    55         if ( 'page' !== $post->post_type ) {
    56             return;
    57         }
    58 
    59         $valid = false;
    60         switch ( $old_status ) {
    61             case 'new':
    62             case 'draft':
    63             case 'auto-draft':
    64             case 'pending':
    65                 $valid = true;
    66                 break;
    67         }
    68 
    69         if ( false === $valid || 'publish' !== $new_status ) {
    70             return;
    71         }
    72 
    73         $this->prepare_data( \__( 'Hey, a new page was published!', 'hey-notify' ), $post );
     59     * @param object $post Post object.
     60     * @return void
     61     */
     62    public function page_published( $post ) {
     63
     64        if ( empty( $post ) || ! is_object( $post ) ) {
     65            return;
     66        }
     67
     68        if ( 'page' !== $post->post_type ) {
     69            return;
     70        }
     71
     72        $current_user = \wp_get_current_user();
     73
     74        if ( 0 === $current_user ) {
     75            $subject = \sprintf(
     76                /* translators: %s: Name of the site */
     77                \__( 'Hey, a new page was published on %s!', 'hey-notify' ),
     78                \get_bloginfo( 'name' )
     79            );
     80        } else {
     81            $subject = \sprintf(
     82                /* translators: 1: Name of the user 2: Name of the site */
     83                \__( 'Hey, a new page was published by %1$s on %2$s!', 'hey-notify' ),
     84                \esc_html( $current_user->display_name ),
     85                \get_bloginfo( 'name' )
     86            );
     87        }
     88
     89        $this->prepare_data( $subject, $post );
    7490    }
    7591
     
    7793     * When a page enters the FUTURE state.
    7894     *
    79      * @param string $new_status New status.
    80      * @param string $old_status Old status.
    81      * @param object $post Post object.
    82      * @return void
    83      */
    84     public function page_scheduled( $new_status, $old_status, $post ) {
    85 
    86         if ( 'page' !== $post->post_type ) {
    87             return;
    88         }
    89 
    90         $valid = false;
    91         switch ( $old_status ) {
    92             case 'new':
    93             case 'draft':
    94             case 'auto-draft':
    95                 $valid = true;
    96                 break;
    97         }
    98 
    99         if ( false === $valid || 'future' !== $new_status ) {
    100             return;
    101         }
    102 
    103         $this->prepare_data( \__( 'Hey, a new page was scheduled!', 'hey-notify' ), $post );
    104     }
    105 
    106     /**
    107      * When a page enters the PENDING state
    108      *
    109      * @param string $new_status New status.
    110      * @param string $old_status Old status.
    111      * @param object $post Post object.
    112      * @return void
    113      */
    114     public function page_pending( $new_status, $old_status, $post ) {
    115 
    116         if ( 'page' !== $post->post_type ) {
    117             return;
    118         }
    119 
    120         $valid = false;
    121         switch ( $old_status ) {
    122             case 'new':
    123             case 'draft':
    124             case 'auto-draft':
    125             case 'publish':
    126                 $valid = true;
    127                 break;
    128         }
    129 
    130         if ( false === $valid || 'pending' !== $new_status ) {
    131             return;
    132         }
    133 
    134         $this->prepare_data( \__( 'Hey, a new page is pending!', 'hey-notify' ), $post );
     95     * @param object $post Post object.
     96     * @return void
     97     */
     98    public function page_scheduled( $post ) {
     99
     100        if ( empty( $post ) || ! is_object( $post ) ) {
     101            return;
     102        }
     103
     104        if ( 'page' !== $post->post_type ) {
     105            return;
     106        }
     107
     108        $current_user = \wp_get_current_user();
     109
     110        if ( 0 === $current_user ) {
     111            $subject = \sprintf(
     112                /* translators: %s: Name of the site */
     113                \__( 'Hey, a new page was scheduled on %s!', 'hey-notify' ),
     114                \get_bloginfo( 'name' )
     115            );
     116        } else {
     117            $subject = \sprintf(
     118                /* translators: 1: Name of the user 2: Name of the site */
     119                \__( 'Hey, a new page was scheduled by %1$s on %2$s!', 'hey-notify' ),
     120                \esc_html( $current_user->display_name ),
     121                \get_bloginfo( 'name' )
     122            );
     123        }
     124
     125        $this->prepare_data( $subject, $post );
     126    }
     127
     128    /**
     129     * When a page enters the PENDING state.
     130     *
     131     * @param object $post Post object.
     132     * @return void
     133     */
     134    public function page_pending( $post ) {
     135
     136        $subject = \sprintf(
     137            /* translators: %s: Name of the site */
     138            \__( 'Hey, a new page is pending on %s!', 'hey-notify' ),
     139            \get_bloginfo( 'name' )
     140        );
     141
     142        $this->prepare_data( $subject, $post );
    135143    }
    136144
     
    138146     * When a page is updated.
    139147     *
    140      * @param string $new_status New status.
    141      * @param string $old_status Old status.
    142      * @param object $post Post object.
    143      * @return void
    144      */
    145     public function page_updated( $new_status, $old_status, $post ) {
    146 
    147         if ( 'page' !== $post->post_type ) {
    148             return;
    149         }
    150 
    151         if ( $old_status !== $new_status ) {
    152             return;
    153         }
    154 
    155         $this->prepare_data( \__( 'Hey, a page was updated!', 'hey-notify' ), $post );
     148     * @param object $post Post object.
     149     * @return void
     150     */
     151    public function page_updated( $post ) {
     152
     153        if ( empty( $post ) || ! is_object( $post ) ) {
     154            return;
     155        }
     156
     157        if ( 'page' !== $post->post_type ) {
     158            return;
     159        }
     160
     161        if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) {
     162            return;
     163        }
     164
     165        $current_user = \wp_get_current_user();
     166
     167        if ( 0 === $current_user ) {
     168            $subject = \sprintf(
     169                /* translators: %s: Name of the site */
     170                \__( 'Hey, a page was updated on %s!', 'hey-notify' ),
     171                \get_bloginfo( 'name' )
     172            );
     173        } else {
     174            $subject = \sprintf(
     175                /* translators: 1: Name of the user 2: Name of the site */
     176                \__( 'Hey, a page was updated by %1$s on %2$s!', 'hey-notify' ),
     177                \esc_html( $current_user->display_name ),
     178                \get_bloginfo( 'name' )
     179            );
     180        }
     181
     182        $this->prepare_data( $subject, $post );
    156183    }
    157184
     
    159186     * When a page is trashed.
    160187     *
    161      * @param string $new_status New status.
    162      * @param string $old_status Old status.
    163      * @param object $post Post object.
    164      * @return void
    165      */
    166     public function page_trashed( $new_status, $old_status, $post ) {
    167 
    168         if ( 'page' !== $post->post_type ) {
    169             return;
    170         }
    171 
    172         if ( 'trash' !== $new_status ) {
    173             return;
    174         }
    175 
    176         $this->prepare_data( \__( 'Hey, a page was deleted!', 'hey-notify' ), $post );
     188     * @param int $id Post ID.
     189     * @return void
     190     */
     191    public function page_trashed( $id ) {
     192
     193        $post = get_post( $id );
     194
     195        if ( is_wp_error( $post ) ) {
     196            return;
     197        }
     198
     199        if ( 'page' !== $post->post_type ) {
     200            return;
     201        }
     202
     203        $current_user = \wp_get_current_user();
     204
     205        if ( 0 === $current_user ) {
     206            $subject = \sprintf(
     207                /* translators: %s: Name of the site */
     208                \__( 'Hey, a page was deleted on %s!', 'hey-notify' ),
     209                \get_bloginfo( 'name' )
     210            );
     211        } else {
     212            $subject = \sprintf(
     213                /* translators: 1: Name of the user 2: Name of the site */
     214                \__( 'Hey, a page was deleted by %1$s on %2$s!', 'hey-notify' ),
     215                \esc_html( $current_user->display_name ),
     216                \get_bloginfo( 'name' )
     217            );
     218        }
     219
     220        $this->prepare_data( $subject, $post );
    177221    }
    178222
  • hey-notify/tags/1.1.0/includes/events/post/class-post-event.php

    r2345565 r2349284  
    7878        switch ( $event->{$event->type} ) {
    7979            case 'post_draft':
    80                 add_action( 'transition_post_status', array( $hook, 'post_draft' ), 10, 3 );
     80                add_action( 'auto-draft_to_draft', array( $hook, 'post_draft' ), 10, 1 );
    8181                break;
    8282            case 'post_published':
    83                 add_action( 'transition_post_status', array( $hook, 'post_published' ), 10, 3 );
     83                add_action( 'auto-draft_to_publish', array( $hook, 'post_published' ), 10, 1 );
     84                add_action( 'draft_to_publish', array( $hook, 'post_published' ), 10, 1 );
     85                add_action( 'future_to_publish', array( $hook, 'post_published' ), 10, 1 );
     86                add_action( 'pending_to_publish', array( $hook, 'post_published' ), 10, 1 );
    8487                break;
    8588            case 'post_scheduled':
    86                 add_action( 'transition_post_status', array( $hook, 'post_scheduled' ), 10, 3 );
     89                add_action( 'auto-draft_to_future', array( $hook, 'post_scheduled' ), 10, 1 );
     90                add_action( 'draft_to_future', array( $hook, 'post_scheduled' ), 10, 1 );
    8791                break;
    8892            case 'post_pending':
    89                 add_action( 'transition_post_status', array( $hook, 'post_pending' ), 10, 3 );
     93                add_action( 'auto-draft_to_pending', array( $hook, 'post_pending' ), 10, 1 );
     94                add_action( 'draft_to_pending', array( $hook, 'post_pending' ), 10, 1 );
    9095                break;
    9196            case 'post_updated':
    92                 add_action( 'transition_post_status', array( $hook, 'post_updated' ), 10, 3 );
     97                add_action( 'publish_to_publish', array( $hook, 'post_updated' ), 10, 1 );
    9398                break;
    9499            case 'post_trashed':
    95                 add_action( 'transition_post_status', array( $hook, 'post_trashed' ), 10, 3 );
     100                add_action( 'trashed_post', array( $hook, 'post_trashed' ), 10, 1 );
    96101                break;
    97102        }
  • hey-notify/tags/1.1.0/includes/events/post/class-post-hook.php

    r2345565 r2349284  
    2121     * When a post enters a DRAFT state.
    2222     *
    23      * @param string $new_status New status.
    24      * @param string $old_status Old status.
    25      * @param object $post Post object.
    26      * @return void
    27      */
    28     public function post_draft( $new_status, $old_status, $post ) {
    29 
    30         if ( 'post' !== $post->post_type ) {
    31             return;
    32         }
    33 
    34         if ( 'draft' === $old_status ) {
    35             return;
    36         }
    37 
    38         if ( 'draft' !== $new_status ) {
    39             return;
    40         }
    41 
    42         $this->prepare_data( \__( 'Hey, a new post was drafted!', 'hey-notify' ), $post );
     23     * @param object $post Post object.
     24     * @return void
     25     */
     26    public function post_draft( $post ) {
     27
     28        if ( empty( $post ) || ! is_object( $post ) ) {
     29            return;
     30        }
     31
     32        if ( 'post' !== $post->post_type ) {
     33            return;
     34        }
     35
     36        $current_user = \wp_get_current_user();
     37
     38        if ( 0 === $current_user ) {
     39            $subject = \sprintf(
     40                /* translators: %s: Name of the site */
     41                \__( 'Hey, a new post was drafted on %s!', 'hey-notify' ),
     42                \get_bloginfo( 'name' )
     43            );
     44        } else {
     45            $subject = \sprintf(
     46                /* translators: 1: Name of the user 2: Name of the site */
     47                \__( 'Hey, a new post was drafted by %1$s on %2$s!', 'hey-notify' ),
     48                \esc_html( $current_user->display_name ),
     49                \get_bloginfo( 'name' )
     50            );
     51        }
     52
     53        $this->prepare_data( $subject, $post );
    4354    }
    4455
     
    4657     * When a post enters the PUBLISH state.
    4758     *
    48      * @param string $new_status New status.
    49      * @param string $old_status Old status.
    50      * @param object $post Post object.
    51      * @return void
    52      */
    53     public function post_published( $new_status, $old_status, $post ) {
    54 
    55         if ( 'post' !== $post->post_type ) {
    56             return;
    57         }
    58 
    59         $valid = false;
    60         switch ( $old_status ) {
    61             case 'new':
    62             case 'draft':
    63             case 'auto-draft':
    64             case 'pending':
    65                 $valid = true;
    66                 break;
    67         }
    68 
    69         if ( false === $valid || 'publish' !== $new_status ) {
    70             return;
    71         }
    72 
    73         $this->prepare_data( \__( 'Hey, a new post was published!', 'hey-notify' ), $post );
     59     * @param object $post Post object.
     60     * @return void
     61     */
     62    public function post_published( $post ) {
     63
     64        if ( empty( $post ) || ! is_object( $post ) ) {
     65            return;
     66        }
     67
     68        if ( 'post' !== $post->post_type ) {
     69            return;
     70        }
     71
     72        $current_user = \wp_get_current_user();
     73
     74        if ( 0 === $current_user ) {
     75            $subject = \sprintf(
     76                /* translators: %s: Name of the site */
     77                \__( 'Hey, a new post was published on %s!', 'hey-notify' ),
     78                \get_bloginfo( 'name' )
     79            );
     80        } else {
     81            $subject = \sprintf(
     82                /* translators: 1: Name of the user 2: Name of the site */
     83                \__( 'Hey, a new post was published by %1$s on %2$s!', 'hey-notify' ),
     84                \esc_html( $current_user->display_name ),
     85                \get_bloginfo( 'name' )
     86            );
     87        }
     88
     89        $this->prepare_data( $subject, $post );
    7490    }
    7591
     
    7793     * When a post enters the FUTURE state.
    7894     *
    79      * @param string $new_status New status.
    80      * @param string $old_status Old status.
    81      * @param object $post Post object.
    82      * @return void
    83      */
    84     public function post_scheduled( $new_status, $old_status, $post ) {
    85 
    86         if ( 'post' !== $post->post_type ) {
    87             return;
    88         }
    89 
    90         $valid = false;
    91         switch ( $old_status ) {
    92             case 'new':
    93             case 'draft':
    94             case 'auto-draft':
    95                 $valid = true;
    96                 break;
    97         }
    98 
    99         if ( false === $valid || 'future' !== $new_status ) {
    100             return;
    101         }
    102 
    103         $this->prepare_data( \__( 'Hey, a new post was scheduled!', 'hey-notify' ), $post );
     95     * @param object $post Post object.
     96     * @return void
     97     */
     98    public function post_scheduled( $post ) {
     99
     100        if ( empty( $post ) || ! is_object( $post ) ) {
     101            return;
     102        }
     103
     104        if ( 'post' !== $post->post_type ) {
     105            return;
     106        }
     107
     108        $current_user = \wp_get_current_user();
     109
     110        if ( 0 === $current_user ) {
     111            $subject = \sprintf(
     112                /* translators: %s: Name of the site */
     113                \__( 'Hey, a new post was scheduled on %s!', 'hey-notify' ),
     114                \get_bloginfo( 'name' )
     115            );
     116        } else {
     117            $subject = \sprintf(
     118                /* translators: 1: Name of the user 2: Name of the site */
     119                \__( 'Hey, a new post was scheduled by %1$s on %2$s!', 'hey-notify' ),
     120                \esc_html( $current_user->display_name ),
     121                \get_bloginfo( 'name' )
     122            );
     123        }
     124
     125        $this->prepare_data( $subject, $post );
    104126    }
    105127
     
    107129     * When a post enters the PENDING state.
    108130     *
    109      * @param string $new_status New status.
    110      * @param string $old_status Old status.
    111      * @param object $post Post object.
    112      * @return void
    113      */
    114     public function post_pending( $new_status, $old_status, $post ) {
    115 
    116         if ( 'post' !== $post->post_type ) {
    117             return;
    118         }
    119 
    120         $valid = false;
    121         switch ( $old_status ) {
    122             case 'new':
    123             case 'draft':
    124             case 'auto-draft':
    125             case 'publish':
    126                 $valid = true;
    127                 break;
    128         }
    129 
    130         if ( false === $valid || 'pending' !== $new_status ) {
    131             return;
    132         }
    133 
    134         $this->prepare_data( \__( 'Hey, a new post is pending!', 'hey-notify' ), $post );
     131     * @param object $post Post object.
     132     * @return void
     133     */
     134    public function post_pending( $post ) {
     135
     136        $subject = \sprintf(
     137            /* translators: %s: Name of the site */
     138            \__( 'Hey, a new post is pending on %s!', 'hey-notify' ),
     139            \get_bloginfo( 'name' )
     140        );
     141
     142        $this->prepare_data( $subject, $post );
    135143    }
    136144
     
    138146     * When a post is updated.
    139147     *
    140      * @param string $new_status New status.
    141      * @param string $old_status Old status.
    142      * @param object $post Post object.
    143      * @return void
    144      */
    145     public function post_updated( $new_status, $old_status, $post ) {
    146 
    147         if ( 'post' !== $post->post_type ) {
    148             return;
    149         }
    150 
    151         if ( $old_status !== $new_status ) {
    152             return;
    153         }
    154 
    155         $this->prepare_data( \__( 'Hey, a post was updated!', 'hey-notify' ), $post );
     148     * @param object $post Post object.
     149     * @return void
     150     */
     151    public function post_updated( $post ) {
     152
     153        if ( empty( $post ) || ! is_object( $post ) ) {
     154            return;
     155        }
     156
     157        if ( 'post' !== $post->post_type ) {
     158            return;
     159        }
     160
     161        if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) {
     162            return;
     163        }
     164
     165        $current_user = \wp_get_current_user();
     166
     167        if ( 0 === $current_user ) {
     168            $subject = \sprintf(
     169                /* translators: %s: Name of the site */
     170                \__( 'Hey, a post was updated on %s!', 'hey-notify' ),
     171                \get_bloginfo( 'name' )
     172            );
     173        } else {
     174            $subject = \sprintf(
     175                /* translators: 1: Name of the user 2: Name of the site */
     176                \__( 'Hey, a post was updated by %1$s on %2$s!', 'hey-notify' ),
     177                \esc_html( $current_user->display_name ),
     178                \get_bloginfo( 'name' )
     179            );
     180        }
     181
     182        $this->prepare_data( $subject, $post );
    156183    }
    157184
     
    159186     * When a post is trashed.
    160187     *
    161      * @param string $new_status New status.
    162      * @param string $old_status Old status.
    163      * @param object $post Post object.
    164      * @return void
    165      */
    166     public function post_trashed( $new_status, $old_status, $post ) {
    167 
    168         if ( 'post' !== $post->post_type ) {
    169             return;
    170         }
    171 
    172         if ( 'trash' !== $new_status ) {
    173             return;
    174         }
    175 
    176         $this->prepare_data( \__( 'Hey, a post was deleted!', 'hey-notify' ), $post );
     188     * @param int $id Post ID.
     189     * @return void
     190     */
     191    public function post_trashed( $id ) {
     192
     193        $post = get_post( $id );
     194
     195        if ( is_wp_error( $post ) ) {
     196            return;
     197        }
     198
     199        if ( 'post' !== $post->post_type ) {
     200            return;
     201        }
     202
     203        $current_user = \wp_get_current_user();
     204
     205        if ( 0 === $current_user ) {
     206            $subject = \sprintf(
     207                /* translators: %s: Name of the site */
     208                \__( 'Hey, a post was deleted on %s!', 'hey-notify' ),
     209                \get_bloginfo( 'name' )
     210            );
     211        } else {
     212            $subject = \sprintf(
     213                /* translators: 1: Name of the user 2: Name of the site */
     214                \__( 'Hey, a post was deleted by %1$s on %2$s!', 'hey-notify' ),
     215                \esc_html( $current_user->display_name ),
     216                \get_bloginfo( 'name' )
     217            );
     218        }
     219
     220        $this->prepare_data( $subject, $post );
    177221    }
    178222
  • hey-notify/tags/1.1.0/includes/filters.php

    r2345565 r2349284  
    3030    $fields[] = (
    3131        Field::make( 'radio_image', 'hey_notify_service', __( 'Select a service', 'hey-notify' ) )
    32             ->set_options( apply_filters( 'hey_notify_services_options', array() ) )
     32            ->set_options( get_service_options() )
    3333            ->set_default_value( \get_option( '_hey_notify_default_service' ) )
    3434    );
     
    106106    $fields[] = (
    107107        Field::make( 'radio_image', 'hey_notify_default_service', __( 'Default service:', 'hey-notify' ) )
    108             ->set_options( apply_filters( 'hey_notify_services_options', array() ) )
     108            ->set_options( get_service_options() )
    109109    );
    110110    return $fields;
    111111}
     112
     113/**
     114 * Get the service options from the filter
     115 *
     116 * @return array
     117 */
     118function get_service_options() {
     119
     120    $services = apply_filters( 'hey_notify_services_options', array() );
     121    $options  = array();
     122
     123    foreach ( $services as $service ) {
     124        if ( isset( $service['image'] ) ) {
     125            $options[ $service['value'] ] = $service['image'];
     126        }
     127    }
     128
     129    return $options;
     130}
  • hey-notify/tags/1.1.0/includes/services/class-discord.php

    r2345565 r2349284  
    2121
    2222    /**
     23     * Class construct
     24     *
     25     * @return void
     26     */
     27    public function __construct() {
     28        parent::__construct();
     29
     30        \add_action( 'hey_notify_send_message_discord', array( $this, 'send' ), 10, 3 );
     31        \add_action( 'hey_notify_discord_settings_core', array( $this, 'get_core_settings' ), 10, 1 );
     32    }
     33
     34    /**
     35     * Get service settings
     36     *
     37     * @param object $data Data.
     38     * @return boolean|array
     39     */
     40    public function get_core_settings( $data ) {
     41
     42        if ( ! is_object( $data ) || ! isset( $data->ID ) ) {
     43            return false;
     44        }
     45
     46        return array(
     47            'webhook_url' => \carbon_get_post_meta( $data->ID, 'hey_notify_discord_webhook' ),
     48            'username'    => \carbon_get_post_meta( $data->ID, 'hey_notify_discord_username' ),
     49            'icon'        => \carbon_get_post_meta( $data->ID, 'hey_notify_discord_avatar' ),
     50        );
     51
     52    }
     53
     54    /**
    2355     * Service options
    2456     *
     
    2759     */
    2860    public function services( $services = array() ) {
    29         if ( ! isset( $services['discord'] ) ) {
    30             $services['discord'] = HEY_NOTIFY_PLUGIN_URL . '/images/services/discord.png';
    31         }
     61        $services[] = array(
     62            'value' => 'discord',
     63            'label' => __( 'Discord', 'hey-notify' ),
     64            'image' => HEY_NOTIFY_PLUGIN_URL . 'images/services/discord.png',
     65        );
    3266
    3367        return $services;
     
    85119
    86120    /**
    87      * Send the message
     121     * Prepare the message
    88122     *
    89123     * @param array $message Message.
    90      * @return void
    91      */
    92     public function send( $message ) {
    93         $service = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_service' );
    94 
    95         if ( 'discord' !== $service ) {
    96             return;
    97         }
    98 
    99         $webhook_url = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_discord_webhook' );
    100         $username    = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_discord_username' );
    101         $avatar      = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_discord_avatar' );
    102         $body        = array();
    103         $embed_item  = array();
     124     * @param array $settings Settings.
     125     * @return array
     126     */
     127    private function prepare( $message, $settings ) {
     128
     129        $body       = array();
     130        $embed_item = array();
    104131
    105132        // Subject.
     
    150177        }
    151178
    152         $body = array(
    153             'embeds' => array( $embed_item ),
    154         );
    155 
    156         if ( '' !== $username ) {
    157             $body['username'] = $username;
    158         }
    159 
    160         if ( '' !== $avatar ) {
    161             $avatar = \wp_get_attachment_image_url( $avatar, array( 250, 250 ) );
    162             if ( false !== $avatar ) {
    163                 $body['avatar_url'] = $avatar;
     179        $body['embeds'] = array( $embed_item );
     180
     181        if ( '' !== $settings['username'] ) {
     182            $body['username'] = $settings['username'];
     183        }
     184
     185        if ( '' !== $settings['avatar'] ) {
     186            if ( filter_var( $settings['avatar'], FILTER_VALIDATE_URL ) ) {
     187                $body['avatar_url'] = $settings['avatar'];
     188            } else {
     189                $avatar = \wp_get_attachment_image_url( $settings['avatar'], array( 250, 250 ) );
     190                if ( false !== $avatar ) {
     191                    $body['avatar_url'] = $avatar;
     192                }
    164193            }
    165194        }
     195
     196        return $body;
     197
     198    }
     199
     200    /**
     201     * Send the message
     202     *
     203     * @param array  $message Message.
     204     * @param string $trigger Trigger.
     205     * @param mixed  $data Data.
     206     * @return void
     207     */
     208    public function send( $message, $trigger, $data ) {
     209
     210        $settings = \apply_filters( "hey_notify_discord_settings_{$trigger}", $data );
     211
     212        if ( ! is_array( $settings ) || ! isset( $settings['webhook_url'] ) ) {
     213            return;
     214        }
     215
     216        $body = $this->prepare( $message, $settings );
    166217
    167218        $json     = \wp_json_encode( $body );
    168219        $response = \wp_remote_post(
    169             $webhook_url,
     220            $settings['webhook_url'],
    170221            array(
    171222                'headers' => array(
     
    176227        );
    177228
    178         do_action( 'hey_notify_message_sent', $json, $response );
     229        \do_action(
     230            'hey_notify_message_sent',
     231            array(
     232                'service'  => 'discord',
     233                'json'     => $json,
     234                'response' => $response,
     235                'trigger'  => $trigger,
     236                'message'  => $message,
     237                'data'     => $data,
     238            )
     239        );
    179240
    180241        if ( ! \is_wp_error( $response ) ) {
  • hey-notify/tags/1.1.0/includes/services/class-email.php

    r2345565 r2349284  
    2121
    2222    /**
     23     * Class construct
     24     *
     25     * @return void
     26     */
     27    public function __construct() {
     28        parent::__construct();
     29
     30        \add_action( 'hey_notify_send_message_email', array( $this, 'send' ), 10, 3 );
     31        \add_filter( 'hey_notify_email_settings_core', array( $this, 'get_core_settings' ), 10, 1 );
     32    }
     33
     34    /**
     35     * Get service settings
     36     *
     37     * @param object $data Data.
     38     * @return boolean|array
     39     */
     40    public function get_core_settings( $data ) {
     41
     42        if ( ! is_object( $data ) || ! isset( $data->ID ) ) {
     43            return false;
     44        }
     45
     46        return array(
     47            'email_addresses' => \carbon_get_post_meta( $data->ID, 'hey_notify_email_addresses' ),
     48        );
     49    }
     50
     51    /**
    2352     * Service options
    2453     *
     
    2756     */
    2857    public function services( $services = array() ) {
    29         if ( ! isset( $services['email'] ) ) {
    30             $services['email'] = HEY_NOTIFY_PLUGIN_URL . '/images/services/email.png';
    31         }
     58        $services[] = array(
     59            'value' => 'email',
     60            'label' => __( 'Email', 'hey-notify' ),
     61            'image' => HEY_NOTIFY_PLUGIN_URL . 'images/services/email.png',
     62        );
    3263
    3364        return $services;
     
    70101
    71102    /**
     103     * Prepare the message
     104     *
     105     * @param array $message Message.
     106     * @param array $settings Settings.
     107     * @return string
     108     */
     109    private function prepare( $message, $settings ) {
     110
     111        $body = '';
     112
     113        // Title.
     114        if ( isset( $message['title'] ) && '' !== $message['title'] ) {
     115            $body .= "{$message['title']}\r\n";
     116        }
     117
     118        // URL.
     119        if ( isset( $message['url'] ) && '' !== $message['url'] ) {
     120            $body .= "{$message['url']}\r\n\r\n";
     121        }
     122
     123        // Content.
     124        if ( isset( $message['content'] ) && '' !== $message['content'] ) {
     125            $body .= "{$message['content']}\r\n\r\n";
     126        }
     127
     128        // Fields.
     129        if ( isset( $message['fields'] ) && is_array( $message['fields'] ) ) {
     130            foreach ( $message['fields'] as $field ) {
     131                $body .= "{$field['name']}: {$field['value']}\r\n";
     132            }
     133        }
     134
     135        // Footer.
     136        if ( isset( $message['footer'] ) && '' !== $message['footer'] ) {
     137            $body .= "{$message['footer']}";
     138        }
     139
     140        return $body;
     141    }
     142
     143    /**
    72144     * Send the message
    73145     *
    74      * @param array $message Message.
     146     * @param array  $message Message.
     147     * @param string $trigger Trigger.
     148     * @param mixed  $data Data.
    75149     * @return void
    76150     */
    77     public function send( $message ) {
    78 
    79         $service = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_service' );
    80 
    81         if ( 'email' !== $service ) {
     151    public function send( $message, $trigger, $data ) {
     152
     153        $settings = \apply_filters( "hey_notify_email_settings_{$trigger}", $data );
     154
     155        if ( false === $settings ) {
    82156            return;
    83157        }
    84158
    85         $email_addresses = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_email_addresses' );
    86         $to_email        = array();
    87         if ( $email_addresses ) {
    88             foreach ( $email_addresses as $email ) {
     159        if ( ! is_array( $settings ) || ! isset( $settings['email_addresses'] ) ) {
     160            return;
     161        }
     162
     163        $to_email = array();
     164        if ( $settings['email_addresses'] ) {
     165            foreach ( $settings['email_addresses'] as $email ) {
    89166                if ( '' !== trim( $email['email'] ) ) {
    90167                    $to_email[] = $email['email'];
     
    106183        }
    107184
    108         $body = '';
    109 
    110         // Title.
    111         if ( isset( $message['title'] ) && '' !== $message['title'] ) {
    112             $body .= "{$message['title']}\r\n";
    113         }
    114 
    115         // URL.
    116         if ( isset( $message['url'] ) && '' !== $message['url'] ) {
    117             $body .= "{$message['url']}\r\n\r\n";
    118         }
    119 
    120         // Content.
    121         if ( isset( $message['content'] ) && '' !== $message['content'] ) {
    122             $body .= "{$message['content']}\r\n\r\n";
    123         }
    124 
    125         // Fields.
    126         if ( isset( $message['fields'] ) && is_array( $message['fields'] ) ) {
    127             foreach ( $message['fields'] as $field ) {
    128                 $body .= "{$field['name']}: {$field['value']}\r\n";
    129             }
    130         }
    131 
    132         // Footer.
    133         if ( isset( $message['footer'] ) && '' !== $message['footer'] ) {
    134             $body .= "{$message['footer']}";
    135         }
     185        $body = $this->prepare( $message, $settings );
    136186
    137187        $headers = array(
     
    141191        $result = wp_mail( $to_email, $subject, $body, $headers );
    142192
    143         do_action( 'hey_notify_message_sent', $body, $result );
     193        \do_action(
     194            'hey_notify_message_sent',
     195            array(
     196                'service'  => 'email',
     197                'response' => $result,
     198                'trigger'  => $trigger,
     199                'message'  => $message,
     200                'data'     => $data,
     201            )
     202        );
    144203    }
    145204}
  • hey-notify/tags/1.1.0/includes/services/class-slack.php

    r2345565 r2349284  
    2121
    2222    /**
     23     * Class construct
     24     *
     25     * @return void
     26     */
     27    public function __construct() {
     28        parent::__construct();
     29
     30        \add_action( 'hey_notify_send_message_slack', array( $this, 'send' ), 10, 3 );
     31        \add_filter( 'hey_notify_slack_settings_core', array( $this, 'get_core_settings' ), 10, 1 );
     32    }
     33
     34    /**
     35     * Get service settings
     36     *
     37     * @param object $data Data.
     38     * @return boolean|array
     39     */
     40    public function get_core_settings( $data ) {
     41
     42        if ( ! is_object( $data ) || ! isset( $data->ID ) ) {
     43            return false;
     44        }
     45
     46        return array(
     47            'webhook_url' => \carbon_get_post_meta( $data->ID, 'hey_notify_slack_webhook' ),
     48            'username'    => \carbon_get_post_meta( $data->ID, 'hey_notify_slack_username' ),
     49            'icon'        => \carbon_get_post_meta( $data->ID, 'hey_notify_slack_icon' ),
     50            'color'       => \carbon_get_post_meta( $data->ID, 'hey_notify_slack_color' ),
     51        );
     52    }
     53
     54    /**
    2355     * Add the service
    2456     *
     
    2759     */
    2860    public function services( $services = array() ) {
    29         if ( ! isset( $services['slack'] ) ) {
    30             $services['slack'] = HEY_NOTIFY_PLUGIN_URL . '/images/services/slack.png';
    31         }
     61
     62        $services[] = array(
     63            'value' => 'slack',
     64            'label' => __( 'Slack', 'hey-notify' ),
     65            'image' => HEY_NOTIFY_PLUGIN_URL . 'images/services/slack.png',
     66        );
    3267
    3368        return $services;
     
    4176     */
    4277    public function fields( $fields = array() ) {
     78
    4379        $fields[] = (
    4480            Field::make( 'text', 'hey_notify_slack_webhook', __( 'Webhook URL', 'hey-notify' ) )
     
    83119            Field::make( 'color', 'hey_notify_slack_color', __( 'Color', 'hey-notify' ) )
    84120                ->set_help_text( __( 'Select a color to use for the message attachment.', 'hey-notify' ) )
     121                ->set_default_value( '#009bff' )
    85122                ->set_conditional_logic(
    86123                    array(
     
    97134
    98135    /**
    99      * Prepare the message
    100      *
    101      * @param array $message Message.
    102      * @return array
    103      */
    104     private function prepare( $message ) {
    105         $clean_message = array(
    106             'notification' => $message['notification'],
    107             'subject'      => $this->sanitize( $message['subject'] ),
    108             'title'        => $this->sanitize( $message['title'] ),
    109             'url'          => $message['url'],
    110             'image'        => $message['image'],
    111             'content'      => $this->sanitize( $message['content'] ),
    112             'footer'       => $this->sanitize( $message['footer'] ),
    113         );
    114 
    115         $clean_fields = array();
    116         foreach ( $message['fields'] as $field ) {
    117             $clean_fields[] = array(
    118                 'name'   => $this->sanitize( $field['name'] ),
    119                 'value'  => $this->sanitize( $field['value'] ),
    120                 'inline' => $field['inline'],
    121             );
    122         }
    123 
    124         $clean_message['fields'] = $clean_fields;
    125 
    126         return $clean_message;
    127     }
    128 
    129     /**
    130136     * Sanitize a string for Slack
    131137     *
     
    134140     */
    135141    private function sanitize( $string ) {
    136         $string = str_replace( '&', '&amp;', $string );
    137         $string = str_replace( '<', '&lt;', $string );
    138         $string = str_replace( '>', '&gt;', $string );
     142        $string = \str_replace( '&', '&amp;', $string );
     143        $string = \str_replace( '<', '&lt;', $string );
     144        $string = \str_replace( '>', '&gt;', $string );
    139145        return $string;
    140146    }
    141147
    142148    /**
    143      * Send the message
     149     * Prepare the message
    144150     *
    145151     * @param array $message Message.
    146      * @return void
    147      */
    148     public function send( $message ) {
    149         $service = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_service' );
    150 
    151         if ( 'slack' !== $service ) {
    152             return;
    153         }
    154 
    155         $message = $this->prepare( $message );
    156 
    157         $webhook_url = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_slack_webhook' );
    158         $username    = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_slack_username' );
    159         $icon        = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_slack_icon' );
    160         $color       = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_slack_color' );
    161         $blocks      = array();
     152     * @param array $settings Settings.
     153     * @return array
     154     */
     155    private function prepare( $message, $settings ) {
     156
     157        $subject = $this->sanitize( $message['subject'] );
     158        $title   = $this->sanitize( $message['title'] );
     159        $content = $this->sanitize( $message['content'] );
     160        $footer  = $this->sanitize( $message['footer'] );
     161        $image   = $message['image'];
     162        $url     = $message['url'];
     163
     164        $blocks = array();
    162165
    163166        // Subject.
    164         if ( isset( $message['subject'] ) && '' !== $message['subject'] ) {
    165             $blocks[] = array(
    166                 'type' => 'section',
    167                 'text' => array(
    168                     'type' => 'mrkdwn',
    169                     'text' => $message['subject'],
     167        if ( isset( $subject ) && '' !== $subject ) {
     168            $blocks[] = array(
     169                'type' => 'section',
     170                'text' => array(
     171                    'type' => 'mrkdwn',
     172                    'text' => $subject,
    170173                ),
    171174            );
     
    173176
    174177        // Title and URL.
    175         if ( '' !== $message['title'] && '' !== $message['url'] ) {
    176             $blocks[] = array(
    177                 'type' => 'section',
    178                 'text' => array(
    179                     'type' => 'mrkdwn',
    180                     'text' => "*<{$message['url']}|{$message['title']}>*",
    181                 ),
    182             );
    183         } elseif ( '' !== $message['title'] && '' === $message['url'] ) {
    184             $blocks[] = array(
    185                 'type' => 'section',
    186                 'text' => array(
    187                     'type' => 'mrkdwn',
    188                     'text' => "*{$message['title']}*",
    189                 ),
    190             );
    191         } elseif ( '' === $message['title'] && '' !== $message['url'] ) {
    192             $blocks[] = array(
    193                 'type' => 'section',
    194                 'text' => array(
    195                     'type' => 'mrkdwn',
    196                     'text' => "*<{$message['url']}|{$message['url']}>*",
     178        if ( '' !== $title && '' !== $url ) {
     179            $blocks[] = array(
     180                'type' => 'section',
     181                'text' => array(
     182                    'type' => 'mrkdwn',
     183                    'text' => "*<{$url}|{$title}>*",
     184                ),
     185            );
     186        } elseif ( '' !== $title && '' === $url ) {
     187            $blocks[] = array(
     188                'type' => 'section',
     189                'text' => array(
     190                    'type' => 'mrkdwn',
     191                    'text' => "*{$title}*",
     192                ),
     193            );
     194        } elseif ( '' === $title && '' !== $url ) {
     195            $blocks[] = array(
     196                'type' => 'section',
     197                'text' => array(
     198                    'type' => 'mrkdwn',
     199                    'text' => "*<{$url}|{$url}>*",
    197200                ),
    198201            );
     
    200203
    201204        // Content.
    202         if ( isset( $message['content'] ) && '' !== $message['content'] ) {
    203             $blocks[] = array(
    204                 'type' => 'section',
    205                 'text' => array(
    206                     'type' => 'mrkdwn',
    207                     'text' => $message['content'],
     205        if ( isset( $content ) && '' !== $content ) {
     206            $blocks[] = array(
     207                'type' => 'section',
     208                'text' => array(
     209                    'type' => 'mrkdwn',
     210                    'text' => $content,
    208211                ),
    209212            );
     
    216219                $fields[] = array(
    217220                    'type' => 'mrkdwn',
    218                     'text' => "*{$field['name']}*\n{$field['value']}",
     221                    'text' => "*{$this->sanitize( $field['name'] )}*\n{$this->sanitize( $field['value'] )}",
    219222                );
    220223            }
     
    224227            );
    225228
    226             if ( isset( $message['image'] ) && '' !== $message['image'] ) {
     229            if ( isset( $image ) && '' !== $image ) {
    227230                $fields_array['accessory'] = array(
    228231                    'type'      => 'image',
    229                     'image_url' => $message['image'],
    230                     'alt_text'  => isset( $message['title'] ) ? $message['title'] : __( 'Attached image', 'hey-notify' ),
     232                    'image_url' => $image,
     233                    'alt_text'  => isset( $title ) ? $title : __( 'Attached image', 'hey-notify' ),
    231234                );
    232235            }
     
    236239
    237240        // Footer.
    238         if ( isset( $message['footer'] ) && '' !== $message['footer'] ) {
    239             $blocks[] = array(
    240                 'type' => 'section',
    241                 'text' => array(
    242                     'type' => 'mrkdwn',
    243                     'text' => $message['footer'],
     241        if ( isset( $footer ) && '' !== $footer ) {
     242            $blocks[] = array(
     243                'type' => 'section',
     244                'text' => array(
     245                    'type' => 'mrkdwn',
     246                    'text' => $footer,
    244247                ),
    245248            );
     
    249252
    250253        $body['attachments'][] = array(
    251             'color'  => $color,
     254            'color'  => $settings['color'],
    252255            'blocks' => $blocks,
    253256        );
    254257
    255         if ( '' !== $username ) {
    256             $body['username'] = $username;
    257         }
    258 
    259         if ( '' !== $icon ) {
    260             $icon_url = \wp_get_attachment_image_url( $icon, array( 250, 250 ) );
    261             if ( false !== $icon_url ) {
    262                 $body['icon_url'] = $icon_url;
     258        if ( '' !== $settings['username'] ) {
     259            $body['username'] = $settings['username'];
     260        }
     261
     262        if ( '' !== $settings['icon'] ) {
     263            if ( filter_var( $settings['icon'], FILTER_VALIDATE_URL ) ) {
     264                $body['icon_url'] = $settings['icon'];
     265            } else {
     266                $icon_url = \wp_get_attachment_image_url( $settings['icon'], array( 250, 250 ) );
     267                if ( false !== $icon_url ) {
     268                    $body['icon_url'] = $icon_url;
     269                }
    263270            }
    264271        }
     272
     273        return $body;
     274    }
     275
     276    /**
     277     * Send the message
     278     *
     279     * @param array  $message Message.
     280     * @param string $trigger Trigger.
     281     * @param mixed  $data Data.
     282     * @return void
     283     */
     284    public function send( $message, $trigger, $data ) {
     285
     286        $settings = \apply_filters( "hey_notify_slack_settings_{$trigger}", $data );
     287
     288        if ( ! is_array( $settings ) || ! isset( $settings['webhook_url'] ) ) {
     289            return;
     290        }
     291
     292        $body = $this->prepare( $message, $settings );
    265293
    266294        $json     = \wp_json_encode( $body );
    267295        $response = \wp_remote_post(
    268             $webhook_url,
     296            $settings['webhook_url'],
    269297            array(
    270298                'headers' => array(
     
    275303        );
    276304
    277         do_action( 'hey_notify_message_sent', $json, $response );
     305        \do_action(
     306            'hey_notify_message_sent',
     307            array(
     308                'service'  => 'slack',
     309                'json'     => $json,
     310                'response' => $response,
     311                'trigger'  => $trigger,
     312                'message'  => $message,
     313                'data'     => $data,
     314            )
     315        );
    278316
    279317        if ( ! \is_wp_error( $response ) ) {
  • hey-notify/tags/1.1.0/languages/hey-notify.pot

    r2345565 r2349284  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Hey Notify 1.0.0\n"
     5"Project-Id-Version: Hey Notify 1.1.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/hey-notify\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2020-07-21T19:21:51+00:00\n"
     12"POT-Creation-Date: 2020-07-30T18:02:04+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.1.0\n"
     
    1717#. Plugin Name of the plugin
    1818#: includes/cpt.php:35
    19 #: includes/services/class-email.php:99
     19#: includes/services/class-email.php:176
    2020msgid "Hey Notify"
    2121msgstr ""
     
    9898msgstr ""
    9999
     100#: includes/events/comment/class-comment-event.php:30
     101msgid "Comments"
     102msgstr ""
     103
     104#: includes/events/comment/class-comment-event.php:43
     105#: includes/events/page/class-page-event.php:43
     106#: includes/events/post/class-post-event.php:43
     107#: includes/events/system/class-system-event.php:43
     108#: includes/events/user/class-user-event.php:43
     109msgid "Action"
     110msgstr ""
     111
     112#: includes/events/comment/class-comment-event.php:46
     113msgid "New Comment"
     114msgstr ""
     115
     116#. translators: %s: Name of the site
     117#: includes/events/comment/class-comment-hook.php:41
     118msgid "Hey, a new comment has been posted on %s!"
     119msgstr ""
     120
     121#: includes/events/comment/class-comment-hook.php:59
     122#: includes/events/page/class-page-hook.php:234
     123#: includes/events/post/class-post-hook.php:234
     124msgid "Author"
     125msgstr ""
     126
     127#: includes/events/comment/class-comment-hook.php:64
     128#: includes/events/user/class-user-hook.php:120
     129#: includes/services/class-email.php:60
     130msgid "Email"
     131msgstr ""
     132
     133#: includes/events/comment/class-comment-hook.php:69
     134#: includes/events/page/class-page-hook.php:239
     135#: includes/events/post/class-post-hook.php:239
     136msgid "Date"
     137msgstr ""
     138
     139#: includes/events/comment/class-comment-hook.php:74
     140msgid "Status"
     141msgstr ""
     142
     143#: includes/events/comment/class-comment-hook.php:106
     144msgid "Approved"
     145msgstr ""
     146
     147#: includes/events/comment/class-comment-hook.php:108
     148msgid "Pending"
     149msgstr ""
     150
     151#: includes/events/comment/class-comment-hook.php:110
     152msgid "Spam"
     153msgstr ""
     154
    100155#: includes/events/page/class-page-event.php:30
    101156msgid "Pages"
    102157msgstr ""
    103158
    104 #: includes/events/page/class-page-event.php:43
    105 #: includes/events/post/class-post-event.php:43
    106 msgid "Action"
    107 msgstr ""
    108 
    109159#: includes/events/page/class-page-event.php:46
    110160msgid "Page Draft"
     
    131181msgstr ""
    132182
    133 #: includes/events/page/class-page-hook.php:42
    134 msgid "Hey, a new page was drafted!"
    135 msgstr ""
    136 
    137 #: includes/events/page/class-page-hook.php:73
    138 msgid "Hey, a new page was published!"
    139 msgstr ""
    140 
    141 #: includes/events/page/class-page-hook.php:103
    142 msgid "Hey, a new page was scheduled!"
    143 msgstr ""
    144 
    145 #: includes/events/page/class-page-hook.php:134
    146 msgid "Hey, a new page is pending!"
    147 msgstr ""
    148 
    149 #: includes/events/page/class-page-hook.php:155
    150 msgid "Hey, a page was updated!"
    151 msgstr ""
    152 
     183#. translators: %s: Name of the site
     184#: includes/events/page/class-page-hook.php:41
     185msgid "Hey, a new page was drafted on %s!"
     186msgstr ""
     187
     188#. translators: 1: Name of the user 2: Name of the site
     189#: includes/events/page/class-page-hook.php:47
     190msgid "Hey, a new page was drafted by %1$s on %2$s!"
     191msgstr ""
     192
     193#. translators: %s: Name of the site
     194#: includes/events/page/class-page-hook.php:77
     195msgid "Hey, a new page was published on %s!"
     196msgstr ""
     197
     198#. translators: 1: Name of the user 2: Name of the site
     199#: includes/events/page/class-page-hook.php:83
     200msgid "Hey, a new page was published by %1$s on %2$s!"
     201msgstr ""
     202
     203#. translators: %s: Name of the site
     204#: includes/events/page/class-page-hook.php:113
     205msgid "Hey, a new page was scheduled on %s!"
     206msgstr ""
     207
     208#. translators: 1: Name of the user 2: Name of the site
     209#: includes/events/page/class-page-hook.php:119
     210msgid "Hey, a new page was scheduled by %1$s on %2$s!"
     211msgstr ""
     212
     213#. translators: %s: Name of the site
     214#: includes/events/page/class-page-hook.php:138
     215msgid "Hey, a new page is pending on %s!"
     216msgstr ""
     217
     218#. translators: %s: Name of the site
     219#: includes/events/page/class-page-hook.php:170
     220msgid "Hey, a page was updated on %s!"
     221msgstr ""
     222
     223#. translators: 1: Name of the user 2: Name of the site
    153224#: includes/events/page/class-page-hook.php:176
    154 msgid "Hey, a page was deleted!"
    155 msgstr ""
    156 
    157 #: includes/events/page/class-page-hook.php:190
    158 #: includes/events/post/class-post-hook.php:190
    159 msgid "Author"
    160 msgstr ""
    161 
    162 #: includes/events/page/class-page-hook.php:195
    163 #: includes/events/post/class-post-hook.php:195
    164 msgid "Date"
     225msgid "Hey, a page was updated by %1$s on %2$s!"
     226msgstr ""
     227
     228#. translators: %s: Name of the site
     229#: includes/events/page/class-page-hook.php:208
     230msgid "Hey, a page was deleted on %s!"
     231msgstr ""
     232
     233#. translators: 1: Name of the user 2: Name of the site
     234#: includes/events/page/class-page-hook.php:214
     235msgid "Hey, a page was deleted by %1$s on %2$s!"
    165236msgstr ""
    166237
     
    193264msgstr ""
    194265
    195 #: includes/events/post/class-post-hook.php:42
    196 msgid "Hey, a new post was drafted!"
    197 msgstr ""
    198 
    199 #: includes/events/post/class-post-hook.php:73
    200 msgid "Hey, a new post was published!"
    201 msgstr ""
    202 
    203 #: includes/events/post/class-post-hook.php:103
    204 msgid "Hey, a new post was scheduled!"
    205 msgstr ""
    206 
    207 #: includes/events/post/class-post-hook.php:134
    208 msgid "Hey, a new post is pending!"
    209 msgstr ""
    210 
    211 #: includes/events/post/class-post-hook.php:155
    212 msgid "Hey, a post was updated!"
    213 msgstr ""
    214 
     266#. translators: %s: Name of the site
     267#: includes/events/post/class-post-hook.php:41
     268msgid "Hey, a new post was drafted on %s!"
     269msgstr ""
     270
     271#. translators: 1: Name of the user 2: Name of the site
     272#: includes/events/post/class-post-hook.php:47
     273msgid "Hey, a new post was drafted by %1$s on %2$s!"
     274msgstr ""
     275
     276#. translators: %s: Name of the site
     277#: includes/events/post/class-post-hook.php:77
     278msgid "Hey, a new post was published on %s!"
     279msgstr ""
     280
     281#. translators: 1: Name of the user 2: Name of the site
     282#: includes/events/post/class-post-hook.php:83
     283msgid "Hey, a new post was published by %1$s on %2$s!"
     284msgstr ""
     285
     286#. translators: %s: Name of the site
     287#: includes/events/post/class-post-hook.php:113
     288msgid "Hey, a new post was scheduled on %s!"
     289msgstr ""
     290
     291#. translators: 1: Name of the user 2: Name of the site
     292#: includes/events/post/class-post-hook.php:119
     293msgid "Hey, a new post was scheduled by %1$s on %2$s!"
     294msgstr ""
     295
     296#. translators: %s: Name of the site
     297#: includes/events/post/class-post-hook.php:138
     298msgid "Hey, a new post is pending on %s!"
     299msgstr ""
     300
     301#. translators: %s: Name of the site
     302#: includes/events/post/class-post-hook.php:170
     303msgid "Hey, a post was updated on %s!"
     304msgstr ""
     305
     306#. translators: 1: Name of the user 2: Name of the site
    215307#: includes/events/post/class-post-hook.php:176
    216 msgid "Hey, a post was deleted!"
    217 msgstr ""
    218 
    219 #: includes/events/post/class-post-hook.php:204
     308msgid "Hey, a post was updated by %1$s on %2$s!"
     309msgstr ""
     310
     311#. translators: %s: Name of the site
     312#: includes/events/post/class-post-hook.php:208
     313msgid "Hey, a post was deleted on %s!"
     314msgstr ""
     315
     316#. translators: 1: Name of the user 2: Name of the site
     317#: includes/events/post/class-post-hook.php:214
     318msgid "Hey, a post was deleted by %1$s on %2$s!"
     319msgstr ""
     320
     321#: includes/events/post/class-post-hook.php:248
    220322msgid "Categories"
    221323msgstr ""
    222324
    223 #: includes/events/post/class-post-hook.php:213
     325#: includes/events/post/class-post-hook.php:257
    224326msgid "Tags"
     327msgstr ""
     328
     329#: includes/events/system/class-system-event.php:30
     330msgid "System"
     331msgstr ""
     332
     333#: includes/events/system/class-system-event.php:46
     334msgid "WordPress Update Available"
     335msgstr ""
     336
     337#: includes/events/system/class-system-event.php:47
     338msgid "Theme Update Available"
     339msgstr ""
     340
     341#: includes/events/system/class-system-event.php:48
     342msgid "Plugin Update Available"
     343msgstr ""
     344
     345#. translators: %s: Name of the site
     346#: includes/events/system/class-system-hook.php:67
     347msgid "Hey, a new version of WordPress is available on %s!"
     348msgstr ""
     349
     350#: includes/events/system/class-system-hook.php:73
     351msgid "Current Version"
     352msgstr ""
     353
     354#: includes/events/system/class-system-hook.php:78
     355msgid "New Version"
     356msgstr ""
     357
     358#: includes/events/system/class-system-hook.php:86
     359msgid "View the update"
     360msgstr ""
     361
     362#. translators: %s: Name of the site
     363#: includes/events/system/class-system-hook.php:153
     364msgid "Hey, new theme updates are available on %s!"
     365msgstr ""
     366
     367#: includes/events/system/class-system-hook.php:159
     368msgid "View the theme updates"
     369msgstr ""
     370
     371#. translators: %s: Name of the site
     372#: includes/events/system/class-system-hook.php:226
     373msgid "Hey, new plugin updates are available on %s!"
     374msgstr ""
     375
     376#: includes/events/system/class-system-hook.php:232
     377msgid "View the plugin updates"
     378msgstr ""
     379
     380#: includes/events/user/class-user-event.php:30
     381msgid "Users"
     382msgstr ""
     383
     384#: includes/events/user/class-user-event.php:46
     385msgid "New User Registration"
     386msgstr ""
     387
     388#: includes/events/user/class-user-event.php:47
     389msgid "Administrator Login"
     390msgstr ""
     391
     392#: includes/events/user/class-user-event.php:48
     393msgid "Administrator Failed Login"
     394msgstr ""
     395
     396#. translators: %s: Name of the site
     397#: includes/events/user/class-user-hook.php:36
     398msgid "Hey, a new user just registered on %s!"
     399msgstr ""
     400
     401#. translators: %s: Name of the site
     402#: includes/events/user/class-user-hook.php:59
     403msgid "Hey, an administrator just logged in to %s!"
     404msgstr ""
     405
     406#. translators: %s: Name of the site
     407#: includes/events/user/class-user-hook.php:92
     408msgid "Hey, an administrator just failed to log in to %s!"
     409msgstr ""
     410
     411#: includes/events/user/class-user-hook.php:110
     412msgid "Display Name"
     413msgstr ""
     414
     415#: includes/events/user/class-user-hook.php:115
     416msgid "Username"
     417msgstr ""
     418
     419#: includes/events/user/class-user-hook.php:125
     420msgid "IP Address"
     421msgstr ""
     422
     423#: includes/events/user/class-user-hook.php:138
     424msgid "View user's profile"
     425msgstr ""
     426
     427#: includes/events/user/class-user-hook.php:161
     428msgid "Unknown"
    225429msgstr ""
    226430
     
    273477msgstr ""
    274478
    275 #: includes/services/class-discord.php:44
    276 #: includes/services/class-slack.php:44
     479#: includes/services/class-discord.php:63
     480msgid "Discord"
     481msgstr ""
     482
     483#: includes/services/class-discord.php:78
     484#: includes/services/class-slack.php:80
    277485msgid "Webhook URL"
    278486msgstr ""
    279487
    280 #: includes/services/class-discord.php:46
     488#: includes/services/class-discord.php:80
    281489msgid "The webhook that you created for your Discord channel."
    282490msgstr ""
    283491
    284 #: includes/services/class-discord.php:46
    285 #: includes/services/class-slack.php:46
     492#: includes/services/class-discord.php:80
     493#: includes/services/class-slack.php:82
    286494msgid "Learn More"
    287495msgstr ""
    288496
    289 #: includes/services/class-discord.php:57
     497#: includes/services/class-discord.php:91
    290498msgid "Discord Avatar"
    291499msgstr ""
    292500
    293 #: includes/services/class-discord.php:58
     501#: includes/services/class-discord.php:92
    294502msgid "Override the default avatar of the webhook. Not required."
    295503msgstr ""
    296504
    297 #: includes/services/class-discord.php:70
     505#: includes/services/class-discord.php:104
    298506msgid "Discord Username"
    299507msgstr ""
    300508
    301 #: includes/services/class-discord.php:71
    302 #: includes/services/class-slack.php:71
     509#: includes/services/class-discord.php:105
     510#: includes/services/class-slack.php:107
    303511msgid "Override the default username of the webhook. Not required."
    304512msgstr ""
    305513
    306 #: includes/services/class-email.php:44
     514#: includes/services/class-email.php:75
    307515msgid "Send notifications to"
    308516msgstr ""
    309517
    310 #: includes/services/class-email.php:47
    311 #: includes/services/class-email.php:53
     518#: includes/services/class-email.php:78
     519#: includes/services/class-email.php:84
    312520msgid "Email Address"
    313521msgstr ""
    314522
    315 #: includes/services/class-email.php:52
     523#: includes/services/class-email.php:83
    316524msgid "Email Addresses"
    317525msgstr ""
    318526
    319 #: includes/services/class-email.php:105
     527#: includes/services/class-email.php:182
    320528msgid "Hey, here's your notification!"
    321529msgstr ""
    322530
    323 #: includes/services/class-slack.php:46
     531#: includes/services/class-slack.php:64
     532msgid "Slack"
     533msgstr ""
     534
     535#: includes/services/class-slack.php:82
    324536msgid "The webhook that you created for your Slack channel."
    325537msgstr ""
    326538
    327 #: includes/services/class-slack.php:57
     539#: includes/services/class-slack.php:93
    328540msgid "Slack Icon"
    329541msgstr ""
    330542
    331 #: includes/services/class-slack.php:58
     543#: includes/services/class-slack.php:94
    332544msgid "Override the default icon of the webhook. Not required."
    333545msgstr ""
    334546
    335 #: includes/services/class-slack.php:70
     547#: includes/services/class-slack.php:106
    336548msgid "Slack Username"
    337549msgstr ""
    338550
    339 #: includes/services/class-slack.php:83
     551#: includes/services/class-slack.php:119
    340552msgid "Color"
    341553msgstr ""
    342554
    343 #: includes/services/class-slack.php:84
     555#: includes/services/class-slack.php:120
    344556msgid "Select a color to use for the message attachment."
    345557msgstr ""
    346558
    347 #: includes/services/class-slack.php:230
     559#: includes/services/class-slack.php:233
    348560msgid "Attached image"
    349561msgstr ""
  • hey-notify/tags/1.1.0/readme.txt

    r2345565 r2349284  
    55Tested up to: 5.4
    66Requires PHP: 5.3
    7 Stable tag: 1.0.0
     7Stable tag: 1.1.0
    88License: GPLv2 or later
    99License URI: http://ww.gnu.org/licenses/gpl-2.0.html
     
    2323= Notifications for: =
    2424
    25 * Posts
    26 * Pages
    27 * Comments (coming soon)
    28 * Users (coming soon)
    29 * System Events (coming soon)
     25* Posts - Status transitions
     26* Pages - Status transitions
     27* Comments - New comments
     28* Users - New users, admin logins, failed admin logins
     29* System Events - WordPrewss, plugin, and theme updates
    3030
    3131== Installation ==
     
    4141== Changelog ==
    4242
     43= 1.1.0 =
     44* Added comment notifications.
     45* Added user notifications.
     46* Added system notifications.
     47
    4348= 1.0.0 =
    4449* Initial release.
  • hey-notify/tags/1.1.0/uninstall.php

    r2345565 r2349284  
    1313}
    1414
    15 $remove_data = \get_option( '_hey_notify_remove_data' );
     15if ( \is_multisite() ) {
     16    $sites = \get_sites(
     17        array(
     18            'number' => 99999,
     19            'fields' => 'ids',
     20        )
     21    );
     22    if ( $sites ) {
     23        foreach ( $sites as $site ) {
     24            \switch_to_blog( $site->blog_id );
     25            $remove_data = \get_option( '_hey_notify_remove_data' );
     26            if ( 'yes' === $remove_data ) {
     27                delete_options();
     28                delete_posts();
     29            }
     30            \restore_current_blog();
     31        }
     32    }
     33} else {
     34    $remove_data = \get_option( '_hey_notify_remove_data' );
     35    if ( 'yes' === $remove_data ) {
     36        delete_options();
     37        delete_posts();
     38    }
     39}
    1640
    17 if ( 'yes' === $remove_data ) {
     41/**
     42 * Delete options
     43 *
     44 * @return void
     45 */
     46function delete_options() {
    1847    \delete_option( '_hey_notify_remove_data' );
    1948    \delete_option( '_hey_notify_default_service' );
     49    \delete_option( 'hey_notify_wordpress_version' );
     50    \delete_option( 'hey_notify_theme_versions' );
     51    \delete_option( 'hey_notify_plugin_versions' );
     52}
    2053
     54/**
     55 * Delete posts
     56 *
     57 * @return void
     58 */
     59function delete_posts() {
    2160    $all_posts = \get_posts(
    2261        array(
  • hey-notify/trunk/hey-notify.php

    r2345565 r2349284  
    44 * Plugin URI: https://heynotifywp.com/
    55 * Description: Get notified when things happen in WordPress.
    6  * Version: 1.0.0
     6 * Version: 1.1.0
    77 * Author: FireTree Design, LLC <info@firetreedesign.com>
    88 * Author URI: https://firetreedesign.com/
     
    1919}
    2020
    21 define( 'HEY_NOTIFY_VERSION', '1.0.0' );
     21define( 'HEY_NOTIFY_VERSION', '1.1.0' );
    2222define( 'HEY_NOTIFY_PLUGIN_FILE', __FILE__ );
    2323define( 'HEY_NOTIFY_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
     
    3636require_once HEY_NOTIFY_PLUGIN_DIR . 'includes/events/post/loader.php';
    3737require_once HEY_NOTIFY_PLUGIN_DIR . 'includes/events/page/loader.php';
     38require_once HEY_NOTIFY_PLUGIN_DIR . 'includes/events/comment/loader.php';
     39require_once HEY_NOTIFY_PLUGIN_DIR . 'includes/events/user/loader.php';
     40require_once HEY_NOTIFY_PLUGIN_DIR . 'includes/events/system/loader.php';
    3841
    3942// Services.
  • hey-notify/trunk/includes/class-hook.php

    r2345565 r2349284  
    5656        );
    5757
    58         $new_data = wp_parse_args( $data, $defaults );
     58        $message = \wp_parse_args( $data, $defaults );
    5959
    60         do_action(
    61             'hey_notify_send_message',
    62             array(
    63                 'notification' => $this->notification,
    64                 'subject'      => $new_data['subject'],
    65                 'title'        => $new_data['title'],
    66                 'url'          => $new_data['url'],
    67                 'image'        => $new_data['image'],
    68                 'content'      => $new_data['content'],
    69                 'fields'       => $new_data['fields'],
    70                 'footer'       => $new_data['footer'],
    71             )
     60        $service = \carbon_get_post_meta( $this->notification->ID, 'hey_notify_service' );
     61
     62        \do_action(
     63            "hey_notify_send_message_{$service}",
     64            $message, // Message.
     65            'core', // Trigger.
     66            $this->notification // Data.
    7267        );
    7368    }
  • hey-notify/trunk/includes/class-service.php

    r2345565 r2349284  
    1919
    2020    /**
    21      * Class constructor
     21     * Class construct
     22     *
     23     * @return void
    2224     */
    2325    public function __construct() {
    2426        add_filter( 'hey_notify_service_fields', array( $this, 'fields' ), 10 );
    2527        add_filter( 'hey_notify_services_options', array( $this, 'services' ), 10 );
    26         add_action( 'hey_notify_send_message', array( $this, 'send' ), 10, 1 );
    2728    }
    2829
     
    4748    }
    4849
    49     /**
    50      * Send the message
    51      *
    52      * @param array $message Message.
    53      * @return void
    54      */
    55     public function send( $message ) {
    56         // Do something.
    57     }
    58 
    5950}
  • hey-notify/trunk/includes/cpt.php

    r2345565 r2349284  
    120120    switch ( $column_name ) {
    121121        case 'service':
    122             $services = \apply_filters( 'hey_notify_services_options', array() );
    123             $service  = \carbon_get_post_meta( $post_id, 'hey_notify_service' );
    124             echo "<img src='" . esc_attr( $services[ $service ] ) . "' style='width: 100px; height: auto;' />";
     122            $services_array = \apply_filters( 'hey_notify_services_options', array() );
     123            $service        = \carbon_get_post_meta( $post_id, 'hey_notify_service' );
     124            foreach ( $services_array as $services ) {
     125                if ( $service === $services['value'] ) {
     126                    echo "<img src='" . esc_attr( $services['image'] ) . "' style='width: 100px; height: auto;' />";
     127                }
     128            }
    125129            break;
    126130        case 'events':
  • hey-notify/trunk/includes/events/page/class-page-event.php

    r2345565 r2349284  
    7777        switch ( $event->{$event->type} ) {
    7878            case 'page_draft':
    79                 add_action( 'transition_post_status', array( $hook, 'page_draft' ), 10, 3 );
     79                add_action( 'auto-draft_to_draft', array( $hook, 'page_draft' ), 10, 1 );
    8080                break;
    8181            case 'page_published':
    82                 add_action( 'transition_post_status', array( $hook, 'page_published' ), 10, 3 );
     82                add_action( 'auto-draft_to_publish', array( $hook, 'page_published' ), 10, 1 );
     83                add_action( 'draft_to_publish', array( $hook, 'page_published' ), 10, 1 );
     84                add_action( 'future_to_publish', array( $hook, 'page_published' ), 10, 1 );
     85                add_action( 'pending_to_publish', array( $hook, 'page_published' ), 10, 1 );
    8386                break;
    8487            case 'page_scheduled':
    85                 add_action( 'transition_post_status', array( $hook, 'page_scheduled' ), 10, 3 );
     88                add_action( 'auto-draft_to_future', array( $hook, 'page_scheduled' ), 10, 1 );
     89                add_action( 'draft_to_future', array( $hook, 'page_scheduled' ), 10, 1 );
    8690                break;
    8791            case 'page_pending':
    88                 add_action( 'transition_post_status', array( $hook, 'page_pending' ), 10, 3 );
     92                add_action( 'auto-draft_to_pending', array( $hook, 'page_pending' ), 10, 1 );
     93                add_action( 'draft_to_pending', array( $hook, 'page_pending' ), 10, 1 );
    8994                break;
    9095            case 'page_updated':
    91                 add_action( 'transition_post_status', array( $hook, 'page_updated' ), 10, 3 );
     96                add_action( 'publish_to_publish', array( $hook, 'page_updated' ), 10, 1 );
    9297                break;
    9398            case 'page_trashed':
    94                 add_action( 'transition_post_status', array( $hook, 'page_trashed' ), 10, 3 );
     99                add_action( 'trashed_post', array( $hook, 'page_trashed' ), 10, 1 );
    95100                break;
    96101        }
  • hey-notify/trunk/includes/events/page/class-page-hook.php

    r2345565 r2349284  
    2121     * When a page enters a DRAFT state.
    2222     *
    23      * @param string $new_status New status.
    24      * @param string $old_status Old status.
    25      * @param object $post Post object.
    26      * @return void
    27      */
    28     public function page_draft( $new_status, $old_status, $post ) {
    29 
    30         if ( 'page' !== $post->post_type ) {
    31             return;
    32         }
    33 
    34         if ( 'draft' === $old_status ) {
    35             return;
    36         }
    37 
    38         if ( 'draft' !== $new_status ) {
    39             return;
    40         }
    41 
    42         $this->prepare_data( \__( 'Hey, a new page was drafted!', 'hey-notify' ), $post );
     23     * @param object $post Post object.
     24     * @return void
     25     */
     26    public function page_draft( $post ) {
     27
     28        if ( empty( $post ) || ! is_object( $post ) ) {
     29            return;
     30        }
     31
     32        if ( 'page' !== $post->post_type ) {
     33            return;
     34        }
     35
     36        $current_user = \wp_get_current_user();
     37
     38        if ( 0 === $current_user ) {
     39            $subject = \sprintf(
     40                /* translators: %s: Name of the site */
     41                \__( 'Hey, a new page was drafted on %s!', 'hey-notify' ),
     42                \get_bloginfo( 'name' )
     43            );
     44        } else {
     45            $subject = \sprintf(
     46                /* translators: 1: Name of the user 2: Name of the site */
     47                \__( 'Hey, a new page was drafted by %1$s on %2$s!', 'hey-notify' ),
     48                \esc_html( $current_user->display_name ),
     49                \get_bloginfo( 'name' )
     50            );
     51        }
     52
     53        $this->prepare_data( $subject, $post );
    4354    }
    4455
     
    4657     * When a page enters the PUBLISH state.
    4758     *
    48      * @param string $new_status New status.
    49      * @param string $old_status Old status.
    50      * @param object $post Post object.
    51      * @return void
    52      */
    53     public function page_published( $new_status, $old_status, $post ) {
    54 
    55         if ( 'page' !== $post->post_type ) {
    56             return;
    57         }
    58 
    59         $valid = false;
    60         switch ( $old_status ) {
    61             case 'new':
    62             case 'draft':
    63             case 'auto-draft':
    64             case 'pending':
    65                 $valid = true;
    66                 break;
    67         }
    68 
    69         if ( false === $valid || 'publish' !== $new_status ) {
    70             return;
    71         }
    72 
    73         $this->prepare_data( \__( 'Hey, a new page was published!', 'hey-notify' ), $post );
     59     * @param object $post Post object.
     60     * @return void
     61     */
     62    public function page_published( $post ) {
     63
     64        if ( empty( $post ) || ! is_object( $post ) ) {
     65            return;
     66        }
     67
     68        if ( 'page' !== $post->post_type ) {
     69            return;
     70        }
     71
     72        $current_user = \wp_get_current_user();
     73
     74        if ( 0 === $current_user ) {
     75            $subject = \sprintf(
     76                /* translators: %s: Name of the site */
     77                \__( 'Hey, a new page was published on %s!', 'hey-notify' ),
     78                \get_bloginfo( 'name' )
     79            );
     80        } else {
     81            $subject = \sprintf(
     82                /* translators: 1: Name of the user 2: Name of the site */
     83                \__( 'Hey, a new page was published by %1$s on %2$s!', 'hey-notify' ),
     84                \esc_html( $current_user->display_name ),
     85                \get_bloginfo( 'name' )
     86            );
     87        }
     88
     89        $this->prepare_data( $subject, $post );
    7490    }
    7591
     
    7793     * When a page enters the FUTURE state.
    7894     *
    79      * @param string $new_status New status.
    80      * @param string $old_status Old status.
    81      * @param object $post Post object.
    82      * @return void
    83      */
    84     public function page_scheduled( $new_status, $old_status, $post ) {
    85 
    86         if ( 'page' !== $post->post_type ) {
    87             return;
    88         }
    89 
    90         $valid = false;
    91         switch ( $old_status ) {
    92             case 'new':
    93             case 'draft':
    94             case 'auto-draft':
    95                 $valid = true;
    96                 break;
    97         }
    98 
    99         if ( false === $valid || 'future' !== $new_status ) {
    100             return;
    101         }
    102 
    103         $this->prepare_data( \__( 'Hey, a new page was scheduled!', 'hey-notify' ), $post );
    104     }
    105 
    106     /**
    107      * When a page enters the PENDING state
    108      *
    109      * @param string $new_status New status.
    110      * @param string $old_status Old status.
    111      * @param object $post Post object.
    112      * @return void
    113      */
    114     public function page_pending( $new_status, $old_status, $post ) {
    115 
    116         if ( 'page' !== $post->post_type ) {
    117             return;
    118         }
    119 
    120         $valid = false;
    121         switch ( $old_status ) {
    122             case 'new':
    123             case 'draft':
    124             case 'auto-draft':
    125             case 'publish':
    126                 $valid = true;
    127                 break;
    128         }
    129 
    130         if ( false === $valid || 'pending' !== $new_status ) {
    131             return;
    132         }
    133 
    134         $this->prepare_data( \__( 'Hey, a new page is pending!', 'hey-notify' ), $post );
     95     * @param object $post Post object.
     96     * @return void
     97     */
     98    public function page_scheduled( $post ) {
     99
     100        if ( empty( $post ) || ! is_object( $post ) ) {
     101            return;
     102        }
     103
     104        if ( 'page' !== $post->post_type ) {
     105            return;
     106        }
     107
     108        $current_user = \wp_get_current_user();
     109
     110        if ( 0 === $current_user ) {
     111            $subject = \sprintf(
     112                /* translators: %s: Name of the site */
     113                \__( 'Hey, a new page was scheduled on %s!', 'hey-notify' ),
     114                \get_bloginfo( 'name' )
     115            );
     116        } else {
     117            $subject = \sprintf(
     118                /* translators: 1: Name of the user 2: Name of the site */
     119                \__( 'Hey, a new page was scheduled by %1$s on %2$s!', 'hey-notify' ),
     120                \esc_html( $current_user->display_name ),
     121                \get_bloginfo( 'name' )
     122            );
     123        }
     124
     125        $this->prepare_data( $subject, $post );
     126    }
     127
     128    /**
     129     * When a page enters the PENDING state.
     130     *
     131     * @param object $post Post object.
     132     * @return void
     133     */
     134    public function page_pending( $post ) {
     135
     136        $subject = \sprintf(
     137            /* translators: %s: Name of the site */
     138            \__( 'Hey, a new page is pending on %s!', 'hey-notify' ),
     139            \get_bloginfo( 'name' )
     140        );
     141
     142        $this->prepare_data( $subject, $post );
    135143    }
    136144
     
    138146     * When a page is updated.
    139147     *
    140      * @param string $new_status New status.
    141      * @param string $old_status Old status.
    142      * @param object $post Post object.
    143      * @return void
    144      */
    145     public function page_updated( $new_status, $old_status, $post ) {
    146 
    147         if ( 'page' !== $post->post_type ) {
    148             return;
    149         }
    150 
    151         if ( $old_status !== $new_status ) {
    152             return;
    153         }
    154 
    155         $this->prepare_data( \__( 'Hey, a page was updated!', 'hey-notify' ), $post );
     148     * @param object $post Post object.
     149     * @return void
     150     */
     151    public function page_updated( $post ) {
     152
     153        if ( empty( $post ) || ! is_object( $post ) ) {
     154            return;
     155        }
     156
     157        if ( 'page' !== $post->post_type ) {
     158            return;
     159        }
     160
     161        if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) {
     162            return;
     163        }
     164
     165        $current_user = \wp_get_current_user();
     166
     167        if ( 0 === $current_user ) {
     168            $subject = \sprintf(
     169                /* translators: %s: Name of the site */
     170                \__( 'Hey, a page was updated on %s!', 'hey-notify' ),
     171                \get_bloginfo( 'name' )
     172            );
     173        } else {
     174            $subject = \sprintf(
     175                /* translators: 1: Name of the user 2: Name of the site */
     176                \__( 'Hey, a page was updated by %1$s on %2$s!', 'hey-notify' ),
     177                \esc_html( $current_user->display_name ),
     178                \get_bloginfo( 'name' )
     179            );
     180        }
     181
     182        $this->prepare_data( $subject, $post );
    156183    }
    157184
     
    159186     * When a page is trashed.
    160187     *
    161      * @param string $new_status New status.
    162      * @param string $old_status Old status.
    163      * @param object $post Post object.
    164      * @return void
    165      */
    166     public function page_trashed( $new_status, $old_status, $post ) {
    167 
    168         if ( 'page' !== $post->post_type ) {
    169             return;
    170         }
    171 
    172         if ( 'trash' !== $new_status ) {
    173             return;
    174         }
    175 
    176         $this->prepare_data( \__( 'Hey, a page was deleted!', 'hey-notify' ), $post );
     188     * @param int $id Post ID.
     189     * @return void
     190     */
     191    public function page_trashed( $id ) {
     192
     193        $post = get_post( $id );
     194
     195        if ( is_wp_error( $post ) ) {
     196            return;
     197        }
     198
     199        if ( 'page' !== $post->post_type ) {
     200            return;
     201        }
     202
     203        $current_user = \wp_get_current_user();
     204
     205        if ( 0 === $current_user ) {
     206            $subject = \sprintf(
     207                /* translators: %s: Name of the site */
     208                \__( 'Hey, a page was deleted on %s!', 'hey-notify' ),
     209                \get_bloginfo( 'name' )
     210            );
     211        } else {
     212            $subject = \sprintf(
     213                /* translators: 1: Name of the user 2: Name of the site */
     214                \__( 'Hey, a page was deleted by %1$s on %2$s!', 'hey-notify' ),
     215                \esc_html( $current_user->display_name ),
     216                \get_bloginfo( 'name' )
     217            );
     218        }
     219
     220        $this->prepare_data( $subject, $post );
    177221    }
    178222
  • hey-notify/trunk/includes/events/post/class-post-event.php

    r2345565 r2349284  
    7878        switch ( $event->{$event->type} ) {
    7979            case 'post_draft':
    80                 add_action( 'transition_post_status', array( $hook, 'post_draft' ), 10, 3 );
     80                add_action( 'auto-draft_to_draft', array( $hook, 'post_draft' ), 10, 1 );
    8181                break;
    8282            case 'post_published':
    83                 add_action( 'transition_post_status', array( $hook, 'post_published' ), 10, 3 );
     83                add_action( 'auto-draft_to_publish', array( $hook, 'post_published' ), 10, 1 );
     84                add_action( 'draft_to_publish', array( $hook, 'post_published' ), 10, 1 );
     85                add_action( 'future_to_publish', array( $hook, 'post_published' ), 10, 1 );
     86                add_action( 'pending_to_publish', array( $hook, 'post_published' ), 10, 1 );
    8487                break;
    8588            case 'post_scheduled':
    86                 add_action( 'transition_post_status', array( $hook, 'post_scheduled' ), 10, 3 );
     89                add_action( 'auto-draft_to_future', array( $hook, 'post_scheduled' ), 10, 1 );
     90                add_action( 'draft_to_future', array( $hook, 'post_scheduled' ), 10, 1 );
    8791                break;
    8892            case 'post_pending':
    89                 add_action( 'transition_post_status', array( $hook, 'post_pending' ), 10, 3 );
     93                add_action( 'auto-draft_to_pending', array( $hook, 'post_pending' ), 10, 1 );
     94                add_action( 'draft_to_pending', array( $hook, 'post_pending' ), 10, 1 );
    9095                break;
    9196            case 'post_updated':
    92                 add_action( 'transition_post_status', array( $hook, 'post_updated' ), 10, 3 );
     97                add_action( 'publish_to_publish', array( $hook, 'post_updated' ), 10, 1 );
    9398                break;
    9499            case 'post_trashed':
    95                 add_action( 'transition_post_status', array( $hook, 'post_trashed' ), 10, 3 );
     100                add_action( 'trashed_post', array( $hook, 'post_trashed' ), 10, 1 );
    96101                break;
    97102        }
  • hey-notify/trunk/includes/events/post/class-post-hook.php

    r2345565 r2349284  
    2121     * When a post enters a DRAFT state.
    2222     *
    23      * @param string $new_status New status.
    24      * @param string $old_status Old status.
    25      * @param object $post Post object.
    26      * @return void
    27      */
    28     public function post_draft( $new_status, $old_status, $post ) {
    29 
    30         if ( 'post' !== $post->post_type ) {
    31             return;
    32         }
    33 
    34         if ( 'draft' === $old_status ) {
    35             return;
    36         }
    37 
    38         if ( 'draft' !== $new_status ) {
    39             return;
    40         }
    41 
    42         $this->prepare_data( \__( 'Hey, a new post was drafted!', 'hey-notify' ), $post );
     23     * @param object $post Post object.
     24     * @return void
     25     */
     26    public function post_draft( $post ) {
     27
     28        if ( empty( $post ) || ! is_object( $post ) ) {
     29            return;
     30        }
     31
     32        if ( 'post' !== $post->post_type ) {
     33            return;
     34        }
     35
     36        $current_user = \wp_get_current_user();
     37
     38        if ( 0 === $current_user ) {
     39            $subject = \sprintf(
     40                /* translators: %s: Name of the site */
     41                \__( 'Hey, a new post was drafted on %s!', 'hey-notify' ),
     42                \get_bloginfo( 'name' )
     43            );
     44        } else {
     45            $subject = \sprintf(
     46                /* translators: 1: Name of the user 2: Name of the site */
     47                \__( 'Hey, a new post was drafted by %1$s on %2$s!', 'hey-notify' ),
     48                \esc_html( $current_user->display_name ),
     49                \get_bloginfo( 'name' )
     50            );
     51        }
     52
     53        $this->prepare_data( $subject, $post );
    4354    }
    4455
     
    4657     * When a post enters the PUBLISH state.
    4758     *
    48      * @param string $new_status New status.
    49      * @param string $old_status Old status.
    50      * @param object $post Post object.
    51      * @return void
    52      */
    53     public function post_published( $new_status, $old_status, $post ) {
    54 
    55         if ( 'post' !== $post->post_type ) {
    56             return;
    57         }
    58 
    59         $valid = false;
    60         switch ( $old_status ) {
    61             case 'new':
    62             case 'draft':
    63             case 'auto-draft':
    64             case 'pending':
    65                 $valid = true;
    66                 break;
    67         }
    68 
    69         if ( false === $valid || 'publish' !== $new_status ) {
    70             return;
    71         }
    72 
    73         $this->prepare_data( \__( 'Hey, a new post was published!', 'hey-notify' ), $post );
     59     * @param object $post Post object.
     60     * @return void
     61     */
     62    public function post_published( $post ) {
     63
     64        if ( empty( $post ) || ! is_object( $post ) ) {
     65            return;
     66        }
     67
     68        if ( 'post' !== $post->post_type ) {
     69            return;
     70        }
     71
     72        $current_user = \wp_get_current_user();
     73
     74        if ( 0 === $current_user ) {
     75            $subject = \sprintf(
     76                /* translators: %s: Name of the site */
     77                \__( 'Hey, a new post was published on %s!', 'hey-notify' ),
     78                \get_bloginfo( 'name' )
     79            );
     80        } else {
     81            $subject = \sprintf(
     82                /* translators: 1: Name of the user 2: Name of the site */
     83                \__( 'Hey, a new post was published by %1$s on %2$s!', 'hey-notify' ),
     84                \esc_html( $current_user->display_name ),
     85                \get_bloginfo( 'name' )
     86            );
     87        }
     88
     89        $this->prepare_data( $subject, $post );
    7490    }
    7591
     
    7793     * When a post enters the FUTURE state.
    7894     *
    79      * @param string $new_status New status.
    80      * @param string $old_status Old status.
    81      * @param object $post Post object.
    82      * @return void
    83      */
    84     public function post_scheduled( $new_status, $old_status, $post ) {
    85 
    86         if ( 'post' !== $post->post_type ) {
    87             return;
    88         }
    89 
    90         $valid = false;
    91         switch ( $old_status ) {
    92             case 'new':
    93             case 'draft':
    94             case 'auto-draft':
    95                 $valid = true;
    96                 break;
    97         }
    98 
    99         if ( false === $valid || 'future' !== $new_status ) {
    100             return;
    101         }
    102 
    103         $this->prepare_data( \__( 'Hey, a new post was scheduled!', 'hey-notify' ), $post );
     95     * @param object $post Post object.
     96     * @return void
     97     */
     98    public function post_scheduled( $post ) {
     99
     100        if ( empty( $post ) || ! is_object( $post ) ) {
     101            return;
     102        }
     103
     104        if ( 'post' !== $post->post_type ) {
     105            return;
     106        }
     107
     108        $current_user = \wp_get_current_user();
     109
     110        if ( 0 === $current_user ) {
     111            $subject = \sprintf(
     112                /* translators: %s: Name of the site */
     113                \__( 'Hey, a new post was scheduled on %s!', 'hey-notify' ),
     114                \get_bloginfo( 'name' )
     115            );
     116        } else {
     117            $subject = \sprintf(
     118                /* translators: 1: Name of the user 2: Name of the site */
     119                \__( 'Hey, a new post was scheduled by %1$s on %2$s!', 'hey-notify' ),
     120                \esc_html( $current_user->display_name ),
     121                \get_bloginfo( 'name' )
     122            );
     123        }
     124
     125        $this->prepare_data( $subject, $post );
    104126    }
    105127
     
    107129     * When a post enters the PENDING state.
    108130     *
    109      * @param string $new_status New status.
    110      * @param string $old_status Old status.
    111      * @param object $post Post object.
    112      * @return void
    113      */
    114     public function post_pending( $new_status, $old_status, $post ) {
    115 
    116         if ( 'post' !== $post->post_type ) {
    117             return;
    118         }
    119 
    120         $valid = false;
    121         switch ( $old_status ) {
    122             case 'new':
    123             case 'draft':
    124             case 'auto-draft':
    125             case 'publish':
    126                 $valid = true;
    127                 break;
    128         }
    129 
    130         if ( false === $valid || 'pending' !== $new_status ) {
    131             return;
    132         }
    133 
    134         $this->prepare_data( \__( 'Hey, a new post is pending!', 'hey-notify' ), $post );
     131     * @param object $post Post object.
     132     * @return void
     133     */
     134    public function post_pending( $post ) {
     135
     136        $subject = \sprintf(
     137            /* translators: %s: Name of the site */
     138            \__( 'Hey, a new post is pending on %s!', 'hey-notify' ),
     139            \get_bloginfo( 'name' )
     140        );
     141
     142        $this->prepare_data( $subject, $post );
    135143    }
    136144
     
    138146     * When a post is updated.
    139147     *
    140      * @param string $new_status New status.
    141      * @param string $old_status Old status.
    142      * @param object $post Post object.
    143      * @return void
    144      */
    145     public function post_updated( $new_status, $old_status, $post ) {
    146 
    147         if ( 'post' !== $post->post_type ) {
    148             return;
    149         }
    150 
    151         if ( $old_status !== $new_status ) {
    152             return;
    153         }
    154 
    155         $this->prepare_data( \__( 'Hey, a post was updated!', 'hey-notify' ), $post );
     148     * @param object $post Post object.
     149     * @return void
     150     */
     151    public function post_updated( $post ) {
     152
     153        if ( empty( $post ) || ! is_object( $post ) ) {
     154            return;
     155        }
     156
     157        if ( 'post' !== $post->post_type ) {
     158            return;
     159        }
     160
     161        if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) {
     162            return;
     163        }
     164
     165        $current_user = \wp_get_current_user();
     166
     167        if ( 0 === $current_user ) {
     168            $subject = \sprintf(
     169                /* translators: %s: Name of the site */
     170                \__( 'Hey, a post was updated on %s!', 'hey-notify' ),
     171                \get_bloginfo( 'name' )
     172            );
     173        } else {
     174            $subject = \sprintf(
     175                /* translators: 1: Name of the user 2: Name of the site */
     176                \__( 'Hey, a post was updated by %1$s on %2$s!', 'hey-notify' ),
     177                \esc_html( $current_user->display_name ),
     178                \get_bloginfo( 'name' )
     179            );
     180        }
     181
     182        $this->prepare_data( $subject, $post );
    156183    }
    157184
     
    159186     * When a post is trashed.
    160187     *
    161      * @param string $new_status New status.
    162      * @param string $old_status Old status.
    163      * @param object $post Post object.
    164      * @return void
    165      */
    166     public function post_trashed( $new_status, $old_status, $post ) {
    167 
    168         if ( 'post' !== $post->post_type ) {
    169             return;
    170         }
    171 
    172         if ( 'trash' !== $new_status ) {
    173             return;
    174         }
    175 
    176         $this->prepare_data( \__( 'Hey, a post was deleted!', 'hey-notify' ), $post );
     188     * @param int $id Post ID.
     189     * @return void
     190     */
     191    public function post_trashed( $id ) {
     192
     193        $post = get_post( $id );
     194
     195        if ( is_wp_error( $post ) ) {
     196            return;
     197        }
     198
     199        if ( 'post' !== $post->post_type ) {
     200            return;
     201        }
     202
     203        $current_user = \wp_get_current_user();
     204
     205        if ( 0 === $current_user ) {
     206            $subject = \sprintf(
     207                /* translators: %s: Name of the site */
     208                \__( 'Hey, a post was deleted on %s!', 'hey-notify' ),
     209                \get_bloginfo( 'name' )
     210            );
     211        } else {
     212            $subject = \sprintf(
     213                /* translators: 1: Name of the user 2: Name of the site */
     214                \__( 'Hey, a post was deleted by %1$s on %2$s!', 'hey-notify' ),
     215                \esc_html( $current_user->display_name ),
     216                \get_bloginfo( 'name' )
     217            );
     218        }
     219
     220        $this->prepare_data( $subject, $post );
    177221    }
    178222
  • hey-notify/trunk/includes/filters.php

    r2345565 r2349284  
    3030    $fields[] = (
    3131        Field::make( 'radio_image', 'hey_notify_service', __( 'Select a service', 'hey-notify' ) )
    32             ->set_options( apply_filters( 'hey_notify_services_options', array() ) )
     32            ->set_options( get_service_options() )
    3333            ->set_default_value( \get_option( '_hey_notify_default_service' ) )
    3434    );
     
    106106    $fields[] = (
    107107        Field::make( 'radio_image', 'hey_notify_default_service', __( 'Default service:', 'hey-notify' ) )
    108             ->set_options( apply_filters( 'hey_notify_services_options', array() ) )
     108            ->set_options( get_service_options() )
    109109    );
    110110    return $fields;
    111111}
     112
     113/**
     114 * Get the service options from the filter
     115 *
     116 * @return array
     117 */
     118function get_service_options() {
     119
     120    $services = apply_filters( 'hey_notify_services_options', array() );
     121    $options  = array();
     122
     123    foreach ( $services as $service ) {
     124        if ( isset( $service['image'] ) ) {
     125            $options[ $service['value'] ] = $service['image'];
     126        }
     127    }
     128
     129    return $options;
     130}
  • hey-notify/trunk/includes/services/class-discord.php

    r2345565 r2349284  
    2121
    2222    /**
     23     * Class construct
     24     *
     25     * @return void
     26     */
     27    public function __construct() {
     28        parent::__construct();
     29
     30        \add_action( 'hey_notify_send_message_discord', array( $this, 'send' ), 10, 3 );
     31        \add_action( 'hey_notify_discord_settings_core', array( $this, 'get_core_settings' ), 10, 1 );
     32    }
     33
     34    /**
     35     * Get service settings
     36     *
     37     * @param object $data Data.
     38     * @return boolean|array
     39     */
     40    public function get_core_settings( $data ) {
     41
     42        if ( ! is_object( $data ) || ! isset( $data->ID ) ) {
     43            return false;
     44        }
     45
     46        return array(
     47            'webhook_url' => \carbon_get_post_meta( $data->ID, 'hey_notify_discord_webhook' ),
     48            'username'    => \carbon_get_post_meta( $data->ID, 'hey_notify_discord_username' ),
     49            'icon'        => \carbon_get_post_meta( $data->ID, 'hey_notify_discord_avatar' ),
     50        );
     51
     52    }
     53
     54    /**
    2355     * Service options
    2456     *
     
    2759     */
    2860    public function services( $services = array() ) {
    29         if ( ! isset( $services['discord'] ) ) {
    30             $services['discord'] = HEY_NOTIFY_PLUGIN_URL . '/images/services/discord.png';
    31         }
     61        $services[] = array(
     62            'value' => 'discord',
     63            'label' => __( 'Discord', 'hey-notify' ),
     64            'image' => HEY_NOTIFY_PLUGIN_URL . 'images/services/discord.png',
     65        );
    3266
    3367        return $services;
     
    85119
    86120    /**
    87      * Send the message
     121     * Prepare the message
    88122     *
    89123     * @param array $message Message.
    90      * @return void
    91      */
    92     public function send( $message ) {
    93         $service = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_service' );
    94 
    95         if ( 'discord' !== $service ) {
    96             return;
    97         }
    98 
    99         $webhook_url = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_discord_webhook' );
    100         $username    = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_discord_username' );
    101         $avatar      = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_discord_avatar' );
    102         $body        = array();
    103         $embed_item  = array();
     124     * @param array $settings Settings.
     125     * @return array
     126     */
     127    private function prepare( $message, $settings ) {
     128
     129        $body       = array();
     130        $embed_item = array();
    104131
    105132        // Subject.
     
    150177        }
    151178
    152         $body = array(
    153             'embeds' => array( $embed_item ),
    154         );
    155 
    156         if ( '' !== $username ) {
    157             $body['username'] = $username;
    158         }
    159 
    160         if ( '' !== $avatar ) {
    161             $avatar = \wp_get_attachment_image_url( $avatar, array( 250, 250 ) );
    162             if ( false !== $avatar ) {
    163                 $body['avatar_url'] = $avatar;
     179        $body['embeds'] = array( $embed_item );
     180
     181        if ( '' !== $settings['username'] ) {
     182            $body['username'] = $settings['username'];
     183        }
     184
     185        if ( '' !== $settings['avatar'] ) {
     186            if ( filter_var( $settings['avatar'], FILTER_VALIDATE_URL ) ) {
     187                $body['avatar_url'] = $settings['avatar'];
     188            } else {
     189                $avatar = \wp_get_attachment_image_url( $settings['avatar'], array( 250, 250 ) );
     190                if ( false !== $avatar ) {
     191                    $body['avatar_url'] = $avatar;
     192                }
    164193            }
    165194        }
     195
     196        return $body;
     197
     198    }
     199
     200    /**
     201     * Send the message
     202     *
     203     * @param array  $message Message.
     204     * @param string $trigger Trigger.
     205     * @param mixed  $data Data.
     206     * @return void
     207     */
     208    public function send( $message, $trigger, $data ) {
     209
     210        $settings = \apply_filters( "hey_notify_discord_settings_{$trigger}", $data );
     211
     212        if ( ! is_array( $settings ) || ! isset( $settings['webhook_url'] ) ) {
     213            return;
     214        }
     215
     216        $body = $this->prepare( $message, $settings );
    166217
    167218        $json     = \wp_json_encode( $body );
    168219        $response = \wp_remote_post(
    169             $webhook_url,
     220            $settings['webhook_url'],
    170221            array(
    171222                'headers' => array(
     
    176227        );
    177228
    178         do_action( 'hey_notify_message_sent', $json, $response );
     229        \do_action(
     230            'hey_notify_message_sent',
     231            array(
     232                'service'  => 'discord',
     233                'json'     => $json,
     234                'response' => $response,
     235                'trigger'  => $trigger,
     236                'message'  => $message,
     237                'data'     => $data,
     238            )
     239        );
    179240
    180241        if ( ! \is_wp_error( $response ) ) {
  • hey-notify/trunk/includes/services/class-email.php

    r2345565 r2349284  
    2121
    2222    /**
     23     * Class construct
     24     *
     25     * @return void
     26     */
     27    public function __construct() {
     28        parent::__construct();
     29
     30        \add_action( 'hey_notify_send_message_email', array( $this, 'send' ), 10, 3 );
     31        \add_filter( 'hey_notify_email_settings_core', array( $this, 'get_core_settings' ), 10, 1 );
     32    }
     33
     34    /**
     35     * Get service settings
     36     *
     37     * @param object $data Data.
     38     * @return boolean|array
     39     */
     40    public function get_core_settings( $data ) {
     41
     42        if ( ! is_object( $data ) || ! isset( $data->ID ) ) {
     43            return false;
     44        }
     45
     46        return array(
     47            'email_addresses' => \carbon_get_post_meta( $data->ID, 'hey_notify_email_addresses' ),
     48        );
     49    }
     50
     51    /**
    2352     * Service options
    2453     *
     
    2756     */
    2857    public function services( $services = array() ) {
    29         if ( ! isset( $services['email'] ) ) {
    30             $services['email'] = HEY_NOTIFY_PLUGIN_URL . '/images/services/email.png';
    31         }
     58        $services[] = array(
     59            'value' => 'email',
     60            'label' => __( 'Email', 'hey-notify' ),
     61            'image' => HEY_NOTIFY_PLUGIN_URL . 'images/services/email.png',
     62        );
    3263
    3364        return $services;
     
    70101
    71102    /**
     103     * Prepare the message
     104     *
     105     * @param array $message Message.
     106     * @param array $settings Settings.
     107     * @return string
     108     */
     109    private function prepare( $message, $settings ) {
     110
     111        $body = '';
     112
     113        // Title.
     114        if ( isset( $message['title'] ) && '' !== $message['title'] ) {
     115            $body .= "{$message['title']}\r\n";
     116        }
     117
     118        // URL.
     119        if ( isset( $message['url'] ) && '' !== $message['url'] ) {
     120            $body .= "{$message['url']}\r\n\r\n";
     121        }
     122
     123        // Content.
     124        if ( isset( $message['content'] ) && '' !== $message['content'] ) {
     125            $body .= "{$message['content']}\r\n\r\n";
     126        }
     127
     128        // Fields.
     129        if ( isset( $message['fields'] ) && is_array( $message['fields'] ) ) {
     130            foreach ( $message['fields'] as $field ) {
     131                $body .= "{$field['name']}: {$field['value']}\r\n";
     132            }
     133        }
     134
     135        // Footer.
     136        if ( isset( $message['footer'] ) && '' !== $message['footer'] ) {
     137            $body .= "{$message['footer']}";
     138        }
     139
     140        return $body;
     141    }
     142
     143    /**
    72144     * Send the message
    73145     *
    74      * @param array $message Message.
     146     * @param array  $message Message.
     147     * @param string $trigger Trigger.
     148     * @param mixed  $data Data.
    75149     * @return void
    76150     */
    77     public function send( $message ) {
    78 
    79         $service = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_service' );
    80 
    81         if ( 'email' !== $service ) {
     151    public function send( $message, $trigger, $data ) {
     152
     153        $settings = \apply_filters( "hey_notify_email_settings_{$trigger}", $data );
     154
     155        if ( false === $settings ) {
    82156            return;
    83157        }
    84158
    85         $email_addresses = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_email_addresses' );
    86         $to_email        = array();
    87         if ( $email_addresses ) {
    88             foreach ( $email_addresses as $email ) {
     159        if ( ! is_array( $settings ) || ! isset( $settings['email_addresses'] ) ) {
     160            return;
     161        }
     162
     163        $to_email = array();
     164        if ( $settings['email_addresses'] ) {
     165            foreach ( $settings['email_addresses'] as $email ) {
    89166                if ( '' !== trim( $email['email'] ) ) {
    90167                    $to_email[] = $email['email'];
     
    106183        }
    107184
    108         $body = '';
    109 
    110         // Title.
    111         if ( isset( $message['title'] ) && '' !== $message['title'] ) {
    112             $body .= "{$message['title']}\r\n";
    113         }
    114 
    115         // URL.
    116         if ( isset( $message['url'] ) && '' !== $message['url'] ) {
    117             $body .= "{$message['url']}\r\n\r\n";
    118         }
    119 
    120         // Content.
    121         if ( isset( $message['content'] ) && '' !== $message['content'] ) {
    122             $body .= "{$message['content']}\r\n\r\n";
    123         }
    124 
    125         // Fields.
    126         if ( isset( $message['fields'] ) && is_array( $message['fields'] ) ) {
    127             foreach ( $message['fields'] as $field ) {
    128                 $body .= "{$field['name']}: {$field['value']}\r\n";
    129             }
    130         }
    131 
    132         // Footer.
    133         if ( isset( $message['footer'] ) && '' !== $message['footer'] ) {
    134             $body .= "{$message['footer']}";
    135         }
     185        $body = $this->prepare( $message, $settings );
    136186
    137187        $headers = array(
     
    141191        $result = wp_mail( $to_email, $subject, $body, $headers );
    142192
    143         do_action( 'hey_notify_message_sent', $body, $result );
     193        \do_action(
     194            'hey_notify_message_sent',
     195            array(
     196                'service'  => 'email',
     197                'response' => $result,
     198                'trigger'  => $trigger,
     199                'message'  => $message,
     200                'data'     => $data,
     201            )
     202        );
    144203    }
    145204}
  • hey-notify/trunk/includes/services/class-slack.php

    r2345565 r2349284  
    2121
    2222    /**
     23     * Class construct
     24     *
     25     * @return void
     26     */
     27    public function __construct() {
     28        parent::__construct();
     29
     30        \add_action( 'hey_notify_send_message_slack', array( $this, 'send' ), 10, 3 );
     31        \add_filter( 'hey_notify_slack_settings_core', array( $this, 'get_core_settings' ), 10, 1 );
     32    }
     33
     34    /**
     35     * Get service settings
     36     *
     37     * @param object $data Data.
     38     * @return boolean|array
     39     */
     40    public function get_core_settings( $data ) {
     41
     42        if ( ! is_object( $data ) || ! isset( $data->ID ) ) {
     43            return false;
     44        }
     45
     46        return array(
     47            'webhook_url' => \carbon_get_post_meta( $data->ID, 'hey_notify_slack_webhook' ),
     48            'username'    => \carbon_get_post_meta( $data->ID, 'hey_notify_slack_username' ),
     49            'icon'        => \carbon_get_post_meta( $data->ID, 'hey_notify_slack_icon' ),
     50            'color'       => \carbon_get_post_meta( $data->ID, 'hey_notify_slack_color' ),
     51        );
     52    }
     53
     54    /**
    2355     * Add the service
    2456     *
     
    2759     */
    2860    public function services( $services = array() ) {
    29         if ( ! isset( $services['slack'] ) ) {
    30             $services['slack'] = HEY_NOTIFY_PLUGIN_URL . '/images/services/slack.png';
    31         }
     61
     62        $services[] = array(
     63            'value' => 'slack',
     64            'label' => __( 'Slack', 'hey-notify' ),
     65            'image' => HEY_NOTIFY_PLUGIN_URL . 'images/services/slack.png',
     66        );
    3267
    3368        return $services;
     
    4176     */
    4277    public function fields( $fields = array() ) {
     78
    4379        $fields[] = (
    4480            Field::make( 'text', 'hey_notify_slack_webhook', __( 'Webhook URL', 'hey-notify' ) )
     
    83119            Field::make( 'color', 'hey_notify_slack_color', __( 'Color', 'hey-notify' ) )
    84120                ->set_help_text( __( 'Select a color to use for the message attachment.', 'hey-notify' ) )
     121                ->set_default_value( '#009bff' )
    85122                ->set_conditional_logic(
    86123                    array(
     
    97134
    98135    /**
    99      * Prepare the message
    100      *
    101      * @param array $message Message.
    102      * @return array
    103      */
    104     private function prepare( $message ) {
    105         $clean_message = array(
    106             'notification' => $message['notification'],
    107             'subject'      => $this->sanitize( $message['subject'] ),
    108             'title'        => $this->sanitize( $message['title'] ),
    109             'url'          => $message['url'],
    110             'image'        => $message['image'],
    111             'content'      => $this->sanitize( $message['content'] ),
    112             'footer'       => $this->sanitize( $message['footer'] ),
    113         );
    114 
    115         $clean_fields = array();
    116         foreach ( $message['fields'] as $field ) {
    117             $clean_fields[] = array(
    118                 'name'   => $this->sanitize( $field['name'] ),
    119                 'value'  => $this->sanitize( $field['value'] ),
    120                 'inline' => $field['inline'],
    121             );
    122         }
    123 
    124         $clean_message['fields'] = $clean_fields;
    125 
    126         return $clean_message;
    127     }
    128 
    129     /**
    130136     * Sanitize a string for Slack
    131137     *
     
    134140     */
    135141    private function sanitize( $string ) {
    136         $string = str_replace( '&', '&amp;', $string );
    137         $string = str_replace( '<', '&lt;', $string );
    138         $string = str_replace( '>', '&gt;', $string );
     142        $string = \str_replace( '&', '&amp;', $string );
     143        $string = \str_replace( '<', '&lt;', $string );
     144        $string = \str_replace( '>', '&gt;', $string );
    139145        return $string;
    140146    }
    141147
    142148    /**
    143      * Send the message
     149     * Prepare the message
    144150     *
    145151     * @param array $message Message.
    146      * @return void
    147      */
    148     public function send( $message ) {
    149         $service = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_service' );
    150 
    151         if ( 'slack' !== $service ) {
    152             return;
    153         }
    154 
    155         $message = $this->prepare( $message );
    156 
    157         $webhook_url = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_slack_webhook' );
    158         $username    = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_slack_username' );
    159         $icon        = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_slack_icon' );
    160         $color       = \carbon_get_post_meta( $message['notification']->ID, 'hey_notify_slack_color' );
    161         $blocks      = array();
     152     * @param array $settings Settings.
     153     * @return array
     154     */
     155    private function prepare( $message, $settings ) {
     156
     157        $subject = $this->sanitize( $message['subject'] );
     158        $title   = $this->sanitize( $message['title'] );
     159        $content = $this->sanitize( $message['content'] );
     160        $footer  = $this->sanitize( $message['footer'] );
     161        $image   = $message['image'];
     162        $url     = $message['url'];
     163
     164        $blocks = array();
    162165
    163166        // Subject.
    164         if ( isset( $message['subject'] ) && '' !== $message['subject'] ) {
    165             $blocks[] = array(
    166                 'type' => 'section',
    167                 'text' => array(
    168                     'type' => 'mrkdwn',
    169                     'text' => $message['subject'],
     167        if ( isset( $subject ) && '' !== $subject ) {
     168            $blocks[] = array(
     169                'type' => 'section',
     170                'text' => array(
     171                    'type' => 'mrkdwn',
     172                    'text' => $subject,
    170173                ),
    171174            );
     
    173176
    174177        // Title and URL.
    175         if ( '' !== $message['title'] && '' !== $message['url'] ) {
    176             $blocks[] = array(
    177                 'type' => 'section',
    178                 'text' => array(
    179                     'type' => 'mrkdwn',
    180                     'text' => "*<{$message['url']}|{$message['title']}>*",
    181                 ),
    182             );
    183         } elseif ( '' !== $message['title'] && '' === $message['url'] ) {
    184             $blocks[] = array(
    185                 'type' => 'section',
    186                 'text' => array(
    187                     'type' => 'mrkdwn',
    188                     'text' => "*{$message['title']}*",
    189                 ),
    190             );
    191         } elseif ( '' === $message['title'] && '' !== $message['url'] ) {
    192             $blocks[] = array(
    193                 'type' => 'section',
    194                 'text' => array(
    195                     'type' => 'mrkdwn',
    196                     'text' => "*<{$message['url']}|{$message['url']}>*",
     178        if ( '' !== $title && '' !== $url ) {
     179            $blocks[] = array(
     180                'type' => 'section',
     181                'text' => array(
     182                    'type' => 'mrkdwn',
     183                    'text' => "*<{$url}|{$title}>*",
     184                ),
     185            );
     186        } elseif ( '' !== $title && '' === $url ) {
     187            $blocks[] = array(
     188                'type' => 'section',
     189                'text' => array(
     190                    'type' => 'mrkdwn',
     191                    'text' => "*{$title}*",
     192                ),
     193            );
     194        } elseif ( '' === $title && '' !== $url ) {
     195            $blocks[] = array(
     196                'type' => 'section',
     197                'text' => array(
     198                    'type' => 'mrkdwn',
     199                    'text' => "*<{$url}|{$url}>*",
    197200                ),
    198201            );
     
    200203
    201204        // Content.
    202         if ( isset( $message['content'] ) && '' !== $message['content'] ) {
    203             $blocks[] = array(
    204                 'type' => 'section',
    205                 'text' => array(
    206                     'type' => 'mrkdwn',
    207                     'text' => $message['content'],
     205        if ( isset( $content ) && '' !== $content ) {
     206            $blocks[] = array(
     207                'type' => 'section',
     208                'text' => array(
     209                    'type' => 'mrkdwn',
     210                    'text' => $content,
    208211                ),
    209212            );
     
    216219                $fields[] = array(
    217220                    'type' => 'mrkdwn',
    218                     'text' => "*{$field['name']}*\n{$field['value']}",
     221                    'text' => "*{$this->sanitize( $field['name'] )}*\n{$this->sanitize( $field['value'] )}",
    219222                );
    220223            }
     
    224227            );
    225228
    226             if ( isset( $message['image'] ) && '' !== $message['image'] ) {
     229            if ( isset( $image ) && '' !== $image ) {
    227230                $fields_array['accessory'] = array(
    228231                    'type'      => 'image',
    229                     'image_url' => $message['image'],
    230                     'alt_text'  => isset( $message['title'] ) ? $message['title'] : __( 'Attached image', 'hey-notify' ),
     232                    'image_url' => $image,
     233                    'alt_text'  => isset( $title ) ? $title : __( 'Attached image', 'hey-notify' ),
    231234                );
    232235            }
     
    236239
    237240        // Footer.
    238         if ( isset( $message['footer'] ) && '' !== $message['footer'] ) {
    239             $blocks[] = array(
    240                 'type' => 'section',
    241                 'text' => array(
    242                     'type' => 'mrkdwn',
    243                     'text' => $message['footer'],
     241        if ( isset( $footer ) && '' !== $footer ) {
     242            $blocks[] = array(
     243                'type' => 'section',
     244                'text' => array(
     245                    'type' => 'mrkdwn',
     246                    'text' => $footer,
    244247                ),
    245248            );
     
    249252
    250253        $body['attachments'][] = array(
    251             'color'  => $color,
     254            'color'  => $settings['color'],
    252255            'blocks' => $blocks,
    253256        );
    254257
    255         if ( '' !== $username ) {
    256             $body['username'] = $username;
    257         }
    258 
    259         if ( '' !== $icon ) {
    260             $icon_url = \wp_get_attachment_image_url( $icon, array( 250, 250 ) );
    261             if ( false !== $icon_url ) {
    262                 $body['icon_url'] = $icon_url;
     258        if ( '' !== $settings['username'] ) {
     259            $body['username'] = $settings['username'];
     260        }
     261
     262        if ( '' !== $settings['icon'] ) {
     263            if ( filter_var( $settings['icon'], FILTER_VALIDATE_URL ) ) {
     264                $body['icon_url'] = $settings['icon'];
     265            } else {
     266                $icon_url = \wp_get_attachment_image_url( $settings['icon'], array( 250, 250 ) );
     267                if ( false !== $icon_url ) {
     268                    $body['icon_url'] = $icon_url;
     269                }
    263270            }
    264271        }
     272
     273        return $body;
     274    }
     275
     276    /**
     277     * Send the message
     278     *
     279     * @param array  $message Message.
     280     * @param string $trigger Trigger.
     281     * @param mixed  $data Data.
     282     * @return void
     283     */
     284    public function send( $message, $trigger, $data ) {
     285
     286        $settings = \apply_filters( "hey_notify_slack_settings_{$trigger}", $data );
     287
     288        if ( ! is_array( $settings ) || ! isset( $settings['webhook_url'] ) ) {
     289            return;
     290        }
     291
     292        $body = $this->prepare( $message, $settings );
    265293
    266294        $json     = \wp_json_encode( $body );
    267295        $response = \wp_remote_post(
    268             $webhook_url,
     296            $settings['webhook_url'],
    269297            array(
    270298                'headers' => array(
     
    275303        );
    276304
    277         do_action( 'hey_notify_message_sent', $json, $response );
     305        \do_action(
     306            'hey_notify_message_sent',
     307            array(
     308                'service'  => 'slack',
     309                'json'     => $json,
     310                'response' => $response,
     311                'trigger'  => $trigger,
     312                'message'  => $message,
     313                'data'     => $data,
     314            )
     315        );
    278316
    279317        if ( ! \is_wp_error( $response ) ) {
  • hey-notify/trunk/languages/hey-notify.pot

    r2345565 r2349284  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Hey Notify 1.0.0\n"
     5"Project-Id-Version: Hey Notify 1.1.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/hey-notify\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2020-07-21T19:21:51+00:00\n"
     12"POT-Creation-Date: 2020-07-30T18:02:04+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.1.0\n"
     
    1717#. Plugin Name of the plugin
    1818#: includes/cpt.php:35
    19 #: includes/services/class-email.php:99
     19#: includes/services/class-email.php:176
    2020msgid "Hey Notify"
    2121msgstr ""
     
    9898msgstr ""
    9999
     100#: includes/events/comment/class-comment-event.php:30
     101msgid "Comments"
     102msgstr ""
     103
     104#: includes/events/comment/class-comment-event.php:43
     105#: includes/events/page/class-page-event.php:43
     106#: includes/events/post/class-post-event.php:43
     107#: includes/events/system/class-system-event.php:43
     108#: includes/events/user/class-user-event.php:43
     109msgid "Action"
     110msgstr ""
     111
     112#: includes/events/comment/class-comment-event.php:46
     113msgid "New Comment"
     114msgstr ""
     115
     116#. translators: %s: Name of the site
     117#: includes/events/comment/class-comment-hook.php:41
     118msgid "Hey, a new comment has been posted on %s!"
     119msgstr ""
     120
     121#: includes/events/comment/class-comment-hook.php:59
     122#: includes/events/page/class-page-hook.php:234
     123#: includes/events/post/class-post-hook.php:234
     124msgid "Author"
     125msgstr ""
     126
     127#: includes/events/comment/class-comment-hook.php:64
     128#: includes/events/user/class-user-hook.php:120
     129#: includes/services/class-email.php:60
     130msgid "Email"
     131msgstr ""
     132
     133#: includes/events/comment/class-comment-hook.php:69
     134#: includes/events/page/class-page-hook.php:239
     135#: includes/events/post/class-post-hook.php:239
     136msgid "Date"
     137msgstr ""
     138
     139#: includes/events/comment/class-comment-hook.php:74
     140msgid "Status"
     141msgstr ""
     142
     143#: includes/events/comment/class-comment-hook.php:106
     144msgid "Approved"
     145msgstr ""
     146
     147#: includes/events/comment/class-comment-hook.php:108
     148msgid "Pending"
     149msgstr ""
     150
     151#: includes/events/comment/class-comment-hook.php:110
     152msgid "Spam"
     153msgstr ""
     154
    100155#: includes/events/page/class-page-event.php:30
    101156msgid "Pages"
    102157msgstr ""
    103158
    104 #: includes/events/page/class-page-event.php:43
    105 #: includes/events/post/class-post-event.php:43
    106 msgid "Action"
    107 msgstr ""
    108 
    109159#: includes/events/page/class-page-event.php:46
    110160msgid "Page Draft"
     
    131181msgstr ""
    132182
    133 #: includes/events/page/class-page-hook.php:42
    134 msgid "Hey, a new page was drafted!"
    135 msgstr ""
    136 
    137 #: includes/events/page/class-page-hook.php:73
    138 msgid "Hey, a new page was published!"
    139 msgstr ""
    140 
    141 #: includes/events/page/class-page-hook.php:103
    142 msgid "Hey, a new page was scheduled!"
    143 msgstr ""
    144 
    145 #: includes/events/page/class-page-hook.php:134
    146 msgid "Hey, a new page is pending!"
    147 msgstr ""
    148 
    149 #: includes/events/page/class-page-hook.php:155
    150 msgid "Hey, a page was updated!"
    151 msgstr ""
    152 
     183#. translators: %s: Name of the site
     184#: includes/events/page/class-page-hook.php:41
     185msgid "Hey, a new page was drafted on %s!"
     186msgstr ""
     187
     188#. translators: 1: Name of the user 2: Name of the site
     189#: includes/events/page/class-page-hook.php:47
     190msgid "Hey, a new page was drafted by %1$s on %2$s!"
     191msgstr ""
     192
     193#. translators: %s: Name of the site
     194#: includes/events/page/class-page-hook.php:77
     195msgid "Hey, a new page was published on %s!"
     196msgstr ""
     197
     198#. translators: 1: Name of the user 2: Name of the site
     199#: includes/events/page/class-page-hook.php:83
     200msgid "Hey, a new page was published by %1$s on %2$s!"
     201msgstr ""
     202
     203#. translators: %s: Name of the site
     204#: includes/events/page/class-page-hook.php:113
     205msgid "Hey, a new page was scheduled on %s!"
     206msgstr ""
     207
     208#. translators: 1: Name of the user 2: Name of the site
     209#: includes/events/page/class-page-hook.php:119
     210msgid "Hey, a new page was scheduled by %1$s on %2$s!"
     211msgstr ""
     212
     213#. translators: %s: Name of the site
     214#: includes/events/page/class-page-hook.php:138
     215msgid "Hey, a new page is pending on %s!"
     216msgstr ""
     217
     218#. translators: %s: Name of the site
     219#: includes/events/page/class-page-hook.php:170
     220msgid "Hey, a page was updated on %s!"
     221msgstr ""
     222
     223#. translators: 1: Name of the user 2: Name of the site
    153224#: includes/events/page/class-page-hook.php:176
    154 msgid "Hey, a page was deleted!"
    155 msgstr ""
    156 
    157 #: includes/events/page/class-page-hook.php:190
    158 #: includes/events/post/class-post-hook.php:190
    159 msgid "Author"
    160 msgstr ""
    161 
    162 #: includes/events/page/class-page-hook.php:195
    163 #: includes/events/post/class-post-hook.php:195
    164 msgid "Date"
     225msgid "Hey, a page was updated by %1$s on %2$s!"
     226msgstr ""
     227
     228#. translators: %s: Name of the site
     229#: includes/events/page/class-page-hook.php:208
     230msgid "Hey, a page was deleted on %s!"
     231msgstr ""
     232
     233#. translators: 1: Name of the user 2: Name of the site
     234#: includes/events/page/class-page-hook.php:214
     235msgid "Hey, a page was deleted by %1$s on %2$s!"
    165236msgstr ""
    166237
     
    193264msgstr ""
    194265
    195 #: includes/events/post/class-post-hook.php:42
    196 msgid "Hey, a new post was drafted!"
    197 msgstr ""
    198 
    199 #: includes/events/post/class-post-hook.php:73
    200 msgid "Hey, a new post was published!"
    201 msgstr ""
    202 
    203 #: includes/events/post/class-post-hook.php:103
    204 msgid "Hey, a new post was scheduled!"
    205 msgstr ""
    206 
    207 #: includes/events/post/class-post-hook.php:134
    208 msgid "Hey, a new post is pending!"
    209 msgstr ""
    210 
    211 #: includes/events/post/class-post-hook.php:155
    212 msgid "Hey, a post was updated!"
    213 msgstr ""
    214 
     266#. translators: %s: Name of the site
     267#: includes/events/post/class-post-hook.php:41
     268msgid "Hey, a new post was drafted on %s!"
     269msgstr ""
     270
     271#. translators: 1: Name of the user 2: Name of the site
     272#: includes/events/post/class-post-hook.php:47
     273msgid "Hey, a new post was drafted by %1$s on %2$s!"
     274msgstr ""
     275
     276#. translators: %s: Name of the site
     277#: includes/events/post/class-post-hook.php:77
     278msgid "Hey, a new post was published on %s!"
     279msgstr ""
     280
     281#. translators: 1: Name of the user 2: Name of the site
     282#: includes/events/post/class-post-hook.php:83
     283msgid "Hey, a new post was published by %1$s on %2$s!"
     284msgstr ""
     285
     286#. translators: %s: Name of the site
     287#: includes/events/post/class-post-hook.php:113
     288msgid "Hey, a new post was scheduled on %s!"
     289msgstr ""
     290
     291#. translators: 1: Name of the user 2: Name of the site
     292#: includes/events/post/class-post-hook.php:119
     293msgid "Hey, a new post was scheduled by %1$s on %2$s!"
     294msgstr ""
     295
     296#. translators: %s: Name of the site
     297#: includes/events/post/class-post-hook.php:138
     298msgid "Hey, a new post is pending on %s!"
     299msgstr ""
     300
     301#. translators: %s: Name of the site
     302#: includes/events/post/class-post-hook.php:170
     303msgid "Hey, a post was updated on %s!"
     304msgstr ""
     305
     306#. translators: 1: Name of the user 2: Name of the site
    215307#: includes/events/post/class-post-hook.php:176
    216 msgid "Hey, a post was deleted!"
    217 msgstr ""
    218 
    219 #: includes/events/post/class-post-hook.php:204
     308msgid "Hey, a post was updated by %1$s on %2$s!"
     309msgstr ""
     310
     311#. translators: %s: Name of the site
     312#: includes/events/post/class-post-hook.php:208
     313msgid "Hey, a post was deleted on %s!"
     314msgstr ""
     315
     316#. translators: 1: Name of the user 2: Name of the site
     317#: includes/events/post/class-post-hook.php:214
     318msgid "Hey, a post was deleted by %1$s on %2$s!"
     319msgstr ""
     320
     321#: includes/events/post/class-post-hook.php:248
    220322msgid "Categories"
    221323msgstr ""
    222324
    223 #: includes/events/post/class-post-hook.php:213
     325#: includes/events/post/class-post-hook.php:257
    224326msgid "Tags"
     327msgstr ""
     328
     329#: includes/events/system/class-system-event.php:30
     330msgid "System"
     331msgstr ""
     332
     333#: includes/events/system/class-system-event.php:46
     334msgid "WordPress Update Available"
     335msgstr ""
     336
     337#: includes/events/system/class-system-event.php:47
     338msgid "Theme Update Available"
     339msgstr ""
     340
     341#: includes/events/system/class-system-event.php:48
     342msgid "Plugin Update Available"
     343msgstr ""
     344
     345#. translators: %s: Name of the site
     346#: includes/events/system/class-system-hook.php:67
     347msgid "Hey, a new version of WordPress is available on %s!"
     348msgstr ""
     349
     350#: includes/events/system/class-system-hook.php:73
     351msgid "Current Version"
     352msgstr ""
     353
     354#: includes/events/system/class-system-hook.php:78
     355msgid "New Version"
     356msgstr ""
     357
     358#: includes/events/system/class-system-hook.php:86
     359msgid "View the update"
     360msgstr ""
     361
     362#. translators: %s: Name of the site
     363#: includes/events/system/class-system-hook.php:153
     364msgid "Hey, new theme updates are available on %s!"
     365msgstr ""
     366
     367#: includes/events/system/class-system-hook.php:159
     368msgid "View the theme updates"
     369msgstr ""
     370
     371#. translators: %s: Name of the site
     372#: includes/events/system/class-system-hook.php:226
     373msgid "Hey, new plugin updates are available on %s!"
     374msgstr ""
     375
     376#: includes/events/system/class-system-hook.php:232
     377msgid "View the plugin updates"
     378msgstr ""
     379
     380#: includes/events/user/class-user-event.php:30
     381msgid "Users"
     382msgstr ""
     383
     384#: includes/events/user/class-user-event.php:46
     385msgid "New User Registration"
     386msgstr ""
     387
     388#: includes/events/user/class-user-event.php:47
     389msgid "Administrator Login"
     390msgstr ""
     391
     392#: includes/events/user/class-user-event.php:48
     393msgid "Administrator Failed Login"
     394msgstr ""
     395
     396#. translators: %s: Name of the site
     397#: includes/events/user/class-user-hook.php:36
     398msgid "Hey, a new user just registered on %s!"
     399msgstr ""
     400
     401#. translators: %s: Name of the site
     402#: includes/events/user/class-user-hook.php:59
     403msgid "Hey, an administrator just logged in to %s!"
     404msgstr ""
     405
     406#. translators: %s: Name of the site
     407#: includes/events/user/class-user-hook.php:92
     408msgid "Hey, an administrator just failed to log in to %s!"
     409msgstr ""
     410
     411#: includes/events/user/class-user-hook.php:110
     412msgid "Display Name"
     413msgstr ""
     414
     415#: includes/events/user/class-user-hook.php:115
     416msgid "Username"
     417msgstr ""
     418
     419#: includes/events/user/class-user-hook.php:125
     420msgid "IP Address"
     421msgstr ""
     422
     423#: includes/events/user/class-user-hook.php:138
     424msgid "View user's profile"
     425msgstr ""
     426
     427#: includes/events/user/class-user-hook.php:161
     428msgid "Unknown"
    225429msgstr ""
    226430
     
    273477msgstr ""
    274478
    275 #: includes/services/class-discord.php:44
    276 #: includes/services/class-slack.php:44
     479#: includes/services/class-discord.php:63
     480msgid "Discord"
     481msgstr ""
     482
     483#: includes/services/class-discord.php:78
     484#: includes/services/class-slack.php:80
    277485msgid "Webhook URL"
    278486msgstr ""
    279487
    280 #: includes/services/class-discord.php:46
     488#: includes/services/class-discord.php:80
    281489msgid "The webhook that you created for your Discord channel."
    282490msgstr ""
    283491
    284 #: includes/services/class-discord.php:46
    285 #: includes/services/class-slack.php:46
     492#: includes/services/class-discord.php:80
     493#: includes/services/class-slack.php:82
    286494msgid "Learn More"
    287495msgstr ""
    288496
    289 #: includes/services/class-discord.php:57
     497#: includes/services/class-discord.php:91
    290498msgid "Discord Avatar"
    291499msgstr ""
    292500
    293 #: includes/services/class-discord.php:58
     501#: includes/services/class-discord.php:92
    294502msgid "Override the default avatar of the webhook. Not required."
    295503msgstr ""
    296504
    297 #: includes/services/class-discord.php:70
     505#: includes/services/class-discord.php:104
    298506msgid "Discord Username"
    299507msgstr ""
    300508
    301 #: includes/services/class-discord.php:71
    302 #: includes/services/class-slack.php:71
     509#: includes/services/class-discord.php:105
     510#: includes/services/class-slack.php:107
    303511msgid "Override the default username of the webhook. Not required."
    304512msgstr ""
    305513
    306 #: includes/services/class-email.php:44
     514#: includes/services/class-email.php:75
    307515msgid "Send notifications to"
    308516msgstr ""
    309517
    310 #: includes/services/class-email.php:47
    311 #: includes/services/class-email.php:53
     518#: includes/services/class-email.php:78
     519#: includes/services/class-email.php:84
    312520msgid "Email Address"
    313521msgstr ""
    314522
    315 #: includes/services/class-email.php:52
     523#: includes/services/class-email.php:83
    316524msgid "Email Addresses"
    317525msgstr ""
    318526
    319 #: includes/services/class-email.php:105
     527#: includes/services/class-email.php:182
    320528msgid "Hey, here's your notification!"
    321529msgstr ""
    322530
    323 #: includes/services/class-slack.php:46
     531#: includes/services/class-slack.php:64
     532msgid "Slack"
     533msgstr ""
     534
     535#: includes/services/class-slack.php:82
    324536msgid "The webhook that you created for your Slack channel."
    325537msgstr ""
    326538
    327 #: includes/services/class-slack.php:57
     539#: includes/services/class-slack.php:93
    328540msgid "Slack Icon"
    329541msgstr ""
    330542
    331 #: includes/services/class-slack.php:58
     543#: includes/services/class-slack.php:94
    332544msgid "Override the default icon of the webhook. Not required."
    333545msgstr ""
    334546
    335 #: includes/services/class-slack.php:70
     547#: includes/services/class-slack.php:106
    336548msgid "Slack Username"
    337549msgstr ""
    338550
    339 #: includes/services/class-slack.php:83
     551#: includes/services/class-slack.php:119
    340552msgid "Color"
    341553msgstr ""
    342554
    343 #: includes/services/class-slack.php:84
     555#: includes/services/class-slack.php:120
    344556msgid "Select a color to use for the message attachment."
    345557msgstr ""
    346558
    347 #: includes/services/class-slack.php:230
     559#: includes/services/class-slack.php:233
    348560msgid "Attached image"
    349561msgstr ""
  • hey-notify/trunk/readme.txt

    r2345565 r2349284  
    55Tested up to: 5.4
    66Requires PHP: 5.3
    7 Stable tag: 1.0.0
     7Stable tag: 1.1.0
    88License: GPLv2 or later
    99License URI: http://ww.gnu.org/licenses/gpl-2.0.html
     
    2323= Notifications for: =
    2424
    25 * Posts
    26 * Pages
    27 * Comments (coming soon)
    28 * Users (coming soon)
    29 * System Events (coming soon)
     25* Posts - Status transitions
     26* Pages - Status transitions
     27* Comments - New comments
     28* Users - New users, admin logins, failed admin logins
     29* System Events - WordPrewss, plugin, and theme updates
    3030
    3131== Installation ==
     
    4141== Changelog ==
    4242
     43= 1.1.0 =
     44* Added comment notifications.
     45* Added user notifications.
     46* Added system notifications.
     47
    4348= 1.0.0 =
    4449* Initial release.
  • hey-notify/trunk/uninstall.php

    r2345565 r2349284  
    1313}
    1414
    15 $remove_data = \get_option( '_hey_notify_remove_data' );
     15if ( \is_multisite() ) {
     16    $sites = \get_sites(
     17        array(
     18            'number' => 99999,
     19            'fields' => 'ids',
     20        )
     21    );
     22    if ( $sites ) {
     23        foreach ( $sites as $site ) {
     24            \switch_to_blog( $site->blog_id );
     25            $remove_data = \get_option( '_hey_notify_remove_data' );
     26            if ( 'yes' === $remove_data ) {
     27                delete_options();
     28                delete_posts();
     29            }
     30            \restore_current_blog();
     31        }
     32    }
     33} else {
     34    $remove_data = \get_option( '_hey_notify_remove_data' );
     35    if ( 'yes' === $remove_data ) {
     36        delete_options();
     37        delete_posts();
     38    }
     39}
    1640
    17 if ( 'yes' === $remove_data ) {
     41/**
     42 * Delete options
     43 *
     44 * @return void
     45 */
     46function delete_options() {
    1847    \delete_option( '_hey_notify_remove_data' );
    1948    \delete_option( '_hey_notify_default_service' );
     49    \delete_option( 'hey_notify_wordpress_version' );
     50    \delete_option( 'hey_notify_theme_versions' );
     51    \delete_option( 'hey_notify_plugin_versions' );
     52}
    2053
     54/**
     55 * Delete posts
     56 *
     57 * @return void
     58 */
     59function delete_posts() {
    2160    $all_posts = \get_posts(
    2261        array(
Note: See TracChangeset for help on using the changeset viewer.