• Hello!

    I would like to remove the action done by meta_generator which is found in
    the class MSP_Frontend_Assets inside class-msp-frontend-assets.php.

    add_action( ‘wp_head’ , array( $this, ‘meta_generator’ ) );

    However, since “$this” is residing inside MSP_Frontend_Assets which is not interfaced to be called from outside. class-msp-frontend-assets.php is being included by class-master-slider.php. I cannot find any way to get the original instantiated MSP_Frontend_Assets class.

    I did try other way such as

    // it is not an array
    remove_action( ‘wp_head’, array( ‘MSP_Frontend_Assets’, ‘meta_generator’ ) );

    // different instance
    remove_action( ‘wp_head’, array( new MSP_Frontend_Assets(), ‘meta_generator’ ) );

    So, the only way seems only calling the original instance of MSP_Frontend_Assets
    remove_action( ‘wp_head’, array( Original_Instance_MSP_Frontend_Assets, ‘meta_generator’ ) );

    Am I correct?
    Or is there any other way that I have overlooked?

    Thanks a lot.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor averta support

    (@averta_support)

    Hi,

    Thank you for choosing Master Slider.
    To disable meta tags, add the below code to functions.php in your theme:

    /**
     * Make sure the function does not exist before defining it
     */
    if( ! function_exists( 'msp_remove_class_filter' ) ){
    
        function msp_remove_class_filter( $tag, $class_name = '', $method_name = '', $priority = 10 ) {
            global $wp_filter;
            // Check that filter actually exists first
            if ( ! isset( $wp_filter[ $tag ] ) ) {
                return FALSE;
            }
    
            if ( is_object( $wp_filter[ $tag ] ) && isset( $wp_filter[ $tag ]->callbacks ) ) {
                // Create $fob object from filter tag, to use below
                $fob       = $wp_filter[ $tag ];
                $callbacks = &$wp_filter[ $tag ]->callbacks;
            } else {
                $callbacks = &$wp_filter[ $tag ];
            }
            // Exit if there aren't any callbacks for specified priority
            if ( ! isset( $callbacks[ $priority ] ) || empty( $callbacks[ $priority ] ) ) {
                return FALSE;
            }
            // Loop through each filter for the specified priority, looking for our class & method
            foreach ( (array) $callbacks[ $priority ] as $filter_id => $filter ) {
                // Filter should always be an array - array( $this, 'method' ), if not goto next
                if ( ! isset( $filter['function'] ) || ! is_array( $filter['function'] ) ) {
                    continue;
                }
                // If first value in array is not an object, it can't be a class
                if ( ! is_object( $filter['function'][0] ) ) {
                    continue;
                }
                // Method doesn't match the one we're looking for, goto next
                if ( $filter['function'][1] !== $method_name ) {
                    continue;
                }
                // Method matched, now let's check the Class
                if ( get_class( $filter['function'][0] ) === $class_name ) {
                    // WordPress 4.7+ use core remove_filter() since we found the class object
                    if ( isset( $fob ) ) {
                        // Handles removing filter, reseting callback priority keys mid-iteration, etc.
                        $fob->remove_filter( $tag, $filter['function'], $priority );
                    } else {
                        // Use legacy removal process (pre 4.7)
                        unset( $callbacks[ $priority ][ $filter_id ] );
                        // and if it was the only filter in that priority, unset that priority
                        if ( empty( $callbacks[ $priority ] ) ) {
                            unset( $callbacks[ $priority ] );
                        }
                        // and if the only filter for that tag, set the tag to an empty array
                        if ( empty( $callbacks ) ) {
                            $callbacks = array();
                        }
                        // Remove this filter from merged_filters, which specifies if filters have been sorted
                        unset( $GLOBALS['merged_filters'][ $tag ] );
                    }
                    return TRUE;
                }
            }
            return FALSE;
        }
    }
    
    add_action( 'plugins_loaded', function(){
        msp_remove_class_filter( 'wp_head', 'MSP_Frontend_Assets', 'meta_generator' );
    });

    If you need any further information, please let me know.

    Best,

    Thread Starter 西門 正 Code Guy

    (@simongcc)

    Thanks for your inspiration, I work it on another plugin so I changed a bit of the calling code to

    function remove_msp_meta() {
      msp_remove_class_filter( 'wp_head', 'MSP_Frontend_Assets', 'meta_generator' );
    }
    // put it to (9) earlier then the meta_generator (10) to add the action so that this action will be called before priority 10 and remove the queued 'meta_generator' from priority 10 action before running
    add_action( 'wp_head', 'remove_msp_meta', 9);

    Thanks a lot.

    Plugin Contributor averta support

    (@averta_support)

    Hi again,

    I’m glad it has been resolved.
    Please let us know if you have any more issues.

    Best,

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to properly remove meta tag in wp_head?’ is closed to new replies.