2017 © Pedro Peláez
 

wordpress-plugin termlimit

WordPress plugin to limit the amount of (custom) taxonomy taxons on a per post type basis.

image

wecodemore/termlimit

WordPress plugin to limit the amount of (custom) taxonomy taxons on a per post type basis.

  • Wednesday, March 25, 2015
  • by wecodemore
  • Repository
  • 5 Watchers
  • 4 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

WordPress Term Limits

Limits terms (categories, post tags, custom taxonomy terms) on a per post type basis, (*1)

Do you have lazy authors who don't care using a single tag? Do you have wannabe SEO experts using all of your tags on each post?, (*2)

Set an end to that. Just like seen on StackOverflow and other StackExchange sites: minimum 1 tag, maximum 5., (*3)

(Yes you can define the amount yourself), (*4)

Needs PHP 5.4+ to run. Will break with lower PHP versions., (*5)

Is this a plugin?

Yes. For WordPress., (*6)

How to install?

You can simply download it and are ready to go. Still the following options are preferred., (*7)

Or just install/import it into your project using Composer, (*8)

composer create-project wcm/termlimits

Or clone the repository into your plugin directory using git, (*9)

git clone git@github.com:wecodemore/wcm-termlimit.git

How to use?

Per default, there is a minimum of 0 terms that need to get added. The maximum is 3. And the limit only applies for the post post type., (*10)

To alter the limit or the type, there are two filters that you can use in a small child plugin:, (*11)

<?php
/** Plugin Name: Term Limit config */

// Apply a minimum of 3 and a limit of 6 terms
add_filter( 'wcm-term.limit', function( Array $limit )
{
    return range( 3, 6 );
} );

// Apply the limit to the following post types
add_filter( 'wcm-term.types', function( Array $types )
{
    return [ 'post', 'my-custom-post-type', ];
} );

In case you want to extend your limit to custom taxonomies, you will also have to write a quick extension/class to account for that:, (*12)

class MyCustomTaxonomy extends AbstractTaxon implements TaxonInterface
{
    public function __construct()
    {
        $this->append( explode( ",", filter_var(
            $_POST['tax_input']['custom_terms'],
            FILTER_SANITIZE_STRING,
            [ FILTER_NULL_ON_FAILURE, ]
        ) ) );
    }
}

To see what exactly you should take as input/$_POST value, use the following mini-plugin to dump your save_post action., (*13)

<?php
/** Plugin Name: (Debug) Dump $_POST during save_post */
add_action( 'save_post', function()
{
    exit( var_dump( $_POST ) );
} );

Important: Make sure that you have at least FTP access and can actually edit or remove the plugin. Else you will get stuck there. This will break (exit) your request and present you with a dump of the post., (*14)

The @TODO List

Custom taxonomy terms., (*15)

Also, there's by now nothing built in to do something in case the limit was exceeded or the needed threshold not reached (min/max taxons). The plugin lets everything go through and just informs the user. One idea so far: extend the notification. The problem with this is that I have no idea what should happen in that case. Should we nuke all added terms? What if 20 are allowed and the user added 21? Should we just cut off one? If yes: Which one? Etc. As you can see, there're a lot of possible UX mine traps and I have by now no idea how to solve them. To be honest: This was just a very quick side project as it is something that is often requested. If you have any idea how to go on this, feel free to open a pull request to discuss your ideas. Thanks in advance., (*16)

License

WCM TermLimits is licensed under the MIT. Do whatever you want and feel comfortable with it. Still a tweet or similar and a star here on GitHub won't hurt, right?, (*17)

The Versions

25/03 2015

dev-master

9999999-dev https://github.com/wecodemore/wcm-termlimit

WordPress plugin to limit the amount of (custom) taxonomy taxons on a per post type basis.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin wordpress tag taxonomy post category term

25/03 2015

v0.3.0

0.3.0.0 https://github.com/wecodemore/wcm-termlimit

WordPress plugin to limit the amount of (custom) taxonomy taxons on a per post type basis.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin wordpress tag taxonomy post category term

20/02 2015

v0.2.5

0.2.5.0 https://github.com/wecodemore/wcm-termlimit

WordPress plugin to limit the amount of (custom) taxonomy taxons on a per post type basis.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin wordpress tag taxonomy post category term

20/02 2015

v0.2.4

0.2.4.0 https://github.com/wecodemore/wcm-termlimit

WordPress plugin to limit the amount of (custom) taxonomy taxons on a per post type basis.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin wordpress tag taxonomy post category term

19/02 2015

v0.2.3

0.2.3.0 https://github.com/wecodemore/wcm-termlimit

WordPress plugin to limit the amount of (custom) taxonomy taxons on a per post type basis.

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin wordpress tag taxonomy post category term

19/02 2015

v0.2.2

0.2.2.0 https://github.com/wecodemore/wcm-termlimit

WordPress plugin to limit the amount of tags, categories or custom taxonomy taxons on a per post type basis.

  Sources   Download

MIT

The Requires

 

plugin wordpress tag taxonomy post category term

19/02 2015

v0.2.1

0.2.1.0 https://github.com/wecodemore/wcm-termlimit

WordPress plugin to limit the amount of tags, categories or custom taxonomy taxons on a per post type basis.

  Sources   Download

MIT

The Requires

 

plugin wordpress tag taxonomy post category term

19/02 2015

v0.2.0

0.2.0.0 https://github.com/wecodemore/wcm-termlimit

WordPress plugin to limit the amount of tags, categories or custom taxonomy taxons on a per post type basis.

  Sources   Download

MIT

The Requires

 

plugin wordpress tag taxonomy post category term

10/02 2015

dev-dev

dev-dev https://github.com/wecodemore/wcm-termlimit

WordPress plugin to limit the amount of tags, categories or custom taxonomy taxons on a per post type basis.

  Sources   Download

MIT

The Requires

 

plugin wordpress tag taxonomy post category term

10/02 2015

0.1.1

0.1.1.0 https://github.com/wecodemore/wcm-termlimit

WordPress plugin to limit the amount of tags, categories or custom taxonomy taxons on a per post type basis.

  Sources   Download

MIT

The Requires

 

plugin wordpress tag taxonomy post category term

10/02 2015

0.1.0

0.1.0.0 https://github.com/wecodemore/wcm-termlimit

WordPress plugin to limit the amount of tags, categories or custom taxonomy taxons on a per post type basis.

  Sources   Download

MIT

The Requires

 

plugin wordpress tag taxonomy post category term