Giter Club home page Giter Club logo

wpdb_activerecord's Introduction

wpdb_activerecord

If you'd like to do it in Ruby instead, then this library might help with some of the boilerplate.

It's a wrapper for the WordPress database, using ActiveRecord, that gives you access to the WordPress database and all its content via a nice ORM.

Installation

gem "wpdb_activerecord"
gem "mysql2", "~> 0.3.0"

Usage

Post

WPDB::Post.all # Get all posts
@post = WPDB::Post.find(75)
@post.tags
@post.categories
@post.comments
@post.attachments # No matter what type
@post.revisions # versions
@post.postmetas # post meta values
@post.author # get user (WPDB::User)

Term

WPDB::Term.tag # get all tags
WPDB::Term.category # get all categories
@term = WPDB::Term.first
@term.posts # get all the term posts

User

@user = WPDB::User.find(25)
@user.posts
@user.comments

Advanced

Sometime we will custom the table name prefix (default is wp_) or inherit to use and redefine something.

You can define your yaml file to setup prefix and association class_name.

Put the config file named "wpdb_activerecord.yml" in config

Example:

# config/wpdb_config.yml
WPDB_PREFIX: "cgjbugpbs_" # the table of WPDB::Post is cgjbugpbs_posts, not wp_posts
WPDB_USER_CLASS: "WUser"

# models/w_user.rb
class WUser < WPDB::User
  def hello
    puts "world"
  end
end

# usage
@author = WPDB::Post.find(25).author
@author.class_name # will get WUser, not WPDB::User
@author.hello # world

All setting attributes you can use:

  • WPDB_PREFIX
  • WPDB_COMMENT_CLASS
  • WPDB_USER_CLASS
  • WPDB_POST_CLASS
  • WPDB_POSTMETA_CLASS
  • WPDB_TERM_CLASS
  • WPDB_TERM_RELATIONSHIP_CLASS
  • WPDB_TERM_TAXONOMY_CLASS

Table Fields

wp_posts

WPDB::Post

  • ID:integer
  • post_author:integer
  • post_date:datetime
  • post_date_gmt:datetime
  • post_content:text
  • post_title:string
  • post_excerpt:string
  • post_status:varchar(20)
  • post_password:varchar(20)
  • post_name:varchar(200) (post slug)
  • post_modified:datetime
  • post_modified_gmt:datetime
  • post_parent:integer
  • guid:varchar(255)
  • menu_order:integer
  • post_type:varchar(20)
  • post_mime_type:varchar(100)
  • comment_count:integer

wp_postmeta

WPDB::Postmeta

  • meta_id:integer
  • post_id:integer
  • meta_key:varchar(255)
  • meta_value:text

wp_comments

WPDB::Comment

  • comment_ID:integer
  • comment_post_id:integer
  • comment_author:varchar(255)
  • comment_author_email:varchar(100)
  • comment_author_url:varchar(200)
  • comment_author_IP:varchar(100)
  • comment_date:datetime
  • comment_date_gmt:datetime
  • comment_content:text
  • comment_karma:integer
  • comment_approved:varchar(20)
  • comment_agent:varchar(255)
  • comment_type:varchar(20)
  • comment_parent:bigint(20)
  • user_id:bigint(20)

wp_users

WPDB::User

  • ID:integer
  • user_login:varchar(60)
  • user_pass:varchar(64)
  • user_nicename:varchar(50)
  • user_email:varchar(100)
  • user_url:varchar(100)
  • user_registered:datetime
  • user_status:integer
  • display_name:varchar(250)

wp_usermeta

WPDB::Usermeta

  • umeta_id:integer
  • user_id:integer
  • meta_key:varchar(255)
  • meta_value:text

wp_terms

WPDB::Term

  • term_id:integer
  • name:varchar(200)
  • slug:varchar(200)
  • term_group:integer

wp_term_taxonomy

WPDB::TermTaxonomy

  • term_taxonomy_id:integer
  • term_id:integer
  • taxonomy:varchar(32)
  • description:text
  • parent:integer
  • count:integer

wp_term_relationships

WPDB::TermRelationship

  • object_id:integer
  • term_taxonomy_id:integer
  • term_order:integer

wp_options

WPDB::Option

  • option_id:integer
  • option_name:varchar(64)
  • option_value:text
  • autoload:varchar(20)

wpdb_activerecord's People

Contributors

dlackty avatar hothero avatar hzchirs avatar nickwarm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

wpdb_activerecord's Issues

Term and Term_taxonomy association

Referring to wp official document, term & term_taxonomy are on-to-many association. so has_many and belongs_to can deal with it. I wonder why you designed both has_one & has_many associations between Term & Term_taxonomy?

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.