Changeset 1633724
- Timestamp:
- 04/09/2017 06:32:17 PM (9 years ago)
- Location:
- slack/trunk
- Files:
-
- 3 added
- 12 edited
-
assets (added)
-
includes/autoloader.php (modified) (3 diffs)
-
includes/event-manager.php (modified) (10 diffs)
-
includes/event-payload.php (modified) (2 diffs)
-
includes/notifier.php (modified) (2 diffs)
-
includes/plugin.php (modified) (5 diffs)
-
includes/post-meta-box.php (modified) (8 diffs)
-
includes/post-type.php (modified) (26 diffs)
-
includes/submit-meta-box.php (modified) (3 diffs)
-
languages (added)
-
languages/slack.pot (added)
-
readme.txt (modified) (2 diffs)
-
slack.php (modified) (3 diffs)
-
views/post-meta-box.php (modified) (3 diffs)
-
views/submit-meta-box.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
slack/trunk/includes/autoloader.php
r891716 r1633724 1 1 <?php 2 /** 3 * Autoloader for the plugin. 4 * 5 * @package WP_Slack 6 * @subpackage Autoloader 7 */ 8 9 if ( ! defined( 'ABSPATH' ) ) { 10 exit; 11 } 12 2 13 /** 3 14 * Class loader using SPL autoloader. … … 21 32 /** 22 33 * 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. 23 37 */ 24 38 public static function register( $class_prefix, $base_path ) { … … 32 46 * Handles autoloading of classes. 33 47 * 34 * @param string $classname Class name 48 * @param string $classname Class name. 35 49 */ 36 50 public static function autoload( $classname ) { -
slack/trunk/includes/event-manager.php
r1567551 r1633724 1 1 <?php 2 2 /** 3 * Event manager. 4 * 5 * @package WP_Slack 6 * @subpackage Event 7 */ 8 9 if ( ! 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 */ 3 30 class WP_Slack_Event_Manager { 4 31 5 32 /** 33 * Plugin's instance. 34 * 6 35 * @var WP_Slack_Plugin 7 36 */ 8 37 private $plugin; 9 38 39 /** 40 * Constructor. 41 * 42 * @param WP_Slack_Plugin $plugin Plugin's instance. 43 */ 10 44 public function __construct( WP_Slack_Plugin $plugin ) { 11 45 $this->plugin = $plugin; … … 14 48 } 15 49 50 /** 51 * Dispatch events. 52 */ 16 53 private function dispatch_events() { 17 54 … … 42 79 } 43 80 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. 48 84 foreach ( $setting['events'] as $event => $is_enabled ) { 49 85 if ( ! empty( $events[ $event ] ) && $is_enabled ) { … … 51 87 } 52 88 } 53 54 89 } 55 90 } 56 91 57 92 /** 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 61 97 */ 62 98 public function get_events() { … … 82 118 83 119 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" . 85 122 '> %4$s', 86 87 123 get_permalink( $post->ID ), 88 124 html_entity_decode( get_the_title( $post->ID ), ENT_QUOTES, get_bloginfo( 'charset' ) ), … … 114 150 115 151 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" . 117 154 '> %4$s', 118 119 155 admin_url( sprintf( 'post.php?post=%d&action=edit', $post->ID ) ), 120 156 html_entity_decode( get_the_title( $post->ID ), ENT_QUOTES, get_bloginfo( 'charset' ) ), … … 152 188 153 189 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" . 155 192 '>%6$s', 156 157 193 admin_url( "comment.php?c=$comment_id&action=editcomment" ), 158 194 $comment->comment_author, … … 167 203 } 168 204 205 /** 206 * Notify Slack from invoked action callback. 207 * 208 * @param array $event Event. 209 * @param array $setting Integration setting. 210 */ 169 211 public function notifiy_via_action( array $event, array $setting ) { 170 $notifier = $this->plugin->notifier;171 172 212 $priority = 10; 173 213 if ( ! empty( $event['priority'] ) ) { … … 175 215 } 176 216 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 179 239 if ( is_string( $event['message'] ) ) { 180 240 $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 ); 183 244 } 184 245 … … 191 252 ); 192 253 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 ); 194 267 } 195 268 }; 196 add_action( $event['action'], $callback, $priority, 5 );197 269 } 198 270 } -
slack/trunk/includes/event-payload.php
r1567551 r1633724 1 1 <?php 2 /** 3 * Event Payload. 4 * 5 * @package WP_Slack 6 * @subpackage Event 7 */ 2 8 9 /** 10 * Event payload representation. 11 */ 3 12 class WP_Slack_Event_Payload { 4 13 5 14 /** 15 * Setting. 16 * 6 17 * @var array 7 18 */ 8 19 private $setting; 9 20 21 /** 22 * Constructor. 23 * 24 * @param array $setting Setting values. 25 */ 10 26 public function __construct( array $setting ) { 11 27 $this->setting = $setting; 12 28 } 13 29 30 /** 31 * Get service URL. 32 * 33 * @return string Service URL 34 */ 14 35 public function get_url() { 15 36 return $this->setting['service_url']; 16 37 } 17 38 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() { 19 45 return json_encode( array( 20 46 'channel' => $this->setting['channel'], … … 24 50 ) ); 25 51 } 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 } 26 67 } -
slack/trunk/includes/notifier.php
r912677 r1633724 1 1 <?php 2 /** 3 * Slack Notifier. 4 * 5 * @package WP_Slack 6 * @subpackage Notifier 7 */ 2 8 9 if ( ! defined( 'ABSPATH' ) ) { 10 exit; 11 } 12 13 /** 14 * Notify Slack via Incoming Webhook API. 15 * 16 * @see https://api.slack.com/incoming-webhooks 17 */ 3 18 class WP_Slack_Notifier { 4 19 5 20 /** 21 * Plugin's instance. 22 * 6 23 * @var WP_Slack_Plugin 7 24 */ 8 25 private $plugin; 9 26 27 /** 28 * Constructor. 29 * 30 * @param WP_Slack_Plugin $plugin Plugin instance. 31 */ 10 32 public function __construct( WP_Slack_Plugin $plugin ) { 11 33 $this->plugin = $plugin; … … 15 37 * Notify Slack with given payload. 16 38 * 17 * @ var WP_Slack_Event_Payload $payload39 * @param WP_Slack_Event_Payload $payload Payload to send via POST. 18 40 * 19 41 * @return mixed True if success, otherwise WP_Error 20 42 */ 21 43 public function notify( WP_Slack_Event_Payload $payload ) { 22 $payload_json = $payload-> toJSON();44 $payload_json = $payload->get_json_string(); 23 45 24 46 $resp = wp_remote_post( $payload->get_url(), array( 25 47 'user-agent' => $this->plugin->name . '/' . $this->plugin->version, 26 48 'body' => $payload_json, 27 'headers' => array(49 'headers' => array( 28 50 'Content-Type' => 'application/json', 29 51 ), -
slack/trunk/includes/plugin.php
r1028900 r1633724 1 1 <?php 2 /** 3 * Main Plugin Class. 4 * 5 * @package WP_Slack 6 */ 7 2 8 /** 3 9 * This is the plugin class and acts as container for component instances and … … 9 15 10 16 /** 17 * Items for setter and getter. 18 * 11 19 * @var array 12 20 */ … … 14 22 15 23 /** 16 * @param string $path Path to main plugin file 24 * Run the plugin. 25 * 26 * @param string $path Path to main plugin file. 17 27 */ 18 28 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'; 22 34 23 35 // Path. … … 34 46 } 35 47 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 */ 36 54 public function __set( $key, $value ) { 37 55 $this->items[ $key ] = $value; 38 56 } 39 57 58 /** 59 * Retrieve item with given key. 60 * 61 * @param string $key Item's key. 62 * 63 * @return mixed Item's value 64 */ 40 65 public function __get( $key ) { 41 66 if ( isset( $this->items[ $key ] ) ) { … … 46 71 } 47 72 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 */ 48 80 public function __isset( $key ) { 49 81 return isset( $this->items[ $key ] ); 50 82 } 51 83 84 /** 85 * Unset item with given key. 86 * 87 * @param string $key Item's key. 88 */ 52 89 public function __unset( $key ) { 53 90 if ( isset( $this->items[ $key ] ) ) { -
slack/trunk/includes/post-meta-box.php
r945146 r1633724 1 1 <?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 */ 3 12 class WP_Slack_Post_Meta_Box { 4 13 5 14 /** 15 * Plugin's instance. 16 * 6 17 * @var WP_Slack_Plugin 7 18 */ 8 19 private $plugin; 9 20 21 /** 22 * Plugin's instance. 23 * 24 * @param WP_Slack_Plugin $plugin Plugin instance. 25 */ 10 26 public function __construct( WP_Slack_Plugin $plugin ) { 11 27 $this->plugin = $plugin; … … 19 35 } 20 36 37 /** 38 * Add the meta box. 39 */ 21 40 public function add_meta_box() { 22 41 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. 40 48 ); 41 49 } … … 44 52 * Display the meta box. 45 53 * 46 * @param object $post54 * @param WP_Post $post Post object. 47 55 */ 48 56 public function render_meta_box( $post ) { 49 57 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. 55 60 ); 56 61 … … 70 75 */ 71 76 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 ) { 73 78 return; 74 79 } … … 109 114 } 110 115 }, 111 'events' => function( $val ) use ( $events ) {116 'events' => function( $val ) use ( $events ) { 112 117 $saved = array_fill_keys( $events , 0 ); 113 118 … … 119 124 120 125 return $saved; 121 } 126 }, 122 127 ); 123 128 … … 138 143 } 139 144 145 /** 146 * AJAX handler for test notify in edit Slack integration screen. 147 */ 140 148 public function ajax_test_notify() { 141 149 try { … … 148 156 foreach ( $expected_params as $param ) { 149 157 if ( ! isset( $_REQUEST[ $param ] ) ) { 158 /* translators: placeholder is request parameter for test notify AJAX. */ 150 159 throw new Exception( sprintf( __( 'Missing param %s', 'slack' ), $param ) ); 151 160 } -
slack/trunk/includes/post-type.php
r907491 r1633724 1 1 <?php 2 /** 3 * Custom Post Type for WP_Slack. 4 * 5 * @package WP_Slack 6 * @subpackage Integration 7 */ 8 2 9 /** 3 10 * Custom post type where each post stores Slack integration settings. … … 13 20 14 21 /** 22 * Plugin's instance. 23 * 15 24 * @var WP_Slack_Plugin 16 25 */ 17 26 private $plugin; 18 27 28 /** 29 * Constructor. 30 * 31 * @param WP_Slack_Plugin $plugin Plugin's instance. 32 */ 19 33 public function __construct( WP_Slack_Plugin $plugin ) { 20 34 $this->plugin = $plugin; … … 48 62 add_action( 'all_admin_notices', array( $this, 'admin_notices' ) ); 49 63 50 // Custom columns 64 // Custom columns. 51 65 add_filter( sprintf( 'manage_%s_posts_columns', $this->name ), array( $this, 'columns_header' ) ); 52 66 add_action( sprintf( 'manage_%s_posts_custom_column', $this->name ), array( $this, 'custom_column_row' ), 10, 2 ); … … 62 76 } 63 77 78 /** 79 * Register the custom post type. 80 */ 64 81 public function register_post_type() { 65 82 $args = array( … … 74 91 'show_in_menu' => true, 75 92 76 'menu_position' => 75, // Below tools 93 'menu_position' => 75, // Below tools. 77 94 'menu_icon' => $this->plugin->plugin_url . 'img/logo.png', 78 95 'can_export' => true, … … 85 102 'capabilities' => array( 86 103 87 // meta caps (don't assign these to roles)104 // Meta caps (don't assign these to roles). 88 105 'edit_post' => 'manage_options', 89 106 'read_post' => 'manage_options', 90 107 'delete_post' => 'manage_options', 91 108 92 // primitive/meta caps109 // Primitive/meta caps. 93 110 'create_posts' => 'manage_options', 94 111 95 // primitive caps used outside of map_meta_cap()112 // Primitive caps used outside of map_meta_cap(). 96 113 'edit_posts' => 'manage_options', 97 114 'edit_others_posts' => 'manage_options', … … 99 116 'read_private_posts' => 'manage_options', 100 117 101 // primitive caps used inside of map_meta_cap()118 // Primitive caps used inside of map_meta_cap(). 102 119 'read' => 'manage_options', 103 120 'delete_posts' => 'manage_options', … … 138 155 } 139 156 157 /** 158 * Remove default submit meta box. 159 */ 140 160 public function remove_submitdiv() { 141 161 remove_meta_box( 'submitdiv', $this->name, 'side' ); 142 162 } 143 163 164 /** 165 * Enqueue scripts for Slack Integration screens. 166 */ 144 167 public function enqueue_scripts() { 145 if ( $this->name === get_post_type()) {168 if ( get_post_type() === $this->name ) { 146 169 wp_dequeue_script( 'autosave' ); 147 170 148 171 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. 163 177 ); 164 178 165 179 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. 177 184 ); 178 185 } 179 186 } 180 187 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 */ 181 195 public function post_updated_messages( $messages ) { 182 196 $messages[ $this->plugin->post_type->name ] = array_fill( 0, 11, __( 'Setting updated.', 'slack' ) ); … … 186 200 187 201 /** 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 191 212 */ 192 213 public function bulk_post_updated_messages( $bulk_messages, $bulk_counts ) { … … 195 216 if ( $this->name === $screen->post_type ) { 196 217 $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' ), 202 228 ); 203 229 } … … 209 235 * Custom bulk actions. 210 236 * 211 * @param array $actions 212 * @return array 237 * @param array $actions List of actions. 238 * @return array List of actions 213 239 * 214 240 * @filter bulk_actions-edit-slack_integration … … 217 243 unset( $actions['edit'] ); 218 244 245 // @codingStandardsIgnoreStart 219 246 // Unfortunately adding bulk actions won't work here. 220 247 // @see https://core.trac.wordpress.org/ticket/16031 … … 222 249 // $actions['activate'] = __( 'Activate', 'slack' ); 223 250 // $actions['deactivate'] = __( 'Deactivate', 'slack' ); 251 // @codingStandardsIgnoreEnd 224 252 225 253 return $actions; … … 229 257 * Custom row actions for this post type. 230 258 * 231 * @param array $actions 232 * @return array 259 * @param array $actions List of actions. 260 * 261 * @return array List of actions 233 262 * 234 263 * @filter post_row_actions … … 237 266 $post = get_post(); 238 267 239 if ( $this->plugin->post_type->name === get_post_type( $post )) {268 if ( get_post_type( $post ) === $this->plugin->post_type->name ) { 240 269 unset( $actions['inline hide-if-no-js'] ); 241 270 unset( $actions['view'] ); … … 245 274 246 275 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 . '&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 . '&action=deactivate', $post->ID ) ), 'deactivate-post_' . $post->ID ), 280 esc_html__( 'Deactivate', 'slack' ) 281 ); 248 282 } else { 249 $actions['activate'] = "<a title='" . esc_attr( __( 'Activate this integration setting' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&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 . '&action=activate', $post->ID ) ), 'activate-post_' . $post->ID ), 287 esc_html__( 'Activate', 'slack' ) 288 ); 250 289 } 251 290 } … … 275 314 * Action handler for activating/deactivating integration setting(s). 276 315 * 277 * @param bool $activate 316 * @param bool $activate Flag to indicated whether this is activattion action. 278 317 */ 279 318 private function _set_active_setting( $activate = true ) { … … 286 325 if ( ! $post ) { 287 326 wp_die( 327 /* translators: placeholder is action type, either 'activate' or 'deactivate'. */ 288 328 sprintf( __( 'The integration you are trying to %s is no longer exists.', 'slack' ), $activate ? 'activate' : 'deactivate' ) 289 329 ); … … 300 340 $key_arg = $activate ? 'activated' : 'deactivated'; 301 341 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 303 350 exit; 304 351 } 305 352 306 353 /** 354 * Display notice when integration is activated or deactivated. 307 355 * 308 356 * @action all_admin_notices … … 310 358 public function admin_notices() { 311 359 $screen = get_current_screen(); 312 if ( $screen->id !== 'edit-' . $this->name) {360 if ( 'edit-' . $this->name !== $screen->id ) { 313 361 return; 314 362 } … … 320 368 321 369 $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' ), 324 374 ); 325 375 326 376 $bulk_counts = array_filter( $bulk_counts ); 327 377 328 // If we have a bulk message to issue:378 // If we have a bulk message to display. 329 379 $messages = array(); 330 380 foreach ( $bulk_counts as $message => $count ) { … … 342 392 * Custom columns for this post type. 343 393 * 344 * @param array $columns 345 * @return array 394 * @param array $columns Post list columns. 395 * @return array Post list columns 346 396 * 347 397 * @filter manage_{post_type}_posts_columns … … 361 411 * Custom column appears in each row. 362 412 * 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. 365 415 * 366 416 * @action manage_{post_type}_posts_custom_column … … 398 448 * 399 449 * @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. 401 452 * @param int $post_id The post ID. 453 * 454 * @return array Array of post classes 402 455 * 403 456 * @filter post_class … … 427 480 * Hides subsubsub top nav. 428 481 * 429 * @return array 482 * @return array Top nav links 430 483 */ 431 484 public function hide_subsubsub() { … … 433 486 } 434 487 488 /** 489 * Change title placeholder for Slack Integration post. 490 * 491 * @param string $title Title placeholder. 492 * 493 * @return string Updated title placeholder 494 */ 435 495 public function title_placeholder( $title ) { 436 496 $screen = get_current_screen(); -
slack/trunk/includes/submit-meta-box.php
r891716 r1633724 1 1 <?php 2 2 /** 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. 5 11 */ 6 12 class WP_Slack_Submit_Meta_Box { 7 13 8 14 /** 15 * Plugin's instance. 16 * 9 17 * @var WP_Slack_Plugin 10 18 */ 11 19 private $plugin; 12 20 21 /** 22 * Constructor. 23 * 24 * @param WP_Slack_Plugin $plugin Plugin's instance. 25 */ 13 26 public function __construct( WP_Slack_Plugin $plugin ) { 14 27 $this->plugin = $plugin; … … 20 33 * Register submit meta box. 21 34 * 22 * @param 35 * @param string $post_type Post type. 23 36 */ 24 37 public function register_meta_box( $post_type ) { … … 31 44 * Display post submit form fields. 32 45 * 33 * @param object $post46 * @param WP_Post $post Post object. 34 47 */ 35 48 public function slack_submitdiv( $post ) { -
slack/trunk/readme.txt
r1567551 r1633724 3 3 Donate link: http://goo.gl/DELyuR 4 4 Tags: slack, api, chat, notification 5 Requires at least: 3.66 Tested up to: 4.7 7 Stable tag: 0. 5.15 Requires at least: 4.3 6 Tested up to: 4.7.3 7 Stable tag: 0.6.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 49 49 == Changelog == 50 50 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 51 57 = 0.5.1 = 52 58 * Removed bin directory for published plugin in WP.org. Props otto42 -
slack/trunk/slack.php
r1028900 r1633724 1 1 <?php 2 /** 3 * Main plugin's file. 4 * 5 * @package WP_Slack 6 */ 7 2 8 /** 3 9 * Plugin Name: Slack 4 10 * Plugin URI: http://gedex.web.id/wp-slack/ 5 11 * Description: This plugin allows you to send notifications to Slack channels when certain events in WordPress occur. 6 * Version: 0. 5.112 * Version: 0.6.0 7 13 * Author: Akeda Bagus 8 14 * Author URI: http://gedex.web.id … … 10 16 * Domain Path: /languages 11 17 * License: GPL v2 or later 12 * Requires at least: 3.613 * Tested up to: 3.918 * Requires at least: 4.3 19 * Tested up to: 4.7.3 14 20 * 15 21 * This program is free software; you can redistribute it and/or modify … … 29 35 WP_Slack_Autoloader::register( 'WP_Slack', trailingslashit( plugin_dir_path( __FILE__ ) ) . '/includes/' ); 30 36 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. 38 add_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 ?> 1 10 <table class="form-table"> 2 11 <tbody> … … 44 53 <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'] ) : ''; ?>"> 45 54 <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 ?> 47 59 </p> 48 60 </td> … … 74 86 </th> 75 87 <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> 77 92 <p class="description"> 78 93 <?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 ?> 1 10 <div class="submitbox" id="submitpost"> 2 11 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 ?> 4 18 <div style="display:none;"> 5 <?php submit_button( __( 'Save' ), 'button', 'save' ); ?>19 <?php submit_button( __( 'Save', 'slack' ), 'button', 'save' ); ?> 6 20 </div> 7 21 … … 25 39 <span class="spinner"></span> 26 40 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' ); ?>" /> 29 43 </div> 30 44 <div class="clear"></div>
Note: See TracChangeset
for help on using the changeset viewer.