Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPressでFTPを使って管理ユーザーを追加する方法(簡単チュートリアル)

WordPressの管理エリアにアクセスできなくなることは、特に締め切りが迫っている時やクライアントのサイトを管理している時など、悪夢のような事態になりかねません。

WPBeginnerでは、パスワード忘れ、セキュリティプラグインの不具合、あるいはハッキングの試みによってロックアウトされたサイトのコントロールを取り戻すために、数え切れないほどのユーザーを支援してきました。

アクセスを回復する方法はいくつかありますが、最も確実な方法の一つは、FTP(File Transfer Protocol)を使って新規管理ユーザーを追加することです。FTPを使ったことがない方のために、FTPで管理ユーザーを追加する方法を順を追って説明します。

How to Add an Admin User in WordPress Using FTP

WordPressでFTPを使って管理ユーザーを追加する場合

WordPress管理エリアの代わりにFTPを使用してWordPress管理ユーザーを追加することは、いくつかの状況で必要になる場合があります:

  • 管理者権限の喪失– パスワードを忘れた、セキュリティ・プラグインでロックされた、プラグインやテーマに問題があるなどの理由でWordPressの管理ダッシュボードに入れない場合、FTPで新しい管理ユーザーを作成してアクセス権を回復することができます。
  • WordPressの破損WordPressでよくあるエラーで管理ダッシュボードにアクセスできないことがあります。FTP経由で新規管理ユーザーを作成することで、コントロールを取り戻すことができます。
  • セキュリティの問題サイトがハッキングされ、ハッカーが管理者アクセス権を取得した場合、新しい管理者ユーザーを作成することで、ハッカーを追い出し、サイトを保護することができます。
  • 移行時の問題– サイトの移行時(ローカルホストからライブサーバーへの移行など)、管理ユーザーが動作しない、または情報をリセットする必要がある場合、FTPで新しい管理ユーザーを作成することですぐに解決できます。

このことを念頭に置いて、FTPを使用してWordPressサイトに管理ユーザーを簡単に追加する方法をステップバイステップで説明します。

プロからのアドバイス WordPressサイトのトラブルでお困りですか?WordPressの緊急サポートがお役に立ちます。ダウンタイムが発生した場合でも、サイトがハッキングされた場合でも、サイトを迅速にオンラインに戻すことができます。

FTPでWordPressに新規管理者アカウントを追加する方法

まず最初に、FTPクライアントが必要です。このソフトウェアを使えば、ダッシュボードにログインせずにWordPressにアクセスすることができます。

新しい管理者アカウントを追加するだけでなく、プラグインを無効化したり、お気に入りのプラグインを一括インストールすることもできます。

このチュートリアルではFileZillaを使います。

次に、FTPクライアントでサイトを接続する必要があります。これを行うには、FTPアクセス詳細(通常、cPanelまたは他のホスティングコントロールパネルでアクセス可能)が必要です。

ステップバイステップのガイダンスについては、WordPressでファイルをアップロードするためにFTPを使用する方法についてのガイドを参照してください。

FTPクライアントがあなたのサイトのファイルに接続されたら、現在のWordPressテーマのfunctions.phpファイルを見つける必要があります。FTPウィンドウの右側、現在のテーマのフォルダーの中にあるファイルを見つけることができるはずです:

/public_html/wp-content/themes/your-current-theme/

画面はこんな感じです。デモサイトは初期設定のTwenty Twenty-Fourテーマを使っています。

Locating functions.php file in FTP

functions.phpファイルを見つけたら、ダブルクリックします。FileZillaがファイルをコンピューターにダウンロードします。

この段階で、コンピューター上にあるファイルを探してください。その後、メモ帳のようなプレーンテキストエディターで開いてください。

次に、管理ユーザー・アカウントを追加するために、このコード・スニペットをファイルの一番下に挿入する必要がある:

1
2
3
4
5
6
7
8
9
10
function wpb_admin_account(){
$user = 'Username';
$pass = 'Password';
$email = 'email@domain.com';
if ( !username_exists( $user )  && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
} }
add_action('init','wpb_admin_account');

UsernamePasswordemail@domain.comを独自の値に置き換えることを忘れないでください。必要であれば、同じコード・スニペットを使用して他のユーザ権限を作成することもできます。

ファイルはこんな感じだ:

Adding the new admin user account code in functions.php

次に、ファイルを保存してFTPクライアントに戻る。

ここで、インターフェースの左側にある編集したばかりのファイルを探す必要があります。それを右クリックし、「アップロード」をクリックします。

Uploading the functions.php file via FTP

新しいウィンドウがポップアップ表示され、ファイルがすでにあなたのサイトのファイルに存在していることを示します。

上書き』オプションを設定し、『OK』をクリックするだけです。

Overwriting an existing functions.php file via FTP

ブラウザーでyourwebsitename.com/wp-adminを開いてください。yourwebsitename.comを自分のドメイン名に置き換えることを忘れないでください。

コードタイプがうまくいけば、ログインページにログイン情報を入力し、WordPress管理エリアに再びアクセスできるようになります。

The default WordPress login page

注: WordPressサイトにログインしたら、FTPクライアントに戻ってfunctions.phpファイルをもう一度開き、追加したコードを削除してください。

コードを削除してもユーザーは削除されません。これは、コードが再び実行され、意図しない結果を招くことがないようにするためです。さらに、必要であればいつでもWordPressサイトに新しいユーザーや作者を追加することができます。

別の方法ホスティングサービスのファイルマネージャーで新規管理ユーザーを追加する。

FTP接続がうまくいかず、WordPressの管理画面からロックアウトされている場合は、WordPressホスティングサービスのファイルマネージャーを使用して、functions.phpにコードを追加することができます。初心者の方は、この方法の方が簡単かもしれません。

このチュートリアルでは、Bluehostのファイルマネージャーを使用します。ホスティングダッシュボードで、「Websites」タブに移動し、ロックアウトされているWordPressサイトを見つけ、「Settings」をクリックします。

Bluehost site settings

中に入ったら、クイックリンクセクションまでスクロールダウンしてください。

次に、『ファイル・マネージャー』をクリックする。

Bluehost File Manager button

前の方法と同じように、現在のWordPressサイトのfunctions.phpファイルを見つける必要があります。

見つけたら、ファイルを右クリックして「編集」を選択するだけだ。

Editing a functions.php file in Bluehost file manager

次に、先ほどの方法と同じコード・スニペットを貼り付ける。

変更を保存」をクリックします。

Adding an add new admin user code in the WordPress functions.php file using Bluehost file manager

次に必要なことは、WordPressのログインURLにアクセスし、新しい管理ユーザーのログイン情報でサインインしてみることです。

ボーナス:WordPressのfunctions.phpハックをさらに詳しく学ぶ

新しい管理ユーザーを追加する以外にも、実はfunctions.phpファイルでできるクールなトリックがたくさんあります。

例えば、WordPressテーマの初期設定にはない新しいウィジェットエリアを追加することができる。こうすることで、ウィジェットを挿入するスペースが増える。

これらのハックのすべてについては、WordPress functions.phpファイルの便利なトリックの究極のリストでさらに詳しく説明しています。

また、これらのヒントやトリックをすべて試してみたい場合は、WPCodeを使用することをお勧めします。FTPクライアントでfunctions.phpを編集することも可能ですが、WPCodeを使えば、ファイルに追加するさまざまなコードスニペットをすべて安全かつ簡単に管理することができます。

こうすることで、追加されたすべてのカスタムコードスニペットをトラッキングし、エラーが発生した場合は数クリックで無効化することができる。

詳しくはWPCodeのレビューをご覧ください。

WPCode

このWordPressチュートリアルで、FTPを使ってWordPressに管理ユーザーを追加する方法を学んでいただけたでしょうか。WordPressのcronジョブの表示とコントロール方法WordPressのwp-cronを無効化し、適切なcronジョブを設定する方法についての投稿もご覧ください。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

アバター

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

28件のコメントLeave a Reply

  1. Faisal

    Worked like a charm.

    Thank you

    • WPBeginner Support

      You’re welcome!

      Admin

  2. Piotr Szcześniak

    Never remeber the snippet so I’m happy to frequently visit you guys! Thx!

  3. Thomas Hansen

    If you are using a child theme is it then the functions.php of the child theme, that you need to insert the code into?

    • WPBeginner Support

      Yes, you would want to add the code there.

      Admin

  4. André Cassiano

    Worked like a charm! Tks.

    • WPBeginner Support

      Glad our guide was able to help :)

      Admin

  5. imran

    worked, Thanks!!

    • WPBeginner Support

      You’re welcome :)

      Admin

  6. Kim H

    Worked like a charm. Thank you for this article!

    • WPBeginner Support

      You’re welcome :)

      Admin

  7. Donovan

    Worked perfectly. Thanks for the great advice.

    • WPBeginner Support

      Glad our article was helpful :)

      Admin

  8. Peter

    Thanks! It worked!

    • WPBeginner Support

      You’re welcome, glad our guide was helpful :)

      Admin

    • WPBeginner Support

      Thanks :)

      Admin

  9. adam

    Thanks man it worked even in WordPress version 4.9.0
    Many Thanks brother !

  10. Warner Mendenhall

    Thank you. Worked perfectly.

  11. charu

    Is any way to delete that entry from database that I have created through function.php i.e delete the last created user for using admin area.

    Thanks

  12. Shafaq

    good explanation but there is an error with my code. user role changed if go into user profile page otherwise no effect . can you please elaborate.

    here is my code

    $level = $profileuser->ihc_user_levels ;
    $id = $profileuser->id ;
    $u= new WP_User( $id ) ;

    if ( $level==’3′) {
    echo ‘user level ‘.$level;
    echo ‘user id ‘.$id;
    $u = wp_update_user( $u->set_role( ‘featured’ ) );
    }

  13. Stef

    I got the big problem that this new user has first to be activated..

    Is it possible to set the activation of the user by function or did I lose and I need to install a backup on my wordpress via ftp?

  14. Rdas

    I have latest WordPress version will it work for me or need to change anything on the code?

  15. Guille

    Great explanation. Thank you so much for this tip. It works like a charm!

  16. Hardeep

    Hello,

    Really informative post, I am developer and sometimes I have to contact sys admin to reset or create new wp user for testing.

    This is very good way, thanks for sharing

  17. Toni Weidman

    How secure is this going to be on an FTP host?

    • Patrick Johanneson

      Not very. So the first thing you should do once you’re logged back in is change the password on that new admin account. Then remove the code from functions.php.

    • Andre

      Start with SFTP with an FTP client (program) that has that. But as Patrick mentioned, you NEED to change your password once you are back in. I don’t mean a simple password either, always make sure you use at least 12 characters mixed with numbers, symbols, lower and uppercase letters (avoid using words).

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.