0

I'm trying to remove an action in edit_user_profile from a plugin. But I don't know how to do, This is add_action from the plugin : https://github.com/jaredatch/Basic-User-Avatars/blob/master/init.php

/**
 * Initialize all the things
 *
 * @since 1.0.0
 */
public function __construct() {
    // Text domain
    $this->load_textdomain();
    // Actions
    add_action( 'admin_init',                array( $this, 'admin_init'               )        );
    add_action( 'show_user_profile',         array( $this, 'edit_user_profile'        )        );
    add_action( 'edit_user_profile',         array( $this, 'edit_user_profile'        )        );
    add_action( 'personal_options_update',   array( $this, 'edit_user_profile_update' )        );
    add_action( 'edit_user_profile_update',  array( $this, 'edit_user_profile_update' )        );
    add_action( 'bbp_user_edit_after_about', array( $this, 'bbpress_user_profile'     )        );
    // Shortcode
    add_shortcode( 'basic-user-avatars',     array( $this, 'shortcode'                )        );
    // Filters
    add_filter( 'get_avatar',                array( $this, 'get_avatar'               ), 10, 5 );
    add_filter( 'avatar_defaults',           array( $this, 'avatar_defaults'          )        );
}
/**
 * Loads the plugin language files.
 *
 * @since 1.0.1
 */
public function load_textdomain() {
    $domain = 'basic-user-avatars';
    $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
    load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
    load_plugin_textdomain( $domain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}

Thank you :)

0

You could try:

add_action( 'plugins_loaded', function() {
    global $basic_user_avatars;
    remove_action( 'edit_user_profile', array( &$basic_user_avatars, 'edit_user_profile' ) );
});

You need to make sure this is done after the other plugin has been initialized, therefore the plugins_loaded action.

  • Thanks Mickael ! Sadly this does not seem to work. I added "9999" to the priority ? Is it good or I misunterstand something ? Have a nice day – Garrosh Sep 15 '18 at 13:52
  • The priority must be the same as in the corresponding add_action. To make sure your code gets executed at a later point, you could wrap it into a plugins_loaded action. See updated answer. – Michael Sep 15 '18 at 13:55
  • Thank you Mickael, I understand better. How can I run some tests to determinate what is wrong ? Thank you – Garrosh Sep 15 '18 at 14:07
  • This should work, but you didn't say where - in which file - you are running the code to remove the action. – Michael Sep 15 '18 at 14:09
  • In functions.php of my child theme. – Garrosh Sep 15 '18 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.