__( '23h Features', '23h-product-features' ), 'target' => 'h23pf_product_data', 'class' => array( 'h23pf_tab' ), 'priority' => 75, ); return $tabs; } public static function panel() { global $post; $pid = $post->ID; $selected = array_map( 'intval', (array) get_post_meta( $pid, '_h23pf_forms', true ) ); $exclude = 'yes' === get_post_meta( $pid, '_h23pf_exclude_global', true ); $forms = get_posts( array( 'post_type' => H23PF_Forms::CPT, 'post_status' => array( 'publish', 'draft' ), 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC', ) ); $cats = wc_get_product_term_ids( $pid, 'product_cat' ); // Forms applied automatically (all products / categories / product list). $auto = array(); foreach ( H23PF_Forms::published() as $f ) { if ( $f['all'] || in_array( $pid, $f['prods'], true ) || array_intersect( $cats, $f['cats'] ) ) { $auto[] = $f['title']; } } // General features that apply to this product. $general = array(); foreach ( H23PF_Features::enabled_items( H23PF_Settings::get( 'features' ) ) as $it ) { if ( empty( $it['cats'] ) || array_intersect( $cats, $it['cats'] ) ) { $general[] = wp_trim_words( wp_strip_all_tags( $it['text'] ), 6 ); } } ?> get_id() ) ) { return; } $forms = isset( $_POST['h23pf_forms'] ) ? array_values( array_filter( array_map( 'absint', (array) wp_unslash( $_POST['h23pf_forms'] ) ) ) ) : array(); $product->update_meta_data( '_h23pf_forms', $forms ); $product->update_meta_data( '_h23pf_exclude_global', empty( $_POST['_h23pf_exclude_global'] ) ? 'no' : 'yes' ); foreach ( array( '_h23pf_min_qty', '_h23pf_step', '_h23pf_max_qty' ) as $key ) { $v = isset( $_POST[ $key ] ) ? trim( sanitize_text_field( wp_unslash( $_POST[ $key ] ) ) ) : ''; $product->update_meta_data( $key, '' === $v ? '' : absint( $v ) ); } $product->update_meta_data( '_h23pf_qty_cumulative', empty( $_POST['_h23pf_qty_cumulative'] ) ? 'no' : 'yes' ); $product->update_meta_data( '_h23pf_hide_features', empty( $_POST['_h23pf_hide_features'] ) ? 'no' : 'yes' ); $order = isset( $_POST['_h23pf_features_order'] ) ? sanitize_key( wp_unslash( $_POST['_h23pf_features_order'] ) ) : 'after'; $product->update_meta_data( '_h23pf_features_order', 'before' === $order ? 'before' : 'after' ); // Each row is sanitized key by key in sanitize_features(). $rows = isset( $_POST['h23pf_pfeatures'] ) && is_array( $_POST['h23pf_pfeatures'] ) ? wp_unslash( $_POST['h23pf_pfeatures'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $own = H23PF_Settings::sanitize_features( $rows, false ); if ( $own ) { $product->update_meta_data( '_h23pf_features', $own ); } else { $product->delete_meta_data( '_h23pf_features' ); } } /* -------- Categories -------- */ public static function cat_add_fields() { ?>

term_id, '_h23pf_min_qty', true ); $step = get_term_meta( $term->term_id, '_h23pf_step', true ); $max = get_term_meta( $term->term_id, '_h23pf_max_qty', true ); ?>

'_h23pf_min_qty', 'h23pf_cat_step' => '_h23pf_step', 'h23pf_cat_max' => '_h23pf_max_qty', ); foreach ( $map as $post_key => $meta_key ) { if ( ! isset( $_POST[ $post_key ] ) ) { continue; } $v = trim( sanitize_text_field( wp_unslash( $_POST[ $post_key ] ) ) ); if ( '' === $v ) { delete_term_meta( $term_id, $meta_key ); } else { update_term_meta( $term_id, $meta_key, absint( $v ) ); } } } }