Plugin Directory

Changeset 1633724


Ignore:
Timestamp:
04/09/2017 06:32:17 PM (9 years ago)
Author:
akeda
Message:

Updates trunk for 0.6.0

Location:
slack/trunk
Files:
3 added
12 edited

Legend:

Unmodified
Added
Removed
  • slack/trunk/includes/autoloader.php

    r891716 r1633724  
    11<?php
     2/**
     3 * Autoloader for the plugin.
     4 *
     5 * @package WP_Slack
     6 * @subpackage Autoloader
     7 */
     8
     9if ( ! defined( 'ABSPATH' ) ) {
     10    exit;
     11}
     12
    213/**
    314 * Class loader using SPL autoloader.
     
    2132    /**
    2233     * Registers Autoloader as an SPL autoloader.
     34     *
     35     * @param string $class_prefix Prefix on class name to be autoloaded.
     36     * @param string $base_path    Path to load the classes.
    2337     */
    2438    public static function register( $class_prefix, $base_path ) {
     
    3246     * Handles autoloading of classes.
    3347     *
    34      * @param string $classname Class name
     48     * @param string $classname Class name.
    3549     */
    3650    public static function autoload( $classname ) {
  • slack/trunk/includes/event-manager.php

    r1567551 r1633724  
    11<?php
    2 
     2/**
     3 * Event manager.
     4 *
     5 * @package WP_Slack
     6 * @subpackage Event
     7 */
     8
     9if ( ! defined( 'ABSPATH' ) ) {
     10    exit;
     11}
     12
     13/**
     14 * Dispatch registered events.
     15 *
     16 * Event registered in WP_Slack is an array with following structure:
     17 *
     18 * {
     19 *
     20 *     @type string   $action      WordPress hook.
     21 *     @type string   $description Description for the event. Appears in integration
     22 *                                 setting.
     23 *     @type bool     $default     Default value for integration setting. True
     24 *                                 means it's checked by default.
     25 *     @type function $message     The callback for $action. This function must
     26 *                                 returns a string to notify to Slack.
     27 *
     28 * }
     29 */
    330class WP_Slack_Event_Manager {
    431
    532    /**
     33     * Plugin's instance.
     34     *
    635     * @var WP_Slack_Plugin
    736     */
    837    private $plugin;
    938
     39    /**
     40     * Constructor.
     41     *
     42     * @param WP_Slack_Plugin $plugin Plugin's instance.
     43     */
    1044    public function __construct( WP_Slack_Plugin $plugin ) {
    1145        $this->plugin = $plugin;
     
    1448    }
    1549
     50    /**
     51     * Dispatch events.
     52     */
    1653    private function dispatch_events() {
    1754
     
    4279            }
    4380
    44             // For each checked event calls the callback, that's,
    45             // hooking into event's action-name to let notifier
    46             // deliver notification based on current integration
    47             // setting.
     81            // For each checked event calls the callback, that's, hooking into
     82            // event's action-name to let notifier deliver notification based on
     83            // current integration setting.
    4884            foreach ( $setting['events'] as $event => $is_enabled ) {
    4985                if ( ! empty( $events[ $event ] ) && $is_enabled ) {
     
    5187                }
    5288            }
    53 
    5489        }
    5590    }
    5691
    5792    /**
    58      * Get list of events. There's filter `slack_get_events`
    59      * to extend available events that can be notified to
    60      * Slack.
     93     * Get list of events. There's filter `slack_get_events` to extend available
     94     * events that can be notified to Slack.
     95     *
     96     * @return array List of events
    6197     */
    6298    public function get_events() {
     
    82118
    83119                        return sprintf(
    84                             'New post published: *<%1$s|%2$s>* by *%3$s*' . "\n" .
     120                            /* translators: 1) URL, 2) post title, and 3) post author. */
     121                            __( 'New post published: *<%1$s|%2$s>* by *%3$s*', 'slack' ) . "\n" .
    85122                            '> %4$s',
    86 
    87123                            get_permalink( $post->ID ),
    88124                            html_entity_decode( get_the_title( $post->ID ), ENT_QUOTES, get_bloginfo( 'charset' ) ),
     
    114150
    115151                        return sprintf(
    116                             'New post needs review: *<%1$s|%2$s>* by *%3$s*' . "\n" .
     152                            /* translators: 1) URL, 2) post title and 3) post author. */
     153                            __( 'New post needs review: *<%1$s|%2$s>* by *%3$s*', 'slack' ) . "\n" .
    117154                            '> %4$s',
    118 
    119155                            admin_url( sprintf( 'post.php?post=%d&action=edit', $post->ID ) ),
    120156                            html_entity_decode( get_the_title( $post->ID ), ENT_QUOTES, get_bloginfo( 'charset' ) ),
     
    152188
    153189                    return sprintf(
    154                         '<%1$s|New comment> by *%2$s* on *<%3$s|%4$s>* (_%5$s_)' . "\n" .
     190                        /* translators: 1) edit URL, 2) comment author, 3) post URL, 4) post title, and 5) comment status. */
     191                        __( '<%1$s|New comment> by *%2$s* on *<%3$s|%4$s>* (_%5$s_)', 'slack' ) . "\n" .
    155192                        '>%6$s',
    156 
    157193                        admin_url( "comment.php?c=$comment_id&action=editcomment" ),
    158194                        $comment->comment_author,
     
    167203    }
    168204
     205    /**
     206     * Notify Slack from invoked action callback.
     207     *
     208     * @param array $event   Event.
     209     * @param array $setting Integration setting.
     210     */
    169211    public function notifiy_via_action( array $event, array $setting ) {
    170         $notifier = $this->plugin->notifier;
    171 
    172212        $priority = 10;
    173213        if ( ! empty( $event['priority'] ) ) {
     
    175215        }
    176216
    177         $callback = function() use( $event, $setting, $notifier ) {
    178             $message = '';
     217        $callback = $this->get_event_callback( $event, $setting );
     218
     219        add_action( $event['action'], $callback, $priority, 5 );
     220    }
     221
     222    /**
     223     * Get event callback for a given event and setting.
     224     *
     225     * @since 0.6.0
     226     *
     227     * @param array $event   Event.
     228     * @param array $setting Integration setting.
     229     *
     230     * @return function Callback for a given event and setting
     231     */
     232    public function get_event_callback( array $event, array $setting ) {
     233        $notifier = $this->plugin->notifier;
     234
     235        return function() use ( $event, $setting, $notifier ) {
     236            $callback_args = array();
     237            $message       = '';
     238
    179239            if ( is_string( $event['message'] ) ) {
    180240                $message = $event['message'];
    181             } else if ( is_callable( $event['message'] ) ) {
    182                 $message = call_user_func_array( $event['message'], func_get_args() );
     241            } elseif ( is_callable( $event['message'] ) ) {
     242                $callback_args = func_get_args();
     243                $message       = call_user_func_array( $event['message'], $callback_args );
    183244            }
    184245
     
    191252                );
    192253
    193                 $notifier->notify( new WP_Slack_Event_Payload( $setting ) );
     254                $resp = $notifier->notify( new WP_Slack_Event_Payload( $setting ) );
     255
     256                /**
     257                 * Fires after notify an event to Slack.
     258                 *
     259                 * @since 0.6.0
     260                 *
     261                 * @param array|WP_Error $resp          Results from wp_remote_post.
     262                 * @param array          $event         Event.
     263                 * @param array          $setting       Integration setting.
     264                 * @param array          $callback_args Callback arguments.
     265                 */
     266                do_action( 'slack_after_notify', $resp, $event, $setting, $callback_args );
    194267            }
    195268        };
    196         add_action( $event['action'], $callback, $priority, 5 );
    197269    }
    198270}
  • slack/trunk/includes/event-payload.php

    r1567551 r1633724  
    11<?php
     2/**
     3 * Event Payload.
     4 *
     5 * @package WP_Slack
     6 * @subpackage Event
     7 */
    28
     9/**
     10 * Event payload representation.
     11 */
    312class WP_Slack_Event_Payload {
    413
    514    /**
     15     * Setting.
     16     *
    617     * @var array
    718     */
    819    private $setting;
    920
     21    /**
     22     * Constructor.
     23     *
     24     * @param array $setting Setting values.
     25     */
    1026    public function __construct( array $setting ) {
    1127        $this->setting = $setting;
    1228    }
    1329
     30    /**
     31     * Get service URL.
     32     *
     33     * @return string Service URL
     34     */
    1435    public function get_url() {
    1536        return $this->setting['service_url'];
    1637    }
    1738
    18     public function toJSON() {
     39    /**
     40     * Get JSON string for the setting.
     41     *
     42     * @return string JSON string
     43     */
     44    public function get_json_string() {
    1945        return json_encode( array(
    2046            'channel'      => $this->setting['channel'],
     
    2450        ) );
    2551    }
     52
     53    /**
     54     * Get JSON string for the setting.
     55     *
     56     * @deprecated 0.6.0 Use get_json_string()
     57     * @see WP_Slack_Event_Payload::get_json_string()
     58     *
     59     * @return string JSON string
     60     * @codingStandardsIgnoreStart
     61     */
     62    public function toJSON() {
     63        // @codingStandardsIgnoreEnd
     64        _deprecated_function( __METHOD__, '0.6.0', 'WP_Slack_Event_Payload::get_json_string()' );
     65        return $this->get_json_string();
     66    }
    2667}
  • slack/trunk/includes/notifier.php

    r912677 r1633724  
    11<?php
     2/**
     3 * Slack Notifier.
     4 *
     5 * @package WP_Slack
     6 * @subpackage Notifier
     7 */
    28
     9if ( ! defined( 'ABSPATH' ) ) {
     10    exit;
     11}
     12
     13/**
     14 * Notify Slack via Incoming Webhook API.
     15 *
     16 * @see https://api.slack.com/incoming-webhooks
     17 */
    318class WP_Slack_Notifier {
    419
    520    /**
     21     * Plugin's instance.
     22     *
    623     * @var WP_Slack_Plugin
    724     */
    825    private $plugin;
    926
     27    /**
     28     * Constructor.
     29     *
     30     * @param WP_Slack_Plugin $plugin Plugin instance.
     31     */
    1032    public function __construct( WP_Slack_Plugin $plugin ) {
    1133        $this->plugin = $plugin;
     
    1537     * Notify Slack with given payload.
    1638     *
    17      * @var WP_Slack_Event_Payload $payload
     39     * @param WP_Slack_Event_Payload $payload Payload to send via POST.
    1840     *
    1941     * @return mixed True if success, otherwise WP_Error
    2042     */
    2143    public function notify( WP_Slack_Event_Payload $payload ) {
    22         $payload_json = $payload->toJSON();
     44        $payload_json = $payload->get_json_string();
    2345
    2446        $resp = wp_remote_post( $payload->get_url(), array(
    2547            'user-agent' => $this->plugin->name . '/' . $this->plugin->version,
    2648            'body'       => $payload_json,
    27             'headers'=> array(
     49            'headers' => array(
    2850                'Content-Type' => 'application/json',
    2951            ),
  • slack/trunk/includes/plugin.php

    r1028900 r1633724  
    11<?php
     2/**
     3 * Main Plugin Class.
     4 *
     5 * @package WP_Slack
     6 */
     7
    28/**
    39 * This is the plugin class and acts as container for component instances and
     
    915
    1016    /**
     17     * Items for setter and getter.
     18     *
    1119     * @var array
    1220     */
     
    1422
    1523    /**
    16      * @param string $path Path to main plugin file
     24     * Run the plugin.
     25     *
     26     * @param string $path Path to main plugin file.
    1727     */
    1828    public function run( $path ) {
    19         // Basic plugin information.
    20         $this->name    = 'wp_slack'; // This maybe used to prefix options, slug of menu or page, and filters/actions.
    21         $this->version = '0.5.1';
     29        // This maybe used to prefix options, slug of menu or page, and
     30        // filters/actions.
     31        $this->name    = 'wp_slack';
     32
     33        $this->version = '0.6.0';
    2234
    2335        // Path.
     
    3446    }
    3547
     48    /**
     49     * Store item's value with a given key.
     50     *
     51     * @param string $key   Item's key.
     52     * @param mixed  $value Item's value.
     53     */
    3654    public function __set( $key, $value ) {
    3755        $this->items[ $key ] = $value;
    3856    }
    3957
     58    /**
     59     * Retrieve item with given key.
     60     *
     61     * @param string $key Item's key.
     62     *
     63     * @return mixed Item's value
     64     */
    4065    public function __get( $key ) {
    4166        if ( isset( $this->items[ $key ] ) ) {
     
    4671    }
    4772
     73    /**
     74     * Checks whether an item with given key exists.
     75     *
     76     * @param string $key Item's key.
     77     *
     78     * @return bool Returns true if item with given key exists.
     79     */
    4880    public function __isset( $key ) {
    4981        return isset( $this->items[ $key ] );
    5082    }
    5183
     84    /**
     85     * Unset item with given key.
     86     *
     87     * @param string $key Item's key.
     88     */
    5289    public function __unset( $key ) {
    5390        if ( isset( $this->items[ $key ] ) ) {
  • slack/trunk/includes/post-meta-box.php

    r945146 r1633724  
    11<?php
    2 
     2/**
     3 * Integration Setting Meta Box.
     4 *
     5 * @package WP_Slack
     6 * @subpackage Integration
     7 */
     8
     9/**
     10 * Handles Integration Setting Meta Box in Edit Slack Integration screen.
     11 */
    312class WP_Slack_Post_Meta_Box {
    413
    514    /**
     15     * Plugin's instance.
     16     *
    617     * @var WP_Slack_Plugin
    718     */
    819    private $plugin;
    920
     21    /**
     22     * Plugin's instance.
     23     *
     24     * @param WP_Slack_Plugin $plugin Plugin instance.
     25     */
    1026    public function __construct( WP_Slack_Plugin $plugin ) {
    1127        $this->plugin = $plugin;
     
    1935    }
    2036
     37    /**
     38     * Add the meta box.
     39     */
    2140    public function add_meta_box() {
    2241        add_meta_box(
    23             // ID.
    24             'slack_setting_metabox',
    25 
    26             // Title.
    27             __( 'Integration Setting', 'slack' ),
    28 
    29             // Callback.
    30             array( $this, 'render_meta_box' ),
    31 
    32             // Screen.
    33             $this->plugin->post_type->name,
    34 
    35             // Context.
    36             'advanced',
    37 
    38             // Priority.
    39             'high'
     42            'slack_setting_metabox',              // ID.
     43            __( 'Integration Setting', 'slack' ), // Title.
     44            array( $this, 'render_meta_box' ),    // Renderer callback.
     45            $this->plugin->post_type->name,       // Screen to render
     46            'advanced',                           // Context
     47            'high'                                // Priority.
    4048        );
    4149    }
     
    4452     * Display the meta box.
    4553     *
    46      * @param object $post
     54     * @param WP_Post $post Post object.
    4755     */
    4856    public function render_meta_box( $post ) {
    4957        wp_nonce_field(
    50             // Action
    51             $this->plugin->post_type->name,
    52 
    53             // Name.
    54             $this->plugin->post_type->name . '_nonce'
     58            $this->plugin->post_type->name,            // Action.
     59            $this->plugin->post_type->name . '_nonce'  // Name.
    5560        );
    5661
     
    7075     */
    7176    public function save_post( $post_id ) {
    72         if ( $this->plugin->post_type->name !== get_post_type( $post_id ) ) {
     77        if ( get_post_type( $post_id ) !== $this->plugin->post_type->name ) {
    7378            return;
    7479        }
     
    109114                }
    110115            },
    111             'events' => function( $val ) use( $events ) {
     116            'events' => function( $val ) use ( $events ) {
    112117                $saved = array_fill_keys( $events , 0 );
    113118
     
    119124
    120125                return $saved;
    121             }
     126            },
    122127        );
    123128
     
    138143    }
    139144
     145    /**
     146     * AJAX handler for test notify in edit Slack integration screen.
     147     */
    140148    public function ajax_test_notify() {
    141149        try {
     
    148156            foreach ( $expected_params as $param ) {
    149157                if ( ! isset( $_REQUEST[ $param ] ) ) {
     158                    /* translators: placeholder is request parameter for test notify AJAX. */
    150159                    throw new Exception( sprintf( __( 'Missing param %s', 'slack' ), $param ) );
    151160                }
  • slack/trunk/includes/post-type.php

    r907491 r1633724  
    11<?php
     2/**
     3 * Custom Post Type for WP_Slack.
     4 *
     5 * @package WP_Slack
     6 * @subpackage Integration
     7 */
     8
    29/**
    310 * Custom post type where each post stores Slack integration settings.
     
    1320
    1421    /**
     22     * Plugin's instance.
     23     *
    1524     * @var WP_Slack_Plugin
    1625     */
    1726    private $plugin;
    1827
     28    /**
     29     * Constructor.
     30     *
     31     * @param WP_Slack_Plugin $plugin Plugin's instance.
     32     */
    1933    public function __construct( WP_Slack_Plugin $plugin ) {
    2034        $this->plugin = $plugin;
     
    4862        add_action( 'all_admin_notices', array( $this, 'admin_notices' ) );
    4963
    50         // Custom columns
     64        // Custom columns.
    5165        add_filter( sprintf( 'manage_%s_posts_columns', $this->name ), array( $this, 'columns_header' ) );
    5266        add_action( sprintf( 'manage_%s_posts_custom_column', $this->name ), array( $this, 'custom_column_row' ), 10, 2 );
     
    6276    }
    6377
     78    /**
     79     * Register the custom post type.
     80     */
    6481    public function register_post_type() {
    6582        $args = array(
     
    7491            'show_in_menu'        => true,
    7592
    76             'menu_position'       => 75, // Below tools
     93            'menu_position'       => 75, // Below tools.
    7794            'menu_icon'           => $this->plugin->plugin_url . 'img/logo.png',
    7895            'can_export'          => true,
     
    85102            'capabilities' => array(
    86103
    87                 // meta caps (don't assign these to roles)
     104                // Meta caps (don't assign these to roles).
    88105                'edit_post'              => 'manage_options',
    89106                'read_post'              => 'manage_options',
    90107                'delete_post'            => 'manage_options',
    91108
    92                 // primitive/meta caps
     109                // Primitive/meta caps.
    93110                'create_posts'           => 'manage_options',
    94111
    95                 // primitive caps used outside of map_meta_cap()
     112                // Primitive caps used outside of map_meta_cap().
    96113                'edit_posts'             => 'manage_options',
    97114                'edit_others_posts'      => 'manage_options',
     
    99116                'read_private_posts'     => 'manage_options',
    100117
    101                 // primitive caps used inside of map_meta_cap()
     118                // Primitive caps used inside of map_meta_cap().
    102119                'read'                   => 'manage_options',
    103120                'delete_posts'           => 'manage_options',
     
    138155    }
    139156
     157    /**
     158     * Remove default submit meta box.
     159     */
    140160    public function remove_submitdiv() {
    141161        remove_meta_box( 'submitdiv', $this->name, 'side' );
    142162    }
    143163
     164    /**
     165     * Enqueue scripts for Slack Integration screens.
     166     */
    144167    public function enqueue_scripts() {
    145         if ( $this->name === get_post_type() ) {
     168        if ( get_post_type() === $this->name ) {
    146169            wp_dequeue_script( 'autosave' );
    147170
    148171            wp_enqueue_style(
    149                 // Handle.
    150                 'slack-admin',
    151 
    152                 // Src.
    153                 $this->plugin->plugin_url . 'css/admin.css',
    154 
    155                 // Deps
    156                 array(),
    157 
    158                 // Version.
    159                 filemtime( $this->plugin->plugin_path . 'css/admin.css' ),
    160 
    161                 // Media.
    162                 'all'
     172                'slack-admin',                                             // Handle.
     173                $this->plugin->plugin_url . 'css/admin.css',               // Src.
     174                array(),                                                   // Deps
     175                filemtime( $this->plugin->plugin_path . 'css/admin.css' ), // Version.
     176                'all'                                                      // Media.
    163177            );
    164178
    165179            wp_enqueue_script(
    166                 // Handle.
    167                 'slack-admin-js',
    168 
    169                 // Src.
    170                 $this->plugin->plugin_url . 'js/admin.js',
    171 
    172                 // Deps
    173                 array( 'jquery' ),
    174 
    175                 // Ver.
    176                 filemtime( $this->plugin->plugin_path . 'js/admin.js' )
     180                'slack-admin-js',                                       // Handle.
     181                $this->plugin->plugin_url . 'js/admin.js',              // Src.
     182                array( 'jquery' ),                                      // Deps.
     183                filemtime( $this->plugin->plugin_path . 'js/admin.js' ) // Ver.
    177184            );
    178185        }
    179186    }
    180187
     188    /**
     189     * Filter message notice when integration setting is updated.
     190     *
     191     * @param array $messages List of messages when post is updated.
     192     *
     193     * @return array Updated messages
     194     */
    181195    public function post_updated_messages( $messages ) {
    182196        $messages[ $this->plugin->post_type->name ] = array_fill( 0, 11,  __( 'Setting updated.', 'slack' ) );
     
    186200
    187201    /**
    188      * @param array $bulk_messages Arrays of messages, each keyed by the corresponding post type. Messages are
    189      *                             keyed with 'updated', 'locked', 'deleted', 'trashed', and 'untrashed'.
    190      * @param array $bulk_counts   Array of item counts for each message, used to build internationalized strings.
     202     * Filter message notice when integration settings were bulk-updated.
     203     *
     204     * @param array $bulk_messages Arrays of messages, each keyed by the
     205     *                             corresponding post type. Messages are keyed with
     206     *                             'updated', 'locked', 'deleted', 'trashed', and
     207     *                             'untrashed'.
     208     * @param array $bulk_counts   Array of item counts for each message, used to
     209     *                             build internationalized strings.
     210     *
     211     * @return array Updated bulk messages
    191212     */
    192213    public function bulk_post_updated_messages( $bulk_messages, $bulk_counts ) {
     
    195216        if ( $this->name === $screen->post_type ) {
    196217            $bulk_messages['post'] = array(
    197                 'updated'   => _n( '%s integration updated.', '%s integrations updated.', $bulk_counts['updated'] ),
    198                 'locked'    => _n( '%s integration not updated, somebody is editing it.', '%s integrations not updated, somebody is editing them.', $bulk_counts['locked'] ),
    199                 'deleted'   => _n( '%s integration permanently deleted.', '%s integrations permanently deleted.', $bulk_counts['deleted'] ),
    200                 'trashed'   => _n( '%s integration moved to the Trash.', '%s integrations moved to the Trash.', $bulk_counts['trashed'] ),
    201                 'untrashed' => _n( '%s integration restored from the Trash.', '%s integrations restored from the Trash.', $bulk_counts['untrashed'] ),
     218                /* translators: placeholder is number of updated integrations. */
     219                'updated'   => _n( '%s integration updated.', '%s integrations updated.', $bulk_counts['updated'], 'slack' ),
     220                /* translators: placeholder is number of updated integrations. */
     221                'locked'    => _n( '%s integration not updated, somebody is editing it.', '%s integrations not updated, somebody is editing them.', $bulk_counts['locked'], 'slack' ),
     222                /* translators: placeholder is number of deleted integrations. */
     223                'deleted'   => _n( '%s integration permanently deleted.', '%s integrations permanently deleted.', $bulk_counts['deleted'], 'slack' ),
     224                /* translators: placeholder is number of trashed integrations. */
     225                'trashed'   => _n( '%s integration moved to the Trash.', '%s integrations moved to the Trash.', $bulk_counts['trashed'], 'slack' ),
     226                /* translators: placeholder is number of restored integrations. */
     227                'untrashed' => _n( '%s integration restored from the Trash.', '%s integrations restored from the Trash.', $bulk_counts['untrashed'], 'slack' ),
    202228            );
    203229        }
     
    209235     * Custom bulk actions.
    210236     *
    211      * @param  array $actions
    212      * @return array
     237     * @param  array $actions List of actions.
     238     * @return array List of actions
    213239     *
    214240     * @filter bulk_actions-edit-slack_integration
     
    217243        unset( $actions['edit'] );
    218244
     245        // @codingStandardsIgnoreStart
    219246        // Unfortunately adding bulk actions won't work here.
    220247        // @see https://core.trac.wordpress.org/ticket/16031
     
    222249        // $actions['activate']   = __( 'Activate', 'slack' );
    223250        // $actions['deactivate'] = __( 'Deactivate', 'slack' );
     251        // @codingStandardsIgnoreEnd
    224252
    225253        return $actions;
     
    229257     * Custom row actions for this post type.
    230258     *
    231      * @param  array $actions
    232      * @return array
     259     * @param  array $actions List of actions.
     260     *
     261     * @return array List of actions
    233262     *
    234263     * @filter post_row_actions
     
    237266        $post = get_post();
    238267
    239         if ( $this->plugin->post_type->name === get_post_type( $post ) ) {
     268        if ( get_post_type( $post ) === $this->plugin->post_type->name ) {
    240269            unset( $actions['inline hide-if-no-js'] );
    241270            unset( $actions['view'] );
     
    245274
    246275            if ( $setting['active'] ) {
    247                 $actions['deactivate'] = "<a title='" . esc_attr( __( 'Deactivate this integration setting' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=deactivate', $post->ID ) ), 'deactivate-post_' . $post->ID ) . "'>" . __( 'Deactivate' ) . "</a>";
     276                $actions['deactivate'] = sprintf(
     277                    '<a title="%1$s" href="%2$s">%3$s</a>',
     278                    esc_attr__( 'Deactivate this integration setting', 'slack' ),
     279                    wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=deactivate', $post->ID ) ), 'deactivate-post_' . $post->ID ),
     280                    esc_html__( 'Deactivate', 'slack' )
     281                );
    248282            } else {
    249                 $actions['activate'] = "<a title='" . esc_attr( __( 'Activate this integration setting' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=activate', $post->ID ) ), 'activate-post_' . $post->ID ) . "'>" . __( 'Activate' ) . "</a>";
     283                $actions['activate'] = sprintf(
     284                    '<a title="%1$s" href="%2$s">%3$s</a>',
     285                    esc_attr__( 'Activate this integration setting', 'slack' ),
     286                    wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=activate', $post->ID ) ), 'activate-post_' . $post->ID ),
     287                    esc_html__( 'Activate', 'slack' )
     288                );
    250289            }
    251290        }
     
    275314     * Action handler for activating/deactivating integration setting(s).
    276315     *
    277      * @param bool $activate
     316     * @param bool $activate Flag to indicated whether this is activattion action.
    278317     */
    279318    private function _set_active_setting( $activate = true ) {
     
    286325        if ( ! $post ) {
    287326            wp_die(
     327                /* translators: placeholder is action type, either 'activate' or 'deactivate'. */
    288328                sprintf( __( 'The integration you are trying to %s is no longer exists.', 'slack' ), $activate ? 'activate' : 'deactivate' )
    289329            );
     
    300340        $key_arg = $activate ? 'activated' : 'deactivated';
    301341
    302         wp_redirect( add_query_arg( array( "$key_arg" => 1, 'ids' => $post->ID ), $sendback ) );
     342        wp_redirect( add_query_arg(
     343            array(
     344                "$key_arg" => 1,
     345                'ids'      => $post->ID,
     346            ),
     347            $sendback
     348        ) );
     349
    303350        exit;
    304351    }
    305352
    306353    /**
     354     * Display notice when integration is activated or deactivated.
    307355     *
    308356     * @action all_admin_notices
     
    310358    public function admin_notices() {
    311359        $screen = get_current_screen();
    312         if ( $screen->id !== 'edit-' . $this->name ) {
     360        if ( 'edit-' . $this->name !== $screen->id ) {
    313361            return;
    314362        }
     
    320368
    321369        $bulk_messages = array(
    322             'activated'   => _n( '%s integration activated.',   '%s integrations activated.',   $bulk_counts['activated'] ),
    323             'deactivated' => _n( '%s integration deactivated.', '%s integrations deactivated.', $bulk_counts['deactivated'] ),
     370            /* translators: number of activated integrations. */
     371            'activated'   => _n( '%s integration activated.', '%s integrations activated.', $bulk_counts['activated'], 'slack' ),
     372            /* translators: number of deactivated integrations. */
     373            'deactivated' => _n( '%s integration deactivated.', '%s integrations deactivated.', $bulk_counts['deactivated'], 'slack' ),
    324374        );
    325375
    326376        $bulk_counts = array_filter( $bulk_counts );
    327377
    328         // If we have a bulk message to issue:
     378        // If we have a bulk message to display.
    329379        $messages = array();
    330380        foreach ( $bulk_counts as $message => $count ) {
     
    342392     * Custom columns for this post type.
    343393     *
    344      * @param  array $columns
    345      * @return array
     394     * @param  array $columns Post list columns.
     395     * @return array Post list columns
    346396     *
    347397     * @filter manage_{post_type}_posts_columns
     
    361411     * Custom column appears in each row.
    362412     *
    363      * @param string $column  Column name
    364      * @param int    $post_id Post ID
     413     * @param string $column  Column name.
     414     * @param int    $post_id Post ID.
    365415     *
    366416     * @action manage_{post_type}_posts_custom_column
     
    398448     *
    399449     * @param array  $classes An array of post classes.
    400      * @param string $class   A comma-separated list of additional classes added to the post.
     450     * @param string $class   A comma-separated list of additional classes added
     451     *                        to the post.
    401452     * @param int    $post_id The post ID.
     453     *
     454     * @return array Array of post classes
    402455     *
    403456     * @filter post_class
     
    427480     * Hides subsubsub top nav.
    428481     *
    429      * @return array
     482     * @return array Top nav links
    430483     */
    431484    public function hide_subsubsub() {
     
    433486    }
    434487
     488    /**
     489     * Change title placeholder for Slack Integration post.
     490     *
     491     * @param string $title Title placeholder.
     492     *
     493     * @return string Updated title placeholder
     494     */
    435495    public function title_placeholder( $title ) {
    436496        $screen = get_current_screen();
  • slack/trunk/includes/submit-meta-box.php

    r891716 r1633724  
    11<?php
    22/**
    3  * Replacement for builtin submitdiv meta box
    4  * for our custom post type.
     3 * Submit Meta Box.
     4 *
     5 * @package WP_Slack
     6 * @subpackage Integration
     7 */
     8
     9/**
     10 * Replacement for builtin submitdiv meta box for Slack integration CPT.
    511 */
    612class WP_Slack_Submit_Meta_Box {
    713
    814    /**
     15     * Plugin's instance.
     16     *
    917     * @var WP_Slack_Plugin
    1018     */
    1119    private $plugin;
    1220
     21    /**
     22     * Constructor.
     23     *
     24     * @param WP_Slack_Plugin $plugin Plugin's instance.
     25     */
    1326    public function __construct( WP_Slack_Plugin $plugin ) {
    1427        $this->plugin = $plugin;
     
    2033     * Register submit meta box.
    2134     *
    22      * @param
     35     * @param string $post_type Post type.
    2336     */
    2437    public function register_meta_box( $post_type ) {
     
    3144     * Display post submit form fields.
    3245     *
    33      * @param object $post
     46     * @param WP_Post $post Post object.
    3447     */
    3548    public function slack_submitdiv( $post ) {
  • slack/trunk/readme.txt

    r1567551 r1633724  
    33Donate link:       http://goo.gl/DELyuR
    44Tags:              slack, api, chat, notification
    5 Requires at least: 3.6
    6 Tested up to:      4.7
    7 Stable tag:        0.5.1
     5Requires at least: 4.3
     6Tested up to:      4.7.3
     7Stable tag:        0.6.0
    88License:           GPLv2 or later
    99License URI:       http://www.gnu.org/licenses/gpl-2.0.html
     
    4949== Changelog ==
    5050
     51= 0.6.0 =
     52* Fix spinner is not showing when sending test notification.
     53* Convert HTML entities in Slack notifications.
     54* Bump tested up to 4.7.3.
     55* For developers, unit tests and end-to-end tests were added.
     56
    5157= 0.5.1 =
    5258* Removed bin directory for published plugin in WP.org. Props otto42
  • slack/trunk/slack.php

    r1028900 r1633724  
    11<?php
     2/**
     3 * Main plugin's file.
     4 *
     5 * @package WP_Slack
     6 */
     7
    28/**
    39 * Plugin Name: Slack
    410 * Plugin URI: http://gedex.web.id/wp-slack/
    511 * Description: This plugin allows you to send notifications to Slack channels when certain events in WordPress occur.
    6  * Version: 0.5.1
     12 * Version: 0.6.0
    713 * Author: Akeda Bagus
    814 * Author URI: http://gedex.web.id
     
    1016 * Domain Path: /languages
    1117 * License: GPL v2 or later
    12  * Requires at least: 3.6
    13  * Tested up to: 3.9
     18 * Requires at least: 4.3
     19 * Tested up to: 4.7.3
    1420 *
    1521 * This program is free software; you can redistribute it and/or modify
     
    2935WP_Slack_Autoloader::register( 'WP_Slack', trailingslashit( plugin_dir_path( __FILE__ ) ) . '/includes/' );
    3036
    31 // Runs this plugin.
    32 $GLOBALS['wp_slack'] = new WP_Slack_Plugin();
    33 $GLOBALS['wp_slack']->run( __FILE__ );
     37// Runs this plugin after all plugins are loaded.
     38add_action( 'plugins_loaded', function() {
     39    $GLOBALS['wp_slack'] = new WP_Slack_Plugin();
     40    $GLOBALS['wp_slack']->run( __FILE__ );
     41});
  • slack/trunk/views/post-meta-box.php

    r1567551 r1633724  
     1<?php
     2/**
     3 * View for Integration Setting Meta Box.
     4 *
     5 * @package WP_Slack
     6 * @subpackage View
     7 */
     8
     9?>
    110<table class="form-table">
    211    <tbody>
     
    4453                <input type="text" class="regular-text" name="slack_setting[icon_emoji]" id="slack_setting[icon_emoji]" value="<?php echo ! empty( $setting['icon_emoji'] ) ? esc_attr( $setting['icon_emoji'] ) : ''; ?>">
    4554                <p class="description">
    46                     <?php printf( __( 'Icon (short name) of the bot that delivers the notification. For available icon short name, see <a href="%s" target="blank" title="Emoji Catalog">here</a>. Short name must be wrapped with colon, for instance <code>:rocket:</code>.', 'slack' ), esc_url( 'http://unicodey.com/emoji-data/table.htm' ) ); ?>
     55                    <?php
     56                    /* translators: placeholder is URL */
     57                    printf( __( 'Icon (short name) of the bot that delivers the notification. For available icon short name, see <a href="%s" target="blank" title="Emoji Catalog">here</a>. Short name must be wrapped with colon, for instance <code>:rocket:</code>.', 'slack' ), esc_url( 'http://unicodey.com/emoji-data/table.htm' ) );
     58                    ?>
    4759                </p>
    4860            </td>
     
    7486            </th>
    7587            <td>
    76                 <input type="checkbox" name="slack_setting[active]" id="slack_setting[active]" <?php checked( ! empty( $setting['active'] ) ? $setting['active'] : false ); ?>>
     88                <label>
     89                    <input type="checkbox" name="slack_setting[active]" id="slack_setting[active]" <?php checked( ! empty( $setting['active'] ) ? $setting['active'] : false ); ?>>
     90                    <?php _e( 'Activate Notifications.', 'slack' ); ?>
     91                </label>
    7792                <p class="description">
    7893                    <?php _e( 'Notification will not be sent if not checked.', 'slack' ); ?>
  • slack/trunk/views/submit-meta-box.php

    r891716 r1633724  
     1<?php
     2/**
     3 * View for Save Setting Meta Box in Edit Slack Integration screen.
     4 *
     5 * @package WP_Slack
     6 * @subpackage View
     7 */
     8
     9?>
    110<div class="submitbox" id="submitpost">
    211
    3     <?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key ?>
     12    <?php
     13    /**
     14     * Hidden submit button early on so that the browser chooses the right
     15     * button when form is submitted with Return key.
     16     */
     17    ?>
    418    <div style="display:none;">
    5         <?php submit_button( __( 'Save' ), 'button', 'save' ); ?>
     19        <?php submit_button( __( 'Save', 'slack' ), 'button', 'save' ); ?>
    620    </div>
    721
     
    2539            <span class="spinner"></span>
    2640
    27             <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e( 'Save' ) ?>" />
    28             <input name="save" type="submit" class="button button-primary button-large" id="publish" accesskey="p" value="<?php esc_attr_e('Save' ) ?>" />
     41            <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e( 'Save', 'slack' ) ?>" />
     42            <input name="save" type="submit" class="button button-primary button-large" id="publish" accesskey="p" value="<?php esc_attr_e( 'Save', 'slack' ); ?>" />
    2943        </div>
    3044        <div class="clear"></div>
Note: See TracChangeset for help on using the changeset viewer.