Latest "WordPress" files
private » Programming Hacks Used In This Site

War And Precedence: Plugin positioning of unpositioned elements that aren’t yet positioned by later-loading stylesheets: A CSS Odyssey

So, I had a crazy problem. You'll notice that there's various draggable elements on this site... such as the "Kupietools" plugin tabs seen at left, the occasional "the site is being worked on right now" notices that pop up, etc. You can drag them around with your mouse.

This is done with a plugin (also available as a standalone javascript module, a few versions behind the plugin as I write this) that retrofits code onto various HTML elements by giving the plugin the classnames it needs to make interactive.

I was doing some optimization on the site loading to speed things up, such as getting WordPress to load a lot of CSS file late so as not to interfere with initial page load stats. (This is a whole art, beyond the scope of this article.)
Suddenly…

Workshop » Reference Section » Grimoires » IT » Platforms » Web » WordPress » Yoast

CURL and Browser get different page versions (301 redirects, content changed, etc. — due to Yoast url parameter stripping only for non-logged-in users)

I had a truly maddening problem where my /embed/ functionality was sometimes returning full pages to CURL commands and online services like redirect-checker.org, etc.

It turned out, it was Yoast's URL parameter stripping. I had failed to update Yoast's settings with some new parameters I was using, and what Yyoast never tells you is that when you're logged in, it lets everything work fine, and only strips parameters for non-logged in users. It just lets you proceed on your way thinking everything is working fine until you can't figure out why curl -I https://mysite.com/blah?param1¶m2 is getting a 301 redirect while https://mysite.com/blah?param1¶m2 is loading fine in your browser. This is especially fun on sites like mine where things like /embed/ and ?embed get written back and forth to each other internally.

I lost several hours to this.

Yoast's docs say there's a way of registering parameters but,…

Workshop » Reference Section » Grimoires » IT » Platforms » Linux » Packages » SQL

SQL query to list all WordPress post revisions for archiving

Here's the SQL query to get all post revisions, which I do prior to cleaning them out of the database, which seems to make it much faster:

SELECT p.*
FROM [posts table name] p
WHERE (p.post_type = 'post' OR p.post_type = 'page') -- Include posts/pages
AND (p.post_date BETWEEN '2020-01-01' AND '2029-07-01') -- Adjust date range
OR (p.post_type = 'revision' AND p.post_parent IN (
SELECT ID FROM [posts table name]
WHERE post_date BETWEEN '2024-01-01' AND '2024-07-01'
));

To get just a count of revisions, change SELECT p.* to SELECT count(*).

Workshop » Reference Section » Grimoires » IT » Troubleshooting log » WordPress

Deactivating, deleting, and completely removing a plugin that WordPress won’t let you deactivate

I installed the WordPress plugin LWS Optimize, which turned out to be unusably broken (which is the reason I'm not linking to it) and made my site unusable. To make matters worse, when I tried to deactivate it, it told me it deactivated... and was still active. I went in through FTP and deleted the plugin folder entirely, and then WordPress said it had been deactivated because it couldn't be found... and it still showed as present and activated in the plugin list.

So I added this to my theme's functions.php file:

add_action('admin_init', function() {
$active_plugins = get_option('active_plugins');
$plugin_to_remove = 'lws-optimize/lws-optimize.php';

if (($key = array_search($plugin_to_remove, $active_plugins)) !== false) {
unset($active_plugins[$key]);
update_option('active_plugins', array_values($active_plugins));
}
});

I then reloaded an admin page and removed that. That deactivated the plugin in the plugins list, but then when I hit the "delete" link, it said it…