WordPress as a data source with .json for Scriptable IOS App

Creating a WordPress site is no longer a specialty with the provided themes. The idea of using WordPress not only as a standard website, but also as a data source / database can be implemented by using a two-line PHP script. We need this script to upload a .json file in WP under media which is normally blocked.

<?php
function cc_mime_types($mimes) {
    $mimes['json'] = 'application/json';
    $mimes['svg'] = 'image/svg+xml';

    return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');

https://github.com/SmonSE/englishForIT/blob/main/wpJson.zip

Installation of your own WordPress plugin

After creating the plugin (ZIP file which includes the php script) it can be installed via the dashboard.

  1. First click on > Plugins > Add new.
  2. Then click on the “Upload plugin” button at the top.
  3. Now select the ZIP file and confirm the “Install now” button.
  4. After the file has been uploaded, you can activate the plugin.

Create your own .json file

Code excerpt from the json file.

// example
{
  "englishIt": "Vocabulary for IT english",
  "createdAt":"2021-03-18 11:43:00.000000",
  "vocabulary":[
    {
      "pos:": "000",
      "english": "Avatar",
      "german": "Benutzerbild",
      "meaning": "An icon or figure that represents .... ."
    },
    {
      "pos:": "001",
      "english": "Bug",
      "german": "Fehler",
      "meaning": "A defect or fault in a program ... ."
    }
  ]
}

Get data source by Scriptable Widget

Collecting data source from .json file which is uploaded on WordPress media.

// example
async function getNewCasesData(){
  let url = "https://../../../englishForItVocs.json";
  let req = new Request(url);
  let apiResult = await req.loadJSON();

return apiResult;
}

Read out values from .json file.

// example
async function createWidget() {
  const list = new ListWidget();
  const vocEng = list.addText(apiData.vocs[0].english);
  const meaning = list.addText(apiData.vocs[0].meaning);

return list;
}