• Resolved th23

    (@th23)


    Indeed a very cool plugin – just something that should have been standard in WP functionality itself! Glad you took care of adding that functionality 🙂

    Two suggestions from my side playing a little bit around with it:

    1) Add option “Shuffle attached media” as (hover) link under post title in “Attached to” column in Media Library view

    2) Add option “Detach” as (hover) link under post title in “Attached to” column (and remove separate “Detach” column to save some space) in Media Library view

    Would be cool to hear, what others say – or even cooler if you could add that functionality!

Viewing 1 replies (of 1 total)
  • Thread Starter th23

    (@th23)

    I played around with the code a bit – and came up with the following solution to my requests.

    1) Open the “shuffle.php” file

    2) Replace

    function shuffle_columns($defaults) {
    	$defaults['shuffle'] = __('Detach');
    	return $defaults;
    }
    add_filter('manage_media_columns', 'shuffle_columns');
    
    function shuffle_custom_column($column_name, $id) {
        if ($column_name === 'shuffle') {
        	$parent = (int) get_post_field('post_parent', (int) $id);
    
    		if ($parent > 0) {
    			printf('<a href="admin.php?action=shuffle_detach&post_id=%d">%s</a>', $id, __('Detach'));
    		}
        }
    }
    add_action('manage_media_custom_column', 'shuffle_custom_column', 10, 2);

    3) Insert instead

    function th23_shuffle_media_columns($defaults) {
    	$defaults_new = array();
    	foreach ($defaults as $default_key => $default_value) {
    		if ($default_key == 'parent') {
    			$default_key = 'th23_attached_to';
    			$default_value = __('Attached to');
    		}
    		$defaults_new[$default_key] = $default_value;
    	}
    	$defaults = $defaults_new;
    	return $defaults;
    }
    add_filter('manage_media_columns', 'th23_shuffle_media_columns');
    
    function th23_shuffle_media_custom_column($column_name, $id) {
        if ($column_name == 'th23_attached_to') {
        	$parent_id = (int) get_post_field('post_parent', (int) $id);
    		if ( $parent_id > 0 ) {
    			//$parent = get_post($parent_id);
    			//print_r($parent);
    			//'<a href="post.php?post=' . $parent['ID'] . '&action=edit">' . $parent->post_title . '</a>';
    
    			echo '<strong><a href="' . get_edit_post_link($parent_id) . '">' . _draft_or_post_title($parent_id) . '</a></strong>, ' . get_the_time(__('Y/m/d'), $parent_id) . '<br />';
    			echo '<div class="row-actions"><a class="hide-if-no-js" onclick="findPosts.open(\'media[]\',\'' . $id . '\');return false;" href="#the-list">' . __('Re-Attach') . '</a> | <a href="admin.php?action=shuffle_detach&post_id=' . $id . '">' . __('Detach') . '</a> | ' . shuffle_do_link($parent_id, __('Shuffle Media')) . '</div>';
    		} else {
    			echo __('(Unattached)') . '<br />';
    			echo '<div class="row-actions"><a class="hide-if-no-js" onclick="findPosts.open(\'media[]\',\'' . $id . '\');return false;" href="#the-list">' . __('Attach') . '</a></div>';
    		}
    	}
    }
    add_action('manage_media_custom_column', 'th23_shuffle_media_custom_column', 10, 2);

    Alternatively modify the existing functions accordingly…

    That’s it – hope this helps someone 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘Shuffle Plugin – Suggestions’ is closed to new replies.