| @@ -57,9 +57,9 @@ | ||
| 57 | 57 | return faustwp_get_setting( 'secret_key', '' ); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | - * Get a FaustWP setting by name. | |
| 61 | + * Get a Faust setting by name. | |
| 62 | 62 | * |
| 63 | 63 | * @param string $name The setting name. |
| 64 | 64 | * @param mixed $default Optional setting value. Default false. |
| 65 | 65 | * |
| @@ -83,9 +83,9 @@ | ||
| 83 | 83 | return apply_filters( 'faustwp_get_setting', $value, $name, $default ); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | - * Update a FaustWP setting value. | |
| 87 | + * Update a Faust setting value. | |
| 88 | 88 | * |
| 89 | 89 | * @link https://developer.wordpress.org/reference/functions/update_option/ |
| 90 | 90 | * |
| 91 | 91 | * @param string $name The setting name. |
| @@ -100,9 +100,9 @@ | ||
| 100 | 100 | update_option( 'faustwp_settings', $settings ); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | - * Get all FaustWP settings. | |
| 104 | + * Get all Faust settings. | |
| 105 | 105 | * |
| 106 | 106 | * @return array An array of settings. |
| 107 | 107 | */ |
| 108 | 108 | function faustwp_get_settings() { |
| @@ -113,5 +113,47 @@ | ||
| 113 | 113 | * |
| 114 | 114 | * @param array $settings Array of plugin settings. |
| 115 | 115 | */ |
| 116 | 116 | return apply_filters( 'faustwp_get_settings', $settings ); |
| 117 | +} | |
| 118 | + | |
| 119 | +/** | |
| 120 | + * Applies the default settings to a site if settings don't already exist. | |
| 121 | + * | |
| 122 | + * @return void | |
| 123 | + */ | |
| 124 | +function maybe_set_default_settings() { | |
| 125 | + $secret_key = get_secret_key(); | |
| 126 | + $settings = faustwp_get_settings(); | |
| 127 | + | |
| 128 | + if ( empty( $settings ) ) { | |
| 129 | + faustwp_update_setting( 'disable_theme', '0' ); | |
| 130 | + faustwp_update_setting( 'enable_rewrites', '1' ); | |
| 131 | + faustwp_update_setting( 'enable_redirects', '1' ); | |
| 132 | + | |
| 133 | + // Force WP to regenerate rewrite rules without calling flush_rewrite_rules which breaks | |
| 134 | + // things when used inside of `switch_to_blog()`. | |
| 135 | + if ( is_multisite() ) { | |
| 136 | + delete_option( 'rewrite_rules' ); | |
| 137 | + } | |
| 138 | + } | |
| 139 | + | |
| 140 | + if ( ! $secret_key ) { | |
| 141 | + faustwp_update_setting( 'secret_key', wp_generate_uuid4() ); | |
| 142 | + } | |
| 143 | +} | |
| 144 | + | |
| 145 | +/** | |
| 146 | + * Get the contents of an SVG icon. | |
| 147 | + * | |
| 148 | + * @param string $icon Filename of the SVG without the .svg extension. | |
| 149 | + * @return string The SVG icon contents or empty string if the icon file does not exist. | |
| 150 | + */ | |
| 151 | +function get_icon( $icon ) { | |
| 152 | + $path = __DIR__ . '/assets/icons/' . $icon . '.svg'; | |
| 153 | + | |
| 154 | + if ( file_exists( $path ) ) { | |
| 155 | + return file_get_contents( $path ); //phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents | |
| 156 | + } | |
| 157 | + | |
| 158 | + return ''; | |
| 117 | 159 | } |