사용자가 유효하지만 이미지 인 URL을 제출할 수 있도록 프런트 엔드 양식을 사용하고 있습니다. .jpg, .png 또는 .gif. 내가 정보를 얻고 게시물 작성 방법유효한 URL은 .jpg, .png 또는 .gif로 끝나는 WordPress 게시물 콘텐츠입니다.
<form action="" id="primaryPostForm" method="POST">
<fieldset>
<p>Accepting GIF/JPG/PNG URL (Max size: 3MB)</p>
<label for="postTitle"><?php _e('* POST TITLE:', 'framework') ?></label>
<input type="text" name="postTitle" id="postTitle" class="required" value="<?php if (isset($_POST['postTitle'])) echo $_POST['postTitle']; ?>" />
</fieldset>
<fieldset>
<label for="postContent"><?php _e('* URL:', 'framework') ?></label>
<textarea name="postContent" id="postContent" class="required" <?php if (isset($_POST['postContent'])) { if (function_exists('stripslashes')) { echo stripslashes($_POST['postContent']); } else { echo $_POST['postContent']; } } ?>></textarea>
</fieldset>
<fieldset>
<input type="hidden" name="submitted" id="submitted" value="true" />
<button type="submit"><?php _e('SUBMIT', 'framework') ?></button>
</fieldset>
</form>
이는 다음과 같습니다 :
이
은 내 양식이다 POST_CONTENT에 삽입 된 문자가 URL과 일치하는지 확인하기 위해if (isset($_POST['submitted']) && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {
$post_information = array(
'post_title' => wp_strip_all_tags($_POST['postTitle']),
'post_content' => $_POST['postContent'],
'post_type' => 'post',
'post_status' => 'publish'
);
$new_post = wp_insert_post($post_information);
내가 좋아하는 것을 그 .jpg/png/gif로 끝나고 다음과 같은 조건부 태그를 작성하십시오.
if $ _POST [ 'postContent'] == JPG/PNG/GIF에서 끝나는 URL { do somet hing}
어떻게해야합니까? ,
이 \b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]\.(?:jpg|png|gif)\b
이 비록 내 마음에 경종을 울리는, 잠재적 보안 위험이 될 수있다 :
무엇을 시도 했습니까? URL (정규식)을 검증하는 예제가 많이 있으며 문자열 끝을 비교하는 것은 매우 간단합니다. –