0

I have 2 functions, one which removes the original meta boxes for 3 custom taxonomies, and one which recreates them in the desired location. The problem is that with all 3 removed, NONE of the meta boxes correctly show the 'Choose from most used' javascript (they only jump the page to the (near) top). However, if I comment out just a single 1 of the remove_meta_box items (it can be any of them), then the other two work as expected.

This 'works':

function myahts_remove_metabox()
{
    remove_meta_box( 'tagsdiv-ahtscollectionmakes', 'ahtscollection', 'side' );
    remove_meta_box( 'tagsdiv-ahtscollectionyear', 'ahtscollection', 'side' );  
    /* remove_meta_box( 'tagsdiv-ahtscollectionos', 'ahtscollection', 'side' ); */
}
add_action( 'add_meta_boxes_ahtscollection' , 'myahts_remove_metabox', 1 );

function ahtscollection_metabox()
{
    add_meta_box( 'ahtscollectionmakes', __('Make', 'myahts'), 'post_tags_meta_box', 'ahtscollection', 'normal', 'high', array( 'taxonomy' => 'ahtscollectionmakes' ) );
    add_meta_box( 'ahtscollectionyear', __('Year Produced', 'myahts'), 'post_tags_meta_box', 'ahtscollection', 'normal', 'low', array( 'taxonomy' => 'ahtscollectionyear' ) );
    add_meta_box( 'ahtscollectionos', __('Operating System', 'myahts'), 'post_tags_meta_box', 'ahtscollection', 'normal', 'low', array( 'taxonomy' => 'ahtscollectionos' ) );
}
add_action( 'add_meta_boxes_ahtscollection', 'ahtscollection_metabox', 10 );

But this DOES NOT :

function myahts_remove_metabox()
{
    remove_meta_box( 'tagsdiv-ahtscollectionmakes', 'ahtscollection', 'side' );
    remove_meta_box( 'tagsdiv-ahtscollectionyear', 'ahtscollection', 'side' );  
    remove_meta_box( 'tagsdiv-ahtscollectionos', 'ahtscollection', 'side' );
}
add_action( 'add_meta_boxes_ahtscollection' , 'myahts_remove_metabox', 1 );

function ahtscollection_metabox()
{
    add_meta_box( 'ahtscollectionmakes', __('Make', 'myahts'), 'post_tags_meta_box', 'ahtscollection', 'normal', 'high', array( 'taxonomy' => 'ahtscollectionmakes' ) );
    add_meta_box( 'ahtscollectionyear', __('Year Produced', 'myahts'), 'post_tags_meta_box', 'ahtscollection', 'normal', 'low', array( 'taxonomy' => 'ahtscollectionyear' ) );
    add_meta_box( 'ahtscollectionos', __('Operating System', 'myahts'), 'post_tags_meta_box', 'ahtscollection', 'normal', 'low', array( 'taxonomy' => 'ahtscollectionos' ) );
}
add_action( 'add_meta_boxes_ahtscollection', 'ahtscollection_metabox', 10 );

The add_meta_box shows up correctly in both instances, it just doesn't function as expected in the 2nd example.

I can't find any errors relating to this, and I can't find any documentation about why it would cause a conflict when I add a 3rd item.

Is there something I'm missing? Any help is greatly appreciated.

Here is the line from load-scripts.php:

var tagBox,array_unique_noempty;!function(a){array_unique_noempty=function(b){var c=[];return a.each(b,function(b,d){d=a.trim(d),d&&-1===a.inArray(d,c)&&c.push(d)}),c},tagBox={clean:function(a){var b=window.tagsBoxL10n.tagDelimiter;return","!==b&&(a=a.replace(new RegExp(b,"g"),",")),a=a.replace(/\s*,\s*/g,",").replace(/,+/g,",").replace(/[,\s]+$/,"").replace(/^[,\s]+/,""),","!==b&&(a=a.replace(/,/g,b)),a},parseTags:function(b){var c=b.id,d=c.split("-check-num-")[1],e=a(b).closest(".tagsdiv"),f=e.find(".the-tags"),g=window.tagsBoxL10n.tagDelimiter,h=f.val().split(g),i=[];return delete h[d],a.each(h,function(b,c){c=a.trim(c),c&&i.push(c)}),f.val(this.clean(i.join(g))),this.quickClicks(e),!1},quickClicks:function(b){var c,d,e=a(".the-tags",b),f=a(".tagchecklist",b),g=a(b).attr("id");e.length&&(d=e.prop("disabled"),c=e.val().split(window.tagsBoxL10n.tagDelimiter),f.empty(),a.each(c,function(b,c){var e,h;c=a.trim(c),c&&(e=a("<span />").text(c),d||(h=a('<a id="'+g+"-check-num-"+b+'" class="ntdelbutton" tabindex="0">X</a>'),h.on("click keypress",function(b){("click"===b.type||13===b.keyCode)&&(13===b.keyCode&&a(this).closest(".tagsdiv").find("input.newtag").focus(),tagBox.parseTags(this))}),e.prepend("&nbsp;").prepend(h)),f.append(e))}))},flushTags:function(b,c,d){var e,f,g,h=a(".the-tags",b),i=a("input.newtag",b),j=window.tagsBoxL10n.tagDelimiter;return c=c||!1,g=c?a(c).text():i.val(),"undefined"==typeof g?!1:(e=h.val(),f=e?e+j+g:g,f=this.clean(f),f=array_unique_noempty(f.split(j)).join(j),h.val(f),this.quickClicks(b),c||i.val(""),"undefined"==typeof d&&i.focus(),!1)},get:function(b){var c=b.substr(b.indexOf("-")+1);a.post(ajaxurl,{action:"get-tagcloud",tax:c},function(d,e){0!==d&&"success"==e&&(d=a('<p id="tagcloud-'+c+'" class="the-tagcloud">'+d+"</p>"),a("a",d).click(function(){return tagBox.flushTags(a("#"+c),this),!1}),a("#"+b).after(d))})},init:function(){var b=this,c=a("div.ajaxtag");a(".tagsdiv").each(function(){tagBox.quickClicks(this)}),a(".tagadd",c).click(function(){b.flushTags(a(this).closest(".tagsdiv"))}),a("input.newtag",c).keyup(function(b){return 13==b.which?(tagBox.flushTags(a(this).closest(".tagsdiv")),!1):void 0}).keypress(function(a){return 13==a.which?(a.preventDefault(),!1):void 0}).each(function(){var b=a(this).closest("div.tagsdiv").attr("id");a(this).suggest(ajaxurl+"?action=ajax-tag-search&tax="+b,{delay:500,minchars:2,multiple:!0,multipleSep:window.tagsBoxL10n.tagDelimiter})}),a("#post").submit(function(){a("div.tagsdiv").each(function(){tagBox.flushTags(this,!1,1)})}),a(".tagcloud-link").click(function(){return tagBox.get(a(this).attr("id")),a(this).unbind().click(function(){return a(this).siblings(".the-tagcloud").toggle(),!1}),!1})}}}(jQuery);

My JS is not so strong, but I'm still not seeing why it wouldn't work.

4
  • Assume you have enabled debug mode, checked the log, etc? If there's no error thrown, the problem must be a logical one.
    – jdm2112
    Commented Mar 21, 2016 at 18:54
  • Debug mode did not provide any clues, and Chrome Dev Tools is not giving any JS errors. When I look at the onclick calls, they are 'missing' the ones for the link when they are broken, but I can't figure out why. This is from the callback function: <p class="hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->choose_from_most_used; ?></a></p> from WordPress Trac, but it doesn't give any indication on what might be going wrong.
    – Carly
    Commented Mar 21, 2016 at 18:58
  • In Dev Tools are you seeing the script is a loaded resource? Any dependencies missing? Sounds like a tough nut to crack.
    – jdm2112
    Commented Mar 21, 2016 at 19:24
  • Yes, it calls load-scripts.php, and does so successfully on other elements even when this link doesn't work.
    – Carly
    Commented Mar 21, 2016 at 19:28

1 Answer 1

0

instead of deleting and creating a new box, try this to just move the existing boxes

add_action("add_meta_boxes_post", function () {

    $listBoxId = [
        "tagsdiv-ahtscollectionmakes",
        "tagsdiv-ahtscollectionyear",
        "tagsdiv-ahtscollectionos",
    ];


    $screen = get_current_screen();
    $page = $screen->id;

    // loop on the "side" boxes
    foreach ($GLOBALS["wp_meta_boxes"][$page]["side"] as $priority => $tabPriority) {
        foreach ($tabPriority as $id => $box) {

            if (in_array($id, $listBoxId)) {
                // creating new box in "normal"
                $GLOBALS["wp_meta_boxes"][$page]["normal"][$priority][$id] = $box;
                // remove the former box
                unset($GLOBALS["wp_meta_boxes"][$page][$context][$priority][$id]);
            }

        }
    }


});
2
  • This doesn't work
    – Carly
    Commented Mar 23, 2016 at 18:22
  • I forget to remove some debug. I edit my answer you can try again
    – mmm
    Commented Mar 23, 2016 at 23:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.