텍스트 영역을 WordPress TinyMCE wp_editor()로 바꾸기
텍스트 영역을 wp_editor()로 바꾸려고 합니다.
내 텍스트 영역 양식 요소는 다음과 같습니다.
<textarea name="post_text" id="post_text" rows="3"><?php echo $content; ?></textarea>
그럼 다음과 같은 것입니다.
wp_editor( $content, 'post_text' );
제가 받는 문제는 양식 텍스트 영역과 wp_editor 텍스트 영역이 모두 페이지에 출력된다는 것입니다.두 텍스트 영역이 모두 표시되는 이유는 무엇입니까?표시할 텍스트 영역이 하나만 있으면 됩니다.모든 것이 잘 저장됩니다. 텍스트 영역이 두 개 표시되는 문제가 있습니다.
편집: 그것이 마치 그들이 원하는 것처럼 간단한가요?display: none;
내 양식의 텍스트 영역에 wp_editor() 텍스트 영역만 표시됩니까?그것은 효과가 있는 것 같지만 약간 어색한 느낌이 듭니다.
해결책을 찾았습니다.세 번째 매개 변수를 사용하여 인수 배열을 전달할 수 있습니다.이는 Codex에 요약되어 있는 것처럼 꽤 분명합니다. http://codex.wordpress.org/Function_Reference/wp_editor
약간 혼란스러운 점은 $editor_id가 소문자만 포함할 수 있다는 것입니다.따라서 양식 처리 스크립트가 밑줄이 있는 것을 찾고 있는 경우(나의 경우) 다음 작업을 수행해야 합니다.
$settings = array( 'textarea_name' => 'post_text' )
wp_editor( $content, $editor_id, $settings );
이 작업을 수행할 수 없습니다.
wp_editor( $content, 'post_text' );
제가 잘못한 부분입니다.
코드에 텍스트 영역을 입력하는 경우
<textarea></textarea>
그러면 당연히 페이지에 표시됩니다. 그렇게 해야 합니다.제가 오해하고 있는 것이 아니라면, 저는 그게 어떻게 말이 되는지 모르겠어요.
당신이 제안한 것처럼 이렇게 하면 당신이 원하는 대로 할 수 있을 것 같습니다.
<textarea style="display:none" name="post_text" id="posttext" rows="3"><?php echo $content; ?></textarea>
그것은 여전히 기능적으로 존재하지만 보이지는 않습니다.
다음 PHP 코드는 "expirationErrorMessage"라는 이름과 ID를 가진 텍스트 영역으로 바뀝니다.
$id = "expirationErrorMessage";
$name = 'expirationErrorMessage';
$content = esc_textarea( stripslashes( $yourtext ) );
$settings = array('tinymce' => true, 'textarea_name' => $name);
wp_editor($content, $id, $settings);
새 텍스트 영역을 페이지에 출력하는 대신(다음 기준)wp_editor()
) 및 원본 텍스트 영역 숨기기display: none;
, 할 수 있는 일:
add_action('admin_init', '20331501_convert_textarea_to_wysiwyg');
function 20331501_convert_textarea_to_wysiwyg(){
wp_enqueue_editor();
add_action( 'admin_print_footer_scripts', function() {
?>
<script>
jQuery(function(){
wp.editor.initialize('the-id-of-your-textarea-without-the-#', {
setup: function (editor) {
editor.on('change', function () {
editor.save();
});
}
});
});
</script>
<?php
}, 10, 2 );
}
이 코드 조각은 기존 텍스트 영역을 wywyg로 변환합니다.editor.save()
양식을 제출할 때 전달되도록 텍스트 영역 값을 업데이트합니다.(@Dan Malcolm)
전화해 보세요.template page
네가 원하는 곳에tinyMCE
, 그 위에template page
가.placeholder
등의CONTENT_EDITOR
그리고 php를 사용합니다.str_replace
추가할 함수tinyMCE
거기까지template
내용:
function add_tinymce_to_page(){
$creatorHTML = file_get_contents(
'your-template-pafe.php',
TRUE
);
$editorHTML = generate_content_with_editor();
$creatorHTML = str_replace(
'CONTENT_EDITOR',
$editorHTML,
$creatorHTML
);
return $creatorHTML;
}
function generate_content_with_editor(){
ob_start();
wp_editor( '', 'tinymcecontenteditor' );
$editor_contents = ob_get_contents();
ob_get_clean();
return $editor_contents;
}
사용합니다.php
의ob
그래서tinyMCE
전체 페이지가 렌더링되기 전에는 표시되지 않습니다.
참조URL : https://stackoverflow.com/questions/20331501/replacing-a-textarea-with-wordpress-tinymce-wp-editor
'programing' 카테고리의 다른 글
PowerShell ISE에서 스크립트가 실행되고 있는지 확인할 수 있는 방법이 있습니까? (0) | 2023.09.24 |
---|---|
커스텀 앱 오픈 URL 스킴을 Xcode 4에 등록하는 방법? (0) | 2023.09.24 |
mariadb JSON_UNCOTEGET's overned's special characters (0) | 2023.09.24 |
XML 파일을 읽고 쓰는 방법? (0) | 2023.09.19 |
MySQL "Alter Table Add Column After Column"의 성능 - 큰 테이블에서 (0) | 2023.09.19 |