Changeset 3384204
- Timestamp:
- 10/24/2025 07:03:59 PM (5 months ago)
- Location:
- vanilla-bean-slack-hooker/trunk
- Files:
-
- 9 edited
-
. (modified) (1 prop)
-
CHANGELOG.md (modified) (1 diff)
-
VERSION (modified) (1 diff)
-
admin/class-vanilla-bean-slack-hooker-admin.php (modified) (1 diff)
-
includes/class-slack-hooker-message.php (modified) (3 diffs)
-
includes/class-vanilla-bean-slack-hooker-loader.php (modified) (1 diff)
-
includes/notifier.php (modified) (4 diffs)
-
readme.txt (modified) (1 diff)
-
vanilla-bean-slack-hooker.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
vanilla-bean-slack-hooker/trunk
-
Property
svn:ignore
set to
maiass.log
-
Property
svn:ignore
set to
-
vanilla-bean-slack-hooker/trunk/CHANGELOG.md
r3372099 r3384204 1 ## 5.5.5 2 25 October 2025 3 4 - Enhancements and fixes in Slack Hooker 5 - feat: added CLI/Auto-update User option in admin settings 6 - fix: added checks for isset conditions to prevent undefined errors 7 - fix: removed error logging in Slack_Hooker_Message 8 - feat: implemented detection of plugin updates during WP-CLI and auto-updates 9 - feat: enhanced update context to differentiate between WP-CLI and auto-updates 10 - feat: implemented plugin updater notifier for detected updates 11 - fix: adjusted email body composition to handle missing payload['text'] scenario 12 1 13 ## 5.5.3 2 14 03 October 2025 -
vanilla-bean-slack-hooker/trunk/VERSION
r3372099 r3384204 1 5.5. 31 5.5.5 -
vanilla-bean-slack-hooker/trunk/admin/class-vanilla-bean-slack-hooker-admin.php
r3277785 r3384204 618 618 //'help' => 'Go get your google map api key', 619 619 ), 620 // CLI/scheduled update username 621 array( 622 'id' => 'cli_username', 623 'type' => 'text', 624 'title' => 'CLI/Auto-update User', 625 'class' => 'text-class', 626 'description' => 'Username shown for WP-CLI and automatic plugin updates', 627 'default' => 'Auto-update', 628 ), 620 629 // default icon 621 630 array( -
vanilla-bean-slack-hooker/trunk/includes/class-slack-hooker-message.php
r2953563 r3384204 81 81 } 82 82 // check for slack app 83 if($endpoint["alert"] ){83 if($endpoint["alert"] && isset($this->payload['text'])){ 84 84 $this->payload['text']='<!'.$endpoint["alert"].'>'.$this->payload['text']; 85 85 } 86 if( $endpoint["icon"]){86 if(isset($endpoint["icon"]) && $endpoint["icon"]){ 87 87 $this->payload['icon_emoji']=$endpoint["icon"]; 88 88 } 89 elseif( $endpoint["emoji"]){89 elseif(isset($endpoint["emoji"]) && $endpoint["emoji"]){ 90 90 $this->payload['icon_emoji']=$endpoint["emoji"]; 91 91 } 92 if(str_starts_with($endpoint["url"],'https://hooks.slack.com/services/') ){92 if(str_starts_with($endpoint["url"],'https://hooks.slack.com/services/') && isset($this->payload['text'])){ 93 93 $this->payload['text']=$this->payload['username'].': '.$this->payload['text']; 94 94 } … … 99 99 100 100 if($isemail){ 101 $output[] = wp_mail($endpoint['url'], $this->payload['username'], $this->payload['text']); 101 $email_body = isset($this->payload['text']) ? $this->payload['text'] : json_encode($this->payload); 102 $output[] = wp_mail($endpoint['url'], $this->payload['username'], $email_body); 102 103 continue; 103 104 } … … 164 165 $formattedEndpoints[]=$epx; 165 166 } 166 error_log("\033[0;53m");167 error_log(print_r($formattedEndpoints,true));168 error_log("\033[0m");169 167 $this->endpoints = $formattedEndpoints; 170 168 } -
vanilla-bean-slack-hooker/trunk/includes/class-vanilla-bean-slack-hooker-loader.php
r2953563 r3384204 127 127 } 128 128 129 add_action('upgrader_process_complete', '\VanillaBeans\SlackHooker\plugin_upgrader', 9999, 2); 129 // Standard hook for admin updates (this works fine) 130 add_action('upgrader_process_complete', function($upgrader, $hook_extra) { 131 \VanillaBeans\SlackHooker\plugin_upgrader($upgrader, $hook_extra); 132 }, 10, 2); 133 134 // For WP-CLI and auto-updates: Detect version changes on every load 135 add_action('plugins_loaded', function() { 136 $current_plugins = get_plugins(); 137 $stored_plugins = get_option('_slackhooker_plugin_versions', array()); 138 139 // Store the current update context (WP-CLI, cron, etc.) 140 $update_context = null; 141 if (defined('WP_CLI') && WP_CLI) { 142 // Get the configured CLI username 143 $options = get_exopite_sof_option('vanilla-bean-slack-hooker'); 144 $update_context = isset($options['cli_username']) ? $options['cli_username'] : 'WP-CLI'; 145 update_option('_slackhooker_update_context', $update_context); 146 } elseif (defined('DOING_CRON') && DOING_CRON) { 147 // Get the configured CLI username (used for auto-updates too) 148 $options = get_exopite_sof_option('vanilla-bean-slack-hooker'); 149 $update_context = isset($options['cli_username']) ? $options['cli_username'] : 'Auto-update'; 150 update_option('_slackhooker_update_context', $update_context); 151 } 152 153 // First time - just store current state 154 if (empty($stored_plugins)) { 155 update_option('_slackhooker_plugin_versions', $current_plugins); 156 return; 157 } 158 159 // Compare to detect updates that happened 160 $updated_plugins = array(); 161 foreach ($current_plugins as $plugin_file => $plugin_data) { 162 if (isset($stored_plugins[$plugin_file])) { 163 $old_version = $stored_plugins[$plugin_file]['Version']; 164 $new_version = $plugin_data['Version']; 165 166 if (version_compare($new_version, $old_version, '>')) { 167 $updated_plugins[$plugin_file] = $plugin_data; 168 } 169 } elseif (!isset($stored_plugins[$plugin_file])) { 170 // New plugin installed 171 $updated_plugins[$plugin_file] = $plugin_data; 172 } 173 } 174 175 // Update stored versions for next check 176 update_option('_slackhooker_plugin_versions', $current_plugins); 177 178 // Send notifications for updated plugins 179 if (!empty($updated_plugins)) { 180 $stored_context = get_option('_slackhooker_update_context', null); 181 182 // If no context was stored, use the configured CLI username 183 if (!$stored_context) { 184 $options = get_exopite_sof_option('vanilla-bean-slack-hooker'); 185 $stored_context = isset($options['cli_username']) ? $options['cli_username'] : 'Auto-update'; 186 } 187 188 foreach ($updated_plugins as $plugin_file => $plugin_data) { 189 $hook_extra = array( 190 'type' => 'plugin', 191 'action' => 'update', 192 'plugin' => $plugin_file, 193 'context' => $stored_context 194 ); 195 196 \VanillaBeans\SlackHooker\plugin_upgrader(null, $hook_extra); 197 } 198 // Clear the context after use 199 delete_option('_slackhooker_update_context'); 200 } 201 }, 0); // Priority 0 to run as early as possible 130 202 } 131 203 -
vanilla-bean-slack-hooker/trunk/includes/notifier.php
r3372099 r3384204 68 68 // build plugin attachment message 69 69 if (!function_exists('\VanillaBeans\SlackHooker\build_attachment_message')) { 70 function build_attachment_message($color, $status, $plugin )70 function build_attachment_message($color, $status, $plugin, $context = null) 71 71 { 72 72 $current_user = wp_get_current_user(); 73 73 // is $current_user an object? 74 74 $username = empty($current_user) ? 'System' : $current_user->display_name??'System'; 75 // is the current user WP-CLI? 76 if (defined('WP_CLI') && WP_CLI) { 77 $username = 'WP-CLI'; 75 76 // Check for stored context first (from version detection) 77 if ($context) { 78 $username = $context; 78 79 } 80 // Otherwise check if WP-CLI is currently running 81 elseif (defined('WP_CLI') && WP_CLI) { 82 $options = get_exopite_sof_option('vanilla-bean-slack-hooker'); 83 $username = isset($options['cli_username']) ? $options['cli_username'] : 'WP-CLI'; 84 } 85 // Check for auto-updates 86 elseif (defined('DOING_CRON') && DOING_CRON) { 87 $options = get_exopite_sof_option('vanilla-bean-slack-hooker'); 88 $username = isset($options['cli_username']) ? $options['cli_username'] : 'Auto-update'; 89 } 90 79 91 $message = array( 80 92 "color" => $color, … … 99 111 // The hook is specified directly in the loader 100 112 if (!function_exists('\VanillaBeans\SlackHooker\plugin_upgrader')) { 101 function plugin_upgrader($ plugin, $upgrader)113 function plugin_upgrader($upgrader, $hook_extra) 102 114 { 103 if (!isset($ upgrader['type'], $upgrader['action']) || $upgrader['type'] != 'plugin' || ($upgrader['action'] != 'install'&& $upgrader['action'] != 'update')) {115 if (!isset($hook_extra['type'], $hook_extra['action']) || $hook_extra['type'] != 'plugin' || ($hook_extra['action'] != 'install'&& $hook_extra['action'] != 'update')) { 104 116 return false; 105 117 } … … 109 121 return false; 110 122 } 111 $obj = $options['notifications']['plugin_change']['tabs']; 112 123 $obj = $options['notifications']['plugin_change']['tabs']; 113 124 114 125 if($obj['plugin_change_onoff']!='yes'){ … … 116 127 } 117 128 118 $colour = $obj['colours'][$upgrader['action']]; 119 $current_user = wp_get_current_user(); 120 // is $current_user an object? 121 $username = empty($current_user) ? 'System' : $current_user->display_name??'System'; 129 $colour = $obj['colours'][$hook_extra['action']]; 122 130 131 // Extract plugin path(s) from hook_extra 132 // Handle both single plugin updates and bulk updates 133 $plugins = array(); 134 if (isset($hook_extra['plugin'])) { 135 // Single plugin update 136 $plugins[] = $hook_extra['plugin']; 137 } elseif (isset($hook_extra['plugins'])) { 138 // Bulk plugin update 139 $plugins = $hook_extra['plugins']; 140 } else { 141 return false; 142 } 123 143 144 // Process each plugin (usually just one) 145 foreach ($plugins as $plugin_path) { 146 $plugin = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path, false); 124 147 148 // Skip if plugin data couldn't be retrieved 149 if (empty($plugin['Name'])) { 150 continue; 151 } 152 153 // Pass context if available 154 $context = isset($hook_extra['context']) ? $hook_extra['context'] : null; 155 $message = build_attachment_message($colour, $hook_extra['action'], $plugin, $context); 156 157 $endpoints = $obj['endpoints']??false; 158 $endpointOptions = $obj['endpointOptions']??'default'; 125 159 126 $plugin = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin->plugin_info(), false); 160 \Vanilla_Bean_Slack_Hooker::notification_send($message, $endpoints, $endpointOptions); 161 } 127 162 128 $message = build_attachment_message($colour,$upgrader['action'],$plugin); 129 130 error_log("\033[0;33m attachment message done \033[0m"); 131 // if $obj has no array key 'endpoints' assign false to $endpoints 132 $endpoints = $obj['endpoints']??false; 133 134 135 $endpointOptions = $obj['endpointOptions']??'default'; 136 137 138 return \Vanilla_Bean_Slack_Hooker::notification_send($message, $endpoints, $endpointOptions); 163 return true; 139 164 } 140 165 } -
vanilla-bean-slack-hooker/trunk/readme.txt
r3372099 r3384204 6 6 Tested up to: 6.8 7 7 PHP Tested up to: 8.2 8 Stable tag: 5.5. 38 Stable tag: 5.5.5 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
vanilla-bean-slack-hooker/trunk/vanilla-bean-slack-hooker.php
r3372099 r3384204 17 17 Plugin URI: https://www.velvary.com.au 18 18 Description: Integrate webhooks into your site for notifications via Slack, Mattermost or others 19 Version: 5.5. 319 Version: 5.5.5 20 20 Author: Velvary 21 21 Author URI: https://www.velvary.com.au
Note: See TracChangeset
for help on using the changeset viewer.