Co-Authors Plus - Version 1.2

Version Description

Download this release

Release Info

Developer batmoo
Plugin Icon wp plugin Co-Authors Plus
Version 1.2
Comparing to
See all releases

Code changes from version 1.1.5 to 1.2

Files changed (3) hide show
  1. admin.js +459 -383
  2. co-authors.php +132 -144
  3. readme.txt +34 -17
admin.js CHANGED
@@ -1,295 +1,293 @@
1
-
2
- (function(){
3
-
4
- var coauthors_table = null;
5
-
6
- var coauthorsTable = jQuery('#coauthors-table');
7
- //var editing = false;
8
-
9
- /*
10
- * Get an author's name from their ID
11
- * Iterates through the coauthors-select input box until finds the entry with the associated ID
12
- * @param int User ID
13
- *
14
- */
15
- function coauthors_get_author_name( authorID ) {
16
- var select = jQuery('#coauthors-select');
17
-
18
- if(authorID){
19
- //Find the provided author ID
20
- var name = "";
21
- select.find("option").each(function(i){
22
- if(this.value == authorID) {
23
- name = this.innerHTML;
24
- return;
25
- }
26
-
27
- });
28
- return name;
29
  }
30
- return false;
31
-
32
- }
33
-
34
- /*
35
- * Selects author (specified by authorID) within the appropriate select box (specified by selectID)
36
- * @param int
37
- * @param string ID of the select box
38
- */
39
- function coauthors_select_author( authorID, selectID ) {
40
- if(!selectID) selectID = '#coauthors-select';
41
-
42
- var select = jQuery(selectID);
43
-
44
- if(authorID){
45
- //Find the provided author ID
46
- select.find("option").each(function(i){
47
- if(this.value == authorID) {
48
- jQuery(this).attr('selected','true')
49
- return false;
50
- }
51
- });
 
52
  }
53
-
54
- }
55
-
56
- /*
57
- * Unselects author
58
- * @param string Name of the Author to remove
59
- */
60
- function coauthors_remove_author( authorName ) {
61
- var select = jQuery('#coauthors-select');
62
- if(authorName){
63
- //Find the provided author ID
64
- select.find("option").each(function(i){
65
- if(this.innerHTML == authorName) {
66
- jQuery(this).removeAttr('selected');
67
- return true;
68
- }
69
- });
70
  }
71
- }
72
-
73
- /*
74
- * Old function not needed; though may be useful for duplicate validation
75
- * @param event
76
- */
77
- var coauthors_select_onchange = function(event){
78
-
79
- };
80
-
81
- /*
82
- * Click handler for the delete button
83
- * @param event
84
- */
85
- var coauthors_delete_onclick = function(event){
86
-
87
- if(confirm('Are you sure you want to delete this author?')) {
88
- var tr = jQuery(this).parent().parent();
89
- var name = tr.find('span.author-tag').text();
90
- coauthors_remove_author(name);
91
- tr.remove();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
- return true;
 
 
 
 
 
 
94
  }
95
- return false;
96
- };
97
-
98
- /*
99
- * Adds a delete button next to an author
100
- * @param object The row to which the new author should be added
101
- */
102
- function coauthors_insert_author_edit_cells(tr){
103
-
104
- var deleteBtn = jQuery('<span></span>')
105
- .addClass('delete-coauthor')
106
- .text('Delete')
107
- .bind('click', coauthors_delete_onclick)
108
- ;
109
 
110
- var td = jQuery('<td></td>')
111
- .addClass('delete')
112
- ;
113
- td.append(deleteBtn);
114
- jQuery(tr).append(td);
115
- return tr;
116
-
117
- }
118
-
119
- /*
120
- * Save coauthor
121
- * @param int Author ID
122
- * @param string Author Name
123
- * @param object The autosuggest input box
124
- */
125
- function coauthors_save_coauthor(authorID, authorName, co) {
126
-
127
- coauthors_remove_author(co.next().text());
128
-
129
- // get sibling <span>, update, and hide
130
- co.next().html(authorName)
131
- .show()
132
- ;
133
-
134
- // select new author
135
- if(co.attr('name')=='coauthors-main') {
136
- coauthors_select_author( authorID, '#post_author_override' );
137
- } else {
138
- coauthors_select_author( authorID )
139
- }
140
 
141
- // editing = false;
142
- }
143
-
144
-
145
- /*
146
- * Add coauthor
147
- * @param int Author ID
148
- * @param string Author Name
149
- * @param object The autosuggest input box
150
- * @param boolean Initial set up or not?
151
- */
152
- function coauthors_add_coauthor(authorID, authorName, co, init){
153
- var selectedIndex = -1;
154
-
155
- // Check if editing
156
- if(co && co.next().attr('class')=='author-tag') {
157
- coauthors_save_coauthor(authorID, authorName, co)
158
-
159
- } else {
160
- // Not editing, so we create a new author entry
161
 
162
- // Create autosuggest box and text tag
163
- if(!co) var co = coauthors_create_autosuggest(authorName)
164
- var tag = coauthors_create_author_tag(authorName);
 
 
 
 
 
 
165
 
166
- coauthors_add_to_table(co, tag);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
- // Add new author to <select>
169
- coauthors_select_author( authorID )
170
 
171
- if(!init) {
172
- // Create new author-suggest and append it to a new row
173
- var newCO = coauthors_create_autosuggest('', false);
174
- coauthors_add_to_table(newCO);
 
 
 
 
175
  }
 
 
 
 
 
 
 
 
 
 
176
  }
177
 
178
- co.bind('blur', coauthors_stop_editing);
179
-
180
- // Set the value for the auto-suggest box to the Author's name and hide it
181
- co.val(authorName)
182
- .hide()
183
- .unbind('focus')
184
- ;
185
-
186
- return true;
187
- }
188
-
189
-
190
- /*
191
- * Add the autosuggest box and text tag to the Co-Authors table
192
- * @param object Autosuggest input box
193
- * @param object Text tag
194
- * @param
195
- */
196
- function coauthors_add_to_table( co, tag, del ) {
197
- if(co) {
198
- var td = jQuery('<td></td>');
199
- td.className = 'suggest';
200
- td.append(co);
201
- td.append(tag);
202
- var tr = jQuery('<tr></tr>');
203
- tr.append(td);
204
-
205
- //Add buttons to row
206
- if(tag && !del) coauthors_insert_author_edit_cells(tr);
207
-
208
- jQuery('#coauthors-table').append(tr);
209
  }
210
- }
211
-
212
- /*
213
- * Creates autosuggest input box
214
- * @param string [optional] Name of the author
215
- * @param string [optional] Name to be applied to the input box
216
- */
217
- function coauthors_create_autosuggest(authorName, inputName) {
218
-
219
- if(!inputName) inputName = 'coauthors2[]';
220
-
221
- var co = jQuery('<input/>')
222
- .attr({
223
- 'class': 'coauthor-suggest',
224
- 'name': inputName
225
- })
226
- .appendTo(div)
227
-
228
- .suggest(coauthor_ajax_suggest_link,{
229
- onSelect:
230
- function() {
231
-
232
- var vals = this.value.split("|");
233
-
234
- var id = jQuery.trim(vals[0]);
235
- var name = jQuery.trim(vals[1]);
236
-
237
- if(id=="New") {
238
- alert('Eventually, this will allow you to add a new author right from here. But it\'s not ready yet. *sigh*');
239
- } else {
240
- coauthors_add_coauthor(id, name, co);
241
- }
242
- }
243
- })
244
- .keydown(function(e) {
245
- if(e.keyCode == 13) {return false;}
246
-
247
- })
248
- ;
249
-
250
- if(authorName)
251
- co.attr('value', authorName);
252
- else
253
- co.attr('value', 'Search for an author')
254
- .focus(function(){co.val('')})
255
- .blur(function(){co.val('Search for an author')})
256
- ;
257
 
258
- return co;
259
-
260
- }
261
-
262
- /*
263
- * Blur handler for autosuggest input box
264
- * @param event
265
- */
266
- function coauthors_stop_editing(event) {
267
-
268
- var co = jQuery(event.target);
269
- var tag = jQuery(co.next());
270
-
271
- co.attr('value',tag.text());
272
-
273
- co.hide();
274
- tag.show();
275
-
276
- // editing = false;
277
- }
278
-
279
- /*
280
- * Creates the text tag for an author
281
- * @param string Name of the author
282
- */
283
- function coauthors_create_author_tag (name) {
284
- var tag = jQuery('<span></span>')
285
- .html(name)
286
- .attr('title', 'Click to edit')
287
- .addClass('author-tag')
288
- // Add Click event to edit
289
- .click(function(){
290
- //if(!editing) {
291
- //editing = true;
292
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  var co = tag.prev();
294
 
295
  tag.hide();
@@ -297,117 +295,195 @@ function coauthors_create_author_tag (name) {
297
  .focus()
298
  ;
299
 
300
- co.previousAuthor = tag.text();
301
- //}
302
-
303
- });
304
-
305
- return tag;
306
- }
307
-
308
-
309
- if(document.getElementById('post_author_override')){
310
-
311
- // Check if user has permissions to change post authors; if not, remove controls and end
312
- if(!coauthors_can_edit_others_posts){
313
- jQuery('#authordiv, #pageauthordiv').remove();
314
- return;
315
- }
316
-
317
- // Changes the meta_box title from "Post Author" to "Post Author(s)"
318
- var h3 = jQuery('#authordiv :header, #pageauthordiv :header').html(
319
- /page[^\/]+$/.test(window.location.href) ?
320
- coauthors_dbx_page_title
321
- :
322
- coauthors_dbx_post_title
323
- );
324
-
325
- // Add the controls to add co-authors
326
- var div = jQuery('#authordiv div, #pageauthordiv div').filter(function(){
327
- if(jQuery(this).is('.inside') || jQuery(this).is('.dbx-content'))
328
- return true;
329
- return false;
330
- })[0];
331
 
332
- if(div){
333
-
334
- // Create the co-authors table
335
- var table = jQuery('<table></table>')
336
- .attr('id', 'coauthors-table')
337
- ;
338
- var coauthors_table = jQuery('<tbody></tbody>')
339
- .appendTo(table)
340
- ;
341
- var tr = jQuery('<tr></tr>');
342
- var td = jQuery('<td></td>')
343
- .addClass('select')
344
- ;
345
-
346
- var select = jQuery('#post_author_override')[0];
347
-
348
- td.append(select);
349
- tr.append(td);
350
- coauthors_table.append(tr);
351
- jQuery(div).append(table);
352
-
353
- // Create input and span for first entry
354
- var nameFirst = select[select.selectedIndex].innerHTML;
355
- var coFirst = coauthors_create_autosuggest(nameFirst, 'coauthors-main')
356
- coFirst.hide();
357
- var tagFirst = coauthors_create_author_tag(nameFirst);
358
- jQuery(select).after(tagFirst)
359
- .after(coFirst)
360
- ;
361
- // Add blur event to suggest box
362
- coFirst.bind('blur', coauthors_stop_editing);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
 
364
- // Create coauthors select box by cloning it from the drop-down
365
- var coauthors = jQuery('#post_author_override').clone(true)
366
- .attr('id', 'coauthors-select')
367
- .attr('name', 'coauthors[]')
368
- .attr({'multiple':'multiple', 'size':5})
369
- .attr('style','height:10em')
370
- .attr('selectedIndex', '-1')
371
- ;
372
- coauthors.insertAfter('#post_author_override');
 
 
 
 
373
 
374
- // Hide both select boxes
375
- jQuery('#post_author_override').hide();
376
- coauthors.hide();
 
 
 
377
 
378
- var help = jQuery('<p></p>').text('Click on an author to edit. Click on "Delete" to remove them.');
379
- jQuery('#authordiv .inside').append(help);
380
-
381
- var presenceInput;
382
- try {
383
- //For MSIE
384
- presenceInput = document.createElement('<input name="coauthors_plugin_is_active" type="hidden" value="1" />');
385
- if(!presenceInput || presenceInput.name != 'coauthors_plugin_is_active')
386
- throw Error();
387
- } catch(e){
388
- presenceInput = document.createElement('input');
389
- presenceInput.name = "coauthors_plugin_is_active";
390
- presenceInput.value = 1;
391
- presenceInput.type = 'hidden';
392
- }
393
- div.appendChild(presenceInput);
394
- }
 
 
 
395
 
396
- // Select authors already added to the post
397
- var addedAlready = {};
398
- jQuery('#the-list tr').each(function(){
399
- var userID = jQuery(this).find('textarea').val();
400
- if(jQuery(this).find("input[@value='_coauthor']").length && !addedAlready[userID]){
401
- var authorName = coauthors_get_author_name(userID);
402
- if(authorName) coauthors_add_coauthor(userID, authorName, undefined, true );
403
- addedAlready[userID] = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  }
405
- });
406
-
407
- // Create new author-suggest and append it to a new row
408
- var newCO = coauthors_create_autosuggest('', false);
409
- coauthors_add_to_table(newCO);
410
-
411
- }
412
-
413
- })();
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //(function(){
2
+ jQuery(document).ready(function () {
3
+
4
+ /*
5
+ * Get an author's name from their ID
6
+ * Iterates through the coauthors-select input box until finds the entry with the associated ID
7
+ * @param int User ID
8
+ *
9
+ */
10
+ function coauthors_get_author_name( authorID ) {
11
+ var select = jQuery('#coauthors-select');
12
+
13
+ if(authorID){
14
+ //Find the provided author ID
15
+ var name = "";
16
+ select.find("option").each(function(i){
17
+ if(this.value == authorID) {
18
+ name = this.innerHTML;
19
+ return;
20
+ }
21
+
22
+ });
23
+ return name;
24
+ }
25
+ return false;
26
+
 
 
27
  }
28
+
29
+ /*
30
+ * Selects author (specified by authorID) within the appropriate select box (specified by selectID)
31
+ * @param int
32
+ * @param string ID of the select box
33
+ */
34
+ function coauthors_select_author( authorID, selectID ) {
35
+ if(!selectID) selectID = '#coauthors-select';
36
+
37
+ var select = jQuery(selectID);
38
+
39
+ if(authorID){
40
+ //Find the provided author ID
41
+ select.find("option").each(function(i){
42
+ if(this.value == authorID) {
43
+ jQuery(this).attr('selected','true');
44
+ // @TODO: Fix to retain order of selected coauthors
45
+ jQuery(this).appendTo(select);
46
+ return false;
47
+ }
48
+ });
49
+ }
50
+
51
  }
52
+
53
+ /*
54
+ * Unselects author
55
+ * @param string Name of the Author to remove
56
+ */
57
+ function coauthors_remove_author( authorName ) {
58
+ var select = jQuery('#coauthors-select');
59
+ if(authorName){
60
+ //Find the provided author ID
61
+ select.find("option").each(function(i){
62
+ if(this.innerHTML == authorName) {
63
+ jQuery(this).removeAttr('selected');
64
+ return true;
65
+ }
66
+ });
67
+ }
 
68
  }
69
+
70
+ /*
71
+ * Old function not needed; though may be useful for duplicate validation
72
+ * @param event
73
+ */
74
+ var coauthors_select_onchange = function(event){
75
+
76
+ };
77
+
78
+ /*
79
+ * Click handler for the delete button
80
+ * @param event
81
+ */
82
+ var coauthors_delete_onclick = function(event){
83
+
84
+ // @TODO: Make i10n friendly
85
+ if(confirm('Are you sure you want to delete this author?')) {
86
+ var tr = jQuery(this).parent().parent();
87
+ var name = tr.find('span.author-tag').text();
88
+ coauthors_remove_author(name);
89
+ tr.remove();
90
+
91
+ return true;
92
+ }
93
+ return false;
94
+ };
95
+
96
+ /*
97
+ * Adds a delete button next to an author
98
+ * @param object The row to which the new author should be added
99
+ */
100
+ function coauthors_insert_author_edit_cells(tr){
101
+
102
+ // @TODO: Make i10n friendly
103
+ var deleteBtn = jQuery('<span></span>')
104
+ .addClass('delete-coauthor')
105
+ .text('Delete')
106
+ .bind('click', coauthors_delete_onclick)
107
+ ;
108
 
109
+ var td = jQuery('<td></td>')
110
+ .addClass('delete')
111
+ ;
112
+ td.append(deleteBtn);
113
+ jQuery(tr).append(td);
114
+ return tr;
115
+
116
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
+ /*
119
+ * Save coauthor
120
+ * @param int Author ID
121
+ * @param string Author Name
122
+ * @param object The autosuggest input box
123
+ */
124
+ function coauthors_save_coauthor(authorID, authorName, co) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
+ coauthors_remove_author(co.next().text());
127
+
128
+ // get sibling <span>, update, and hide
129
+ co.next().html(authorName)
130
+ .show()
131
+ ;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
+ // select new author
134
+ if(co.attr('name')=='coauthors-main') {
135
+ coauthors_select_author( authorID, '#post_author_override' );
136
+ } else {
137
+ coauthors_select_author( authorID )
138
+ }
139
+
140
+ }
141
+
142
 
143
+ /*
144
+ * Add coauthor
145
+ * @param int Author ID
146
+ * @param string Author Name
147
+ * @param object The autosuggest input box
148
+ * @param boolean Initial set up or not?
149
+ */
150
+ function coauthors_add_coauthor(authorID, authorName, co, init){
151
+ var selectedIndex = -1;
152
+
153
+ // Check if editing
154
+ if(co && co.next().attr('class')=='author-tag') {
155
+ coauthors_save_coauthor(authorID, authorName, co);
156
+
157
+ } else {
158
+ // Not editing, so we create a new author entry
159
+
160
+ // Create autosuggest box and text tag
161
+ if(!co) var co = coauthors_create_autosuggest(authorName)
162
+ var tag = coauthors_create_author_tag(authorName);
163
 
164
+ coauthors_add_to_table(co, tag);
 
165
 
166
+ // Add new author to <select>
167
+ coauthors_select_author( authorID )
168
+
169
+ if(!init) {
170
+ // Create new author-suggest and append it to a new row
171
+ var newCO = coauthors_create_autosuggest('', false);
172
+ coauthors_add_to_table(newCO);
173
+ }
174
  }
175
+
176
+ co.bind('blur', coauthors_stop_editing);
177
+
178
+ // Set the value for the auto-suggest box to the Author's name and hide it
179
+ co.val(authorName)
180
+ .hide()
181
+ .unbind('focus')
182
+ ;
183
+
184
+ return true;
185
  }
186
 
187
+
188
+ /*
189
+ * Add the autosuggest box and text tag to the Co-Authors table
190
+ * @param object Autosuggest input box
191
+ * @param object Text tag
192
+ * @param
193
+ */
194
+ function coauthors_add_to_table( co, tag, del ) {
195
+ if(co) {
196
+ var td = jQuery('<td></td>');
197
+ td.className = 'suggest';
198
+ td.append(co);
199
+ td.append(tag);
200
+ var tr = jQuery('<tr></tr>');
201
+ tr.append(td);
202
+
203
+ //Add buttons to row
204
+ if(tag && !del) coauthors_insert_author_edit_cells(tr);
205
+
206
+ jQuery('#coauthors-table').append(tr);
207
+ }
 
 
 
 
 
 
 
 
 
 
208
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
 
210
+ /*
211
+ * Creates autosuggest input box
212
+ * @param string [optional] Name of the author
213
+ * @param string [optional] Name to be applied to the input box
214
+ */
215
+ function coauthors_create_autosuggest(authorName, inputName) {
216
+
217
+ if(!inputName) inputName = 'coauthors2[]';
218
+
219
+ var co = jQuery('<input/>')
220
+ .attr({
221
+ 'class': 'coauthor-suggest',
222
+ 'name': inputName
223
+ })
224
+ .appendTo(div)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
 
226
+ .suggest(coauthor_ajax_suggest_link,{
227
+ onSelect:
228
+ function() {
229
+
230
+ var vals = this.value.split("|");
231
+
232
+ var id = jQuery.trim(vals[0]);
233
+ var name = jQuery.trim(vals[1]);
234
+
235
+ if(id=="New") {
236
+ //alert('Eventually, this will allow you to add a new author right from here. But it\'s not ready yet. *sigh*');
237
+ coauthors_new_author_display(name);
238
+ } else {
239
+ coauthors_add_coauthor(id, name, co);
240
+ }
241
+ }
242
+ })
243
+ .keydown(function(e) {
244
+ if(e.keyCode == 13) {return false;}
245
+
246
+ })
247
+ ;
248
+
249
+ if(authorName)
250
+ co.attr('value', authorName);
251
+ else
252
+ co.attr('value', 'Search for an author')
253
+ .focus(function(){co.val('')})
254
+ .blur(function(){co.val('Search for an author')})
255
+ ;
256
+
257
+ return co;
258
+
259
+ }
260
+
261
+ /*
262
+ * Blur handler for autosuggest input box
263
+ * @param event
264
+ */
265
+ function coauthors_stop_editing(event) {
266
+
267
+ var co = jQuery(event.target);
268
+ var tag = jQuery(co.next());
269
+
270
+ co.attr('value',tag.text());
271
+
272
+ co.hide();
273
+ tag.show();
274
+
275
+ // editing = false;
276
+ }
277
+
278
+ /*
279
+ * Creates the text tag for an author
280
+ * @param string Name of the author
281
+ */
282
+ function coauthors_create_author_tag (name) {
283
+
284
+ // @TODO: need to make i10n friendly
285
+ var tag = jQuery('<span></span>')
286
+ .html(name)
287
+ .attr('title', 'Click to edit')
288
+ .addClass('author-tag')
289
+ // Add Click event to edit
290
+ .click(function(){
291
  var co = tag.prev();
292
 
293
  tag.hide();
295
  .focus()
296
  ;
297
 
298
+ co.previousAuthor = tag.text();
299
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
 
301
+ return tag;
302
+ }
303
+
304
+
305
+ /*
306
+ * Display form for creating new author
307
+ * @param string Name of the author
308
+ */
309
+ function coauthors_new_author_display (name) {
310
+
311
+ tb_show('Add New User', '?inlineId=awesome&modal=true');
312
+
313
+ }
314
+
315
+ /*
316
+ * Creates display for adding new author
317
+ * @param string Name of the author
318
+ */
319
+ function coauthors_new_author_create_display ( ) {
320
+
321
+ var author_window = jQuery('<div></div>')
322
+ .appendTo(jQuery('body'))
323
+ .attr('id','new-author-window')
324
+ .addClass('wrap')
325
+ .append(
326
+ jQuery('<div></div>')
327
+ .addClass('icon32')
328
+ .attr('id','icon-users')
329
+ )
330
+ .append(
331
+ jQuery('<h2></h2>')
332
+ .text('Add new author')
333
+ .attr('id', 'add-new-user')
334
+
335
+ )
336
+ .append(
337
+ jQuery('<div/>')
338
+ .attr('id', 'createauthor-ajax-response')
339
+ )
340
+ ;
341
+
342
+ var author_form = jQuery('<form />')
343
+ .appendTo(author_window)
344
+ .attr({
345
+ id: 'createauthor',
346
+ name: 'createauthor',
347
+ method: 'post',
348
+ action: ''
349
+ })
350
+ ;
351
+
352
+
353
+
354
+ var create_text_field = function( name, id, label) {
355
+
356
+ var field = jQuery('<input />')
357
+ .attr({
358
+ type:'text',
359
+ name: name,
360
+ id: id,
361
+ })
362
+ var label = jQuery('<label></label>')
363
+ .attr('for',name)
364
+ .text(label)
365
+
366
+ //return {field, label};
367
+
368
+ };
369
+
370
+ create_field('user_login', 'user_login', 'User Name');
371
+ create_field('first_name', 'first_name', 'First Name');
372
+
373
+ //last_name
374
+ //email
375
+ //pass1
376
+ //role
377
+ }
378
+
379
+
380
+
381
+ if(jQuery('#post_author_override')){
382
 
383
+ // Check if user has permissions to change post authors; if not, remove controls and end
384
+ if(!coauthors_can_edit_others_posts){
385
+ jQuery('#authordiv, #pageauthordiv').remove();
386
+ return;
387
+ }
388
+
389
+ // Changes the meta_box title from "Post Author" to "Post Author(s)"
390
+ var h3 = jQuery('#authordiv :header, #pageauthordiv :header').html(
391
+ /page[^\/]+$/.test(window.location.href) ?
392
+ coauthors_dbx_page_title
393
+ :
394
+ coauthors_dbx_post_title
395
+ );
396
 
397
+ // Add the controls to add co-authors
398
+ var div = jQuery('#authordiv div, #pageauthordiv div').filter(function(){
399
+ if(jQuery(this).is('.inside') || jQuery(this).is('.dbx-content'))
400
+ return true;
401
+ return false;
402
+ })[0];
403
 
404
+ if(div){
405
+
406
+ // Create the co-authors table
407
+ var table = jQuery('<table></table>')
408
+ .attr('id', 'coauthors-table')
409
+ ;
410
+ var coauthors_table = jQuery('<tbody></tbody>')
411
+ .appendTo(table)
412
+ ;
413
+ var tr = jQuery('<tr></tr>');
414
+ var td = jQuery('<td></td>')
415
+ .addClass('select')
416
+ ;
417
+
418
+ var select = jQuery('#post_author_override')[0];
419
+
420
+ td.append(select);
421
+ tr.append(td);
422
+ coauthors_table.append(tr);
423
+ jQuery(div).append(table);
424
 
425
+ // Create input and span for first entry
426
+ var nameFirst = select[select.selectedIndex].innerHTML;
427
+ var coFirst = coauthors_create_autosuggest(nameFirst, 'coauthors-main')
428
+ coFirst.hide();
429
+ var tagFirst = coauthors_create_author_tag(nameFirst);
430
+ jQuery(select).after(tagFirst)
431
+ .after(coFirst)
432
+ ;
433
+ // Add blur event to suggest box
434
+ coFirst.bind('blur', coauthors_stop_editing);
435
+
436
+ // Create coauthors select box by cloning it from the drop-down
437
+ var coauthors = jQuery('#post_author_override').clone(true)
438
+ .attr('id', 'coauthors-select')
439
+ .attr('name', 'coauthors[]')
440
+ .attr({'multiple':'multiple', 'size':5})
441
+ .attr('style','height:10em')
442
+ .attr('selectedIndex', '-1')
443
+ ;
444
+ coauthors.insertAfter('#post_author_override');
445
+
446
+ // Hide both select boxes
447
+ jQuery('#post_author_override').hide();
448
+ coauthors.hide();
449
+
450
+ // @TODO: need to make i10n friendly
451
+ var help = jQuery('<p></p>').text('Click on an author to edit. Click on "Delete" to remove them.');
452
+ jQuery('#authordiv .inside').append(help);
453
+
454
+ var presenceInput;
455
+ try {
456
+ //For MSIE
457
+ presenceInput = document.createElement('<input name="coauthors_plugin_is_active" type="hidden" value="1" />');
458
+ if(!presenceInput || presenceInput.name != 'coauthors_plugin_is_active')
459
+ throw Error();
460
+ } catch(e){
461
+ presenceInput = document.createElement('input');
462
+ presenceInput.name = "coauthors_plugin_is_active";
463
+ presenceInput.value = 1;
464
+ presenceInput.type = 'hidden';
465
+ }
466
+ div.appendChild(presenceInput);
467
+
468
  }
469
+
470
+ // Select authors already added to the post
471
+ var addedAlready = [];
472
+ jQuery('#the-list tr').each(function(){
473
+ var userID = jQuery(this).find('textarea').val();
474
+
475
+ if((jQuery(this).find("input[value='_coauthor']").length) && (!addedAlready[userID])) {
476
+ var authorName = coauthors_get_author_name(userID);
477
+ if(authorName) coauthors_add_coauthor(userID, authorName, undefined, true );
478
+ addedAlready[userID] = true;
479
+ }
480
+ });
481
+
482
+ // Create new author-suggest and append it to a new row
483
+ var newCO = coauthors_create_autosuggest('', false);
484
+ coauthors_add_to_table(newCO);
485
+
486
+ }
487
+
488
+ });
489
+ //})();
co-authors.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Co-Authors Plus
4
  Plugin URI: http://wordpress.org/extend/plugins/co-authors-plus/
5
  Description: Allows multiple authors to be assigned to a post. Co-authored posts appear on a co-author's posts page and feed. New template tags allow listing of co-authors. Editors may assign co-authors to a post via the 'Post Author' box. <em>This plugin is an extended version of the Co-Authors plugin originally developed at [Shepherd Interactive](http://www.shepherd-interactive.com/ "Shepherd Interactive specializes in web design and development in Portland, Oregon") (2007). Their plugin was inspired by 'Multiple Authors' plugin by Mark Jaquith (2005).</em>
6
- Version: 1.1.5
7
  Author: Mohammad Jangda
8
  Author URI: http://digitalize.ca
9
  Copyright: Some parts (C) 2009, Mohammad; Other parts (C) 2008, Weston Ruter, Shepherd Interactive
@@ -24,14 +24,21 @@ along with this program; if not, write to the Free Software
24
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
 
26
 
27
- ## Change Log ##
 
 
 
 
 
 
 
 
28
 
29
  *2009-04-26 / 1.1.5*
30
 
31
- * Bug fix: Not searching Updated SQL query for autosuggest to search through first name, last name, and nickname
32
- * Bug fix: When editing an author, and clicking on a suggested author, the original author was not be removed
33
- * Docs: Added code comments to javascript; more still to be added
34
- * Docs: Updated readme information
35
 
36
  *2009-04-25 / 1.1.4*
37
 
@@ -59,7 +66,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
59
 
60
  @@ To do @@
61
  - Setting to enable/disable co-authors for Pages
62
- - Check Cross-browser compatibility
63
  - admin.js: need to check to ensure that an author added is not a duplicate
64
  - Display all coauthors in table on "Edit Posts" page
65
 
@@ -69,7 +75,7 @@ define('COAUTHORS_DEFAULT_BEFORE', '');
69
  define('COAUTHORS_DEFAULT_BETWEEN', ', ');
70
  define('COAUTHORS_DEFAULT_BETWEEN_LAST', ' and ');
71
  define('COAUTHORS_DEFAULT_AFTER', '');
72
- define('COAUTHORS_PLUS_VERSION', '1.1.4');
73
 
74
  if(floatval(get_option('coauthors_plus_version')) < 1.0)
75
  coauthors_updatedb();
@@ -143,7 +149,8 @@ function coauthors_posts_join_filter($join){
143
  }
144
  return $join;
145
  }
146
- add_filter('posts_join', 'coauthors_posts_join_filter');
 
147
  function coauthors_posts_where_filter($where){
148
  global $wpdb;
149
  if(is_author())
@@ -152,12 +159,6 @@ function coauthors_posts_where_filter($where){
152
  }
153
  add_filter('posts_where', 'coauthors_posts_where_filter');
154
 
155
- //function coauthors_posts_query_filter($sql){ //this was needed when meta_value = query_vars[author] was not tested in the LEFT JOIN ON clause
156
- // return preg_replace("{^(\s*SELECT\b(?!\s*DISTINCT))}i", '$1 DISTINCT', $sql);
157
- //}
158
- //add_filter('posts_request', 'coauthors_posts_query_filter');
159
-
160
-
161
  class CoAuthorsIterator {
162
  var $position = -1;
163
  var $original_authordata;
@@ -281,9 +282,9 @@ function coauthors_lastnames($between = null, $betweenLast = null, $before = nul
281
  if($betweenLast === NULL)
282
  $betweenLast = __(COAUTHORS_DEFAULT_BETWEEN_LAST, 'co-authors');
283
  if($before === NULL)
284
- $before = COAUTHORS_DEFAULT_BEFORE; //__(COAUTHORS_DEFAULT_BEFORE, 'co-authors');
285
  if($after === NULL)
286
- $after = COAUTHORS_DEFAULT_AFTER; //__(COAUTHORS_DEFAULT_AFTER, 'co-authors');
287
  coauthors__echo('the_author_lastname', $between, $betweenLast, $before, $after);
288
  }
289
  function coauthors_nicknames($between = null, $betweenLast = null, $before = null, $after = null){
@@ -292,9 +293,9 @@ function coauthors_nicknames($between = null, $betweenLast = null, $before = nul
292
  if($betweenLast === NULL)
293
  $betweenLast = __(COAUTHORS_DEFAULT_BETWEEN_LAST, 'co-authors');
294
  if($before === NULL)
295
- $before = COAUTHORS_DEFAULT_BEFORE; //__(COAUTHORS_DEFAULT_BEFORE, 'co-authors');
296
  if($after === NULL)
297
- $after = COAUTHORS_DEFAULT_AFTER; //__(COAUTHORS_DEFAULT_AFTER, 'co-authors');
298
  coauthors__echo('the_author_nickname', $between, $betweenLast, $before, $after);
299
  }
300
  function coauthors_links($between = null, $betweenLast = null, $before = null, $after = null){
@@ -314,79 +315,87 @@ function coauthors_IDs($between = null, $betweenLast = null, $before = null, $af
314
  if($betweenLast === NULL)
315
  $betweenLast = __(COAUTHORS_DEFAULT_BETWEEN_LAST, 'co-authors');
316
  if($before === NULL)
317
- $before = COAUTHORS_DEFAULT_BEFORE; //__(COAUTHORS_DEFAULT_BEFORE, 'co-authors');
318
  if($after === NULL)
319
- $after = COAUTHORS_DEFAULT_AFTER; //__(COAUTHORS_DEFAULT_AFTER, 'co-authors');
320
- coauthors__echo('the_author_ID', $between, $betweenLast, $before, $after);
321
  }
322
- //function coauthors_emails($between = null, $betweenLast = null, $before = null, $after = null){
323
- // if($between === NULL)
324
- // $between = __(COAUTHORS_DEFAULT_BETWEEN, 'co-authors');
325
- // if($betweenLast === NULL)
326
- // $betweenLast = __(COAUTHORS_DEFAULT_BETWEEN_LAST, 'co-authors');
327
- // if($before === NULL)
328
- // $before = COAUTHORS_DEFAULT_BEFORE; //__(COAUTHORS_DEFAULT_BEFORE, 'co-authors');
329
- // if($after === NULL)
330
- // $after = COAUTHORS_DEFAULT_AFTER; //__(COAUTHORS_DEFAULT_AFTER, 'co-authors');
331
- // coauthors__echo('the_author_email', $between, $betweenLast, $before, $after);
332
- //}
333
- //function coauthors_urls($between = null, $betweenLast = null, $before = null, $after = null){
334
- // if($between === NULL)
335
- // $between = __(COAUTHORS_DEFAULT_BETWEEN, 'co-authors');
336
- // if($betweenLast === NULL)
337
- // $betweenLast = __(COAUTHORS_DEFAULT_BETWEEN_LAST, 'co-authors');
338
- // if($before === NULL)
339
- // $before = COAUTHORS_DEFAULT_BEFORE; //__(COAUTHORS_DEFAULT_BEFORE, 'co-authors');
340
- // if($after === NULL)
341
- // $after = COAUTHORS_DEFAULT_AFTER; //__(COAUTHORS_DEFAULT_AFTER, 'co-authors');
342
- // coauthors__echo('the_author_url', $between, $betweenLast, $before, $after);
343
- //}
344
- //function coauthors_icq($between = null, $betweenLast = null, $before = null, $after = null){
345
- // if($between === NULL)
346
- // $between = __(COAUTHORS_DEFAULT_BETWEEN, 'co-authors');
347
- // if($betweenLast === NULL)
348
- // $betweenLast = __(COAUTHORS_DEFAULT_BETWEEN_LAST, 'co-authors');
349
- // if($before === NULL)
350
- // $before = COAUTHORS_DEFAULT_BEFORE; //__(COAUTHORS_DEFAULT_BEFORE, 'co-authors');
351
- // if($after === NULL)
352
- // $after = COAUTHORS_DEFAULT_AFTER; //__(COAUTHORS_DEFAULT_AFTER, 'co-authors');
353
- // coauthors__echo('the_author_icq', $between, $betweenLast, $before, $after);
354
- //}
355
-
356
-
357
  function coauthors_init(){
358
- if(is_admin())
359
- wp_enqueue_script( 'jquery' );
 
360
  }
361
  add_action('init', 'coauthors_init');
362
-
363
- function coauthors_add_stylesheet() {
364
- global $current_user;
365
- print '<link rel="stylesheet" type="text/css" href="../' . PLUGINDIR . '/co-authors-plus/admin.css" />';
366
- }
367
- add_action('admin_print_scripts', 'coauthors_add_stylesheet');
368
-
369
- function coauthors_modify_post_sidebar(){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
  global $current_user;
 
 
371
 
372
- print '<script type="text/javascript">';
373
- print 'var coauthors_can_edit_others_posts = ' . ($current_user->has_cap('edit_others_posts') ? 'true' : 'false') . "\n";
374
- print 'var coauthors_dbx_post_title = "' . __('Post Author(s)', 'co-authors') . '";';
375
- print 'var coauthors_dbx_page_title = "' . __('Page Author(s)', 'co-authors') . '";';
376
- print 'var coauthors_add_author_label = "' . __('+ Add author', 'co-authors') . '";';
377
- print 'var coauthors_confirm_delete_label = "' . __('Are you sure you want to remove the user \u201C%s\u201D as an author?', 'co-authors') . '";';
378
- #print 'var coauthors_moveUp_author_label = "' . __('+ Add author', 'co-authors') . '";';
379
- #print 'var coauthors_moveDown_author_label = "' . __('+ Add author', 'co-authors') . '";';
380
- #print 'var coauthors_delete_author_label = "' . __('+ Add author', 'co-authors') . '";';
381
- print '</script>';
382
-
383
- print '<script type="text/javascript" src="../' . PLUGINDIR . '/co-authors-plus/admin.js"></script>';
384
-
385
-
386
- }
387
- add_action('admin_footer', 'coauthors_modify_post_sidebar'); //dbx_post_sidebar,edit_form_advanced
388
 
389
- //Update a post's co-authors
 
 
 
 
 
390
  function coauthors_update_post($postID){
391
  global $current_user, $wpdb;
392
  if($current_user->has_cap('edit_others_posts') && @$_POST['coauthors_plugin_is_active']){
@@ -408,44 +417,7 @@ add_action('save_post', 'coauthors_update_post');
408
 
409
  function coauthors_delete_user_action($userID){
410
  global $wpdb;
411
- //$reassign = null;
412
- ////Get $reassign parameter from calling wp_delete_user function
413
- //if(function_exists('debug_backtrace')){
414
- // $callstack = debug_backtrace();
415
- // foreach($callstack as $caller){
416
- // if($caller['function'] == 'wp_delete_user'){
417
- // if(is_numeric($caller['args'][1/*reassign*/]))
418
- // $reassign = (int)$caller['args'][1/*reassign*/];
419
- // break;
420
- // }
421
- // }
422
- //}
423
- ////Otherwise, try to get the reassign user from POST data
424
- //else if(@$_POST['delete_option'] == 'reassign' && is_numeric(@$_POST['reassign_user'])) {
425
- // $reassign = (int)$_POST['reassign_user'];
426
- //}
427
-
428
- //Reassign all co-author post meta
429
- //if($reassign){
430
- // $postIDs = $wpdb->get_col("SELECT ID FROM $wpdb->posts p LEFT JOIN $wpdb->postmeta pm ON p.ID = pm.post_id AND p.post_type != 'revision' AND pm.meta_key = '_coauthor' AND pm.meta_value = '$reassign';");
431
- // foreach($postIDs as $postID){
432
- // //if the post's post_author != $reassign and there isn't a post meta coauthor which is $reassign
433
- // if($wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts p
434
- // LEFT JOIN $wpdb->postmeta pm
435
- // ON p.ID = pm.post_id AND pm.meta_key = '_coauthor' AND pm.meta_value = '$reassign'
436
- // WHERE p.ID = $postID AND p.post_type != 'revision' AND (p.post_author = '$reassign' OR pm.meta_value = '$reassign')") == 0)
437
- // {
438
- // update_post_meta($postID, '_coauthor', $reassign, $userID);
439
- // }
440
- // //the reassign author already exists for this post, so just delete the post meta
441
- // else {
442
- // delete_post_meta($postID, '_coauthor', $userID);
443
- // }
444
- // }
445
- //}
446
- ////Delete all co-author post meta
447
- //else
448
- $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = '_coauthor' AND meta_value = '$userID';");
449
  }
450
  add_action('delete_user', 'coauthors_delete_user_action');
451
 
@@ -550,27 +522,43 @@ function coauthors_wp_list_authors($args = ''){
550
  if ( !$echo )
551
  return $return;
552
  echo $return;
553
- }
554
-
555
-
556
-
557
- add_action('admin_print_scripts', 'coauthor_js_admin_header' );
558
-
559
- function coauthor_js_admin_header() {
560
- //use JavaScript SACK library for Ajax
561
- //wp_print_scripts( array( 'sack' ));
562
-
563
- // Add suggest.js plugin
564
- wp_enqueue_script( 'suggest' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
565
 
566
- // Define custom JavaScript function
567
- ?>
568
- <script type="text/javascript">
569
- //<![CDATA[
570
- var coauthor_ajax_suggest_link = '<?php bloginfo( 'wpurl' ); ?>/wp-content/plugins/co-authors-plus/suggest.php';
571
- //]]>
572
- </script>
573
- <?php
574
- } // end of PHP function coauthor_js_admin_header
 
 
575
 
576
- ?>
3
  Plugin Name: Co-Authors Plus
4
  Plugin URI: http://wordpress.org/extend/plugins/co-authors-plus/
5
  Description: Allows multiple authors to be assigned to a post. Co-authored posts appear on a co-author's posts page and feed. New template tags allow listing of co-authors. Editors may assign co-authors to a post via the 'Post Author' box. <em>This plugin is an extended version of the Co-Authors plugin originally developed at [Shepherd Interactive](http://www.shepherd-interactive.com/ "Shepherd Interactive specializes in web design and development in Portland, Oregon") (2007). Their plugin was inspired by 'Multiple Authors' plugin by Mark Jaquith (2005).</em>
6
+ Version: 1.2
7
  Author: Mohammad Jangda
8
  Author URI: http://digitalize.ca
9
  Copyright: Some parts (C) 2009, Mohammad; Other parts (C) 2008, Weston Ruter, Shepherd Interactive
24
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
 
26
 
27
+ ## Change Log ##
28
+
29
+ *2009-06-16 / 1.2.0*
30
+
31
+ * FIX: Added compatibility for WordPress 2.8
32
+ * FIX: Added new template tags (get_the_coauthor_meta & the_coauthor_meta) to fix issues related to displaying author info on author archive pages
33
+ * FIX: Plugin should now work for plugins not using the wp_ DB prefix
34
+ * FIX: Coauthors should no longer be alphabetically reordered when the post is updated
35
+ * UPDATE: Plugin now used WordPress native AJAX calls to tighten security
36
 
37
  *2009-04-26 / 1.1.5*
38
 
39
+ * Updated SQL query for autosuggest to search through first name, last name, and nickname
40
+ * Added code comments to javascript; more still to be added
41
+ * Updated readme information
 
42
 
43
  *2009-04-25 / 1.1.4*
44
 
66
 
67
  @@ To do @@
68
  - Setting to enable/disable co-authors for Pages
 
69
  - admin.js: need to check to ensure that an author added is not a duplicate
70
  - Display all coauthors in table on "Edit Posts" page
71
 
75
  define('COAUTHORS_DEFAULT_BETWEEN', ', ');
76
  define('COAUTHORS_DEFAULT_BETWEEN_LAST', ' and ');
77
  define('COAUTHORS_DEFAULT_AFTER', '');
78
+ define('COAUTHORS_PLUS_VERSION', '1.2');
79
 
80
  if(floatval(get_option('coauthors_plus_version')) < 1.0)
81
  coauthors_updatedb();
149
  }
150
  return $join;
151
  }
152
+ add_filter('posts_join', 'coauthors_posts_join_filter');
153
+
154
  function coauthors_posts_where_filter($where){
155
  global $wpdb;
156
  if(is_author())
159
  }
160
  add_filter('posts_where', 'coauthors_posts_where_filter');
161
 
 
 
 
 
 
 
162
  class CoAuthorsIterator {
163
  var $position = -1;
164
  var $original_authordata;
282
  if($betweenLast === NULL)
283
  $betweenLast = __(COAUTHORS_DEFAULT_BETWEEN_LAST, 'co-authors');
284
  if($before === NULL)
285
+ $before = COAUTHORS_DEFAULT_BEFORE;
286
  if($after === NULL)
287
+ $after = COAUTHORS_DEFAULT_AFTER;
288
  coauthors__echo('the_author_lastname', $between, $betweenLast, $before, $after);
289
  }
290
  function coauthors_nicknames($between = null, $betweenLast = null, $before = null, $after = null){
293
  if($betweenLast === NULL)
294
  $betweenLast = __(COAUTHORS_DEFAULT_BETWEEN_LAST, 'co-authors');
295
  if($before === NULL)
296
+ $before = COAUTHORS_DEFAULT_BEFORE;
297
  if($after === NULL)
298
+ $after = COAUTHORS_DEFAULT_AFTER;
299
  coauthors__echo('the_author_nickname', $between, $betweenLast, $before, $after);
300
  }
301
  function coauthors_links($between = null, $betweenLast = null, $before = null, $after = null){
315
  if($betweenLast === NULL)
316
  $betweenLast = __(COAUTHORS_DEFAULT_BETWEEN_LAST, 'co-authors');
317
  if($before === NULL)
318
+ $before = COAUTHORS_DEFAULT_BEFORE;
319
  if($after === NULL)
320
+ $after = COAUTHORS_DEFAULT_AFTER;
321
+ coauthors__echo('the_author_ID', $between, $betweenLast, $before, $after);
322
  }
323
+
324
+ function get_the_coauthor_meta( $field, $userID = 0 ) {
325
+ if(is_author() && $userID == 0) {
326
+ global $wp_query;
327
+ $curauth = $wp_query->get_queried_object();
328
+
329
+ if(function_exists('get_the_author_meta')) {//get_bloginfo('version') >= 2.8) {
330
+ return get_the_author_meta('description', $curauth->ID);
331
+ }
332
+ }
333
+ }
334
+
335
+ function the_coauthor_meta( $field, $userID = 0 ) {
336
+ echo get_the_coauthor_meta($field, $userID);
337
+ }
338
+
339
+ /*
340
+ * Init the plugin
341
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
  function coauthors_init(){
343
+ if(is_admin()) {
344
+
345
+ }
346
  }
347
  add_action('init', 'coauthors_init');
348
+
349
+ // Add the main JS script and CSS file
350
+ if(get_bloginfo('version') >= 2.8) {
351
+ // Using WordPress 2.8, are we?
352
+ add_action('admin_enqueue_scripts', 'coauthors_enqueue_scripts');
353
+ function coauthors_enqueue_scripts($hook_suffix) {
354
+ wp_enqueue_style('co-authors-plus', plugins_url('co-authors-plus/admin.css'), false, '', 'all');
355
+ wp_enqueue_script('co-authors-plus', plugins_url('co-authors-plus/admin.js'), array('jquery', 'suggest', 'sack'), '', true);
356
+ }
357
+ } else {
358
+ // Pfft, you're old school
359
+ add_action('admin_print_scripts', 'coauthors_enqueue_scripts_pre28');
360
+ function coauthors_enqueue_scripts_pre28($hook_suffix) {
361
+ //wp_enqueue_style('co-authors-plus', plugins_url('co-authors-plus/admin.css'), false, '', 'all');
362
+ wp_enqueue_script('co-authors-plus', plugins_url('co-authors-plus/admin.js'), array('jquery', 'suggest', 'sack'), '');
363
+ ?>
364
+ <link type="text/css" rel="stylesheet" href="<?php echo plugins_url('co-authors-plus/admin.css') ?>" media="all" />
365
+ <?php
366
+ }
367
+
368
+ }
369
+
370
+ // Add JS variables
371
+ add_action('admin_print_scripts', 'coauthors_admin_header' );
372
+ function coauthors_admin_header() {
373
  global $current_user;
374
+
375
+ wp_print_scripts( array( 'sack' ));
376
 
377
+ ?>
378
+ <script type="text/javascript">
379
+ //<![CDATA[
380
+
381
+ // Not currently used, but likely will when the 'Create New Author' functionality is built
382
+ var coauthors_sack = new sack("<?php bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php" );
383
+
384
+ // The link used for the autosuggest
385
+ var coauthor_ajax_suggest_link = "<?php bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php?action=coauthors_ajax_suggest"
386
+
387
+ var coauthors_can_edit_others_posts = "<?php echo ($current_user->has_cap('edit_others_posts') ? 'true' : 'false')?>";
388
+ var coauthors_dbx_post_title = "<?php _e('Post Author(s)', 'co-authors')?>";
389
+ var coauthors_dbx_page_title = "<?php _e('Page Author(s)', 'co-authors')?>";
390
+ var coauthors_add_author_label = "<?php _e('+ Add author', 'co-authors')?>";
391
+ var coauthors_confirm_delete_label = "<?php _e('Are you sure you want to remove the user \u201C%s\u201D as an author?', 'co-authors')?>";
 
392
 
393
+ //]]>
394
+ </script>
395
+ <?php
396
+ } // end of PHP function coauthor_js_admin_header
397
+
398
+ // Update a post's co-authors
399
  function coauthors_update_post($postID){
400
  global $current_user, $wpdb;
401
  if($current_user->has_cap('edit_others_posts') && @$_POST['coauthors_plugin_is_active']){
417
 
418
  function coauthors_delete_user_action($userID){
419
  global $wpdb;
420
+ $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = '_coauthor' AND meta_value = '$userID';");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  }
422
  add_action('delete_user', 'coauthors_delete_user_action');
423
 
522
  if ( !$echo )
523
  return $return;
524
  echo $return;
525
+ }
526
+
527
+ add_action('wp_ajax_coauthors_ajax_suggest', 'coauthors_ajax_suggest' );
528
+ function coauthors_ajax_suggest() {
529
+ global $wpdb;
530
+
531
+ // Make sure that user is logged in; we don't want to enable direct access
532
+ get_currentuserinfo();
533
+ global $user_level;
534
+ if ($user_level >= 7) {
535
+
536
+ $q = '%'.strtolower($_REQUEST["q"]).'%';
537
+ if (!$q) return;
538
+
539
+ $authors_query = $wpdb->prepare("SELECT DISTINCT u.ID, u.display_name, u.user_email FROM $wpdb->users AS u"
540
+ ." INNER JOIN $wpdb->usermeta AS um ON u.ID = um.user_id"
541
+ ." WHERE ID = ANY (SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '".$wpdb->prefix."user_level' AND meta_value >= 1)"
542
+ ." AND (um.meta_key = 'first_name' OR um.meta_key = 'last_name' OR um.meta_key = 'nickname')"
543
+ ." AND (u.user_login LIKE %s"
544
+ ." OR u.user_nicename LIKE %s"
545
+ ." OR u.display_name LIKE %s"
546
+ ." OR u.user_email LIKE %s"
547
+ ." OR um.meta_value LIKE %s)",$q,$q,$q,$q,$q);
548
+
549
+
550
+ $authors = $wpdb->get_results($authors_query, ARRAY_A);
551
 
552
+ if(is_array($authors)) {
553
+ foreach ($authors as $author) {
554
+
555
+ echo $author['ID']." | ". $author['display_name'] ." | ".$author['user_email'] ."\n";
556
+ }
557
+ }
558
+ //echo "New | Add new author: ".trim($q,'%')."\n";
559
+ }
560
+ die();
561
+
562
+ }
563
 
564
+ ?>
readme.txt CHANGED
@@ -2,32 +2,39 @@
2
  Contributors: batmoo
3
  Donate link: http://digitalize.ca/donate
4
  Tags: authors, users
5
- Tested up to: 2.7.1
6
  Requires at least: 2.6
7
- Stable tag: 1.1.5
8
 
9
  Allows multiple authors to be assigned to a Post or Page via search-as-you-type input boxes.
10
 
11
  == Description ==
12
 
13
- > **IMPORTANT: If you are upgrading from 1.1.3, please delete the plugin from your plugins directory and reinstall!**
14
-
15
  Allows multiple authors to be assigned to a Post or Page via the search-as-you-type inputs. Co-authored posts appear on a co-author's posts page and feed. New template tags allow listing of co-authors. Editors and Administrators may assign co-authors to a post. Additionally, co-authors may edit the posts they are associated with, and co-authors who are contributors may only edit posts if they have not been published (as is usual).
16
 
17
  This plugin is an extended version of the Co-Authors plugin originally developed at [Shepherd Interactive](http://www.shepherd-interactive.com/ "Shepherd Interactive specializes in web design and development in Portland, Oregon") (2007). Their plugin was inspired by 'Multiple Authors' plugin by Mark Jaquith (2005).
18
 
19
- The extended version is created by Mohammad Jangda, and incorporates search-as-you-type functionality for adding users, which aims to make easy the task of adding multiple users to posts and pages, especially when dealing with a system with hundreds of users (typical of newspaper and magazine sites).
20
 
21
- > *See "Other Notes" section for Template Tags and usage information
22
 
23
  = Changelog =
 
 
 
 
 
 
 
 
 
24
 
25
  *2009-04-26 / 1.1.5*
26
 
27
- * Bug fix: Not searching Updated SQL query for autosuggest to search through first name, last name, and nickname
28
- * Bug fix: When editing an author, and clicking on a suggested author, the original author was not be removed
29
- * Docs: Added code comments to javascript; more still to be added
30
- * Docs: Updated readme information
31
 
32
  *2009-04-25 / 1.1.4*
33
 
@@ -65,11 +72,11 @@ The extended version is created by Mohammad Jangda, and incorporates search-as-y
65
 
66
  == Basic Usage and Other Notes ==
67
 
68
- *Only Author-level and above can be added as co-authors. Namely, contributers cannot be added as co-authors.
69
- *As per WordPress design, only Editor-level and above users can change Post Authors. Authors cannot change authors or add co-authors (yet)
70
- *As per WordPress design, when an editor creates a new Post or Page, they are by default added as an author. However, they can changed by clicking on their name and typing in the name of the new author.
71
- *The search-as-you-type box starts searching once two letters have been added, and executes a new search with every subsequent letter.
72
- *The search-as-you-type box searches through the following user fields: a) user_login; b) user_nicename; c) display_name; d) user_email; e) first_name; f) last_name; and g) nickname.
73
 
74
 
75
  == Template Tags ==
@@ -82,7 +89,7 @@ New template tags enable listing of co-authors:
82
  * <code>coauthors_lastnames()</code>
83
  * <code>coauthors_nicknames()</code>
84
  * <code>coauthors_links()</code>
85
- * <code>coauthors_IDs()</code>
86
 
87
  These template tags correspond to their "<code>the_author*</code>" equivalents; take special note of the pluralization.
88
  Each of these template tags accept four optional arguments:
@@ -126,11 +133,21 @@ For example:
126
  print $i->is_last() ? ' and ' : ', ';
127
  the_author();
128
  }
 
 
 
 
 
 
 
 
 
 
129
 
130
 
131
  == Frequently Asked Questions ==
132
 
133
- = What�s the main difference between Co-Authors and Co-Authors Plus? =
134
 
135
  The most notable difference is the replacement of the standard WordPress authors drop-downs with search-as-you-type/auto-suggest/whatever-you-call-them input boxes. As a result, major bits of the JavaScript code was changed to be more jQuery-friendly. Eventually, I hope to include the ability to add new Users from within the Edit Post/Page screen and possibly Gravatar support.
136
 
2
  Contributors: batmoo
3
  Donate link: http://digitalize.ca/donate
4
  Tags: authors, users
5
+ Tested up to: 2.8
6
  Requires at least: 2.6
7
+ Stable tag: 1.2
8
 
9
  Allows multiple authors to be assigned to a Post or Page via search-as-you-type input boxes.
10
 
11
  == Description ==
12
 
 
 
13
  Allows multiple authors to be assigned to a Post or Page via the search-as-you-type inputs. Co-authored posts appear on a co-author's posts page and feed. New template tags allow listing of co-authors. Editors and Administrators may assign co-authors to a post. Additionally, co-authors may edit the posts they are associated with, and co-authors who are contributors may only edit posts if they have not been published (as is usual).
14
 
15
  This plugin is an extended version of the Co-Authors plugin originally developed at [Shepherd Interactive](http://www.shepherd-interactive.com/ "Shepherd Interactive specializes in web design and development in Portland, Oregon") (2007). Their plugin was inspired by 'Multiple Authors' plugin by Mark Jaquith (2005).
16
 
17
+ The extended version is created by [Mohammad Jangda](http://digitalize.ca), and incorporates search-as-you-type functionality for adding users, which aims to make easy the task of adding multiple users to posts and pages, especially when dealing with a system with hundreds of users (typical of newspaper and magazine sites).
18
 
19
+ > *See "Other Notes" section for Template Tags and usage information*
20
 
21
  = Changelog =
22
+
23
+ *2009-06-16 / 1.2.0*
24
+
25
+ * FIX: Added compatibility for WordPress 2.8
26
+ * FIX: Added new template tags (get_the_coauthor_meta & the_coauthor_meta) to fix issues related to displaying author info on author archive pages. See [Other Notes](http://wordpress.org/extend/plugins/co-authors-plus/other_notes/) for details.
27
+ * FIX: Plugin should now work for plugins not using the 'wp_' DB prefix
28
+ * FIX: Coauthors should no longer be alphabetically reordered when the post is updated
29
+ * FIX: Plugin now used WordPress native AJAX calls to tighten security
30
+ * DOCS: Added details about the new template tags
31
 
32
  *2009-04-26 / 1.1.5*
33
 
34
+ * FIX: Not searching Updated SQL query for autosuggest to search through first name, last name, and nickname
35
+ * FIX: When editing an author, and clicking on a suggested author, the original author was not be removed
36
+ * DOCS: Added code comments to javascript; more still to be added
37
+ * DOCS: Updated readme information
38
 
39
  *2009-04-25 / 1.1.4*
40
 
72
 
73
  == Basic Usage and Other Notes ==
74
 
75
+ * Only Author-level and above can be added as co-authors. Namely, contributers cannot be added as co-authors.
76
+ * As per WordPress design, only Editor-level and above users can change Post Authors. Authors cannot change authors or add co-authors (yet)
77
+ * As per WordPress design, when an editor creates a new Post or Page, they are by default added as an author. However, they can changed by clicking on their name and typing in the name of the new author.
78
+ * The search-as-you-type box starts searching once two letters have been added, and executes a new search with every subsequent letter.
79
+ * The search-as-you-type box searches through the following user fields: a) user_login; b) user_nicename; c) display_name; d) user_email; e) first_name; f) last_name; and g) nickname.
80
 
81
 
82
  == Template Tags ==
89
  * <code>coauthors_lastnames()</code>
90
  * <code>coauthors_nicknames()</code>
91
  * <code>coauthors_links()</code>
92
+ * <code>coauthors_IDs()</code>
93
 
94
  These template tags correspond to their "<code>the_author*</code>" equivalents; take special note of the pluralization.
95
  Each of these template tags accept four optional arguments:
133
  print $i->is_last() ? ' and ' : ', ';
134
  the_author();
135
  }
136
+
137
+ = NEW (2009-06-16): (the coauthor meta) Template Tags =
138
+
139
+ *Two new template tags were added to fix issues related to displaying author info on an Author Archive page:*
140
+
141
+ * <code>get_the_coauthor_meta( $field )</code> (2.8 only)
142
+ * <code>the_coauthor_meta( $field )</code> (2.8 only)
143
+
144
+ Note: These will only work on Author Archive pages and with WordPress 2.8 only. The $field variable corresponds with the same values accepted by the [the author meta](http://codex.wordpress.org/Template_Tags/the_author_meta) function
145
+
146
 
147
 
148
  == Frequently Asked Questions ==
149
 
150
+ = What is the main difference between Co-Authors and Co-Authors Plus? =
151
 
152
  The most notable difference is the replacement of the standard WordPress authors drop-downs with search-as-you-type/auto-suggest/whatever-you-call-them input boxes. As a result, major bits of the JavaScript code was changed to be more jQuery-friendly. Eventually, I hope to include the ability to add new Users from within the Edit Post/Page screen and possibly Gravatar support.
153