Skip to content

Commit a505c8b

Browse files
authored
Merge pull request #203 from Emilia-Capital/filip/remote-images-fallback
Fallback for remote host images
2 parents 13dd774 + 7d489b7 commit a505c8b

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

assets/css/page-widgets/whats-new.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@
5757
border-radius: var(--prpl-border-radius);
5858
box-shadow: 5px 5px 5px var(--prpl-color-gray-2);
5959
border: 1px solid var(--prpl-color-gray-2);
60+
background-color: var(--prpl-color-gray-1); /* Fallback, if remote host image is not accessible */
6061
}

assets/js/web-components/prpl-badge.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ customElements.define(
2020
}"
2121
alt="Badge"
2222
${ false === complete ? 'style="filter: grayscale(1);opacity: 0.25;"' : '' }
23+
onerror="this.onerror=null;this.src='${
24+
progressPlannerBadge.placeholderImageUrl
25+
}';"
2326
/>
2427
`;
2528
}

classes/admin/class-scripts.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function localize_script( $handle ) {
102102
'progressPlannerBadge',
103103
[
104104
'remoteServerRootUrl' => \progress_planner()->get_remote_server_root_url(),
105+
'placeholderImageUrl' => \progress_planner()->get_placeholder_svg(),
105106
]
106107
);
107108
break;

classes/class-base.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ public function get_remote_server_root_url() {
144144
: 'https://progressplanner.com';
145145
}
146146

147+
/**
148+
* Get the placeholder SVG.
149+
*
150+
* @param int $width The width of the placeholder image.
151+
* @param int $height The height of the placeholder image.
152+
*
153+
* @return string
154+
*/
155+
public function get_placeholder_svg( $width = 1200, $height = 675 ) {
156+
return 'data:image/svg+xml;base64,' . base64_encode( sprintf( '<svg width="%1$d" height="%2$d" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="%3$d" height="%4$d" style="fill:#F6F5FB;stroke:#534786;stroke-width:2"/><text x="50%%" y="50%%" font-size="20" text-anchor="middle" alignment-baseline="middle" font-family="monospace" fill="#534786">progressplanner.com</text></svg>', $width, $height, ( $width - 4 ), ( $height - 4 ) ) );
157+
}
158+
147159
/**
148160
* Get the activation date.
149161
*

views/page-widgets/latest-badge.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
alt="<?php echo \esc_attr( $prpl_latest_badge->get_name() ); ?>"
3838
width="1200"
3939
height="675"
40+
onerror="this.onerror=null;this.src='<?php echo \esc_url( \progress_planner()->get_placeholder_svg() ); ?>';"
4041
/>
4142
<?php if ( 'no-license' !== \get_option( 'progress_planner_license_key', 'no-license' ) && ! \progress_planner()->is_local_site() ) : ?>
4243
<?php

0 commit comments

Comments
 (0)