• Resolved Isabel Pinhel

    (@isabelpinhel)


    Hi there,

    I need to remove an action added inside a Class constructor without resorting to editing plugin files but have had no luck so far.
    The action I am trying to remove is located on line 23 of wc-vendors/classes/admin/class-admin-users.php and is the following:
    add_action( 'edit_user_profile', array( $this, 'show_extra_profile_fields' ) );

    Here is what I have tried so far to no avail in my theme’s functions.php file:

    add_action( 'wp_head', 'remove_wc_vendors_actions' );
    function remove_wc_vendors_actions() {
        if ( is_callable( array( $WCV_Admin_Users, 'show_extra_profile_fields' ) ) ) {
    		global $WCV_Admin_Users;
    		remove_action( 'edit_user_profile' , array( $WCV_Admin_Users, 'show_extra_profile_fields' ) );
        }
    }
    add_action( 'wp_head', 'remove_wc_vendors_actions' );
    function remove_wc_vendors_actions() {
        if ( is_callable( array( 'WCV_Admin_Users', 'show_extra_profile_fields' ) ) ) {
    		remove_action( 'edit_user_profile' , array( 'WCV_Admin_Users', 'show_extra_profile_fields' ) );
    	}
    }
    add_action( 'wp_head', 'remove_wc_vendors_actions' );
    function remove_wc_vendors_actions() {
        if ( is_callable( 'WCV_Admin_Users::show_extra_profile_fields' ) ) {
    		remove_action( 'edit_user_profile', 'WCV_Admin_Users::show_extra_profile_fields' );
    	}
    
    }

    Please could you provide code to remove this action?
    Many thanks,
    Isabel

    • This topic was modified 1 year, 12 months ago by Isabel Pinhel.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @isabelpinhel,

    I’ll check this with the team. I’ll update you if this is possible.

    Cheers,
    Lloyd

    Thread Starter Isabel Pinhel

    (@isabelpinhel)

    Hi,

    Thanks so much! Look forward to a positive outcome.

    Isabel

    Hi @isabelpinhel,

    Can you try the following:

    add_action( 'admin_init', 'remove_extra_profile_fields', 1 );
    
    /**
     * Remove user extra profile fields.
     */
    function remove_extra_profile_fields() {
    	global $wp_filter;
    	if ( ! isset( $wp_filter['edit_user_profile'][10] ) || ! is_array( $wp_filter['edit_user_profile'][10] ) ) {
    		return false;
    	}
    
    	foreach ( $wp_filter['edit_user_profile'][10] as $unique_id => $value ) {
    		if ( is_object( $value['function'][0] ) && $value['function'][1] === 'show_extra_profile_fields' && get_class( $value['function'][0] ) ) {
    			if ( is_a( $wp_filter['edit_user_profile'], 'WP_Hook' ) ) {
    				unset( $wp_filter['edit_user_profile']->callbacks[10][ $unique_id ] );
    			} else {
    				unset( $wp_filter['edit_user_profile'][10][ $unique_id ] );
    			}
    		}
    	}
    	return false;
    }

    Cheers,
    Lloyd

    Thread Starter Isabel Pinhel

    (@isabelpinhel)

    Hi Lloyd,

    The code worked!
    Many thanks!
    Isabel

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Remove action inside Class constructor’ is closed to new replies.