Code Monkey home page Code Monkey logo

cakephp-wordpress-datasource's Introduction

CakePHP-Wordpress-Datasource

CakePHP 2.x plugin for accessing Wordpress via XML-RPC.

Status

As of the latest commit, the datasource allows the following functions:

  1. getPost($post_id, array $fields = array()) Retrieve a post
  2. getPosts(array $filter = array(), array $fields = array()) Retrieve list of posts
  3. newPost(array $post) Create a new post
  4. editPost($post_id, array $post) Edit an existing post
  5. deletePost($post_id) Delete an existing post

More functions coming soon. I plan to have all the methods in http://codex.wordpress.org/XML-RPC_WordPress_API

Todos

  1. More detailed installation instructions
  2. Attempted to use CakePHP's unofficial Xmlrpc Source (https://github.com/cakephp/datasources/blob/2.0/Model/Datasource/XmlrpcSource.php) by extending it
  3. Create Post, Taxonomy, Comment and Users models inside the plugin
  4. Add more helper functions based on http://codex.wordpress.org/XML-RPC_WordPress_API
  5. Add the CRUD methods for better integration with models

Requirements

  • PHP version: PHP 5.2+
  • CakePHP version: Cakephp 2.x
  • Wordpress 3.5+ Installation

Installation

  1. Copy the plugin to your application plugins folder. Make sure the directory name is "WordpressSource"

  2. Create a new datasource entry in your Config/database.php

     public $wp = array(
             'datasource' => 'WordpressSource.WordpressSource',
             'host' => 'mywordpress.com',
             'path' => '/xmlrpc.php',
             'username' => 'admin',
             'password' => '*******',
             'blog_id' => 0
     );
    
  3. Add this line to the bottom of your app's Config/bootstrap.php

     CakePlugin::load('WordpressSource', array('routes' => false, 'bootstrap' => false));
    
  4. Make sure XML-RPC is turned on in your Wordpress installation. This is enabled by default in versions 3.5+

  5. In your controller load the datasource directly

     $this->WP = ConnectionManager::getDataSource('wp');
    
  6. You now have access to the helper functions. See Examples for more details

Examples

  1. Get the title of the last 5 modified blog posts that are published

     $res = $this->WP->getPosts(array(
             'post_status' => 'publish',
             'post_type' => 'post',
             'number' => 5,
             'orderby' => 'post_modified',
             'order' => 'desc',
     ), array(
             'post_title'
     ));
     debug($res);
    

Branch Strategy

Master is currently stable. Refer to status for working functionalities. When submitting PRs, please use the development branch.

API limitations

I decided to document the many limitations of the XML-RPC API with possible workarounds. I ask the community to please amend to this section any other limitations or solutions.

  1. The API does not allow you to fetch a count of posts.

    • Solution 1: when the Datasource calls for a count, set the 'number' parameter in the filters to 999,999. This itself sounds like a horrible idea and performances test will need to be done.
    • Solution 2: when the Datasource calls for a count, set the 'number' parameter to a reasonable number and make multiple calls to get the total number.
    • Solution 3: submit a PR to the codebase to add this obviously useful functionality
    • Solution 4: create a Wordpress plugin that extends the XML-RPC API (http://codex.wordpress.org/XML-RPC_Extending)
    • Solution 5: use the Datasource to sync with a local database that would be more flexible using a DBOsource
  2. The API does not allow you to filter by columns outside the documented columns (http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#Parameters_2). Currently, all "non-registered" columns are simply ignored by the API.

    • Solution 1: once we get a response, we can filter the array. We would also have to implement a proper "count" override since the count of data coming from the API would no longer be the sane as what the datasource returns.
    • Solution 2: submit a PR to the codebase to add this obviously useful functionality
    • Solution 3: create a Wordpress plugin that extends the XML-RPC API (http://codex.wordpress.org/XML-RPC_Extending)
    • Solution 4: use the Datasource to sync with a local database that would be more flexible using a DBOsource

cakephp-wordpress-datasource's People

Contributors

angelxmoreno avatar

Watchers

 avatar  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.