Home 게시판 커뮤니티 Q&A api 후킹 질문입니다.

1개 답변, 2 voices Last updated by Avatar of 082net082net 12 years, 7 months 전
  • Avatar of 김대현김대현
    Participant
    @myios
    #6667

    어떤 카테고리에 글을 작성할때만 후킹을 하고싶은데

    add_action 으로 필터가 가능한지요?

     

    [code title=””]

    function pushService_post($post_ID)

    {

    global $post;

     

    // 예시.. 클래스 아이디인 계정에게만 푸쉬를 날린다..

    $dataStruct = array();

     

    pushService_sendPush($post -> ID.”adsad”, $dataStruct);

     

    return $post_ID;

    }

    add_action ( ‘publish_post’, ‘pushService_post’);

    [/code]

    Avatar of 082net082net
    Keymaster
    @082net
    #6670

    ‘publish_post’ 를 쓰시는 것 보다는 ‘transition_post_status’ 후크를 사용해서 draft/schedule/pending 상태에서 처음 publish 될 때만 적용되도록 하시는게 좋습니다. 그렇지 않을 경우 글이 update/modify 될 때 마다 해당 hook가 실행되게 됩니다.

    해당 hook에 등록한 함수에서 대충…

    [code title=”예제”]
    funciton my_transition_post_status($new, $old, $post) {
    if ( $post->post_type == ‘post’ && $new == ‘publish’ && $new != $old ) {
    $cats = wp_get_post_categories($post->ID);// 카테고리 ID 값들만 가져옴
    if ( $cats && (in_array($mycat_id, $cats)) ) {
    ……
    }
    }
    add_action(‘transition_post_status’, ‘my_transition_post_status’, 10, 3);
    [/code]

    Avatar of 082net
    Facebook 사용자 모임 그룹 도 함께 운영되고 있으며, 격 주로 미트업과 스터디를 진행하고 있으니 관심 있으신 분들의 많은 참여 바랍니다 🙂
2 글 보임 - 1에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.