__( 'Entire site', 'age-verification-screen-for-woocommerce' ), 'partial' => __( 'Partial', 'age-verification-screen-for-woocommerce' ) ); $option_value = $this->sanitize( (array) $value['value'] ); ?> $label ): ?>

label; ?>
name ], 'full' ); ?> name="[post_type][name; ?>]" id="[post_type][name; ?>][full]">
name ], 'partial' ); ?> name="[post_type][name; ?>]" id="[post_type][name; ?>][partial]">
getRestrictedPostCount( $type->name ) ); $link = add_query_arg( [ 'age_restricted' => 'yes' ], sprintf( admin_url( 'edit.php?post_type=%s' ), $type->name ) ); ?>
is_premium() ): ?> getPremiumPostTypes() as $type ): ?>
label; ?>

label; ?>
name ], 'full' ); ?> name="[taxonomy][name; ?>]" id="[taxonomy][name; ?>][full]">
name ], 'partial' ); ?> name="[taxonomy][name; ?>]" id="[taxonomy][name; ?>][partial]">
getRestrictedTermsCount( $type->name ) ); $link = add_query_arg( [ 'age_restricted' => 'yes' ], sprintf( admin_url( 'edit-tags.php?taxonomy=%s' ), $type->name ) ); ?>
is_premium() ): ?> getPremiumTaxonomies() as $type ): ?>
label; ?>

__( 'Restricting type', 'age-verification-screen-for-woocommerce' ), 'id' => Settings::SETTINGS_PREFIX . self::FIELD_ID, 'type' => self::FIELD_TYPE, 'default' => $this->getDefaults(), ); } public function getDefaults() { $value['restriction_type'] = 'full'; foreach ( Config::getSupportedPostTypes() as $type ) { $value['post_type'][ $type->name ] = 'full'; } foreach ( Config::getSupportedTaxonomies() as $taxonomy ) { $value['taxonomy'][ $taxonomy->name ] = 'full'; } return $value; } public function sanitize( $value ) { $value['restriction_type'] = in_array( $value['restriction_type'], [ 'full', 'partial' ] ) ? $value['restriction_type'] : 'full'; foreach ( Config::getSupportedPostTypes() as $type ) { $name = $type->name; $value['post_type'][ $name ] = ! empty( $value['post_type'][ $name ] ) && in_array( $value['post_type'][ $name ], [ 'partial', 'full' ] ) ? $value['post_type'][ $name ] : 'none'; } foreach ( Config::getSupportedTaxonomies() as $taxonomy ) { $name = $taxonomy->name; $value['taxonomy'][ $name ] = ! empty( $value['taxonomy'][ $name ] ) && in_array( $value['taxonomy'][ $name ], [ 'partial', 'full' ] ) ? $value['taxonomy'][ $name ] : 'none'; } return $value; } public function getPremiumPostTypes() { $postTypes = get_post_types( [ 'public' => true ], 'objects' ); $supportedPostTypes = Config::getSupportedPostTypes(); $postTypes = array_filter( $postTypes, function ( $name ) use ( $supportedPostTypes ) { return ! array_key_exists( $name, $supportedPostTypes ); }, ARRAY_FILTER_USE_KEY ); return $postTypes; } public function getPremiumTaxonomies() { $postTypes = get_taxonomies( [ 'public' => true, 'show_ui' => true ], 'objects' ); $supportedTaxonomies = Config::getSupportedTaxonomies(); return array_filter( $postTypes, function ( $name ) use ( $supportedTaxonomies ) { return ! array_key_exists( $name, $supportedTaxonomies ); }, ARRAY_FILTER_USE_KEY ); } public function getRestrictedPostCount( $postType ) { $args = array( 'posts_per_page' => - 1, 'post_type' => $postType, 'post_status' => 'any', 'fields' => 'ids', 'no_found_rows' => true, 'meta_key' => PostRestrictionManager::UNDER_RESTRICTION_META_KEY, 'meta_value' => 'yes' ); $posts_query = new \WP_Query( $args ); return $posts_query->post_count; } public function getRestrictedTermsCount( $taxonomy ) { $args = array( 'taxonomy' => $taxonomy, 'meta_key' => TaxonomyRestrictionManager::UNDER_RESTRICTION_META_KEY, 'meta_value' => 'yes', 'fields' => 'count' ); return intval( get_terms( $args ) ); } }