wp_ajax_get_permalink

函式
wp_ajax_get_permalink ( No parameters )

wp_ajax_get_permalink. 這個函式通常用於在WordPress編輯器中獲取一個文章的固定連結,而不需要重新載入頁面: 該函式首先檢查當前使用者是否有必要的許可權來檢視文章,然後使用get_permalink的函式來檢索固定連結。檢索到的固定連結會以JSON物件的形式返回到AJAX請求的響應中。

獲取固定連結的Ajax處理程式。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_ajax_get_permalink() {
check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
$post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0;
wp_die( get_preview_post_link( $post_id ) );
}
function wp_ajax_get_permalink() { check_ajax_referer( 'getpermalink', 'getpermalinknonce' ); $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0; wp_die( get_preview_post_link( $post_id ) ); }
function wp_ajax_get_permalink() {
	check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
	$post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0;
	wp_die( get_preview_post_link( $post_id ) );
}

常見問題

FAQs
檢視更多 >