WordPress PHP 'printf' giving two values - php

I'm running WordPress 4.9.6 with BuddyPress and BuddyPress XProfile plugin.
XProfile is getting the users location and returning it as a hyperlink in their profile to search the rest of the site with the same location tag.
The issue I'm getting is the PHP script is returning the location plus a number which changes between 69, 76, and 22.
This is the code that I'm running to get the location:
/**
* Modify the appearance of value.
*
* #param string $field_value Original value of field.
* #param int $field_id Id of field.
*
* #return string Value formatted
*/
public static function display_filter( $field_value, $field_id = 0 ) {
if ( empty( $field_value ) ) {
return;
}
$term_id = absint( $field_value );
$tax = self::get_selected_taxonomy( $field_id );
$term = get_term( $term_id, $tax );
if ( ! $term || is_wp_error( $term ) ) {
return '';
}
return printf( '%2$s', esc_url( get_term_link( $term, $tax ) ), esc_html( $term->name ) );
}
/**
* Get the terms content.
*
* #param int $field_id field id.
*
* #return string
*/
public static function get_selected_taxonomy( $field_id ) {
if ( ! $field_id ) {
return '';
}
return bp_xprofile_get_meta( $field_id, 'field', 'selected_taxonomy', true );
}
}
I changed from sprintf to printf as it was returning the full HTML code.
Since changing to printf, this error has occurred.
What part do I need to amend or remove to lose the number tag being generated, please?
This is a screenshot of the tag plus the number below it

Related

How to Add User Role ColunmTo Woocommcerce Orders table

Can't seem to figure out the PHP code to add a new column on the woocommcerce orders admin page to show the customers user role?
Thanks for your time
Darren
Strugglinjg to get any PHP snippets ive found to work
Here is the code snippet you can add to your functions.php:
/**
* Add custom column.
*
* #param array $columns Columns.
* #return array
*/
function set_custom_edit_shop_order_columns( $columns ) {
$columns['user_role'] = __( 'Role', 'your-text-domain' );
return $columns;
}
add_filter( 'manage_shop_order_posts_columns', 'set_custom_edit_shop_order_columns', 100, 1 );
/**
* Add data to custom column.
*
* #param string $column Column slug.
* #param id $post_id Post ID.
*/
function custom_shop_order_column( $column, $post_id ) {
if ( 'user_role' === $column ) {
$order_user = get_post_meta( $post_id, '_customer_user', true );
if ( ! empty( $order_user ) ) {
$user = get_user_by( 'ID', $order_user );
if ( ! empty( $user ) ) {
echo implode( ', ', ( array ) $user->roles );
}
}
}
}
add_action( 'manage_shop_order_posts_custom_column', 'custom_shop_order_column', 100, 2 );
This will only work if you have not opted in for High-Performance Order Storage (HPOS), otherwise you may have to tweak custom_shop_order_column() method to retrieve data from new custom order meta table.

How can output the slug of product with custom base slug

first of all thx to everyone who put answers here and to all the staff of stackoverflow.
I write a class(copy paste and mod) of WC_duplicate_product off woocommerce in order to put a meta on duplicates and to generate a slug wit base as "https://website.com/slug-base/product-name", but I cant acomplish the part of slug-base. If anybody can help me i'll appreciate.
This is my code, feel free to use and mod:
/**
* Function to create the duplicate of the product.
*
* #param WC_Product $product The product to duplicate.
* #return WC_Product The duplicate.
*/
public function product_duplicate( $product ) {
/**
* Filter to allow us to exclude meta keys from product duplication..
*
* #param array $exclude_meta The keys to exclude from the duplicate.
* #param array $existing_meta_keys The meta keys that the product already has.
* #since 2.6
*/
$meta_to_exclude = array_filter(
apply_filters(
'woocommerce_duplicate_product_exclude_meta',
array(),
array_map(
function ( $datum ) {
return $datum->key;
},
$product->get_meta_data()
)
)
);
$duplicate = clone $product;
$duplicate->set_id( 0 );
$char = 47;
/* translators: %s contains the name of the original product. */
$duplicate->set_name( sprintf( '%s', $duplicate->get_name()) );
$duplicate->set_total_sales( 0 );
if ( '' !== $product->get_sku( 'edit' ) ) {
$duplicate->set_sku( wc_product_generate_unique_sku( 0, $product->get_sku( 'edit' ) ) );
}
$duplicate->set_status( 'draft' );
$duplicate->set_date_created( null );
$duplicate->set_slug( 'vendor'.sprintf( '%c', $char).'' );
$duplicate->set_rating_counts( 0 );
$duplicate->set_average_rating( 0 );
$duplicate->set_review_count( 0 );
$duplicate->add_meta_data( '_is_clone', 'true' );
foreach ( $meta_to_exclude as $meta_key ) {
$duplicate->delete_meta_data( $meta_key );
}
/**
* This action can be used to modify the object further before it is created - it will be passed by reference.
*
* #since 3.0
*/
do_action( 'woocommerce_product_duplicate_before_save', $duplicate, $product );
// Save parent product.
$duplicate->save();
// Duplicate children of a variable product.
if ( ! apply_filters( 'woocommerce_duplicate_product_exclude_children', false, $product ) && $product->is_type( 'variable' ) ) {
foreach ( $product->get_children() as $child_id ) {
$child = wc_get_product( $child_id );
$child_duplicate = clone $child;
$child_duplicate->set_parent_id( $duplicate->get_id() );
$child_duplicate->set_id( 0 );
$child_duplicate->set_date_created( null );
// If we wait and let the insertion generate the slug, we will see extreme performance degradation
// in the case where a product is used as a template. Every time the template is duplicated, each
// variation will query every consecutive slug until it finds an empty one. To avoid this, we can
// optimize the generation ourselves, avoiding the issue altogether.
$this->generate_unique_slug( $child_duplicate );
if ( '' !== $child->get_sku( 'edit' ) ) {
$child_duplicate->set_sku( wc_product_generate_unique_sku( 0, $child->get_sku( 'edit' ) ) );
}
foreach ( $meta_to_exclude as $meta_key ) {
$child_duplicate->delete_meta_data( $meta_key );
}
/**
* This action can be used to modify the object further before it is created - it will be passed by reference.
*
* #since 3.0
*/
do_action( 'woocommerce_product_duplicate_before_save', $child_duplicate, $child );
$child_duplicate->save();
}
// Get new object to reflect new children.
$duplicate = wc_get_product( $duplicate->get_id() );
}
return $duplicate;
}
this is teh part of code that I need to polish to get the desired slug, so when i run this clas, always obtain https://website.com/slug-baseproduct-name

Add Woocommerce Subscription switch to cart programmatically

I'm looking for a way to programmatically add a switch between two Woocommerce subscription variations to the cart.
We're building a headless WP site, so I don't want to do it with a link, as described in this question
I've tried the following simple way, but it won't allow it that way, since the user is already subscribed:
WC()->cart->add_to_cart( 1907, 1, 1908 );
I want to mimic what is happening when the user goes to the upgrade/downgrade page, selects a new variation and presses Switch subscription. Usually that means that the user is sent to checkout with the switch in cart, I just want it to be added to the cart, since we have our own checkout.
The main issue is that Woocommerce thinks that a subscription product is unpurchaseable when it is added to the cart any other way than through the subscription switch form. The form sends a couple of GET-parameters which sends WC through some extra validation, and then allows the item to be added to the cart if everything else is valid.
My solution to this is to mimic this validation with some functions of my own, mostly stolen from the subscription plugin.
/**
* Must be set to true before programmatically adding subscription switch to cart.
*
* #var bool
*/
$kbhl_adding_switch_to_cart = false;
/**
* Array filled with data about current subscription.
* Should only be retrieved by kbhl_get_current_subscription_data().
*
* #var array
*/
$kbhl_global_current_subscription_data = array();
/**
* Cache whether a given product is purchasable or not to save running lots of queries for the same product in the same request
*
* $is_purchasable_cache taken from plugins\woocommerce-subscriptions\includes\class-wcs-limiter.php
*
* #var array
*/
$kbhl_purchasable_cache = array();
/**
* $user_subscriptions_to_product taken from plugins\woocommerce-subscriptions\includes\class-wcs-limiter.php
*
* #var array
*/
$kbhl_user_subscriptions_to_product = array();
/**
* If a product is being marked as not purchasable because it is limited and the customer has a subscription,
* but the current request is to switch the subscription, then mark it as purchasable.
*
* Function is_purchasable_switch() taken from plugins\woocommerce-subscriptions\includes\class-wcs-limiter.php
*
* #param bool $is_purchasable Current purchasable status.
* #param obj $product Product being checked.
*
* #return bool New purchasable status.
*/
function kbhl_is_purchasable_switch( $is_purchasable, $product ) {
global $kbhl_purchasable_cache;
$kbhl_current_subscription_data = kbhl_get_current_subscription_data();
// Only process this filter if running custom add switch function.
if ( ! empty( $kbhl_current_subscription_data['id'] ) ) {
return $is_purchasable;
}
$product_key = wcs_get_canonical_product_id( $product );
// Set an empty cache if one isn't set yet.
if ( ! isset( $kbhl_purchasable_cache[ $product_key ] ) ) {
$kbhl_purchasable_cache[ $product_key ] = array();
}
// Exit early if we've already determined this product's purchasability via switching.
if ( isset( $kbhl_purchasable_cache[ $product_key ]['switch'] ) ) {
return $kbhl_purchasable_cache[ $product_key ]['switch'];
}
// If the product is already purchasble, we don't need to determine it's purchasibility via switching/auto-switching.
if ( true === $is_purchasable || ! is_user_logged_in() || ! wcs_is_product_switchable_type( $product ) || ! WC_Subscriptions_Product::is_subscription( $product->get_id() ) ) {
$kbhl_purchasable_cache[ $product_key ]['switch'] = $is_purchasable;
return $kbhl_purchasable_cache[ $product_key ]['switch'];
}
$user_id = get_current_user_id();
$product_limitation = wcs_get_product_limitation( $product );
if ( 'no' == $product_limitation || ! wcs_user_has_subscription( $user_id, $product->get_id(), wcs_get_product_limitation( $product ) ) ) {
$kbhl_purchasable_cache[ $product_key ]['switch'] = $is_purchasable;
return $kbhl_purchasable_cache[ $product_key ]['switch'];
}
// Adding to cart.
if ( array_key_exists( $kbhl_current_subscription_data['id'], kbhl_get_user_subscriptions_to_product( $product, $user_id, $product_limitation ) ) ) {
$is_purchasable = true;
}
$kbhl_purchasable_cache[ $product_key ]['switch'] = $is_purchasable;
return $kbhl_purchasable_cache[ $product_key ]['switch'];
}
add_filter( 'woocommerce_subscription_is_purchasable', 'kbhl_is_purchasable_switch', 13, 2 );
/**
* Gets a list of the customer subscriptions to a product with a particular limited status.
*
* Function get_user_subscriptions_to_product() taken from plugins\woocommerce-subscriptions\includes\class-wcs-limiter.php
*
* #param WC_Product|int $product The product object or product ID.
* #param int $user_id The user's ID.
* #param string $limit_status The limit status.
*
* #return WC_Subscription[] An array of a customer's subscriptions with a specific status and product.
*/
function kbhl_get_user_subscriptions_to_product( $product, $user_id, $limit_status ) {
global $user_subscriptions_to_product;
$product_id = is_object( $product ) ? $product->get_id() : $product;
$cache_key = "{$product_id}_{$user_id}_{$limit_status}";
if ( ! isset( $user_subscriptions_to_product[ $cache_key ] ) ) {
// Getting all the customers subscriptions and removing ones without the product is more performant than querying for subscriptions with the product.
$subscriptions = wcs_get_subscriptions(
array(
'customer_id' => $user_id,
'status' => $limit_status,
)
);
foreach ( $subscriptions as $subscription_id => $subscription ) {
if ( ! $subscription->has_product( $product_id ) ) {
unset( $subscriptions[ $subscription_id ] );
}
}
$user_subscriptions_to_product[ $cache_key ] = $subscriptions;
}
return $user_subscriptions_to_product[ $cache_key ];
}
/**
* When a subscription switch is added to the cart, store a record of pertinent meta about the switch.
*
* #since 1.4
*/
/**
* When a subscription switch is added to the cart, store a record of pertinent meta about the switch.
*
* Function set_switch_details_in_cart() taken from plugins\woocommerce-subscriptions\includes\class-wc-subscriptions-switcher.php
*
* #param array $cart_item_data Current cart item data.
* #param int $product_id ID of current product.
* #param int $variation_id ID of current product variation.
*
* #return array Updated cart item data.
*/
function kbhl_set_switch_details_in_cart( $cart_item_data, $product_id, $variation_id ) {
try {
$kbhl_current_subscription_data = kbhl_get_current_subscription_data();
if ( empty( $kbhl_current_subscription_data['id'] ) || empty( $kbhl_current_subscription_data['item'] ) ) {
return $cart_item_data;
}
$subscription = wcs_get_subscription( $kbhl_current_subscription_data['id'] );
// Requesting a switch for someone elses subscription.
if ( ! current_user_can( 'switch_shop_subscription', $subscription->get_id() ) ) {
wc_add_notice( __( 'You can not switch this subscription. It appears you do not own the subscription.', 'woocommerce-subscriptions' ), 'error' );
WC()->cart->empty_cart( true );
return array();
}
$item = wcs_get_order_item( absint( $kbhl_current_subscription_data['item'] ), $subscription );
// Else it's a valid switch.
$product = wc_get_product( $item['product_id'] );
$parent_products = WC_Subscriptions_Product::get_parent_ids( $product );
$child_products = array();
if ( ! empty( $parent_products ) ) {
foreach ( $parent_products as $parent_id ) {
$child_products = array_unique( array_merge( $child_products, wc_get_product( $parent_id )->get_children() ) );
}
}
if ( $product_id != $item['product_id'] && ! in_array( $item['product_id'], $child_products ) ) {
return $cart_item_data;
}
$next_payment_timestamp = $subscription->get_time( 'next_payment' );
// If there are no more payments due on the subscription, because we're in the last billing period, we need to use the subscription's expiration date, not next payment date.
if ( false == $next_payment_timestamp ) {
$next_payment_timestamp = $subscription->get_time( 'end' );
}
$cart_item_data['subscription_switch'] = array(
'subscription_id' => $subscription->get_id(),
'item_id' => absint( $kbhl_current_subscription_data['item'] ),
'next_payment_timestamp' => $next_payment_timestamp,
'upgraded_or_downgraded' => '',
);
return $cart_item_data;
} catch ( Exception $e ) {
wc_add_notice( __( 'There was an error locating the switch details.', 'woocommerce-subscriptions' ), 'error' );
WC()->cart->empty_cart( true );
return array();
}
}
add_filter( 'woocommerce_add_cart_item_data', 'kbhl_set_switch_details_in_cart', 11, 3 );
/**
* Gets subscription data for current user.
*
* #return array Subscription data, also stored to global variable $kbhl_global_current_subscription_data
*/
function kbhl_get_current_subscription_data() {
global $kbhl_adding_switch_to_cart, $kbhl_global_current_subscription_data;
if ( ! $kbhl_adding_switch_to_cart ) {
return array();
}
if ( ! empty( $kbhl_global_current_subscription_data ) ) {
return $kbhl_global_current_subscription_data;
}
$subscription_data = array();
$subs = wcs_get_users_subscriptions();
if ( ! empty( $subs ) ) {
foreach ( $subs as $sub ) {
$subscription_data['id'] = $sub->get_id();
foreach ( $sub->get_items() as $item_id => $item ) {
$subscription_data['item'] = $item_id;
break; // There should only be 1 order item.
}
break; // There should only be 1 subscription.
}
}
$kbhl_global_current_subscription_data = $subscription_data;
return $kbhl_global_current_subscription_data;
}
With this added you can add the switch to the cart as follows:
global $kbhl_adding_switch_to_cart; // If run inside a function.
WC()->cart->empty_cart( true );
$kbhl_adding_switch_to_cart = true;
WC()->cart->add_to_cart( 1907, 1, 1927 );
$kbhl_adding_switch_to_cart = false; // Reset after to get back to default validation.

how do I render a bulk edit checkbox on wp_list_table

I'm trying to use wp_list_table by making an extended class. I have two actions to run through on the bulk-update functionality provided. However I don't quite know how to write the proper case switch statement to set the resulting checkbox to apply for either array actions based on the action taken...(see I know what I need to do, but I don't quite know how to do it).
This is the smallest bit of relatable code I have to work with:
/**
* Render the bulk edit checkbox
*
* #param array $item
*
* #return string
*/
function column_cb( $item ) {
return sprintf(
'<input type="checkbox" name="bulk-reset[]" value="%s" />', $item['id']
);
}
/**
* Method for name column
*
* #param array $item an array of DB data
*
* #return string
*/
function column_name( $item ) {
$delete_nonce = wp_create_nonce( 'sp_delete_customer' );
$reset_nonce = wp_create_nonce( 'sp_reset_payouts' );
$title = '<strong>' . $item['name'] . '</strong>';
$actions = [
'delete' => sprintf( 'Delete', esc_attr( $_REQUEST['page'] ), 'delete', absint( $item['id'] ), $delete_nonce ),
'reset' => sprintf( 'Reset', esc_attr( $_REQUEST['page'] ), 'reset', absint( $item['id'] ), $reset_nonce )
];
return $title . $this->row_actions( $actions );
}
/**
* Returns an associative array containing the bulk action
*
* #return array
*/
public function get_bulk_actions() {
$actions = array(
'bulk-delete' => 'Delete',
'bulk-reset' => 'Reset'
);
return $actions;
}
Reviewing this one last time, I think I need a function that is called on the name property as an escaped php echo right? Then that function should return either bulk-reset[] or bulk-delete[] based on $_post['delete-*'] right???
Since mulling this over, I've tried to pen together the solution, but for whatever reason that action_type function I made does not get called:
/**
* Render the bulk edit checkbox
*
* #param array $item
*
* #return string
*/
function column_cb( $item ) {
global $action_type;
return sprintf(
'<input type="checkbox" name="'.$action_type.'" value="%s" />', $item['id']
);
}
/**
* Pick the Checkbox Value based on post Value
*
*
* #return string
*
*/
public function action_type() {
if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' )
|| ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' )
) {
$output = "bulk-delete[]";
} else {
$output = "bulk-reset[]";
}
return $output;
}
Edit 2: realizing that won't work because this sets the value post and I needed it set before page load...I guess this means I need to have the array name be generic and the post action handles how to deal with the data... maybe for simplicity sake I should set the edit action to the same bulk-delete data set as its ultimately the same set of checkboxes.
Edit 3: I can't do what I suggest at the end of edit2 because the portion of code to run the actions depends on the array name of the post and that array name is set on page load. I don't quite know what to do.
try this three function in " class My_Example_List_Table extends WP_List_Table " class and modification as per your requirement
function column_id($item){
$actions = array(
/* 'edit' => sprintf('Edit',$_REQUEST['page'],'edit',$item['ID']),*/
'delete' => sprintf('Delete',$_REQUEST['page'],'delete',$item['id']),
);
return sprintf('%1$s %2$s', $item['id'], $this->row_actions($actions) );
}
function get_bulk_actions() {
$actions = array(
'delete' => 'Delete'
);
return $actions;
}
function process_bulk_action(){
global $wpdb;
$table_name = $wpdb->prefix."tablename";
if ('delete' === $this->current_action()) {
$ids = isset($_REQUEST['id']) ? $_REQUEST['id'] : array();
if (is_array($ids)) $ids = implode(',', $ids);
if (!empty($ids)) {
$wpdb->query("DELETE FROM $table_name WHERE id IN($ids)");
}
}
}
Here's how I solved this:
Change (or not 😎 ) the checkbox array value to something generic. I chose myCheckboxes[]
this part is not shown in the answer above but the portion of the code executing the update or delete queries was the point where the data was set...I saw that changing the value there allows my checkbox column to be applied to all actions. (I'm planning to refactor the code further once I solve a related issue so this isn't the entire code snippet (ie. this is NOT a drop in copy/paste replacement, just context for how I solved this)
Here is the relevant missing bottom portion that you can see was changed to match the new checkbox value:
// // If the delete bulk action is triggered
if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' )
|| ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' )
) {
$delete_ids = esc_sql( $_POST['my_CheckBoxes'] );
// loop over the array of record IDs and delete them
foreach ( $delete_ids as $id ) {
self::delete_customer( $id );
}
wp_redirect( esc_url( add_query_arg() ) );
exit;
}

Use radio input instead of checkbox on Select Category - Wordpress

I'm currently developing a site for a Church and using wordpress. This Church is an international organization, and have several communities around Argentina and Uruguay. I created a custom post type Community so the users can add a new community or add/modify info related like location (maps) managers, activities. Those communities are related to the wordpress categories with
'taxonomies' => array( 'category' )
My concern is, how I can modify just for the Community Post form, to instead of having a checkbox widget to select the categories, another component to be use, at least change the checkbox to a radio because I want to remove the option to select more than 1 category per Community.
Regards
You can use this helper class, so the code will look like this
<?php
if ( !class_exists( 'WDS_Taxonomy_Radio' ) ) {
/**
* Removes and replaces the built-in taxonomy metabox with our radio-select metabox.
* #link http://codex.wordpress.org/Function_Reference/add_meta_box#Parameters
*/
class WDS_Taxonomy_Radio {
// Post types where metabox should be replaced (defaults to all post_types associated with taxonomy)
public $post_types = array();
// Taxonomy slug
public $slug = '';
// Taxonomy object
public $taxonomy = false;
// New metabox title. Defaults to Taxonomy name
public $metabox_title = '';
// Metabox priority. (vertical placement)
// 'high', 'core', 'default' or 'low'
public $priority = 'high';
// Metabox position. (column placement)
// 'normal', 'advanced', or 'side'
public $context = 'side';
// Set to true to hide "None" option & force a term selection
public $force_selection = false;
/**
* Initiates our metabox action
* #param string $tax_slug Taxonomy slug
* #param array $post_types post-types to display custom metabox
*/
public function __construct( $tax_slug, $post_types = array() ) {
$this->slug = $tax_slug;
$this->post_types = is_array( $post_types ) ? $post_types : array( $post_types );
add_action( 'add_meta_boxes', array( $this, 'add_radio_box' ) );
}
/**
* Removes and replaces the built-in taxonomy metabox with our own.
*/
public function add_radio_box() {
foreach ( $this->post_types() as $key => $cpt ) {
// remove default category type metabox
remove_meta_box( $this->slug .'div', $cpt, 'side' );
// remove default tag type metabox
remove_meta_box( 'tagsdiv-'.$this->slug, $cpt, 'side' );
// add our custom radio box
add_meta_box( $this->slug .'_radio', $this->metabox_title(), array( $this, 'radio_box' ), $cpt, $this->context, $this->priority );
}
}
/**
* Displays our taxonomy radio box metabox
*/
public function radio_box() {
// uses same noncename as default box so no save_post hook needed
wp_nonce_field( 'taxonomy_'. $this->slug, 'taxonomy_noncename' );
// get terms associated with this post
$names = wp_get_object_terms( get_the_ID(), $this->slug );
// get all terms in this taxonomy
$terms = (array) get_terms( $this->slug, 'hide_empty=0' );
// filter the ids out of the terms
$existing = ( !is_wp_error( $names ) && !empty( $names ) )
? (array) wp_list_pluck( $names, 'term_id' )
: array();
// Check if taxonomy is hierarchical
// Terms are saved differently between types
$h = $this->taxonomy()->hierarchical;
// default value
$default_val = $h ? 0 : '';
// input name
$name = $h ? 'tax_input['. $this->slug .'][]' : 'tax_input['. $this->slug .']';
echo '<div style="margin-bottom: 5px;">
<ul id="'. $this->slug .'_taxradiolist" data-wp-lists="list:'. $this->slug .'_tax" class="categorychecklist form-no-clear">';
// If 'category,' force a selection, or force_selection is true
if ( $this->slug != 'category' && !$this->force_selection ) {
// our radio for selecting none
echo '<li id="'. $this->slug .'_tax-0"><label><input value="'. $default_val .'" type="radio" name="'. $name .'" id="in-'. $this->slug .'_tax-0" ';
checked( empty( $existing ) );
echo '> '. sprintf( __( 'No %s', 'wds' ), $this->taxonomy()->labels->singular_name ) .'</label></li>';
}
// loop our terms and check if they're associated with this post
foreach ( $terms as $term ) {
$val = $h ? $term->term_id : $term->slug;
echo '<li id="'. $this->slug .'_tax-'. $term->term_id .'"><label><input value="'. $val .'" type="radio" name="'. $name .'" id="in-'. $this->slug .'_tax-'. $term->term_id .'" ';
// if so, they get "checked"
checked( !empty( $existing ) && in_array( $term->term_id, $existing ) );
echo '> '. $term->name .'</label></li>';
}
echo '</ul></div>';
}
/**
* Gets the taxonomy object from the slug
* #return object Taxonomy object
*/
public function taxonomy() {
$this->taxonomy = $this->taxonomy ? $this->taxonomy : get_taxonomy( $this->slug );
return $this->taxonomy;
}
/**
* Gets the taxonomy's associated post_types
* #return array Taxonomy's associated post_types
*/
public function post_types() {
$this->post_types = !empty( $this->post_types ) ? $this->post_types : $this->taxonomy()->object_type;
return $this->post_types;
}
/**
* Gets the metabox title from the taxonomy object's labels (or uses the passed in title)
* #return string Metabox title
*/
public function metabox_title() {
$this->metabox_title = !empty( $this->metabox_title ) ? $this->metabox_title : $this->taxonomy()->labels->name;
return $this->metabox_title;
}
}
$custom_tax_mb = new WDS_Taxonomy_Radio( 'category', array('community') );
// Update optional properties
// $custom_tax_mb->priority = 'low';
// $custom_tax_mb->context = 'normal';
// $custom_tax_mb->metabox_title = __( 'Custom Metabox Title', 'yourtheme' );
// $custom_tax_mb->force_selection = true;
}
Source: How to Replace WordPress Default Taxonomy Metabox - WebDevStudios

Categories