/** * 秘密URLからパスワードなしで読めるよう設定 **/ function custom_smart_password_form($html) { global $post; $password = @$_GET['post_password']; if ( isset($password) ){ /// パスワード付きURLの場合... /// 自動閲覧できるようにする $html .= <<<EOM <script> window.addEventListener("DOMContentLoaded", function(){ jQuery('[name="post_password"').val('{$password}'); setTimeout(function(){ var urlBeforeQuery= location.href.split("?")[0]; window.history.pushState({}, document.title, urlBeforeQuery ); jQuery('[type="submit"]')[0].click(); }, 100); }); </script> EOM; } return $html; } add_filter( 'the_password_form', 'custom_smart_password_form' );
例:https://msweb.sakura.ne.jp/works?post_password=1235