WordPress.org

Ready to get started?Download WordPress

Forums

Custom Field Template
Media Button opens in same window...won't save anything? (9 posts)

  1. illuminateddesigns
    Member
    Posted 3 years ago #

    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.

  2. illuminateddesigns
    Member
    Posted 3 years ago #

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

  3. illuminateddesigns
    Member
    Posted 3 years ago #

    bump

  4. leup
    Member
    Posted 3 years ago #

    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','http://view.jquery.com/trunk/plugins/metadata/jquery.metadata.js',array('jquery'),false,true);
  5. Helen Hou-Sandi
    WordPress Dev
    Posted 3 years ago #

    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?

  6. leup
    Member
    Posted 3 years ago #

    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','http://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.

  7. Helen Hou-Sandi
    WordPress Dev
    Posted 3 years ago #

    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.

  8. leup
    Member
    Posted 3 years ago #

    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' );
  9. cornhustlah
    Member
    Posted 3 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic