id ) { return; } $frontend_url_setting = faustwp_get_setting( 'frontend_uri' ); if ( empty( $frontend_url_setting ) ) { ?>

', '' ); ?>

'align-middle', 'label_for' => 'frontend_uri', ) ); add_settings_field( 'secret_key', __( 'Secret Key', 'faustwp' ), __NAMESPACE__ . '\\display_secret_key_field', 'faustwp-settings', 'settings_section', array( 'class' => 'align-middle', 'label_for' => 'secret_key', ) ); add_settings_field( 'menu_locations', __( 'Menu Locations', 'faustwp' ), __NAMESPACE__ . '\\display_menu_locations_field', 'faustwp-settings', 'settings_section', array( 'class' => 'align-middle', 'label_for' => 'menu_locations', ) ); add_settings_field( 'enable_disable', __( 'Features', 'faustwp' ), __NAMESPACE__ . '\\display_enable_disable_fields', 'faustwp-settings', 'settings_section' ); } add_filter( 'sanitize_option_faustwp_settings', __NAMESPACE__ . '\\sanitize_faustwp_settings', 10, 2 ); /** * Validates and sanitizes Faust settings. * * The plugin settings page will display any relevant errors when * rejecting invalid settings values. Updates to Faust settings that * are not initiated from the plugin settings page will not return or * display errors, but will still reject invalid values. * * Once settings are validated, the sanitized values are returned. * * @param array $settings Faust settings array to validate and sanitize. * @param string $option WP option name where settings are saved. * @return array Sanitized settings. */ function sanitize_faustwp_settings( $settings, $option ) { $errors = null; $protocols = array( 'http', 'https' ); foreach ( $settings as $name => $value ) { switch ( $name ) { case 'frontend_uri': if ( '' === $value || preg_match( '#http(s?)://(.+)#i', $value ) ) { $settings[ $name ] = esc_url_raw( $value, $protocols ); } else { $errors[ $name ] = __( 'The Front-end site URL you entered did not appear to be a valid URL. Please enter a valid URL.', 'faustwp' ); $settings[ $name ] = faustwp_get_setting( $name ); } break; case 'secret_key': if ( ! wp_is_uuid( $value, 4 ) ) { $errors[ $name ] = __( 'The secret key you entered did not appear to be a valid UUID.', 'faustwp' ); $settings[ $name ] = get_secret_key(); } break; case 'menu_locations': $settings[ $name ] = sanitize_text_field( $value ); break; case 'enable_redirects': case 'enable_rewrites': case 'disable_theme': case 'enable_image_source': if ( $value ) { $settings[ $name ] = '1'; } else { unset( $settings[ $name ] ); } break; default: // Remove any settings we don't expect. unset( $settings[ $name ] ); } } if ( null !== $errors && is_array( $errors ) ) { foreach ( $errors as $name => $error ) { add_settings_error( $option, "faustwp_invalid_{$name}", $error ); } } return $settings; } add_action( 'load-settings_page_faustwp-settings', __NAMESPACE__ . '\\handle_regenerate_secret_key', 5 ); /** * Callback for WordPress 'load-{$page_hook}' action. * * Nonce set in WPE\FaustWP\Settings\display_secret_key_field(). * * Regenerate the secret key. * * @return void */ function handle_regenerate_secret_key() { $screen = get_current_screen(); if ( 'settings_page_faustwp-settings' !== $screen->id ) { return; } if ( empty( $_GET['regenerate_nonce'] ) ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } check_admin_referer( 'regenerate_secret', 'regenerate_nonce' ); faustwp_update_setting( 'secret_key', wp_generate_uuid4() ); wp_safe_redirect( admin_url( '/options-general.php?page=faustwp-settings' ) ); exit; } /** * Callback for add_submenu_page() function. * * Display the settings page. * * @return void */ function display_settings_page() { require FAUSTWP_DIR . '/includes/settings/views/headless-settings.php'; } /** * Callback for WordPress add_settings_field() method parameter. * * Display the "Menu Locations" text field. * * @return void */ function display_menu_locations_field() { $menu_locations = faustwp_get_setting( 'menu_locations', 'Primary, Footer' ); ?>

headless post previews.', 'faustwp' ) ), 'https://faustjs.org/docs/next/guides/post-page-previews' ); ?>

features.', 'faustwp' ) ), 'https://faustjs.org/docs/faustwp/settings' ); ?>




array_key_exists( 'wp-graphql/wp-graphql.php', get_plugins() ), 'icons' => array( 'checkSmall' => get_icon( 'check-small' ), ), 'strings' => array( 'default' => esc_html__( 'Install and Activate', 'faustwp' ), 'installing' => esc_html__( 'Installing…', 'faustwp' ), 'active' => esc_html__( 'WPGraphQL is active', 'faustwp' ), 'failed' => esc_html__( 'Installation failed', 'faustwp' ), ), ); wp_localize_script( 'faustwp-wpgraphql-install', 'faustwp', $faustwp ); } } add_filter( 'plugin_action_links_faustwp/faustwp.php', __NAMESPACE__ . '\\add_action_link_settings' ); /** * Adds a link to the Settings page on the Installed Plugins page. * * @param array $links The array of plugin action links. */ function add_action_link_settings( $links ) { $url = add_query_arg( 'page', 'faustwp-settings', admin_url( 'options-general.php' ) ); return array_merge( array( '' . esc_html__( 'Settings', 'faustwp' ) . '', ), $links ); } add_filter( 'faustwp_get_setting', __NAMESPACE__ . '\\trim_frontend_uri_trailing_slash', 10, 2 ); /** * Ensure that this plugin's frontend_uri setting does not have a trailing slash. * * @param mixed $value The setting value. * @param string $name The setting name. * * @return string */ function trim_frontend_uri_trailing_slash( $value, $name ) { if ( 'frontend_uri' !== $name ) { return $value; } return untrailingslashit( $value ); }