class-ld-settings-fields.php 30.5 KB
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
<?php
/**
 * LearnDash Settings Fields API.
 *
 * @since 3.0.0
 * @package LearnDash\Settings\Fields
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'LearnDash_Settings_Fields' ) ) {

	/**
	 * Class to create the settings field.
	 *
	 * @since 3.0.0
	 */
	class LearnDash_Settings_Fields {

		/**
		 * Array to hold all field type instances.
		 *
		 * @var array
		 */
		protected static $_instances = array(); // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore

		/**
		 * Define the field type 'text', 'select', etc. This is unique.
		 *
		 * @var string
		 */
		protected $field_type = '';

		/**
		 * Public constructor for class
		 *
		 * @since 3.0.0
		 */
		public function __construct() {
		}

		/**
		 * Get field instance by key
		 *
		 * @since 3.0.0
		 *
		 * @param string $field_key Key to unique field instance.
		 *
		 * @return object instance of field if present.
		 */
		final public static function get_field_instance( $field_key = '' ) {
			if ( ! empty( $field_key ) ) {
				if ( isset( self::$_instances[ $field_key ] ) ) {
					return self::$_instances[ $field_key ];
				}
			}

			return null;
		}

		/**
		 * Add field instance by key
		 *
		 * @since 3.0.0
		 *
		 * @param string $field_key Key to unique field instance.
		 *
		 * @return object instance of field if present.
		 */
		final public static function add_field_instance( $field_key = '' ) {
			if ( ! empty( $field_key ) ) {
				if ( ! isset( self::$_instances[ $field_key ] ) ) {
					$section_class                  = get_called_class();
					self::$_instances[ $field_key ] = new $section_class();
				}
				return self::$_instances[ $field_key ];
			}

			return null;
		}

		/**
		 * Utility function so we are not hard coding the create/validate
		 * member functions in various settings files.
		 *
		 * @since 3.0.0
		 *
		 * @return reference to validation function.
		 */
		final public function get_creation_function_ref() {
			return array( $this, 'create_section_field' );
		}

		/**
		 * Utility function so we are not hard coding the create/validate
		 * member functions in various settings files.
		 *
		 * @since 3.0.0
		 *
		 * @return reference to validation function.
		 */
		final public function get_validation_function_ref() {
			return array( $this, 'validate_section_field' );
		}

		/**
		 * Utility function so we are not hard coding the create/validate
		 * member functions in various settings files.
		 *
		 * @since 3.0.0
		 *
		 * @return reference to validation function.
		 */
		final public function get_value_function_ref() {
			return array( $this, 'value_section_field' );
		}

		/**
		 * Show all fields in section.
		 *
		 * @since 3.0.0
		 *
		 * @param array $section_fields Array of fields for section.
		 */
		public static function show_section_fields( $section_fields = array() ) {

			if ( ! empty( $section_fields ) ) {
				$parents_settings = array();
				foreach ( $section_fields as $field_id => $field ) {
					if ( ( isset( $field['args']['parent_setting'] ) ) && ( ! empty( $field['args']['parent_setting'] ) ) ) {
						// if we have a 'parent_setting'. Then try and figure out if it was the same as the last one.
						if ( ( empty( $parents_settings ) ) || ( ! in_array( $field['args']['parent_setting'], $parents_settings, true ) ) ) {
							$parent_setting_slug = $field['args']['parent_setting'];
							if ( ( isset( $section_fields[ $parent_setting_slug ]['args']['child_section_state'] ) ) && ( 'open' === $section_fields[ $parent_setting_slug ]['args']['child_section_state'] ) ) {
								$child_setting_state = 'open';
							} else {
								$child_setting_state = 'closed';
							}
							$parents_settings[] = $field['args']['parent_setting'];

							echo '<div class="ld-settings-sub ld-settings-sub-level-' . count( $parents_settings ) . ' ld-settings-sub-' . esc_attr( $field['args']['parent_setting'] ) . ' ld-settings-sub-state-' . esc_attr( $child_setting_state ) . '" data-parent-field="' . esc_attr( $field['args']['setting_option_key'] ) . '_' . esc_attr( $field['args']['parent_setting'] ) . '_field">';
						} else {
							if ( $parents_settings[ count( $parents_settings ) - 1 ] === $field['args']['parent_setting'] ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf

							} elseif ( in_array( $field['args']['parent_setting'], $parents_settings, true ) ) {
								while ( ! empty( $parents_settings ) ) {
									$p_set = $parents_settings[ count( $parents_settings ) - 1 ];
									if ( $p_set !== $field['args']['parent_setting'] ) {
										echo '</div>';
										unset( $parents_settings[ count( $parents_settings ) - 1 ] );
									} else {
										break;
									}
								}
								if ( empty( $parents_settings ) ) {
									$parents_settings = array();
								} else {
									$parents_settings = array_values( $parents_settings );
								}
							}
						}
					} elseif ( ! empty( $parents_settings ) ) {
						while ( ! empty( $parents_settings ) ) {
							$p_set = $parents_settings[ count( $parents_settings ) - 1 ];
							echo '</div>';
							unset( $parents_settings[ count( $parents_settings ) - 1 ] );
						}
						if ( empty( $parents_settings ) ) {
							$parents_settings = array();
						} else {
							$parents_settings = array_values( $parents_settings );
						}
					}
					self::show_section_field_row( $field );
				}
				if ( ! empty( $parents_settings ) ) {
					while ( ! empty( $parents_settings ) ) {
						$p_set = $parents_settings[ count( $parents_settings ) - 1 ];
						echo '</div>';
						unset( $parents_settings[ count( $parents_settings ) - 1 ] );
					}
					if ( empty( $parents_settings ) ) {
						$parents_settings = array();
					}
				}
			}
		}

		/**
		 * Shows the field row
		 *
		 * @since 3.0.0
		 *
		 * @param array $field Array of field settings.
		 */
		public static function show_section_field_row( $field ) {
			$field_error_class = '';

			if ( ( isset( $field['args']['setting_option_key'] ) ) && ( ! empty( $field['args']['setting_option_key'] ) ) ) {
				$settings_errors = get_settings_errors( $field['args']['setting_option_key'] );
				if ( ! empty( $settings_errors ) ) {
					foreach ( $settings_errors as $settings_error ) {
						if ( ( $settings_error['setting'] == $field['args']['setting_option_key'] ) && ( $settings_error['code'] == $field['args']['name'] ) && ( 'error' == $settings_error['type'] ) ) {
							$field_error_class = 'learndash-settings-field-error';
						}
					}
				}
			}

			$field_class = '';
			if ( ( isset( $field['args']['type'] ) ) && ( ! empty( $field['args']['type'] ) ) ) {
				$field_instance = self::get_field_instance( $field['args']['type'] );
				if ( ( ! $field_instance ) || ( 'LearnDash_Settings_Fields' !== get_parent_class( $field_instance ) ) ) {
					return;
				}
				$field_class = 'sfwd_input_type_' . $field['args']['type'];
			}

			if ( ( isset( $field['args']['desc_before'] ) ) && ( ! empty( $field['args']['desc_before'] ) ) ) {
				echo wp_kses_post( wptexturize( $field['args']['desc_before'] ) );
			}
			if ( ( isset( $field['args']['row_disabled'] ) ) && ( true === $field['args']['row_disabled'] ) ) {
				$field_class .= ' learndash-row-disabled';
			}

			// Adds a required class to the field row container.
			if ( ( isset( $field['args']['required'] ) ) && ( 'required' === $field['args']['required'] ) ) {
				$field_class .= ' learndash-settings-input-required';
			}

			if ( ( isset( $field['args']['type'] ) ) && ( 'hidden' !== $field['args']['type'] ) ) {
				/**
				 * Filters the HTML content to be echoed before outside row settings.
				 *
				 * @param string $output_content Content to be echoed.
				 * @param array  $field_arguments An array of setting field arguments.
				 */
				$output = apply_filters( 'learndash_settings_row_outside_before', '', $field['args'] );
				if ( ! empty( $output ) ) {
					echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML.
				}
				?>
				<div id="<?php echo esc_attr( $field['args']['id'] ); ?>_field" class="sfwd_input <?php echo esc_attr( $field_class ); ?> <?php echo esc_attr( $field_error_class ); ?>">
					<?php
						/**
						 * Filters the HTML content to be echoed before inside row settings.
						 *
						 * @param string $output_content Content to be echoed.
						 * @param array  $field_arguments An array of setting field arguments.
						 */
						$output = apply_filters( 'learndash_settings_row_inside_before', '', $field['args'] );
					if ( ! empty( $output ) ) {
						echo $output;// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML.
					};
					?>
					<?php
					if ( ( isset( $field['args']['row_description_before'] ) ) && ( ! empty( $field['args']['row_description_before'] ) ) ) {
						echo '<span class="sfwd_row_description sfwd_row_description_before">' . esc_html( $field['args']['row_description_before'] ) . '</span>';
					}
					?>
					<?php if ( ( ! isset( $field['args']['label_none'] ) ) || ( true !== $field['args']['label_none'] ) ) { ?>
						<?php
						/**
						 * Filters the HTML content to be echoed before outside row label settings.
						 *
						 * @param string $output_content Content to be echoed.
						 * @param array  $field_arguments An array of setting field arguments.
						 */
						$output = apply_filters( 'learndash_settings_row_label_outside_before', '', $field['args'] );
						if ( ! empty( $output ) ) {
							echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML.
						}
						?>
						<span class="sfwd_option_label
						<?php
						if ( ( isset( $field['args']['label_full'] ) ) && ( true === $field['args']['label_full'] ) ) {
							echo ' sfwd_option_label_full';
						}
						?>
							">
							<?php
							/**
							 * Filters the HTML content to be echoed before inside row label settings.
							 *
							 * @param string $output_content Content to be echoed.
							 * @param array  $field_arguments An array of setting field arguments.
							 */
								$output = apply_filters( 'learndash_settings_row_label_inside_before', '', $field['args'] );
							if ( ! empty( $output ) ) {
								echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML.
							};
							?>
							<a class="sfwd_help_text_link"
								<?php if ( ( isset( $field['args']['help_text'] ) ) && ( ! empty( $field['args']['help_text'] ) ) ) { ?>
									style="cursor:pointer;" title="<?php esc_html_e( 'Click for Help!', 'learndash' ); ?>"
									onclick="toggleVisibility('<?php echo esc_attr( $field['args']['id'] ); ?>_tip');"
								<?php } ?>
								>
								<?php if ( ( isset( $field['args']['help_text'] ) ) && ( ! empty( $field['args']['help_text'] ) ) ) { ?>
									<img alt="" src="<?php echo esc_url( LEARNDASH_LMS_PLUGIN_URL ); ?>assets/images/question.png" />
								<?php } ?>

								<label for="<?php echo esc_attr( $field['args']['label_for'] ); ?>" class="sfwd_label">
								<?php
								if ( ( isset( $field['args']['label'] ) ) && ( ! empty( $field['args']['label'] ) ) ) {
									echo esc_html( $field['args']['label'] );
								}
								if ( isset( $field['args']['required'] ) ) {
									?>
									<span class="learndash_required_field"><abbr title="<?php esc_html_e( 'Required', 'learndash' ); ?>">*</abbr></span>
									<?php
								}
								?>
								</label>
							</a>
							<?php
							if ( ( isset( $field['args']['label_description'] ) ) && ( ! empty( $field['args']['label_description'] ) ) ) {
								?>
								<span class="descripton"><?php echo wp_kses_post( $field['args']['label_description'] ); // cspell:disable-line. ?></span>
								<?php
							}

							if ( ( isset( $field['args']['help_text'] ) ) && ( ! empty( $field['args']['help_text'] ) ) ) {
								if ( ( isset( $field['args']['help_show'] ) ) && ( true === $field['args']['help_show'] ) ) {
									$help_style = ' style="display: block !important;" ';
								} else {
									$help_style = ' style="display: none;" ';
								}
								?>
								<div id="<?php echo esc_attr( $field['args']['id'] ); ?>_tip" class="sfwd_help_text_div" <?php echo $help_style; ?>> <?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $help_style hardcoded above. ?>
									<label class="sfwd_help_text"><?php echo wp_kses_post( $field['args']['help_text'] ); ?></label>
								</div>
								<?php
							}
							?>
							<?php
								/**
								 * Filters the HTML content to be echoed after inside row label settings.
								 *
								 * @param string $output_content Content to be echoed.
								 * @param array  $field_arguments An array of setting field arguments.
								 */
								$output = apply_filters( 'learndash_settings_row_label_inside_after', '', $field['args'] );
							if ( ! empty( $output ) ) {
								echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML.
							};
							?>
						</span>
							<?php
								/**
								 * Filters the HTML content to be echoed after outside row label settings.
								 *
								 * @param string $output_content Content to be echoed.
								 * @param array  $field_arguments An array of setting field arguments.
								 */
								$output = apply_filters( 'learndash_settings_row_label_outside_after', '', $field['args'] );
							if ( ! empty( $output ) ) {
								echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML.
							};
							?>
					<?php } ?>
					<?php
						/**
						 * Filters the HTML content to be echoed before outside row input settings.
						 *
						 * @param string $output_content Content to be echoed.
						 * @param array  $field_arguments An array of setting field arguments.
						 */
						$output = apply_filters( 'learndash_settings_row_input_outside_before', '', $field['args'] );
					if ( ! empty( $output ) ) {
						echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML.
					};
					?>
					<span class="sfwd_option_input
					<?php
					if ( ( isset( $field['args']['input_full'] ) ) && ( true === $field['args']['input_full'] ) ) {
						echo ' sfwd_option_input_full';
					}
					?>
						">
						<?php
							/**
							 * Filters the HTML content to be echoed before outside row label settings.
							 *
							 * @param string $output_content Content to be echoed.
							 * @param array  $field_arguments An array of setting field arguments.
							 */
							$output = apply_filters( 'learndash_settings_row_input_inside_before', '', $field['args'] );
						if ( ! empty( $output ) ) {
							echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML.
						}

						if ( ( ! isset( $field['args']['input_show'] ) ) || ( true === $field['args']['input_show'] ) ) {
							?>
							<div class="sfwd_option_div">
								<?php call_user_func( $field['args']['display_callback'], $field['args'] ); ?>

								<?php
								if ( isset( $field['args']['input_note'] ) && ! empty( $field['args']['input_note'] ) ) {
									?>
									<span class="sfwd_option_input_note"><?php echo wp_kses_post( $field['args']['input_note'] ); ?></span>
									<?php
								}
								?>
							</div>
							<?php
						}
						/**
						 * Filters the HTML content to be echoed after inside row input settings.
						 *
						 * @param string $output_content Content to be echoed.
						 * @param array  $field_arguments An array of setting field arguments.
						 */
						$output = apply_filters( 'learndash_settings_row_input_inside_after', '', $field['args'] );
						if ( ! empty( $output ) ) {
							echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML.
						};
						?>
					</span>
					<?php
						/**
						 * Filters the HTML content to be echoed after outside row input settings.
						 *
						 * @param string $output_content Content to be echoed.
						 * @param array  $field_arguments An array of setting field arguments.
						 */
						$output = apply_filters( 'learndash_settings_row_input_outside_after', '<p class="ld-clear"></p>', $field['args'] );
					if ( ! empty( $output ) ) {
						echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML.
					};
					?>
					<?php
					if ( ( isset( $field['args']['row_description_after'] ) ) && ( ! empty( $field['args']['row_description_after'] ) ) ) {
						echo '<span class="sfwd_row_description sfwd_row_description_after">' . esc_html( $field['args']['row_description_after'] ) . '</span>';
					}
					?>

					<?php
					/**
					 * Filters the HTML content to be echoed after inside row settings.
					 *
					 * @param string $output_content Content to be echoed.
					 * @param array  $field_arguments An array of setting field arguments.
					 */
					$output = apply_filters( 'learndash_settings_row_inside_after', '', $field['args'] );
					if ( ! empty( $output ) ) {
						echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML.
					}
					?>
				</div>
				<?php
				/**
				 * Filters the HTML content to be echoed after outside row settings.
				 *
				 * @param string $output_content Content to be echoed.
				 * @param array  $field_arguments An array of setting field arguments.
				 */
				$output = apply_filters( 'learndash_settings_row_outside_after', '', $field['args'] );
				if ( ! empty( $output ) ) {
					echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML.
				}
			} else {
				if ( ( isset( $field['callback'] ) ) && ( ! empty( $field['callback'] ) ) && ( is_callable( $field['callback'] ) ) ) {
					call_user_func( $field['callback'], $field['args'] );
				}
			}
			if ( ( isset( $field['args']['desc_after'] ) ) && ( ! empty( $field['args']['desc_after'] ) ) ) {
				echo wp_kses_post( wptexturize( $field['args']['desc_after'] ) );
			}
		}

		/**
		 * Skeleton function to create the field output.
		 *
		 * @since 3.0.0
		 *
		 * @param array $field_args main field args array.
		 */
		public function create_section_field( $field_args = array() ) {
		}

		/**
		 * Create the HTML output from the field args 'id' attribute.
		 *
		 * @since 3.4.0.5
		 *
		 * @param array   $field_args main field args array. should contain element for 'attrs'.
		 * @param boolean $wrap Flag to wrap field attribute in normal output or just return value.
		 *
		 * @return string of HTML representation of the attrs array attributes.
		 */
		public function get_field_attribute_id( $field_args = array(), $wrap = true ) {
			$field_attribute = '';

			if ( isset( $field_args['id'] ) ) {
				if ( true === $wrap ) {
					$field_attribute .= ' id="' . $field_args['id'] . '" ';
				} else {
					$field_attribute .= $field_args['id'];
				}
			}

			return $field_attribute;
		}

		/**
		 * Create the HTML output from the field args 'required' attribute.
		 *
		 * @since 3.0.0
		 *
		 * @param array $field_args main field args array. should contain element for 'attrs'.
		 *
		 * @return string of HTML representation of the attrs array attributes.
		 */
		public function get_field_attribute_required( $field_args = array() ) {
			$field_attribute = '';

			if ( isset( $field_args['required'] ) ) {
				$field_attribute .= ' required="' . $field_args['required'] . '" ';
			}

			return $field_attribute;
		}

		/**
		 * Create the HTML output from the field args 'input_label_before' attribute.
		 *
		 * @since 3.3.0
		 *
		 * @param array $field_args main field args array. should contain element for 'attrs'.
		 *
		 * @return string of HTML representation of the attrs array attributes.
		 */
		public function get_field_attribute_label_before( $field_args = array() ) {
			$field_attribute = '';

			if ( ( isset( $field_args['input_label_before'] ) ) && ( ! empty( $field_args['input_label_before'] ) ) ) {
				$field_attribute .= $field_args['input_label_before'];
			}

			return $field_attribute;
		}

		/**
		 * Create the HTML output from the field args 'input_mask_before' attribute.
		 *
		 * @since 3.3.0
		 *
		 * @param array $field_args main field args array.
		 *
		 * @return string of HTML representation of the attrs array attributes.
		 */
		public function get_field_attribute_mask_before( $field_args = array() ) {
			$field_attribute = '';

			if ( ( isset( $field_args['input_mask_before'] ) ) && ( ! empty( $field_args['input_mask_before'] ) ) ) {
				$field_attribute .= ' value-input-mask-before="' . $field_args['input_mask_before'] . '" ';
			}

			return $field_attribute;
		}

		/**
		 * Create the HTML output from the field args 'name' attribute.
		 *
		 * @since 3.0.0
		 *
		 * @param array   $field_args main field args array. should contain element for 'attrs'.
		 * @param boolean $wrap Flag to wrap field attribute in normal output or just return value.
		 *
		 * @return string of HTML representation of the attrs array attributes.
		 */
		public function get_field_attribute_name( $field_args = array(), $wrap = true ) {
			$field_attribute = '';

			if ( isset( $field_args['name'] ) ) {
				$field_multiple = '';
				if ( ( isset( $field_args['multiple'] ) ) && ( true == $field_args['multiple'] ) ) {
					$field_multiple = '[]';
				}

				if ( ! empty( $field_args['setting_option_key'] ) && ( ! isset( $field_args['use_raw_name'] ) || ( isset( $field_args['use_raw_name'] ) && false === $field_args['use_raw_name'] ) ) ) {
					if ( true === $wrap ) {
						if ( ( isset( $field_args['name_wrap'] ) ) && ( true === $field_args['name_wrap'] ) ) {
							$field_attribute .= ' name="' . $field_args['setting_option_key'] . '[' . $field_args['name'] . ']' . $field_multiple . '" ';
						} else {
							$field_attribute .= ' name="' . $field_args['name'] . $field_multiple . '" ';
						}
					} else {
						if ( ( isset( $field_args['name_wrap'] ) ) && ( true === $field_args['name_wrap'] ) ) {
							$field_attribute .= $field_args['setting_option_key'] . '[' . $field_args['name'] . ']';
						} else {
							$field_attribute .= $field_args['name'];
						}
					}
				} else {
					if ( true === $wrap ) {
						$field_attribute .= ' name="' . $field_args['name'] . $field_multiple . '" ';
					} else {
						$field_attribute .= $field_args['name'] . $field_multiple;
					}
				}
			}

			return $field_attribute;
		}

		/**
		 * Create the HTML output from the field args 'placeholder' attribute.
		 *
		 * @since 3.0.0
		 *
		 * @param array $field_args main field args array. should contain element for 'attrs'.
		 *
		 * @return string of HTML representation of the attrs array attributes.
		 */
		public function get_field_attribute_placeholder( $field_args = array() ) {
			$field_attribute = '';

			if ( ( isset( $field_args['placeholder'] ) ) && ( ! empty( $field_args['placeholder'] ) ) ) {
				if ( is_string( $field_args['placeholder'] ) ) {
					$field_attribute .= ' placeholder="' . esc_html( $field_args['placeholder'] ) . '" ';
				} elseif ( is_array( $field_args['placeholder'] ) ) {
					foreach ( $field_args['placeholder'] as $placeholder_key => $placeholder_value ) {
						$field_attribute .= ' placeholder="' . esc_html( $placeholder_value ) . '" ';
						break;
					}
				}
			}

			return $field_attribute;
		}

		/**
		 * Create the HTML output from the field args 'placeholder' attribute.
		 *
		 * @since 3.0.0
		 *
		 * @param array   $field_args main field args array. should contain element for 'attrs'.
		 * @param boolean $wrap Flag to wrap field attribute in normal output or just return value.
		 * @return string of HTML representation of the attrs array attributes.
		 */
		public function get_field_attribute_value( $field_args = array(), $wrap = true ) {
			$field_attribute = '';

			if ( isset( $field_args['id'] ) ) {
				if ( true === $wrap ) {
					$field_attribute .= ' value="' . $field_args['value'] . '" ';
				} else {
					$field_attribute .= $field_args['value'];
				}
			}

			return $field_attribute;
		}

		/**
		 * Create the HTML output from the field args 'legend' attribute.
		 *
		 * @since 3.0.0
		 *
		 * @param array $field_args main field args array. should contain element for 'attrs'.
		 *
		 * @return string of HTML representation of the attrs array attributes.
		 */
		public function get_field_legend( $field_args = array() ) {
			$field_legend = '';

			if ( ( isset( $field_args['label'] ) ) && ( ! empty( $field_args['label'] ) ) ) {
				$field_legend .= '<legend class="screen-reader-text">';
				$field_legend .= '<span>' . $field_args['label'] . '</span>';
				$field_legend .= '</legend>';
			}

			return $field_legend;
		}

		/**
		 * Create the HTML output from the field args 'type' attribute.
		 *
		 * @since 3.0.0
		 *
		 * @param array $field_args main field args array. should contain element for 'attrs'.
		 *
		 * @return string of HTML representation of the attrs array attributes.
		 */
		public function get_field_attribute_type( $field_args = array() ) {
			$field_attribute = '';

			if ( isset( $field_args['type'] ) ) {
				$field_attribute .= ' type="' . $field_args['type'] . '" ';
			}

			return $field_attribute;
		}

		/**
		 * Create the HTML output from the field args 'class' attribute.
		 *
		 * @since 3.0.0
		 *
		 * @param array $field_args main field args array. should contain element for 'attrs'.
		 * @param bool  $wrap       Whether to create a CSS class from the field args.
		 *
		 * @return string of HTML representation of the attrs array attributes.
		 */
		public function get_field_attribute_class( $field_args = array(), $wrap = true ) {
			$field_attribute = '';

			if ( true === $wrap ) {
				$field_attribute .= 'class="';
			}
			$field_attribute .= 'learndash-section-field learndash-section-field-' . $this->field_type;

			if ( ( isset( $field_args['class'] ) ) && ( ! empty( $field_args['class'] ) ) ) {
				$field_attribute .= ' ' . $field_args['class'];
			}
			if ( true === $wrap ) {
				$field_attribute .= '" ';
			}

			return $field_attribute;
		}

		/**
		 * Create the HTML output from the field args 'attrs' attribute.
		 *
		 * @since 3.0.0
		 *
		 * @param array $field_args main field args array. should contain element for 'attrs'.
		 *
		 * @return string of HTML representation of the attrs array attributes.
		 */
		public function get_field_attribute_misc( $field_args = array() ) {
			$field_attribute = '';

			if ( ( isset( $field_args['attrs'] ) ) && ( ! empty( $field_args['attrs'] ) ) ) {
				foreach ( $field_args['attrs'] as $key => $val ) {
					$field_attribute .= ' ' . $key . '="' . $val . '" ';
				}
			}

			return $field_attribute;
		}


		/**
		 * Create the HTML output from the field args 'input_label' attribute.
		 *
		 * @since 3.0.0
		 *
		 * @param array $field_args main field args array. Should contain element for 'input_label'.
		 *
		 * @return string of HTML representation of the attrs array attributes.
		 */
		public function get_field_attribute_input_label( $field_args = array() ) {
			$field_attribute = '';

			if ( ( isset( $field_args['input_label'] ) ) && ( ! empty( $field_args['input_label'] ) ) ) {
				$field_attribute .= ' ' . $field_args['input_label'];
			}

			return $field_attribute;
		}

		/**
		 * Get Field Error Message
		 *
		 * @since 3.0.7
		 *
		 * @param array $field_args Array of field args.
		 */
		public function get_field_error_message( $field_args = array() ) {
			$field_attribute = '';

			if ( ( isset( $field_args['input_error'] ) ) && ( ! empty( $field_args['input_error'] ) ) ) {
				$field_attribute .= '<div class="learndash-section-field-error" style="display:none;">' . $field_args['input_error'] . '</div>';
			}

			return $field_attribute;
		}

		/**
		 * Get Field Attribute Input Description
		 *
		 * @since 3.0.0
		 *
		 * @param array $field_args Array of field args.
		 */
		public function get_field_attribute_input_description( $field_args = array() ) {
			$field_attribute = '';

			if ( ( isset( $field_args['input_description'] ) ) && ( ! empty( $field_args['input_description'] ) ) ) {
				$field_attribute .= '<span class="descripton">' . $field_args['input_description'] . '</span>'; // cspell:disable-line.
			}

			return $field_attribute;
		}

		/**
		 * Get Field Sub-Field Trigger
		 *
		 * @since 3.0.0
		 *
		 * @param array $field_args Array of field args.
		 */
		public function get_field_sub_trigger( $field_args = array() ) {
			$field_attribute = '';

			if ( ( isset( $field_args['name'] ) ) && ( ! empty( $field_args['name'] ) ) ) {
				$field_attribute .= ' data-settings-sub-trigger="ld-settings-sub-' . $field_args['name'] . '" ';
			}

			return $field_attribute;
		}

		/**
		 * Get Field Inner-Field Trigger
		 *
		 * @since 3.0.0
		 *
		 * @param array $field_args Array of field args.
		 */
		public function get_field_inner_trigger( $field_args = array() ) {
			$field_attribute = '';

			if ( ( isset( $field_args['name'] ) ) && ( ! empty( $field_args['name'] ) ) ) {
				$field_attribute .= ' data-settings-inner-trigger="ld-settings-inner-' . $field_args['name'] . '" ';
			}

			return $field_attribute;
		}


		/**
		 * Default validation function. Should be overridden in Field subclass.
		 *
		 * @since 3.0.0
		 *
		 * @param mixed  $val Value to validate.
		 * @param string $key Key of value being validated.
		 * @param array  $args Array of field args.
		 *
		 * @return mixed $val validated value.
		 */
		public function validate_section_field( $val, $key, $args = array() ) {
			if ( ! empty( $val ) ) {
						$val = call_user_func( $args['field']['value_type'], $val );
			}

			return $val;
		}

		/**
		 * Get Settings Field Value.
		 *
		 * @since 3.0.0
		 *
		 * @param mixed  $val       Value to validate.
		 * @param string $key       Key of value being validated.
		 * @param array  $args      Array of field args.
		 * @param array  $post_args Array of post args.
		 *
		 * @return mixed $val validated value.
		 */
		public function value_section_field( $val = '', $key = '', $args = array(), $post_args = array() ) {
			return $val;
		}

		/**
		 * Convert Settings Field value to REST value.
		 *
		 * @since 3.3.0
		 *
		 * @param mixed           $val        Value from REST to be converted to internal value.
		 * @param string          $key        Key field for value.
		 * @param array           $field_args Array of field args.
		 * @param WP_REST_Request $request    Request object.
		 */
		public function field_value_to_rest_value( $val, $key, $field_args, WP_REST_Request $request ) {
			return $val;
		}

		/**
		 * Convert REST submit value to internal Settings Field acceptable value.
		 *
		 * @since 3.3.0
		 *
		 * @param mixed  $val        Value from REST to be converted to internal value.
		 * @param string $key        Key field for value.
		 * @param array  $field_args Array of field args.
		 */
		public function rest_value_to_field_value( $val = '', $key = '', $field_args = array() ) {
			return $val;
		}
	}
}