• This is odd and I can’t find anything online or on the forums that address this. When I use the Media Button in a Text Area, when I click to say, upload an image, the Media Upload screen opens in the same window. If I upload an image and try and insert it into a post, it simple takes me to a blank window.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter illuminateddesigns

    (@illuminateddesigns)

    I just realized that this only happens when I disable the ‘editor’ in my Custom Post Type. Anybody know a way around this?

    Thread Starter illuminateddesigns

    (@illuminateddesigns)

    bump

    Hi !

    What i did to workaround the need to enable ‘editor’ is adding these lines at the end of function ‘custom_field_template_admin_scripts‘ in file ‘custom-filed-template.php‘ (the plugin core file) :

    add_thickbox();
    wp_enqueue_script('media-upload');
    wp_enqueue_script('jquery-metadata','https://view.jquery.com/trunk/plugins/metadata/jquery.metadata.js',array('jquery'),false,true);
    Moderator Helen Hou-Sandi

    (@helen)

    Core Lead Developer and 4.0, 4.7, and 5.6 Release Lead

    I’m having the same problem with using the media button without editor enabled. I tried leup’s fix but it’s not working for me, though enabling the editor does allow me to insert media into a TinyMCE area. I put those lines after the endif; – is that correct?

    My function looks like this :

    function custom_field_template_admin_scripts() {
      if ( !defined('WP_PLUGIN_DIR') )
        $plugin_dir = str_replace( ABSPATH, '', dirname(__FILE__) );
      else
        $plugin_dir = dirname( plugin_basename(__FILE__) );
    
      wp_enqueue_script( 'jquery' );
      wp_enqueue_script( 'jquery-form' );
      wp_enqueue_script( 'date', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/date.js', array('jquery') );
      wp_enqueue_script( 'bgiframe', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.bgiframe.js', array('jquery') ) ;
      wp_enqueue_script( 'datePicker', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.datePicker.js', array('jquery') );
      wp_enqueue_script( 'textarearesizer', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.textarearesizer.js', array('jquery') );
      if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') || (isset($post) && $post->post_type=='page') ) :
        wp_enqueue_script( 'editor' );
    
    //////////////////////////////
    //PATCH leup
        add_thickbox();
        wp_enqueue_script('media-upload');
        wp_enqueue_script('jquery-metadata','https://view.jquery.com/trunk/plugins/metadata/jquery.metadata.js',array('jquery'),false,true);
    //////////////////////////////
    
      endif;
    }

    (before or after the last endif is mostly the same. If you put the 3 lines before the last endif allow us to load these scripts only if we are on a edit page…)

    With these lines, the media window pops up in a thickbox instead of opening in a new page.

    Well, it works for me.

    Moderator Helen Hou-Sandi

    (@helen)

    Core Lead Developer and 4.0, 4.7, and 5.6 Release Lead

    The media picker is showing up in the thickbox – it just doesn’t have the “insert into post” button unless you enable the editor, so attempting to insert anything into a custom field doesn’t work with editor disabled.

    In fact, i figured that my code isn’t enough. I had to add a hook for styles in custom_field_template :

    [...]
    add_action( 'admin_print_styles', array(&$this, 'custom_field_template_admin_styles') );
    [...]

    which calls :

    function custom_field_template_admin_styles() {
        if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') || (isset($post) && $post->post_type=='page') ) {
          wp_enqueue_style( 'thickbox' );
        }
      }

    and, in custom_field_template_admin_scripts i replaced :

    add_thickbox();

    by

    wp_enqueue_script( 'thickbox' );

    i need a fix for this as well, but am not willing to edit the plugin’s core files .. anyone got a way the plugin can be altered via the functions.php file or some other workaround to get the desired effect?

    for now i think im gonna just hide the editor via styles injected in the admin CSS:

    how-to-hide-an-admin-menu-in-wordpress

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Custom Field Template] Media Button opens in same window…won't save anything?’ is closed to new replies.