WordPress.org

Ready to get started?Download WordPress

Forums

Adding a simple dropdown to MCE toolbar? (2 posts)

  1. hendridm
    Member
    Posted 1 year ago #

    I'm trying to add a dropdown menu to the MCE editors via a plugin. Unfortunately, it is showing up with some strange placement/alignment:
    http://i1270.photobucket.com/albums/jj612/hendridm/screenshot.png

    This seems like it should be simple, but I've been racking my brains trying to figure it out.

    I tried add_action('media_buttons' ...) and add_action('media_buttons_context' ...), but it always aligns strangely. I don't care where the button is, per se. I just want it visible on both the Visual and HTML editors.

    What am I doing wrong? Incidently, if I uncomment the /img/ua2.png button, it displays fine with correct alignment. Is there a better way to do this?

    add_action('media_buttons','upsell_add_sc_select', 11);
    function upsell_add_sc_select(){
        $include = array(1 => "Ad #1", 2 => "Ad #2"); //test array
        echo '<select id="upsell_add_select">&nbsp;<option>Upsell Ads</option>';
        foreach ($include as $key => $val){
        	$upsell_ad_id = explode("#", $key);
    		echo '<option value="[upsellad id='.$key.']">'.$val.'</option>';
    	}
    	echo '</select>';
    	//echo '<a href="#"><img src="/img/ua2.png" /></a>';
    }
    
    add_action('admin_head', 'button_js');
    function button_js() {
    	echo '<script type="text/javascript">
    	jQuery(document).ready(function(){
    	   jQuery("#upsell_add_select").change(function() {
    			  send_to_editor(jQuery("#upsell_add_select :selected").val());
            		  return false;
    		});
    	});
    	</script>';
    }
  2. hendridm
    Member
    Posted 1 year ago #

    For the record, this is what the upsell_add_sc_select() function is outputting, which looks fine to me:

    <select id="upsell_add_select"><option>Upsell Ads</option><option value="[upsellad id=1]">Ad #1</option><option value="[upsellad id=2]">Ad #2</option></select>

Topic Closed

This topic has been closed to new replies.

About this Topic