HEX
Server: LiteSpeed
System: Linux s166.bitcommand.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: h340499 (1922)
PHP: 8.2.16
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/h340499/public_html/wp-content/plugins/learnpress/inc/Widgets/LPWidgetBase.php
<?php

namespace LearnPress\Widgets;

use LearnPress\MetaBox\LPMetaBoxField;
use WP_Widget;

/**
 * Class AbstractWidget
 *
 * @package LearnPress\Widgets
 * @since 4.2.3.2
 * @version 1.0.0
 */
class LPWidgetBase extends WP_Widget {
	protected $prefix                = 'learnpress_';
	protected $lp_widget_id          = '';
	protected $lp_widget_name        = '';
	protected $lp_widget_description = '';
	protected $lp_widget_class       = '';
	protected $lp_widget_options     = [];
	protected $lp_widget_setting     = [];

	public function __construct() {
		$id_base         = $this->prefix . $this->lp_widget_id;
		$name            = $this->lp_widget_name;
		$widget_options  = array_merge(
			[
				'description'                 => $this->lp_widget_description,
				'classname'                   => $this->lp_widget_class,
				'customize_selective_refresh' => true,
			],
			$this->lp_widget_options
		);
		$control_options = $this->control_options;
		parent::__construct( $id_base, $name, $widget_options, $control_options );
	}

	public function form( $instance ) {
		if ( empty( $this->lp_widget_setting ) ) {
			echo '<p>' . esc_html__( 'There are no options for this widget.', 'learnpress' ) . '</p>';
			return;
		}

		foreach ( $this->lp_widget_setting as $key => $setting ) {
			$extra            = $setting;
			$extra['value']   = $instance[ $key ] ?? '';
			$extra['default'] = $setting['std'] ?? '';
			$extra['id']      = $this->get_field_id( $key );

			if ( isset( $setting['type'] ) && LPMetaBoxField::CHECKBOX === $setting['type'] ) {
				$html_wrapper = [
					'<p style="display:flex;flex-direction:row-reverse;justify-content:left;align-items:center">' => '</p>',
					'<label for="' . $extra['id'] . '">' . ( $setting['label'] ?? '' ) . '</label>' => '',
				];
			} else {
				$html_wrapper = [
					'<p style="display:flex;flex-direction:column">' => '</p>',
					'<label for="' . $extra['id'] . '">' . ( $setting['label'] ?? '' ) . '</label>' => '',
				];
			}

			LPMetaBoxField::render( $setting['type'], $this->get_field_name( $key ), $extra, $html_wrapper );
		}
	}
}