Skip to content

Commit

Permalink
refactor: plugin logo funcionality
Browse files Browse the repository at this point in the history
  • Loading branch information
harunbleech committed Sep 27, 2024
1 parent b390cf0 commit 7d9408b
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 32 deletions.
Binary file removed assets/icons/vrts-logo-icon.png
Binary file not shown.
File renamed without changes
File renamed without changes
19 changes: 1 addition & 18 deletions components/admin-header-navigation/index.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
<nav class="vrts_admin_header_menu">
<a class="vrts_logo_link" href="<?php echo esc_url( admin_url( 'admin.php?page=vrts-tests' ) ); ?>">
<h2>
<span class="vrts_logo">
<?php
echo wp_kses( vrts()->get_plugin_logo_icon( false ), [
'svg' => [
'xmlns' => [],
'width' => [],
'height' => [],
'viewbox' => [],
'style' => [],
'xml:space' => [],
],
'path' => [
'fill' => [],
'd' => [],
],
]);
?>
</span>
<span class="vrts_logo"><?php vrts()->logo(); ?></span>
<?php echo esc_html( $data['plugin_name'] ); ?>
</h2>
</a>
Expand Down
2 changes: 1 addition & 1 deletion components/emails/test-run/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<table cellpadding="0" cellspacing="0" border="0" role="presentation" style="border-spacing: 0">
<tr>
<td valign="middle">
<img src="<?php echo esc_url( vrts()->get_plugin_url( 'assets/icons/vrts-logo-icon_reduced.png' ) ); ?>" width="20" height="20" alt="VRTs logo" style="width: 20px; height: 20px; display: block" />
<img src="<?php echo esc_url( vrts()->get_plugin_url( 'assets/images/vrts-logo.png' ) ); ?>" width="20" height="20" alt="VRTs logo" style="width: 20px; height: 20px; display: block" />
</td>
<td valign="middle" style="padding-left: 4px">
<p style="color: #262626; margin: 0; padding: 0; font-size: 12px; line-height: 20px; mso-line-height-alt: normal">
Expand Down
2 changes: 1 addition & 1 deletion components/emails/test-run/header.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<table cellpadding="0" cellspacing="0" border="0" role="presentation" style="width: 100%; padding-bottom: 25px; border-spacing: 0;">
<tr>
<td width="1%" valign="middle">
<img src="<?php echo esc_url( vrts()->get_plugin_url( 'assets/icons/vrts-logo-icon_reduced.png' ) ); ?>" width="40" height="40" alt="VRTs logo" style="width: 40px; height: 40px; display: block" />
<img src="<?php echo esc_url( vrts()->get_plugin_url( 'assets/images/vrts-logo.png' ) ); ?>" width="40" height="40" alt="VRTs logo" style="width: 40px; height: 40px; display: block" />
</td>
<td width="99%" valign="middle" style="padding-left: 10px;">
<table border="0" cellspacing="0" width="100%">
Expand Down
33 changes: 23 additions & 10 deletions includes/core/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,23 +271,34 @@ public function icon( $icon ) {
}

/**
* Get the plugin logo icon.
* Get the plugin logo.
*
* @param boolean $base64 return base 64 encoded or not.
* @param bool $escape If true it will escape the logog.
*
* @return string the logo as string.
*/
public function get_plugin_logo_icon( $base64 = true ) {
$icon_path = $this->get_plugin_path( 'assets/icons/vrts-logo-icon.svg' );
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a file.
$svg = file_get_contents( $icon_path );
public function get_logo( $escape = true ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';

if ( $base64 ) {
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- It's a file.
return 'data:image/svg+xml;base64,' . base64_encode( $svg );
$filesystem = new WP_Filesystem_Direct( null );
$logo = $filesystem->get_contents( $this->get_plugin_path( "assets/images/vrts-logo.svg" ) );

if ( $escape ) {
return wp_kses( $logo, $this->wp_kses_svg() );
}

return $svg;
return $logo;
}

/**
* The plugin logo.
*/
public function logo() {
echo wp_kses(
$this->get_logo( false ),
$this->wp_kses_svg()
);
}

/**
Expand Down Expand Up @@ -342,6 +353,8 @@ private function wp_kses_svg() {
'xmlns' => true,
'aria-hidden' => true,
'focusable' => true,
'style' => [],
'xml:space' => [],
],
'path' => [
'd' => true,
Expand Down
2 changes: 1 addition & 1 deletion includes/features/class-admin-columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function column_heading( $columns ) {
$added_columns = [];
$added_columns['vrts_testing_status'] = sprintf(
'<span class="vrts-status" title="%2$s %3$s">%1$s<span class="screen-reader-text">%2$s %3$s</span></span>',
vrts()->get_plugin_logo_icon( false ),
vrts()->get_logo(),
vrts()->get_plugin_info( 'name' ),
__( 'Status', 'visual-regression-tests' )
);
Expand Down
2 changes: 1 addition & 1 deletion includes/features/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function add_main_menu() {
'manage_options',
'vrts',
'',
vrts()->get_plugin_logo_icon(),
'data:image/svg+xml;base64,' . base64_encode( vrts()->get_logo() ),
80
);
}
Expand Down

0 comments on commit 7d9408b

Please sign in to comment.