12 votes

Listing WordPress posts with thumbnail images

One of the nested loops can be eliminated, by joining these two queries: ...
user avatar
  • 107k
11 votes

Listing WordPress posts with thumbnail images

This is going to be a bit of a drive-by code review due to time limitations and my limited php knowledge, but hopefully I can add some value here. Here are some high-level things I've noticed about ...
user avatar
  • 1,873
8 votes

Check efficiency of PHP code that will query over 8500 orders

The biggest performance issue is probably here: ...
user avatar
  • 107k
7 votes
Accepted

First attempt - Wordpress PHP Settings API wrapper

The first small thing that pops out is array( &$this, 'method_name' ). That's PHP 4 and you can totally drop the & (...
user avatar
  • 439
6 votes
Accepted

Correctly coding an OOP object

Separation of concern You mention "separation of concern" in your question. It's fantastic that you actually know about it, and are trying to adopt good practices whilst learning about OO. ...
user avatar
6 votes

Trim string of words based on character count

Yes, it's extremely inefficient, because in every iteration you count the number of words twice: once in count_words, and then ...
user avatar
  • 107k
5 votes

Listing WordPress posts with thumbnail images

Sometimes the nested loops cannot be avoided in certain areas, however the purpose is not just to have optimized code, but also more readable code. The code needs to be separated as units or each ...
user avatar
  • 51
5 votes
Accepted

Checking for existence of URL parameters

GET and setters One of the points of @EliasVanOotegemto was that your class expects the $_GET variable to be set, which is not ideal because it makes your class ...
user avatar
  • 24.9k
5 votes
Accepted

Recursive download articles and dump to MongoDB

The logic for getting 100 posts is duplicated for the case of the initial load and subsequent loads with an offset. It would be better to refactor in a way to eliminate the duplicated logic: ...
user avatar
  • 107k
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 ...
user avatar
  • 9,558
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: ...
user avatar
5 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 ...
user avatar
  • 166
4 votes

Correctly coding an OOP object

Welcome to the world of OOP. I think its awesome you are trying something new and pushing yourself, keep going! Before you read on keep in mind this may seem harsh. I have no intention of hurting you. ...
user avatar
  • 1,094
4 votes

First attempt - Wordpress PHP Settings API wrapper

your first function should use a switch statement instead of a complex if then statement. ...
user avatar
  • 28.5k
4 votes
Accepted

DB security and efficiency in WordPress plugins

I'm just going to write some comments from the top down. First of all I would like to point you to PSR, and especially PSR-2, since following a well known coding style will help other developers read ...
user avatar
4 votes
Accepted

Inserting a name into a database table

In terms of security, you should be safe from SQL injection since you are using parameterized queries as recommended. That's true whether or not you validate the names using the regex. Do not ...
user avatar
4 votes

Recursive download articles and dump to MongoDB

Your code follows most of PEP8. However: Lines should be a maximum of 79 characters. The exception to this is comments, at 72. Operators should have a space either side of them. ...
user avatar
  • 41.6k
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 ...
user avatar
  • 2,597
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. ...
user avatar
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 ...
user avatar
  • 7,596
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. ...
user avatar
  • 166
3 votes

Check efficiency of PHP code that will query over 8500 orders

Yes, this code does look like a performance disaster! I will try to review what I can, but without proper profiling and lack of data structures and code context, it's nearly impossible for someone ...
user avatar
  • 5,687
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 ...
user avatar
3 votes
Accepted

PHP function (in WordPress) echoing HTML

There are several issues I have with your function. Some are about your function breaking the basics about what a function is/should do, others are perhaps a tad more personal (as in: a matter of ...
user avatar
3 votes
Accepted

Related links for WordPress posts

I haven't really looked into your code that much, but the first thing I noticed is that you have a number of methods (like the constructor) that you expect to be an array. That's fine, sometimes you ...
user avatar
3 votes
Accepted

Listing links for categories

One thing that is quite important to really understand. It's something that is said all too often, but it's very true: Premature optimzation is the root of all evil By your own admission, you're ...
user avatar
3 votes

Add user profile fields

I would make a single function, since all your functions do the same thing. It just needs an extra argument. ...
user avatar
  • 231
3 votes

Saving array values for a secondary foreach loop

Your approach seems fine, assuming that the entries in $child_pages are the correct order. I mention that because you mentioned the ordering requirement in the ...
user avatar
  • 107k
3 votes
Accepted

Determine value in range, inject to HTML to be used in CSS

Why is $lim01 never used? Is it always equal to 1? Only one of the subscription packs applies, if at all. You should first make it clear which subscription pack ...
user avatar
3 votes
Accepted

Wordpress downloader and unpacker

You don't need to escape slashes for grep, you can simplify to: ...
user avatar
  • 107k

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