Coder Social home page Coder Social logo

cms-toolkit's Introduction

======= WordPress CMS Toolkit

This plugin provides tools for extending WordPress for use as a Content Management System (CMS). Tools include things like the function build_post_type(), a helper function for WordPress core's register_post_type function. The goal of the Toolkit is to promote DRY coding practices while simplifying the process of creating admin meta boxes. While CMS Toolkit is currently integrated with WordPress as a plugin, it may be more helpful to think of it as a library - a collection of methods which, when installed, are available throughout the application and make building complex functionality in WordPress a little easier.

Build Status

Table of Contents

  1. Install
  2. Activate
  3. Develop
  4. Extend
  5. Technical details
  6. Unit Tests
  7. FAQ

Install

This plugin can be installed as a normal WordPress plugin.

Warning: This plugin requires PHP 5.3+.

Activate

To activate the plugin follow the steps below:

  1. Login to WordPress account.
  2. Go to Plugins screen and find "WordPress CMS Toolkit" in the list
  3. Click Activate Plugin to activate it.

Develop

See CONTRIBUTING.md

How to Use

Out of the box this plugin makes namespaces, classes, and methods available to WordPress. Developers should write 'child' plugins that import classes and functionality from this one. Importing with use...as in PHP is kind of like using import <module> as in python.

To check if this plugin is active, check for the existence of the DEPENDENCIES_READY constant in your child plugin.

Example:

<?php 
if ( defined('DEPENDENCIES_READY') ) {
   // do stuff... 
} else {
// do other stuff... 
} 
?> 

What's a namespace?

A namespace is an isolated place where classes and methods can live without trampling all over other methods in your system. Classes in this plugin exist in the CFPB\Utils namespace and can be imported with use. To get the post type class, include a line like: use \CFPB\Utils\PostTypes; at the beginning. You can also rename the class something else by use \CFPB\Utils\PostTypes as Foo;. PHP namespacing is really cool, read about it. Some people don't like use, to avoid it you'll have to write out the fully qualified namespace whenever you call methods or instantiate classes out of this plugin.

Example

There are many examples of how to use these methods in the unit tests, but here's a full example of child plugin:

<?php 
/* * 
* Add the normal Plugin front matter here 
* */

namespace YourVendorName\YourPluginName;

use \CFPB\Utils\PostType;

class Base {
   public $util;

  function __construct() { 
    $this->util = new PostType(); 
  }

  static function build() {
     add_action( 'init', array($this,'post_types') );
  }
  static function post_types() {
    $this->util->build_post_type(
      'Regulation',
      'Regulations',
      'regulation',
      $prefix = 'cfpb_',
      $args = array(
        'has_archive' => false,
        'rewrite' => array( 
          'slug' => 'regulations',
          'with_front' => false
        ),
      'supports' => array( 
        'title',
        'editor',
        'revisions',
        'page-attributes',
        'custom-fields'
        )
      )
    );
  $this->util->maybe_flush_rewrite_rules('cfpb_regulation');
  } 
}

$p = new \Vendor\Plugin\Base(); 
if ('DEPENDENCIES_READY') {
  add_action('plugins_loaded', array($p, 'build')); 
} 
?>

##Technical details

This plugin extends WordPress by adding objects for creating self-validating meta box forms (for post screens only, for now), post types, and taxonomies. It also modifies WordPress permissions to inhibit certain behaviors among under- privileged users.

This plugin is highly extensible and 'child plugins' should be created in order to actually do anything (except for permissions, for now).

See /inc/README.md for how this plugin works and examples of how to extend it organized by class.

Unit Tests

[WP_Mock and PHPunit](http://greg.harmsboone.org/blog/2014/01/01/writing-unit- tests-for-wordpress) are used to write unit tests for each method. Any core WordPress methods called are mocked. WP_Mock may be installed through composer and PHPunit installation is well documented.

Many of these tests end without assertions. In these tests, the verification is that a core WordPress method is called properly and the correct number of times.

cms-toolkit's People

Contributors

dpford avatar gboone avatar himedlooff avatar kurtw avatar mistergone avatar rosskarchner avatar scotchester avatar willbarton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

cms-toolkit's Issues

A formset's howto should only be shown once

In this example, it seems redundant to show the howto text for the "Content area" formset ("Enter one or two blocks of content to be featured at the top of the page.") each time. Or, maybe we need another level of howto text. One for outside the repeating groups of fields, and one for inside each field group.

screen shot 2015-04-15 at 14 07 41

Thoughts, @kurtw?

Serialized custom field data is not imported correctly after being exported by the standard WordPress export/import plugin

This is probably not a bug specific to CMS Toolkit, but I couldn't think of a better place to put it.

Example:

The milestone meta_value is stored in an array of strings:


"milestones": [
  "Determine how much you can afford to spend on a home",
  "Decide if it’s the right time to buy a new home",
  "Gather your application paperwork"
],

This data is exported to WordPress's XML format in a serialized form, like so:

…
<wp:postmeta>
    <wp:meta_key>milestones</wp:meta_key>
    <wp:meta_value><![CDATA[a:3:{i:0;s:52:"Determine how much you can afford to spend on a home";i:1;s:50:"Decide if it’s the right time to buy a new home ";i:2;s:34:"Gather your application paperwork ";}]]></wp:meta_value>
</wp:postmeta>
…

After attempting to import into a different WordPress installation, the JSON output for the field shows:


"milestones": [
  "a:0:{}",
  "a:3:{i:0;s:52:\"Determine how much you can afford to spend on a home\";i:1;s:50:\"Decide if it’s the right time to buy a new home \";i:2;s:34:\"Gather your application paperwork \";}"
],

For some reason, the data is not being correctly unserialized. It could be being exported incorrectly, imported incorrectly, or both.

Things we've tried:

  • Using WP-CLI to export and import the data. WP-CLI definitely doesn't export it correctly. It shows an empty serialized array:

    wp:postmeta
    wp:meta_keymilestones/wp:meta_key
    wp:meta_value/wp:meta_value
    /wp:postmeta

  • Adding a maybe_unserialize() call to the line in the import plugin's parser that sets meta values. Appears to have no effect.

I think the next step is a full step-by-step debugging of the import process.

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.