Code Monkey home page Code Monkey logo

Comments (4)

pixeltherapy avatar pixeltherapy commented on July 27, 2024 1

I've been looking to do the same for some of my own WP themes but when I sit down to refactor for dependency injection my eyes start glazing over at the task ahead. I'm where you are in terms of seeing where you want to be and how to get there, minus the optimism.

I'm borrowing your custom post class for a minute to rule out bugs in my own class but I like your tidy approach to adding admin edit columns. I look forward to seeing how it develops.

As an aside, you might consider using "require-dev" for unit test and similar tooling to reduce bloat in production use.

from posttypes.

jjgrainger avatar jjgrainger commented on July 27, 2024 1

Following on from issue #11 the Taxonomy class could become a standalone thing, available to developers to register taxonomies.

Taxonomies could be created as objects then be passed to the post type to register it, or could still use the taxonomy slug.

// register a post type
$books = new PostType('book');

// register a taxonomy
$genre = new Taxonomy('genre');

// register the taxonomy to the books post type
// using the taxonomy object
$books->taxonomy($genre);
// or with the taxonomy slug
$books->taxonomy('genre');

// register the post type
$books->register();

Using the taxonomy class to create objects can then open up additional methods for manipulating the taxonomy.

$genre = new Taxonomy('genre');

// modify the taxonomy admin columns
$genre->columns()->add([
    'populatrity_score' => __('Popularity')
]);

Then there is how the taxonomy is registered, can it register itself to a post type, or does that have to be done through a PostType object? Or both?

// register taxonomy to post type
$genre->postType('post');
// alternativly, if a books PostType object is available
$books->taxonomy('genre');

Then there is whether we need to provide it with a register() method too.

$genre->register();

Will explore this further...

from posttypes.

pixeltherapy avatar pixeltherapy commented on July 27, 2024 1

I like how tidy all this looks. I'm going to give it a whirl in my dev theme and see what issues arise.

from posttypes.

jjgrainger avatar jjgrainger commented on July 27, 2024

Now the Taxonomy class is an independent thing from PostType the last dependency to fix is the Columns. Something I've discovered recently is that you can type hint a parameter but also default it to null.

In light of this, I'm thinking the columns() method in the PostType (and soon to be in Taxonomy) can accept a ColumnManager dependency. This can default to null, which then will instantiate the default Column class and assign it.

The method will look something like:

class PostType
{

    //... additional methods and properties

    public var $columns;

    public function columns(ColumnManager $columns = null)
    {
        // if the column manager is already set, return it
        if (isset($this->columns)) {
            return $this->columns;
        }

        // if no custom ColumnManager is passed
        if (is_null($columns)) {
            // instatiate one using PostTypes default
            $this->columns = new PostTypes\ColumnManager;
        } else {
            // otherwise assign the custom ColumnManager
            $this->columns = $columns;
        }

        return $this->columns;
    }
}

This way when creating PostTypes and Taxonomy classes:

// create post type
$books = new PostType('book');

// default to PostType\ColumnManager
$books->columns()->add([...]);

// using a custom ColumnManager
$books->columns(new MyCustomColumnManager)->add([...]);

// register the post type to WordPress
$books->register();

from posttypes.

Related Issues (20)

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.