Working with BBS Network Data - WordPress Plugin Tutorial - Part 2
Jul 14, 2022 2:51 PM
In part 2 of the BBS Network Feed WordPress plugin tutorial we will focus on building the admin page so that we can get some data from the API. By the end of this section you should have some data to work with.
Table of contents
1. Introduction
Related stories
3. Display the BBS post titles on a page
4. Add BBS post content
5. Put it all together
Admin page for the BBS Network Feed plugin
1. Create a function to register the admin menu page

2. Add the callback function to create the page for the plugin settings and actions

The result is a menu item for the BBS Network Feed plugin and a page to input your API key.

Saving the API key
To get the data from the dfuse API we need an API key. If you haven't already created an account on the dfuse website, you will need to do that now and get your API key.
Now that we have the admin page we can register the setting to save the API key. Create a function called bbsnf_register_settings.

You can now enter and save your API key ready for getting some data.
Add a button to the admin page
We need to create a button on the plugin page for getting the data. This will go at the bottom of the bbsnf_admin_page function after the first form.


Get the Auth Token
Now we have a button but it doesn't do anything yet. The PHP functions we wrote in the first script tutorial can be reused with some modifications for WordPress.
The first thing we will need to do is get the Auth token as it is required to be able to get data. The main difference is that we need to use wp_remote_post instead of directly using curl. It may be worthwhile to check how the code differs from the curl version to help clarify what is happening here.

Get the data
1. Create a folder called data in your plugin directory. We will store the data in a file in this folder.
2. Add the function to get the data from the API

3. WordPress cannot handle the graphql query string so we will need to add a filter to send it in the right format

4. Add a function called bbsnf_api_get_admin_action to hook up our button to get the data. Add this just after the bbsnf_register_settings function. This function will add a parameter to the url to indicate success or failure to get the data.

5. Add a function called bbsnf_get_data after bbsnf_api_get_admin_action. This function calls the two functions we created earlier to get the data and returns a bool value for success or failure.

6. Now all we need to do is give some indication on the admin page depending on whether or not we got the data. In step 4 we added a query string to the url so we will make use of this. At the top of bbsnf_admin_page add the following code.

Now get some data!
We should now be able to fetch some data. Try it for yourself. It can take a while sometimes. You should see the success message. If not you will need to dig into the code and do a bit of debugging. The most likely reasons for failure would be a timeout or exceeding your data limit. See the next section.

If you got the success message, go to your plugin folder and you should see a file called data.json in the data folder. The size will be something like this if you got the full 1000 transactions
-rw-r--r-- 1 theotter staff 9265537 Jul 14 16:43 data.json
The graphql string
A final note is that you may want to decrease the number of transactions you get in the graphql string especially if you are getting errors and need to debug. If you are using a community account you may go over your data limit if you aren't careful.
You can do this by changing the limit parameter in the query string. The default is 100 and the maximum is 1000 for a community account but you may want to drop it to 10 for debugging.

That's it for part 2. Now you have a WordPress plugin that gets some BBS Network data. In the next part we will process the data to produce a feed of post titles. Happy coding!
The code for part 2
1
Comments
Powered by RoundtableAn AI/DeFi-powered Enterprise Media Operating System. Learn more at Roundtable.io.© Roundtable 2026. By using this site you agree to the Terms of Use and Privacy Policy

