settings = $settings; } public function register() : void { add_action( 'admin_menu', [$this, 'addPage'] ); add_action( 'admin_init', [$this, 'registerSettings'] ); add_action( 'admin_post_featherdash_import', [$this, 'importSettings'] ); add_action( 'admin_post_featherdash_reset', [$this, 'resetSettings'] ); add_action( 'admin_post_featherdash_review', [$this, 'review'] ); add_filter( 'script_loader_tag', [$this, 'moduleTag'], 10, 3 ); add_filter( 'plugin_action_links_' . plugin_basename( FEATHERDASH_FILE ), [$this, 'actionLinks'] ); } public function addPage() : void { $hook = add_options_page( __( 'FeatherDash', 'featherdash' ), __( 'FeatherDash', 'featherdash' ), 'manage_options', 'featherdash', [$this, 'render'] ); if ( is_string( $hook ) ) { add_action( 'load-' . $hook, [$this, 'onLoad'] ); } } public function onLoad() : void { // When FeatherDash was first used, for the review request. add_option( self::INSTALLED_OPTION, time(), '', false ); add_filter( 'admin_body_class', [$this, 'bodyClass'] ); add_action( 'admin_enqueue_scripts', [$this, 'enqueue'] ); add_action( 'admin_notices', [$this, 'maybeShowImportError'] ); } public function registerSettings() : void { register_setting( 'featherdash', Settings::OPTION, [ 'type' => 'array', 'sanitize_callback' => [Settings::class, 'sanitize'], 'default' => [], ] ); } public function bodyClass( string $classes ) : string { return $classes . ' fd-settings'; } public function enqueue() : void { // Media library modal for image fields. wp_enqueue_media(); if ( file_exists( FEATHERDASH_DIR . 'dist/settings.css' ) ) { wp_enqueue_style( 'featherdash-settings', FEATHERDASH_URL . 'dist/settings.css', [], $this->version( 'dist/settings.css' ) ); } if ( file_exists( FEATHERDASH_DIR . 'dist/settings.js' ) ) { wp_enqueue_script( 'featherdash-settings', FEATHERDASH_URL . 'dist/settings.js', [], $this->version( 'dist/settings.js' ), [ 'in_footer' => true, 'strategy' => 'defer', ] ); } } /** * @param string $tag * @param string $handle * @param string $src */ public function moduleTag( $tag, $handle, $src ) : string { if ( $handle !== 'featherdash-settings' && $handle !== 'featherdash-menu-builder' ) { return $tag; } $tag = preg_replace( '/\\stype=([\'"])[^\'"]*\\1/', '', $tag ) ?? $tag; return str_replace( '