do_action and add_action on two different installed plugins won't work

I have an existing plugin (wptelegram) which implements in its code a call for do_action (for example, wptelegram_p2tg_after_send_post) that I would want to hook a function into. I created a basic single file plugin, installed and activated, I do see the logs for it to be activated, however, when the do_action is fired, I don't my add_action fires (no log printing so I guess it's not working)

[13-Aug-2021 21:07:04 UTC] WPTELEGRAM_LOADED!
[13-Aug-2021 21:07:04 UTC] myplugin activated
?php
/**
* Plugin Name: My first plugin
*/

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
    die;
}

if (!function_exists('write_log')) {

    function write_log($log) {
        if (true === WP_DEBUG) {
            if (is_array($log) || is_object($log)) {
                error_log(print_r($log, true));
            } else {
                error_log($log);
            }
        }
    }

}

function activate_myplugin() {
    write_log('myplugin activated');
}

function deactivate_myplugin() {
    write_log('myplugin deactivated');
}

register_activation_hook( __FILE__, 'activate_myplugin' );
register_deactivation_hook( __FILE__, 'deactivate_myplugin' );


if (defined('WPTELEGRAM_LOADED')  WPTELEGRAM_LOADED) {
    write_log('WPTELEGRAM_LOADED!');

    function my_callback($result, $post, $trigger, $force) {
        write_log('my_callback!');
    }

    add_action( 'wptelegram_p2tg_after_send_post', 'my_callback', 10, 4 );
}

Topic troubleshooting plugin-development hooks Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.