[grade=B] v1.9.2: hide raw YouTube URL above the video card (strip first YT link from displayed text, preserve trailing punctuation)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* Plugin Name: Beep
|
||||
* Description: A Twitter-style microblog for WordPress, with likes, replies, and Gravatars. Use the [beep_feed] shortcode on any page.
|
||||
* Version: 1.9.1
|
||||
* Version: 1.9.2
|
||||
* Requires at least: 6.0
|
||||
* Requires PHP: 7.4
|
||||
* Author: Sami Ahmed
|
||||
@@ -14,7 +14,7 @@ if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
define('BEEP_VERSION', '1.9.1');
|
||||
define('BEEP_VERSION', '1.9.2');
|
||||
define('BEEP_FILE', __FILE__);
|
||||
define('BEEP_DIR', plugin_dir_path(__FILE__));
|
||||
define('BEEP_URL', plugin_dir_url(__FILE__));
|
||||
|
||||
@@ -71,7 +71,7 @@ class Beep_Quotes {
|
||||
$avatar = esc_url($author['avatar']);
|
||||
$name = esc_html($author['name']);
|
||||
$handle = esc_html('@' . $author['username']);
|
||||
$content = make_clickable(wp_kses_post($quoted['content']));
|
||||
$content = make_clickable(wp_kses_post(beep_strip_youtube_link($quoted['content'])));
|
||||
$time = esc_html($quoted['time_ago']);
|
||||
$qid = esc_attr($quoted['id']);
|
||||
|
||||
|
||||
+29
-2
@@ -318,7 +318,7 @@ function beep_render_post($post, $args = []) {
|
||||
$time_iso = gmdate('c', $ts);
|
||||
$time_full = mysql2date('F j, Y g:i a', $post->post_date);
|
||||
|
||||
$content = beep_format_content($post->post_content);
|
||||
$content = beep_format_content(beep_strip_youtube_link($post->post_content));
|
||||
$like_count = Beep_Likes::get_count($post->ID, 'post');
|
||||
$reply_count = Beep_Replies::reply_count($post->ID);
|
||||
$user_liked = Beep_Likes::user_has_liked($post->ID, 'post');
|
||||
@@ -576,7 +576,7 @@ function beep_render_reply($comment, $all_comments = [], $depth = 0, $post_id =
|
||||
$time = beep_relative_time($ts);
|
||||
$time_iso = gmdate('c', $ts);
|
||||
|
||||
$content = beep_format_content($comment->comment_content);
|
||||
$content = beep_format_content(beep_strip_youtube_link($comment->comment_content));
|
||||
$can_delete = current_user_can('moderate_comments') || ($author_id && $author_id === get_current_user_id());
|
||||
$like_count = Beep_Likes::get_count($comment->comment_ID, 'reply');
|
||||
$user_liked = Beep_Likes::user_has_liked($comment->comment_ID, 'reply');
|
||||
@@ -740,6 +740,33 @@ function beep_render_youtube_card($text) {
|
||||
. '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the first YouTube URL from text (the one that gets a video card),
|
||||
* so the raw link doesn't display above the card. Returns text unchanged
|
||||
* when no YouTube link is present.
|
||||
*/
|
||||
function beep_strip_youtube_link($text) {
|
||||
$vid = beep_youtube_id_from_text($text);
|
||||
if ($vid === '') {
|
||||
return $text;
|
||||
}
|
||||
$stripped = preg_replace_callback(
|
||||
'~(?<![\w.-])(?:https?://)?(?:www\.|m\.)?(?:youtube\.com/(?:watch\?[^#\s]*v=|shorts/|embed/|live/)|youtu\.be/)[A-Za-z0-9_-]{11}(?![A-Za-z0-9_-])[^\s]*~i',
|
||||
function ($m) {
|
||||
// Preserve trailing sentence punctuation that the URL regex grabbed
|
||||
return preg_match('/([.,;:!?]+)$/', $m[0], $t) ? $t[1] : '';
|
||||
},
|
||||
(string) $text,
|
||||
1
|
||||
);
|
||||
if ($stripped === null) {
|
||||
return $text;
|
||||
}
|
||||
$stripped = preg_replace('~[ \t]{2,}~', ' ', $stripped);
|
||||
$stripped = preg_replace('~[ \t]+([.,;:!?])~', '$1', $stripped);
|
||||
return trim($stripped);
|
||||
}
|
||||
|
||||
function beep_relative_time($timestamp) {
|
||||
$now = time();
|
||||
$diff = $now - $timestamp;
|
||||
|
||||
+4
-1
@@ -4,7 +4,7 @@ Tags: microblog, twitter, tweets, social, comments, polls, elementor
|
||||
Requires at least: 6.0
|
||||
Tested up to: 6.9
|
||||
Requires PHP: 7.4
|
||||
Stable tag: 1.9.1
|
||||
Stable tag: 1.9.2
|
||||
License: GPLv2 or later
|
||||
|
||||
A Twitter-style microblog for WordPress. Posts, likes, replies, polls, quotes, GIFs, and Gravatars. Use [beep_feed] shortcode or Elementor widget.
|
||||
@@ -46,6 +46,9 @@ Features:
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.9.2 =
|
||||
* YouTube links no longer display as raw hyperlinks above the video card - the card replaces the URL text (posts, replies, and quoted beeps).
|
||||
|
||||
= 1.9.1 =
|
||||
* YouTube links in beeps, replies, and quoted beeps automatically render as a video card (thumbnail + play button; click to play inline). Supports youtube.com/watch, youtu.be, shorts, embed, and live URLs.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user