{"id":15027764,"url":"https://github.com/dwnload/wpsettingsapi","last_synced_at":"2025-04-09T20:22:30.652Z","repository":{"id":23061881,"uuid":"98045994","full_name":"dwnload/WpSettingsApi","owner":"dwnload","description":"A PHP class abstraction that removes all the headaches of the WordPress settings API under the hood and builds a nice options panel on the fly. ","archived":false,"fork":false,"pushed_at":"2024-04-25T16:14:00.000Z","size":357,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2024-04-25T20:17:25.195Z","etag":null,"topics":["package","php","php80","php81","wordpress","wordpress-api","wordpress-php-library","wordpress-settings-api"],"latest_commit_sha":null,"homepage":"https://frosty.media/plugins/wp-settings-api/","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/dwnload.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2017-07-22T17:08:17.000Z","updated_at":"2024-04-25T16:14:03.000Z","dependencies_parsed_at":"2024-09-24T20:07:06.623Z","dependency_job_id":null,"html_url":"https://github.com/dwnload/WpSettingsApi","commit_stats":{"total_commits":182,"total_committers":5,"mean_commits":36.4,"dds":0.3846153846153846,"last_synced_commit":"85f6a145b808e590e2688334fc554c1c76f05383"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwnload%2FWpSettingsApi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwnload%2FWpSettingsApi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwnload%2FWpSettingsApi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwnload%2FWpSettingsApi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwnload","download_url":"https://codeload.github.com/dwnload/WpSettingsApi/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248104772,"owners_count":21048402,"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":["package","php","php80","php81","wordpress","wordpress-api","wordpress-php-library","wordpress-settings-api"],"created_at":"2024-09-24T20:07:00.873Z","updated_at":"2025-04-09T20:22:30.631Z","avatar_url":"https://github.com/dwnload.png","language":"PHP","readme":"# Dwnload WordPress Settings Api\n\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/dwnload/wp-settings-api.svg)]()\n[![Latest Stable Version](https://img.shields.io/packagist/v/dwnload/wp-settings-api.svg)](https://packagist.org/packages/dwnload/wp-settings-api)\n[![Total Downloads](https://img.shields.io/packagist/dt/dwnload/wp-settings-api.svg)](https://packagist.org/packages/dwnload/wp-settings-api)\n[![License](https://img.shields.io/packagist/l/dwnload/wp-settings-api.svg)](https://packagist.org/packages/dwnload/wp-settings-api)\n![Build Status](https://github.com/dwnload/WpSettingsApi/actions/workflows/main.yml/badge.svg)\n[![codecov](https://codecov.io/gh/dwnload/WpSettingsApi//branch/develop/graph/badge.svg)](https://codecov.io/gh/dwnload/WpSettingsApi/)\n\nIt's a PHP class wrapper for handling WordPress [Settings API](http://codex.wordpress.org/Settings_API).\n\n## Package Installation (via Composer)\n\nTo install this package, edit your `composer.json` file:\n\n```json\n{\n    \"require\": {\n        \"dwnload/wp-settings-api\": \"^3.8\"\n    }\n}\n```\n\nNow run:\n\n`$ composer install dwnload/wp-settings-api`\n\nUsage Example\n---------------\n\n@see [examples/Example.php](https://github.com/dwnload/WpSettingsApi/tree/master/examples/Example.php)\n\n#### Suggested package\n\n⭐️ `frontpack/composer-assets-plugin`\n\n**As of v3.2.1**, this shouldn't be needed any more (unless you are filtering local assets only). Assets will now\nbe loaded via the jsdelivr CDN. \n\n**Otherwise**, since this is a PHP package and not a WordPress plugin the assets included can't be loaded properly.\nIn order to have the settings page inherit the styles and use the proper JS, you've got to copy the\n`/assets` directory to your plugin or theme. Then add the following to filter the asset src to your\ndirectory:\n\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace Vendor\\Package;\n\nuse Dwnload\\WpSettingsApi\\Api\\Script;\nuse Dwnload\\WpSettingsApi\\Api\\Style;\nuse Dwnload\\WpSettingsApi\\WpSettingsApi;\nuse TheFrosty\\WpUtilities\\Plugin\\AbstractHookProvider;\nuse TheFrosty\\WpUtilities\\Plugin\\HooksTrait;\n\n/**\n * Class WpSettingsApi\n *\n * @package Dwnload\\WpSettingsApi\n */\nclass WpSettingsApiScripts extends AbstractHookProvider\n{\n\n\n    public function addHooks(array $scripts): void\n    {\n        \\add_filter(WpSettingsApi::FILTER_PREFIX . 'admin_scripts', [$this, 'adminScripts']);\n        \\add_filter(WpSettingsApi::FILTER_PREFIX . 'admin_styles', [$this, 'adminStyles']);\n    }\n    \n    /**\n     * The default script needs to be moved from the vendor directory somewhere into our app since the\n     * vendor directory is outside of the doc root.\n     * @param Script[] $scripts\n     * @return array\n     */\n    public function adminScripts(array $scripts): array\n    {\n        \\array_walk($scripts, function (Script $script, int $key) use (\u0026$scripts) {\n            switch ($script-\u003egetHandle()) {\n                case WpSettingsApi::ADMIN_SCRIPT_HANDLE:\n                /**\n                 * If you're not using the `TheFrosty\\WpUtilities\\Plugin\\AbstractHookProvider`\n                 * use `plugins_url()` in place of the `$this-\u003egetPlugin()-\u003egetUrl` or any other WP\n                 * function that will point to the asset.\n                 * (Should match `frontpack/composer-assets-plugin configs`)\n                 */\n                $scripts[$key]-\u003esetSrc($this-\u003egetPlugin()-\u003egetUrl('assets/js/admin.js'));\n                break;\n            case WpSettingsApi::ADMIN_MEDIA_HANDLE:\n                /**\n                 * If you're not using the `TheFrosty\\WpUtilities\\Plugin\\AbstractHookProvider`\n                 * use `plugins_url()` in place of the `$this-\u003egetPlugin()-\u003egetUrl` or any other WP\n                 * function that will point to the asset.\n                 * (Should match `frontpack/composer-assets-plugin configs`)\n                 */\n                $scripts[$key]-\u003esetSrc($this-\u003egetPlugin()-\u003egetUrl('assets/js/wp-media-uploader.js'));\n                break;\n            }\n            $this-\u003eregisterScript($script);\n        });\n    \n        return $scripts;\n    }\n    \n    /**\n     * The default style needs to be moved from the vendor directory somewhere into our app since the\n     * vendor directory is outside of the doc root.\n     * @param Style[] $styles\n     * @return array\n     */\n    public function adminStyles(array $styles): array\n    {\n        \\array_walk($styles, function (Style $style, int $key) use (\u0026$styles) {\n            if ($style-\u003egetHandle() === WpSettingsApi::ADMIN_STYLE_HANDLE) {\n                /**\n                 * If you're not using the `TheFrosty\\WpUtilities\\Plugin\\AbstractHookProvider`\n                 * use `plugins_url()` in place of the `$this-\u003egetPlugin()-\u003egetUrl` or any other WP\n                 * function that will point to the asset.\n                 */\n                $styles[$key]-\u003esetSrc($this-\u003egetPlugin()-\u003egetUrl('assets/css/admin.css'));\n                $this-\u003eregisterStyle($style);\n            }\n        });\n    \n        return $styles;\n    }\n    \n    /**\n     * If the script is not registered before being returned back to the filter the src still uses\n     * the vendor directory file path.\n     * @param Script $script\n     */\n    private function registerScript(Script $script): void\n    {\n        \\wp_register_script(\n            $script-\u003egetHandle(),\n            $script-\u003egetSrc(),\n            $script-\u003egetDependencies(),\n            $script-\u003egetVersion(),\n            $script-\u003egetInFooter()\n        );\n    }\n    \n    /**\n     * If the style is not registered before being returned back to the filter the src still uses\n     * the vendor directory file path.\n     * @param Style $style\n     */\n    private function registerStyle(Style $style): void\n    {\n        \\wp_register_style(\n            $style-\u003egetHandle(),\n            $style-\u003egetSrc(),\n            $style-\u003egetDependencies(),\n            $style-\u003egetVersion(),\n            $style-\u003egetMedia()\n        );\n    }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwnload%2Fwpsettingsapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwnload%2Fwpsettingsapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwnload%2Fwpsettingsapi/lists"}