What is the downside of using a filter as a “poor man’s” dependency injection?
What is the downside of using a filter as a “poor man’s” dependency injection?
What is the downside of using a filter as a “poor man’s” dependency injection?
How to Get WP_Customize_Image_Control content?
Yes absolutely, It would be great to abstract away your queries at a single place. You might also use caching in your repository.
There’s nothing wrong with using the global $post variable per se, although there are people who will say that using global variables is always bad. But since you’re using it multiple times in the same object, it would be better to just get the post once and store it in a class property. I prefer … Read more
The example in Settings API documentation uses admin_init and admin_menu for registering custom settings and admin pages. https://developer.wordpress.org/plugins/settings/custom-settings-page/ There’s also an old Codex entry on actions typically run on front and back end requests, which can help pick a suitable action hook. https://codex.wordpress.org/Plugin_API/Action_Reference I also highly recommend the excellent old Q&A about instantiating classes in … Read more
Ok, so this is how I did it, and it’s not an awful hack. So my problem was passing values (in this case, query args) to a callback function from a instance of a class that was created BEFORE the query args existed. The transient approach worked but can break anytime. So when the function … Read more
If you look at the documentation for get_term_by(), you’ll see that it: Will return false if $taxonomy does not exist or $term was not found. You need to account for this possibility in your code by checking the value of $term. You’ll also note from the documentation that get_term_by() does not return a WP_Error, so … Read more
You’re not doing anything unusual or unsafe. You are just defining functions, which is a perfectly normal and reasonable thing to do with JavaScript. If there’s a malicious script running on your page then sure, it could redefine those methods, but it could also do other things that much worse. This is why you need … Read more
If you use the WordPress API to retrieve the metadata, then it should be cached for you. If you do other complex stuff, there is the Transients API for caching data yourself, which will take advantage of whatever object cache you use with WordPress. EDIT – I should clarify, it’ll be loaded for each request … Read more
I’m not 100% sure, but this problem seems related to the unfiltered_html capability restriction. unfiltered_html Since 2.0 Allows user to post HTML markup or even JavaScript code in pages, posts, and comments. Note: Enabling this option for untrusted users may result in their posting malicious or poorly formatted code. An easy fix (and probably a … Read more