Joined March 2014
·

Nikola Nikolov

Lead Developer/Owner at Paiyak Development at Paiyak Development
·
Varna, Bulgaria
·
·
·

Posted to How to disable wordpress updates over 1 year ago

It's good to always point out that disabling updates is a bad idea - updates are there for a reason - they improve security(which is very important), performance and user experience.

It's true that if there are plugins that don't keep-up with the WordPress core development, you can get your site broken, but that's a different story.

Posted to A Better WordPress User Object over 1 year ago

If you look at the source for WPUser - https://github.com/WordPress/WordPress/blob/master/wp-includes/capabilities.php#L406 - you would see that it also implements the `get(),isset()and_set()` magic methods.

It's also important to know that a single call to get_user_meta() loads all of the users meta fields into the WP object cache. This way any subsequent calls to either get_user_meta() or WP_User::__get() would not require a trip to the DB.

Posted to WordPress Cheatsheet over 1 year ago

Some notes:

"get the home URL
<?php echo get_option('home'); ?>

Better to use
<?php echo home_url(); ?>
You can even add stuff at the end of the URL: <?php echo home_url( '/goes/at/the/end/' ); ?>

Any of the includes - use get_template_part() - this way templates can be overridden in a child theme. For instance to get about.php :

<?php get_template_part( 'about' ); ?>

Also to get the search form:

<?php get_search_form(); ?>

Posted to WordPress PHP Templates? over 1 year ago

That's a double-edged sword. Yes it will be easy for you to navigate through the conditional blocks, but it will be more difficult for the less-tech-savvy admin of a site that uses your theme to figure-out what he has to tweak in order to add/remove something somewhere.

That's why some people recommend to use as much of get_template_part() as possible instead.

Use action hooks as well. Use an action that fires before the content of a page for instance. Then use add_action() in your theme's functions.php file in order to run any logic checks and once you figure out what has to be included just use get_template_part(). If you have a lot of secondary templates, put them in a well-organized directory structure(like /template-parts/header/, /template-parts/footer/, /template-parts/content/, etc. ) that will make it easier to navigate through.

This way you can end-up with a bunch of 10-line templates but it will be dead-easy to go in and add a new element to them.

Are you saying that this also gets rid of the /wp-includes/ | /wp-content/ | /wp-admin/ parts in the URLs of scripts and styles? Obviously you can easily change the name of the wp-content directory, but this doesn't go for the admin and includes directories.

The easiest thing for me to notice is when one of the resources comes from one of the above-mentioned URLs. This tells me that the site is powered by WordPress right away.

You have two ways to get around that:
- Include the correct file :) When you don't want to parse the request via WordPress' main query(like when handling AJAX via a php file), include the wp-load.php file
- Even better - send your AJAX to /wp-admin/admin-ajax.php with at least an "action" parameter.
Then in your plugin/theme you have to add(if your action parameter is "myaction")

add_action( 'wp_ajax_myaction', 'myaction_function_callback' );

Note that the above will only work for requests from logged-in users. To add support for non-logged-in users add this:

add_action( 'wp_ajax_nopriv_myaction', 'myaction_function_callback' );

myaction_function_callback should be an existing function(you can use any "callback" parameter - like array( $myobject, 'callback' ) ).
Once you're done with processing the AJAX request don't forget to do exit() or die() so that WordPress doesn't print '0' at the end of your output.

Achievements
25 Karma
0 Total ProTip Views
Interests & Skills