-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathcheck.js
51 lines (42 loc) · 997 Bytes
/
check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* External dependencies
*/
import { connect } from 'react-redux';
import { get } from 'lodash';
/**
* WordPress dependencies
*/
import { withAPIData } from '@wordpress/components';
import { compose } from '@wordpress/element';
/**
* Internal dependencies
*/
import { getCurrentPostType } from '../../selectors';
export function PageAttributesCheck( { postType, children } ) {
const supportsPageAttributes = get( postType.data, [
'supports',
'page-attributes',
], false );
// Only render fields if post type supports page attributes
if ( ! supportsPageAttributes ) {
return null;
}
return children;
}
const applyConnect = connect(
( state ) => {
return {
postTypeSlug: getCurrentPostType( state ),
};
}
);
const applyWithAPIData = withAPIData( ( props ) => {
const { postTypeSlug } = props;
return {
postType: `/wp/v2/types/${ postTypeSlug }?context=edit`,
};
} );
export default compose( [
applyConnect,
applyWithAPIData,
] )( PageAttributesCheck );