@wordpress/hooks use to add actions/filters within multiple plugin

I am trying to use @wordpress/hooks package in one of my react based plugin. I have added some hooks(filters/actions) and I need to hook into these from different plugin.

I am able to add filter for applied filters within same plugin reactJs file but not working when added from different plugin.

Here is code from main plugin –

import React from 'react';
import { Component } from '@wordpress/element';
import { applyFilters } from '@wordpress/hooks';
import { addFilter } from '@wordpress/hooks';
import { useFilters } from '@woocommerce/components';

export const TEST_FILTER = 'wk_test_filter';

// addFilter( TEST_FILTER, 'plugin-domain', title => {
//  return `Added to ${title}`;
// } );

export const titleFilter = applyFilters( TEST_FILTER, 'Default text' );

class App extends Component {
    constructor( props ) {
        super( props );
    }

    render() {
        return (
            <div>
                <h1>{ titleFilter }</h1>
            </div>
        );
    }
}

export default useFilters( TEST_FILTER )(App);

The commented code in above snippet is working fine but when I add the same filter from different react based plugin then it is not working anymore.

Source URL

0

Leave a Comment