{"id":17004212,"url":"https://github.com/ppfeufer/wp-esi-client","last_synced_at":"2026-03-23T16:30:19.325Z","repository":{"id":104336860,"uuid":"151722299","full_name":"ppfeufer/wp-esi-client","owner":"ppfeufer","description":"ESI Client for WordPress","archived":true,"fork":false,"pushed_at":"2024-09-02T20:44:59.000Z","size":287,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-27T10:08:33.423Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ppfeufer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-10-05T13:08:55.000Z","updated_at":"2024-09-02T22:19:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"247d870b-9098-44a5-81e4-d5895840a9b4","html_url":"https://github.com/ppfeufer/wp-esi-client","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppfeufer%2Fwp-esi-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppfeufer%2Fwp-esi-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppfeufer%2Fwp-esi-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppfeufer%2Fwp-esi-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ppfeufer","download_url":"https://codeload.github.com/ppfeufer/wp-esi-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239940321,"owners_count":19722005,"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-10-14T04:43:05.248Z","updated_at":"2026-03-23T16:30:19.277Z","avatar_url":"https://github.com/ppfeufer.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ESI Client for WordPress\u003ca name=\"esi-client-for-wordpress\"\u003e\u003c/a\u003e\n\nA simple and lightweight ESI client that can be used in WordPress plugins and provides access to the public ESI endpoints. Meaning, the endpoints that don't requiere any form of authentication.\n\nTo use this in your WordPress plugin, make sure your plugin fetches the master.zip file from this repo and extracts it, preferrably into `/wp-content/EsiClient`.\n\n______________________________________________________________________\n\n\u003c!-- mdformat-toc start --slug=github --maxlevel=6 --minlevel=1 --\u003e\n\n- [ESI Client for WordPress](#esi-client-for-wordpress)\n  - [Requirements](#requirements)\n  - [How To](#how-to)\n    - [Preparation in your plugin](#preparation-in-your-plugin)\n    - [Hook it up with WordPress](#hook-it-up-with-wordpress)\n    - [The Update Function(s)](#the-update-functions)\n      - [Check if an update is needed](#check-if-an-update-is-needed)\n      - [Update](#update)\n      - [Helper](#helper)\n    - [Use in your Plugin](#use-in-your-plugin)\n      - [Autoloader](#autoloader)\n      - [Work with the Esi client](#work-with-the-esi-client)\n\n\u003c!-- mdformat-toc end --\u003e\n\n______________________________________________________________________\n\n## Requirements\u003ca name=\"requirements\"\u003e\u003c/a\u003e\n\n- PHP 7.2 or newer\n- WordPress 5.0 or newer\n- mySQL `max_allowed_packet=10M` or more\n\n## How To\u003ca name=\"how-to\"\u003e\u003c/a\u003e\n\nMake sure that you implement a method in you register_activation_hook that checks the Esi Client version to the one you are using in your plugin.\n\n### Preparation in your plugin\u003ca name=\"preparation-in-your-plugin\"\u003e\u003c/a\u003e\n\nTo do so, first define a variable/constand that holds the Esi Client version you are using.\n\n```php\n$esiClientVersion = 20181005;\n```\n\n### Hook it up with WordPress\u003ca name=\"hook-it-up-with-wordpress\"\u003e\u003c/a\u003e\n\nNow you need to make sure WordPress is checking if the ESI client is locally available in at least the version you are using.\n\n```php\n// on plugin activation from plugin management (Activate Link)\nregister_activation_hook($this-\u003epluginFile, 'checkEsiClientForUpdates');\n\n// This needs to be added because the activbation hook is not fired on\n// plugin updates, so it needs to be checked every time the plugin is loaded\nadd_action('plugins_loaded', 'checkEsiClientForUpdates');\n```\n\nWith these 2 lines you make sure your plugin is calling the `checkEsiClientForUpdates` function on activation and every time the plugin is loaded. The second line is needed because the activation hook is not called on plugin updates.\n\n### The Update Function(s)\u003ca name=\"the-update-functions\"\u003e\u003c/a\u003e\n\nWith your hooks and actions registered, you now need the update function. This is a multiple step process.\n\n#### Check if an update is needed\u003ca name=\"check-if-an-update-is-needed\"\u003e\u003c/a\u003e\n\nFirst we call a general update check function to check if an update is actually needed.\n\n```php\nfunction checkEsiClientForUpdates() {\n    // import your plugins desired ESI client version or set it here, what ever you like\n    global $esiClientVersion;\n\n    // this is to make sure that if the ESI client doesn't exist locally\n    // it gets downloaded and installed\n    $esiClientCurrentVersion = null;\n\n    if(class_exists('\\WordPress\\EsiClient\\Swagger')) {\n        $esiClient = new \\WordPress\\EsiClient\\Swagger;\n        $esiClientCurrentVersion = $esiClient-\u003egetEsiClientVersion();\n    }\n\n    /**\n     * Check if the current ESI client needs to be updated\n     */\n    if(version_compare($esiClientCurrentVersion, $esiClientVersion) \u003c 0) {\n        updateEsiClient($esiClientVersion);\n    }\n}\n```\n\n#### Update\u003ca name=\"update\"\u003e\u003c/a\u003e\n\nNow the actual update function ...\n\n```php\nfunction updateEsiClient(string $version = null) {\n    // check if ZipArchive is available\n    $hasZipArchive = (class_exists('ZipArchive')) ? true : false;\n\n    $remoteZipFile = 'https://github.com/ppfeufer/wp-esi-client/archive/master.zip';\n    $dirInZipFile = '/wp-esi-client-master';\n\n    if(!is_null($version)) {\n        $remoteZipFile = 'https://github.com/ppfeufer/wp-esi-client/archive/v' . $version . '.zip';\n        $dirInZipFile = '/wp-esi-client-' . $version;\n    }\n\n    $esiClientZipFile = WP_CONTENT_DIR . '/uploads/EsiClient.zip';\n\n    wp_remote_get($remoteZipFile, [\n        'timeout' =\u003e 300,\n        'stream' =\u003e true,\n        'filename' =\u003e $esiClientZipFile\n    ]);\n\n    // remove an older local version of the ESI client\n    if(is_dir(WP_CONTENT_DIR . '/EsiClient/')) {\n        $this-\u003errmdir(WP_CONTENT_DIR . '/EsiClient/');\n    }\n\n    // extract using ZipArchive\n    if($hasZipArchive === true) {\n        $zip = new ZipArchive;\n\n        if(!$zip-\u003eopen($esiClientZipFile)) {\n            throw new Exception('PHP-ZIP: Unable to open the Esi Client zip file');\n        }\n\n        if(!$zip-\u003eextractTo(WP_CONTENT_DIR)) {\n            throw new Exception('PHP-ZIP: Unable to extract Esi Client zip file');\n        }\n\n        $zip-\u003eclose();\n    }\n\n    // extract using PclZip\n    if($hasZipArchive === false) {\n        require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');\n\n        $zip = new PclZip($esiClientZipFile);\n\n        if(!$zip-\u003eextract(PCLZIP_OPT_PATH, WP_CONTENT_DIR)) {\n            throw new Exception('PHP-ZIP: Unable to extract Esi Client zip file');\n        }\n    }\n\n    // rename folder\n    rename(\\WP_CONTENT_DIR . $dirInZipFile, \\WP_CONTENT_DIR . '/EsiClient/');\n\n    // remove temp zip file\n    unlink($esiClientZipFile);\n}\n```\n\n#### Helper\u003ca name=\"helper\"\u003e\u003c/a\u003e\n\nWe also need a little helper function in order to remove the old ESI client directory.\n\n```php\nfunction rrmdir(string $dir) {\n    if(is_dir($dir)) {\n        $objects = scandir($dir);\n\n        foreach($objects as $object) {\n            if($object != \".\" \u0026\u0026 $object != \"..\") {\n                if(is_dir($dir . \"/\" . $object)) {\n                    $this-\u003errmdir($dir . \"/\" . $object);\n                } else {\n                    unlink($dir . \"/\" . $object);\n                }\n            }\n        }\n\n        rmdir($dir);\n    }\n}\n```\n\n### Use in your Plugin\u003ca name=\"use-in-your-plugin\"\u003e\u003c/a\u003e\n\n#### Autoloader\u003ca name=\"autoloader\"\u003e\u003c/a\u003e\n\nYou have to make sure that the ESI classes will be loaded when you call them\n\n```php\n/**\n * Autoloading ESI classes\n */\n\\spl_autoload_register('autoloadEsiClient');\n\nfunction autoloadEsiClient($className) {\n    // If the specified $className does not include our namespace, duck out.\n    if(strpos($className, 'WordPress\\EsiClient') === false) {\n        return;\n    }\n\n    // Split the class name into an array to read the namespace and class.\n    $fileParts = explode('\\\\', $className);\n\n    // Do a reverse loop through $fileParts to build the path to the file.\n    $namespace = '';\n    for($i = count($fileParts) - 1; $i \u003e 0; $i--) {\n        // Read the current component of the file part.\n        $current = str_ireplace('_', '-', $fileParts[$i]);\n\n        $namespace = '/' . $current . $namespace;\n\n        // If we're at the first entry, then we're at the filename.\n        if(count($fileParts) - 1 === $i) {\n            $namespace = '';\n            $fileName = $current . '.php';\n\n            /* If 'interface' is contained in the parts of the file name, then\n             * define the $file_name differently so that it's properly loaded.\n             * Otherwise, just set the $file_name equal to that of the class\n             * filename structure.\n             */\n            if(strpos(strtolower($fileParts[count($fileParts) - 1]), 'interface')) {\n                // Grab the name of the interface from its qualified name.\n                $interfaceNameParts = explode('_', $fileParts[count($fileParts) - 1]);\n                $interfaceName = $interfaceNameParts[0];\n\n                $fileName = $interfaceName . '.php';\n            }\n        }\n\n        // Now build a path to the file using mapping to the file location.\n        $filepath = trailingslashit(WP_CONTENT_DIR . '/EsiClient' . $namespace);\n        $filepath .= $fileName;\n\n        // If the file exists in the specified path, then include it.\n        if(file_exists($filepath)) {\n            include_once($filepath);\n        }\n    }\n}\n```\n\n#### Work with the Esi client\u003ca name=\"work-with-the-esi-client\"\u003e\u003c/a\u003e\n\nThis ESI client has a couple of Repository classes that will do all themagic for you. You just have to call them and, if needed, give them some arguments.\n\nExample for getting alliance information from an alliance ID:\n\n```php\n$allianceApi = new \\WordPress\\EsiClient\\Repository\\AllianceRepository;\n$allianceData = $allianceApi-\u003ealliancesAllianceId($allianceId)\n```\n\nNow `$allianceData` is a nice `\\WordPress\\EsiClient\\Model\\Alliance\\AlliancesAllianceId` Model which provides you with the needed getter methods.\n\n```php\n// get alliance name\necho $allianceData-\u003egetName();\n\n// get alliance ticker\necho $allianceData-\u003egetTicker();\n```\n\nAnd so on.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fppfeufer%2Fwp-esi-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fppfeufer%2Fwp-esi-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fppfeufer%2Fwp-esi-client/lists"}