array( ethebo__( 'General' ), 'dashicons-admin-site-alt3' ),
'bookings' => array( ethebo__( 'Bookings' ), 'dashicons-calendar-alt' ),
'emails' => array( ethebo__( 'Emails' ), 'dashicons-email-alt' ),
'sync' => array( ethebo__( 'Sync' ), 'dashicons-update' ),
'advanced' => array( ethebo__( 'Advanced' ), 'dashicons-admin-tools' ),
'guide' => array( ethebo__( 'Guide' ), 'dashicons-book-alt' ),
);
}
private static function url( $tab ) {
return admin_url( 'edit.php?post_type=' . ETHEBO_Post_Type::PT . '&page=ethebo-settings&tab=' . $tab );
}
/* ---------------------------------------------------------------------
* Saving: only the fields of the submitted tab change.
* ------------------------------------------------------------------ */
public static function sanitize( $in, $section ) {
$all = in_array( $section, array( 'all', 'general' ), true ); // Full array (or the old single form).
$out = array();
if ( $all || 'gen_general' === $section ) {
$lang = sanitize_key( $in['language'] ?? 'en' );
$accent = sanitize_hex_color( $in['accent'] ?? '' );
$out['language'] = ( 'auto' === $lang || isset( ethebo_languages()[ $lang ] ) ) ? $lang : 'en';
$out['currency'] = mb_substr( sanitize_text_field( $in['currency'] ?? '€' ), 0, 8 );
$out['accent'] = $accent ? $accent : '#2563eb';
}
if ( $all || 'gen_bookings' === $section ) {
$email = sanitize_email( $in['admin_email'] ?? '' );
$out['admin_email'] = is_email( $email ) ? $email : get_option( 'admin_email' );
$out['auto_confirm'] = empty( $in['auto_confirm'] ) ? 0 : 1;
$out['guest_emails'] = empty( $in['guest_emails'] ) ? 0 : 1;
}
if ( $all || 'gen_emails' === $section ) {
$from = sanitize_email( $in['mail_from_email'] ?? '' );
$out['mail_from_name'] = mb_substr( sanitize_text_field( $in['mail_from_name'] ?? '' ), 0, 80 );
$out['mail_from_email'] = is_email( $from ) ? $from : '';
}
if ( $all || 'gen_sync' === $section ) {
$intervals = ethebo_sync_intervals();
$out['sync_interval'] = isset( $intervals[ $in['sync_interval'] ?? '' ] ) ? $in['sync_interval'] : 'ethebo_30min';
}
if ( $all || 'gen_advanced' === $section ) {
$out['delete_data'] = empty( $in['delete_data'] ) ? 0 : 1;
}
return (array) apply_filters( 'ethebo_sanitize_settings', $out, $in, $section );
}
/* ---------------------------------------------------------------------
* Page
* ------------------------------------------------------------------ */
public static function page() {
$o = wp_parse_args( (array) get_option( 'ethebo_settings', array() ), ethebo_defaults() );
$tabs = self::tabs();
$tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'general'; // phpcs:ignore WordPress.Security.NonceVerification
$tab = isset( $tabs[ $tab ] ) ? $tab : 'general';
?>
' . esc_html( $title ) . ' ';
if ( $desc ) {
echo '' . esc_html( $desc ) . '
';
}
echo '';
}
private static function tab_general( $o ) {
self::section( ethebo__( 'General' ), ethebo__( 'Language, currency and colour of the booking form.' ) );
?>
ethebo__( 'search bar (e.g. on the home page)' ),
'[ethebo_properties]' => ethebo__( 'list of all properties' ),
'[ethebo_properties search="no" limit="3"]' => ethebo__( 'a few properties without search (e.g. "Featured rooms")' ),
'[ethebo_properties type="apartment"]' => ethebo__( 'only one type' ),
'[ethebo_booking id="123"]' => ethebo__( 'calendar + booking form for one property' ),
);
foreach ( $codes as $code => $desc ) :
?>