こんにちはみんな私はフィールド検証で打たれたいくつかの仕事の後にワードプレスで私の最初のプラグインを始めました。
"preix_author_url"
問題は、プラグインで使用するフィールドがあります。
add_action('save_post', 'my_function_name');
検証クラスの例を作成しました
<?php
class validator {
public static function isUrl($str = '') {
if(strlen($str) == 0)
return FALSE;
return preg_match('!^http(s)?://[\w-]+\.[\w-]+(\S+)?$!i',$str);
}
}
の"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']);
}
}
}
次に、validateがfalseを返す場合、投稿ページにエラーを表示したいと思います。しかし、私はそれらのエラーや通知を表示する方法を取得できませんでした。