12
votes
Listing WordPress posts with thumbnail images
One of the nested loops can be eliminated, by joining these two queries:
...
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 ...
8
votes
Check efficiency of PHP code that will query over 8500 orders
The biggest performance issue is probably here:
...
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 & (...
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. ...
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 ...
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 ...
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 ...
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:
...
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 ...
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:
...
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 ...
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. ...
4
votes
First attempt - Wordpress PHP Settings API wrapper
your first function should use a switch statement instead of a complex if then statement.
...
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 ...
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 ...
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. ...
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 ...
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.
...
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 ...
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.
...
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 ...
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 ...
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 ...
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 ...
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 ...
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.
...
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 ...
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 ...
3
votes
Accepted
Wordpress downloader and unpacker
You don't need to escape slashes for grep, you can simplify to:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
wordpress × 150php × 121
javascript × 16
mysql × 15
jquery × 14
bash × 12
html × 9
beginner × 8
plugin × 8
object-oriented × 7
security × 7
performance × 6
array × 6
sql × 6
css × 6
linux × 6
e-commerce × 5
nginx × 5
regex × 4
strings × 3
api × 3
ajax × 3
iteration × 3
twitter-bootstrap × 3
installer × 3