{"id":13666345,"url":"https://github.com/YahnisElsts/ajax-wrapper","last_synced_at":"2025-04-26T12:31:25.459Z","repository":{"id":149771647,"uuid":"79485081","full_name":"YahnisElsts/ajax-wrapper","owner":"YahnisElsts","description":"AJAX action wrapper for WordPress","archived":false,"fork":false,"pushed_at":"2025-03-06T10:24:02.000Z","size":14,"stargazers_count":21,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T15:50:31.635Z","etag":null,"topics":["wordpress"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YahnisElsts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-01-19T19:05:08.000Z","updated_at":"2025-04-07T22:32:46.000Z","dependencies_parsed_at":"2025-04-22T15:52:26.979Z","dependency_job_id":null,"html_url":"https://github.com/YahnisElsts/ajax-wrapper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YahnisElsts%2Fajax-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YahnisElsts%2Fajax-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YahnisElsts%2Fajax-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YahnisElsts%2Fajax-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YahnisElsts","download_url":"https://codeload.github.com/YahnisElsts/ajax-wrapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250986429,"owners_count":21518511,"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":["wordpress"],"created_at":"2024-08-02T06:01:15.421Z","updated_at":"2025-04-26T12:31:25.130Z","avatar_url":"https://github.com/YahnisElsts.png","language":"PHP","funding_links":[],"categories":["WordPress Plugins","Helper library, code snippet"],"sub_categories":["2. Sage"],"readme":"# AJAX Action Wrapper\n\nThis helper library makes it easier to handle AJAX requests in WordPress plugins. Mainly for personal use.\n\n### Example\nDefine action:\n```php\n$exampleAction = ajaw_v1_CreateAction('ws_do_something')\n\t-\u003ehandler(array($this, 'myAjaxCallback'))\n\t-\u003erequiredCap('manage_options')\n\t-\u003emethod('post')\n\t-\u003erequiredParam('foo')\n\t-\u003eoptionalParam('bar', 'default value')\n\t-\u003eregister();\n```\n\nCall from JavaScript:\n```javascript\nAjawV1.getAction('ws_do_something').post(\n\t{\n\t\t'foo': '...'\n\t},\n\tfunction(response) {\n\t\tconsole.log(response);\n\t}\n);\n```\n\n### Features\n- Automate common, boring stuff.\n\t- [x] Automatically pass the `admin-ajax.php` URL and nonce to JS.\n\t- [x] Define required parameters.\n\t\t```php\n\t\t$builder-\u003erequiredParam('foo', 'int')\n\t\t```\n\t- [x] Define optional parameters with default values.\n\t\t```php\n\t\t$builder-\u003eoptionalParam('meaningOfLife', 42, 'int')\n\t\t```\n\t- [x] Automatically remove \"magic quotes\" that WordPress adds to `$_GET`, `$_POST` and `$_REQUEST`.\n\t- [x] Encode return values as JSON.\n- Security should be the default.\n\t- [x] Generate and verify nonces. Nonce verification is on by default, but can be disabled.\n\t\t```php\n\t\t$builder-\u003ewithoutNonce()\n\t\t```\n\t- [x] Check capabilities.\n\t\t```php\n\t\t$builder-\u003erequiredCap('manage_options');\n\t\t```\n\t- [x] Verify that all required parameters are set.\n\t- [x] Validate parameter values.\n\t\t```php\n\t\t$builder-\u003eoptionalParam('things', 1, 'int', function($value) {\n\t\t\tif ($value \u003e 10) {\n\t\t\t\treturn new WP_Error(\n\t\t\t\t\t'excessive_things',\n\t\t\t\t\t'Too many things!',\n\t\t\t\t\t400 //HTTP status code.\n\t\t\t\t);\n\t\t\t}\n\t\t})\n\t\t```\n\t- [x] Set the required HTTP method.\n\t\t```php\n\t\t$builder-\u003emethod('post')\n\t\t```\n- Resilience.\n\t- [ ] Lenient response parsing to work around bugs in other plugins. For example, deal with extraneous whitespace and PHP notices in AJAX responses.\n\t- [x] Multiple versions of the library can coexist on the same site.\n\n### Why not use the REST API instead?\n\nBackwards compatibility. In theory, this library should be compatible with WP 4.1+.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYahnisElsts%2Fajax-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FYahnisElsts%2Fajax-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYahnisElsts%2Fajax-wrapper/lists"}