Skip to content

Commit f6e3b63

Browse files
authored
[N/A] Branding Adjustment and Bug Fixes (#190)
* [N/A] Quick branding adjustment * [N/A] Fix PHP error during create project. * [N/A] Avoid unnecessary "warning" * [N/A] Another Branding Update * [N/A] Another round of Create Project/Branding Adjustments * [N/A] Couple more fixes * [N/A] Yet another branding fix. * [N/A] Final branding adjustment
1 parent 1536b9a commit f6e3b63

File tree

4 files changed

+149
-58
lines changed

4 files changed

+149
-58
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ mkdir project-name && cd project-name && composer create-project --repository-ur
6969
You can quickly remove the project by using:
7070

7171
```bash
72-
ddev delete project-name -O -y && cd ../ && rm -rf project-name
72+
ddev stop && ddev delete project-name -O -y && cd ../ && rm -rf project-name
7373
```
7474

7575
## Changelog

bin/composer-scripts/ProjectEvents/PostCreateProjectScript.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ class PostCreateProjectScript extends ComposerScript {
3131
'package-name' => 'WPStarter',
3232
'function-prefix' => 'wpstarter_',
3333
'text-domain' => 'wp-starter',
34-
'proxy-domain' => '',
3534
'branding' => 'viget',
36-
'branding-name' => '',
37-
'branding-website' => '',
3835
];
3936

4037
/**
@@ -156,23 +153,25 @@ public static function getProjectInfo(): void {
156153
self::$info['function'] = self::ask( 'Do you want to customize the function prefix?', self::$info['function'] );
157154

158155
// Proxy Domain.
159-
self::$info['proxy-domain'] = self::ask( 'Would you like to proxy media (uploads) from another domain? (leave blank to skip)', self::$info['proxy-domain'] );
156+
$proxyDomain = empty( self::$info['proxy-domain'] ) ? '' : self::$info['proxy-domain'];
157+
self::$info['proxy-domain'] = self::ask( 'Would you like to proxy media (uploads) from another domain? (leave blank to skip)', $proxyDomain );
160158

161159
self::$info['proxy-domain'] = preg_replace( '#^https?://#', '', self::$info['proxy-domain'] );
162160
self::$info['proxy-domain'] = rtrim( self::$info['proxy-domain'], '/' );
163161

164162
// Make sure the proxy domain is a valid domain.
165-
if ( ! filter_var( self::$info['proxy-domain'], FILTER_VALIDATE_DOMAIN ) ) {
163+
if ( self::$info['proxy-domain'] && ! filter_var( self::$info['proxy-domain'], FILTER_VALIDATE_DOMAIN ) ) {
166164
self::writeWarning( 'Invalid proxy domain name. Ignoring...' );
167165
self::$info['proxy-domain'] = '';
168166
}
169167

170168
// Branding.
169+
$branding = empty( self::$info['branding'] ) ? self::$defaults['branding'] : self::$info['branding'];
171170
self::$info['branding'] = self::select( 'Agency Branding:', [
172171
'viget' => 'Viget',
173172
'custom' => 'Custom',
174173
'none' => 'None',
175-
], self::$info['branding'] );
174+
], $branding );
176175

177176
if ( 'custom' === self::$info['branding'] ) {
178177
$brandingName = empty( self::$info['branding-name'] ) ? 'My Agency' : self::$info['branding-name'];
@@ -663,9 +662,9 @@ private static function updateBranding(): void {
663662
$footerFile = self::translatePath( 'wp-content/mu-plugins/viget-wp/src/classes/Admin/Footer.php' );
664663
$loginScreenFile = self::translatePath( 'wp-content/mu-plugins/viget-wp/src/classes/Admin/LoginScreen.php' );
665664

666-
// Disable the login screen branding.
667-
if ( file_exists( $loginScreenFile ) ) {
668-
self::searchReplaceFile( '$this->login_css();', '// $this->login_css();', $loginScreenFile );
665+
// Modify the login screen branding.
666+
if ( 'viget' !== self::$info['branding'] && file_exists( $loginScreenFile ) ) {
667+
self::searchReplaceFile( '$logo_url = VIGETWP_PLUGIN_URL . \'src/assets/images/logo.svg\';', '$logo_url = \'\';', $loginScreenFile );
669668
}
670669

671670
if ( ! file_exists( $footerFile ) ) {
@@ -678,7 +677,16 @@ private static function updateBranding(): void {
678677
return;
679678
}
680679

681-
self::searchReplaceFile( 'https://www.viget.com/', self::$info['branding-website'], $footerFile );
682-
self::searchReplaceFile( 'Viget', self::$info['branding-name'], $footerFile );
680+
if ( 'custom' !== self::$info['branding'] || empty( self::$info['branding-name'] ) || empty( self::$info['branding-website'] ) ) {
681+
return;
682+
}
683+
684+
if ( ! empty( self::$info['branding-website'] ) ) {
685+
self::searchReplaceFile( 'https://www.viget.com/', self::$info['branding-website'], $footerFile );
686+
}
687+
688+
if ( ! empty( self::$info['branding-name'] ) ) {
689+
self::searchReplaceFile( 'esc_html__( \'Viget\', \'viget-wp\' )', 'esc_html__( \'' . addslashes( self::$info['branding-name'] ) . '\', \'viget-wp\' )', $footerFile );
690+
}
683691
}
684692
}

bin/composer-scripts/ProjectEvents/PostInstallScript.php

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class PostInstallScript extends ComposerScript {
3333
*/
3434
const DEFAULT_ADMIN_USER = 'viget';
3535

36+
/**
37+
* Set Default Admin Email
38+
*/
39+
const DEFAULT_ADMIN_EMAIL = '[email protected]';
40+
3641
/**
3742
* @var array
3843
*/
@@ -398,7 +403,20 @@ public static function getSiteInfo(): void {
398403

399404
// Site Description.
400405
$name = self::$env['PROJECT_NAME'] ?? self::$info['title'];
401-
$description = ! empty( self::$info['description'] ) ? self::$info['description'] : sprintf( 'A custom WordPress Site for %s by Viget.', $name );
406+
$defaultDescription = sprintf( 'A custom WordPress site for %s', $name );
407+
408+
$brandingName = 'Viget';
409+
if ( 'custom' === self::$env['PROJECT_BRANDING'] && ! empty( self::$env['PROJECT_BRANDING_NAME']) ) {
410+
$brandingName = self::$env['PROJECT_BRANDING_NAME'];
411+
} elseif ( 'none' === self::$env['PROJECT_BRANDING'] ) {
412+
$brandingName = '';
413+
}
414+
415+
if ( $brandingName ) {
416+
$defaultDescription .= " by $brandingName";
417+
}
418+
419+
$description = ! empty( self::$info['description'] ) ? self::$info['description'] : $defaultDescription;
402420
self::$info['description'] = self::ask( 'What is the Site Description (tagline)?', $description );
403421

404422
// Site URL.
@@ -407,11 +425,11 @@ public static function getSiteInfo(): void {
407425
self::$info['url'] = self::ask( 'What is the URL?*', $url );
408426

409427
// Admin Username.
410-
self::$info['username'] = self::$info['username'] ?? self::DEFAULT_ADMIN_USER;
428+
self::$info['username'] = self::$info['username'] ?? self::getDefaultAdminUsername();
411429
self::$info['username'] = self::ask( 'Set the admin username:*', self::$info['username'] );
412430

413431
// Admin Email.
414-
self::$info['email'] = self::$info['email'] ?? '[email protected]';
432+
self::$info['email'] = self::$info['email'] ?? self::getDefaultAdminEmail( self::$info['username'] );
415433
self::$info['email'] = self::ask( 'What is the admin email address?*', self::$info['email'] );
416434

417435
// Admin Password.
@@ -751,4 +769,37 @@ public static function renderSuccessMessage(): void {
751769

752770
self::writeLine( $success );
753771
}
772+
773+
/**
774+
* Get the default admin username.
775+
*
776+
* @return string
777+
*/
778+
private static function getDefaultAdminUsername(): string {
779+
$defaultUsername = self::DEFAULT_ADMIN_USER;
780+
if ( 'none' === self::$env['PROJECT_BRANDING'] ) {
781+
$defaultUsername = 'root';
782+
} elseif( 'custom' === self::$env['PROJECT_BRANDING'] && ! empty( self::$env['PROJECT_BRANDING_NAME'] ) ) {
783+
$defaultUsername = self::slugify( self::$env['PROJECT_BRANDING_NAME'] );
784+
}
785+
return $defaultUsername;
786+
}
787+
788+
/**
789+
* Get the default admin email.
790+
*
791+
* @param string $defaultUsername
792+
*
793+
* @return string
794+
*/
795+
private static function getDefaultAdminEmail( string $defaultUsername ): string {
796+
$defaultEmail = self::DEFAULT_ADMIN_EMAIL;
797+
if ( 'none' === self::$env['PROJECT_BRANDING'] ) {
798+
$defaultEmail = '[email protected]';
799+
} elseif( 'custom' === self::$env['PROJECT_BRANDING'] && ! empty( self::$env['PROJECT_BRANDING_WEBSITE'] ) ) {
800+
$domain = parse_url( self::$env['PROJECT_BRANDING_WEBSITE'], PHP_URL_HOST );
801+
$defaultEmail = $defaultUsername . '@' . $domain;
802+
}
803+
return $defaultEmail;
804+
}
754805
}

wp-content/mu-plugins/viget-wp/src/classes/Admin/LoginScreen.php

Lines changed: 75 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,60 +37,92 @@ private function login_css(): void {
3737
add_action(
3838
'login_enqueue_scripts',
3939
function () {
40+
$logo_url = $this->get_logo_url();
41+
42+
$brand_colors = apply_filters(
43+
'vigetwp_brand_colors',
44+
[
45+
'primary' => '#1596BB',
46+
'secondary' => '#0e6d88',
47+
'accent' => '#f26628',
48+
]
49+
);
4050
?>
4151
<style>
42-
#login h1 a,
43-
.login h1 a {
44-
background-image: url('<?php echo VIGETWP_PLUGIN_URL; ?>src/assets/images/viget-logo-transparent.svg');
45-
background-repeat: no-repeat;
46-
background-size: contain;
47-
height: 65px;
48-
width: 220px;
49-
}
50-
body.login {
51-
position: relative;
52-
}
53-
body.login::after {
54-
content: '';
55-
background-image: url('<?php echo VIGETWP_PLUGIN_URL; ?>src/assets/images/viget-logo-transparent.svg');
56-
background-repeat: no-repeat;
57-
background-position: -10% 0;
58-
background-size: 300%;
59-
position: absolute;
60-
inset: 0;
61-
z-index: -1;
62-
opacity: 0.075;
63-
}
64-
body.login.wp-core-ui .button-primary {
65-
background-color: #1596BB;
66-
transition: all 200ms ease-in-out;
67-
}
68-
body.login.wp-core-ui .button-primary:hover {
69-
background-color: #0e6d88;
70-
}
52+
:root {
53+
--brand-primary: <?php echo esc_html( $brand_colors['primary'] ); ?>;
54+
--brand-secondary: <?php echo esc_html( $brand_colors['secondary'] ); ?>;
55+
--brand-accent: <?php echo esc_html( $brand_colors['accent'] ); ?>;
56+
}
57+
58+
<?php if ( $logo_url ) : ?>
59+
#login h1 a,
60+
.login h1 a {
61+
background-image: url('<?php echo esc_html( $logo_url ); ?>');
62+
background-repeat: no-repeat;
63+
background-size: contain;
64+
height: 65px;
65+
width: 220px;
66+
}
67+
<?php endif; ?>
7168

72-
body.login #backtoblog a,
73-
body.login #nav a,
74-
body.login h1 a {
75-
transition: all 200ms ease-in-out;
76-
}
69+
body.login {
70+
position: relative;
71+
}
72+
body.login::after {
73+
content: '';
74+
background-image: url('<?php echo esc_html( $logo_url ); ?>');
75+
background-repeat: no-repeat;
76+
background-position: -10% 0;
77+
background-size: 300%;
78+
position: absolute;
79+
inset: 0;
80+
z-index: -1;
81+
opacity: 0.075;
82+
}
83+
body.login.wp-core-ui .button-primary {
84+
background-color: var(--brand-primary);
85+
transition: all 200ms ease-in-out;
86+
}
87+
body.login.wp-core-ui .button-primary:hover {
88+
background-color: var(--brand-secondary);
89+
}
7790

78-
body.login #backtoblog a:hover,
79-
body.login #nav a:hover,
80-
body.login h1 a:hover {
81-
color: #1596BB;
82-
}
91+
body.login #backtoblog a,
92+
body.login #nav a,
93+
body.login h1 a {
94+
transition: all 200ms ease-in-out;
95+
}
8396

84-
body.login input[type=checkbox]:focus, body.login input[type=color]:focus, body.login input[type=email]:focus, body.login input[type=password]:focus, input[type=text]:focus {
85-
border-color: #1596BB !important;
86-
box-shadow: 0 0 0 1px #1596BB !important;
87-
}
97+
body.login #backtoblog a:hover,
98+
body.login #nav a:hover,
99+
body.login h1 a:hover {
100+
color: var(--brand-primary);
101+
}
102+
103+
body.login input[type=checkbox]:focus, body.login input[type=color]:focus, body.login input[type=email]:focus, body.login input[type=password]:focus, input[type=text]:focus {
104+
border-color: var(--brand-primary) !important;
105+
box-shadow: 0 0 0 1px var(--brand-primary) !important;
106+
}
88107
</style>
89108
<?php
90109
}
91110
);
92111
}
93112

113+
/**
114+
* Get the logo URL.
115+
*
116+
* @return string
117+
*/
118+
private function get_logo_url(): string {
119+
$logo_url = VIGETWP_PLUGIN_URL . 'src/assets/images/logo.svg';
120+
if ( has_custom_logo() ) {
121+
$logo_url = wp_get_attachment_image_url( get_theme_mod( 'custom_logo' ), 'full' );
122+
}
123+
return $logo_url;
124+
}
125+
94126
/**
95127
* Change the login logo URL.
96128
*

0 commit comments

Comments
 (0)