esc_attr() right way and use

No you don’t need esc_attr() function to print out fixed static text. You only need it to print out dynamic or generated text, so that if the attributes have any special characters that may break your HTML, esc_attr will escape that properly. In your particular case, you can just write: echo ‘<label><input type=”checkbox” id=”custom_header” name=”custom_header” … Read more

How do I add a WP_List_Table to WordPress page?

Your WP_List_Table will be different — this was adapted from WP_List_Table – a step by step guide and using the GIST: Sample plugin for usage of WP_List_Table class (complete version). You’ll want to adjust your methods to include CSS on the front-end as well (not included in this answer). WARNING : Since this class is … Read more

Why do you need to wrap a function inside array($this, function)

It’s a PHP callback. You need the syntax to keep a reference to the class instance. Put it this way – if you didn’t have $this, how does the caller know that getStuffDone is a method of your class, and not just a regular PHP function? It doesn’t. Using array( $this, ‘getStuffDone’ ) says to … Read more

Include WP_Query in my own PHP file?

Load WordPress in custom PHP Script: You need to load essential WordPress core functionality in your custom PHP script for WP_Query to work properly. For example, let’s say you have a custom PHP file named my-cron.php and WordPress is installed in the web root, like this: public_html/ index.php my-cron.php <– wp-load.php wp-settings.php … wp-admin/ wp-content/ … Read more

WP-API v2 Custom Endpoint Response Formatting

You can call the REST API methods to prepare your output in the same way that the plugin does by default, this will also allow any plugins to tie into the output as you have used the ACF plugin as seen in your example output. The WP_REST_Posts_Controller class has the following in its get posts … Read more

How can I fetch loop of post titles via AJAX?

you can wrap your function and hook it to ajax call like this: //if you want only logged in users to access this function use this hook add_action(‘wp_ajax_more_links’, ‘my_AJAX_more_links_function’); //if you want none logged in users to access this function use this hook add_action(‘wp_ajax_nopriv_more_links’, ‘my_AJAX_more_links_function’); function my_AJAX_more_links_function(){ check_ajax_referer(‘more_links’); $success_response = new WP_Ajax_Response(); $args = array(‘posts_per_page’ … Read more

What is the best php version to use with WordPress?

There isn’t (and shouldn’t) be an answer with any specific version for this. New versions come out, old versions get discontinued. At the minimum you should use supported version of PHP. This ensures it still receives bug fixes and (or for less recent version) security updates. Preferably you should be use the latest stable version … Read more

Disable Attachment Pages Completely

You can filter default rewrite rules and remove those for attachments: function cleanup_default_rewrite_rules( $rules ) { foreach ( $rules as $regex => $query ) { if ( strpos( $regex, ‘attachment’ ) || strpos( $query, ‘attachment’ ) ) { unset( $rules[ $regex ] ); } } return $rules; } add_filter( ‘rewrite_rules_array’, ‘cleanup_default_rewrite_rules’ ); Don’t forget to … Read more

add_action in namespace not working

Before going too far down this path I would suggest that you familiarize yourself with PHP name resolution rules. To answer your actual question – When you namespace functions, the fully qualified name of those functions includes the namespace. In your example, you have defined two functions: \myPlugin\add_activation_notice and \myPlugin\activation_notice. When calling either of these … Read more