Ticket #12722: 12722.diff
| File 12722.diff, 6.5 KB (added by , 13 years ago) |
|---|
-
wp-includes/widgets.php
901 901 do_action( 'dynamic_sidebar', $wp_registered_widgets[$id] ); 902 902 903 903 if ( is_callable($callback) ) { 904 905 if ( wp_check_widget_lock( $id ) ) 906 _admin_notice_widget_locked( $wp_registered_widgets[$id] ); 907 904 908 call_user_func_array($callback, $params); 905 909 $did_one = true; 906 910 } … … 1268 1272 1269 1273 return $sidebars_widgets; 1270 1274 } 1275 1276 /** 1277 * Check to see if the post is currently being edited by another user. 1278 * 1279 * @since 3.6.0 1280 * 1281 * @param int $id Widget id 1282 * @return bool|int False: not locked or locked by current user. Int: user ID of user with lock. 1283 */ 1284 function wp_check_widget_lock( $id ) { 1285 $locks = get_option( '_widgets_lock' ); 1286 if ( empty( $locks[$id] ) ) 1287 return; 1288 1289 $lasts = get_option( '_widgets_last' ); 1290 $last = $lasts[$id]; 1291 1292 $lock = explode( ':', $locks[$id] ); 1293 $time = $lock[0]; 1294 $user = isset( $lock[1] ) ? $lock[1] : $last; 1295 1296 $time_window = apply_filters( 'wp_check_widget_lock_window', AUTOSAVE_INTERVAL * 2 ); 1297 1298 if ( $time && $time > time() - $time_window && $user != get_current_user_id() ) 1299 return $user; 1300 1301 return false; 1302 } 1303 1304 /** 1305 * Mark the widget as currently being edited by the current user 1306 * 1307 * @since 3.6.0 1308 * 1309 * @param int $id ID of the widget to be locked 1310 * @return bool|array Returns false if there is no current user, or an array of the lock time and the user ID. 1311 */ 1312 function wp_set_widget_lock( $id ) { 1313 if ( 0 == ( $user_id = get_current_user_id() ) ) 1314 return false; 1315 1316 $now = time(); 1317 $lock = "$now:$user_id"; 1318 1319 $locks = get_option( '_widgets_lock' ); 1320 $locks[$id] = $lock; 1321 1322 update_option( '_widgets_lock', $locks ); 1323 return array( $now, $user_id ); 1324 } 1325 1326 /** 1327 * Mark the widget's last editor as the current user 1328 * 1329 * @since 3.6.0 1330 * 1331 * @param string $id ID of the widget to being edited 1332 * @return bool|array Returns false if is no current user 1333 */ 1334 function wp_set_widget_last( $id ) { 1335 if ( 0 == ( $user_id = get_current_user_id() ) ) 1336 return; 1337 1338 $lasts = get_option( '_widget_lasts' ); 1339 1340 if ( ! empty( $lasts[$id] ) && $lasts[$id] == get_current_user_id() ) 1341 return $lasts[$id]; 1342 1343 $lasts[$id] = $user_id; 1344 update_option( '_widget_lasts', $lasts ); 1345 1346 return $user_id; 1347 } 1348 1349 /** 1350 * Outputs the notice message to say that someone else is editing this post at the moment. 1351 * 1352 * @since 3.6.0 1353 * @return none 1354 */ 1355 function _admin_notice_widget_locked( $widget ) { 1356 $locks = get_option( '_widgets_lock' ); 1357 $lasts = get_option( '_widgets_last' ); 1358 1359 $last = 0; 1360 if ( ! empty( $lasts ) ) 1361 $last = $lasts[$widget['id']]; 1362 1363 $lock = explode( ':', $locks[$widget['id']] ); 1364 $user = isset( $lock[1] ) ? $lock[1] : $last; 1365 if ( ! empty( $user ) ) { 1366 $last_user = get_userdata( $user ); 1367 $last_user_name = $last_user->display_name; 1368 } else { 1369 $last_user_name = __( 'Somebody' ); 1370 } 1371 1372 $message = sprintf( __( 'Warning: %s is currently editing the <strong>%s</strong> widget.' ), 1373 esc_html( $last_user_name ), 1374 esc_html( $widget['name'] ) 1375 ); 1376 printf( '<div class="widget-error" data-id="%s"><p>%s</p></div>', $widget['id'], $message ); 1377 } 1378 No newline at end of file -
wp-admin/includes/ajax-actions.php
1566 1566 } 1567 1567 } 1568 1568 1569 wp_set_widget_lock( $widget_id ); 1570 wp_set_widget_last( $widget_id ); 1571 1569 1572 if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) { 1570 1573 $sidebars[$sidebar_id] = $sidebar; 1571 1574 wp_set_sidebars_widgets($sidebars); -
wp-admin/js/widgets.js
103 103 ui.item.css({margin:'', 'width':''}); 104 104 }, 105 105 stop: function(e,ui) { 106 wpWidgets.fixErrors(ui.item.parent()); 107 106 108 if ( ui.item.hasClass('ui-draggable') && ui.item.data('draggable') ) 107 109 ui.item.draggable('destroy'); 108 110 … … 174 176 }); 175 177 }, 176 178 179 fixErrors : function (sb, del) { 180 sb.find('div.widget-error').hide().each(function (i, error) { 181 error = $(error); 182 183 var node = error.clone(), wdgt = error.parent().find('[id$="' + error.data('id') + '"]'); 184 if ( error.remove() && wdgt.length && ( !del || ( del.prop('id') != wdgt.prop('id') ) ) ) 185 wdgt.before(node.show()); 186 187 }); 188 }, 189 177 190 saveOrder : function(sb) { 178 191 if ( sb ) 179 192 $('#' + sb).closest('div.widgets-holder-wrap').find('.spinner').css('display', 'inline-block'); … … 197 210 }, 198 211 199 212 save : function(widget, del, animate, order) { 200 var sb = widget.closest('div.widgets-sortables').attr('id'), data = widget.find('form').serialize(), a; 213 var sortables = widget.closest('div.widgets-sortables'), 214 sb = sortables.attr('id'), 215 data = widget.find('form').serialize(), a; 201 216 widget = $(widget); 202 217 $('.spinner', widget).show(); 203 218 … … 234 249 widget.remove(); 235 250 wpWidgets.resize(); 236 251 } 252 253 wpWidgets.fixErrors(sortables, widget); 237 254 } else { 238 255 $('.spinner').hide(); 239 256 if ( r && r.length > 2 ) { … … 241 258 wpWidgets.appendTitle(widget); 242 259 wpWidgets.fixLabels(widget); 243 260 } 261 wpWidgets.fixErrors(sortables); 244 262 } 245 263 if ( order ) 246 264 wpWidgets.saveOrder(); -
wp-admin/css/colors-fresh.css
275 275 } 276 276 277 277 div.error, 278 div.widget-error, 278 279 .login #login_error { 279 280 background-color: #ffebe8; 280 281 border-color: #c00; 281 282 } 282 283 283 div.error a { 284 div.error a, 285 div.widget-error a { 284 286 color: #c00; 285 287 } 286 288 -
wp-admin/css/wp-admin.css
498 498 .widefat, 499 499 div.updated, 500 500 div.error, 501 div.widget-error, 501 502 .wrap .add-new-h2, 502 503 textarea, 503 504 input[type="text"], … … 651 652 } 652 653 653 654 div.updated, 654 div.error { 655 div.error, 656 div.widget-error { 655 657 padding: 0 0.6em; 656 658 margin: 5px 15px 2px; 657 659 } 658 660 659 661 div.updated p, 660 div.error p { 662 div.error p, 663 div.widget-error p { 661 664 margin: 0.5em 0; 662 665 padding: 2px; 663 666 } … … 8071 8074 padding: 15px 0 0; 8072 8075 } 8073 8076 8077 div.widget-error { 8078 margin-bottom: 15px; 8079 } 8080 8074 8081 #available-widgets .widget-holder { 8075 8082 padding: 7px 5px 0; 8076 8083 }