Fix fallback avatar and clean up code

One hour after the last release. This is why I do not believe in God.
This commit is contained in:
Tetrakern 2023-08-05 00:21:22 +02:00
parent 259e571cfa
commit e3f85ea08e
2 changed files with 31 additions and 14 deletions

View File

@ -249,18 +249,15 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
| `wp_enqueue_scripts` | `fictioneer_add_custom_scripts`, `fictioneer_customizer_queue`, `fictioneer_style_queue`
| `wp_head` | `fictioneer_output_head_seo`, `fictioneer_output_rss`, `fictioneer_output_schemas`, `fictioneer_add_fiction_css`
| ACF HOOK | FICTIONEER ACTIONS
| ---: | :--- |
| `acf/fields/post_object/query/name=fictioneer_chapter_story` | `fictioneer_acf_scope_chapter_story`
| `acf/fields/post_object/query/name=fictioneer_post_story_blogs` | `fictioneer_acf_scope_blog_posts`
| `acf/save_post` | `fictioneer_update_post_relationships`, `fictioneer_acf_append_chapter_to_story`
| `acf/update_value/name=fictioneer_story_chapters` | `fictioneer_remember_chapters_modified`
<br>
| WORDPRESS HOOK | FICTIONEER FILTERS
| ---: | :--- |
| `comment_reply_link` | `fictioneer_comment_login_to_reply`
| `content_save_pre` | `fictioneer_strip_shortcodes_for_non_administrators`
| `excerpt_length` | `fictioneer_custom_excerpt_length`
| `get_avatar` | `fictioneer_avatar_fallback`
| `get_avatar_url` | `fictioneer_get_avatar_url`
| `get_the_excerpt` | `fictioneer_fix_excerpt`
| `kses_allowed_protocols` | `fictioneer_extend_allowed_protocols`
| `logout_url` | `fictioneer_logout_redirect`
@ -276,6 +273,15 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
| `wp_is_application_passwords_available` | `__return_false`
| `wp_sitemaps_enabled` | `__return_false`
<br>
| ACF HOOK | FICTIONEER ACTIONS
| ---: | :--- |
| `acf/fields/post_object/query/name=fictioneer_chapter_story` | `fictioneer_acf_scope_chapter_story`
| `acf/fields/post_object/query/name=fictioneer_post_story_blogs` | `fictioneer_acf_scope_blog_posts`
| `acf/save_post` | `fictioneer_update_post_relationships`, `fictioneer_acf_append_chapter_to_story`
| `acf/update_value/name=fictioneer_story_chapters` | `fictioneer_remember_chapters_modified`
## Caching
Fictioneer is cache aware. This means the theme provides an interface to aid cache plugins in purging stale caches across the site, not just the updated post. It can even operate as static website with dynamic content being fetched via AJAX. By default, four cache plugins are considered: [WP Super Cache](https://wordpress.org/plugins/wp-super-cache/), [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/), [LiteSpeed Cache](https://wordpress.org/plugins/litespeed-cache/), and [WP Rocket](https://wp-rocket.me/). Whenever you publish or update content, a series of actions is triggered to purge anything related.

View File

@ -17,7 +17,8 @@ if ( ! function_exists( 'fictioneer_avatar_fallback' ) ) {
*/
function fictioneer_avatar_fallback( $avatar, $id_or_email ) {
$default_url = get_avatar_url( $id_or_email, ['force_default' => true] );
$default_url = get_avatar_url( 'nonexistentemail@example.com', array( 'force_default' => true ) );
return str_replace( '<img', '<img onerror="this.src=\'' . $default_url . '\';this.srcset=\'\';this.onerror=\'\';"', $avatar );
}
}
@ -42,7 +43,10 @@ if ( ! function_exists( 'fictioneer_get_custom_avatar_url' ) ) {
// Override default avatar with external avatar if allowed
if ( $user && is_object( $user ) && ! $user->fictioneer_enforce_gravatar ) {
$avatar_url = empty( $user->fictioneer_external_avatar_url ) ? null : $user->fictioneer_external_avatar_url;
if ( $avatar_url ) return $avatar_url;
if ( ! empty( $avatar_url ) ) {
return $avatar_url;
}
}
return false;
@ -67,13 +71,15 @@ if ( ! function_exists( 'fictioneer_get_avatar_url' ) ) {
*/
function fictioneer_get_avatar_url( $url, $id_or_email, $args ) {
// Abort conditions...
if ( $args['force_default'] ) {
return $url;
}
// Setup
$user = fictioneer_get_user_by_id_or_email( $id_or_email );
$custom_avatar = fictioneer_get_custom_avatar_url( $user );
// Abort conditions...
if ( $args['force_default'] ) return $url;
// Check user and permissions
if ( $user ) {
$user_disabled = $user->fictioneer_disable_avatar;
@ -85,7 +91,9 @@ if ( ! function_exists( 'fictioneer_get_avatar_url' ) ) {
}
// Return custom avatar if set
if ( $custom_avatar ) return $custom_avatar;
if ( ! empty( $custom_avatar ) ) {
return $custom_avatar;
}
// Return default avatar
return $url;
@ -110,10 +118,13 @@ if ( ! function_exists( 'fictioneer_ajax_get_avatar' ) ) {
function fictioneer_ajax_get_avatar() {
// Setup and validations
$user = fictioneer_get_validated_ajax_user();
if ( ! $user ) wp_send_json_error( ['error' => __( 'Request did not pass validation.', 'fictioneer' )] );
if ( ! $user ) {
wp_send_json_error( array( 'error' => __( 'Request did not pass validation.', 'fictioneer' ) ) );
}
// Response
wp_send_json_success( ['url' => get_avatar_url( $user->ID )] );
wp_send_json_success( array( 'url' => get_avatar_url( $user->ID ) ) );
}
}
add_action( 'wp_ajax_fictioneer_ajax_get_avatar', 'fictioneer_ajax_get_avatar' );