Skip to content

Commit

Permalink
Branding: Add AspireUpdate\Branding.
Browse files Browse the repository at this point in the history
  • Loading branch information
costdev committed Nov 7, 2024
1 parent 5f1f29a commit 4f0eb82
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
17 changes: 17 additions & 0 deletions assets/css/aspire-update.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@
display: none;
}

.aspireupdate-notice {
background-color: #f0f6fc;
border: 1px solid #70b9e3;
border-radius: 50px;
max-width: max-content;
}

.aspireupdate-notice p::before {
content: '';
display: inline-block;
margin-inline-end: .5em;
vertical-align: middle;
background: url(../images/aspirepress-logo-icon.svg) no-repeat center center / 20px 20px;
height: 20px;
width: 20px;
}

#voltron {
color: transparent;
font-size: clamp(4px, 0.9vw, 8px);
Expand Down
119 changes: 119 additions & 0 deletions includes/class-branding.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php
/**
* The Class for adding branding to the dashboard.
*
* @package aspire-update
*/

namespace AspireUpdate;

/**
* The Class for adding branding to the dashboard.
*/
class Branding {
/**
* Hold a single instance of the class.
*
* @var object
*/
private static $instance = null;

/**
* The Constructor.
*/
public function __construct() {
$admin_settings = Admin_Settings::get_instance();
if ( $admin_settings->get_setting( 'enable', false ) ) {
add_action( 'admin_notices', [ $this, 'output_admin_notice' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
}
}

/**
* Initialize Class.
*
* @return object
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}

/**
* Enqueue scripts and styles.
*
* @param string $hook The page identifier.
* @return void
*/
public function admin_enqueue_scripts( $hook ) {
if ( defined( 'AP_REMOVE_UI' ) && AP_REMOVE_UI ) {
return;
}

$allowed_screens = [
'update-core.php',
'plugins.php',
'plugin-install.php',
'themes.php',
'theme-install.php',
];

if ( in_array( $hook, $allowed_screens, true ) ) {
wp_enqueue_style( 'aspire_update_settings_css', plugin_dir_url( __DIR__ ) . 'assets/css/aspire-update.css', [], AP_VERSION );
}
}

/**
* Output admin notice.
*
* @return void
*/
public function output_admin_notice() {
if ( defined( 'AP_REMOVE_UI' ) && AP_REMOVE_UI ) {
return;
}

$current_screen = get_current_screen();
if ( ! $current_screen instanceof \WP_Screen ) {
return;
}

$message = '';
switch ( $current_screen->base ) {
case 'plugins':
case 'plugin-install':
$message = sprintf(
/* translators: 1: The name of the plugin, 2: The documentation URL. */
__( 'Your plugin updates are now powered by <strong>%1$s</strong>. <a href="%2$s">Learn more</a>', 'AspireUpdate' ),
'AspireUpdate',
__( 'https://docs.aspirepress.org/aspireupdate/', 'AspireUpdate' )
);
break;
case 'themes':
case 'theme-install':
$message = sprintf(
/* translators: 1: The name of the plugin, 2: The documentation URL. */
__( 'Your theme updates are now powered by <strong>%1$s</strong>. <a href="%2$s">Learn more</a>', 'AspireUpdate' ),
'AspireUpdate',
__( 'https://docs.aspirepress.org/aspireupdate/', 'AspireUpdate' )
);
break;
case 'update-core':
$message = sprintf(
/* translators: 1: The name of the plugin, 2: The documentation URL. */
__( 'Your WordPress, plugin, theme and translation updates are now powered by <strong>%1$s</strong>. <a href="%2$s">Learn more</a>', 'AspireUpdate' ),
'AspireUpdate',
__( 'https://docs.aspirepress.org/aspireupdate/', 'AspireUpdate' )
);
break;
}

if ( '' === $message ) {
return;
}

echo wp_kses_post( '<div class="notice aspireupdate-notice notice-info"><p>' . $message . '</p></div>' );
}
}

0 comments on commit 4f0eb82

Please sign in to comment.