
{"id":8788,"date":"2023-10-25T08:37:29","date_gmt":"2023-10-25T01:37:29","guid":{"rendered":"https:\/\/tapchicntt.com\/?p=8788"},"modified":"2025-04-15T11:32:14","modified_gmt":"2025-04-15T04:32:14","slug":"wordpress-vo-hieu-hoa-rest-api-wp-json-trong-wordpress","status":"publish","type":"post","link":"https:\/\/tapchicntt.com\/wordpress-vo-hieu-hoa-rest-api-wp-json-trong-wordpress\/","title":{"rendered":"[WordPress] V\u00f4 hi\u1ec7u h\u00f3a REST API (wp-json) trong wordpress"},"content":{"rendered":"\n<p>Trong Wordpres th\u00ec REST API l\u00e0 l\u1ee3i \u00edch qu\u1ea3n l\u00fd WordPress b\u1eb1ng API. Nh\u01b0ng \u0111\u1ed3ng ngh\u0129a v\u1edbi l\u1ee3i \u00edch, th\u00ec n\u00f3 c\u0169ng mang l\u1ea1i r\u1ee7i ro v\u1ec1 b\u1ea3o m\u1eadt nh\u01b0 c\u00f3 th\u1ec3 d\u1ec5 d\u00e0ng crawler d\u1eef li\u1ec7u, ho\u1eb7c c\u00e1c hacker c\u00f3 th\u1ec3 th\u1ef1c hi\u1ec7n c\u00e1c cu\u1ed9c t\u1ea5n c\u00f4ng&nbsp;Brute Force \u0111\u1ec3 l\u1ea5y m\u1eadt kh\u1ea9u c\u1ee7a b\u1ea1n.<\/p>\n\n\n\n<p>V\u00ec v\u1eady, n\u1ebfu kh\u00f4ng s\u1eed d\u1ee5ng REST API, b\u1ea1n n\u00ean v\u00f4 hi\u1ec7u h\u00f3a n\u00f3 \u0111i.<\/p>\n\n\n\n<p>R\u1ea5t \u0111\u01a1n gi\u1ea3n l\u00e0 s\u1eed d\u1ee5ng \u0111o\u1ea1n code d\u01b0\u1edbi \u0111\u00e2y \u0111\u1eb7t v\u00e0o file&nbsp;<code>functions.php<\/code>&nbsp;c\u1ee7a theme m\u00e0 b\u1ea1n \u0111ang s\u1eed d\u1ee5ng:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nadd_filter( &#039;rest_authentication_errors&#039;, function( $result ) {\n    if ( ! empty( $result ) ) {\n        return $result;\n    }\n    if ( ! is_user_logged_in() ) {\n        return new WP_Error( &#039;rest_not_logged_in&#039;, &#039;You are not currently logged in.&#039;, array( &#039;status&#039; =&gt; 401 ) );\n    }\n    return $result;\n});\n<\/pre><\/div>\n\n\n<p>\u0110o\u1ea1n code tr\u00ean s\u1ebd y\u00eau c\u1ea7u t\u1ea5t c\u1ea3 c\u00e1c request t\u1edbi REST API Endpoint ph\u1ea3i b\u1eaft bu\u1ed9c x\u00e1c th\u1ef1c \u0111\u0103ng nh\u1eadp m\u1edbi c\u00f3 th\u1ec3 l\u1ea5y d\u1eef li\u1ec7u v\u1ec1.<\/p>\n\n\n\n<p>Ho\u1eb7c c\u00e1c b\u1ea1n c\u00f3 th\u1ec3 ph\u00e2n \u0111\u1ecbnh 1 s\u1ed1 user c\u00f3 quy\u1ec1n request t\u1edbi REST API:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nadd_filter( &#039;rest_authentication_errors&#039;, function( $result ) {\n    if ( ! empty( $result ) ) {\n        return $result;\n    }\n    if ( ! is_user_logged_in() ) {\n        return new WP_Error( &#039;rest_not_logged_in&#039;, &#039;You are not currently logged in.&#039;, array( &#039;status&#039; =&gt; 401 ) );\n    } else if ( ! current_user_can(&#039;administrator&#039;) {\n\t\treturn new WP_Error( &#039;rest_not_user&#039;, &#039;You do not have permission to use it.&#039;, array( &#039;status&#039; =&gt; 401 ) );\n\t}\n    return $result;\n});\n<\/pre><\/div>\n\n\n<p>\u0110o\u1ea1n code tr\u00ean s\u1ebd y\u00eau c\u1ea7u t\u1ea5t c\u1ea3 c\u00e1c request t\u1edbi REST API Endpoint ph\u1ea3i b\u1eaft bu\u1ed9c x\u00e1c th\u1ef1c \u0111\u0103ng nh\u1eadp v\u00e0 user v\u1edbi quy\u1ec1n <code>administrator<\/code> m\u1edbi c\u00f3 th\u1ec3 l\u1ea5y d\u1eef li\u1ec7u v\u1ec1.<\/p>\n\n\n\n<p>V\u00ec WordPress khuy\u1ebfn ngh\u1ecb ch\u00fang ta kh\u00f4ng n\u00ean v\u00f4 hi\u1ec7u ho\u00e0n to\u00e0n REST API, n\u00f3 s\u1ebd l\u00e0m \u1ea3nh h\u01b0\u1edfng t\u1edbi c\u00e1c ch\u1ee9c n\u0103ng c\u1ee7a WP-Admin.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Trong Wordpres th\u00ec REST API l\u00e0 l\u1ee3i \u00edch qu\u1ea3n l\u00fd WordPress b\u1eb1ng API. Nh\u01b0ng \u0111\u1ed3ng ngh\u0129a v\u1edbi l\u1ee3i \u00edch, th\u00ec [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":6979,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[241,143],"tags":[],"class_list":["post-8788","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hooks","category-thu-thuat-wordpress"],"views":809,"_links":{"self":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/8788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/comments?post=8788"}],"version-history":[{"count":4,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/8788\/revisions"}],"predecessor-version":[{"id":9701,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/8788\/revisions\/9701"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media\/6979"}],"wp:attachment":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media?parent=8788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/categories?post=8788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/tags?post=8788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}