{"id":662,"date":"2023-05-13T10:19:51","date_gmt":"2023-05-13T03:19:51","guid":{"rendered":"https:\/\/dev.artru.eu.org\/?p=662"},"modified":"2023-08-21T17:37:25","modified_gmt":"2023-08-21T10:37:25","slug":"bao-mat-rest-api","status":"publish","type":"post","link":"https:\/\/artru.net\/zh\/bao-mat-rest-api\/","title":{"rendered":"\u5728 Wordpress \u4e2d\u4fdd\u62a4 REST API"},"content":{"rendered":"<h2 class=\"wp-block-heading\">\u662f\u5426\u53ef\u4ee5\u7981\u7528 REST API\uff1f<\/h2>\n\n\n\n<p>\u8fd9\u4e5f\u662f\u6211\u601d\u8003\u4e86\u5f88\u4e45\u7684\u540c\u4e00\u4e2a\u95ee\u9898\u3002\u5728\u4e86\u89e3\u4e86 API \u4e4b\u540e\uff0c\u6211\u5f97\u5230\u4e86\u7b54\u6848\u3002<\/p>\n\n\n\n<p>REST API \u5b8c\u5168\u96c6\u6210\u5728 WordPress 4.7 (2016) \u7248\u4e2d\u3002\u6240\u4ee5 WordPress \u7ba1\u7406\u529f\u80fd\u4f9d\u8d56\u4e8e API\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u8fc7\u6ee4\u5668\u6765\u9a8c\u8bc1 API \u7528\u6237\u8bf7\u6c42\u3002\u8fd9\u6709\u6548\u5730\u963b\u6b62\u4e86\u5916\u90e8 API \u8bbf\u95ee\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd ADMIN \u5e10\u6237\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u63d2\u5165 php \u4ee3\u7801\u4ee5\u7981\u7528 REST API<\/h2>\n\n\n\n<p>\u5c06\u4ee3\u7801\u63d2\u5165\u4e3b\u9898\/\u5b50\u4e3b\u9898\u6216mu-plugins\u7684functionc.php\u6587\u4ef6\u4e2d\uff08\u6211\u4f7f\u7528mu-plugins\u4f5c\u4e3a\u7f51\u7ad9\u7684\u529f\u80fd\u914d\u7f6e\u6587\u4ef6\uff09\u3002<\/p>\n\n\n\n<p><strong>PHP\u4ee3\u7801\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\" data-no-translation=\"\" data-no-auto-translation=\"\"><code data-no-translation=\"\" data-no-auto-translation=\"\">\/** T\u1eaft REST API cho ng\u01b0\u1eddi d\u00f9ng ch\u01b0a \u0111\u0103ng nh\u1eadp *\/\nadd_filter( 'rest_authentication_errors', function( $result ) {\n    if ( true === $result || is_wp_error( $result ) ) {\n        return $result;\n    }\n    if ( ! is_user_logged_in() ) {\n        return new WP_Error(\n            'rest_not_logged_in',\n            __( 'You are not currently logged in.' ),\n            array( 'status' =&gt; 401 )\n        );\n    }\n    return $result;\n});<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>C\u00f3 th\u1ec3 t\u1eaft REST API kh\u00f4ng? \u0110\u00e2y c\u0169ng ch\u00ednh l\u00e0 v\u1ea5n \u0111\u1ec1 m\u00e0 m\u00ecnh suy t\u01b0 b\u1ea5y l\u00e2u. Sau khi m\u00ecnh t\u00ecm hi\u1ec3u v\u1ec1 API th\u00ec \u0111\u00e3 c\u00f3 \u0111\u01b0\u1ee3c c\u00e2u [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-662","post","type-post","status-publish","format-standard","hentry","category-website"],"_links":{"self":[{"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/posts\/662","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/comments?post=662"}],"version-history":[{"count":0,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/posts\/662\/revisions"}],"wp:attachment":[{"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/media?parent=662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/categories?post=662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artru.net\/zh\/wp-json\/wp\/v2\/tags?post=662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}