Plugin Directory

Changeset 3384204


Ignore:
Timestamp:
10/24/2025 07:03:59 PM (5 months ago)
Author:
vsmash
Message:

fix to trunk

Location:
vanilla-bean-slack-hooker/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • vanilla-bean-slack-hooker/trunk

    • Property svn:ignore set to
      maiass.log
  • vanilla-bean-slack-hooker/trunk/CHANGELOG.md

    r3372099 r3384204  
     1## 5.5.5
     225 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
    113## 5.5.3
    21403 October 2025
  • vanilla-bean-slack-hooker/trunk/VERSION

    r3372099 r3384204  
    1 5.5.3
     15.5.5
  • vanilla-bean-slack-hooker/trunk/admin/class-vanilla-bean-slack-hooker-admin.php

    r3277785 r3384204  
    618618                    //'help'        => 'Go get your google map api key',
    619619                ),
     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                ),
    620629                // default icon
    621630                array(
  • vanilla-bean-slack-hooker/trunk/includes/class-slack-hooker-message.php

    r2953563 r3384204  
    8181            }
    8282            // check for slack app
    83             if($endpoint["alert"]){
     83            if($endpoint["alert"] && isset($this->payload['text'])){
    8484                $this->payload['text']='<!'.$endpoint["alert"].'>'.$this->payload['text'];
    8585            }
    86             if($endpoint["icon"]){
     86            if(isset($endpoint["icon"]) && $endpoint["icon"]){
    8787                $this->payload['icon_emoji']=$endpoint["icon"];
    8888            }
    89             elseif($endpoint["emoji"]){
     89            elseif(isset($endpoint["emoji"]) && $endpoint["emoji"]){
    9090                $this->payload['icon_emoji']=$endpoint["emoji"];
    9191            }
    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'])){
    9393                $this->payload['text']=$this->payload['username'].': '.$this->payload['text'];
    9494            }
     
    9999
    100100                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);
    102103                    continue;
    103104                }
     
    164165            $formattedEndpoints[]=$epx;
    165166        }
    166         error_log("\033[0;53m");
    167         error_log(print_r($formattedEndpoints,true));
    168         error_log("\033[0m");
    169167        $this->endpoints = $formattedEndpoints;
    170168    }
  • vanilla-bean-slack-hooker/trunk/includes/class-vanilla-bean-slack-hooker-loader.php

    r2953563 r3384204  
    127127        }
    128128
    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
    130202    }
    131203
  • vanilla-bean-slack-hooker/trunk/includes/notifier.php

    r3372099 r3384204  
    6868// build plugin attachment message
    6969if (!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)
    7171    {
    7272        $current_user = wp_get_current_user();
    7373        // is $current_user an object?
    7474        $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;
    7879        }
     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       
    7991        $message = array(
    8092            "color" => $color,
     
    99111// The hook is specified directly in the loader
    100112if (!function_exists('\VanillaBeans\SlackHooker\plugin_upgrader')) {
    101     function plugin_upgrader($plugin, $upgrader)
     113    function plugin_upgrader($upgrader, $hook_extra)
    102114    {
    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')) {
    104116            return false;
    105117        }
     
    109121            return false;
    110122        }
    111             $obj = $options['notifications']['plugin_change']['tabs'];
    112 
     123        $obj = $options['notifications']['plugin_change']['tabs'];
    113124
    114125        if($obj['plugin_change_onoff']!='yes'){
     
    116127        }
    117128
    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']];
    122130
     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        }
    123143
     144        // Process each plugin (usually just one)
     145        foreach ($plugins as $plugin_path) {
     146            $plugin = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path, false);
    124147
     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';
    125159
    126         $plugin = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin->plugin_info(), false);
     160            \Vanilla_Bean_Slack_Hooker::notification_send($message, $endpoints, $endpointOptions);
     161        }
    127162
    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;
    139164    }
    140165}
  • vanilla-bean-slack-hooker/trunk/readme.txt

    r3372099 r3384204  
    66Tested up to: 6.8
    77PHP Tested up to: 8.2
    8 Stable tag: 5.5.3
     8Stable tag: 5.5.5
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • vanilla-bean-slack-hooker/trunk/vanilla-bean-slack-hooker.php

    r3372099 r3384204  
    1717Plugin URI:        https://www.velvary.com.au
    1818Description:       Integrate webhooks into your site for notifications via Slack, Mattermost or others
    19 Version: 5.5.3
     19Version: 5.5.5
    2020Author:            Velvary
    2121Author URI:        https://www.velvary.com.au
Note: See TracChangeset for help on using the changeset viewer.