تابع ووکامرسی wc_rest_check_post_permissions بررسی permission پست محصول

تابع ووکامرسی wc_rest_check_post_permissions – بررسی permission پست محصول
Syntax – سینتکس
wc_rest_check_post_permissions( (string) $post_type, (string) $context = 'read', (int) $object_id = 0 );
Parameters – پارامتر ها (3)
- 1- $post_type (string)
- 2- $context (string)
- 3- $object_id (int)
Usage – نحوه استفاده
if ( !function_exists( 'wc_rest_check_post_permissions' ) ) {
require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-rest-functions.php';
}
// The post type.
$post_type = '';
// Request context.
$context = 'read';
// The object id.
$object_id = -1;
// NOTICE! Understand what this does before running.
$result = wc_rest_check_post_permissions($post_type, $context, $object_id);
Defined – محل تعریف
/includes/wc-rest-functions.php
function wc_rest_check_post_permissions( $post_type, $context = 'read', $object_id = 0 ) {
$contexts = array(
'read' => 'read_private_posts',
'create' => 'publish_posts',
'edit' => 'edit_post',
'delete' => 'delete_post',
'batch' => 'edit_others_posts',
);
if ( 'revision' === $post_type ) {
$permission = false;
} else {
$cap = $contexts[ $context ];
$post_type_object = get_post_type_object( $post_type );
$permission = current_user_can( $post_type_object->cap->$cap, $object_id );
}
return apply_filters( 'woocommerce_rest_check_permissions', $permission, $context, $object_id, $post_type );
}
versions – نسخه ها
از نسخه : 2.6.0
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر