Git Product home page Git Product logo

wordpress-crud-example's Introduction

Basic example of wordpress plugin to select, update, insert and delete from database (CRUD)

This is the code for the article:

https://laloah.wordpress.com/2013/06/14/basic-example-of-wordpress-plugin-to-select-update-insert-and-delete-from-database-crud

Click on "Download ZIP" to download the example

Tired of looking for a basic example of a plugin to solve my needs for CRUD operations on a custom table in wordpress I decided to to it myself, and here it is.

This plugin is just a starting point to develop your own management plugin.

plugin

This example works with a custom table in the wordpress database. it’s written with simplicity in mind so you can understand everithing quickly.

Includes the following files

  • init – plugin initialization, where everything is put toghether
  • list – showing a list of items
  • update – for updating and deleting items
  • create – for inserting new items
  • style-admin.css – stylesheet to use in the admin screens

How to use the code

First, install and use the plugin to understand how it works:

  • Download the files
  • Unzip to wp-content/plugins folder
  • Create the table manually on the same wordpress database using the file example-database.sql (you can use the phpmyadmin tool)
  • Activate the plugin

You will see a new administration menu on your left:

menu items

Take your time and perform all operations: select, insert, update and delete

Customize the code

If yout take a look at the code you’ll see that every function has a prefix “sinetiks” and the name of the table “schools“. This is because you need to create a namespace to avoid duplicated function names.

prefix

(The name “sinetiks” is the name of my company and “schools” the name of the table to manage)

How to modify the code to manage another table:

  • Replace “sinetiks” with your company name and “school” with the table name
  • Replace the columns ID and NAME with your columns
  • Modify the html forms

To learn how to use the wordpress database functions: http://codex.wordpress.org/Class_Reference/wpdb

The code is written with the minimum to avoid complexity.

Remember that the purpose of this code is to help you build your own plugin with validations, style, proper messages, etc.

Good luck!

wordpress-crud-example's People

Contributors

eduardoarandah avatar abhij0990 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.