'array', 'sanitize_callback' => array( __CLASS__, 'sanitize' ), ) ); } public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Settings', 'launchvik' ) . '' ); return $links; } public static function assets( $hook ) { if ( 'settings_page_' . self::PAGE !== $hook ) { return; } wp_enqueue_media(); wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_style( 'launchvik-admin', LAUNCHVIK_URL . 'assets/admin.css', array(), launchvik_asset_version( 'assets/admin.css' ) ); wp_enqueue_script( 'launchvik-admin', LAUNCHVIK_URL . 'assets/admin.js', array( 'jquery', 'wp-color-picker' ), launchvik_asset_version( 'assets/admin.js' ), true ); wp_localize_script( 'launchvik-admin', 'launchvikAdmin', array( 'useImage' => __( 'Use this image', 'launchvik' ), 'copied' => __( 'Copied!', 'launchvik' ), 'copy' => __( 'Copy', 'launchvik' ), ) ); do_action( 'launchvik_admin_enqueue' ); } /** * Validate everything posted from the settings form. */ public static function sanitize( $in ) { $d = launchvik_defaults(); $in = is_array( $in ) ? $in : array(); $out = array(); $out['mode'] = in_array( $in['mode'] ?? '', array( 'off', 'coming_soon', 'maintenance' ), true ) ? $in['mode'] : 'off'; $roles = array_keys( wp_roles()->roles ); $posted_roles = isset( $in['bypass_roles'] ) && is_array( $in['bypass_roles'] ) ? array_map( 'sanitize_key', $in['bypass_roles'] ) : array(); $out['bypass_roles'] = array_values( array_intersect( $posted_roles, $roles ) ); $out['headline'] = sanitize_text_field( $in['headline'] ?? '' ); $out['message'] = wp_kses_post( $in['message'] ?? '' ); $out['logo_url'] = esc_url_raw( $in['logo_url'] ?? '' ); $out['bg_image'] = esc_url_raw( $in['bg_image'] ?? '' ); $out['bg_overlay'] = min( 90, max( 0, absint( $in['bg_overlay'] ?? $d['bg_overlay'] ) ) ); foreach ( array( 'bg_color', 'text_color', 'accent_color' ) as $key ) { $color = sanitize_hex_color( $in[ $key ] ?? '' ); $out[ $key ] = $color ? $color : $d[ $key ]; } $launch = sanitize_text_field( $in['launch_date'] ?? '' ); $out['launch_date'] = preg_match( '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/', $launch ) ? $launch : ''; $out['auto_launch'] = empty( $in['auto_launch'] ) ? 0 : 1; $out['launch_email'] = empty( $in['launch_email'] ) ? 0 : 1; if ( $out['auto_launch'] && 'off' !== $out['mode'] ) { $launch_ts = launchvik_launch_timestamp( $out ); if ( ! $launch_ts ) { $out['auto_launch'] = 0; add_settings_error( LAUNCHVIK_OPTION, 'launchvik_no_date', __( 'Automatic launch needs a launch date, so it was left off.', 'launchvik' ), 'error' ); } elseif ( $launch_ts <= time() ) { $out['auto_launch'] = 0; add_settings_error( LAUNCHVIK_OPTION, 'launchvik_past_date', __( 'The launch date has already passed, so automatic launch was left off. Pick a future date.', 'launchvik' ), 'warning' ); } } $out['show_countdown'] = empty( $in['show_countdown'] ) ? 0 : 1; $out['show_login_link'] = empty( $in['show_login_link'] ) ? 0 : 1; $out['block_rest'] = empty( $in['block_rest'] ) ? 0 : 1; $out['retry_after_hours'] = min( 168, max( 1, absint( $in['retry_after_hours'] ?? 1 ) ) ); $paths = array(); foreach ( explode( "\n", sanitize_textarea_field( $in['excluded_paths'] ?? '' ) ) as $line ) { $line = trim( $line ); if ( '' !== $line && '/' === $line[0] ) { $paths[] = $line; } } $out['excluded_paths'] = implode( "\n", array_unique( $paths ) ); // Add-ons (LaunchVik Pro) validate their own fields here. return apply_filters( 'launchvik_sanitize_settings', $out, $in ); } /* ---------- Preview link actions ---------- */ /** * Stops the request unless the user can manage options. */ public static function require_manager() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do that.', 'launchvik' ), 403 ); } } /** * Capability check plus nonce check, for form handlers. */ public static function guard( $action ) { self::require_manager(); check_admin_referer( $action ); } public static function back( $notice ) { wp_safe_redirect( add_query_arg( array( 'page' => self::PAGE, 'launchvik_notice' => $notice, ), admin_url( 'options-general.php' ) ) ); exit; } public static function create_link() { self::require_manager(); check_admin_referer( 'launchvik_create_link' ); $links = launchvik_get_links(); if ( count( $links ) >= 100 ) { self::back( 'limit' ); } $label = sanitize_text_field( wp_unslash( $_POST['label'] ?? '' ) ); $days = min( 365, absint( $_POST['days'] ?? 7 ) ); $id = strtolower( wp_generate_password( 12, false ) ); $links[ $id ] = array( 'label' => '' !== $label ? $label : __( 'Client preview', 'launchvik' ), 'token' => wp_generate_password( 32, false ), 'created' => time(), 'expires' => $days ? time() + $days * DAY_IN_SECONDS : 0, 'views' => 0, 'last_used' => 0, ); update_option( LAUNCHVIK_LINKS_OPTION, $links ); self::back( 'created' ); } public static function revoke_link() { self::require_manager(); check_admin_referer( 'launchvik_revoke_link' ); $id = sanitize_key( wp_unslash( $_POST['link_id'] ?? '' ) ); $links = launchvik_get_links(); if ( isset( $links[ $id ] ) ) { unset( $links[ $id ] ); update_option( LAUNCHVIK_LINKS_OPTION, $links ); } self::back( 'revoked' ); } /* ---------- Screen ---------- */ private static function notice() { // Read-only: picks which fixed message to show after a redirect from our own handlers, which check nonces. $key = isset( $_GET['launchvik_notice'] ) ? sanitize_key( wp_unslash( $_GET['launchvik_notice'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $messages = array( 'created' => array( 'success', __( 'Preview link created. Copy it and send it to your client.', 'launchvik' ) ), 'revoked' => array( 'success', __( 'Preview link turned off. Anyone using it now sees the holding page.', 'launchvik' ) ), 'limit' => array( 'error', __( 'You have 100 links. Turn some off before making more.', 'launchvik' ) ), ); $messages = apply_filters( 'launchvik_admin_notices', $messages ); if ( isset( $messages[ $key ] ) ) { printf( '

%2$s

', esc_attr( $messages[ $key ][0] ), esc_html( $messages[ $key ][1] ) ); } } /** * "Your site went live" notice, shown on every admin screen until dismissed. */ public static function launched_notice() { $info = get_option( 'launchvik_auto_launched' ); if ( ! is_array( $info ) || ! current_user_can( 'manage_options' ) ) { return; } $dismiss = wp_nonce_url( admin_url( 'admin-post.php?action=launchvik_dismiss_launched' ), 'launchvik_dismiss_launched' ); printf( '

๐Ÿš€ %1$s %3$s ยท %5$s

', esc_html( sprintf( /* translators: %s: date and time */ __( 'LaunchVik: your site went live automatically on %s.', 'launchvik' ), self::format_time( $info['time'] ?? 0 ) ) ), esc_url( home_url( '/' ) ), esc_html__( 'View site', 'launchvik' ), esc_url( $dismiss ), esc_html__( 'Dismiss', 'launchvik' ) ); } public static function dismiss_launched() { self::require_manager(); check_admin_referer( 'launchvik_dismiss_launched' ); delete_option( 'launchvik_auto_launched' ); wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url() ); exit; } public static function format_time( $ts ) { return $ts ? wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), (int) $ts ) : 'โ€”'; } public static function render() { if ( ! current_user_can( 'manage_options' ) ) { return; } $s = launchvik_get_settings(); $name = LAUNCHVIK_OPTION; $links = launchvik_get_links(); ?>


$link ) : $valid = launchvik_link_is_valid( $link ); ?>