How to use the @wordpress/hooks.addFilter function in @wordpress/hooks

To help you get started, we’ve selected a few @wordpress/hooks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / site-kit-wp / assets / js / modules / analytics / setup.js View on Github external
} catch ( err ) {
				this.setState(
					{
						isLoading: false,
						errorCode: err.code,
						errorMsg: err.message,
						errorReason: err.data && err.data.reason ? err.data.reason : false,
					}
				);
			}
		} else {
			await this.getAccounts();
		}

		// Handle save hook from the settings page.
		addFilter( 'googlekit.SettingsConfirmed',
			'googlekit.AnalyticsSettingsConfirmed',
			( chain, module ) => {
				if ( 'analytics' !== module.replace( '-module', '' ) ) {
					return chain;
				}
				const { isEditing } = this.props;
				if ( isEditing ) {
					return this.handleSubmit();
				}
			} );
	}
github gambitph / Stackable / src / block / icon-list / design.js View on Github external
/**
 * External dependencies
 */
import { omit } from 'lodash'

/**
 * WordPress dependencies
 */
import { addFilter } from '@wordpress/hooks'

// Remove text from block designs being applied.
addFilter( 'stackable.icon-list.design.no-text-attributes', 'stackable/icon-list', attributes => {
	return omit( attributes, [
		'text',
	] )
} )
github google / site-kit-wp / assets / js / components / data / index.js View on Github external
result.error_data[ 403 ].reason
					) {
						if ( 'insufficientPermissions' === result.error_data[ 403 ].reason ) {
							// Insufficient scopes - add a notice.
							addFilter( 'googlesitekit.DashboardNotifications',
								'googlesitekit.AuthNotification',
								fillFilterWithComponent( DashboardAuthAlert ), 1 );
						} else if ( 'forbidden' === result.error_data[ 403 ].reason ) {
							// Insufficient access permissions - add a notice.
							addFilter( 'googlesitekit.DashboardNotifications',
								'googlesitekit.AuthNotification',
								fillFilterWithComponent( DashboardPermissionAlert ), 1 );
						}

						// Increase the notice count.
						addFilter( 'googlesitekit.TotalNotifications',
							'googlesitekit.AuthCountIncrease', ( count ) => {
								// Only run once.
								removeFilter( 'googlesitekit.TotalNotifications', 'googlesitekit.AuthCountIncrease' );
								return count + 1;
							} );
					}

					each( keyIndexesMap[ key ], ( index ) => {
						const request = dataRequest[ index ];

						this.setCache( request.key, result );
						this.resolve( request, result );
					} );
				}

				// Trigger an action indicating this data load completed from the API.
github insideout10 / wordlift-plugin / src / src / js / src / block-editor / filters / add-entity.filters.js View on Github external
export default store => {
  // Hook to `wordlift.AddEntity.preWrapperContainer` in order to display notices.
  addFilter("wordlift.AddEntity.beforeWrapperContainer", "wordlift", values => values.concat(<Notice />));

  // Hook to `wordlift.AddEntity.preWrapperContainer` in order to display notices.
  addFilter("wordlift.AddEntity.afterWrapperContainer", "wordlift", values =>
    values.concat(
      <Provider store={store}>
        <CreateEntityFormContainer />
      </Provider>
    )
  );
};
github godaddy-wordpress / coblocks / src / extensions / advanced-controls / index.js View on Github external
addFilter(
	'blocks.registerBlockType',
	'coblocks/AdvancedControls/attributes',
	addAttributes
);

addFilter( 'editor.BlockEdit', 'coblocks/advanced', withAdvancedControls );

addFilter(
	'blocks.getSaveContent.extraProps',
	'coblocks/applySpacingClass',
	applySpacingClass
);

addFilter(
	'editor.BlockListBlock',
	'coblocks/addEditorBlockAttributes',
	addEditorBlockAttributes
);
github htmlburger / carbon-fields / packages / blocks / fields / checkbox / index.js View on Github external
/**
 * External dependencies.
 */
import { addFilter } from '@wordpress/hooks';

/**
 * Internal dependencies.
 */
import './style.scss';

addFilter( 'carbon-fields.checkbox-field.block', 'carbon-fields/blocks', ( OriginalCheckboxField ) => OriginalCheckboxField );
github WordPress / gutenberg / packages / block-editor / src / hooks / custom-class-name.native.js View on Github external
...customClasses,
		] ).join( ' ' );

		if ( filteredClassName ) {
			blockAttributes.className = filteredClassName;
		} else {
			delete blockAttributes.className;
		}
	}

	return blockAttributes;
}

addFilter( 'blocks.registerBlockType', 'core/custom-class-name/attribute', addAttribute );
addFilter( 'blocks.getSaveContent.extraProps', 'core/custom-class-name/save-props', addSaveProps );
addFilter( 'blocks.getBlockAttributes', 'core/custom-class-name/addParsedDifference', addParsedDifference );
github Automattic / jetpack / extensions / blocks / videopress / editor.js View on Github external
{
					attributes,
					isEligible: attrs => ! attrs.guid,
					save,
					supports,
					isDeprecation: true,
				},
				deprecatedV1,
			],
		};
	}

	return settings;
};

addFilter( 'blocks.registerBlockType', 'jetpack/videopress', addVideoPressSupport );
github gambitph / Stackable / src / modules / content-align / index.js View on Github external
const contentAlign = blockName => {
	addFilter( `stackable.${ blockName }.edit.inspector.before`, `stackable/${ blockName }/content-align`, addAlignToolbar, 11 )
	addFilter( `stackable.${ blockName }.attributes`, `stackable/${ blockName }/content-align`, addAttributes )
	addFilter( `stackable.${ blockName }.styles`, `stackable/${ blockName }/content-align`, addStyles, 9 )
	doAction( `stackable.module.content-align`, blockName )
}
github WordPress / gutenberg / editor / hooks / align.js View on Github external
* @param  {Object} props      Additional props applied to save element
 * @param  {Object} blockType  Block type
 * @param  {Object} attributes Block attributes
 * @return {Object}            Filtered props applied to save element
 */
export function addAssignedAlign( props, blockType, attributes ) {
	const { align } = attributes;

	if ( includes( getBlockValidAlignments( blockType ), align ) ) {
		props.className = classnames( `align${ align }`, props.className );
	}

	return props;
}

addFilter( 'blocks.registerBlockType', 'core/align/addAttribute', addAttribute );
addFilter( 'editor.BlockListBlock', 'core/editor/align/with-data-align', withDataAlign );
addFilter( 'editor.BlockEdit', 'core/editor/align/with-toolbar-controls', withToolbarControls );
addFilter( 'blocks.getSaveContent.extraProps', 'core/align/addAssignedAlign', addAssignedAlign );