{"id":13520134,"url":"https://github.com/MarcoPal/wp-custom-endpoints","last_synced_at":"2025-03-31T16:30:34.697Z","repository":{"id":143941164,"uuid":"147035900","full_name":"MarcoPal/wp-custom-endpoints","owner":"MarcoPal","description":"WP Custom Endpoints, a blazing fast way to add custom endpoints to your Wordpress REST API, inspired by Laravel routing.","archived":false,"fork":false,"pushed_at":"2018-11-28T10:34:50.000Z","size":12,"stargazers_count":28,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-02T05:22:48.514Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MarcoPal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-09-01T22:03:14.000Z","updated_at":"2023-03-14T10:43:53.000Z","dependencies_parsed_at":"2024-02-23T01:27:24.589Z","dependency_job_id":null,"html_url":"https://github.com/MarcoPal/wp-custom-endpoints","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcoPal%2Fwp-custom-endpoints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcoPal%2Fwp-custom-endpoints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcoPal%2Fwp-custom-endpoints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcoPal%2Fwp-custom-endpoints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarcoPal","download_url":"https://codeload.github.com/MarcoPal/wp-custom-endpoints/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222670691,"owners_count":17020513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T05:02:12.340Z","updated_at":"2024-11-02T03:30:18.976Z","avatar_url":"https://github.com/MarcoPal.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# WP Custom Endpoints\nA plugin to add custom endpoints to your WordPress REST API\n\n1. Edit route.php to add your custom endpoints.\n2. Add your controllers to manage the routes\n3. (optional) Edit config.php to setup your API namespace and version.\n\n\nYou'll find all your defined routes in the main JSON at\nyourdomain.com/wp-json\n\n\n\n### Example\nFile route.php\n```\nRoute::get('posts', 'PostsController@getAllPosts');\nRoute::get('posts/{id?}', 'PostsController@getPostById');\nRoute::get('posts/{category}/{id}', 'PostsController@getPostById');\n```\n\nYour controller:\n```\nclass PostsController extends WP_Custom_Endpoints\n{\n\n    public static function getAllPosts()\n    {\n        $posts = get_posts(['posts_per_page' =\u003e 5]);\n        return array_map(function ($post) {\n            return self::post_schema($post);\n        }, $posts);\n    }\n    \n    \n    public static function getPostById($request)\n        {\n            if (!empty($request['category'])) {\n                // Filter all post by category\n            }\n    \n            if (empty($request['id']))\n                return self::getAllPosts([]);\n    \n            $post = get_post($request['id']);\n    \n            return self::post_schema($post);\n        }\n\n}\n```\n\n\u0026nbsp;\n\u0026nbsp;\n\nBy default you have 3 methods that you can extend in your controller:\n\n```\npublic function get_permission_callback();\n```\n\nIf this function returns true, the response will be proccessed\nIf it returns false, a default error message will be returned\nand the request will not proceed with processing\n\n\u0026nbsp;\n\u0026nbsp;\n\n```\npublic function get_validate_callback($param, $request, $key)\n\n```\nThis function should return true if the value is valid, and false if not.\n\n\u0026nbsp;\n\u0026nbsp;\n\n```\npublic function get_sanitize_callback($param, $request, $key)\n```\nUsed to sanitize the value of the argument before passing it to the main callback.\n\n\u0026nbsp;\n\u0026nbsp;\n\u0026nbsp;\n\u0026nbsp;\n\u0026nbsp;\n\u0026nbsp;\n\u0026nbsp;\n\u0026nbsp;\n\nTODO:\nAdd a 3rd parameter to the routes declaration to define custom callback methods\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMarcoPal%2Fwp-custom-endpoints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMarcoPal%2Fwp-custom-endpoints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMarcoPal%2Fwp-custom-endpoints/lists"}