body {background: unset;} HEAD; } // Inject Sleeky files yourls_add_action( 'html_head', 'sleeky_head_scripts' ); function sleeky_head_scripts() { // This is so the user doesn't have to reload page twice in settings screen if (isset( $_POST['theme_choice'] )) { // User has just changed theme if ($_POST['theme_choice'] == "light") { setTheme("light"); } else { setTheme("dark"); } } else { // User has not just changed theme if (yourls_get_option( 'theme_choice' ) == "light") { setTheme("light"); } else { setTheme("dark"); } } } // Inject Sleeky files function setTheme($theme) { $url = yourls_plugin_url( __DIR__ ); if ($theme == "light") { echo << HEAD; } else if ($theme == "dark") { echo << HEAD; } } // Inject information and options into the frontend yourls_add_action( 'html_head', 'addOptions' ); function addOptions() { $url = yourls_plugin_url( __DIR__ ); echo << HEAD; } // Register our plugin admin page yourls_add_action( 'plugins_loaded', 'sleeky_add_settings' ); function sleeky_add_settings() { yourls_register_plugin_page( 'sleeky_settings', 'Sleeky Settings', 'sleeky_do_settings_page' ); // parameters: page slug, page title, and function that will display the page itself } // Display admin page function sleeky_do_settings_page() { // Check if a form was submitted if( isset( $_POST['theme_choice'] ) ) { // Check nonce yourls_verify_nonce( 'sleeky_settings' ); // Process form sleeky_settings_update(); } // Get value from database $theme_choice = yourls_get_option( 'theme_choice' ); // Create nonce $nonce = yourls_create_nonce( 'sleeky_settings' ); echo <<

Sleeky Settings

HTML; } // Update option in database function sleeky_settings_update() { $in = $_POST['theme_choice']; if( $in ) { // Validate theme_choice. ALWAYS validate and sanitize user input. // Here, we want an integer // $in = intval( $in); if ($in == "light" or $in == "dark") { // Update value in database yourls_update_option( 'theme_choice', $in ); } else { echo "Error"; } } } // Hide admin links for non-authenticated users if (yourls_is_valid_user() != 1) { echo <<ul#admin_menu li:not(.frontend_link) {display: none} HEAD; }