*/ public $settings_modal_toggles = []; /** @var array */ public $props = []; #[\Override] public function init(): void { $this->name = __( 'Upcoming Events', 'agenticdaisy-calendar' ); $this->icon = ''; $this->settings_modal_toggles = [ 'general' => [ 'toggles' => [ 'main_content' => __( 'Upcoming Events Settings', 'agenticdaisy-calendar' ), ], ], ]; } /** * @return array> */ #[\Override] public function get_fields(): array { return [ 'number_of_events' => [ 'label' => __( 'Number of Events', 'agenticdaisy-calendar' ), 'type' => 'range', 'default' => '5', 'range_settings' => [ 'min' => '1', 'max' => '50', 'step' => '1', ], 'toggle_slug' => 'main_content', ], 'category' => [ 'label' => __( 'Category ID', 'agenticdaisy-calendar' ), 'type' => 'text', 'default' => '', 'description' => __( 'Filter to a specific category ID. Leave empty for all.', 'agenticdaisy-calendar' ), 'toggle_slug' => 'main_content', ], 'date_range' => [ 'label' => __( 'Date Range (days)', 'agenticdaisy-calendar' ), 'type' => 'select', 'default' => '30', 'options' => [ '7' => __( '7 days', 'agenticdaisy-calendar' ), '30' => __( '30 days', 'agenticdaisy-calendar' ), '90' => __( '90 days', 'agenticdaisy-calendar' ), '365' => __( '365 days', 'agenticdaisy-calendar' ), ], 'toggle_slug' => 'main_content', ], 'show_date' => [ 'label' => __( 'Show Date', 'agenticdaisy-calendar' ), 'type' => 'yes_no_button', 'default' => 'on', 'options' => [ 'on' => __( 'Yes', 'agenticdaisy-calendar' ), 'off' => __( 'No', 'agenticdaisy-calendar' ), ], 'toggle_slug' => 'main_content', ], 'show_time' => [ 'label' => __( 'Show Time', 'agenticdaisy-calendar' ), 'type' => 'yes_no_button', 'default' => 'on', 'options' => [ 'on' => __( 'Yes', 'agenticdaisy-calendar' ), 'off' => __( 'No', 'agenticdaisy-calendar' ), ], 'toggle_slug' => 'main_content', ], 'show_location' => [ 'label' => __( 'Show Location', 'agenticdaisy-calendar' ), 'type' => 'yes_no_button', 'default' => 'off', 'options' => [ 'on' => __( 'Yes', 'agenticdaisy-calendar' ), 'off' => __( 'No', 'agenticdaisy-calendar' ), ], 'toggle_slug' => 'main_content', ], 'show_description' => [ 'label' => __( 'Show Description', 'agenticdaisy-calendar' ), 'type' => 'yes_no_button', 'default' => 'off', 'options' => [ 'on' => __( 'Yes', 'agenticdaisy-calendar' ), 'off' => __( 'No', 'agenticdaisy-calendar' ), ], 'toggle_slug' => 'main_content', ], 'layout' => [ 'label' => __( 'Layout', 'agenticdaisy-calendar' ), 'type' => 'select', 'default' => 'list', 'options' => [ 'list' => __( 'List', 'agenticdaisy-calendar' ), 'compact' => __( 'Compact', 'agenticdaisy-calendar' ), ], 'toggle_slug' => 'main_content', ], 'users' => [ 'label' => __( 'Users', 'agenticdaisy-calendar' ), 'type' => 'text', 'default' => '', 'description' => __( 'Comma-separated user logins to filter. Leave empty for all.', 'agenticdaisy-calendar' ), 'toggle_slug' => 'main_content', ], ]; } /** * @param array|string $attrs * @param string|null $content * @param string $render_slug * @return string */ #[\Override] public function render( $attrs, $content, $render_slug ): string { $raw_num = $this->props['number_of_events'] ?? 0; $raw_category = $this->props['category'] ?? ''; $raw_range = $this->props['date_range'] ?? ''; $raw_layout = $this->props['layout'] ?? ''; $raw_users = $this->props['users'] ?? ''; $num_events = is_numeric( $raw_num ) && (int) $raw_num > 0 ? absint( (int) $raw_num ) : 5; $category = is_string( $raw_category ) && $raw_category !== '' ? sanitize_text_field( $raw_category ) : ''; $date_range = is_string( $raw_range ) && $raw_range !== '' ? sanitize_text_field( $raw_range ) : '30'; $show_date = ( $this->props['show_date'] ?? 'on' ) === 'on' ? 'true' : 'false'; $show_time = ( $this->props['show_time'] ?? 'on' ) === 'on' ? 'true' : 'false'; $show_location = ( $this->props['show_location'] ?? 'off' ) === 'on' ? 'true' : 'false'; $show_description = ( $this->props['show_description'] ?? 'off' ) === 'on' ? 'true' : 'false'; $layout = is_string( $raw_layout ) && $raw_layout !== '' ? sanitize_text_field( $raw_layout ) : 'list'; $users = is_string( $raw_users ) && $raw_users !== '' ? sanitize_text_field( $raw_users ) : ''; return sprintf( '
', $num_events, esc_attr( $category ), esc_attr( $date_range ), esc_attr( $show_date ), esc_attr( $show_time ), esc_attr( $show_location ), esc_attr( $show_description ), esc_attr( $layout ), esc_attr( $users ) ); } }