WordPress.org

Forums

Add media "Insert into Post" not working (2 posts)

  1. craigcreid
    Member
    Posted 2 years ago #

    The new "add media" function is not working for me properly since updating to 3.5

    The window opens fine and I can select which image I want no problem. I can hit "insert into post" button and close the window, however the image never actually gets inserted into the post.

    I have tried removing all plugins. No help.

    I have tried switching the theme to the twentytwelve one, and it then works fine. So I figure it must be a problem within the functions file of my custom theme, however I have no idea how to fix it. I am using a customised version of "html5-reset-wordpress-theme".

    This is my functions file:

    <?php
    
            // Translations can be filed in the /languages/ directory
    
            load_theme_textdomain( 'html5reset', TEMPLATEPATH . '/languages' );
    
            $locale = get_locale();
    
            $locale_file = TEMPLATEPATH . "/languages/$locale.php";
    
            if ( is_readable($locale_file) )
    
                require_once($locale_file);
    
    	// Add RSS links to <head> section
    
    	automatic_feed_links();
    
    	// Load jQuery
    
    	if ( !function_exists(core_mods) ) {
    
    		function core_mods() {
    
    			if ( !is_admin() ) {
    
    				wp_deregister_script('jquery');
    
    				wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"), false);
    
    				wp_enqueue_script('jquery');
    
    			}
    
    		}
    
    		core_mods();
    
    	}
    
    	// Clean up the <head>
    
    	function removeHeadLinks() {
    
        	remove_action('wp_head', 'rsd_link');
    
        	remove_action('wp_head', 'wlwmanifest_link');
    
        }
    
        add_action('init', 'removeHeadLinks');
    
        remove_action('wp_head', 'wp_generator');
    
        if (function_exists('register_sidebar')) {
        	register_sidebar(array(
        		'name' => __('Sidebar Widgets','html5reset' ),
        		'id'   => 'sidebar-widgets',
        		'description'   => __( 'These are widgets for the sidebar.','html5reset' ),
    
        		'before_widget' => '<div id="side-widget"><div id="%1$s" class="widget %2$s">',
        		'after_widget'  => '</div></div>',
        		'before_title'  => '<h2>',
        		'after_title'   => '</h2>'
    
        	));
    
    register_sidebars( 1,
    	array(
    		'name' => 'widgetized-page-top',
    		'before_widget' => '<div id="%1$s" class="widget %2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="widgettitle">',
            'after_title' => '</h2>'
    	)
    );
    
        }
    
        add_theme_support( 'post-formats', array('aside', 'gallery', 'link', 'image', 'quote', 'status', 'audio', 'chat', 'video')); // Add 3.1 post format theme support.
    
    add_filter('mce_css', 'tuts_mcekit_editor_style');
    
    function tuts_mcekit_editor_style($url) {
    
        if ( !empty($url) )
    
            $url .= ',';
    
        // Retrieves the plugin directory URL
    
        // Change the path here if using different directories
    
        $url .= trailingslashit( plugin_dir_url(__FILE__) ) . '/editor-styles.css';
    
        return $url;
    
    }
    
    /**
    
     * Add "Styles" drop-down
    
     */
    
    add_filter( 'mce_buttons_2', 'tuts_mce_editor_buttons' );
    
    function tuts_mce_editor_buttons( $buttons ) {
    
        array_unshift( $buttons, 'styleselect' );
    
        return $buttons;
    
    }
    
    /**
    
     * Add styles/classes to the "Styles" drop-down
    
     */
    
    add_filter( 'tiny_mce_before_init', 'tuts_mce_before_init' );
    
    function tuts_mce_before_init( $settings ) {
    
        $style_formats = array(
    
            array(
    
                'title' => 'Download Link',
    
                'selector' => 'a',
    
                'classes' => 'download'
    
                ),
    
            array(
    
                'title' => 'Testimonial',
    
                'selector' => 'p',
    
                'classes' => 'testimonial',
    
            ),
    
            array(
    
                'title' => 'Warning Box',
    
                'block' => 'div',
    
                'classes' => 'warning box',
    
                'wrapper' => true
    
            ),
    
    	array(
    
                'title' => 'Pulled News',
    
                'block' => 'div',
    
                'classes' => 'pulled-news',
    
                'wrapper' => true
    
                ),
    
    array(
    
                'title' => 'Pulled Media',
    
                'block' => 'div',
    
                'classes' => 'pulled-media',
    
                'wrapper' => true
    
                ),
    
    array(
    
                'title' => 'Pulled Video',
    
                'block' => 'div',
    
                'classes' => 'pulled-video',
    
                'wrapper' => true
    
                ),
    
     array(
    
                'title' => 'Red Uppercase Text',
    
                'block' => 'div',
    
                'styles' => array(
    
                    'color' => '#ff0000',
    
                    'fontWeight' => 'bold',
    
                    'textTransform' => 'uppercase'
    
                ) 
    
            )
    
        );
    
        $settings['style_formats'] = json_encode( $style_formats );
    
        return $settings;
    
    }
    
    /* Learn TinyMCE style format options at http://www.tinymce.com/wiki.php/Configuration:formats */
    
    /*
    
     * Add custom stylesheet to the website front-end with hook 'wp_enqueue_scripts'
    
     */
    
    add_action('wp_enqueue_scripts', 'tuts_mcekit_editor_enqueue');
    
    /*
    
     * Enqueue stylesheet, if it exists.
    
     */
    
    function tuts_mcekit_editor_enqueue() {
    
      $StyleUrl = get_stylesheet_directory_uri().'editor-style.css'; // Customstyle.css is relative to the current file
    
      wp_enqueue_style( 'myCustomStyles', $StyleUrl );
    
    }
    
    function publish_later_on_feed($where) {
    
    	global $wpdb;
    
    	if ( is_feed() ) {
    
    		// timestamp in WP-format
    
    		$now = gmdate('Y-m-d H:i:s');
    
    		// value for wait; + device
    
    		$wait = '5'; // integer
    
    		// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
    
    		$device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
    
    		// add SQL-sytax to default $where
    
    		$where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
    
    	}
    
    	return $where;
    
    }
    
    add_filter('posts_where', 'publish_later_on_feed');
    
    /*
    
     * Fix caption margin
    
     */
    
    class fixImageMargins{
    
        public $xs = 0; //change this to change the amount of extra spacing
    
        public function __construct(){
    
            add_filter('img_caption_shortcode', array(&$this, 'fixme'), 10, 3);
    
        }
    
        public function fixme($x=null, $attr, $content){
    
            extract(shortcode_atts(array(
    
                    'id'    => '',
    
                    'align'    => '',
    
                    'width'    => '',
    
                    'caption' => ''
    
                ), $attr));
    
            if ( 1 > (int) $width || empty($caption) ) {
    
                return $content;
    
            }
    
            if ( $id ) $id = 'id="' . $id . '" ';
    
        return '<div ' . $id . 'class="wp-caption ' . $align . '" style="width: ' . ((int) $width + $this->xs) . 'px">'
    
        . $content . '<p class="wp-caption-text">' . $caption . '</p></div>';
    
        }
    
    }
    
    $fixImageMargins = new fixImageMargins();
    
    function excerpt($limit) {
          $excerpt = explode(' ', get_the_excerpt(), $limit);
          if (count($excerpt)>=$limit) {
            array_pop($excerpt);
            $excerpt = implode(" ",$excerpt).'...';
          } else {
            $excerpt = implode(" ",$excerpt);
          }
          $excerpt = preg_replace('<code>\[[^\]]*\]</code>','',$excerpt);
          return $excerpt;
        }
    
        function content($limit) {
          $content = explode(' ', get_the_content(), $limit);
          if (count($content)>=$limit) {
            array_pop($content);
            $content = implode(" ",$content).'...';
          } else {
            $content = implode(" ",$content);
          }
          $content = preg_replace('/\[.+\]/','', $content);
          $content = apply_filters('the_content', $content);
          $content = str_replace(']]>', ']]>', $content);
          return $content;
        }
    
    add_filter( 'wp_get_attachment_link' , 'add_lighbox_rel' );
    function add_lighbox_rel( $attachment_link ) {
    	if( strpos( $attachment_link , 'a href') != false && strpos( $attachment_link , 'img src') != false )
    		$attachment_link = str_replace( 'a href' , 'a rel="lightbox" href' , $attachment_link );
    	return $attachment_link;
    }
    
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 150, 150, true );
    
    function insert_img_rel_attrib( $html, $id, $caption, $title, $align, $url, $size, $alt )
    {
      /* Run your magic on the image $html to insert rel attrib */
      return $html;
    }
    add_filter( 'image_send_to_editor', 'insert_img_rel_attrib' );
    
    function catch_that_image() {
      global $post, $posts;
      $first_img = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_img = $matches [1] [0];
    
      if(empty($first_img)){ //Defines a default image
        $first_img = "/images/default.jpg";
      }
      return $first_img;
    }
    
    function register_my_menus() {
    register_nav_menus(
    array(
    'top-menu' => __( 'Top Menu' ),
    'footer-menu' => __( 'Footer Menu' )
    )
    );
    }
    add_action( 'init', 'register_my_menus' );
    
    ?>

    Any help would be much appreciated.

  2. craigcreid
    Member
    Posted 2 years ago #

    Found the bit of rogue code that was causing the image to not be inserted:

    function insert_img_rel_attrib( $html, $id, $caption, $title, $align, $url, $size, $alt )
    {
      /* Run your magic on the image $html to insert rel attrib */
      return $html;
    }
    add_filter( 'image_send_to_editor', 'insert_img_rel_attrib' );

Topic Closed

This topic has been closed to new replies.

About this Topic