Download the PHP package brandonwamboldt/wp-orm without Composer

On this page you can find all versions of the php package brandonwamboldt/wp-orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp-orm

WordPress ORM

WordPress ORM is a small library that adds a basic ORM into WordPress, which is easily extendable and includes models for core WordPress models such as posts, pages, comments and users. It's designed to allow you to easily add new models other than custom post types, and not have to write a lot of manual SQL.

Installation

While you can install and activate it like a normal plugin, I'd recommend putting it in the /wp-content/mu-plugins folder and adding a script called wp-orm.php to load the main plugin file (only top level .php files are loaded from mu-plugins).

wp-orm.php:

Examples

Get 5 published pages, ordered by post title.

Find a user by their login

Example of a more complex query

Updating a model

Meta data

Users, posts, pages and comments all support meta data.

Meta data is saved immediately using WordPress meta data functions under the hood. Calling save() is not needed.

Custom Models

You can now use this venue, persist it, and use the custom query DSL shown above to query it.

Model Methods

Model::get_table()

This is a static method that you must define in your models, and should return the table to persist data to.

Model::get_searchable_fields()

This is a static method that you must define in your models, and should return an array of properties to search when doing a search query.

Model::get_primary_key()

Return's the property used as a primary key. Defaults to id.

Model::create(array $properties)

Create a new model from an array of properties.

Model::find_one_by(string $property, mixed $value)

Find a single model with the specified property value.

Model::find_one(integer $id)

Find a single model who's primary key is equal to the given ID.

Model::query()

Return a new WordPress\ORM\Query object.

Model::all()

Return every single model in the database.

$model->primary_key()

Return the model's primary key (the value, not the property name).

$model->to_array()

Return all of the model's properties as an array.

$model->flatten_props(array $props)

Call right before save(), should flatten any objects in the properties into strings so they can be persisted. Defaults to flattening DateTime objects into a timestamp and arrays into a serialized array.

$model->save()

Save your model to the database. Creates a new row if the model doesn't have an ID, or updates an existing row if their is an ID.

$model->delete()

Delete the model from the database. Returns true if it was successful or false if it was not.

ORM Queries

Below are the functions you have access to after you call the Model::query() function.

$query->limit(integer $limit)

Limits the number of results returned using an SQL LIMIT clause.

$query->offset(integer $offset)

Offset the results returned, used with pagination. Uses the SQL OFFSET clause.

$query->sort_by(string $property)

Sort results by the specified property. Can also be a MySQL function such as RAND().

$query->order(string $order)

Order the results in the given order. Can be one of ASC or DESC.

$query->search(string $search_term)

Limit results to items matching the given search term. Searches the properties returned by Model::get_searchable_fields.

$query->where(string $property, string $value)

Add a parameter to the where clause. Equivalent to WHERE $property = '$value'. $value is automatically escaped.

$query->where_not(string $property, string $value)

Add a parameter to the where clause. Equivalent to WHERE $property != '$value'. $value is automatically escaped.

$query->where_like(string $property, string $value)

Add a parameter to the where clause. Equivalent to WHERE $property LIKE '$value'. $value is automatically escaped.

$query->where_not_like(string $property, string $value)

Add a parameter to the where clause. Equivalent to WHERE $property NOT LIKE '$value'. $value is automatically escaped.

$query->where_lt(string $property, string $value)

Add a parameter to the where clause. Equivalent to WHERE $property < '$value'. $value is automatically escaped.

$query->where_lte(string $property, string $value)

Add a parameter to the where clause. Equivalent to WHERE $property <= '$value'. $value is automatically escaped.

$query->where_gt(string $property, string $value)

Add a parameter to the where clause. Equivalent to WHERE $property > '$value'. $value is automatically escaped.

$query->where_gte(string $property, string $value)

Add a parameter to the where clause. Equivalent to WHERE $property >= '$value'. $value is automatically escaped.

$query->where_in(string $column, array $in)

Limit results to items where the given column is one of the given values. Equivalent to WHERE $property IN ('value1', 'value2') where value1 and value2 are values in the array.

$query->where_not_in(string $column, array $in)

Limit results to items where the given column is not one of the given values. Equivalent to WHERE $property NOT IN ('value1', 'value2') where value1 and value2 are values in the array.

$query->where_any(array $where)

Limit results to items that match any of the property/value pairs given in the array. Must match at least one.

$query->where_all(array $where)

Limit results to items that match all of the property/value pairs given in the array.

Actions & Filters

wporm_query($sql, $model_class)

Manipulate the raw SQL query created by the Query class.

wporm_count_query($sql, $model_class)

Manipulate the raw SQL query created by the Query class (the row count variation).

License

This code is licensed under the MIT license.


All versions of wp-orm with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package brandonwamboldt/wp-orm contains the following files

Loading the files please wait ....