Author: Faison Zutavern

  • Creating a WordPress Plugin to Export MySQL data as CSV

    Recently at work, a client requested the ability to export user browsing information as a Comma-separated values (CSV) file. I was asked if I could make this happen, and I was pretty sure I could figure it out. It took a couple of hours of research, but It was a fun and educational experience that lead me to new understandings of PHP, WordPress, and MySQL.

    I decided to share what I learned with as much concise detail as possible and with the same process I took, because without the extremely helpful guides from the programming communities online, I would not be as strong a programmer as I am today. So thank you everyone, and read ahead for the guide.

    Summary

    This guide will help you write a WordPress plugin that has an Admin Page which is accessible from the Tools menu on the WordPress Dashboard. It will use PHP to retrieve data from a MySQL database, format it as a CSV file, and send it to the browser to be downloaded without storing a file on the server.

    The Steps and The Skills

    Step 1 – Send a CSV file to the Browser: PHP
    Step 2 – Build the Database Query: MySQL, WordPress Database
    Step 3 – Access the WordPress Database: WordPress Development, PHP
    Step 4 – Make it a Plugin: WordPress Development, PHP, minimal HTML
    Step 5 – Activate and Use the Plugin: End results
    Update 1 – Add Content-Length Header: PHP
    (more…)