Hello guys i started my first plugin in wordpress after few work i got struck in field validation..
Problem is i have a field called "preix_author_url"
then in my plugin i use
add_action('save_post', 'my_function_name');
i have created a validation class example
<?php
class validator {
public static function isUrl($str = '') {
if(strlen($str) == 0)
return FALSE;
return preg_match('!^http(s)?://[w-]+.[w-]+(S+)?$!i',$str);
}
}
in "my_function_name()"
function my_function_name(){
global $post;
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if(isset($_POST['post_type']) && $_POST['post_type'] == 'wallpapers'){
require_once( WALLP_FILE_PATH . '/wallp-core/wallp-validator.php' );
$validate = new validator();
if(isset($_POST['preix_author_url'])){
if($validate->isUrl($_POST['preix_author_url']))
update_post_meta($post->ID, 'preix_author_url', $_POST['preix_author_url']);
}
}
}
Now i want to show error in post page if validate return false. But i didnt get the way to display those errors or notification..
So after a little while i figured this out at last. I promise to come back to you with in 20 minutes but I failed because I thought it was that easy!! I found out after searching everywhere that admin_notices wont work on save_post hook! So heres a good solution with your problem.
I tried this in my personal website and it worked beautifully!! Ive also learned a lot of things with this!