- Adding capability to user (not role)
To add capability directly to user, we can use the add_cap() method in the WP_User class
$user_id = get_current_user_id();
$user = new WP_User( $user_id );
$user->add_cap( 'edit_posts' );
- Fields in usermeta table
The usermeta table consists of key value pairs of meta information about the user. IT contains following fields
- first name
- last name
- nickname
- show_admin_bar_front
- wp_capabilities
- wp_user_levels
The Header API
The wordpress plugins and themes are identified by the header comment used in index.php and style.css respectively.
It contains information like the version number, uri. We can make use of this info internally to perform update on the custom db tables we have created.
For that we can get the version number of our plugin using:-
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$data = get_plugin_data(WP_CONTENT_DIR . '/plugins/movie-library/movie-library.php');
var_dump($data['Version']);
die();
The wp HTTP API:
The HTTP api wrapper methods can be used to send requests like GET, POST and HEAD. But what if we want to send request of another method?, for that we can use the wp_remote_request() method
$response = wp_remote_request(
'https://dev-bkp.local/wp-json/wp/v2/',
array( 'method' => 'PUT' ));
Other methods in the API
wp_remote_get()wp_remote_post()wp_remote_head()
Disabling wp cron
The WP Cron system is not true cron, it needs a request to be made by the user so that the cron jobs are run. What if there are some critical jobs that needed to be run and we got no requests?, for that what we can do is disable the default behaviour and use of our system cron to run the cron jobs.
We can use command to send request directly to the cron.php and make the cron jobs run instead of relying on external requests.
For that first we have to define the constant to disable deafult cron behaviour
define('DISABLE_WP_CRON', true);
Then we can use crontab e and add new entry, we can use a tool like CURL to make request to the cron.php of our site
*/05 * * * * curl http://bkp-dev.local/wp-cron.php?doing_wp_cron
This will run every 5 minutes.
Leave a Reply