{"id":26682972,"url":"https://github.com/dark-kitt/wordpress-theme-configuration","last_synced_at":"2025-07-21T22:32:42.164Z","repository":{"id":225293556,"uuid":"765033576","full_name":"dark-kitt/wordpress-theme-configuration","owner":"dark-kitt","description":"WordPress theme configuration MU-Plugin, which includes multiple WordPress hooks to improve themes","archived":false,"fork":false,"pushed_at":"2024-04-29T07:48:12.000Z","size":182,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-02T06:10:20.829Z","etag":null,"topics":["composer","composer-package","configuration-management","php","php8","wordpress","wordpress-plugin"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc-by-sa-4.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dark-kitt.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,"publiccode":null,"codemeta":null}},"created_at":"2024-02-29T06:46:05.000Z","updated_at":"2024-04-29T07:48:16.000Z","dependencies_parsed_at":"2024-03-01T09:25:37.047Z","dependency_job_id":"3ee91a22-5333-4af9-9818-39ed327b3475","html_url":"https://github.com/dark-kitt/wordpress-theme-configuration","commit_stats":null,"previous_names":["dark-kitt/wordpress-theme-configuration"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dark-kitt/wordpress-theme-configuration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dark-kitt%2Fwordpress-theme-configuration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dark-kitt%2Fwordpress-theme-configuration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dark-kitt%2Fwordpress-theme-configuration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dark-kitt%2Fwordpress-theme-configuration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dark-kitt","download_url":"https://codeload.github.com/dark-kitt/wordpress-theme-configuration/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dark-kitt%2Fwordpress-theme-configuration/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266392685,"owners_count":23922217,"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","status":"online","status_checked_at":"2025-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["composer","composer-package","configuration-management","php","php8","wordpress","wordpress-plugin"],"created_at":"2025-03-26T08:28:45.485Z","updated_at":"2025-07-21T22:32:42.141Z","avatar_url":"https://github.com/dark-kitt.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **WordPress Theme Configuration**\n\nProject: [Part 1](https://github.com/dark-kitt/wordpress-boilerplate/tree/main), [**Part 2**](https://github.com/dark-kitt/wordpress-theme-configuration), [Part 3](https://github.com/dark-kitt/wordpress-theme-vue)\n\n---\n\n## Introduction\n\nA base WordPress theme configuration written as MU-Plugin, which includes multiple WordPress hooks to improve your theme. Configure the selected theme in the **_functions.php_** file with the listed methods below.\n\nThe [Autoloader MU-Plugin](https://github.com/dark-kitt/wordpress-mu-plugin-autoloader) is required to load this plugin by WordPress. After **composer update** copy the **_mu-plugin-autoloader.php_** file inside of the _`/mu-plugins`_ directory, to load the WordPress Theme Configuration MU-Plugin automatically.\n\nNote: The REST API uses the **JWT Authentication for WP REST API** to secure the API endpoints.\n\nGeneral WordPress configurations are placed in the **_base-configuration.php_** file. For each type / part of WordPress, you can find a PHP Trait in the _`/traits`_ directory. E.g.: attachment.php file for Media Library settings, post.php file for the Post settings... etc.\n\n**Note: The Gutenberg editor is always disabled!** If WP_HOME is different than WP_SITEURL the Gutenberg editor throws multiple errors. If you are interested, take a look at [Github WordPress / gutenberg (issue 1761).](https://github.com/WordPress/gutenberg/issues/1761)\n\nUse [ACF (Advanced Custom Fields)](https://www.advancedcustomfields.com/) or install the [Classic Editor Plugin](https://wordpress.org/plugins/classic-editor/), to add content to each post / page.\n\n### Methods\n\n- [get_instance()](#get_instance)\n- [set_up_theme()](#set_up_theme-wpdb-wp_rewrite-pagenow-array-args--defaults-)\n- [post()](#post-array-args--defaults-)\n- [page()](#page-array-args--defaults-)\n- [attachment()](#attachment-array-args--defaults-)\n- [comments()](#comments-array-args--defaults-)\n- [menu()](#menu-array-args--defaults-)\n- [custom_post_type()](#custom_post_type-array-args--defaults-)\n- [REST_API()](#rest_api-array-args--defaults-)\n\nControl each method with the passed **arguments** array or use the default settings. If you are interested in the defaults, want to check out each argument, or set your own custom defaults, take a look inside the trait files in the _`/trait`_ directory.\n\n### Requirements\n\n- [PHP: ^7.\\*](https://www.php.net/manual/de/mysql-xdevapi.installation.php)\n- [WordPress: ^5.5\\*](https://wordpress.org/support/article/how-to-install-wordpress/)\n- [WordPress MU-Plugin Autoloader](https://github.com/dark-kitt/wordpress-mu-plugin-autoloader)\n- [JWT Authentication for WP REST API](https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/)\n\n**to maintain content (optional)**\n\n- [ACF (Advanced Custom Fields)](https://www.advancedcustomfields.com/)\n- [Classic Editor Plugin](https://wordpress.org/plugins/classic-editor/)\n\nNote: If you need an easy way to install this project with all requirements take a look at [part 1](#) of the **[WordPress Boilerplate](#)** project.\n\n---\n\n## Installation\n```shell\ncomposer require dark-kitt/wordpress-theme-configuration\n```\n\nIf you have a specific path to your MU-Plugin directory, please add the following lines to your composer.json file.\n```json\n\"extra\": {\n  \"installer-paths\": {\n    \"path/to/mu-plugins/{$name}/\": [\n      \"type:wordpress-muplugin\"\n    ]\n  },\n  \"wordpress-install-dir\": \"path/to/wordpress\"\n},\n```\n\nAfterward, configure the plugin with the **`functions.php`** file in the _`/themes/your-theme`_ directory. Don't forget to insert the **[JWT Authentication for WP REST API](https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/)** if you want to use the **`REST_API()`** method.\n\nNote: For a specific commit of your VCS Repo `\"require\": { \"vendor/repo_name\": \"dev-main#eec8698\" }` (branch#commit).\n\n**common composer cmds**\n\n```shell\ncomposer install\ncomposer update\n# package control\ncomposer require verdor/package\ncomposer remove verdor/package\n\ncomposer clear-cache\ncomposer show -i # installed packages\n```\n\n**Autoloader for WordPress MU-Plugins**\n\nThe **[wordpress-mu-plugin-autoloader](#)** is a WordPress MU-Plugin based on [richardtape/subdir-loader.php](https://gist.github.com/richardtape/05c70849e949a5017147) Github Gist. Copy the **_mu-plugin-autoloader.php_** file inside of the _`/mu-plugins`_ directory, to load MU-Plugins automatically.\n\n---\n\n## Methods [ Arguments ]\n\nGeneral WordPress configurations are placed in the **_base-configuration.php_** file. For each type / part of WordPress, you can find a PHP Trait in the _`/traits`_ directory. Check out the **_example.function.php_** file to get knowledge about the usage and how you can configure your theme inside of the **_functions.php_** file in your _`/themes/your-theme`_ directory.\n\n### get_instance()\n\nExecutes the singleton instance and return itself.\n\n```PHP\n$kitt_instance = KiTT\\ThemeSetUp::get_instance();\n```\n\n### set_up_theme( $wpdb, $wp_rewrite, $pagenow, array $args = defaults )\n\nSet the defined globals `$wpdb`, `$wp_rewrite` and `$pagenow` and call the main theme set up method. This method will also call the `meta_box();` and the `company_settings();` methods, which includes the custom **SEO** meta box, the custom **Homepage** meta box, the custom **Error Page** meta box and the **Company** menu page. The `set_up_theme()` method gives you the ability to install languages for WordPress and sets further settings for **ACF (Advanced Custom Fields)**. All default arguments are listed below.\n\n```PHP\nglobal $wpdb,\n  $wp_rewrite,\n  $pagenow;\n\n$kitt_instance = KiTT\\ThemeSetUp::get_instance();\n$kitt_instance-\u003eset_up_theme(\n  $wpdb, /** reqiured */\n  $wp_rewrite, /** reqiured */\n  $pagenow, /** reqiured */\n  [\n    'set_up' =\u003e [\n      /** custom favicon, logos and login logo url */\n      'favicon' =\u003e $kitt_instance-\u003etheme_url . '/img/wp-favicon.png',\n      'login_logo' =\u003e $kitt_instance-\u003etheme_url . '/img/wp-login-logo.svg',\n      'login_logo_url' =\u003e WP_HOME,\n      'admin_bar_logo' =\u003e $kitt_instance-\u003etheme_url . '/img/wp-admin-bar-logo.svg',\n      'permalink_structure' =\u003e '/%postname%/',\n      'default_user_role' =\u003e 'editor',\n      'remove_welcome' =\u003e true,\n      /** 1 = Mon, 2 = Thu ... 7 = Sun */\n      'start_of_week' =\u003e 1,\n      'timezone_string' =\u003e 'Europe/Berlin',\n      'time_format' =\u003e 'H:i',\n      'date_format' =\u003e 'd/m/Y',\n      /**\n       * install backend languages\n       *\n       * list of available translations\n       * https://translate.wordpress.org/\n       *\n       * to remove a translation\n       * delete the language code and the\n       * files in the /web/storage/lang directory\n       */\n      'install_languages' =\u003e ['de_DE'],\n      /** configure ACF (Advanced Custom Fields) */\n      'ACF' =\u003e [\n        /** add background color button to WYSIWYG editor */\n        'WYSIWYG_BG_color' =\u003e true,\n        'save_load' =\u003e [\n          /** default: null, if null = ACF default -\u003e /themes/your-theme/acf-json */\n          'JSON_save' =\u003e constant('WP_STORAGE_DIR') . '/acf/acf-json',\n          /** default: null, if null = ACF default -\u003e /themes/your-theme/acf-json */\n          'JSON_load' =\u003e constant('WP_STORAGE_DIR') . '/acf/acf-json',\n          /** default: null, if null = ACF default -\u003e /themes/your-theme/acf-json */\n          'AutoSync_JSON_save' =\u003e constant('WP_STORAGE_DIR') . '/acf/acf-json',\n          /** default: null, if null = ACF default -\u003e /themes/your-theme/acf-json */\n          'AutoSync_JSON_load' =\u003e constant('WP_STORAGE_DIR') . '/acf/acf-json',\n          /** default: null, if null = ACF default -\u003e /themes/your-theme/acf-php */\n          'AutoSync_PHP_save' =\u003e constant('WP_STORAGE_DIR') . '/acf/acf-php',\n          /** default: null, if null = ACF default -\u003e /themes/your-theme/acf-php */\n          'AutoSync_PHP_load' =\u003e constant('WP_STORAGE_DIR') . '/acf/acf-php'\n        ],\n        'google_api_key' =\u003e false\n      ],\n      /** add or remove company settings menu page */\n      'company_settings' =\u003e true\n    ]\n  ]\n);\n```\n\n### post( array $args = defaults )\n\nUse this method to modify the **default post section**. All default arguments are listed below.\n\nNote: Use [ACF (Advanced Custom Fields)](https://www.advancedcustomfields.com/) or install the [Classic Editor Plugin](https://wordpress.org/plugins/classic-editor/), to add content to each post.\n\n```PHP\n$kitt_instance-\u003epost([\n  /** removes completely the default post section */\n  'remove_post' =\u003e false,\n  'post' =\u003e [\n    /**\n     * info:\n     * https://developer.wordpress.org/reference/functions/remove_post_type_support/\n     *\n     * NOTE:\n     * Gutenberg editor is always disabled\n     */\n    'remove_support' =\u003e ['excerpt', 'comments', 'trackbacks', 'author'],\n    /** inspect the label attribute for=\"\" in the screen options panel */\n    'remove_meta_box' =\u003e ['commentsdiv', 'slugdiv'],\n    /** en- or disable the SEO meta box */\n    'SEO' =\u003e true,\n    /** to disable tag support */\n    'tag' =\u003e true,\n    /** to disable category support */\n    'category' =\u003e true,\n    /** set default post slug */\n    'post_slug' =\u003e false,\n    /** rename default post section */\n    'rename_labels' =\u003e [\n      'name' =\u003e 'Posts',\n      'singular_name' =\u003e 'Post',\n      'menu_name' =\u003e 'Posts',\n      'all_items' =\u003e 'All Posts',\n      'add_new' =\u003e 'Add New',\n      'add_new_item' =\u003e 'Add New Post',\n      'edit' =\u003e 'Edit',\n      'edit_item' =\u003e 'Edit Post',\n      'new_item' =\u003e 'New Post',\n      'view' =\u003e 'View',\n      'view_item' =\u003e 'View Post',\n      'search_items' =\u003e 'Search Posts',\n      'not_found' =\u003e 'No Posts found',\n      'not_found_in_trash' =\u003e 'No Posts found in trash'\n    ]\n  ]\n]);\n```\n\n### page( array $args = defaults )\n\nUse this method to modify the **default page section**. All default arguments are listed below.\n\nNote: Use [ACF (Advanced Custom Fields)](https://www.advancedcustomfields.com/) or install the [Classic Editor Plugin](https://wordpress.org/plugins/classic-editor/), to add content to each page.\n\n```PHP\n$kitt_instance-\u003epage([\n  /** removes completely the default page section */\n  'remove_page' =\u003e false,\n  'page' =\u003e [\n    /**\n     * info:\n     * https://developer.wordpress.org/reference/functions/remove_post_type_support/\n     *\n     * NOTE:\n     * Gutenberg editor is always disabled\n     */\n    'remove_support' =\u003e ['excerpt', 'comments', 'trackbacks', 'author'],\n    /** inspect the label attribute for=\"\" in the screen options panel */\n    'remove_meta_box' =\u003e ['commentsdiv', 'slugdiv'],\n    /** en- or disable the SEO meta box */\n    'SEO' =\u003e true,\n    /** to enable tag support */\n    'tag' =\u003e true,\n    /** to enable category support */\n    'category' =\u003e true,\n    /** rename default post section */\n    'rename_labels' =\u003e [\n      'name' =\u003e 'Pages',\n      'singular_name' =\u003e 'Page',\n      'menu_name' =\u003e 'Pages',\n      'all_items' =\u003e 'All Pages',\n      'add_new' =\u003e 'Add New',\n      'add_new_item' =\u003e 'Add New Page',\n      'edit' =\u003e 'Edit',\n      'edit_item' =\u003e 'Edit Page',\n      'new_item' =\u003e 'New Page',\n      'view' =\u003e 'View',\n      'view_item' =\u003e 'View Page',\n      'search_items' =\u003e 'Search Pages',\n      'not_found' =\u003e 'No Pages found',\n      'not_found_in_trash' =\u003e 'No Pages found in trash'\n    ]\n  ]\n]);\n```\n\n### attachment( array $args = defaults )\n\nSet up options for the **Media Library**. All default arguments are listed below.\n\nNote: If another theme was previously activated and the **new upload directory** is different, check the project for the old upload directory and when it is unnecessary delete it manually.\n\nNote: That this method can add also the \"Find Duplicates\" attachments modal, which goes through the database and compares images to find duplicates.\n\n```PHP\n$kitt_instance-\u003eattachment([\n  'attachment' =\u003e [\n    /** to enable tag support */\n    'tag' =\u003e false,\n    /** to enable category support */\n    'category' =\u003e false,\n    /** enable search duplicates support */\n    'search_duplicates' =\u003e true\n  ],\n  /**\n   * set custom upload mimes\n   *\n   * extend_defaults = true|false\n   * true = merges the default upload mimes\n   * false = replaces the default upload mimes\n   *\n   * list of defaulst:\n   * https://developer.wordpress.org/reference/functions/get_allowed_mime_types/\n   */\n  'upload_mimes' =\u003e [\n    'extend_defaults' =\u003e true,\n    'jpg|jpeg|jpe' =\u003e 'image/jpeg',\n    'gif' =\u003e 'image/gif',\n    'png' =\u003e 'image/png',\n    /**\n     * NOTE:\n     * the XML declaration is required\n     * in each SVG file, otherwise\n     * the SVG upload is not accepted\n     *\n     * enter the version and the encoding\n     * charset at the top of each SVG file\n     *\n     * \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n     * \u003csvg xmlns=\"http://www.w3.org/2000/svg\" ... viewBox=\"0 0 100 57\"\u003e\n     *     ...\n     * \u003c/svg\u003e\n     */\n    'svg' =\u003e 'image/svg+xml',\n    'pdf' =\u003e 'application/pdf',\n    'mp3|m4a|m4b' =\u003e 'audio/mpeg',\n    'mp4|m4v' =\u003e 'video/mp4',\n    'zip' =\u003e 'application/zip'\n  ],\n  'options_media' =\u003e [\n    /** WP default 150x150px */\n    'thumbnail_size' =\u003e [\n        'thumbnail_size_w' =\u003e 150,\n        'thumbnail_size_h' =\u003e 150\n    ],\n    /** WP default 1 */\n    'thumbnail_crop' =\u003e 1,\n    /** WP default 300x300px */\n    'medium_size' =\u003e [\n        'medium_size_w' =\u003e 300,\n        'medium_size_h' =\u003e 300\n    ],\n    /** WP default 768x768px */\n    'medium_large_size' =\u003e [\n        'medium_large_size_w' =\u003e 768,\n        'medium_large_size_h' =\u003e 768\n    ],\n    /** WP default 1024x1024px */\n    'large_size' =\u003e [\n        'large_size_w' =\u003e 1024,\n        'large_size_h' =\u003e 1024\n    ],\n    /** WP default 0 */\n    'uploads_yearmonth' =\u003e 1,\n    /** WP default open */\n    'ping_status' =\u003e 'closed',\n    /** WP default open */\n    'comment_status' =\u003e 'closed',\n    /** /wp-content/uploads */\n    'upload_path' =\u003e constant('WP_UPLOAD_DIR'),\n    /** http://127.0.0.1/uploads */\n    'upload_url_path' =\u003e constant('WP_UPLOAD_URL')\n  ]\n]);\n```\n\n### comments( array $args = defaults )\n\nRemove completely **Comments** from WordPress.\n\n```PHP\n$kitt_instance-\u003ecomments([\n  /** removes completely the default comments section */\n  'remove_comments' =\u003e true\n]);\n```\n\n### menu( array $args = defaults )\n\nThis method will **replace** the Menu (**_nav-menus.php_**) section from an **Appearance** submenu page to a **top-level** page underneath the Pages section. Additionally, the method adds the **support** for the role **editor** to edit the Menu section (=\u003e editors can edit menus).\n\n```PHP\n$kitt_instance-\u003emenu([\n  /** register main menu locations */\n  'menu' =\u003e [\n    'locations'  =\u003e [\n      'header' =\u003e 'Header',\n      'main' =\u003e 'Main',\n      'footer' =\u003e 'Footer'\n    ]\n  ]\n]);\n```\n\n### custom_post_type( array $args = defaults )\n\nThis is a custom **register_post_type** method, which includes some additional options. A **slug is required** to register custom **menu locations** and to use the custom **homepage meta box**. All default arguments are listed below.\n\n```PHP\n/**\n * register new post type\n * example: \"Pages EN\"\n *\n * menu icon info:\n * https://developer.wordpress.org/resource/dashicons/#menu\n */\n$kitt_instance-\u003ecustom_post_type([\n  'custom_post_type' =\u003e [\n    /** similar to the WP method */\n    'post_type' =\u003e 'pages_en',\n    'description' =\u003e 'Pages EN',\n    'capability_type' =\u003e 'post',\n    'public' =\u003e true,\n    'show_ui'  =\u003e true,\n    'show_in_menu' =\u003e true,\n    'map_meta_cap' =\u003e true,\n    'hierarchical' =\u003e true,\n    'query_var' =\u003e true,\n    'has_archive' =\u003e true,\n    'rewrite' =\u003e ['slug' =\u003e 'en'],\n    'supports' =\u003e ['title', 'revisions', 'page-attributes', 'thumbnail', 'custom-fields', 'post-formats'],\n    'menu_position' =\u003e 21,\n    'menu_icon' =\u003e 'dashicons-admin-page',\n    'taxonomies' =\u003e ['post_tag', 'category'],\n    'labels' =\u003e [\n      'name' =\u003e 'Pages EN',\n      'singular_name' =\u003e 'Page EN',\n      'menu_name' =\u003e 'Pages EN',\n      'all_items' =\u003e 'All EN Pages',\n      'add_new' =\u003e 'Add New',\n      'add_new_item' =\u003e 'Add New EN Page',\n      'edit' =\u003e 'Edit',\n      'edit_item' =\u003e 'Edit EN Page',\n      'new_item' =\u003e 'New EN Page',\n      'view' =\u003e 'View',\n      'view_item' =\u003e 'View EN Page',\n      'search_items' =\u003e 'Search EN Pages',\n      'not_found' =\u003e 'No EN Pages found',\n      'not_found_in_trash' =\u003e 'No EN Pages found in trash',\n      'attributes' =\u003e 'Page Attributes'\n    ],\n    'tag' =\u003e true,\n    'category' =\u003e true,\n    'remove_meta_box' =\u003e ['commentsdiv', 'slugdiv'],\n    /**\n     * dashboard at a glance widget icon\n     * post-count, page-count, comment-count\n     * or custom CSS class\n     */\n    'dashboard_icon' =\u003e 'page-count',\n    /**\n     * menu locations will be registered if a slug exists\n     * caution, do not overwrite existing locations\n     */\n    'menu_locations' =\u003e [\n      'header_en' =\u003e 'Header EN',\n      'main_en' =\u003e 'Main EN',\n      'footer_en' =\u003e 'Footer EN'\n    ],\n    /** add or remove SEO support */\n    'SEO' =\u003e true\n  ]\n]);\n```\n\n### REST_API( array $args = defaults )\n\nThis **`REST_API()`** method uses the **JWT Authentication for WP REST API** to secure the API endpoints. It uses also **PHP Mailer** to send emails via a REST route. In the examples below, you can see how you can optionally use this instance to configure PHP Mailer for your forms. You can also send the server **settings** via a POST body request with **axios**, **jQuery**, or any other way to send a request.\n\nWhile you configure your custom **REST-API**, it is required to create a user with the role **rest_api_user**. This is important because the user with the role **rest_api_user** has only access to the REST-API and not to the backend system.\n\nIf you are using Postman for testing the API request, to retrieve the token from JWT Authentication for WP REST API, send the `username` and `password` as post body (raw/json) data. The `\\WP_REST_Server::CREATABLE` or other methods are described on [developer.wordpress.org](https://developer.wordpress.org/reference/classes/wp_rest_server/). Please take a deeper look inside the **_rest-api.php_** file to get more information about the handling.\n\nUse the existing instance to push additional methods (`$kitt_instance-\u003erest_routes['posts'][] = []`) to existing routes or register totally new routes (`$kitt_instance-\u003erest_routes['new_route'][] = []`) to your REST API configuration.\n\nNote: The **axios GET** (READABLE) request can not send data via the body.\n\n**EXAMPLE: define your custom REST-API**\n\n```PHP\n$kitt_instance-\u003eREST_API([\n  'rest_api' =\u003e [\n    /**\n     * set the namespace for your routes\n     * =\u003e example.com/wp-json/-\u003enamespace\u003c-/route\n     */\n    'namespace' =\u003e explode('.', parse_url(WP_HOME)['host'])[0],\n    /** removes the default REST API */\n    'remove_default' =\u003e true,\n    /**\n     * examples:\n     * 'Access-Control-Allow-Origin: ' . WP_HOME\n     * 'Access-Control-Allow-Methods: POST, GET'\n     * 'Access-Control-Allow-Credentials: true'\n     * 'Access-Control-Max-Age: 600'\n     */\n    'headers' =\u003e [\n      'Access-Control-Allow-Headers: Authorization, X-WP-Nonce, Content-Disposition, Content-MD5, Content-Type',\n      'Access-Control-Allow-Origin: ' . WP_HOME,\n      'Access-Control-Allow-Methods: POST, GET',\n      'Access-Control-Allow-Credentials: true',\n      'Access-Control-Max-Age: 600'\n    ],\n    /** JWT token arguments */\n    'token' =\u003e [\n      'expiration_time' =\u003e time() + (DAY_IN_SECONDS * 7),\n      'header' =\u003e 'Access-Control-Allow-Headers, Access-Control-Allow-Origin, Content-Type, Authorization'\n    ]\n  ]\n]);\n```\n\n**EXAMPLE: configuration for PHP Mailer in the functions.php file**\n\n```PHP\n/**\n * update email route arguments\n * set server settings\n *\n * update values with WP constants\n * or set your custom settings\n */\n$kitt_instance-\u003erest_routes['email']['args']['host'] = ['default' =\u003e constant('SMTP_HOST')]; // 'smtp.gmail.com'\n$kitt_instance-\u003erest_routes['email']['args']['SMTP_auth'] = ['default' =\u003e constant('SMTP_AUTH')]; // boolean\n$kitt_instance-\u003erest_routes['email']['args']['username'] = ['default' =\u003e constant('SMTP_USERNAME')]; // 'your@username.com'\n/**\n * use google app password:\n * https://support.google.com/accounts/answer/185833?hl=en\n */\n$kitt_instance-\u003erest_routes['email']['args']['password'] = ['default' =\u003e constant('SMTP_PASSWORD')]; // 'app-password'\n$kitt_instance-\u003erest_routes['email']['args']['SMTP_secure'] = ['default' =\u003e constant('SMTP_SECURE')]; // 'tls'\n$kitt_instance-\u003erest_routes['email']['args']['port'] = ['default' =\u003e constant('SMTP_PORT')]; // 587\n/** PHPMailer debug */\n$kitt_instance-\u003erest_routes['email']['args']['debug'] = ['default' =\u003e false];\n/**\n * email test data\n *\n * test e.g. via postman\n * send data with route -\u003e /wp-json/namespace/email\n */\n$kitt_instance-\u003erest_routes['email']['args']['set_from'] = ['default' =\u003e [\n  'address' =\u003e 'from@address.com',\n  'name' =\u003e 'User Joe'\n]];\n$kitt_instance-\u003erest_routes['email']['args']['add_address'] = ['default' =\u003e [[\n  'address' =\u003e 'add_to@address.com',\n  'name' =\u003e 'User Foo'\n]]];\n$kitt_instance-\u003erest_routes['email']['args']['add_reply_to'] = ['default' =\u003e [\n  'address' =\u003e 'add_to_reply@address.com',\n  'name' =\u003e 'User Bar'\n]];\n```\n\n**EXAMPLE: for adding a custom REST route in the functions.php file**\n\n```PHP\n/**\n * register custom REST routes\n *\n * functions.php\n * modifing default args\n * $kitt_instance-\u003erest_routes['route']['args']['param'] = ['default' =\u003e 'value']\n *\n * add route\n * extend $this-\u003erest_routes array\n * e.g.\n * $kitt_instance-\u003erest_routes['endpoint'][] = [\n *     'methods'  =\u003e \\WP_REST_Server::CREATABLE,\n *     'callback' =\u003e 'call_callback_API',\n *     'permission_callback' =\u003e 'edit_others_posts',\n *     'args' =\u003e [\n *        'param_one' =\u003e ['default' =\u003e 'one']\n *     ]\n * ];\n * add REST route method\n * extend $instance\n * e.g.\n * $kitt_instance-\u003ecall_callback_API = function (\\WP_REST_Request $request)\n * {\n *     // $_GET and $_POST params\n *     $params = $request-\u003eget_params();\n *     $response = new \\WP_REST_Response($params, 200);\n *     return $response;\n * };\n */\n$kitt_instance-\u003erest_routes['endpoint'][] = [\n  /**\n   * add a custom REST route\n   * example: return Vue.js routes\n   *\n   * const READABLE = 'GET';\n   * const CREATABLE = 'POST';\n   * ...\n   * const ALLMETHODS = 'GET, POST, PUT, PATCH, DELETE';\n   *\n   * NOTE: axios GET request can not send data via body\n   *\n   * documentation\n   * https://developer.wordpress.org/reference/classes/wp_rest_server/\n   */\n  'methods'  =\u003e \\WP_REST_Server::CREATABLE,\n  'callback' =\u003e 'my_custom_callback', // string required!!!\n  /**\n   * string required\n   * ... current_user_can($route['permission_callback']); ...\n   *\n   * list of roles and capabilities\n   * https://wordpress.org/support/article/roles-and-capabilities/\n   */\n  'permission_callback' =\u003e 'rest_api_user',\n  /** set the defaults */\n  'args' =\u003e [\n    'param_one' =\u003e ['default' =\u003e false]\n  ]\n];\n\n/**\n * add a custom REST callback method\n */\n$kitt_instance-\u003emy_custom_callback = function (\\WP_REST_Request $request) use ($kitt_instance)\n{\n  /** $_GET and $_POST params */\n  $params = $request-\u003eget_params();\n  /** get the default params */\n  $default = $request-\u003eget_default_params();\n\n  /** update posts default arguments with request data */\n  $args = $kitt_instance-\u003ereplace_val_in_array($default, $params);\n\n  /** do stuff!!! */\n  $response = \"my custom response\";\n\n  return new \\WP_REST_Response($response, 200);\n};\n```\n\n---\n\n**Note: The Gutenberg editor is always disabled!** If WP_HOME is different from WP_SITEURL the Gutenberg editor throws multiple errors. If you are interested, take a look at [Github WordPress / gutenberg (issue 1761).](https://github.com/WordPress/gutenberg/issues/1761)\n\nUse [ACF (Advanced Custom Fields)](https://www.advancedcustomfields.com/) or install the [Classic Editor Plugin](https://wordpress.org/plugins/classic-editor/), to add content to each post / page.\n\n---\n\n---\n\n## License\n\n[![](https://upload.wikimedia.org/wikipedia/commons/e/e5/CC_BY-SA_icon.svg)](https://creativecommons.org/licenses/by-sa/4.0)\n\n---\n\n## Includes\n\n- [dark-kitt / wordpress-mu-plugin-autoloader](https://github.com/dark-kitt/wordpress-mu-plugin-autoloader)\n- [JWT Authentication for WP REST API](https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdark-kitt%2Fwordpress-theme-configuration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdark-kitt%2Fwordpress-theme-configuration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdark-kitt%2Fwordpress-theme-configuration/lists"}