Advertisement

How to Upload Custom Options to PTU WordPress Plugin

The Publish Sorts Limitless plugin, also known as “PTU”, allows you to easily add custom post types and taxonomies to your wordpress web page. I created this plugin because other plugins, identical to the more popular Custom designed Post Sort UI plugin, are bloated and full of upsells. This is a great add-on for any […]

The Publish Sorts Limitless plugin, also known as “PTU”, allows you to easily add custom post types and taxonomies to your wordpress web page. I created this plugin because other plugins, identical to the more popular Custom designed Post Sort UI plugin, are bloated and full of upsells. This is a great add-on for any web page that requires custom post types and/or taxonomies.

In this data, I can show you how to add custom concepts to the submission type and taxonomy registration. This way, you will be able to provide a built-in integration to your theme so that anyone who uses it can further control their own custom submission types and taxonomies.

These data are mainly spherically focused ancient problemsas blocking issues have been adapted directly to the web page editor, where the end buyer can fully customize submission types and taxonomies.

Why add custom choices to the Post up Variety Infinite plugin

As a theme developer you might be wondering why you need to add custom concepts to the PTU plugin. By having concepts along with the plugin, you will be able to make it easier for the end buyer to keep an eye on the design of their custom submission types and taxonomies. My general theme is a great example.

Here is a screenshot showing the “Single Post” settings added during the Common theme:

wordpress Theme Post Types Unlimited Single Post Settings” class=”wp-image-64664″/>

This provides the buyer with the following useful fields:

  • Use blank template: Allow using a blank template for submit type posts (i.e. without header/footer)
  • Dynamic model: Choose a template to display the submission.
  • Title: Change the default header text of the single submission web page.
  • Title style: Choose the setting style (can be used to hide the header of the web page).
  • Title Tag: Choose the HTML tag that defines the header of the web page (h1,h2,h3,h4,h5,h6,div).
  • Disposition: Choose the structure for your submission-type posts (no sidebar, left sidebar, right sidebar, full computer screen, and so on).
  • Next/Previous: Allows next and previous links at the bottom of the post, before the footer (often disabled when using a dynamic template, as you can add next/previous links on the fly via the dynamic template).

There are actually many more settings if you don’t have a dynamic template set up, on the other hand much more often than not customers are now creating dynamic templates for their sending types.

As you can see, when you create custom post types with Common, you have a lot of control over how individual posts appear. Typically, issues are coded so that custom post type archives and individual posts always look the same. Common also includes settings for custom taxonomies.

This way, buyers don’t have to use hooks, filters, or template parts to modify their custom submission types and taxonomies. This makes it possible for non-developers to create more complex web pages.

How the Infinite Variety System Works

The Put up Varieties Infinite plugin works using the core wordpress capabilities. Custom designed submission types and taxonomies are actually registered as submission types themselves. And the settings while registering/improving a submission type or taxonomy are completed via a practice metabox.

The registered custom submission types are saved in a case submission type called ptu and custom taxonomies are saved in a case submission type called ptu_tax.

When the Internet web page is small enough, the plugin hooks into the init hook to query ptu and ptu_tax dispatch types, iterate and look at them. Custom dispatch types and taxonomies are stored in a class variable, so they could be retrieved quickly.

Retrieving a file of published varieties and taxonomies

These are the two functions you can use to retrieve custom submission types and taxonomies:

  • PTUPostTypes::get_registered_items() – returns an array of send types, where the game name given by the send type and the fee is the send type ID ptu.
  • PTUTaxonomies::get_registered_items() – returns an array of registered taxonomies, where the name of the taxonomy established by the game and the rate is the ptu_tax submission type ID.

If you want to review or browse custom send types or taxonomies created by your buyer, you can use them to make the methods public.

Retrieving a sort or taxonomy environment value

I mentioned earlier that the send type and taxonomy settings are completed via a metabox, so they are stored as custom fields. To get the cost of any atmosphere you might be able to use the core get_post_meta() They work like this:

// Get submit type atmosphere value.
get_post_meta( 'post_type_name', '_ptu_{option_id}', true );

// Get taxonomy atmosphere value.
get_post_meta( 'taxonomy_name', '_ptu_{option_id}', true );

The Post up Varieties Infinite plugin automatically provides a _ptu_ prefix to custom fields once saved. You will definitely want to include this prefix when getting the cost of your personal concepts. I will be able to explain a bit better with some examples in a bit.

How to add custom choices to post sorting and taxonomy Add New/Edit Views

Along with the concepts it is very simple and is completed by creating new tabs in the default metabox. You will have the ability to add new tabs to each type of submission and the taxonomy shows new/edit. This is completed by hooking to ptu/posttypes/meta_box_tabs AND ptu/taxonomies/meta_box_tab filters.

Here is an example of a new tab called “Cool Theme Settings” with some custom concepts. This code will add the equivalent settings to each submission type and taxonomy environment pages.

/**
 * Add custom concepts to the Put up Varieties Infinite Plugin.
 *
 * @link https://www.wpexplorer.com/post-types-unlimited-custom-options/
 */
function wpexplorer_add_ptu_type_tabs( array $tabs ): array {
	$tabs[] = [
		'id'     => 'themename_settings',
		'title'  => esc_html__( 'Cool Theme Settings', 'themename' ),
		'fields' => [
			[
				'name' => esc_html__( 'Check Option', 'themename' ),
				'id'   => 'check_option',
				'type' => 'checkbox',
			],
			[
				'name' => esc_html__( 'Text Option', 'themename' ),
				'id'   => 'text_option',
				'type' => 'text',
			],
			[
				'name'    => esc_html__( 'Custom Select Option', 'themename' ),
				'id'      => 'select_option',
				'type'    => 'select',
				'choices' => [
					''         => esc_html__( '- Select -', 'themename' ),
					'option_1' => esc_html__( 'Option 1', 'themename' ),
					'option_2' => esc_html__( 'Option 2', 'themename' ),
					'option_3' => esc_html__( 'Option 3', 'themename' ),
				],
			],
			[
				'name' => esc_html__( 'Image Select Option', 'themename' ),
				'id'   => 'image_size_option',
				'type' => 'image_size',
			],
		],
	];
	return $tabs;
}
add_filter( 'ptu/posttypes/meta_box_tabs', 'wpexplorer_add_ptu_type_tabs' );
add_filter( 'ptu/taxonomies/meta_box_tabs', 'wpexplorer_add_ptu_type_tabs' );

This code will add a new tab that looks like this:

Variety of random fields

The development snippet should be great in a moment, but it definitely shows better how to add some field types. Below is a table of all field types with an overview and the extra argument file that can be added for the type.

Field sorting Description Further topics
text Basic text field. (bool) required
(int) maximum length
amount Amount type field. (int) step
(int) minimum
(int) maximum
textarea Text area. (int) lines
checkbox Checkbox.
make a selection Create a custom dropdown menu. (array) conceivable alternatives
multi_select Multiple checkboxes grouped together. (array) conceivable alternatives
internet web page Make a selection that returns all pages.
image_size Makes a selection that returns all defined image sizes.
taxonomy Makes a selection that returns all registered public taxonomy names.
dashicon The Dashicon icon allows you to make a selection.

Conditional fields (show/hide)

The magnificence of Metabox has the ability to show/hide tabs and fields via a scenario key. You will have the option to add a new scenario key to the card matrix to control the display of cards or to particular concepts to control the visibility of the selection.

The conditional argument works through an array using the following structure:

'scenario' => [ 'setting_to_check', 'operator', 'value_to_check' ]
  • setting_to_check: (string) ID of the atmosphere to check its cost.
  • operator: (string) can also be “=” or “!=”.
  • value_to_check: (string) the expected value to which it should be equal or different.

For example, let’s say you want to upload a card that displays more efficiently if the “public” post type setting is enabled, you’ll be able to do so like this:

function wpexplorer_add_ptu_type_tabs( array $tabs ): array {
	$tabs[] = [
		'id'        => 'themename_public_settings',
		'title'     => esc_html__( 'Public Settings', 'themename' ),
		'condition' => [ 'public', '=', 'true' ], // !!! CONDITIONAL CHECK !!!
		'fields'    => [ ]
	];
	return $tabs;
}
add_filter( 'ptu/posttypes/meta_box_tabs', 'wpexplorer_add_ptu_type_tabs' );

Or let’s say you are with 2 concepts, on the other hand the second selection should be displayed at its best if the main selection is enabled. You will be able to do it like this:

function wpexplorer_add_ptu_type_tabs( array $tabs ): array {
	$tabs[] = [
		'id'        => 'themename_public_settings',
		'title'     => esc_html__( 'Public Settings', 'themename' ),
		'fields'    => [
			[
				'name' => esc_html__( 'Check Option', 'themename' ),
				'id'   => 'check_option',
				'type' => 'checkbox',
			],
			[
				'name'      => esc_html__( 'Conditional Text Option', 'themename' ),
				'id'        => 'text_option',
				'type'      => 'text',
				'condition' => [ 'check_option', '=', 'true' ], // !!! CONDITIONAL CHECK !!!
			],
		]
	];
	return $tabs;
}
add_filter( 'ptu/posttypes/meta_box_tabs', 'wpexplorer_add_ptu_type_tabs' );

By using conditional ratings, you will have the ability to provide a better shopping experience if certain concepts are not sought after at the expense of other concepts. Simply, the conditional ability may be very minimal and will best help you try a single selection at a time, as opposed to a single value.

Retrieving custom probability values

Now that you know how to load custom concepts, I’ll be able to explain how to get the cost of those concepts. I outlined earlier that you’ll use the basic get_post_meta() function to get the cost of your fields. Alternatively, to get the value of the custom field, you’ll need to pass the correct ID based on the post type or taxonomy. I can show you the best way to look at this.

Get the value of a sorting possibility put up for sale

Let’s say you want to have a selection to make a construction choice for individual posts of the custom post type, and the selection ID is “post_layout”. So, regardless of the code you’re using to get the existing post construction, you’ll need to add an extra checkout to your custom PTU selection.

Here is an example of how to get a send type selection value:

if ( is_callable( 'PTUPostTypes::get_registered_items' ) ) {
	// Get the submit type.
	$post_type = get_post_type();

	// Get registered PTU submit types.
	$ptu_types = PTUPostTypes::get_registered_items();

	// Take a look at if the existing submit type is part of the PTU types.
	if ( isset( $ptu_types[ $post_type ] ) ) {
		$ptu_post_layout = get_post_meta( $ptu_types[ $post_type ], '_ptu_themename_post_layout', true );
	}
}

The code works by checking to see if the existing post is a PTU custom post type, and if so, uses get_post_meta to grab the custom field value. Take note to replace themename_post_layout to the ID of the selection you are retrieving.

Getting the value of a Chance taxonomy

Getting the rate for a taxonomy selection is very similar to that of a practice submission type. The difference is that you have to run a check against the registered taxonomies.

Here is an example of how to get a taxonomy selection value:

if ( is_callable( 'PTUTaxonomies::get_registered_items' ) ) {
	// Get the existing taxonomy.
	$taxonomy = get_query_var( 'taxonomy' );

	// Get registered PTU taxonomies.
	$ptu_taxonomies = PTUTaxonomies::get_registered_items();

	// Take a look at if the taxonomy is part of the PTU taxonomies.
	if ( isset( $ptu_taxonomies[ $taxonomy ] ) ) {
		$ptu_archive_layout = get_post_meta( $ptu_taxonomies[ $taxonomy ], '_ptu_themename_archive_layout', true );
	}
}

The code works by checking to see if the existing taxonomy is a PTU custom taxonomy, and if so, uses get_post_meta to grab the value of the custom field. Take note to replace themename_archive_layout to the ID of the selection you are retrieving.

Creating a helper function to retrieve possible choices

To look at DRY rules I might recommend along with a helper function in your theme that you can use to get the cost of a PTU post type or taxonomy. Post up Varieties Infinite does not include a helper function because it is no longer wanted.

Get Put Up Sort Probability Value Helper Function

Here is a helper function to return a send type selection value:

/**
 * Get the cost of a PTU submit type atmosphere.
 */
function themename_get_ptu_meta( string $post_type, string $setting_id, $default="" ) {
	if ( is_callable( 'PTUPostTypes::get_registered_items' ) ) {
		$ptu_types = PTUPostTypes::get_registered_items();
		if ( isset( $ptu_types[ $post_type ] ) ) {
			if ( $default && ! metadata_exists( 'submit', $ptu_types[ $post_type ], $setting_id ) ) {
				return $default;
			}
			return get_post_meta( $ptu_types[ $post_type ], $setting_id, true );
		}
	}
}

And here’s how you might use the function:

$post_layout = themename_get_ptu_meta( get_post_type(), 'post_layout' );

Get the taxonomy probability value support function

Here is a helper function to return a taxonomy selection value:

/**
 * Get the cost of a PTU taxonomy atmosphere.
 */
function themename_get_ptu_tax_meta( string $taxonomy, string $setting_id, $default="" ) {
	if ( is_callable( 'PTUTaxonomies::get_registered_items' ) ) {
		$ptu_taxonomies = PTUTaxonomies::get_registered_items();
		if ( isset( $ptu_taxonomies[ $taxonomy ] ) ) {
			if ( $default && ! metadata_exists( 'submit', $ptu_taxonomies[ $taxonomy ], $setting_id ) ) {
				return $default;
			}
			return get_post_meta( $ptu_taxonomies[ $taxonomy ], $setting_id, true );
		}
	}
}

And here’s how you might use the function:

$archive_layout = themename_get_ptu_tax_meta( get_query_var( 'taxonomy' ), 'archive_layout' );

In each support function you will have the opportunity to see that I have also added a $default parameter you can use. This can occasionally help you pass a default value in case the custom field does not exist.

Conclusion

Along with the concepts in your theme for the Infinite Post Variety Plugin is super easy and you will have to do it too! Especially if you are selling a better elegance theme, it will actually be great for your buyers to add custom post types and taxonomies to their web page and have additional control over how they appear without any coding knowledge.

Additionally, you will simply save yourself the hassle of selling or maintaining your own custom themes and instead become a ThemeForest affiliate and recommend/use my general theme.

Let me know in the comments if you have any problems or questions!

The article How to Load Custom Options on wordpress PTU Plugin appeared first on WPExplorer.

WP Support Plans

[ continue ]

wordpress Maintenance Plans | wordpress hosting

Learn more

<a href=”https://wpmountain.com/how-one-can-upload-customized-choices-to-the-ptu-wordpress-plugin/”>Source link

See what others are saying about this...

Débloquez Vos Fléchisseurs De La Hanche

Product Name: Débloquez Vos Fléchisseurs De La Hanche Click here to get Débloquez Vos Fléchisseurs De La Hanche at discounted price while it’s still available… All orders are protected by SSL encryption – the highest...

Acid Reflux sl cb – case study | Blue Heron Health News

Product Name: Acid Reflux sl cb – case study | Blue Heron Health News Click here to get Acid Reflux sl cb – case study | Blue Heron Health News at discounted price while it’s still available… All orders are protected by SSL encryption –...

Sweat Miracle™ – FREE Video Presentation

Product Name: Sweat Miracle™ – FREE Video Presentation Click here to get Sweat Miracle™ – FREE Video Presentation at discounted price while it’s still available… All orders are protected by SSL encryption – the highest...

My advice for people of color Check out Spoil Into Tech

Welcome to Breaking the project – a collection of blogs that delves into difficult business eventualities and the possible choices of underrepresented heads of families and entrepreneurs. Learn how they grew or expanded their companies, explored entrepreneurial...

14+ Easiest E mail Automation Equipment for Your Industry (Professional Select)

We’ve run online firms and websites for years, so we understand how long it should most likely take to write down emails to shoppers, leads, and subscribers. As a industry owner, your time is effective. You want to pay attention to emerging your corporation, not...

Taming Stubbornness: How to Deal with Kids Who Throw Tantrums

Product Name: Taming Stubbornness: How to Deal with Kids Who Throw Tantrums Click here to get Taming Stubbornness: How to Deal with Kids Who Throw Tantrums at discounted price while it’s still available… All orders are protected by SSL encryption –...

How To Re-Package deal Your Present Divi Subscriptions & Save Hundreds

The Divi Summer time Sale is in entire swing with excellent provides on Divi, Divi AI, Divi Groups, Divi Cloud, Divi VIP, and a whole lot of Divi Market products. To benefit from the ones excellent provides, it’s a will have to to behave now. Along side...

The most profitable trading indicators in the world | VipIndicators.com

Product Name: The most profitable trading indicators in the world | VipIndicators.com Click here to get The most profitable trading indicators in the world | VipIndicators.com at discounted price while it’s still available… All orders are protected by SSL...

Free Presentation: Relationship Rewriting Method | Be Irresistible

Product Name: Free Presentation: Relationship Rewriting Method | Be Irresistible Click here to get Free Presentation: Relationship Rewriting Method | Be Irresistible at discounted price while it’s still available… All orders are protected by SSL...

Volca Burn

Product Name: Volca Burn Click here to get Volca Burn at discounted price while it’s still available… All orders are protected by SSL encryption – the highest industry standard for online security from trusted vendors. Volca Burn is backed with a 60...

How to Upload Custom Options to PTU WordPress Plugin

The Publish Sorts Limitless plugin, also known as “PTU”, allows you to easily add custom post types and taxonomies to your wordpress web page. I created this plugin because other plugins, identical to the more popular Custom designed Post Sort UI plugin, are bloated…