PluginProbe
Friends / 4.3.2
Friends v4.3.2
4.3.2 4.3.1 4.3.0 4.2.2 4.2.1 4.2.0 4.1.0 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.0 2.9.1 All 88 releases
← All changes | includes/class-frontend.php +93 -38 4.1.04.3.2 View file →
@@ -325,15 +325,31 @@
325 325
326 326 return $file_paths;
327 327 }
328 328
329 + /**
330 + * Get an asset version that changes when the local file changes.
331 + *
332 + * @param string $file Relative asset path.
333 + * @return string Asset version.
334 + */
335 + private function get_asset_version( $file ) {
336 + $path = dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file;
337 + if ( file_exists( $path ) ) {
338 + return Friends::VERSION . '-' . filemtime( $path );
339 + }
340 +
341 + return Friends::VERSION;
342 + }
343 +
329 344 public function default_theme() {
330 345 $handle = 'friends';
331 346 $file = 'friends.css';
332 - $version = Friends::VERSION;
347 + $version = $this->get_asset_version( $file );
333 348 wp_enqueue_style( $handle, plugins_url( $file, FRIENDS_PLUGIN_FILE ), array(), apply_filters( 'friends_debug_enqueue', $version, $handle, dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file ) );
334 349
335 - wp_enqueue_script( 'friends-default-theme', plugins_url( 'friends-default-theme.js', FRIENDS_PLUGIN_FILE ), array( 'jquery', 'friends' ), $version, true );
350 + $file = 'friends-default-theme.js';
351 + wp_enqueue_script( 'friends-default-theme', plugins_url( $file, FRIENDS_PLUGIN_FILE ), array( 'jquery', 'friends' ), $this->get_asset_version( $file ), true );
336 352 }
337 353
338 354 /**
339 355 * Reference our script for the /friends page
@@ -345,35 +361,36 @@
345 361 global $wp_query;
346 362
347 363 $handle = 'friends';
348 364 $file = 'friends.js';
349 - $version = Friends::VERSION;
365 + $version = $this->get_asset_version( $file );
350 366 wp_enqueue_script( $handle, plugins_url( $file, FRIENDS_PLUGIN_FILE ), array( 'common', 'jquery', 'wp-util' ), apply_filters( 'friends_debug_enqueue', $version, $handle, dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file ), true );
351 367
352 368 $query_vars = wp_json_encode( $this->get_minimal_query_vars( $wp_query->query_vars ) );
353 369
354 370 $variables = array(
355 - 'emojis_json' => plugins_url( 'emojis.json', FRIENDS_PLUGIN_FILE ),
356 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
357 - 'rest_base' => rest_url( 'friends/v1/' ),
358 - 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
359 - 'text_link_expired' => __( 'The link has expired. A new link has been generated, please click it again.', 'friends' ),
360 - 'text_undo' => __( 'Undo' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
361 - 'text_trash_post' => __( 'Trash this post', 'friends' ),
362 - 'text_del_convers' => __( 'Do you really want to delete this conversation?', 'friends' ),
363 - 'text_no_more_posts' => __( 'No more posts available.', 'friends' ),
364 - 'text_checking_url' => __( 'Checking URL.', 'friends' ),
365 - 'text_refreshed' => __( 'Refreshed', 'friends' ),
366 - 'text_refreshing' => __( 'Refreshing', 'friends' ),
367 - 'text_compact_mode' => __( 'Compact mode', 'friends' ),
368 - 'text_expanded_mode' => __( 'Expanded mode', 'friends' ),
369 - 'text_loading_comments' => __( 'Loading comments...', 'friends' ),
370 - 'text_still_loading' => __( 'Still loading...', 'friends' ),
371 - 'refresh_now' => isset( $_GET['refresh'] ) ? 'true' : 'false', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
372 - 'query_vars' => $query_vars,
373 - 'qv_sign' => sha1( wp_salt( 'nonce' ) . $query_vars ),
374 - 'current_page' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1,
375 - 'max_page' => $wp_query->max_num_pages,
371 + 'emojis_json' => plugins_url( 'emojis.json', FRIENDS_PLUGIN_FILE ),
372 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
373 + 'rest_base' => rest_url( 'friends/v1/' ),
374 + 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
375 + 'text_link_expired' => __( 'The link has expired. A new link has been generated, please click it again.', 'friends' ),
376 + 'text_undo' => __( 'Undo' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
377 + 'text_trash_post' => __( 'Trash this post', 'friends' ),
378 + 'text_del_convers' => __( 'Do you really want to delete this conversation?', 'friends' ),
379 + 'text_no_more_posts' => __( 'No more posts available.', 'friends' ),
380 + 'text_checking_url' => __( 'Checking URL.', 'friends' ),
381 + 'text_refreshed' => __( 'Refreshed', 'friends' ),
382 + 'text_refreshing' => __( 'Refreshing', 'friends' ),
383 + 'text_compact_mode' => __( 'Compact mode', 'friends' ),
384 + 'text_expanded_mode' => __( 'Expanded mode', 'friends' ),
385 + 'text_loading_comments' => __( 'Loading comments...', 'friends' ),
386 + 'text_still_loading' => __( 'Still loading...', 'friends' ),
387 + 'message_delivery_nonce' => wp_create_nonce( 'friends-message-delivery-statuses' ),
388 + 'refresh_now' => isset( $_GET['refresh'] ) ? 'true' : 'false', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
389 + 'query_vars' => $query_vars,
390 + 'qv_sign' => sha1( wp_salt( 'nonce' ) . $query_vars ),
391 + 'current_page' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1,
392 + 'max_page' => $wp_query->max_num_pages,
376 393 );
377 394
378 395 // translators: %s is a user handle.
379 396 $variables['text_confirm_delete_follower'] = __( 'Do you really want to delete the follower %s?', 'friends' );
@@ -418,11 +435,15 @@
418 435 public function dequeue_scripts() {
419 436 if ( is_user_logged_in() && Friends::on_frontend() && 'block' !== $this->theme ) {
420 437 // Dequeue theme styles so that they don't interact with the Friends frontend.
421 438 $wp_styles = wp_styles();
439 + $theme_root_path = wp_parse_url( get_theme_root_uri(), PHP_URL_PATH );
422 440 foreach ( $wp_styles->queue as $style ) {
423 441 $src = $wp_styles->registered[ $style ]->src;
424 - if ( 'global-styles' === $style || false !== strpos( $src, '/themes/' ) ) {
442 + $src_path = wp_parse_url( $src, PHP_URL_PATH );
443 + $is_theme_style = $theme_root_path && $src_path
444 + && 0 === strpos( $src_path, trailingslashit( $theme_root_path ) );
445 + if ( 'global-styles' === $style || $is_theme_style ) {
425 446 wp_dequeue_style( $style );
426 447 }
427 448 }
428 449 }
@@ -519,12 +540,13 @@
519 540
520 541 public function mastodon_theme() {
521 542 $handle = 'friends-mastodon';
522 543 $file = 'templates/mastodon/mastodon.css';
523 - $version = Friends::VERSION;
544 + $version = $this->get_asset_version( $file );
524 545 wp_enqueue_style( $handle, plugins_url( $file, FRIENDS_PLUGIN_FILE ), array(), apply_filters( 'friends_debug_enqueue', $version, $handle, dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file ) );
525 546
526 - wp_enqueue_script( 'friends-mastodon', plugins_url( 'templates/mastodon/mastodon.js', FRIENDS_PLUGIN_FILE ), array( 'jquery', 'friends' ), $version, true );
547 + $file = 'templates/mastodon/mastodon.js';
548 + wp_enqueue_script( 'friends-mastodon', plugins_url( $file, FRIENDS_PLUGIN_FILE ), array( 'jquery', 'friends' ), $this->get_asset_version( $file ), true );
527 549 wp_localize_script(
528 550 'friends-mastodon',
529 551 'friendsMastodon',
530 552 array(
@@ -555,12 +577,13 @@
555 577
556 578 public function twitter_theme() {
557 579 $handle = 'friends-twitter';
558 580 $file = 'templates/twitter/twitter.css';
559 - $version = Friends::VERSION;
581 + $version = $this->get_asset_version( $file );
560 582 wp_enqueue_style( $handle, plugins_url( $file, FRIENDS_PLUGIN_FILE ), array(), apply_filters( 'friends_debug_enqueue', $version, $handle, dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file ) );
561 583
562 - wp_enqueue_script( 'friends-twitter', plugins_url( 'templates/twitter/twitter.js', FRIENDS_PLUGIN_FILE ), array( 'jquery', 'friends' ), $version, true );
584 + $file = 'templates/twitter/twitter.js';
585 + wp_enqueue_script( 'friends-twitter', plugins_url( $file, FRIENDS_PLUGIN_FILE ), array( 'jquery', 'friends' ), $this->get_asset_version( $file ), true );
563 586 wp_localize_script(
564 587 'friends-twitter',
565 588 'friendsTwitter',
566 589 array(
@@ -579,12 +602,13 @@
579 602
580 603 public function google_reader_theme() {
581 604 $handle = 'friends-google-reader';
582 605 $file = 'templates/google-reader/google-reader.css';
583 - $version = Friends::VERSION;
606 + $version = $this->get_asset_version( $file );
584 607 wp_enqueue_style( $handle, plugins_url( $file, FRIENDS_PLUGIN_FILE ), array(), apply_filters( 'friends_debug_enqueue', $version, $handle, dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file ) );
585 608
586 - wp_enqueue_script( 'friends-google-reader', plugins_url( 'templates/google-reader/google-reader.js', FRIENDS_PLUGIN_FILE ), array( 'jquery' ), $version, true );
609 + $file = 'templates/google-reader/google-reader.js';
610 + wp_enqueue_script( 'friends-google-reader', plugins_url( $file, FRIENDS_PLUGIN_FILE ), array( 'jquery' ), $this->get_asset_version( $file ), true );
587 611
588 612 add_filter(
589 613 'friends_template_paths_theme_google-reader',
590 614 function ( $file_paths ) {
@@ -656,9 +680,9 @@
656 680 // No theme swap needed; templates are registered as plugin templates
657 681 // and injected via template_override.
658 682 $handle = 'friends-blocks';
659 683 $file = 'friends-blocks.css';
660 - $version = Friends::VERSION;
684 + $version = $this->get_asset_version( $file );
661 685 wp_enqueue_style( $handle, plugins_url( $file, FRIENDS_PLUGIN_FILE ), array(), apply_filters( 'friends_debug_enqueue', $version, $handle, dirname( FRIENDS_PLUGIN_FILE ) . '/' . $file ) );
662 686 }
663 687
664 688 /**
@@ -867,20 +891,21 @@
867 891 $author = User::get_post_author( get_post( $block->context['postId'] ) );
868 892 } else {
869 893 return '';
870 894 }
871 - if ( empty( $author ) ) {
895 + if ( empty( $author ) || is_wp_error( $author ) ) {
872 896 return '';
873 897 }
874 898
875 - $author_name = $author->display_name;
899 + $author_name = $author->display_name;
900 + $author_name_html = apply_filters( 'friends_author_display_name_html', esc_html( $author_name ), $author_name, $author );
876 901 $override_author_name = apply_filters( 'friends_override_author_name', '', $author_name, $block->context['postId'] );
877 902 if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
878 - $author_name = sprintf( '<a href="%1$s" target="%2$s" class="wp-block-post-author-name__link">%3$s</a>', $author->get_local_friends_page_url(), esc_attr( $attributes['linkTarget'] ), $author_name );
903 + $author_name_html = sprintf( '<a href="%1$s" target="%2$s" class="wp-block-post-author-name__link">%3$s</a>', esc_url( $author->get_local_friends_page_url() ), esc_attr( $attributes['linkTarget'] ), $author_name_html );
879 904 }
880 905
881 906 if ( $override_author_name && trim( str_replace( $override_author_name, '', $author_name ) ) === $author_name ) {
882 - $author_name .= ' – ' . esc_html( $override_author_name );
907 + $author_name_html .= ' – ' . esc_html( $override_author_name );
883 908 }
884 909
885 910 $classes = array();
886 911 if ( isset( $attributes['textAlign'] ) ) {
@@ -890,9 +915,25 @@
890 915 $classes[] = 'has-link-color';
891 916 }
892 917 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
893 918
894 - return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $author_name );
919 + return sprintf(
920 + '<div %1$s>%2$s</div>',
921 + $wrapper_attributes,
922 + wp_kses(
923 + $author_name_html,
924 + array_merge(
925 + wp_kses_allowed_html( 'post' ),
926 + array(
927 + 'a' => array(
928 + 'class' => true,
929 + 'href' => true,
930 + 'target' => true,
931 + ),
932 + )
933 + )
934 + )
935 + );
895 936 };
896 937 }
897 938 return $settings;
898 939 }
@@ -1263,14 +1304,15 @@
1263 1304 the_post();
1264 1305 $args = array(
1265 1306 'friends' => $friends,
1266 1307 );
1308 + $args['item_friend_user'] = User::get_post_author( $post );
1267 1309
1268 1310 if ( $known_author ) {
1269 1311 $args['friend_user'] = $known_author;
1270 1312 $args['avatar'] = $known_avatar;
1271 1313 } else {
1272 - $args['friend_user'] = User::get_post_author( $post );
1314 + $args['friend_user'] = $args['item_friend_user'];
1273 1315 $args['avatar'] = $args['friend_user']->get_avatar_url();
1274 1316 }
1275 1317
1276 1318 $read_time = self::calculate_read_time( get_the_content() );
@@ -1674,8 +1716,16 @@
1674 1716 $friends_args = array();
1675 1717 $path = 'frontend/subscriptions';
1676 1718 break;
1677 1719
1720 + case 'messages':
1721 + $friends_args = array(
1722 + 'title' => __( 'Direct Messages', 'friends' ),
1723 + 'no-bottom-margin' => true,
1724 + );
1725 + $path = 'frontend/messages';
1726 + break;
1727 +
1678 1728 case 'followers':
1679 1729 if ( ! class_exists( '\Activitypub\Collection\Followers' ) ) {
1680 1730 return 'frontend/index';
1681 1731 }
@@ -2168,8 +2218,13 @@
2168 2218 $is_friends = array_shift( $pagename_parts );
2169 2219
2170 2220 if ( 'friends' !== $is_friends ) {
2171 2221 return $query;
2222 + }
2223 +
2224 + if ( isset( $pagename_parts[0] ) && 'settings' === $pagename_parts[0] ) {
2225 + wp_safe_redirect( self_admin_url( 'admin.php?page=friends-settings' ) );
2226 + exit;
2172 2227 }
2173 2228
2174 2229 // Not available for the general public or friends.
2175 2230 $viewable = $this->has_required_priviledges() && Friends::on_frontend();