WordPress 사용자 정의 기능 만들기
장바구니 플러그인을 개발하고 있으며, 고객을 위한 새로운 사용자 역할을 만들 예정입니다.
새로운 사용자 역할에 이러한 커스텀 기능을 할당할 수 있도록 커스텀 기능을 작성하는 방법이 질문입니다.이 답변은 새로운 기능을 만들 수 있는 방법을 제시했습니다만, 이것은 원래 기능의 새로운 명칭에 불과합니다.
커스텀 기능을 제어하는 새로운 기능을 만드는 방법을 설명할 수 있는 사람이 있습니까?
먼저 Wordpress 사용자 역할은 기능 집합으로 단순하다는 것을 이해해야 합니다.그렇긴 하지만, 당신이 플러그인을 만들고 있다고 했으니, 나는 당신이 코드화에 익숙하지 않다고 생각하고, 이것에 다른 플러그인을 사용하는 것보다 당신의 솔루션을 코드화하는 것을 두려워하지 않는다.
이 코드를 사용하면 새 사용자 역할을 만들고 사용자 지정 기능을 추가할 수 있습니다.
<?php
// create a new user role
function wpeagles_example_role()
{
add_role(
'example_role',
'example Role',
[
// list of capabilities for this role
'read' => true,
'edit_posts' => true,
'upload_files' => true,
]
);
}
// add the example_role
add_action('init', 'wpeagles_example_role');
이 사용자 역할에 커스텀 기능을 추가하려면 다음 코드를 사용합니다.
//adding custom capability
<?php
function wpeagles_example_role_caps()
{
// gets the example_role role object
$role = get_role('example_role');
// add a custom capability
// you can remove the 'edit_others-post' and add something else (your own custom capability) which you can use in your code login along with the current_user_can( $capability ) hook.
$role->add_cap('edit_others_posts', true);
}
// add example_role capabilities, priority must be after the initial role definition
add_action('init', 'wpeagles_example_role_caps', 11);
향후 참조: https://developer.wordpress.org/plugins/users/roles-and-capabilities/
플러그인별로 사용자 지정 역할 및 기능을 생성할 수 있습니다.커스텀 코드로 2개의 옵션을 사용할 수도 있고 기존의 플러그인을 사용할 수도 있습니다.
커스텀 코드의 경우:https://wordpress.stackexchange.com/questions/35165/how-do-i-create-a-custom-role-capability
기존 플러그인 사용:사용자 역할 및 기능
언급URL : https://stackoverflow.com/questions/14617732/wordpress-create-custom-capability
'itsource' 카테고리의 다른 글
SQL Server 2008 Express에서 동일한 서버에 SQL Server 데이터베이스를 복제하려면 어떻게 해야 합니까? (0) | 2023.04.07 |
---|---|
임시 테이블에 저장 프로시저 결과 삽입 (0) | 2023.04.07 |
MongoDB가 작동하지 않는다."오류: dbpath(/data/db)가 존재하지 않습니다." (0) | 2023.04.02 |
스트라이프 오류: '토큰이 지원되지 않습니다' 구독에 등록하려고 하면 (0) | 2023.04.02 |
Postgresql vs Oracle (0) | 2023.04.02 |