Frontend Submissions は、プログラムで利用できる多くの機能を提供します。
ユーザーをベンダーにする
Frontend Submissions には、 make_user_vendor() というヘルパー関数があり、これは一度に2つのことを行います。
- ユーザーをベンダーにする
- その新しいベンダーのステータスを承認済みに変更する
EDD_FES()->vendors->make_user_vendor( $user_id );
重要: 上記で使用されている ID パラメータは、WordPress のユーザー ID です。
ベンダーのステータスを変更する
ベンダーには3つのステータスがあります。
- 承認済み
- 保留中
- 一時停止中
実行できるアクションも2つあります。
- 一時停止解除
- 取り消し
これらすべてが同じメソッドを使用しますが、ステータスとアクションは異なるものです。 仕組みは次のとおりです。
まず、これらのいずれかのような Frontend Submissions オブジェクトをインスタンス化する必要があります。
// Example showing required input $vendor = new FES_Vendor( $_id_or_email = false, $by_user_id = false );
// using a vendor ID $vendor = new FES_Vendor( 14, false ); // using the email address associated with the vendor ID $vendor = new FES_Vendor( '[email protected]', true );
次に、これらの例のいずれかのように、そのオブジェクトで change_status() メソッドを実行します。
// Example showing required input $vendor->change_status( $new_status = '', $in_admin = false, $output = false );
$in_admin 入力により、このアクションを管理エリアのコンテキストで許可するかどうか、またはその外部で許可するかどうかを宣言できます。たとえば、管理エリア内ではこの変更を許可したいが、管理エリア外では許可したくない場合があります。
// Set a vendor to approved, inside the admin area, with no output $vendor->change_status( 'approved' ); // Set a vendor to pending, outside the admin area, with no output $vendor->change_status( 'pending', true ); // Set a vendor to suspended, outside the admin area, with no output $vendor->change_status( 'suspended', true, true );
上記のステータス変更に加えて、次のアクションを実行できます。
// Revoke a vendor, inside the admin area, with no output. // This will effectively make a user NOT a vendor, and remove all their products. $vendor->change_status( 'revoke' ); // Changes a user from suspended to approved. At this point identical to setting // a user to approved, but in the future may contain some additional features. $vendor->change_status( 'unsuspend' );
