WordPress REST API Authentication

Trying to access your custom posttype through the WordPress rest-API, but want to make sure the session has the correct permissions? Well, according to the docs you could do this with Basic Authentication.
However it did not seem to work. I was trying the proof of concept with a request like this:

$url_test  = 'https://yourtestwebsite.url/wp-json/wp/v2/yourcustomposttype';
$user = 'yourapiusername';
$pass = 'yourapiuserpassword';
$auth = base64_encode($user.':'.$pass);
$ctx = stream_context_create(array('http' => array('header' => 'Authorization: Basic '.$auth)));
$data = file_get_contents($url_test, false, $ctx);

Adding yourcustomposttype to the rest api is simple, but you can not add any permissions check. So I added an extra check for the correct permission first before adding the custom endpoint, like so:

Continue reading WordPress REST API Authentication

Index WP MySQL For Speed

Consider using his plugin by default:
https://wordpress.org/plugins/index-wp-mysql-for-speed/

You only have to run it once, to create better indexing keys on the database tables, which in my eyes should be default in WordPress.
Unbelievable what I see in speed performance so far!

(Found this plugin actually by following the steps in this blog article for a client.)

But wait, there is more!
https://www.plumislandmedia.net/wordpress/performance/optimizing-wordpress-database-servers/

WordPress Constants

Something I wanted to keep for reference.
See the source here: https://wppb.me/wordpress-constants

WordPress offers multiple ways to configure and customize your site, from the admin panel to hooks (filters and actions). However, one of the most powerful and often overlooked methods is through PHP constants. These constants provide developers with fine-grained control over various aspects of WordPress functionality.

Continue reading WordPress Constants

WP_MEMORY_LIMIT or WP_MAX_MEMORY_LIMIT ?

the more you know

By default, WordPress enforces a memory limit of 40 MB. This means a single PHP script is allowed to use up to 40 MB of RAM. In certain cases, you may need to increase WordPress’ memory limit to run heavier plugins like WooCommerce or bbPress. To increase WordPress’ memory limit, you can define WP_MEMORY_LIMIT in your wp-config.php file using the line below.

define( 'WP_MEMORY_LIMIT', '256M' );

The setting above will allow WordPress to use up to 256 MB of RAM for each script, as long as the memory_limit setting in your php.ini file is 256 MB or greater. As is often the case with computing resources, setting a higher memory limit doesn’t necessarily increase the performance of your WordPress site. Since WP_MEMORY_LIMIT controls memory allocation PER SCRIPT, it’s actually in your best interest to set it as low as possible to reduce the chance of a rogue script saturating the RAM in your server.

Sometimes, it’s a good idea to tailor WordPress’ memory allocation separately for the frontend and backend. That’s where WP_MAX_MEMORY_LIMIT comes in. WP_MAX_MEMORY_LIMIT allows you to set a different memory limit for WordPress’ administration dashboard. This is useful because certain administration tasks require more RAM. Below is an example of how you can use WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT together.

define( 'WP_MEMORY_LIMIT', '64M' );
define( 'WP_MAX_MEMORY_LIMIT', '256M');

The setting above will allocate up to 64 MB of RAM per PHP script for processes spawned from WordPress’ frontend, while administration-related scripts from the backend dashboard will be able to use up to 256 MB of RAM.

WordPress Menu target=_blank

How to open external menu links in a new tab with WordPress?
When creating a menu with WordPress, you can decide that a menu item links to an external page by adding a Custom Link. (And thank you Press Customizr for the images.)

You can change the target of this link, so that it opens in a new browser tab. For that you need to check an option located below the Navigation label field of the menu item and named “Open link in a new tab“, as illustrated in the following screenshot.

If this option is not visible, it means that it’s not enabled in the menu screen option. Simply follow those steps to activate the option :

  1. Click on the Screen Options link in the top right corner of the menu admin screen.
  1. Check the “Link Target” option : this will reveal the “Open link in a new tab” option.

That’s all folks!