id ) ) { return; } $field = $this->extra; $field['id'] = $this->id; $field['default'] = $this->default; $field['description'] = $this->description; $field['label'] = $this->label; $class = ! empty( $field['class'] ) ? 'class="' . esc_attr( $field['class'] ) . '"' : ''; $style = ! empty( $field['style'] ) ? 'style="' . esc_attr( $field['style'] ) . '"' : ''; $wrapper_class = ! empty( $field['wrapper_class'] ) ? esc_attr( $field['wrapper_class'] ) : ''; $wrapper_attr = $this->extra['wrapper_attr'] ?? []; $name = ! empty( $field['name'] ) ? esc_attr( $field['name'] ) : esc_attr( $field['id'] ); $name = 'name="' . $name . '"'; // Check if meta key exists in database $meta_exists = metadata_exists( 'post', $thepostid, $this->id ); $value_db = $this->meta_value( $thepostid ); // Only use default if meta key doesn't exist in database if ( ! $meta_exists && $field['default'] !== '' ) { $value_db = $field['default']; } $checked = ''; if ( 'yes' === $value_db ) { $checked = 'checked="checked"'; } if ( isset( $field['value'] ) && $field['value'] === 'yes' ) { $checked = 'checked="checked"'; } // Custom attribute handling $custom_attributes = array(); if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { foreach ( $field['custom_attributes'] as $attribute => $custom_attribute ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $custom_attribute ) . '"'; } } $dependency_check = $this->extra['dependency'] ?? []; if ( ! empty( $dependency_check ) ) { if ( $dependency_check['is_disable'] ) { $wrapper_class .= ' lp-option-disabled'; } $wrapper_attr[] = 'data-dependency=' . $dependency_check['name']; } printf( '
', esc_attr( $this->id . '_field ' . $wrapper_class ), implode( ' ', $wrapper_attr ), esc_attr( $this->id ), wp_kses_post( $this->label ) ); echo ' '; if ( ! empty( $field['description'] ) ) { echo '' . wp_kses_post( $field['description'] ) . ''; if ( ! empty( $field['desc_tip'] ) ) { learn_press_quick_tip( $field['desc_tip'] ); } } echo '
'; } public function save( $post_id ) { $value = isset( $_POST[ $this->id ] ) ? 'yes' : 'no'; update_post_meta( $post_id, $this->id, $value ); return $value; } }