api_token = 'ZqXNQfXBhn364vbBBPki6iKB'; add_action( 'woocommerce_before_add_to_cart_form', array($this, 'vgh_display_booking_dates'), 5 ); } public function wp_rest_allow_all_cors() { remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' ); add_filter( 'rest_pre_serve_request', function( $value ) { header( 'Access-Control-Allow-Origin: *' ); header( 'Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE' ); header( 'Access-Control-Allow-Credentials: true' ); return $value; }); } public function vgh_register_app_routes(){ register_rest_route( 'app/v1', '/boot', array( 'methods' => 'POST', 'callback' => array( $this, 'route_get_boot' ) ) ); register_rest_route( 'app/v1', '/codes', array( 'methods' => 'GET', 'callback' => array( $this, 'route_get_codes' ) ) ); register_rest_route( 'app/v1', '/setwifi', array( 'methods' => 'GET', 'callback' => array( $this, 'set_wifi_code' ) ) ); register_rest_route( 'app/v1', '/pois', array( 'methods' => 'POST', 'callback' => array( $this, 'route_get_offers' ) ) ); register_rest_route( 'app/v1', '/orderableitems', array( 'methods' => 'GET', 'callback' => array( $this, 'route_get_orderable_items' ) ) ); register_rest_route( 'app/v1', '/orders', array( 'methods' => 'GET', 'callback' => array( $this, 'route_get_pending_orders' ) ) ); register_rest_route( 'app/v1', '/infotext', array( 'methods' => 'GET', 'callback' => array( $this, 'route_get_infotext' ) ) ); register_rest_route( 'app/v1', '/infotext', array( 'methods' => 'POST', 'callback' => array( $this, 'route_set_infotext' ) ) ); register_rest_route( 'app/v1', '/guestcomment', array( 'methods' => 'POST', 'callback' => array( $this, 'route_set_guest_comment' ) ) ); register_rest_route( 'app/v1', '/order', array( 'methods' => 'POST', 'callback' => array( $this, 'route_create_order' ) ) ); register_rest_route( 'app/v1', '/update_order', array( 'methods' => 'POST', 'callback' => array( $this, 'route_update_order' ) ) ); register_rest_route( 'app/v1', '/listing', array( 'methods' => 'POST', 'callback' => array( $this, 'route_get_berths' ) ) ); register_rest_route( 'app/v1', '/create_coupon', array( 'methods' => 'POST', 'callback' => array( $this, 'route_create_discount_code' ) ) ); register_rest_route( 'app/v1', '/toggle_berth_type', array( 'methods' => 'POST', 'callback' => array( $this, 'route_toggle_berth_type' ) ) ); } public function add_cors_http_header(){ header("Access-Control-Allow-Origin: *"); } function vgh_customer_app_install() { global $wpdb; global $vgh_customer_app_db_version; $vgh_customer_app_db_version = '1.1'; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); $charset_collate = $wpdb->get_charset_collate(); $table_name = $wpdb->prefix . 'vgh_checkins'; $default_datetime = date('m/d/Y h:i:s a', time()); $sql = "CREATE TABLE $table_name ( id MEDIUMINT(9) NOT NULL AUTO_INCREMENT, berth_post_id MEDIUMINT(9) NOT NULL, booking_order_id MEDIUMINT(9) NOT NULL, token TINYTEXT NOT NULL, timestamp DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id) ) $charset_collate;"; $result = dbDelta( $sql ); add_option( 'vgh_customer_app_db_version', $vgh_customer_app_db_version ); return; } public function vgh_display_booking_dates() { $display = true; if ( isset( $_GET['start_date'] ) ) { $checkin_date = $_GET['start_date']; } else { $display = false; } if ( isset( $_GET['end_date'] ) ) { $checkout_date = $_GET['end_date']; } else { $display = false; } $display_wish_notice = true; if ( isset( $_GET['on-location'] ) ) { $display_wish_notice = false; } if ( $display === true ) { echo '

'; if ( $display_wish_notice ) { // echo 'Vi kommer i den mån det går placera er enligt önskemål
'; } echo 'Incheck: '. $checkin_date .' kl. 12:00
'; echo 'Utcheck: '. $checkout_date .' kl. 11:30

'; } } public function get_checkin_from_token($token){ global $wpdb; $rows = $wpdb->get_results( 'SELECT * FROM `' . $wpdb->prefix . 'vgh_checkins' . '` WHERE `token` = "' . $token . '";' ); if ( sizeof( $rows ) > 0 ) { return $rows[0]; } else { return false; } } public function create_token_from_booking_order_id($booking_order_id){ $length = 18; $token = bin2hex(random_bytes($length)) . ( $booking_order_id + 9 ) . bin2hex(random_bytes($length)); return $token; } public function do_checkin( $booking_order_id, $berth_post_id ){ global $wpdb; $rows = $wpdb->get_results( 'SELECT * FROM `' . $wpdb->prefix . 'vgh_checkins' . '` WHERE `berth_post_id` = ' . $berth_post_id . ' AND `booking_order_id` = "' . $booking_order_id . '";' ); if ( sizeof( $rows ) == 0 ) { $length = 18; $token = bin2hex(random_bytes($length)) . ( $booking_order_id + 9 ) . bin2hex(random_bytes($length)); $result = $wpdb->insert( $wpdb->prefix . 'vgh_checkins', array( 'berth_post_id' => $berth_post_id, 'booking_order_id' => $booking_order_id, 'token' => $token, 'timestamp' => date('Y-m-d H:i:s') ) ); if ( $result !== false ) { $result = $token; } } else { $result = $rows[0]->token; } return $result; } /** Customer app **/ public function route_get_boot(){ $_POST = json_decode( file_get_contents("php://input"), true ); if ( !isset( $_POST['token'] ) ) { return ['error' => 'missing_token', 'message' => 'Token is missing in request']; } $checkin = $this->get_checkin_from_token( $_POST['token'] ); $berth_post_id = $checkin->berth_post_id; $berth_name = get_the_title( $berth_post_id ); $codes = $this->get_codes(); $boot_data = [ 'berth_name' => $berth_name, 'codes' => $codes ]; return $boot_data; } public function route_create_order(){ $_POST = json_decode( file_get_contents("php://input"), true ); $result = $_POST; global $woocommerce; $token = $_POST['token']; $order_products = $_POST['order']; $checkin = $this->get_checkin_from_token( $token ); if ( $checkin === false ) { return ['error' => 'no_checkin_found', 'message' => 'No active checkin found' ]; } $booking_order = new WC_Order( $checkin->booking_order_id ); $address = array( 'first_name' => $booking_order->get_billing_first_name(), 'last_name' => $booking_order->get_billing_last_name(), 'company' => $booking_order->get_billing_company(), 'email' => $booking_order->get_billing_email(), 'phone' => $booking_order->get_billing_phone(), 'address_1' => $booking_order->get_billing_address_1(), 'address_2' => $booking_order->get_billing_address_2(), 'city' => $booking_order->get_billing_city(), 'state' => $booking_order->get_billing_state(), 'postcode' => $booking_order->get_billing_postcode(), 'country' => $booking_order->get_billing_country() ); $order = wc_create_order(); foreach ($order_products as $order_product) { $product = wc_get_product( $order_product['product_id'] ); $amount = $order_product['amount']; $order->add_product( $product, $amount); } $order->set_address( $address, 'billing' ); $order->set_created_via('customerapp'); $order->set_shipping_first_name( $booking_order->get_billing_first_name() ); $order->set_shipping_last_name( $booking_order->get_billing_last_name() ); $order->set_shipping_address_1( 'Plats: ' . get_the_title( $checkin->berth_post_id ) . ' | Tid: ' . $_POST['deliverytime'] ); $order->set_shipping_address_2( $booking_order->get_customer_note() ); $order->calculate_totals(); $order->update_status("Completed", 'App order', TRUE); $this->send_notification( 'Leverera order '. $order->get_order_number() .' till bokning #' . $checkin->booking_order_id . ' som ligger på ' . get_the_title( $checkin->berth_post_id ) . '. Önskad leveranstid: ' . $_POST['deliverytime'], 'https://bryggan.vvgh.se?deeplink=orders' ); return $result; } public function route_get_codes(){ $codes = $this->get_codes(); return $codes; } public function route_get_offers( $data = false ){ $_POST = json_decode( file_get_contents("php://input"), true ); $high_prio_args = array( 'numberposts' => 3, 'post_type' => 'poi', 'orderby' => 'rand', 'meta_query' => array( array( 'key' => 'priority', 'value' => '1', 'compare' => '=', ) ) ); $medium_prio_args = array( 'numberposts' => 2, 'post_type' => 'poi', 'orderby' => 'rand', 'meta_query' => array( array( 'key' => 'priority', 'value' => '2', 'compare' => '=', ) ) ); $low_prio_args = array( 'numberposts' => 1, 'post_type' => 'poi', 'orderby' => 'rand', 'meta_query' => array( array( 'key' => 'priority', 'value' => '3', 'compare' => '=', ) ) ); // if ( isset( $_POST['category'] ) ) { // $args['tax_query'] = [ // array( // 'taxonomy' => 'poi_categories', // 'field' => 'slug', // 'terms' => $_POST['category'], // ), // ]; // } $high_prio_pois = get_posts( $high_prio_args ); $medium_prio_pois = get_posts( $medium_prio_args ); $low_prio_pois = get_posts( $low_prio_args ); // $poi_posts = []; // $i = 1; // foreach ($low_prio_pois as $poi) { // $poi_posts[] = $poi; // break; // } // $i = 1; // foreach ($medium_prio_pois as $poi) { // $poi_posts[] = $poi; // $i++; // if ( $i === 2 ) { // break; // } // } // $i = 1; // foreach ($high_prio_pois as $poi) { // $poi_posts[] = $poi; // $i++; // if ( $i === 3 ) { // break; // } // } $pois = []; foreach ($high_prio_pois as $poi_post) { $image_array = get_field('image', $poi_post->ID); if ( isset( $image_array['sizes']['shop_single'] ) ) { $image = $image_array['sizes']['medium']; } else { $image = $image_array['url']; } $poi = [ 'label' => get_field('label', $poi_post->ID), 'body' => get_field('body', $poi_post->ID), 'link' => get_field('poi_url', $poi_post->ID), 'image' => $image, 'priority' => get_field('priority', $poi_post->ID), ]; array_push( $pois, $poi ); } foreach ($medium_prio_pois as $poi_post) { $image_array = get_field('image', $poi_post->ID); if ( isset( $image_array['sizes']['shop_single'] ) ) { $image = $image_array['sizes']['medium']; } else { $image = $image_array['url']; } $poi = [ 'label' => get_field('label', $poi_post->ID), 'body' => get_field('body', $poi_post->ID), 'link' => get_field('poi_url', $poi_post->ID), 'image' => $image, 'priority' => get_field('priority', $poi_post->ID), ]; array_push( $pois, $poi ); } foreach ($low_prio_pois as $poi_post) { $image_array = get_field('image', $poi_post->ID); if ( isset( $image_array['sizes']['shop_single'] ) ) { $image = $image_array['sizes']['medium']; } else { $image = $image_array['url']; } $poi = [ 'label' => get_field('label', $poi_post->ID), 'body' => get_field('body', $poi_post->ID), 'link' => get_field('poi_url', $poi_post->ID), 'image' => $image, 'priority' => get_field('priority', $poi_post->ID), ]; array_push( $pois, $poi ); } return $pois; } public function route_get_orderable_items(){ $args = array( 'numberposts' => -1, 'post_type' => 'product', 'orderby' => 'post_title', 'order' => 'ASC', 'tax_query' => [ array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => 'kundapp', ), ] ); $products = get_posts($args); $orderableitems = []; foreach ( $products as $key => $product ) { $_product = wc_get_product( $product->ID ); $orderableitem = [ 'id' => $product->ID, 'name' => $product->post_title, 'price' => $_product->get_price() . 'kr', 'confirmation' => '', 'description' => $_product->post->post_excerpt, 'amount' => 0, ]; array_push( $orderableitems, $orderableitem ); } return $orderableitems; } /** Admin app **/ public function route_get_berths(){ $_POST = json_decode( file_get_contents("php://input"), true ); if ( $_POST['token'] !== $this->api_token ) { return 'Invalid token.'; exit(); } if ( isset( $_POST['date'] ) ) { $date = $_POST['date']; } else { $date = false; } date_default_timezone_set ( 'Europe/Stockholm' ); if ( $date == '' ) { $date = false; } if ( $date === false ) { $now_datetimestring = date( 'Y-m-d' ); } else { $now_datetimestring = $date; } $book_start = $now_datetimestring . ' 12:00:01'; $dateTimeStart = new DateTime($book_start); $book_end = $now_datetimestring . ' 23:59:59'; $dateTimeEnd = new DateTime($book_end); if ( $dateTimeStart > $dateTimeEnd ) { $dates_valid = 0; } $bookings = WC_Bookings_Controller::get_bookings_in_date_range( $dateTimeStart->getTimestamp(), $dateTimeEnd->getTimestamp(), '', true ); $sorted_bookings = []; foreach ($bookings as $booking) { $order = wc_get_order( $booking->get_order_id() ); $booking_order_id = $booking->get_order_id(); $boat_make = get_post_meta( $booking_order_id, 'boat_make', true); $boat_model = get_post_meta( $booking_order_id, 'boat_model', true); $boat_name = get_post_meta( $booking_order_id, 'boat_name', true); $berthspot = get_post_meta( $booking_order_id, 'berthspot', true); // Fetch additional metadata from order if (!is_bool( $order )) { $items = $order->get_items(); } else { continue; } $meta_string = ''; foreach($items as $item) { $item_data = $item->get_data(); if (isset( $item_data['meta_data'] )) { if( is_array( $item_data['meta_data'] ) ){ foreach ($item_data['meta_data'] as $key => $meta_data) { if ( $key > 0 ) { $meta_string .= '
'; } $meta_string .= $meta_data->value; } } } } $customer_first_name = $order->get_billing_first_name(); $customer_last_name = $order->get_billing_last_name(); $customer_phone = $order->get_billing_phone(); $booking_start = $booking->get_start_date(); $booking_start_date = explode(', ', $booking_start)[0]; if ( $booking_start_date == date('Y-m-d')) { $arrival_today = true; } else { $arrival_today = false; } $booking_end = $booking->get_end_date(); $booking_end_date = explode(', ', $booking_end)[0]; if ( $booking_end_date == date('Y-m-d')) { $departure_today = true; } else { $departure_today = false; } // Put together gathered data $output_data = [ 'booking' => $booking, 'order_id' => $booking_order_id, 'customer_name' => $customer_first_name . ' ' . $customer_last_name, 'customer_phone' => $customer_phone, 'start_date' => $booking_start_date, 'end_date' => $booking_end_date, 'arrival_today' => $arrival_today, 'departure_today' => $departure_today, 'metadata' => $meta_string, 'boat' => [ 'make' => $boat_make, 'model' => $boat_model, 'name' => $boat_name, 'berthspot' => $berthspot, ] ]; if ( $order != false ) { $items = $order->get_items(); foreach ( $items as $item ) { $product = get_post( $item->get_product_id() ); $output_data['name'] = $product->post_title; $slug = $product->post_name; if ( !isset( $sorted_bookings[$slug] ) ) { $sorted_bookings[$slug] = []; } array_push( $sorted_bookings[$slug], $output_data ); } } } ksort($sorted_bookings); $args = array ( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => 'okategoriserad' ), ), ); $bookings_query = new WP_Query($args); $berth_posts = $bookings_query->posts; $booked_count = sizeof( $sorted_bookings ); $total_count = sizeof( $berth_posts ); $available_count = $total_count - $booked_count; $all_berths = []; foreach ($berth_posts as $berth) { $berth_post_length = floatval( get_field('length', $berth->ID) ); $berth_post_width = floatval( get_field('width', $berth->ID) ); $berth_post_depth = floatval( get_field('depth', $berth->ID) ); $priority_berth = get_field('priority_berth', $berth->ID); $port = get_field('port', $berth->ID); $berth_type = get_field('berth_type', $berth->ID); $berth_type_labels = [ 'dropin' => 'Dropin', 'bookable' => 'Bokbar' ]; $all_berths[ $berth->post_name ] = [ 'id' => $berth->ID, 'name' => $berth->post_title, 'slug' => $berth->post_name, 'length' => $berth_post_length, 'width' => $berth_post_width, 'depth' => $berth_post_depth, 'checked_in' => false, 'priority_berth' => $priority_berth, 'port' => $port, 'type' => $berth_type_labels[ $berth_type ] ]; if ( isset( $sorted_bookings[ $berth->post_name ] ) ) { $filterstring = ''; $all_berths[ $berth->post_name ]['checked_in'] = true; if ( !isset( $all_berths[ $berth->post_name ]['guests'] ) ) { $all_berths[ $berth->post_name ]['guests'] = []; } foreach ($sorted_bookings[ $berth->post_name ] as $sorted_booking) { $guest_comment = get_post_meta($sorted_booking['order_id'], 'guest_comment', true); if ( $guest_comment == '' ) { $guest_comment = ''; } $all_berths[ $berth->post_name ]['guests'][] = [ 'order_id' => $sorted_booking['order_id'], 'boat' => $sorted_booking['boat'], 'customer_name' => $sorted_booking['customer_name'], 'customer_phone' => $sorted_booking['customer_phone'], 'start_date' => $sorted_booking['start_date'], 'end_date' => $sorted_booking['end_date'], 'arrival_today' => $sorted_booking['arrival_today'], 'departure_today' => $sorted_booking['departure_today'], 'metadata' => $sorted_booking['metadata'], 'comment' => $guest_comment ]; $filterstring = $filterstring . ' ' . $sorted_booking['order_id']; $filterstring = $filterstring . ' ' . $sorted_booking['boat']['model'] . ' ' . $sorted_booking['boat']['make'] . ' ' . $sorted_booking['boat']['name']; $all_berths[ $berth->post_name ]['filterstring'] = $filterstring; } } } ksort($all_berths); return [ 'berths_available_count' => $available_count, 'berths_booked_count' => $booked_count, 'all_berths' => $all_berths, 'booked_berths' => $sorted_bookings]; } public function route_set_guest_comment(){ $_POST = json_decode( file_get_contents("php://input"), true ); if ( $_POST['token'] !== $this->api_token ) { return 'Invalid token.'; exit(); } $order_id = $_POST['order_id']; $comment = $_POST['comment']; update_post_meta( $order_id, 'guest_comment', $comment ); } public function route_get_infotext(){ $info_text = get_field('vgh_info_text', 'options'); return ['infotext' => $info_text, 'infotext_html' => nl2br($info_text)]; } public function route_set_infotext(){ $_POST = json_decode( file_get_contents("php://input"), true ); if ( $_POST['token'] !== $this->api_token ) { return 'Invalid token.'; exit(); } $info_text = $_POST['infotext']; update_field('vgh_info_text', $info_text, 'options'); return ['infotext' => $info_text, 'infotext_html' => nl2br($info_text)]; } public function route_get_pending_orders(){ if ( $_GET['token'] !== $this->api_token ) { return 'Invalid token.'; exit(); } $args = array( 'post_type' => 'shop_order', 'post_status' => 'wc-pending', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'AND', array( 'key' => '_created_via', 'value' => 'customerapp', 'compare' => '=', ) ) ); $orders_query = new WP_Query( $args ); $orders = $orders_query->posts; $pending_orders = []; foreach ($orders as $order) { $order = wc_get_order( $order->ID ); $order_items = $order->get_items(); $order_total = $order->get_total(); $items = []; foreach( $order_items as $product ) { $items[] = [ 'product' => $product['name'], 'quantity' => $product['qty'], 'price' => $product['total'] ]; } $shipping_first_name = $order->get_shipping_first_name(); $shipping_last_name = $order->get_shipping_last_name(); $shipping_address_1 = $order->get_shipping_address_1(); $shipping_address_2 = $order->get_shipping_address_2(); $boat_model = get_post_meta($order_id, 'boat_model', true); $boat_name = get_post_meta($order_id, 'boat_name', true); if ( $boat_model == '' && $boat_name == '' ) { $boat = ''; } else { $boat = $boat_model . ' (' . $boat_name . ')'; } $pending_order = [ 'id' => $order->get_order_number(), 'items' => $items, 'delivery' => [ 'name' => $shipping_first_name . ' ' . $shipping_last_name, 'address' => $shipping_address_1, 'meta' => $shipping_address_2, 'boat' => $boat ], 'price' => $order_total, ]; $pending_orders[] = $pending_order; } return ['pending_order_count' => sizeof($pending_orders), 'pending_orders' => $pending_orders]; } public function route_update_order(){ $_POST = json_decode( file_get_contents("php://input"), true ); if ( !isset( $_POST['token'] ) ) { return ['error' => 'missing_token', 'message' => 'Token is missing in request']; } if ( !isset( $_POST['order_id'] ) ) { return ['error', 'missing order ID', 'message' => 'Order ID missing']; } if ( !isset( $_POST['status'] ) ) { return ['error', 'missing status', 'message' => 'Status missing']; } $order_id = $_POST['order_id']; $status = $_POST['status']; $order = wc_get_order( $order_id ); if ( $status === 'paid' ) { $order->update_status('completed'); } if ( $status === 'cancelled' ) { $order->update_status('wc-cancelled'); } return []; } public function route_create_discount_code(){ $_POST = json_decode( file_get_contents("php://input"), true ); if ( !isset( $_POST['token'] ) ) { return ['error' => 'missing_token', 'message' => 'Token is missing in request']; } if ( !isset( $_POST['code'] ) ) { return ['error', 'missing code', 'message' => 'Code missing']; } if ( !isset( $_POST['amount'] ) ) { return ['error', 'missing amount', 'message' => 'Value missing']; } $code = $_POST['code']; $amount = $_POST['amount']; $coupon_code = $code; $amount = $amount; $discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product $coupon = array( 'post_title' => $coupon_code, 'post_content' => '', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'shop_coupon' ); $new_coupon_id = wp_insert_post( $coupon ); $today = date("Y-m-d"); $valid_until = date( "Y-m-d", strtotime( "$today +7 day" ) ); update_post_meta( $new_coupon_id, 'discount_type', $discount_type ); update_post_meta( $new_coupon_id, 'coupon_amount', $amount ); update_post_meta( $new_coupon_id, 'individual_use', 'no' ); update_post_meta( $new_coupon_id, 'product_ids', '' ); update_post_meta( $new_coupon_id, 'exclude_product_ids', '' ); update_post_meta( $new_coupon_id, 'usage_limit', 1 ); update_post_meta( $new_coupon_id, 'date_expires', $valid_until); update_post_meta( $new_coupon_id, 'apply_before_tax', 'yes' ); update_post_meta( $new_coupon_id, 'free_shipping', 'no' ); } public function route_toggle_berth_type(){ $_POST = json_decode( file_get_contents("php://input"), true ); if ( !isset( $_POST['token'] ) ) { return ['error' => 'missing_token', 'message' => 'Token is missing in request']; } if ( !isset( $_POST['berth_id'] ) ) { return ['error' => 'missing_id', 'message' => 'Berth ID is missing in request']; } $berth_id = $_POST['berth_id']; $current_berth_type = get_field('berth_type', $berth_id); if ( $current_berth_type == 'bookable' ) { update_field('berth_type', 'dropin', $berth_id); } if ( $current_berth_type == 'dropin' ) { update_field('berth_type', 'bookable', $berth_id); } $response = $this->route_get_berths(); return $response; } /** General functions **/ public function get_codes(){ $wifi_code = get_field('currentwificode', 'options'); $codes_repeater = get_field('codes', 'options'); $today = date('Ymd'); $codes = ['status' => 'missing']; if ( is_array( $codes_repeater ) ) { foreach ($codes_repeater as $date_code) { $date_from = $date_code['date_valid_from']; $date_to = $date_code['date_valid_to']; if ( $today >= $date_from && $today <= $date_to ) { $codes = [ 'status' => 'ok', 'wifi' => [ 'code' => $wifi_code ], 'wc' => [ 'code' => $date_code['code_wc'] ] ]; } } } return $codes; } public function vgh_register_app_options_page(){ $args = array( 'page_title' => 'Inställningar för kundapp', 'menu_title' => 'Kundapp', 'menu_slug' => '', 'capability' => 'edit_posts', 'position' => false, 'parent_slug' => '', 'icon_url' => false, /* (boolean) If set to true, this options page will redirect to the first child page (if a child page exists). If set to false, this parent page will appear alongside any child pages. Defaults to true */ 'redirect' => true, /* (int|string) The '$post_id' to save/load data to/from. Can be set to a numeric post ID (123), or a string ('user_2'). Defaults to 'options'. Added in v5.2.7 */ 'post_id' => 'options', /* (boolean) Whether to load the option (values saved from this options page) when WordPress starts up. Defaults to false. Added in v5.2.8. */ 'autoload' => false, /* (string) The update button text. Added in v5.3.7. */ 'update_button' => 'Spara', /* (string) The message shown above the form on submit. Added in v5.6.0. */ 'updated_message' => 'Inställningar sparade' ); acf_add_options_page( $args ); } public function vgh_register_app_custom_fields(){ include_once('customer-app-cf.php'); } public function send_notification($message, $url = ''){ curl_setopt_array($ch = curl_init(), array( CURLOPT_URL => "https://api.pushover.net/1/messages.json", CURLOPT_POSTFIELDS => array( // "token" => "ajPoKRQChLLnm8fWJmZqRKWU4JicqU", // dev "token" => "a314icx2qvzonn1ycxe3e1cyimwxrp", // prod // "user" => "uPR6iAt75fdKaGsMVvYCLKbtRuMeDj", // dev "user" => "u77vfvjvn26rqtsgatv5hhjyevd2k7", // prod "message" => $message, "url" => $url ), CURLOPT_SAFE_UPLOAD => true, CURLOPT_RETURNTRANSFER => 1 )); curl_exec($ch); curl_close($ch); } public function set_wifi_code(){ if ( isset( $_GET['token'] ) ) { if ( $_GET['token'] !== 'vghtoken' ) { exit(); } } $code = mt_rand(10000000, 99999999); $controlleruser = get_field('controlleruser', 'options'); $controllerpassword = get_field('controllerpassword', 'options'); $controllerurl = get_field('controllerurl', 'options'); $controllerversion = get_field('controllerversion', 'options'); $debug = false; $site_id = get_field('site_id', 'options'); $wlan_id = get_field('wlan_id', 'options'); $unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); $set_debug_mode = $unifi_connection->set_debug($debug); $loginresults = $unifi_connection->login(); $results = $unifi_connection->set_wlansettings($wlan_id, $code); if ( $results === true ) { update_field('currentwificode', $code, 'options'); } return $results; } } new VghCustomerApp();
Fatal error: Array and string offset access syntax with curly braces is no longer supported in /home/vasterv2/vasterviksgasthamn.se/webroot/wp-content/plugins/woocommerce/includes/wc-formatting-functions.php on line 791