Skip to content

Commit 664bc2b

Browse files
author
ThemeBoy
committedAug 24, 2014
Enable adding bulk posts of a post type tag 0.9.4
1 parent 56b80e1 commit 664bc2b

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed
 

‎ajax-dropdowns.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22
/**
33
* @package Ajax_Dropdowns
4-
* @version 0.9.3
4+
* @version 0.9.4
55
*/
66
/*
77
Plugin Name: Ajax Dropdowns
88
Plugin URI: http://wordpress.org/plugins/ajax-dropdowns/
99
Description: Display a group of posts that can be switched using dropdowns.
1010
Author: ThemeBoy
11-
Version: 0.9.3
11+
Version: 0.9.4
1212
Author URI: http://themeboy.com/
1313
*/
1414

@@ -18,7 +18,7 @@
1818
/**
1919
* Plugin setup
2020
*
21-
* @since 0.9.3
21+
* @since 0.9.4
2222
*/
2323
class Ajax_Dropdowns {
2424

@@ -51,7 +51,7 @@ public function __construct() {
5151
*/
5252
private function define_constants() {
5353
if ( !defined( 'AJAX_DROPDOWNS_VERSION' ) )
54-
define( 'AJAX_DROPDOWNS_VERSION', '0.9.3' );
54+
define( 'AJAX_DROPDOWNS_VERSION', '0.9.4' );
5555

5656
if ( !defined( 'AJAX_DROPDOWNS_URL' ) )
5757
define( 'AJAX_DROPDOWNS_URL', plugin_dir_url( __FILE__ ) );
@@ -195,8 +195,9 @@ public static function posts_meta_box( $post, $args ) {
195195
$posts = get_posts( array( 'post_type' => $post_type, 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC' ) );
196196
if ( $posts && is_array( $posts ) ):
197197
?>
198-
<optgroup label="<?php echo $object->labels->name; ?> (<?php echo sizeof( $posts ); ?>)">
198+
<optgroup label="<?php echo $object->labels->name; ?>">
199199
<?php
200+
printf( '<option value="%s" data-post-type="%s">%s</option>', 0, $object->labels->singular_name, sprintf( __( '&mdash; Add all %1$s (%2$s) &mdash;', 'ajaxd' ), $object->labels->name, sizeof( $posts ) ) );
200201
foreach ( $posts as $post ):
201202
printf( '<option value="%s" data-post-type="%s">%s</option>', $post->ID, $object->labels->singular_name, $post->post_title );
202203
endforeach;

‎assets/js/ajaxd-admin.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@ jQuery(document).ready(function($){
1818
$selected = $(this).find("option:selected");
1919
$table = $(".ajaxd-posts-table");
2020
$table.find(" > tbody tr.ajaxd-placeholder").hide();
21-
$table.find(" > tbody:last").append("<tr><td class=\"icon\"><span class=\"dashicons dashicons-menu post-state-format\"></span></td><td><input type=\"hidden\" name=\"ajax_post[]\" value=\""+post_id+"\">"+$selected.text()+"</td><td>"+$selected.data("post-type")+"</td><td><a href=\"#\" class=\"dashicons dashicons-no-alt ajaxd-delete\"></a></td></tr>");
21+
if ( $selected.val() == 0 ) {
22+
$selected.siblings("option:enabled").each(function() {
23+
$table.find(" > tbody:last").append("<tr><td class=\"icon\"><span class=\"dashicons dashicons-menu post-state-format\"></span></td><td><input type=\"hidden\" name=\"ajax_post[]\" value=\""+$(this).val()+"\">"+$(this).text()+"</td><td>"+$(this).data("post-type")+"</td><td><a href=\"#\" class=\"dashicons dashicons-no-alt ajaxd-delete\"></a></td></tr>");
24+
$(this).prop("disabled", true);
25+
});
26+
} else {
27+
$table.find(" > tbody:last").append("<tr><td class=\"icon\"><span class=\"dashicons dashicons-menu post-state-format\"></span></td><td><input type=\"hidden\" name=\"ajax_post[]\" value=\""+post_id+"\">"+$selected.text()+"</td><td>"+$selected.data("post-type")+"</td><td><a href=\"#\" class=\"dashicons dashicons-no-alt ajaxd-delete\"></a></td></tr>");
28+
$selected.siblings("[value=0]").each(function() {
29+
console.log($(this).siblings("option:enabled").length);
30+
$(this).prop("disabled", $(this).siblings("option:enabled").length <= 1);
31+
});
32+
}
2233
$selected.prop("disabled", true);
2334
$(this).val("").trigger("chosen:updated");
2435
});
@@ -29,7 +40,7 @@ jQuery(document).ready(function($){
2940
}).on("click", ".ajaxd-delete", function() {
3041
$row = $(this).closest("tr");
3142
$id = $row.find("input[name=\"ajax_post[]\"]").val();
32-
$(".ajaxd-posts option[value=\""+$id+"\"]").prop("disabled", false);
43+
$(".ajaxd-posts option[value=\""+$id+"\"]").prop("disabled", false).siblings("[value=0]").prop("disabled", false);
3344
$(".ajaxd-posts").trigger("chosen:updated");
3445
$row.remove();
3546
$table = $(".ajaxd-posts-table");

‎readme.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: ThemeBoy, brianmiyaji
33
Tags: ajax, dropdowns, option, posts, pages, custom post types, tabs, groups, redirect, inline
44
Requires at least: 3.0
55
Tested up to: 3.9
6-
Stable tag: 0.9.3
6+
Stable tag: 0.9.4
77
License: GPLv2 or later
88

99
Display a group of posts that can be switched using dropdowns.
@@ -62,6 +62,9 @@ Automatic updates should work like a charm; as always though, ensure you backup
6262

6363
== Changelog ==
6464

65+
= 0.9.4 =
66+
* Feature - Enable bulk adding all posts of a post type.
67+
6568
= 0.9.3 =
6669
* Tweak - Order posts by title in admin.
6770

0 commit comments

Comments
 (0)
Please sign in to comment.