私は入力として画像を取るWordpressのプラグインを作っています。私は、画像を追加したり削除したりするためにユーザにインターフェースを与える必要があります。このインターフェースを提供するための最良の選択肢は何ですか?wordpressプラグインのテキスト入力を受け入れるインターフェイス
1
A
答えて
0
私はmedia_handle_upload()
があなたが探しているものだと思います。このWordPress関数は、ファイルのアップロード/ POST要求を処理し、データベースに添付ファイルの投稿を作成します。 WordPressコーデックスのHere is the full documentation
これを使用して、ユーザーがフォームを介してフロントエンドから画像をアップロードできるようにするインターフェイスを作成できます。
アップロードフォーム(例):
<form id="featured_upload" method="post" action="#" enctype="multipart/form-data">
<input type="file" name="my_image_upload" id="my_image_upload" multiple="false" />
<input type="hidden" name="post_id" id="post_id" value="55" />
<?php wp_nonce_field('my_image_upload', 'my_image_upload_nonce'); ?>
<input id="submit_my_image_upload" name="submit_my_image_upload" type="submit" value="Upload" />
</form>
ここ
は、現在
Codex(将来の場合は、ここでそれを再投稿リンクの変更)で
media_handle_upload
のために与える公式の一例です
保存アタッチメント(例):
<?php
// Check that the nonce is valid, and the user can edit this post.
if (
isset($_POST['my_image_upload_nonce'], $_POST['post_id'])
&& wp_verify_nonce($_POST['my_image_upload_nonce'], 'my_image_upload')
&& current_user_can('edit_post', $_POST['post_id'])
) {
// The nonce was valid and the user has the capabilities, it is safe to continue.
// These files need to be included as dependencies when on the front end.
require_once(ABSPATH . 'wp-admin/includes/image.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/media.php');
// Let WordPress handle the upload.
// Remember, 'my_image_upload' is the name of our file input in our form above.
$attachment_id = media_handle_upload('my_image_upload', $_POST['post_id']);
if (is_wp_error($attachment_id)) {
// There was an error uploading the image.
} else {
// The image was uploaded successfully!
}
} else {
// The security check failed, maybe show the user an error.
}
画像をアップロードするには、wp_delete_attachment
のプラグインが必要な場合があります。 (Full Documentation here)。
これにより、特定のメディア添付ファイルをIDで削除できます。ここではコーデックスで与えられた例である:あなたのニーズに応じて
<?php wp_delete_attachment(76); ?>
あなたが同様にあなたのプラグインでそれらのいくつかを使用する場合がありますように、私はまた、Related "Attachments" functions in the Codexを模索推薦します。
関連する問題
- 1. テーブルビューのセルにテキスト入力を受け入れるには?
- 2. Pygame GUIからのテキスト入力を受け入れる方法
- 3. 簡単なテキスト入力フィールドで改行を受け入れる
- 4. MVC剃刀、テキスト入力で記号(<)を受け入れる
- 5. ジャバスクリプトの入力を受け入れる
- 6. ログインユーザー入力を受け入れるトリガー
- 7. インターフェイスの配列を受け入れるか、TypeScriptの単一インターフェイスを受け入れます。
- 8. javascript - テキスト入力正の整数だけを受け入れる方法
- 9. 複数のIPアドレスを受け入れるためのJqueryプラグイン入力フィールド
- 10. JSON形式の入力を受け入れるためのカスタムWordPress REST API
- 11. 入力テキスト要素が入力としてドロップされた要素を受け入れるのを防ぐ
- 12. jsp入力テキストIDは文字列のみを受け入れる
- 13. Android - テキストの編集...キーボードからの入力が受け入れられない
- 14. Django forms.FloatFieldとIntegerFieldは、検証エラーなしでテキスト入力を受け入れる
- 15. maxlengthで数字だけを受け入れる入力フィールド
- 16. ウェブサイトのユーザーからのYAML入力を受け入れる
- 17. 0〜12の数字のみを受け入れる入力フィールド?
- 18. 入力の種類のみを受け入れる
- 19. レガシーコードの受け入れを受け入れる
- 20. Javaのファイルから入力を受け入れる
- 21. テキストボックスからの入力を受け入れる方法
- 22. 文字のみを入力として受け入れる
- 23. ログインテンプレートすべての入力を受け入れる
- 24. bashスクリプトで複数の入力行を受け入れる
- 25. Ember.js受け入れテストの入力値を確認する
- 26. javaScript - 数値入力 - 特定の数値を受け入れる
- 27. スキャナ入力の空白値を受け入れる方法
- 28. キャンバスへのhtml入力がバックスペースを受け入れる
- 29. select:非公開の文字入力を受け入れる
- 30. Javaでゲッタークラスのユーザー入力を受け入れる