質問: { action: 'my_pre_submit_validation', security: '";echo wp_create_nonce( 'pre_publish_validation' ); echo"', form_data: form_data }; jquery.post(ajaxurl, data, function(response) { if (response=='true') { jquery('#ajax-loading').hide(); jquery('#publish').removeclass('button-primary-disabled'); return true; }else{ alert('correggi i seguenti errori: ' + response); jquery('#ajax-loading').hide(); jquery('#publish').removeclass('button-primary-disabled'); return false; } }); return false; }); }); </script> "; } } add_action('wp_ajax_my_pre_submit_validation', 'pre_submit_validation'); function pre_submit_validation(){ //simple security check check_ajax_referer( 'pre_publish_validation', 'security' ); $error=null; /* check categories */ $post_data=str_replace("%5d","]",$_post['form_data']); $post_data=str_replace("%5b","[",$post_data); $post_data=substr($post_data,strpos($post_data,"&post_category")+18); $post_data=substr($post_data,0,strpos($post_data,"&newcategory")); $categories_array=array(); if(strlen($post_data)>0) { $categories_array=explode("&post_category[]=",$post_data); } if(count($categories_array)>0) { // categories setted } else $error="you must select categories"; /* check tag */ $post_data=str_replace("%2c",",",$_post['form_data']); $post_data=str_replace("%5d","]", $post_data); $post_data=str_replace("%5b","[",$post_data); $post_data=substr($post_data,strpos($post_data,"tax_input[post_tag]=")+20); $post_data=substr($post_data,0,strpos($post_data,"&")); if(strlen($post_data)==0) $error="you must select tags"; //print validation response if($error==null) { echo'true'; die(); } else { echo $error; die(); } }
回答: 私はこの記事が古くなっていることを知っています、しかしここにたくさんの異なる投稿要件オプションを持っているniceプラグインがあります - wypiekacz