array( 'cod' ), 'lead_minutes' => 20, 'sound' => 'yes', 'refresh' => 15, 'no_notes' => 'yes', 'short_form' => 'yes', 'ip_limit' => 10, 'phone_cap' => 3, ); $saved = get_option( 'sofrah_board_settings', array() ); return wp_parse_args( is_array( $saved ) ? $saved : array(), $defaults ); } /** * One setting. * * @param string $key Setting name. * @return mixed */ function sofrah_board_setting( $key ) { $s = sofrah_board_settings(); return $s[ $key ] ?? null; } /** * Creates the diner status page once, or finds it again if it was trashed and restored. * * @return int Page ID. */ function sofrah_board_ensure_status_page() { $id = (int) get_option( 'sofrah_board_status_page' ); if ( $id && 'page' === get_post_type( $id ) && 'trash' !== get_post_status( $id ) ) { return $id; } $id = wp_insert_post( array( 'post_type' => 'page', 'post_status' => 'publish', 'post_title' => __( 'Order status', 'sofrah-order-board' ), 'post_content' => '[sofrah_order_status]', ) ); if ( $id && ! is_wp_error( $id ) ) { update_option( 'sofrah_board_status_page', (int) $id ); return (int) $id; } return 0; } add_action( 'admin_menu', function () { add_submenu_page( 'woocommerce', __( 'Order board settings', 'sofrah-order-board' ), __( 'Order board settings', 'sofrah-order-board' ), 'manage_woocommerce', 'sob-settings', 'sofrah_board_settings_page' ); }, 60 ); /** * The settings screen. */ function sofrah_board_settings_page() { if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } $notice = ''; if ( isset( $_POST['sofrah_board_save'] ) && check_admin_referer( 'sofrah_board_settings' ) ) { $methods = array_map( 'sanitize_key', (array) wp_unslash( $_POST['sofrah_board_methods'] ?? array() ) ); update_option( 'sofrah_board_settings', array( 'methods' => array_values( array_filter( $methods ) ), 'lead_minutes' => max( 1, min( 240, absint( $_POST['sofrah_board_lead_minutes'] ?? 20 ) ) ), 'sound' => empty( $_POST['sofrah_board_sound'] ) ? 'no' : 'yes', 'refresh' => max( 5, min( 120, absint( $_POST['sofrah_board_refresh'] ?? 15 ) ) ), 'no_notes' => empty( $_POST['sofrah_board_no_notes'] ) ? 'no' : 'yes', 'short_form' => empty( $_POST['sofrah_board_short_form'] ) ? 'no' : 'yes', 'ip_limit' => min( 1000, absint( $_POST['sofrah_board_ip_limit'] ?? 10 ) ), 'phone_cap' => min( 100, absint( $_POST['sofrah_board_phone_cap'] ?? 3 ) ), ) ); $notice = __( 'Settings saved.', 'sofrah-order-board' ); } $notice = sofrah_board_save_venue_settings() ?: $notice; $s = sofrah_board_settings(); $gateways = function_exists( 'WC' ) ? WC()->payment_gateways()->payment_gateways() : array(); ?>