게시물 데이터를 저장하기 전에 어떻게 편집 할 수 있습니까? wp_insert_post문서화 된 것처럼 보입니다. 나는 이런 식으로하고

플러그인이 있으며 데이터베이스에 저장하기 전에 일부 필터를 통해 게시물 내용을 실행할 수 있기를 원합니다. 상기 찾고에서 플러그인 API를 , 나는 모습들이 도움이 될 것 같은 것을 두 개의 후크를 참조하십시오

save_post
wp_insert_post

유일한 문제는 save_post변수를 반환 할 필요가없는 것처럼 보이 므로 내용을 필터링하는 방법을 모르고 wp_insert_post문서화 된 것처럼 보입니다.

나는 이런 식으로하고 싶다 :

add_action('whatever_hook_name','my_function');

function my_function($post_content){
    return $post_content.' <br> This post was saved on '.time();
}

타임 스탬프를 추가하는 것보다, 즉 일부 정규식 필터를 실행하는 것보다 더 유용한 것을 할 것입니다. 그러나 이것은 내가 추가하려는 일반적인 유형의 필터 / 액션입니다.

최신 정보

게시물에 표시 될 때가 아니라 데이터베이스에 저장되는 방식으로 데이터를 가로 채고 싶습니다 (예 :에 필터를 추가하지 않음 the_content)



답변

wp_insert_post_data 필터는 작업을 수행 할 수 있습니다

add_filter( 'wp_insert_post_data' , 'filter_post_data' , '99', 2 );

function filter_post_data( $data , $postarr ) {
    // Change post title
    $data['post_title'] .= '_suffix';
    return $data;
}


답변

content_save_pre정확하게 필터를 사용하십시오 the_content. 차이점은 게시물이 표시되지 않고 저장 될 때 작동한다는 것입니다.

http://codex.wordpress.org/Plugin_API/Filter_Reference/content_save_pre


답변

후크를 확인할 수도 있습니다 pre_post_update

add_action('pre_post_update', 'before_data_is_saved_function');

function before_data_is_saved_function($post_id) {

}


답변

교체 활성 테마에 다음 코드를 추가 <shell>[shell]저장하기 전에 :

 add_filter('content_save_pre', 'my_sanitize_content', 10, 1);
 function my_sanitize_content($value) {
   return str_replace('<shell>', '[shell]', $value);
 }


답변

모든 게시물 끝에 비슷한 것을 추가하려면 the_content필터 를 사용하는 것이 좋습니다 .

function append_to_content( $content ) {
    global $post;
    return $content.'<br />This post was saved on '.$post->post_date;
}
add_filter( 'the_content', 'append_to_content' );


답변