File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/filters.tar
block-list-block.js 0000644 00000004720 15155105052 0010237 0 ustar 00 /**
* External dependencies
*/
import { Component } from '@wordpress/element';
import { createHigherOrderComponent } from '@wordpress/compose';
import { getBlockType } from '@wordpress/blocks';
import { addFilter } from '@wordpress/hooks';
/**
* withDefaultAttributes HOC for editor.BlockListBlock.
*
* @param object BlockListBlock The BlockListBlock element.
*/
const withDefaultAttributes = createHigherOrderComponent(
( BlockListBlock ) => {
class WrappedComponent extends Component {
mounted = false;
componentDidMount() {
const { block, setAttributes } = this.props;
if ( block.name.startsWith( 'woocommerce/' ) ) {
setAttributes( this.getAttributesWithDefaults() );
}
}
componentDidUpdate() {
if (
this.props.block.name.startsWith( 'woocommerce/' ) &&
! this.mounted
) {
this.mounted = true;
}
}
getAttributesWithDefaults() {
const blockType = getBlockType( this.props.block.name );
let attributes = this.props.attributes;
if (
! this.mounted &&
this.props.block.name.startsWith( 'woocommerce/' ) &&
typeof blockType.attributes !== 'undefined' &&
typeof blockType.defaults !== 'undefined'
) {
attributes = Object.assign(
{},
this.props.attributes || {}
);
Object.keys( blockType.attributes ).map( ( key ) => {
if (
typeof attributes[ key ] === 'undefined' &&
typeof blockType.defaults[ key ] !== 'undefined'
) {
attributes[ key ] = blockType.defaults[ key ];
}
return key;
} );
}
return attributes;
}
render() {
return (
<BlockListBlock
{ ...this.props }
attributes={ this.getAttributesWithDefaults() }
/>
);
}
}
return WrappedComponent;
},
'withDefaultAttributes'
);
/**
* Hook into `editor.BlockListBlock` to set default attributes (if blocks
* define them separately) when a block is inserted.
*
* This is a workaround for Gutenberg which does not save "default" attributes
* to the post, which means if defaults change, all existing blocks change too.
*
* See https://github.com/WordPress/gutenberg/issues/7342
*
* To use this, the block name needs a `woocommerce/` prefix, and as well
* as defining `attributes` during block registration, you must also declare an
* array called `defaults`. Defaults should be omitted from `attributes`.
*/
addFilter(
'editor.BlockListBlock',
'woocommerce-blocks/block-list-block',
withDefaultAttributes
);
exclude-draft-status-from-analytics.js 0000644 00000002104 15155105053 0014075 0 ustar 00 /**
* External dependencies
*/
import { addFilter } from '@wordpress/hooks';
addFilter(
'woocommerce_admin_analytics_settings',
'woocommerce-blocks/exclude-draft-status-from-analytics',
( settings ) => {
const removeCheckoutDraft = ( optionsGroup ) => {
if ( optionsGroup.key === 'customStatuses' ) {
return {
...optionsGroup,
options: optionsGroup.options.filter(
( option ) => option.value !== 'checkout-draft'
),
};
}
return optionsGroup;
};
const actionableStatusesOptions =
settings.woocommerce_actionable_order_statuses.options.map(
removeCheckoutDraft
);
const excludedStatusesOptions =
settings.woocommerce_excluded_report_order_statuses.options.map(
removeCheckoutDraft
);
return {
...settings,
woocommerce_actionable_order_statuses: {
...settings.woocommerce_actionable_order_statuses,
options: actionableStatusesOptions,
},
woocommerce_excluded_report_order_statuses: {
...settings.woocommerce_excluded_report_order_statuses,
options: excludedStatusesOptions,
},
};
}
);
get-block-attributes.js 0000644 00000002744 15155105053 0011144 0 ustar 00 /**
* External dependencies
*/
import { addFilter } from '@wordpress/hooks';
/**
* Adjust attributes on load to set defaults so default attributes get saved.
*
* @param {Object} blockAttributes Original block attributes.
* @param {Object} blockType Block type settings.
*
* @return {Object} Filtered block attributes.
*/
const setBlockAttributeDefaults = ( blockAttributes, blockType ) => {
if ( blockType.name.startsWith( 'woocommerce/' ) ) {
Object.keys( blockType.attributes ).map( ( key ) => {
if (
typeof blockAttributes[ key ] === 'undefined' &&
typeof blockType.defaults !== 'undefined' &&
typeof blockType.defaults[ key ] !== 'undefined'
) {
blockAttributes[ key ] = blockType.defaults[ key ];
}
return key;
} );
}
return blockAttributes;
};
/**
* Hook into `blocks.getBlockAttributes` to set default attributes (if blocks
* define them separately) when a block is loaded.
*
* This is a workaround for Gutenberg which does not save "default" attributes
* to the post, which means if defaults change, all existing blocks change too.
*
* See https://github.com/WordPress/gutenberg/issues/7342
*
* To use this, the block name needs a `woocommerce/` prefix, and as well
* as defining `attributes` during block registration, you must also declare an
* array called `defaults`. Defaults should be omitted from `attributes`.
*/
addFilter(
'blocks.getBlockAttributes',
'woocommerce-blocks/get-block-attributes',
setBlockAttributeDefaults
);