> */ public static function all(): array { $elements = array( 'booking' => array( 'title' => __( 'Booking form', 'schedulereed' ), 'shortcode' => 'schedulereed', 'icon' => 'eicon-calendar', 'scripts' => array( Widget::HANDLE ), 'elementor' => Elementor\BookingWidget::class, 'divi' => Divi\BookingModule::class, 'fields' => array( 'service' => array( 'label' => __( 'Service', 'schedulereed' ), 'type' => 'select', 'options' => array( '' => __( 'All services', 'schedulereed' ) ) + self::services(), 'default' => '', ), 'layout' => array( 'label' => __( 'Show as', 'schedulereed' ), 'type' => 'select', 'options' => array( 'inline' => __( 'Form on the page', 'schedulereed' ), 'button' => __( 'Button that opens the form', 'schedulereed' ), ), 'default' => 'inline', ), 'button' => array( 'label' => __( 'Button text', 'schedulereed' ), 'type' => 'text', 'default' => '', ), ), ), 'portal' => array( 'title' => __( 'My bookings', 'schedulereed' ), 'shortcode' => 'schedulereed_portal', 'icon' => 'eicon-person', 'scripts' => array( Widget::HANDLE ), 'elementor' => Elementor\PortalWidget::class, 'divi' => Divi\PortalModule::class, 'fields' => array(), ), ); /** * Add page builder elements. * * @param array $elements Elements by key. */ return (array) apply_filters( 'schedulereed_builder_elements', $elements ); } /** * One element. * * @param string $key Key. * @return array|null */ public static function get( string $key ): ?array { return self::all()[ $key ] ?? null; } /** * Render an element through its shortcode. * * @param string $key Key. * @param array $settings Builder settings. */ public static function render( string $key, array $settings ): string { $element = self::get( $key ); if ( null === $element ) { return ''; } $attrs = ''; foreach ( array_keys( $element['fields'] ) as $field ) { $value = (string) ( $settings[ $field ] ?? '' ); if ( '' !== $value ) { $attrs .= sprintf( ' %s="%s"', $field, esc_attr( $value ) ); } } return do_shortcode( '[' . $element['shortcode'] . $attrs . ']' ); } /** * Active services as select options. * * @return array */ private static function services(): array { $out = array(); foreach ( Services::bookables()->all( true ) as $row ) { $out[ (string) $row['id'] ] = (string) $row['name']; } return $out; } }