From 8666f07e743d7dc184841e7746651725a37e5749 Mon Sep 17 00:00:00 2001 From: Nathan Schmidt <91974372+nathan-schmidt-viget@users.noreply.github.com> Date: Wed, 13 Dec 2023 11:17:42 -0700 Subject: [PATCH] [#12] styling header navigation with logout button --- .../goodbids/src/classes/network/Sites.php | 66 +++++++++++++++++++ .../goodbids-nonprofit/assets/css/theme.css | 32 +++++++++ themes/goodbids-nonprofit/parts/header.html | 17 +++-- themes/goodbids-nonprofit/style.css | 2 +- 4 files changed, 112 insertions(+), 5 deletions(-) diff --git a/client-mu-plugins/goodbids/src/classes/network/Sites.php b/client-mu-plugins/goodbids/src/classes/network/Sites.php index edc054eff..3f494e2bc 100644 --- a/client-mu-plugins/goodbids/src/classes/network/Sites.php +++ b/client-mu-plugins/goodbids/src/classes/network/Sites.php @@ -45,6 +45,7 @@ public function __construct() { // New Site Actions $this->activate_child_theme_on_new_site(); + $this->copy_logo_to_new_site(); } /** @@ -390,4 +391,69 @@ private function init_site_defaults( int $site_id ): void { restore_current_blog(); } + + /** + * Copies logo to the new site in the WordPress Multisite network + * + * @since 1.0.0 + * + */ + private function copy_logo_to_new_site(): void { + add_action( + 'goodbids_init_site', + function ( $site_id ) { + + // switch to main site + switch_to_blog( get_main_site_id() ); + + $attachment_id = get_theme_mod( 'custom_logo' ); + + // get image path. + $file = wp_get_original_image_path( $attachment_id ); + + // exit the function if an attachment with this specific ID doesn't exist. + if ( ! $file ) { + return; + } + + restore_current_blog(); + + $uploads = wp_upload_dir(); + + $filename = wp_unique_filename( $uploads['path'], basename( $file ) ); + $new_file = $uploads['path'] . "/$filename"; + $new_file_url = $uploads['url'] . "/$filename"; + + // copy the media file + $sideload = @copy( $file, $new_file ); + + if ( false === $sideload ) { + return; + } + + // insert media file into the media gallery + $inserted_attachment_id = wp_insert_attachment( + array( + 'guid' => $new_file_url, + 'post_mime_type' => mime_content_type( $new_file ), + 'post_title' => preg_replace( '/\.[^.]+$/', '', $filename ), + 'post_content' => '', + 'post_status' => 'inherit', + ), + $new_file + ); + + // make sure this file is included, because wp_generate_attachment_metadata() depends on it + require_once ABSPATH . 'wp-admin/includes/image.php'; + // update the attachment metadata. + wp_update_attachment_metadata( + $inserted_attachment_id, + wp_generate_attachment_metadata( $inserted_attachment_id, $new_file ) + ); + + // update the site logo to the main site logo + update_option( 'site_logo', $inserted_attachment_id ); + } + ); + } } diff --git a/themes/goodbids-nonprofit/assets/css/theme.css b/themes/goodbids-nonprofit/assets/css/theme.css index 004be504d..54f4650af 100644 --- a/themes/goodbids-nonprofit/assets/css/theme.css +++ b/themes/goodbids-nonprofit/assets/css/theme.css @@ -8,3 +8,35 @@ background-color: var(--wp--preset--color--contrast); color: var(--wp--preset--color--contrast-4); } + +/*TODO move this all to Tailwind once we set that up*/ +.wp-button-custom > a { + background-color: var(--wp--preset--color--contrast); + color: var(--wp--preset--color--base-2); + font-size: var(--wp--preset--font-size--x-small); + font-weight: 500; + text-decoration: none; + border-color: var(--wp--preset--color--contrast); + border-radius: 100px; + border-width: 0; + padding-top: 0.8rem; + padding-right: 1.5rem; + padding-left: 1.5rem; + padding-bottom: 0.8rem; + + &:hover { + background-color: var(--wp--preset--color--contrast-4); + border-color: var(--wp--preset--color--contrast); + color: var(--wp--preset--color--contrast); + } + + &:focus { + background-color: var(--wp--preset--color--contrast-4); + border-color: var(--wp--preset--color--contrast); + color: var(--wp--preset--color--contrast); + outline-color: var(--wp--preset--color--contrast); + outline-offset: 2px; + outline-style: dotted; + outline-width: 1px; + } +} diff --git a/themes/goodbids-nonprofit/parts/header.html b/themes/goodbids-nonprofit/parts/header.html index 11e985b8e..7a96d4d06 100644 --- a/themes/goodbids-nonprofit/parts/header.html +++ b/themes/goodbids-nonprofit/parts/header.html @@ -3,14 +3,15 @@ style="padding-top:20px;padding-bottom:20px">
for
+for