post_type, array_keys( Config::getSupportedPostTypes() ) ) ) {
update_post_meta( $postID, self::UNDER_RESTRICTION_META_KEY, isset( $_POST[ self::UNDER_RESTRICTION_META_KEY ] ) ? 'yes' : 'no' );
update_post_meta( $postID, self::UNDER_RESTRICTION_EXCEPT_META_KEY, isset( $_POST[ self::UNDER_RESTRICTION_EXCEPT_META_KEY ] ) ? 'yes' : 'no' );
}
}, 10, 2 );
add_action( 'post_submitbox_misc_actions', function () {
global $post;
if ( in_array( $post->post_type, array_keys( Config::getSupportedPostTypes() ) ) ) {
?>
ID ), true ) ?>
name=""
id="">
query_vars['meta_key'] = self::UNDER_RESTRICTION_META_KEY;
$query->query_vars['meta_value'] = 'yes';
}
} );
add_action( 'init', function () {
foreach ( Config::getSupportedPostTypes() as $postType ) {
add_filter( 'manage_' . $postType->name . '_posts_columns', function ( $columns ) {
$columns['age_restriction'] = __( 'Age restriction', 'age-verification-screen-for-woocommerce' );
return $columns;
} );
add_action( 'manage_' . $postType->name . '_posts_custom_column', function ( $column, $post_id ) {
switch ( $column ) {
case 'age_restriction' :
if ( get_post_meta( $post_id, self::UNDER_RESTRICTION_META_KEY, true ) === 'yes' ) {
?>
name, function ( $bulkActions ) {
$bulkActions['restrict_age__action'] = __( 'Restrict Age', 'age-verification-screen-for-woocommerce' );
$bulkActions['unrestrict_age__action'] = __( 'Remove Age Restriction', 'age-verification-screen-for-woocommerce' );
return $bulkActions;
} );
add_filter( 'handle_bulk_actions-edit-' . $postType->name, function ( $redirect, $doaction, $object_ids ) {
$redirect = remove_query_arg( array(
'restrict_age__action',
'unrestrict_age__action'
), $redirect );
if ( $doaction == 'restrict_age__action' ) {
foreach ( $object_ids as $post_id ) {
update_post_meta( $post_id, self::UNDER_RESTRICTION_META_KEY, 'yes' );
}
$this->getContainer()->getAdminNotifier()->flash( __( 'Restriction items have been changed successfully.', 'age-verification-screen-for-woocommerce' ) );
}
if ( $doaction == 'unrestrict_age__action' ) {
foreach ( $object_ids as $post_id ) {
delete_post_meta( $post_id, self::UNDER_RESTRICTION_META_KEY );
}
$this->getContainer()->getAdminNotifier()->flash( __( 'Restriction items have been changed successfully.', 'age-verification-screen-for-woocommerce' ) );
}
return $redirect;
}, 10, 3 );
}
} );
}
}
public static function isUnderRestriction( $postId ) {
// todo hook
return get_post_meta( $postId, self::UNDER_RESTRICTION_META_KEY, true ) === 'yes';
}
}