I was able to use the following regex to cover all tags & attributes with protocols:
/<(?:input\b[^<]*\bvalue=[\"\']https?:\/\/|link\b[^<]*?\brel=[\'\"]canonical[\'\"][^<]*?>)(*SKIP)(*F)|https?:\/\//
This is the updated section:
# If 'Relative' option is selected, remove domain from all internal links
$exceptions="<(?:input\b[^<]*\bvalue=[\"\"]https?:\/\/|link\b[^<]*?\brel=[\'\"]canonical[\'\"][^<]*?>)(*SKIP)(*F)';
if ( $this->option == 2 ) {
$website = preg_replace( '/https?:\/\//', '', home_url() );
$links = preg_replace( "https://wordpress.stackexchange.com/" . $exceptions . '|https?:\/\/' . $website . "https://wordpress.stackexchange.com/", '', $links );
}
# For all external links, remove protocols
$links = preg_replace( '/<(?:input\b[^<]*\bvalue=[\"\']https?:\/\/|link\b[^<]*?\brel=[\'\"]canonical[\'\"][^<]*?>)(*SKIP)(*F)|https?:\/\//', '//', $links );
Related Posts:
- Dynamic URL to reference custom PHP files
- How to use $_GET function WordPress backend
- How does one make a URL return dynamic JSON with custom Content Type?
- WordPress add_rewrite_rule
- Create a custom plugin with dynamic child pages listing database records
- When to use Exceptions vs Error Objects vs just plain false/null
- Is it safe to use $_SERVER[‘REQUEST_URI’]?
- The correct method to pass query vars in AJAX using ajaxurl
- WordPress URL Rewrite not working
- How to check if feed URL was requested?
- Detect a focus on wp_editor
- simple wordpress ajax plugin not working when not logged in
- Utilize WP-CLI from inside WordPress, not SSH
- Saving metabox repeatable fields
- how to create and show sessions in word press?
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- do not show web page section when using advanced custom fields pro
- How to get all existing post types
- New Plugin Review
- Create custom blocks for bootstrap
- allow users to publish without admin approval
- Wrap First Character after in a tag
- Query String being Removed Creating a Pagination Issue within a Custom Plugin
- Remove query string specific key value
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- Do my defines need to be unique?
- WordPress Scheduled Event Request Blocking
- Delete a WordPress transient from a shortcode on Page/Post update
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- Saving an array of dynamic repeater data as post_meta
- WordPress wpform plugin submit and get multiple checked value from checkbox [closed]
- Improve page speed loading using CDN and async or defer attribute
- Applying A Category to Existing Posts Where Page Title Matches Regex
- Script to browser problem PHP
- Store a default value for a transient on plugin activation
- wp query foreach deleting record returning only first or last item
- How to make own crop image function for WordPress plugin
- How can I hide that I Use WordPress (with W3 Total Cache)
- wp_insert_post: array only. wp_update_post: array|object (?)
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Post’s ID pattern?
- Building a REST API for your web app exposes primary keys of DB records?
- Custom meta box values are not getting saved for my custom post type
- Extract links from content
- Custom Registration username_exists / email_exists
- How can I search all plugins for composer’s vendor/autoload.php?
- How do i add slugs to a URL, but still redirecting to the same page
- Action Hook Inside WordPress Plugin Shortcode
- Nginx WordPress and another Web app URL structure
- Can I remove or edit an include() from a function with a filter?
- how to get attached file url for current post?
- Creating customized php files in theme folder
- Submit form to db
- Add a custom WooCommerce settings tab with sections
- Workaround for og:image unsupported webp image type, Yoast SEO?
- PHP using external anonymous function inside class
- Using ACF Relationship field to set post type to draft or published status
- Add Pre-Defined Value to Click Counter in WordPress
- How can i avoid duplicate same post in wp?
- Drop down question
- code that I can run, or a plug in to show what sql tables something pulls information from
- Automatic email message after manual user approval
- custom mailchimp form using HTTP API
- How to override theme’s public static function inside of a trait?
- pass datetime using wp_localize_script to frontend from settings page
- add custom metabox to media library custom widget
- using filter and hook inside class
- Get WordPress username to customize url
- Display attached images of a page or post that are insetred using gallery
- overwrite wordpress gallery with custom gallery shortcode
- Enqueue sripts and styles only if function is called
- Add widget area from visual editor
- Register/enqueue scripts only on certain admin pages
- Looping through custom data in a custom table to display all items in a post
- Priority call methods – PHPMailer->addAddress(NULL)
- not able to access $_POST on backend profile update
- Need to Echo A Url path to show on a wordpress page
- Custom Plugin Develoment, Form Action
- WordPress Query Crashes Browser
- How to send logs to plugin owner for a plugin?
- How to Request a User to Register on Landing at a Site, Then Automatically Delete the Users Password on Logout?
- Plugin Modification Change Functionality For Logged User Only
- Force CSV download with template_redirect
- INCOMING: Wall of code for form and $_POST, not updating custom field’s value
- add shortcode heading showing multiple time
- WP multisite network plugin fails to see classes loaded with spl autoload
- Passing multiple variables through url (php)
- AJAX & PHP | Call a specific PHP function from a PHP file via AJAX?
- What is this mark for “? function()” [closed]
- Remove /category/ from category (archive) page URLs (without using a plugin)
- using a shortcode in a hyperlink
- How to automatically convert images to WebP on WordPress?
- Import js variables loaded via wp_localize_script() into js module without global scope connection
- Custom taxonomy with page post type – WordPress
- Query posts by custom taxonomy slug in WP REST API?
- oneOf JSON Schema validation not properly working for custom post meta value?
- Is there a way to get wp_editor (tinymce) content?
- How to cut a section of a URL from a string with a regular expression?
- Too few arguments at registering new templates in my plugin
- I want to lists posts in wordpress to nearest location entered by the user