Skip to content

Commit

Permalink
added taxonomies meta box
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipsesrl committed Apr 2, 2020
1 parent bb6afb7 commit 6068a14
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.udesly.com/
Tags: webflow to wordpress, editor, page builder, layout design, udesly, webflow
Requires at least: 5.0
Tested up to: 5.2.3
Stable tag: 2.0.2
Stable tag: 2.0.3
License: GPLv3 or later
License URI: https://www.udesly.com/terms-conditions-of-use/#udesly-wordpress-plugin
Requires PHP: 5.6.0
Expand Down Expand Up @@ -82,6 +82,9 @@ Absolutely! You can use the Udesly Adapter to create more than one website.

== Changelog ==

= 2.0.3 =
* Added metabox to choose taxonomies inside custom post type

= 2.0.2 =
* Added js support for multiple mini cart in same page

Expand Down
61 changes: 60 additions & 1 deletion includes/CPT/CustomPostTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ public static function init_all_custom_post_types()
),
'rewrite' => array(
'slug' => $slug
)
),
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
));
}
}
Expand All @@ -138,6 +141,8 @@ public static function taxonomy_rewrite_slug_field($args)
<?php
}



public static function rewrite_custom_taxonomies()
{
$cached_types = wp_cache_get('udesly_registered_types');
Expand Down Expand Up @@ -197,10 +202,64 @@ public static function add_registered_taxonomies_to_featured_image($post_types)
return $post_types;
}

public static function add_custom_metaboxes() {
$cached_taxonomies = wp_cache_get('udesly_registered_taxonomies');

foreach ($cached_taxonomies as $taxonomy => $post_type) {

$title = str_replace('_', ' ', $taxonomy);
$title = ucfirst($title);
add_meta_box( "taxonomy-dropdown-div--${taxonomy}", $title, [self::class, 'add_taxonomy_metabox'],$post_type ,'side','core', $taxonomy);
}
}

public static function add_taxonomy_metabox( $post, $args ) {
$title = $args['title'];
$taxonomy = $args['args'];
//The name of the form
$name = 'tax_input[' . $taxonomy . '][]';
$id = $taxonomy.'dropdown';
//Get current and popular terms
$postterms = get_the_terms( $post->ID, $taxonomy );
$current = ($postterms ? array_pop($postterms) : false);
$current = ($current ? $current->term_id : 0);
?>

<div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
<!-- Display taxonomy terms -->
<div id="<?php echo $taxonomy; ?>-all" class="tabs-panel">
<?php $args = array(
'show_option_all' => "Choose a $title",
'show_option_none' => '',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 0,
'hide_empty' => 0,
'child_of' => 0,
'exclude' => '',
'echo' => 1,
'selected' => 1,
'hierarchical' => 1,
'name' => $name,
'id' => $id,
'class' => 'form-no-clear',
'depth' => 0,
'tab_index' => 0,
'taxonomy' => $taxonomy,
'hide_if_empty' => true
); ?>

<?php wp_dropdown_categories($args); ?>
</div>
</div>
<?php
}

public static function admin_hooks()
{
add_action('admin_init', array(self::class, "rewrite_custom_taxonomies"));
add_filter('udesly_attach_featured_image_terms', array(self::class, "add_registered_taxonomies_to_featured_image"), 1, 1);
add_action( 'add_meta_boxes', array(self::class, "add_custom_metaboxes"));
}

public static function custom_taxonomy_archive($template)
Expand Down
23 changes: 23 additions & 0 deletions includes/misc/terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,27 @@ function udesly_get_main_category($id = null){
'name' => $term->name,
'url' => get_term_link($term),
);
}

function udesly_get_taxonomies($taxonomy, $limit = 0, $post_id = null)
{
if (!$post_id) {
global $post;
$post_id = $post->ID; // loop post
}

$taxonomy = $taxonomy != '' ? $taxonomy : 'cat';

$tax_ids = wp_get_post_terms($post_id, $taxonomy, array(
'number' => $limit
));

// Return categories
$taxonomies = array();

foreach ($tax_ids as $tax) {
$taxonomies[] = (object)array('name' => $tax->name, 'link' => get_term_link($tax));
}

return $taxonomies;
}
4 changes: 2 additions & 2 deletions udesly-adapter-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Udesly Adapter
* Plugin URI: https://www.udesly.com
* Description: This is a support plugin for Udesly (Webflow to WordPress converter) that allows you to enable additional features for your theme.
* Version: 2.0.2
* Version: 2.0.3
* Author: Udesly
* Author URI: https://www.udesly.com
* License: GPL-2.0+
Expand All @@ -29,7 +29,7 @@
// Constants
defined('UDESLY_ADAPTER_PLUGIN_DIRECTORY_PATH') ?: define('UDESLY_ADAPTER_PLUGIN_DIRECTORY_PATH', plugin_dir_path(__FILE__));
defined('UDESLY_ADAPTER_PLUGIN_DIRECTORY_URL') ?: define('UDESLY_ADAPTER_PLUGIN_DIRECTORY_URL', plugin_dir_url(__FILE__));
defined('UDESLY_ADAPTER_VERSION') ?: define('UDESLY_ADAPTER_VERSION', "2.0.2");
defined('UDESLY_ADAPTER_VERSION') ?: define('UDESLY_ADAPTER_VERSION', "2.0.3");
defined('UDESLY_TEXT_DOMAIN') ?: define('UDESLY_TEXT_DOMAIN', "udesly-adapter-plugin");

defined('UDESLY_ADAPTER_PLUGIN_MISC_PATH') ?: define('UDESLY_ADAPTER_PLUGIN_MISC_PATH', plugin_dir_path(__FILE__) . 'includes/misc/');
Expand Down

0 comments on commit 6068a14

Please sign in to comment.