WordPress REST API validation

There is no such maxLength option in the WP REST API. You can pass a validate_callback though. Example: <?php add_action( ‘rest_api_init’, function () { register_rest_route( ‘myplugin/v1’, ‘/author/(?P<id>\d+)’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘my_awesome_func’, ‘args’ => array( ‘id’ => array( ‘validate_callback’ => function($param, $request, $key) { return is_numeric( $param ); } ), ), ) ); … Read more

Server side validation

You can capture the form submission by creating a small plugin / or by editing your theme functions file, and you can do this using a ajax hook. In the plugin you would load this on the edit post page: jQuery(document).ready(function(){ jQuery(‘#post’).submit(function(){ var request = jQuery(this).serializeArray(); request.push({name: ‘action’, value: ‘check_some_stuff’}); jQuery.post(ajaxurl, request, function(response){ if(response.error){ response … Read more

How to Debug the ‘save_post’ Action?

Your code works just fine on my end. So, I’d say your problem is elsewhere. Troubleshooting guide. You can use standard debugging or FirePHP. I also use the following for cases where FirePHP doesn’t display information, i.e., save_post. function my_log( $msg, $title=”” ) { $error_dir=”/Applications/MAMP/logs/php_error.log”; $date = date( ‘d.m.Y h:i:s’ ); $msg = print_r( $msg, … Read more

is_email() VS sanitize_email()

is_email() will take the provided string( a email address) and run checks on it to ensure that it is indeed an email address and that the string has no illegal characters in it. It would simply not change anything in the string you provided but return either true if the string passes all the function … Read more

Sample code for validating custom metabox?

Straight from the WP Codex @ http://codex.wordpress.org/Function_Reference/add_meta_box, you call the save_post hook and specify the function that will be run to validate/save your data: /* Do something with the data entered */ add_action(‘save_post’, ‘myplugin_save_postdata’); Then you define that function, which will automatically be passed the post id. Additionally, you can access the $_POST array to … Read more

How to properly validate data from $_GET or $_REQUEST using WordPress functions?

WordPress doesn’t provide any specific data validation functions for SUPERGLOBALS. I use the PHP filter_input function then escape it as I would any untrusted variable. $url = filter_input( INPUT_GET, ‘some_query_string’, FILTER_VALIDATE_URL ); echo ‘<a href=”‘. esc_url( $url ). ‘”>Click Me</a>’; The PHP filter input accepts: Validate filters Sanitize filters Other filters Additional Filter flags

How should one implement add_settings_error on custom menu pages?

There are several components to error/notice creation and display process: add_settings_error() call to add item to stack (global $wp_settings_errors variable). settings_errors transient that keeps the errors so they survive move from page to page. settings_errors() function get_settings_errors() to retrieve errors from memory or transient and then displays them. These work like a charm for Settings … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)