CodeCanyon Required Post Fields for WordPress 5272956

CodeCanyon Required Post Fields for WordPress 5272956

CodeCanyon Required Post Fields for WordPress 5272956
WordPress \ Utilities
Required \ Publishing \ Fields \ Tags \ Workflow \ Wordpress \ Image \ Featured

Plugin - Required Post Fields for WordPress 5272956 by interconnectit @ CodeCanyon

WordPress \ Utilities

Last Update: 7 August 13; Software Version: WordPress 3.5, WordPress 3.4, WordPress 3.3; Files Included: JavaScript JS, CSS, PHP.

Required Post Fields helps you ensure that your users & authors don’t publish content by mistake if they forget to do something. It’s common to require content to have a featured image, be categorised or tagged, or to need a custom excerpt. This plugin makes sure that happens.

It adds settings to your admin area to let you make certain post fields required. You can force authors to upload a thumbnail and even set a minimum required image size for it, as well as the ability to require a title, content, custom excerpt, tags and a non default category.

The plugin fully supports any custom post types out of the box and you can also add as many extra validation rules as you like using the plugin’s API!

Usage
Upload and activate the plugin. Head to the Writing settings page and scroll to the bottom. There you will find boxes to check to make certain fields required when a user adds or edits a post or page.

The default options are.

- Require title

- Require content

- Require custom excerpt

- Require non default category

- Require tags

- Require featured image

- Minimum size for featured images

When you add or edit a post and it doesn’t meet the requirements the relevant fields will be highlighted.

API
For the developers among you (or those brave enough to add a few lines of PHP) there is an API to add/remove your own required fields too, even for custom fields.

register_required_field( name, message [, callback [, post types [, highlight ] ] ] )
This adds a validation check to any item in the $_POST array of a WordPress edit screen.

Use it in an admin_init hook like so.

add_action('admin_init', 'my_required_fields');
function my_required_fields() {
// adds a basic check to see if $_POST[ 'custom_meta_field' ]
// is empty or not
register_required_field( 'custom_meta_field', 'You must fill out the custom meta field' );
}

unregister_required_field( name, [, callback [, post types ] ] )
add_action('admin_init', 'my_non_required_fields');
function my_non_required_fields() {
// remove the default validation check for post content
// only for the 'page' post type
unregister_required_field( 'post_content', array('required_fields', '_not_empty'), 'page' );
}

Custom Validations
You can call register_required_field() with a custom validation callback.

The entire $_POST array is available as the second argument to your validation functions so you have access to everything you would ever need.

A custom callback example that checks for a site wide option to be set.

register_required_field(
'twitter',
'Please enter a twitter username for the site before publishing',
function( $value, $postarr ) {
$site_twitter = get_option( 'site_twitter' );
if ( $site_twitter )
return true;
// do not publish if there's no twitter account set
return false;
},
array( 'post', 'custom_post_type' ) // adds the validation to posts and 'custom_post_type'
);

Multiple validations
You can call register_required_field() against the same $_POST field as many times as you want. They are non destructive so will have a cumulative effect.

register_required_field( 'post_title', 'Title must be filled in' );
register_required_field( 'post_title', 'Title must contain a number', 'check_for_number' );
register_required_field( 'post_title', 'Title must be at least 2 words', 'check_word_count' );
// returns false is $value contains no numbers
function check_for_number( $value, $postarr ) {
return preg_match( '/d+/', $value );
}
// returns false if $value is less than 2 words
function check_word_count( $value, $postarr ) {
return count( explode( ' ', strip_tags($value) ) ) >= 2;
}

Adding options to the settings screen
There are plenty of hooks available to modify the behaviour of this plugin. One such hook allows you to extend the writing settings available to administrators in the settings.

The following is an example of adding an option to require a page template to be set for pages.

add_filter( 'required_fields_settings', 'my_required_fields_settings' );
function my_required_fields_settings( $fields ) {
$fields[ 'my_page_setting' ] = array(
'title' => __( 'Template' ), // The setting field label
'setting_cb' => 'intval', // The setting field validation (see register_setting())
'setting_field' => array( 'required_fields', 'checkbox_field' ), // A built in checkbox field
'setting_description' => '', // Additional description text for the field
'name' => 'page_template', // The $_POST field to check
'message' => __( 'You should select a page template before publishing.' ), // Error message
'validation_cb' => 'has_page_template', // custom validation callback
'post_type' => 'page', // post type for validation
'highlight' => '#page_template' // CSS selector to highlight on fail
);
return $fields;
}
// check $value is not empty and not set to 'default'
function has_page_template( $value, $postarr ) {
return ! empty( $value ) && $value !== 'default';
}

Highlighting fields with an error
In the above example you should note that the highlight option contains a CSS selector targeting the error field.

If you do this the plugin will highlight the field or section that matches the selectors. Clicking on the error message will scroll the page to the field that has an error and shake it to make it clear what needs to be actioned.

Thanks!
We’re happy to answer any support questions and provide code examples to achieve what you want with the plugin’s API in the comments.

Keywords: categories, custom post types, editing, editor, excerpt, featured image, publishing, required fields, tags, wordpress, workflow.



Tags: Required, Fields, Image, Featured, Publishing

Premium CodeCanyon Required Post Fields for WordPress 5272956 WordPress Themes, Website Templates, Mobile Themes, Flash Templates & Scripts from creative professional designers. Full details of CodeCanyon Required Post Fields for WordPress 5272956 for digital design and education. CodeCanyon Required Post Fields for WordPress 5272956 desigen style information or anything related.

Comments:

Name:*
E-Mail:*
Add Comments:
Enter Code: *