Skip to main content
Share Your Experience: Take the 2024 Developer Survey
6 votes
Accepted

Modify a WordPress loop to show posts of certain categories, based on user roles

Optimizations I recommend separating the logic from the functionality, as well as using a generalized filter instead of explicit conditionals. You should avoid declaring functions, classes, and ...
Will B.'s user avatar
  • 176
5 votes
Accepted

cron daily and weekly scripts for a minimal Nginx server environment

As mentioned by cas in the discussion, you can simplify your loops: ...
Stephen Kitt's user avatar
5 votes

Ensure that all `h2` tags have a `span` inserted

I would agree with discussion in comments that this should be looked at as a stop-gap solution only, as the real answer here is to change the HTML source, or better yet, the CSS styling for the ...
Mike Brant's user avatar
  • 9,608
4 votes

Ensure that all `h2` tags have a `span` inserted

Since the other answer and comments already pointed out the semantical optimizations, here's a rather syntactical one. The code does exactly the same as the one you have, but faster. ...
Hugo G's user avatar
  • 364
4 votes

PHP create JSON file from Twitter API

This is a partial review. $file_loc and $json_folder Use $json_folder in the construction ...
Sumurai8's user avatar
  • 2,595
4 votes
Accepted

Check if a postcode is in a list

Inside of a function call, avoid echoing. By hardcoding echoes, you prevent the "silent" usage of the function. It may be necessary in the future to present the output in more than one format, so ...
mickmackusa's user avatar
  • 8,674
4 votes

Shorten and optimize php custom code for wordpress page template and use shortcodes

Here is an improvement, but I would recommend a few additional changes as well. ...
Phil F's user avatar
  • 186
4 votes

Woocommerce order change status

This is a partial review only, I may edit this post later as more details become available. I am not familiar with woocommerce at all. You may have design constraints but I would strongly recommend to ...
Kate's user avatar
  • 6,753
3 votes
Accepted

Wordpress downloader and unpacker

You don't need to escape slashes for grep, you can simplify to: ...
janos's user avatar
  • 111k
3 votes

WordPress Post Type template

Your code looks good, (although I did not review each particular) The only thing that stood out to me is that your files do not begin with a check to see if the file is being accessed directly. You ...
Daniel H's user avatar
3 votes

Custom Homepage

I wanted to give some thoughts around coding style. I know you are working in Wordpress which, as a code base, does a relatively poor job in reinforcing good coding style. So if, any of my comments ...
Mike Brant's user avatar
  • 9,608
3 votes
Accepted

Webapp Substrate script for WordPress on Debian-Nginx

The outer heredoc construct isn't really required. You do not verify that you have command line arguments. You do not assign your command line arguments to the variable ...
user157887's user avatar
3 votes
Accepted

chmod all .htaccess files under all website dirs under public_html dir

Instead of manually scanning each files and directory and testing if they are a directory using pushd, I would directly try to target ...
301_Moved_Permanently's user avatar
3 votes

Performance of WordPress Plugin is currently very bad and needs to be improved

If you don't need to worry about WordPress filters on getting post meta, you probably can just do this with a single SQL statement and iterate through the results, rather than relying on WordPress to ...
Phil F's user avatar
  • 186
3 votes

Function for iterating out an unordered list of custom taxonomy terms

As pointed out, there is a lot of code repetition and this is a big problem when any changes get made. It's so easy to quickly make a change to one piece of code and miss the 3 other versions of it ...
Nigel Ren's user avatar
  • 368
3 votes
Accepted

Adding CSS to each page on WordPress

A simpler approach to add the style can be used Per your request: I'd like my code to be \$O(1)\$ not \$O(n)\$. I haven’t tested this but based on this SO answer using ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
3 votes
Accepted

Instantiating classes in WordPress plugin

1. The constructor is not a good place for actions & filters. See this very detailed answer from WP.SE or this blog post for some reasoning. As far as I understand, it makes testing much more ...
kero's user avatar
  • 146
3 votes
Accepted

Custom Block with ACF in WordPress

Regarding readability/maintainability, my eye is drawn toward missed opportunities to practice D.R.Y. coding practices. I will suggest ways to make less verbose/repeated code, avoid heavily ...
mickmackusa's user avatar
  • 8,674
2 votes
Accepted

Re-sorting newsfeed based on date

You may not be to concerned about performance, but there actually is a lot of room for improvement here. Have a look at the refactored code first: ...
Pevara's user avatar
  • 842
2 votes

Handling a WordPress form with multiple checkboxes

You are open to reflected XSS via show_img_url. You should always HTML encode user input when outputting it. You don't really need to add the class to each cell. ...
tim's user avatar
  • 25.1k
2 votes
Accepted

Laravel Wordpress REST API Controller

In this example I'm using this curl wrapper. I have created separate class to take care of querying rest api as this logic should not be in controller. Names could use some more polishing but in ...
xReprisal's user avatar
  • 331
2 votes
Accepted

Moving WordPress database and files to new host

Make input validation more user-friendly You ask to enter host, user and port, and if one of them is empty you exit. If I entered a host and a user and accidentally pressed enter for port (empty), I ...
janos's user avatar
  • 111k
2 votes
Accepted

Responsive jQuery menu

Ok, let's talk about the elephant in the room: your CSS being in JS. This is going to be very hard to maintain. If you left this code as is, took a 2-week vacation or something, and came back, I bet ...
Joseph's user avatar
  • 25.1k
2 votes
Accepted

WordPress Settings Plugin security

A cursory glance suggests the main issue is a lack of escaping on the HTML esc_attr esc_html ...
Tom J Nowell's user avatar
2 votes

PHP create JSON file from Twitter API

This function is doing WAY too much. you are storing unnecessarily hard-coded default configuration storing OAuth configuration (where it is not clear how you handle OAuth for individual end users) ...
Mike Brant's user avatar
  • 9,608
2 votes

Outputting a logo from the Wordpress Customiser

Here are my suggestions: There is no point of "fetching" the image url if has_custom_logo returns false. Instead, I would define ...
Dan Cantir's user avatar
2 votes
Accepted

Displaying a price quote depending on the selected number of rooms

Making the Javascript code more versatile You can query the DOM for all select list elements (i.e. <select>) to handle the change event on any of them. ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
2 votes
Accepted

PHP function which filters content from Wordpress database (wp_posts table)

This seems an odd design choice considering you are working in a domain-specific tagging language. Why not have Wordpress code transform the post to HTML for you as it already does for your regular ...
Mike Brant's user avatar
  • 9,608
2 votes
Accepted

Elegant wp-query markup for repetitive post-type category loops

First off, Wordpress is an awful platform when it comes to separation of business logic from display logic. If you expect to continue working in it, you can expect to continue to feel the pain that ...
Mike Brant's user avatar
  • 9,608

Only top scored, non community-wiki answers of a minimum length are eligible