diff --git a/components/Accordion.php b/components/Accordion.php index 4ef83a3ac3..ba3116d61a 100644 --- a/components/Accordion.php +++ b/components/Accordion.php @@ -13,9 +13,7 @@ namespace Tutor\Components; -if ( ! defined( 'ABSPATH' ) ) { - exit; -} +defined( 'ABSPATH' ) || exit; /** * Accordion Component Class. @@ -274,4 +272,4 @@ class="tutor-accordion-content" ); } -} \ No newline at end of file +} diff --git a/components/Avatar.php b/components/Avatar.php index 5dc4c25781..2297062262 100644 --- a/components/Avatar.php +++ b/components/Avatar.php @@ -11,7 +11,6 @@ namespace Tutor\Components; use Tutor\Components\Constants\Size; -use Tutor\Components\Contracts\ComponentInterface; defined( 'ABSPATH' ) || exit; @@ -41,7 +40,7 @@ * * @since 4.0.0 */ -class Avatar extends BaseComponent implements ComponentInterface { +class Avatar extends BaseComponent { /** * Avatar size (20, 24, etc). diff --git a/components/BaseComponent.php b/components/BaseComponent.php index dbd2633d51..7cc7f57a0c 100644 --- a/components/BaseComponent.php +++ b/components/BaseComponent.php @@ -13,8 +13,6 @@ namespace Tutor\Components; -use Tutor\Components\Contracts\ComponentInterface; - defined( 'ABSPATH' ) || exit; /** @@ -24,7 +22,7 @@ * * @since 4.0.0 */ -abstract class BaseComponent implements ComponentInterface { +abstract class BaseComponent { /** * Keep the component as string @@ -36,13 +34,13 @@ abstract class BaseComponent implements ComponentInterface { protected $component_string = ''; /** - * Create a new Button instance. + * Create a new component instance. * * @since 4.0.0 * - * @return ComponentInterface + * @return static */ - public static function make(): ComponentInterface { + public static function make() { return new static(); } @@ -56,6 +54,7 @@ public static function make(): ComponentInterface { * ] * * @since 4.0.0 + * * @var array */ protected $attributes = array(); @@ -69,6 +68,7 @@ public static function make(): ComponentInterface { * @since 4.0.0 * * @param array $attrs Key–value pairs of HTML attributes. + * * @return self */ public function attrs( array $attrs ): self { @@ -115,6 +115,18 @@ protected function esc( $value, $esc_fn = 'esc_html' ): string { return call_user_func( $esc_fn, $value ); } + /** + * Get the component output as an HTML string. + * + * Note: Child classes must implement this method and are responsible + * for preparing and properly sanitizing the component’s HTML output. + * + * @since 4.0.0 + * + * @return string The component HTML output. + */ + abstract public function get(): string; + /** * Render the component * @@ -123,7 +135,8 @@ protected function esc( $value, $esc_fn = 'esc_html' ): string { * @return void */ public function render(): void { - echo $this->get(); // phpcs:ignore. + // phpcs:ignore -- Sanitization is performed within each child class’s `get` method implementation. + echo $this->get(); } } diff --git a/components/Contracts/ComponentInterface.php b/components/Contracts/ComponentInterface.php deleted file mode 100644 index 3730f0070f..0000000000 --- a/components/Contracts/ComponentInterface.php +++ /dev/null @@ -1,54 +0,0 @@ -searchPlaceholder = $placeholder; + $this->search_placeholder = $placeholder; } else { $this->placeholder = $placeholder; } @@ -738,7 +738,8 @@ public function loading_message( $loading_message = '' ): self { * 'description' => '', * ) * ); - * ``` + * ```. + * * @return self */ public function options( $options = array() ): self { @@ -768,6 +769,7 @@ public function max_selections( $max_selections = 3 ): self { * @param array $groups the options for input field. * * Example format for $groups: + * * ``` * $groups = array( * array( @@ -788,7 +790,8 @@ public function max_selections( $max_selections = 3 ): self { * ), * ), * ); - * ``` + * ```. + * * @return self */ public function groups( $groups = array() ): self { @@ -1080,7 +1083,7 @@ protected function render_select_input(): string { 'required' => $this->required, 'placeholder' => $this->placeholder, - 'searchPlaceholder' => $this->searchPlaceholder, + 'searchPlaceholder' => $this->search_placeholder, 'emptyMessage' => $this->empty_message, 'loadingMessage' => $this->loading_message, 'maxHeight' => $this->max_height, diff --git a/templates/demo-components/dynamic-components.php b/templates/demo-components/dynamic-components.php index 115bfec31d..d96e3c4551 100644 --- a/templates/demo-components/dynamic-components.php +++ b/templates/demo-components/dynamic-components.php @@ -1,3 +1,15 @@ + + * @link https://themeum.com + * @since 4.0.0 + */ + +defined( 'ABSPATH' ) || exit; +?> @@ -255,7 +267,7 @@ Button::make()->label( 'Another Modal' )->variant( 'destructive' )->attr( 'onclick', 'TutorCore.modal.showModal("another-modal")' )->render(); Button::make()->label( 'Headless Modal' )->variant( 'primary-soft' )->attr( 'onclick', 'TutorCore.modal.showModal("headless-modal")' )->render(); ?> - +