コピペOK! 「公開」ボタンの有効・無効を切り替えるセーフティーの設置方法
「間違えて記事を公開してしまった」なんてことありませんか?
僕はいつも「下書きとして保存」ボタンと間違えて、青く目立つ「公開」ボタンを押してしまいそうで不安なんですが、そろそろそんな不安ともおさらばしようと、テーマ「ShapeShifter」の次のバージョンでは、「公開」ボタンを無効にするセーフティーを設置しました。

「すぐに公開する」の下に設置されている「チェックボックス」と「公開」ボタンが無効になっていることが確認できると思います。
で、チェックを外すと、

「公開」ボタンがクリックできるようになります。
ちなみに初期設定として無効にしています。また、「公開済み」ページの編集では出力されませんので、普通に更新できます。
ええ、本当に単純で別に紹介するほどのことでもない気がしますが、すぐに1ページ書けそうですし、僕にとっては重宝しそうな機能だったので、設置方法と合わせて紹介していきます。
設置方法
こういう既存のボックス内などに出力させたい場合、ワードプレスでは大抵そこに出力させるためのフックが用意されています。
今回上のスクリーンショットで紹介した位置であれば、アクションフック「post_submitbox_misc_actions」にフックさせることで出力できますので覚えておきましょう。JetPackで「パブリサイズ共有」の設定が出力されている場所でもあります。
add_action( 'post_submitbox_misc_actions', 'your_func' ); your_func() { // print htmls here. }
こんな感じで自由にテキストを出力することができます。
コピペ用コード
以下コピペ用です。
「functions.php」のどこかに貼り付けてください。テキストは「_e()」内の「Disable Publish Button」を日本語に書き換えてください。ローカライズ用に英語で書いているだけです。
if( is_admin() ) { add_action( 'post_submitbox_misc_actions', 'disable_publish_button' ); function disable_publish_button() { global $post; $status = get_post_status( $post ); if( $status != 'publish' ) { ?> <div class="misc-pub-section"> <span id="disable-publish-button"> <?php _e( 'Disable <b>Publish</b> Button', 'textdomain' );?> </span> <input type="checkbox" id="ss-disable-publish-button" onClick="javascript:handleSafetyCheckbox();" checked> </div> <style scoped> .misc-pub-section #disable-publish-button { padding: 2px 0 1px; display: inline!important; height: auto!important; font-style: normal !important; } .misc-pub-section #disable-publish-button:before { font: 400 20px/1 dashicons; speak: none; display: inline-block; padding: 0 2px 0 0; top: 0; left: -1px; position: relative; vertical-align: top; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-decoration: none!important; content: "\f160"; color: #82878c; } </style> <script> var handleSafetyCheckbox = function() { ( function( $ ) { if( $( '#ss-disable-publish-button:checked' ).length > 0 ) { $( 'input#publish' ).addClass( 'disabled' ); } else { $( 'input#publish' ).removeClass( 'disabled' ); } }) ( jQuery ); }; ( function( $ ) { $( document ).ready( function() { handleSafetyCheckbox(); }); }) ( jQuery ); </script> <?php } } }
スタイルはその上にある「すぐに公開する」をコピペしただけです。
この機能のためだけのプラグイン出してみようかな。あまりにもショボい気がするけど、あると安心するんですよ。