Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
noblogs-wp-ssl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Noblogs
noblogs-wp-ssl
Commits
9633e795
Commit
9633e795
authored
9 years ago
by
sand
Browse files
Options
Downloads
Patches
Plain Diff
add a filter for 'the_content'
Now the plugin has 2 filters: - output buffer (disabled) - 'the_content'
parent
b6a45e02
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
noblogs-wp-ssl.php
+27
-10
27 additions, 10 deletions
noblogs-wp-ssl.php
with
27 additions
and
10 deletions
noblogs-wp-ssl.php
+
27
−
10
View file @
9633e795
...
...
@@ -2,7 +2,7 @@
/*
Plugin Name: Noblogs Wp SSL
Plugin URI: https://git.autistici.org/ai/noblogs-wp-ssl
Description: Rewrite internal URLS to use HTTPS
Description: Rewrite internal URLS to use HTTPS
.
Version: 0.1
Author: Cloudflare, sand
License: GPLv2
...
...
@@ -17,7 +17,15 @@ if ( !function_exists('add_action') ) {
exit
;
}
function
wp_ssl_buffer_wrapup
(
$buffer
)
{
function
rewrite_links
(
$buffer
)
{
// replace href or src attributes within script, link, base, and img tags with just "//" for protocol
$re
=
"/(<(?:script|link|base|img|form)(?:[^>]*)(?:href|src|action)=[
\"
'])http:
\\
/
\\
/([^.]+\.noblogs\.org)/i"
;
$subst
=
"$1https://$2"
;
return
preg_replace
(
$re
,
$subst
,
$buffer
);
}
// This is a filter function that act on the whole output buffer
function
noblogs_wp_ssl_buffer_wrapup
(
$buffer
)
{
// skip rewrite if not on HTTPS
if
(
empty
(
$_SERVER
[
'HTTPS'
]))
{
return
$buffer
;
...
...
@@ -36,10 +44,7 @@ function wp_ssl_buffer_wrapup($buffer) {
}
if
(
is_null
(
$content_type
)
||
substr
(
$content_type
,
0
,
9
)
===
'text/html'
)
{
// replace href or src attributes within script, link, base, and img tags with just "//" for protocol
$re
=
"/(<(?:script|link|base|img|form)(?:[^>]*)(?:href|src|action)=[
\"
'])http:
\\
/
\\
/([^.]+\.noblogs\.org)/i"
;
$subst
=
"$1https://$2"
;
$return
=
preg_replace
(
$re
,
$subst
,
$buffer
);
$return
=
rewrite_links
(
$buffer
);
// on regex error, skip overwriting buffer
if
(
$return
)
{
...
...
@@ -50,8 +55,20 @@ function wp_ssl_buffer_wrapup($buffer) {
return
$buffer
;
}
function
wp_ssl_buffer_init
()
{
ob_start
(
'wp_ssl_buffer_wrapup'
);
// This is a filter function that act on the post $content
function
noblogs_wp_ssl_content_filter
(
$content
)
{
// skip rewrite if not on HTTPS
if
(
empty
(
$_SERVER
[
'HTTPS'
]))
{
return
$buffer
;
}
$return
=
rewrite_links
(
$content
);
if
(
$return
)
{
$content
=
$return
;
}
return
$content
;
}
add_action
(
'plugins_loaded'
,
'wp_ssl_buffer_init'
);
// ob_start('wp_ssl_buffer_wrapup');
add_filter
(
'the_content'
,
'noblogs_wp_ssl_content_filter'
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment