The WordPress VIP platform is a hosting environment, here the sites should not be down because of performance for even a minute, the WordPress VIP follows strict coding practices and efficient coding standards.
Let’s start with the best practices.
- Create good changesets -> This means creating good changesets as in version controls and commits, the commits should be created for defining one feature or change only, we must not club many changes into a single commit, that would not be the best efficient method for version control.
We must bundle only related changes together, for example if we are changing the input name for a form, then in both html and php files we are changing, so we can bundle both of these changes to a single commit together.
Is atomic -> The changes must be left in a valid state, no commit must add invalid or broken code - Good commit message -> The commit messages should be self descriptive and must define the changes which have been done inside the code.
We must also use proper semantic commit structure for the commit messages, commit messages must always be in the present tense. - Database queries -> Where possible, direct database queries should be avoided and instead WordPress API functions should be used to retrieve and manipulate data.
Make sure all your queries are protected from SQL injection using $wpdb->prepare
Although many operations can be performed on the database side, keeping your database queries simple and doing the necessary calculations and logic in PHP will make your code scale much better.
Do not use DISTINCT, GROUP, or any other query statement whose results are returned by generating temporary tables. ->> Performance hazard
Cache the results of queries where it makes sense -> Caching = less db queries = more fast site = less expense 😀
Optimize DB queries ->
$exclude = array( get_the_ID(), ...$suggested_posts ); // $suggested_posts contains post id of suggested posts in current page
$args = array(
'posts_per_page' => 7,
'author' => get_the_author_meta( 'ID' ),
'post_type' => 'post',
'post_status' => 'publish',
'post__not_in' => get_option( 'sticky_posts' ),
'orderby' => 'date',
'order' => 'DESC',
);
$result = new WP_Query( $args );
Fetching 7 posts as 3 + 1 + 3 where, 3 -> Number of posts we need, 1 -> The current post, 3 -> Number of suggested posts. 3 would be the result we need and 4 can be excluded results
Loop through the posts in the result
If post is in $exclude array, skip the post.
Compare the post date in php and check if it is under 1 month, break loop if its not.
If three posts are printed, break the loop.- Write environment-specific code -> The wordpress VIP setup provides the constant VIP_GO_APP_ENVIRONMENT -> This can help check the current environment and write environment specific code
Dev Workflow
The application is deployed with a GitHub repository within the wpcomvip GitHub organization. Each VIP platform environment of the
application tracks a specific branch of its GitHub repository.
For locally developing code that requires Node.js, such as plugins and themes for WordPress applications.
, local development is encouraged to keep his Node.js in release version with long term support (LTS).
Locally built code artifacts are committed as static assets to his GitHub repository for the application.
