フォーラムへの返信

4件の返信を表示中 - 1 - 4件目 (全4件中)
  • フォーラム: 使い方全般
    返信が含まれるトピック: プレビュー画面内に公開ボタンを設置
    トピック投稿者 white50

    (@white50)

    自己解決致しましたので、共有しておきます。

    以下のコードで出来ました。

    single.php

    <?php if(current_user_can('read_private_pages')) : ?>
    <?php
    $url = add_query_arg(array('action'=>'mypublish', 'post'=>$post->ID),home_url());
    echo  "<a href='" . wp_nonce_url($url, 'my-publish-post_' . $post->ID) . "'>公開する</a>";
    ?><?php endif; ?>

    function.php

    if(isset($_REQUEST['action']) && $_REQUEST['action']=='mypublish')
        add_action('init','my_publish_draft');
    
        function my_publish_draft(){
             //Get the post's ID.
             $post_id = (isset($_REQUEST['post']) ?  (int) $_REQUEST['post'] : 0);
    
            //No post? Oh well..
            if(empty($post_id))
                return;
    
            $nonce = $_REQUEST['_wpnonce'];
    
            //Check nonce
            if (! wp_verify_nonce($nonce,'my-publish-post_'.$post_id))
                wp_die('Are you sure?'); 
    
            //Check user permissions
            if (!current_user_can('publish_posts'))
                wp_die("You can't do that"); 
    
            //Any other checks you may wish to perform..
    
            //Publish post
            wp_publish_post( $post_id );
    
            //Redirect to published post
            $redirect = get_permalink($post_id);
            wp_redirect($redirect);
            exit;
        }

    フォーラム: 使い方全般
    返信が含まれるトピック: 閲覧ユーザーによるタグ付け
    トピック投稿者 white50

    (@white50)

    ありがとうございます!
    まさに探している情報でした!

    トピック投稿者 white50

    (@white50)

    ご回答ありがとうございます。
    ご協力下さったのに、申し訳ないのですが
    全然別の方法で、自己解決致しました。

    トピック投稿者 white50

    (@white50)

    追記です。

    記事IDは不明な状態での場合です。

4件の返信を表示中 - 1 - 4件目 (全4件中)