Our RJM Programming Linux CentOS Web Server cPanel Apache web serverโs suite of software has a very useful report called Apache Status. We use it a bit like another Linux user without this report might use โฆ
ps -ef
โฆ or โฆ
top
โฆ to monitor processes on the web server.
We noticed a particular URL call to (and โฆ Spoiler Alert โฆ now it is safe for us to offer it) โฆ
โฆ appeared to be โvery popularโ?! Hogwash! It panned out to be a โhanging around URLโ issue! Huh?! Yes, before todayโs fix, this WordPress Blog (you are reading) posting would cause a blank webpage. Now, in our experience with WordPress, this is highly unusual. Especially, the way, also, this webpage would โhang aroundโ with enough bad intention that even if logged into WordPress we could not reach the โAdd Postโ webpage to have a look at it. So, what is the alternative? Well, as we alluded to in WordPress Blog Post Frontend Error Tutorial, we used cPanelโs โphpMyAdminโ option to then (adding that after selecting correct WordPress database you need to use SQL to find the offending blog posting via SQL like
SELECT * FROM wps_posts WHERE post_name=โgmail-webmail-email-attachment-on-ipad-signature-reply-tutorialโ;
) โฆ
- select the relevant WordPress database
- pick the wps_posts table
- click โBrowseโ button
- check โEditโ button checkbox
- click โEditโ button
- modify the post_content field to fix the problem
- click โGoโ button at the bottom
โฆ and we used the content of the post_content field copied to the copy buffer to then construct a local disk HTML file and test with our MAMP local web server in an HTML Online Validator fashion ( via web browser address bar URL like HTTP://localhost:888/test.html here with macOS). What do you think happened?
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Nothing bad, just appropriate content. So saaaadddddd. What to do next? Well, we saved (ie. hived) that content away, but cleared it away from the blog post in that phpMyAdmin form to see whether we could access the โAdd Postโ webpage doing that. We could, giving us a chance to look at Custom Fields, perhaps, as the more likely source of problems out of Tags and Categories and them. Back at WordPress Landing Page Custom Fields Inhouse Media Tutorial we discussed this with some โlinksofuseโ logic to create those lightbulb ( 💡 ) emoji dropdowns you sometimes see, which present relevant links for further reading. Lo and behold, the Adobe second link weโd offered looked a bit dodgy?!
Long story short โฆ
- an initial fix of hiving off those links, but wiping โlinksofuseโ on this blog posting stopped the โhanging aroundโ symptoms โฆ
- adding back in the blog posting content, via that WordPress โAdd Pageโ webpage continued the improvement, with no โhanging aroundโ symptoms โฆ
- modifying the โlinksofuseโ Custom Field to just the first non-contentious link continued the improvement, with no โhanging aroundโ symptoms
โฆ and weโd have been happy to leave it at that, except a nagging thought about other blog postings, perhaps, having the same issues, persisted in our cranium โฆ so โฆ we looked into WordPress TwentyTen themeโs single.php (mainly โcodexโ) code for clues. We narrowed the issue down to the relationship between an Adobe URL and the use of PHP file_get_contents, and improved the situation via โฆ
<?php
$ch = curl_init(); // thanks to https://www.php.net/manual/en/ref.curl.php
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, "//" . explode("//", $encs[$iqs])[1]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$encc = curl_exec($ch);
curl_close($ch);
$enccont="";
if ($encc) {
try {
$enccont=@file_get_contents("//" . explode("//", $encs[$iqs])[1]);
} catch (Exception $eqgf) {
}
}
?>
โฆ allowing us to add back in that dodgy looking link, catered for! Aaaaaaah!
By the way, what is wrong with not worrying about this? Well, our hosting has a limit on MySql connection counts. Fill it with โhanging aroundโ ones, and the web server will eventually get quite unwell!
Previous relevant WordPress Landing Page Custom Fields Inhouse Media Tutorial is shown below.
The recent WordPress Landing Page Custom Fields Tutorial used window.open calls to access WordPress Blog Custom Field URLs, but some web browsers block these calls, and so, as of today, weโve made the reasoning more complex to allow for the possibility of โฆ
- displaying โinhouse mediaโ ( ie. on domain rjmprogramming.com.au ) in this same webpage up above the dropdown in an HTML iframe that is invisible to the user unless needed โฆ as per โฆ
- on domain rjmprogramming.com.au
- URL ends with .m* is opened in an HTML video element
- URL ends with .a* is opened in an HTML audio element
- URL ends with .* is opened in an HTML img element
โฆ else โฆ
- open URL in window.open([derivedURL],โ_blankโ); // call
These changes involve changes to three TwentyTen themed PHP files as per โฆ
- header.php โฆ
<<?php echo $heading_tag; ?> id="site-title">
<span id=hdgspan>
<a itemprop="name" id="ahomeis" href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a><iframe style="width:600px;height:600px;display:none;" name=hdgiframe id=hdgiframe srcdoc=''></iframe>
</span>
</<?php echo $heading_tag; ?>> - single.php โฆ
if ($encsuffix == "") { $encsuffix="<select id='linkhints' class='linkhints' TITLE='Our link hints for this blog posting' style='margin-right:20px;float:right;display:inline-block;width:60px;' onchange=\"if (this.value.length > 0) { if (this.value.toLowerCase().indexOf('rjmprogramming.com.au') != -1 && this.value.toLowerCase().indexOf('.htm') == -1 && this.value.toLowerCase().indexOf('.php') == -1 && this.value.toLowerCase().indexOf('.pdf') == -1 && this.value.toLowerCase().replace('.au','').slice(-5).indexOf('.') != -1 && document.getElementById('hdgiframe')) { document.getElementById('hdgiframe').style.display='block'; document.getElementById('hdgiframe').className='linkhints'; document.getElementById('hdgiframe').style.marginTop='20px'; document.getElementById('hdgiframe').style.marginBottom='20px'; document.getElementById('hdgiframe').onclick=function() { location.href='#linkhints'; }; location.href='#hdgiframe'; if (this.value.toLowerCase().indexOf('.m') != -1) { document.getElementById('hdgiframe').srcdoc='<html><body><video controls><source SRC=' + this.value + '></source></video></body></html>'; } else if (this.value.toLowerCase().replace('com.au','').indexOf('.a') != -1) { document.getElementById('hdgiframe').srcdoc='<html><body><audio controls><source SRC=' + this.value + '></source></audio></body></html>'; } else if (this.value.toLowerCase().replace('.pdf','').replace('com.au','').slice(-5).indexOf('.') != -1) { document.getElementById('hdgiframe').srcdoc='<html><body><style> html { background: url(' + this.value + ') no-repeat center fixed; background-size: contain; } </style><br></body></html>'; } else { document.getElementById('hdgiframe').src = this.value; } } else { window.open(this.value,'_blank'); } }\"><option value=''>💡</option></select>"; } - loop.php โฆ
if ($encsuffix == "") { $encsuffix="<select id='linkhints' class='linkhints' TITLE='Our link hints for this blog posting' style='margin-right:20px;float:right;display:inline-block;width:60px;' onchange=\"if (this.value.length > 0) { if (this.value.toLowerCase().indexOf('rjmprogramming.com.au') != -1 && this.value.toLowerCase().indexOf('.htm') == -1 && this.value.toLowerCase().indexOf('.php') == -1 && this.value.toLowerCase().indexOf('.pdf') == -1 && this.value.toLowerCase().replace('.au','').slice(-5).indexOf('.') != -1 && document.getElementById('hdgiframe')) { document.getElementById('hdgiframe').style.display='block'; document.getElementById('hdgiframe').className='linkhints'; document.getElementById('hdgiframe').style.marginTop='20px'; document.getElementById('hdgiframe').style.marginBottom='20px'; document.getElementById('hdgiframe').onclick=function() { location.href='#linkhints'; }; location.href='#hdgiframe'; if (this.value.toLowerCase().indexOf('.m') != -1) { document.getElementById('hdgiframe').srcdoc='<html><body><video controls><source SRC=' + this.value + '></source></video></body></html>'; } else if (this.value.toLowerCase().replace('com.au','').indexOf('.a') != -1) { document.getElementById('hdgiframe').srcdoc='<html><body><audio controls><source SRC=' + this.value + '></source></audio></body></html>'; } else if (this.value.toLowerCase().replace('.pdf','').replace('com.au','').slice(-5).indexOf('.') != -1) { document.getElementById('hdgiframe').srcdoc='<html><body><style> html { background: url(' + this.value + ') no-repeat center fixed; background-size: contain; } </style><br></body></html>'; } else { document.getElementById('hdgiframe').src = this.value; } } else { window.open(this.value,'_blank'); } }\"><option value=''>💡</option></select>"; }
Stop Press
In a future blog posting (that will be accessible via this WordPress Recent Post Bug Fix Tutorial link in days to come) you will read how our work here interfered a little with the WordPress โRecent Postsโ widget inhouse enhancements we last talked about at WordPress Recent Post Semi-Transparent Background Tutorial. Where we have blue code snippets above you can see us getting this work to live in its environment better with some uppercase and spacing changes.
23/10/2019
Did you know?
Did you wonder about (the code snippet comparison) โฆ
<style> html { background: url(' + this.value + ') no-repeat center fixed; background-size: contain; } </style>
โฆ rather, than, say โฆ
<img src=' + this.value + '></img>
โฆ above? Well, itโs to do with the situation where you set aside a set width and height of space (600px X 600px for us) in an HTML iframe and want to โhostโ an image media source. The question you need to ask is โฆ โIs it more important to show an image in its original dimensions, or would a proportional view (ie. keep the same aspect ratio) of the image be okay?โ If the latter is the case, then that style tag approach way above (that can be placed into the webpageโs head or body sections) that we started using when we presented the recent Full Sized Fixed Background Image Primer Tutorial (except on that occasion cover was used rather than todayโs contain usage) allows for a full view of the imageโs content.
Previous relevant WordPress Landing Page Custom Fields Tutorial is shown below.
WordPress blog PHP logic, such as used behind the scenes of WordPress Custom Fields Primer Tutorial, as far as its โloopโ arrangements go, separates into two modes, those being โฆ
- single blog posting mode of access that suited yesterdayโs changes to the WordPress TwentyTen themed blogโs โsingle.phpโ modifications (for URLs like https://www.rjmprogramming.com.au/ITblog/?p=[postID] or https://www.rjmprogramming.com.au/ITblog/[post-slug-permalink]) which distinguish themselves that during the โloopโ logic of โsingle.phpโ the PHP $post object exists (and so the $post->ID of โ$enclosurev = get_post_meta($post->ID, โlinksofuseโ, true);โ below makes sense) โฆ whereas, today โฆ
- multiple blog posting non-search, non-tag, non-category mode of access suits, instead, (just before) the last reference to โ<?php the_content(โ within its โ<?php while ( have_posts() ) : the_post(); ?gt; โฆ innards โฆ <?php endwhile; // end of the loop. ?>โ code snippet of WordPress TwentyTen themed blogโs โloop.phpโ (we found out, again, via โ<?php echo โyoo hoo!โ; ?>โ experiments) modifications (for URL like https://www.rjmprogramming.com.au/ITblog/) which replace the
โ$enclosurev = get_post_meta($post->ID, โlinksofuseโ, true);โwith โ$enclosurev = get_metadata(โpostโ, get_the_ID(), โlinksofuseโ, true);โ (because in โloop.phpโ (last incarnation of โ<?php the_content(โ) the $post object does not exist)
In summary, the intervention code directly before โloop.phpโโs โ<?php while ( have_posts() ) : the_post(); ?> โฆ innards โฆ <?php endwhile; // end of the loop. ?>โโs last incarnation of โ<?php the_content(โ goes, for us โฆ
<?php
$encsuffix='';
$enclosurev = get_metadata('post', get_the_ID(), 'linksofuse', true);
if ($enclosurev) {
if (strpos($enclosurev, "-") !== false || strpos($enclosurev, ",") !== false || strpos($enclosurev, "//") !== false) {
$encs=explode(",", $enclosurev);
for ($iqs=0; $iqs<sizeof($encs); $iqs++) {
if ($encsuffix == "") { $encsuffix="<select id='linkhints' class='linkhints' title='Our link hints for this blog posting' style='margin-top:-30px;margin-right:20px;float:right;display:inline-block;width:60px;' onchange=\"if (this.value.length > 0) { window.open(this.value,'_blank'); }\"><option value=''>💡</option></select>"; }
if (strpos($encs[$iqs], "//") !== false) {
$enctitle="URL " . $encs[$iqs];
$enccont=@file_get_contents("//" . explode("//", $encs[$iqs])[1]);
if (strpos($enccont, "</title>") !== false) {
$enctitle=explode(">", explode("</title>", $enccont)[0])[-1 + sizeof(explode(">", explode("</title>", $enccont)[0]))];
}
$encsuffix=str_replace("</select>", "<option value='" . $encs[$iqs] . "'>" . $enctitle . "</option></select>", $encsuffix);
} else if (strpos($encs[$iqs], "-") !== false) {
$encsm=explode("-", $encs[$iqs]);
$encsuffix=str_replace("</select>", "<option value='//www.rjmprogramming.com.au/ITblog/" . $encs[$iqs] . "'></option></select>", $encsuffix);
$enctitle=strtoupper(substr($encsm[0],0,1)) . strtolower(substr($encsm[0],1));
for ($jqs=1; $jqs<sizeof($encsm); $jqs++) {
$enctitle.=" " . strtoupper(substr($encsm[$jqs],0,1)) . strtolower(substr($encsm[$jqs],1));
}
$encsuffix=str_replace("></option></select>", ">" . $enctitle . "</option></select>", $encsuffix);
} else {
if (substr($encs[$iqs],0,1) >= '0' && substr($encs[$iqs],0,1) <= '9') {
$enctitle="Blog Posting " . $encs[$iqs];
$enccont=@file_get_contents("https://www.rjmprogramming.com.au/ITblog/?p=" . $encs[$iqs]);
if (strpos($enccont, "</title>") !== false) {
$enctitle=explode(">", explode("</title>", $enccont)[0])[-1 + sizeof(explode(">", explode("</title>", $enccont)[0]))];
}
$encsuffix=str_replace("</select>", "<option value='" . "//www.rjmprogramming.com.au/ITblog/?p=" . $encs[$iqs] . "'>" . $enctitle . "</option></select>", $encsuffix);
} else if (strpos($encs[$iqs], "/tag/") !== false) {
$enctitle="Blog Tag " . str_replace("-"," ",str_replace("/tag/","",$encs[$iqs]));
$enccont=@file_get_contents("https://www.rjmprogramming.com.au/ITblog" . $encs[$iqs]);
$encsuffix=str_replace("</select>", "<option value='" . "//www.rjmprogramming.com.au/ITblog" . $encs[$iqs] . "'>" . $enctitle . "</option></select>", $encsuffix);
} else if (strpos($encs[$iqs], "/category/") !== false) {
$enctitle="Blog Category " . str_replace("-"," ",str_replace("/category/","",$encs[$iqs]));
$enccont=@file_get_contents("https://www.rjmprogramming.com.au/ITblog" . $encs[$iqs]);
$encsuffix=str_replace("</select>", "<option value='" . "//www.rjmprogramming.com.au/ITblog" . $encs[$iqs] . "'>" . $enctitle . "</option></select>", $encsuffix);
} else if (strpos($encs[$iqs], "tag/") !== false) {
$enctitle="Blog Tag " . str_replace("-"," ",str_replace("tag/","",$encs[$iqs]));
$enccont=@file_get_contents("https://www.rjmprogramming.com.au/ITblog/" . $encs[$iqs]);
$encsuffix=str_replace("</select>", "<option value='" . "//www.rjmprogramming.com.au/ITblog/" . $encs[$iqs] . "'>" . $enctitle . "</option></select>", $encsuffix);
} else if (strpos($encs[$iqs], "category/") !== false) {
$enctitle="Blog Category " . str_replace("-"," ",str_replace("category/","",$encs[$iqs]));
$enccont=@file_get_contents("https://www.rjmprogramming.com.au/ITblog/" . $encs[$iqs]);
$encsuffix=str_replace("</select>", "<option value='" . "//www.rjmprogramming.com.au/ITblog/" . $encs[$iqs] . "'>" . $enctitle . "</option></select>", $encsuffix);
}
}
}
}
}
echo $encsuffix;
?>
And so, again, we say โฆ
I spy with my little eye something beginning with โฆ
Yes,
Up above,![]()
โฆ and which a click on the blog image today gets you to, a webpage of allthis blogโs recent posts.
Previous relevant WordPress Custom Fields Primer Tutorial is shown below.
I spy with my little eye something beginning with โฆ
Yes,
Up above,![]()
Aw ... what a bright idea?! How come I click on the light bulb () and it has dropdown options unique to this blog post?
Glad you asked. And all because โฆ
Letโs talk about WordPress blog Custom Fields, and an associated great link we stumbled upon. We followed its advice to change Theme code โฆ yay!!!! Except this time, it wasnโt (good olโ) header.php that changed for our Custom Field foray (weโve codenamed โOperation 4Aโ โฆ tee hee).
Working to a plan like this, often the first question is (especially with event-driven programming code) โWhere is the intervention point?โ.
You will need to enter your custom fields code inside the WordPress loop.
Look for the line that looks like this:
<?php while ( have_posts() ) : the_post(); ?>
You want to make sure that you add your code before the following line:
<?php endwhile; // end of the loop. ?>
โฆ good advice, and looking in the themes โtwentytenโ folder several PHP files had these two. But trial and error (just placing <?php echo โyoo hoo!โ; ?>) we found that โsingle.phpโ could be tweaked to change the WordPress blog webpage here, and intervene. Place the intervention near โendwhileโ and it goes down the bottom of the postโs content, and near โwhile ( have_posts() ) : the_post();โ you get it up near the top of the postโs content (the placement we opted for).
Working to a plan like this, often the next question is โWhat do you want to do now that you know where to intervene?โ and here we decided we wanted a dropdown way to navigate to links that are related to the content in one of 5 ways โฆ
- a number corresponds to a posting number webpage at the WordPress (TwentyTen themed) blog here
- a โ-โ (no spaces) delimited single โslugโ word corresponds to this WordPress blog permalink
- โtag/[tag-words]โ corresponds to this WordPress [tag-words] tag lookup
- โcategory/[category-words]โ corresponds to this WordPress [category-words] category lookup
- absolute URL will add to dropdown and try to navigate there
โฆ to allow the user to โread upโ on the posting to follow, perhaps.
And so โฆ โHow come I click on the light bulb and it has dropdown options unique to this blog post?โ
The intervention code in โsingle.phpโ directly under โ<?php while ( have_posts() ) : the_post(); ?>โ โฆ
<?php
$encsuffix='';
$enclosurev = get_post_meta($post->ID, 'linksofuse', true);
if ($enclosurev) {
if (strpos($enclosurev, "-") !== false || strpos($enclosurev, ",") !== false || strpos($enclosurev, "//") !== false) {
$encs=explode(",", $enclosurev);
for ($iqs=0; $iqs<sizeof($encs); $iqs++) {
if ($encsuffix == "") { $encsuffix="<select id='linkhints' class='linkhints' title='Our link hints for this blog posting' style='margin-right:20px;float:right;display:inline-block;width:60px;' onchange=\"if (this.value.length > 0) { window.open(this.value,'_blank'); }\"><option value=''>💡</option></select>"; }
if (strpos($encs[$iqs], "//") !== false) {
$enctitle="URL " . $encs[$iqs];
$enccont=@file_get_contents("//" . explode("//", $encs[$iqs])[1]);
if (strpos($enccont, "</title>") !== false) {
$enctitle=explode(">", explode("</title>", $enccont)[0])[-1 + sizeof(explode(">", explode("</title>", $enccont)[0]))];
}
$encsuffix=str_replace("</select>", "<option value='" . $encs[$iqs] . "'>" . $enctitle . "</option></select>", $encsuffix);
} else if (strpos($encs[$iqs], "-") !== false) {
$encsm=explode("-", $encs[$iqs]);
$encsuffix=str_replace("</select>", "<option value='//www.rjmprogramming.com.au/ITblog/" . $encs[$iqs] . "'></option></select>", $encsuffix);
$enctitle=strtoupper(substr($encsm[0],0,1)) . strtolower(substr($encsm[0],1));
for ($jqs=1; $jqs<sizeof($encsm); $jqs++) {
$enctitle.=" " . strtoupper(substr($encsm[$jqs],0,1)) . strtolower(substr($encsm[$jqs],1));
}
$encsuffix=str_replace("></option></select>", ">" . $enctitle . "</option></select>", $encsuffix);
} else {
if (substr($encs[$iqs],0,1) >= '0' && substr($encs[$iqs],0,1) <= '9') {
$enctitle="Blog Posting " . $encs[$iqs];
$enccont=@file_get_contents("https://www.rjmprogramming.com.au/ITblog/?p=" . $encs[$iqs]);
if (strpos($enccont, "</title>") !== false) {
$enctitle=explode(">", explode("</title>", $enccont)[0])[-1 + sizeof(explode(">", explode("</title>", $enccont)[0]))];
}
$encsuffix=str_replace("</select>", "<option value='" . "//www.rjmprogramming.com.au/ITblog/?p=" . $encs[$iqs] . "'>" . $enctitle . "</option></select>", $encsuffix);
} else if (strpos($encs[$iqs], "/tag/") !== false) {
$enctitle="Blog Tag " . str_replace("-"," ",str_replace("/tag/","",$encs[$iqs]));
$enccont=@file_get_contents("https://www.rjmprogramming.com.au/ITblog" . $encs[$iqs]);
$encsuffix=str_replace("</select>", "<option value='" . "//www.rjmprogramming.com.au/ITblog" . $encs[$iqs] . "'>" . $enctitle . "</option></select>", $encsuffix);
} else if (strpos($encs[$iqs], "/category/") !== false) {
$enctitle="Blog Category " . str_replace("-"," ",str_replace("/category/","",$encs[$iqs]));
$enccont=@file_get_contents("https://www.rjmprogramming.com.au/ITblog" . $encs[$iqs]);
$encsuffix=str_replace("</select>", "<option value='" . "//www.rjmprogramming.com.au/ITblog" . $encs[$iqs] . "'>" . $enctitle . "</option></select>", $encsuffix);
} else if (strpos($encs[$iqs], "tag/") !== false) {
$enctitle="Blog Tag " . str_replace("-"," ",str_replace("tag/","",$encs[$iqs]));
$enccont=@file_get_contents("https://www.rjmprogramming.com.au/ITblog/" . $encs[$iqs]);
$encsuffix=str_replace("</select>", "<option value='" . "//www.rjmprogramming.com.au/ITblog/" . $encs[$iqs] . "'>" . $enctitle . "</option></select>", $encsuffix);
} else if (strpos($encs[$iqs], "category/") !== false) {
$enctitle="Blog Category " . str_replace("-"," ",str_replace("category/","",$encs[$iqs]));
$enccont=@file_get_contents("https://www.rjmprogramming.com.au/ITblog/" . $encs[$iqs]);
$encsuffix=str_replace("</select>", "<option value='" . "//www.rjmprogramming.com.au/ITblog/" . $encs[$iqs] . "'>" . $enctitle . "</option></select>", $encsuffix);
}
}
}
}
}
?>
โฆ looks for an optionally filled in blog posting Custom Field called โlinksofuseโ for a comma separated list of links as per the 5 types of definitions above, and shows these as dropdown option values under that light bulb () under the blog posting title before the blog posting content (that includes the blog posting image we always have).
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.