Widgets page, first run, see #9511
git-svn-id: http://svn.automattic.com/wordpress/trunk@10912 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
7c460ad4d3
commit
123d7ee968
|
@ -1268,6 +1268,110 @@ case 'lj-importer' :
|
|||
echo $result->get_error_message();
|
||||
die;
|
||||
break;
|
||||
case 'widgets-order' :
|
||||
check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
|
||||
|
||||
if ( !current_user_can('switch_themes') )
|
||||
die('-1');
|
||||
|
||||
unset( $_POST['savewidgets'], $_POST['action'] );
|
||||
$sidebars_widgets = array('array_version' => 3);
|
||||
|
||||
foreach ( $_POST as $key => $val ) {
|
||||
if ( preg_match( '/^(wp_inactive_widgets|sidebar-[0-9]+)$/', $key ) ) {
|
||||
if ( preg_match( '/^[0-9a-z,_-]+$/i', $val ) ) {
|
||||
$val = explode(',', $val);
|
||||
|
||||
foreach ( $val as $k => $v ) {
|
||||
$val[$k] = substr($v, strpos($v, '_') + 1);
|
||||
}
|
||||
} elseif ( '' == $val ) {
|
||||
$val = array();
|
||||
} else {
|
||||
die('-1');
|
||||
}
|
||||
|
||||
$sidebars_widgets[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
wp_set_sidebars_widgets($sidebars_widgets);
|
||||
|
||||
die('1');
|
||||
break;
|
||||
case 'save-widget' :
|
||||
check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
|
||||
|
||||
if ( !current_user_can('switch_themes') )
|
||||
die('-1');
|
||||
|
||||
unset( $_POST['savewidgets'], $_POST['action'] );
|
||||
|
||||
$number = isset($_POST['widget_number']) ? $_POST['widget_number'] : '';
|
||||
if ( isset($_POST['id_base']) )
|
||||
$id_base = $_POST['id_base'];
|
||||
else
|
||||
die('-1');
|
||||
|
||||
$sidebar_id = (string) $_POST['sidebar'];
|
||||
$sidebars = wp_get_sidebars_widgets();
|
||||
$sidebar = isset($sidebars[$sidebar_id]) ? $sidebars[$sidebar_id] : array();
|
||||
|
||||
// delete
|
||||
if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
|
||||
$del_id = $_POST['widget-id'];
|
||||
$widget = isset($wp_registered_widgets[$del_id]) ? $wp_registered_widgets[$del_id] : false;
|
||||
|
||||
if ( !in_array($del_id, $sidebar, true) || !$widget )
|
||||
die('-1');
|
||||
|
||||
$option = str_replace( '-', '_', 'widget_' . $id_base );
|
||||
$data = get_option($option);
|
||||
|
||||
if ( isset($widget['params'][0]['number']) ) {
|
||||
$number = $widget['params'][0]['number'];
|
||||
if ( is_array($data) && isset($data[$number]) ) {
|
||||
unset( $data[$number] );
|
||||
update_option($option, $data);
|
||||
}
|
||||
} else {
|
||||
if ( $data ) {
|
||||
$data = array();
|
||||
update_option($option, $data);
|
||||
}
|
||||
}
|
||||
|
||||
$sidebar = array_diff( $sidebar, array($del_id) );
|
||||
$sidebars[$sidebar_id] = $sidebar;
|
||||
wp_set_sidebars_widgets($sidebars);
|
||||
|
||||
echo "deleted:$del_id";
|
||||
die();
|
||||
}
|
||||
|
||||
// save
|
||||
foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
|
||||
if ( $name == $id_base ) {
|
||||
if ( !is_callable( $control['callback'] ) )
|
||||
continue;
|
||||
|
||||
if ( $number ) {
|
||||
// don't delete other instances of the same multi-widget
|
||||
foreach ( $sidebar as $_widget_id ) {
|
||||
if ( isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) )
|
||||
unset($wp_registered_widgets[$_widget_id]['params'][0]['number']);
|
||||
}
|
||||
}
|
||||
|
||||
ob_start();
|
||||
call_user_func_array( $control['callback'], $control['params'] );
|
||||
ob_end_clean();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
die('1');
|
||||
break;
|
||||
default :
|
||||
do_action( 'wp_ajax_' . $_POST['action'] );
|
||||
die('0');
|
||||
|
|
|
@ -33,7 +33,6 @@ kbd, code {
|
|||
background: #eaeaea;
|
||||
}
|
||||
|
||||
div#current-widgets,
|
||||
#postcustomstuff table,
|
||||
#your-profile fieldset,
|
||||
#rightnow,
|
||||
|
@ -83,8 +82,7 @@ div.dashboard-widget-notice {
|
|||
background-color: #cfe1ef;
|
||||
}
|
||||
|
||||
div.dashboard-widget-submit,
|
||||
ul.widget-control-list div.widget-control-actions {
|
||||
div.dashboard-widget-submit {
|
||||
border-top-color: #ccc;
|
||||
}
|
||||
|
||||
|
@ -101,10 +99,6 @@ textarea.disabled {
|
|||
background-color: #ccc;
|
||||
}
|
||||
/* #upload-menu li a.upload-tab-link, */
|
||||
li.widget-list-control-item h4.widget-title a:hover,
|
||||
li.widget-list-control-item h4.widget-title a,
|
||||
#dragHelper li.widget-list-control-item h4.widget-title a,
|
||||
#draghelper li.widget-list-control-item h4.widget-title a:visited,
|
||||
.login #backtoblog a:hover,
|
||||
#plugin-information .action-button a,
|
||||
#plugin-information .action-button a:hover,
|
||||
|
@ -112,11 +106,6 @@ li.widget-list-control-item h4.widget-title a,
|
|||
color: #fff;
|
||||
}
|
||||
|
||||
li.widget-list-control-item div.widget-control {
|
||||
background-color: #fff;
|
||||
border-color: #dfdfdf;
|
||||
}
|
||||
|
||||
.metabox-holder .postbox h3,
|
||||
#poststuff .postbox h3,
|
||||
#poststuff .stuffbox h3 {
|
||||
|
@ -143,11 +132,6 @@ strong .post-com-count span {
|
|||
background-color: #21759b;
|
||||
}
|
||||
|
||||
ul#widget-list li.widget-list-item h4.widget-title {
|
||||
background-color: #f0f0f0;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.sorthelper {
|
||||
background-color: #ccf3fa;
|
||||
}
|
||||
|
@ -276,7 +260,7 @@ td.help {
|
|||
border-bottom-color: #dadada;
|
||||
}
|
||||
|
||||
.side-info ul, .widget-description {
|
||||
.side-info ul {
|
||||
color: #666;
|
||||
}
|
||||
|
||||
|
@ -429,7 +413,6 @@ a.page-numbers {
|
|||
}
|
||||
|
||||
div#available-widgets-filter,
|
||||
ul#widget-list li.widget-list-item,
|
||||
.commentlist li {
|
||||
border-bottom-color: #ccc;
|
||||
}
|
||||
|
@ -531,10 +514,6 @@ div#plugin-information-header {
|
|||
border-color: #666;
|
||||
}
|
||||
|
||||
#current-widgets .drop-widget-here {
|
||||
background-color: #ffc;
|
||||
}
|
||||
|
||||
#dashboard_secondary div.dashboard-widget-content ul li a {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
@ -543,13 +522,6 @@ input.readonly, textarea.readonly {
|
|||
background-color: #ddd;
|
||||
}
|
||||
|
||||
#dragHelper h4.widget-title,
|
||||
li.widget-list-control-item h4,
|
||||
#dragHelper li.widget-list-control-item h4 {
|
||||
background-color: #2683ae;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
#ed_toolbar input,
|
||||
#ed_reply_toolbar input {
|
||||
background: #fff url("../images/fade-butt.png") repeat-x 0 -2px;
|
||||
|
@ -1595,3 +1567,8 @@ input[readonly] {
|
|||
.theme-listing br.line {
|
||||
border-bottom-color: #ccc;
|
||||
}
|
||||
|
||||
div.widgets-holder-wrap {
|
||||
background-color: #F1F1F1;
|
||||
border-color: #DDDDDD;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ kbd, code {
|
|||
background: #eaeaea;
|
||||
}
|
||||
|
||||
div#current-widgets,
|
||||
#postcustomstuff table,
|
||||
#your-profile fieldset,
|
||||
#rightnow,
|
||||
|
@ -83,8 +82,7 @@ div.dashboard-widget-notice {
|
|||
background-color: #cfe1ef;
|
||||
}
|
||||
|
||||
div.dashboard-widget-submit,
|
||||
ul.widget-control-list div.widget-control-actions {
|
||||
div.dashboard-widget-submit {
|
||||
border-top-color: #ccc;
|
||||
}
|
||||
|
||||
|
@ -101,10 +99,6 @@ textarea.disabled {
|
|||
background-color: #ccc;
|
||||
}
|
||||
/* #upload-menu li a.upload-tab-link, */
|
||||
li.widget-list-control-item h4.widget-title a:hover,
|
||||
li.widget-list-control-item h4.widget-title a,
|
||||
#dragHelper li.widget-list-control-item h4.widget-title a,
|
||||
#draghelper li.widget-list-control-item h4.widget-title a:visited,
|
||||
.login #backtoblog a:hover,
|
||||
#plugin-information .action-button a,
|
||||
#plugin-information .action-button a:hover,
|
||||
|
@ -112,14 +106,9 @@ li.widget-list-control-item h4.widget-title a,
|
|||
color: #fff;
|
||||
}
|
||||
|
||||
li.widget-list-control-item div.widget-control {
|
||||
background-color: #fff;
|
||||
border-color: #dfdfdf;
|
||||
}
|
||||
|
||||
.metabox-holder .postbox h3,
|
||||
#poststuff .postbox h3,
|
||||
#poststuff .stuffbox h3 {
|
||||
.widget .widget-top,
|
||||
.postbox h3,
|
||||
.stuffbox h3 {
|
||||
background: #dfdfdf url("../images/gray-grad.png") repeat-x left top;
|
||||
text-shadow: #fff 0 1px 0;
|
||||
}
|
||||
|
@ -143,11 +132,6 @@ strong .post-com-count span {
|
|||
background-color: #21759b;
|
||||
}
|
||||
|
||||
ul#widget-list li.widget-list-item h4.widget-title {
|
||||
background-color: #f0f0f0;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.sorthelper {
|
||||
background-color: #ccf3fa;
|
||||
}
|
||||
|
@ -276,7 +260,7 @@ td.help {
|
|||
border-bottom-color: #dadada;
|
||||
}
|
||||
|
||||
.side-info ul, .widget-description {
|
||||
.side-info ul {
|
||||
color: #666;
|
||||
}
|
||||
|
||||
|
@ -429,7 +413,6 @@ a.page-numbers {
|
|||
}
|
||||
|
||||
div#available-widgets-filter,
|
||||
ul#widget-list li.widget-list-item,
|
||||
.commentlist li {
|
||||
border-bottom-color: #ccc;
|
||||
}
|
||||
|
@ -531,10 +514,6 @@ div#plugin-information-header {
|
|||
border-color: #666;
|
||||
}
|
||||
|
||||
#current-widgets .drop-widget-here {
|
||||
background-color: #ffc;
|
||||
}
|
||||
|
||||
#dashboard_secondary div.dashboard-widget-content ul li a {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
@ -543,13 +522,6 @@ input.readonly, textarea.readonly {
|
|||
background-color: #ddd;
|
||||
}
|
||||
|
||||
#dragHelper h4.widget-title,
|
||||
li.widget-list-control-item h4,
|
||||
#dragHelper li.widget-list-control-item h4 {
|
||||
background-color: #2683ae;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
#ed_toolbar input,
|
||||
#ed_reply_toolbar input {
|
||||
background: #fff url("../images/fade-butt.png") repeat-x 0 -2px;
|
||||
|
@ -642,8 +614,8 @@ li.widget-list-control-item h4,
|
|||
background-color: #fff;
|
||||
}
|
||||
|
||||
.metabox-holder .postbox,
|
||||
#poststuff .postbox,
|
||||
.widget,
|
||||
.postbox,
|
||||
#titlediv,
|
||||
#poststuff .postarea,
|
||||
#poststuff .stuffbox,
|
||||
|
@ -654,15 +626,17 @@ li.widget-list-control-item h4,
|
|||
border-color: #dfdfdf;
|
||||
}
|
||||
|
||||
.metabox-holder .postbox,
|
||||
#poststuff .postbox {
|
||||
.widget,
|
||||
.postbox {
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
.widget .widget-top,
|
||||
.ui-sortable .postbox h3 {
|
||||
color: #464646;
|
||||
}
|
||||
|
||||
.widget .widget-top,
|
||||
.ui-sortable .postbox h3:hover {
|
||||
color: #000;
|
||||
}
|
||||
|
@ -1595,3 +1569,8 @@ input[readonly] {
|
|||
.theme-listing br.line {
|
||||
border-bottom-color: #ccc;
|
||||
}
|
||||
|
||||
div.widgets-holder-wrap {
|
||||
background-color: #F1F1F1;
|
||||
border-color: #DDDDDD;
|
||||
}
|
||||
|
|
|
@ -274,6 +274,7 @@ h3 {
|
|||
|
||||
h4 {
|
||||
display: block;
|
||||
font-size: 1em;
|
||||
font-weight: bold;
|
||||
margin: 1.33em 0;
|
||||
}
|
||||
|
|
|
@ -188,11 +188,6 @@ input {
|
|||
line-height: 20px;
|
||||
}
|
||||
|
||||
#the-comment-list .comment-item,
|
||||
ul#widget-list li.widget-list-item {
|
||||
zoom: 100%;
|
||||
}
|
||||
|
||||
#wphead-info {
|
||||
float: right;
|
||||
}
|
||||
|
@ -207,7 +202,7 @@ a.button {
|
|||
padding: 4px 6px;
|
||||
}
|
||||
|
||||
* html div.widget-liquid-left-holder,
|
||||
* html div.widget-liquid-left,
|
||||
* html div.widget-liquid-right {
|
||||
display: block;
|
||||
position: relative;
|
||||
|
@ -227,6 +222,7 @@ a.button {
|
|||
zoom: 100%;
|
||||
}
|
||||
|
||||
#the-comment-list .comment-item,
|
||||
#post-status-info,
|
||||
#wpwrap,
|
||||
#wpcontent,
|
||||
|
@ -239,11 +235,13 @@ a.button {
|
|||
#post-body,
|
||||
#editorcontainer,
|
||||
.tablenav,
|
||||
.widget-control-list,
|
||||
li.widget-list-control-item,
|
||||
.widget-liquid-left,
|
||||
.widget-liquid-right,
|
||||
#widgets-left,
|
||||
.widgets-sortables,
|
||||
#dragHelper,
|
||||
li.widget-list-control-item h4,
|
||||
.widget-sortable,
|
||||
.widget .widget-top,
|
||||
.widget,
|
||||
.widget-control-actions,
|
||||
.tagchecklist,
|
||||
#col-container,
|
||||
|
@ -353,3 +351,23 @@ table.ie-fixed {
|
|||
* html .feature-filter .feature-group li {
|
||||
width: 145px;
|
||||
}
|
||||
|
||||
* html .widget-top .widget-title-action a {
|
||||
background: url("../images/menu-bits.gif") no-repeat scroll 0 -110px;
|
||||
}
|
||||
|
||||
* html .widget {
|
||||
border-color: #dfdfdf;
|
||||
}
|
||||
|
||||
* html div.widget-liquid-left {
|
||||
width: 99%;
|
||||
}
|
||||
|
||||
#wp_inactive_widgets {
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
* html .widgets-sortables {
|
||||
height: 50px;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,4 @@
|
|||
h4.widget-title span {
|
||||
float: right;
|
||||
}
|
||||
h4.widget-title a {
|
||||
float: left;
|
||||
margin-left: 0;
|
||||
margin-right: 1em;
|
||||
}
|
||||
ul#widget-list li.widget-list-item h4.widget-title {
|
||||
float: right;
|
||||
}
|
||||
|
||||
ul#widget-list li.widget-list-item div.widget-description {
|
||||
margin: 0 200px 0 0;
|
||||
padding: 0 4em 0 0;
|
||||
|
@ -19,9 +9,3 @@ ul#widget-list li.widget-list-item div.widget-description {
|
|||
margin-left: 8px;
|
||||
float: right;
|
||||
}
|
||||
li.widget-list-control-item h4.widget-title a,
|
||||
#dragHelper li.widget-list-control-item h4.widget-title a,
|
||||
#draghelper li.widget-list-control-item h4.widget-title a:visited {
|
||||
right: auto;
|
||||
left: 1em;
|
||||
}
|
||||
|
|
|
@ -1,25 +1,55 @@
|
|||
/* 2 column liquid layout */
|
||||
div.widget-liquid-left-holder {
|
||||
div.widget-liquid-left {
|
||||
float: left;
|
||||
clear: left;
|
||||
width: 100%;
|
||||
margin-right: -310px;
|
||||
margin-right: -325px;
|
||||
}
|
||||
|
||||
div.widget-liquid-left {
|
||||
margin-right: 320px;
|
||||
div#widgets-left {
|
||||
margin-right: 335px;
|
||||
}
|
||||
|
||||
div.widget-liquid-right {
|
||||
float: right;
|
||||
clear: right;
|
||||
width: 300px;
|
||||
position: relative;
|
||||
width: 320px;
|
||||
}
|
||||
|
||||
/* pasitioning etc. */
|
||||
form#widgets-filter {
|
||||
position: relative;
|
||||
.widgets-sortables li {
|
||||
width: 300px;
|
||||
margin: 15px 0 18px;
|
||||
}
|
||||
|
||||
#widgets-left .widgets-sortables li,
|
||||
#widgets-left #widget-list li {
|
||||
float: left;
|
||||
margin: 0 15px 18px 3px;
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
.widget-placeholder {
|
||||
border-width: 1px;
|
||||
border-style: dashed;
|
||||
margin-bottom: 20px;
|
||||
height: 25px;
|
||||
width: 298px;
|
||||
}
|
||||
|
||||
div.widgets-holder-wrap {
|
||||
padding: 8px 8px 0;
|
||||
margin: 12px 0;
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
-moz-border-radius: 6px;
|
||||
-khtml-border-radius: 6px;
|
||||
-webkit-border-radius: 6px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
#widgets-left #available-widgets {
|
||||
background-color: transparent;
|
||||
border: 0 none;
|
||||
}
|
||||
|
||||
div#available-widgets-filter {
|
||||
|
@ -31,147 +61,94 @@ ul#widget-list {
|
|||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
min-height: 100px;
|
||||
}
|
||||
|
||||
ul#widget-list li.widget-list-item {
|
||||
padding: .7em 0.9em;
|
||||
margin: 0;
|
||||
border-bottom-width: 1px;
|
||||
border-bottom-style: solid;
|
||||
.widget .widget-top {
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
h4.widget-title span {
|
||||
float: left;
|
||||
.widget-top .widget-title {
|
||||
margin-right: 30px;
|
||||
padding: 7px 9px;
|
||||
}
|
||||
|
||||
h4.widget-title a {
|
||||
.widget-top .widget-title-action {
|
||||
float: right;
|
||||
text-decoration: underline;
|
||||
border-bottom: none;
|
||||
margin-left: 1em;
|
||||
}
|
||||
|
||||
ul#widget-list li.widget-list-item h4.widget-title {
|
||||
position: relative;
|
||||
margin: 0;
|
||||
padding: .5em 1em;
|
||||
width: 200px;
|
||||
float: left;
|
||||
font-size: 13px;
|
||||
-moz-border-radius: 3px;
|
||||
-khtml-border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
#dragHelper h4.widget-title {
|
||||
padding: .5em 1em;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
ul#widget-list li.widget-list-item div.widget-description {
|
||||
.widget-title-action a {
|
||||
display: block;
|
||||
margin: 0 0 0 200px;
|
||||
padding: 0 0 0 4em;
|
||||
font-size: 11px;
|
||||
width: 24px;
|
||||
height: 26px;
|
||||
}
|
||||
|
||||
ul#widget-list li.widget-list-item ul.widget-control-info {
|
||||
.widget-top:hover .widget-title-action a {
|
||||
background: url("../images/menu-bits.gif") no-repeat scroll 0 -110px;
|
||||
}
|
||||
|
||||
.widget .widget-inside {
|
||||
margin: 15px;
|
||||
font-size: 11px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.widget-control,
|
||||
.widget-description {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#available-widgets .widget-description,
|
||||
.widget-liquid-right .widget-control,
|
||||
#wp_inactive_widgets .widget-control {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.widget .widget-control p {
|
||||
margin: 0 0 1em;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.widget-title h4 {
|
||||
margin: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.sidebar-name {
|
||||
margin: 0 0 12px;
|
||||
padding: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.widgets-sortables {
|
||||
min-height: 50px;
|
||||
}
|
||||
|
||||
.widget-control-actions {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.widget-control-actions a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
div#sidebar-info {
|
||||
padding: 0 1em;
|
||||
margin-bottom: 1em;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
ul.widget-control-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0 1em;
|
||||
}
|
||||
|
||||
div#current-widgets p.submit {
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
li.widget-list-control-item {
|
||||
margin: 1em 0;
|
||||
-moz-border-radius: 3px;
|
||||
-khtml-border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
li.widget-list-control-item h4,
|
||||
#dragHelper li.widget-list-control-item h4,
|
||||
li.widget-sortable h4 {
|
||||
margin: 0;
|
||||
cursor: move;
|
||||
font-size: 13px;
|
||||
padding: 0.4em 0.8em;
|
||||
position: relative;
|
||||
-moz-border-radius: 3px;
|
||||
-khtml-border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.widget-control-save,
|
||||
.widget-control-remove {
|
||||
margin-right: 8px;
|
||||
float: left;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
li.widget-list-control-item h4.widget-title a,
|
||||
#dragHelper li.widget-list-control-item h4.widget-title a,
|
||||
#draghelper li.widget-list-control-item h4.widget-title a:visited {
|
||||
right: 1em;
|
||||
}
|
||||
|
||||
li.widget-list-control-item h4.widget-title a:hover {
|
||||
.widget-title a,
|
||||
.widget-title a:hover {
|
||||
text-decoration: none;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
li.widget-list-control-item div.widget-control {
|
||||
border-width: 0 1px 1px;
|
||||
border-style: none solid solid;
|
||||
display: none;
|
||||
padding: 15px;
|
||||
font-size: 11px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
li.widget-list-control-item div.widget-control p {
|
||||
margin: 0 0 1em;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
ul.widget-control-list div.widget-control-actions {
|
||||
padding: 0.5em 0 0;
|
||||
}
|
||||
|
||||
.widget-control-edit {
|
||||
font-size: 10px;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
div#current-widgets {
|
||||
padding-top: 1em;
|
||||
border-width: 1px 0 0;
|
||||
border-style: solid none none;
|
||||
}
|
||||
|
||||
#widget-controls .widefat {
|
||||
width: 92%;
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
#widget-controls select.widefat {
|
||||
width: auto;
|
||||
display: block;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Display list of widgets, either all or matching search.
|
||||
* Display list of the available widgets, either all or matching search.
|
||||
*
|
||||
* The search parameter are search terms separated by spaces.
|
||||
*
|
||||
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
function wp_list_widgets( $show = 'all', $_search = false ) {
|
||||
global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls;
|
||||
|
||||
if ( $_search ) {
|
||||
// sanitize
|
||||
$search = preg_replace( '/[^\w\s]/', '', $_search );
|
||||
|
@ -31,11 +32,11 @@ function wp_list_widgets( $show = 'all', $_search = false ) {
|
|||
$show = 'all';
|
||||
?>
|
||||
|
||||
<ul id='widget-list'>
|
||||
<?php
|
||||
<ul id="widget-list">
|
||||
<?php
|
||||
$no_widgets_shown = true;
|
||||
$already_shown = array();
|
||||
foreach ( $wp_registered_widgets as $name => $widget ) :
|
||||
foreach ( $wp_registered_widgets as $name => $widget ) {
|
||||
if ( 'all' == $show && in_array( $widget['callback'], $already_shown ) ) // We already showed this multi-widget
|
||||
continue;
|
||||
|
||||
|
@ -63,104 +64,30 @@ function wp_list_widgets( $show = 'all', $_search = false ) {
|
|||
|
||||
if ( ! isset( $widget['params'][0] ) )
|
||||
$widget['params'][0] = array();
|
||||
ob_start();
|
||||
$args = wp_list_widget_controls_dynamic_sidebar( array( 0 => array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template', '_show' => $show ), 1 => $widget['params'][0] ) );
|
||||
$sidebar_args = call_user_func_array( 'wp_widget_control', $args );
|
||||
$widget_control_template = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$widget_id = $widget['id']; // save this for later in case we mess with $widget['id']
|
||||
|
||||
$is_multi = false !== strpos( $widget_control_template, '%i%' );
|
||||
if ( !$sidebar || $is_multi ) {
|
||||
$add_query = array(
|
||||
'sidebar' => $sidebar,
|
||||
'key' => false,
|
||||
'edit' => false
|
||||
);
|
||||
if ( 'all' == $show && $is_multi ) {
|
||||
// it's a multi-widget. We only need to show it in the list once.
|
||||
$already_shown[] = $widget['callback'];
|
||||
$num = (int) array_pop( $ids = explode( '-', $widget['id'] ) );
|
||||
$id_base = $wp_registered_widget_controls[$widget['id']]['id_base'];
|
||||
// so that we always add a new one when clicking "add"
|
||||
while ( isset($wp_registered_widgets["$id_base-$num"]) )
|
||||
$num++;
|
||||
$widget['id'] = "$id_base-$num";
|
||||
$add_query['base'] = $id_base;
|
||||
$add_query['key'] = $num;
|
||||
$add_query['sidebar'] = $GLOBALS['sidebar'];
|
||||
}
|
||||
$add_query['add'] = $widget['id'];
|
||||
$action = 'add';
|
||||
$add_url = clean_url( wp_nonce_url( add_query_arg( $add_query ), "add-widget_$widget[id]" ) );
|
||||
} else {
|
||||
$action = 'edit';
|
||||
$edit_url = clean_url( add_query_arg( array(
|
||||
'sidebar' => $sidebar,
|
||||
'edit' => $widget['id'],
|
||||
'key' => array_search( $widget['id'], $sidebars_widgets[$sidebar] ),
|
||||
) ) );
|
||||
|
||||
$widget_control_template = '<textarea rows="1" cols="1">' . htmlspecialchars( $widget_control_template ) . '</textarea>';
|
||||
}
|
||||
|
||||
$widget_control_template = $sidebar_args['before_widget'] . $widget_control_template . $sidebar_args['after_widget'];
|
||||
|
||||
$no_widgets_shown = false;
|
||||
|
||||
$args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template' );
|
||||
|
||||
if ( 'all' != $show && $sidebar_args['_widget_title'] )
|
||||
$widget_title = $sidebar_args['_widget_title'];
|
||||
else
|
||||
$widget_title = $widget['name'];
|
||||
?>
|
||||
if ( isset($wp_registered_widget_controls[$widget['id']]['id_base']) && isset($widget['params'][0]['number']) ) {
|
||||
$id_base = $wp_registered_widget_controls[$widget['id']]['id_base'];
|
||||
$args['_temp_id'] = "$id_base-__i__";
|
||||
$args['_multi_num'] = next_widget_id_number($id_base);
|
||||
$args['_add'] = 'multi';
|
||||
} else {
|
||||
$args['_add'] = 'single';
|
||||
if ( $sidebar )
|
||||
$args['_hide'] = '1';
|
||||
}
|
||||
|
||||
<li id="widget-list-item-<?php echo attribute_escape( $widget['id'] ); ?>" class="widget-list-item">
|
||||
<h4 class="widget-title widget-draggable">
|
||||
|
||||
<span><?php echo $widget_title; ?></span>
|
||||
|
||||
<?php if ( 'add' == $action ) : ?>
|
||||
|
||||
<a class="widget-action widget-control-add" href="<?php echo $add_url; ?>"><?php _e( 'Add' ); ?></a>
|
||||
|
||||
<?php elseif ( 'edit' == $action ) :
|
||||
// We echo a hidden edit link for the sake of the JS. Edit links are shown (needlessly?) after a widget is added.
|
||||
?>
|
||||
|
||||
<a class="widget-action widget-control-edit" href="<?php echo $edit_url; ?>" style="display: none;"><?php _e( 'Edit' ); ?></a>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
</h4>
|
||||
|
||||
|
||||
<ul id="widget-control-info-<?php echo $widget['id']; ?>" class="widget-control-info">
|
||||
|
||||
<?php echo $widget_control_template; ?>
|
||||
|
||||
</ul>
|
||||
|
||||
<?php if ( 'add' == $action ) : ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="widget-description">
|
||||
<?php echo ( $widget_description = wp_widget_description( $widget_id ) ) ? $widget_description : ' '; ?>
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
</li>
|
||||
|
||||
<?php endforeach; if ( $no_widgets_shown ) : ?>
|
||||
|
||||
<li><?php _e( 'No matching widgets' ); ?></li>
|
||||
|
||||
<?php endif; ?>
|
||||
$args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
|
||||
call_user_func_array( 'wp_widget_control', $args );
|
||||
}
|
||||
|
||||
if ( $no_widgets_shown )
|
||||
echo '<li>' . __( 'No matching widgets' ) . "</li>\n";
|
||||
?>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
@ -172,14 +99,12 @@ function wp_list_widgets( $show = 'all', $_search = false ) {
|
|||
*
|
||||
* @param string $sidebar
|
||||
*/
|
||||
function wp_list_widget_controls( $sidebar ) {
|
||||
function wp_list_widget_controls( $sidebar, $hide = false ) {
|
||||
add_filter( 'dynamic_sidebar_params', 'wp_list_widget_controls_dynamic_sidebar' );
|
||||
?>
|
||||
|
||||
<ul class="widget-control-list">
|
||||
|
||||
<?php if ( !dynamic_sidebar( $sidebar ) ) echo "<li />"; ?>
|
||||
|
||||
<ul class="widgets-sortables<?php echo $hide ? ' hide-if-js' : ''; ?>">
|
||||
<?php dynamic_sidebar( $sidebar ); ?>
|
||||
</ul>
|
||||
|
||||
<?php
|
||||
|
@ -199,18 +124,31 @@ function wp_list_widget_controls_dynamic_sidebar( $params ) {
|
|||
$i++;
|
||||
|
||||
$widget_id = $params[0]['widget_id'];
|
||||
$id = isset($params[0]['_temp_id']) ? $params[0]['_temp_id'] : $widget_id;
|
||||
$hidden = isset($params[0]['_hide']) ? ' style="display:none;"' : '';
|
||||
|
||||
$params[0]['before_widget'] = "<li id='widget-list-control-item-$i-$widget_id' class='widget-list-control-item widget-sortable'>\n";
|
||||
$params[0]['before_widget'] = "<li id='widget-${i}_$id' class='widget'$hidden>";
|
||||
$params[0]['after_widget'] = "</li>";
|
||||
$params[0]['before_title'] = "%BEG_OF_TITLE%";
|
||||
$params[0]['after_title'] = "%END_OF_TITLE%";
|
||||
$params[0]['before_title'] = "%BEG_OF_TITLE%"; // deprecated
|
||||
$params[0]['after_title'] = "%END_OF_TITLE%"; // deprecated
|
||||
if ( is_callable( $wp_registered_widgets[$widget_id]['callback'] ) ) {
|
||||
$wp_registered_widgets[$widget_id]['_callback'] = $wp_registered_widgets[$widget_id]['callback'];
|
||||
$wp_registered_widgets[$widget_id]['callback'] = 'wp_widget_control';
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
function next_widget_id_number($id_base) {
|
||||
global $wp_registered_widgets;
|
||||
$number = 2;
|
||||
|
||||
while ( isset($wp_registered_widgets["$id_base-$number"]) )
|
||||
$number++;
|
||||
|
||||
return $number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Meta widget used to display the control form for a widget.
|
||||
*
|
||||
|
@ -222,120 +160,86 @@ function wp_list_widget_controls_dynamic_sidebar( $params ) {
|
|||
* @return array
|
||||
*/
|
||||
function wp_widget_control( $sidebar_args ) {
|
||||
global $wp_registered_widgets, $wp_registered_widget_controls, $sidebars_widgets, $edit_widget;
|
||||
global $wp_registered_widgets, $wp_registered_widget_controls, $sidebars_widgets;
|
||||
|
||||
$widget_id = $sidebar_args['widget_id'];
|
||||
$sidebar_id = isset($sidebar_args['id']) ? $sidebar_args['id'] : false;
|
||||
|
||||
$control = isset($wp_registered_widget_controls[$widget_id]) ? $wp_registered_widget_controls[$widget_id] : 0;
|
||||
$control = isset($wp_registered_widget_controls[$widget_id]) ? $wp_registered_widget_controls[$widget_id] : array();
|
||||
$widget = $wp_registered_widgets[$widget_id];
|
||||
|
||||
$key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : 'no-key'; // position of widget in sidebar
|
||||
|
||||
$edit = -1 < $edit_widget && is_numeric($key) && $edit_widget === $key; // (bool) are we currently editing this widget
|
||||
$edit = isset($_GET['editwidget']); // editing without js
|
||||
$nonce = $edit ? wp_create_nonce("edit-widget_$widget_id") : '';
|
||||
|
||||
$id_format = $widget['id'];
|
||||
|
||||
if ( ! isset( $sidebar_args['_show'] ) )
|
||||
$sidebar_args['_show'] = '';
|
||||
|
||||
if ( ! isset( $sidebar_args['_display'] ) )
|
||||
$sidebar_args['_display'] = '';
|
||||
$widget_number = isset($control['params'][0]['number']) ? $control['params'][0]['number'] : '';
|
||||
$add_new = $sidebar_args['_add'];
|
||||
$id_base = isset($control['id_base']) ? $control['id_base'] : $widget_id;
|
||||
|
||||
// We aren't showing a widget control, we're outputing a template for a mult-widget control
|
||||
if ( 'all' == $sidebar_args['_show'] && 'template' == $sidebar_args['_display'] && isset($control['params'][0]['number']) ) {
|
||||
// number == -1 implies a template where id numbers are replaced by a generic '%i%'
|
||||
if ( isset($sidebar_args['_display']) && 'template' == $sidebar_args['_display'] && $widget_number ) {
|
||||
// number == -1 implies a template where id numbers are replaced by a generic '__i__'
|
||||
$control['params'][0]['number'] = -1;
|
||||
// if given, id_base means widget id's should be constructed like {$id_base}-{$id_number}
|
||||
if ( isset($control['id_base']) )
|
||||
$id_format = $control['id_base'] . '-%i%';
|
||||
$id_format = $control['id_base'] . '-__i__';
|
||||
|
||||
$multi_number = $sidebar_args['_multi_num'];
|
||||
}
|
||||
|
||||
$widget_title = '';
|
||||
// We grab the normal widget output to find the widget's title
|
||||
if ( ( 'all' != $sidebar_args['_show'] || 'template' != $sidebar_args['_display'] ) && is_callable( $widget['_callback'] ) ) {
|
||||
ob_start();
|
||||
$args = func_get_args();
|
||||
call_user_func_array( $widget['_callback'], $args );
|
||||
$widget_title = ob_get_clean();
|
||||
$widget_title = wp_widget_control_ob_filter( $widget_title );
|
||||
}
|
||||
$wp_registered_widgets[$widget_id]['callback'] = $wp_registered_widgets[$widget_id]['_callback'];
|
||||
unset($wp_registered_widgets[$widget_id]['_callback']);
|
||||
|
||||
if ( $widget_title && $widget_title != $sidebar_args['widget_name'] )
|
||||
/* translators: 1: widget name, 2: widget title */
|
||||
$widget_title = sprintf( _x('%1$s: %2$s', 'widget' ), $sidebar_args['widget_name'], $widget_title );
|
||||
else
|
||||
$widget_title = wp_specialchars( strip_tags( $sidebar_args['widget_name'] ) );
|
||||
|
||||
$sidebar_args['_widget_title'] = $widget_title;
|
||||
|
||||
if ( empty($sidebar_args['_display']) || 'template' != $sidebar_args['_display'] )
|
||||
echo $sidebar_args['before_widget'];
|
||||
?>
|
||||
echo $sidebar_args['before_widget']; ?>
|
||||
<div class="widget-top">
|
||||
<h4 class="widget-title"><span><?php echo $widget_title ?></span>
|
||||
<div class="widget-title-action">
|
||||
<?php if ( !$edit ) { ?>
|
||||
<a class="widget-action widget-control-edit" href="<?php echo clean_url( add_query_arg( array( 'edit' => $id_format, 'key' => $key ) ) ); ?>"></a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="widget-title"><h4><?php echo $widget_title ?></h4></div>
|
||||
</div>
|
||||
|
||||
<?php if ( $edit ) : ?>
|
||||
|
||||
<a class="widget-action widget-control-edit" href="<?php echo clean_url( remove_query_arg( array( 'edit', 'key' ) ) ); ?>"><?php _e('Cancel'); ?></a>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<a class="widget-action widget-control-edit" href="<?php echo clean_url( add_query_arg( array( 'edit' => $id_format, 'key' => $key ) ) ); ?>"><?php _e('Edit'); ?></a>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
</h4></div>
|
||||
|
||||
<div class="widget-control"<?php if ( $edit ) echo ' style="display: block;"'; ?>>
|
||||
|
||||
<?php
|
||||
if ( $control )
|
||||
<div class="widget-inside">
|
||||
<form action="" method="post">
|
||||
<div class="widget-control">
|
||||
<?php
|
||||
if ( isset($control['callback']) )
|
||||
call_user_func_array( $control['callback'], $control['params'] );
|
||||
else
|
||||
echo '<p>' . __('There are no options for this widget.') . '</p>';
|
||||
?>
|
||||
echo "\t\t<p>" . __('There are no options for this widget.') . "</p>\n"; ?>
|
||||
|
||||
<input type="hidden" name="widget-id[]" value="<?php echo $id_format; ?>" />
|
||||
<input type="hidden" class="widget-width" value="<?php echo $control['width']; ?>" />
|
||||
<input type="hidden" name="widget-id" class="widget-id" value="<?php echo $id_format; ?>" />
|
||||
<input type="hidden" name="id_base" class="id_base" value="<?php echo $id_base; ?>" />
|
||||
<input type="hidden" name="widget-width" value="<?php echo $control['width']; ?>" />
|
||||
<input type="hidden" name="widget-height" value="<?php echo $control['height']; ?>" />
|
||||
<input type="hidden" name="widget_number" class="widget_number" value="<?php echo $widget_number; ?>" />
|
||||
<input type="hidden" name="add_new" class="add_new" value="<?php echo $add_new; ?>" />
|
||||
<?php
|
||||
if ( isset($multi_number) )
|
||||
echo "\t\t\t<input type='hidden' name='multi_number' class='multi_number' value='$multi_number' />\n"; ?>
|
||||
|
||||
<div class="widget-control-actions">
|
||||
|
||||
<?php if ( $control ) : ?>
|
||||
|
||||
<a class="button widget-action widget-control-save hide-if-no-js edit alignleft" href="#save:<?php echo $id_format; ?>"><?php _e('Done'); ?></a>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<a class="button widget-action widget-control-remove alignright" href="<?php echo clean_url( wp_nonce_url( add_query_arg( array( 'remove' => $id_format, 'key' => $key ) ), "remove-widget_$widget[id]" ) ); ?>"><?php _e('Remove'); ?></a>
|
||||
<a class="button widget-control-remove alignleft" href="<?php echo $edit ? clean_url( add_query_arg( array( 'remove' => $id_format, 'key' => $key, '_wpnonce' => $nonce ) ) ) : '#remove'; ?>"><?php _e('Remove'); ?></a>
|
||||
<?php if ( !empty($control) ) { ?>
|
||||
<a class="button-primary widget-control-save alignright" href="<?php echo $edit ? clean_url( add_query_arg( array( 'save' => $id_format, 'key' => $key, '_wpnonce' => $nonce ) ) ) : '#save'; ?>"><?php _e('Save'); ?></a>
|
||||
<?php } ?>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="widget-description">
|
||||
<?php echo ( $widget_description = wp_widget_description($widget_id) ) ? "$widget_description\n" : "$widget_title\n"; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
if ( empty($sidebar_args['_display']) || 'template' != $sidebar_args['_display'] )
|
||||
echo $sidebar_args['after_widget'];
|
||||
|
||||
return $sidebar_args;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@internal Missing Short Description}}
|
||||
*
|
||||
* @since unknown
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
function wp_widget_control_ob_filter( $string ) {
|
||||
if ( false === $beg = strpos( $string, '%BEG_OF_TITLE%' ) )
|
||||
return '';
|
||||
if ( false === $end = strpos( $string, '%END_OF_TITLE%' ) )
|
||||
return '';
|
||||
$string = substr( $string, $beg + 14 , $end - $beg - 14);
|
||||
$string = str_replace( ' ', ' ', $string );
|
||||
return trim( wp_specialchars( strip_tags( $string ) ) );
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,150 +1,157 @@
|
|||
jQuery(function($) {
|
||||
$('.noscript-action').remove();
|
||||
|
||||
var reminded = false;
|
||||
var lameWidgetReminder = function() {
|
||||
if ( reminded )
|
||||
var wpWidgets;
|
||||
(function($) {
|
||||
|
||||
wpWidgets = {
|
||||
init : function() {
|
||||
var rem;
|
||||
$('h3.sidebar-name').click(function(){
|
||||
var c = $(this).siblings('.widgets-sortables');
|
||||
if ( c.is(':visible') ) {
|
||||
c.hide().sortable('disable');
|
||||
} else {
|
||||
c.show().sortable('enable').sortable('refresh');
|
||||
}
|
||||
$(this).siblings('#widget-list').toggle();
|
||||
});
|
||||
this.addEvents();
|
||||
|
||||
$('#widget-list .widget').draggable({
|
||||
connectToSortable: '.widgets-sortables',
|
||||
handle: '.widget-title',
|
||||
distance: 2,
|
||||
tolerance: 'pointer',
|
||||
// forcePlaceholderSize: true,
|
||||
helper: 'clone',
|
||||
start: function() {
|
||||
wpWidgets.fixWebkit(1);
|
||||
},
|
||||
stop: function(e,ui) {
|
||||
if ( rem )
|
||||
$(rem).hide();
|
||||
rem = '';
|
||||
wpWidgets.fixWebkit();
|
||||
}
|
||||
});
|
||||
|
||||
$('.widgets-sortables').sortable({
|
||||
placeholder: 'widget-placeholder',
|
||||
connectWith: '.widgets-sortables',
|
||||
items: '.widget',
|
||||
handle: '.widget-title',
|
||||
cursor: 'move',
|
||||
distance: 2,
|
||||
tolerance: 'pointer',
|
||||
// forcePlaceholderSize: true,
|
||||
// helper: 'clone',
|
||||
opacity: 0.65,
|
||||
start: function(e,ui) {
|
||||
wpWidgets.fixWebkit(1);
|
||||
},
|
||||
stop: function(e,ui) {
|
||||
var add = ui.item.find('input.add_new').val(), n = ui.item.find('input.multi_number').val(), id = ui.item.attr('id'), sb = $(this).parent().attr('id');
|
||||
|
||||
if ( add ) {
|
||||
if ( 'multi' == add ) {
|
||||
ui.item.html( ui.item.html().replace(/<[^<>]+>/g, function(m){ return m.replace(/__i__/g, n); }) );
|
||||
ui.item.attr( 'id', id.replace(/__i__/g, n) );
|
||||
n++;
|
||||
$('li#' + id).find('input.multi_number').val(n);
|
||||
} else if ( 'single' == add ) {
|
||||
ui.item.attr( 'id', 'new-' + id );
|
||||
rem = 'li#' + id;
|
||||
}
|
||||
wpWidgets.addEvents(ui.item);
|
||||
wpWidgets.save( ui.item.find('form').serializeArray(), sb, 0 );
|
||||
ui.item.find('input.add_new').val('');
|
||||
}
|
||||
wpWidgets.saveOrder(sb);
|
||||
wpWidgets.fixWebkit();
|
||||
},
|
||||
receive: function(e,ui) {
|
||||
if ( !$(this).is(':visible') )
|
||||
$(this).sortable('cancel');
|
||||
}
|
||||
|
||||
}).not(':visible').sortable('disable');
|
||||
},
|
||||
|
||||
saveOrder : function(sb) {
|
||||
$('#' + sb + ' .ajax-feedback').css('visibility', 'visible');
|
||||
var p = {
|
||||
action: 'widgets-order',
|
||||
savewidgets: $('#_wpnonce_widgets').val()
|
||||
};
|
||||
$('.widgets-sortables').each( function() {
|
||||
p[$(this).parent().attr('id')] = $(this).sortable('toArray').join(',');
|
||||
});
|
||||
$.post( ajaxurl, p, function(){
|
||||
$('.ajax-feedback').css('visibility', 'hidden');
|
||||
});
|
||||
},
|
||||
|
||||
save : function(data, sb, del, t) {
|
||||
var a;
|
||||
sb = sb || '';
|
||||
$('#' + sb + ' .ajax-feedback').css('visibility', 'visible');
|
||||
|
||||
a = {
|
||||
action: 'save-widget',
|
||||
savewidgets: $('#_wpnonce_widgets').val(),
|
||||
sidebar: sb
|
||||
};
|
||||
|
||||
if ( del )
|
||||
a['delete_widget'] = 1;
|
||||
|
||||
$.map(data, function(n,i){ a[n.name] = n.value; });
|
||||
|
||||
$.post( ajaxurl, a, function(r){
|
||||
var id;
|
||||
$('.ajax-feedback').css('visibility', 'hidden');
|
||||
if ( !t )
|
||||
return;
|
||||
window.onbeforeunload = function () { return widgetsL10n.lamerReminder };
|
||||
$('h2:first').after( '<div class="updated"><p>' + widgetsL10n.lameReminder + '</p></div>' );
|
||||
$('#current-widgets .submit input[name=save-widgets]').css( 'background-color', '#ffffe0' ).click( function() {
|
||||
window.onbeforeunload = null;
|
||||
} );
|
||||
reminded = true;
|
||||
};
|
||||
|
||||
var increment = 1;
|
||||
|
||||
// Open or close widget control form
|
||||
var toggleWidget = function( li, disableFields ) {
|
||||
var width = li.find('input.widget-width').val();
|
||||
|
||||
// it seems IE chokes on these animations because of the positioning/floating
|
||||
var widgetAnim = $.browser.msie ? function() {
|
||||
var t = $(this);
|
||||
if ( t.is(':visible') ) {
|
||||
if ( disableFields ) { t.find( ':input:enabled' ).not( '[name="widget-id[]"], [name*="[submit]"]' ).attr( 'disabled', 'disabled' ); }
|
||||
li.css( 'marginLeft', 0 );
|
||||
t.siblings('div').children('h4').children('a').text( widgetsL10n.edit );
|
||||
if ( del ) {
|
||||
$(t).parents('li.widget').remove();
|
||||
if ( !a.widget_number ) {
|
||||
id = a['widget-id'];
|
||||
$('#available-widgets .widget-id').each(function(){
|
||||
if ( $(this).val() == id )
|
||||
$(this).parents('li.widget').show();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
t.find( ':disabled' ).attr( 'disabled', '' ); // always enable on open
|
||||
if ( width > 250 )
|
||||
li.css( 'marginLeft', ( width - 250 ) * -1 );
|
||||
t.siblings('div').children('h4').children('a').text( widgetsL10n.cancel );
|
||||
$(t).parents('.widget-inside').hide();
|
||||
}
|
||||
t.toggle();
|
||||
} : function() {
|
||||
var t = $(this);
|
||||
});
|
||||
},
|
||||
|
||||
if ( t.is(':visible') ) {
|
||||
if ( disableFields ) { t.find( ':input:enabled' ).not( '[name="widget-id[]"], [name*="[submit]"]' ).attr( 'disabled', 'disabled' ); }
|
||||
if ( width > 250 )
|
||||
li.animate( { marginLeft: 0 } );
|
||||
t.siblings('div').children('h4').children('a').text( widgetsL10n.edit );
|
||||
} else {
|
||||
t.find( ':disabled' ).attr( 'disabled', '' ); // always enable on open
|
||||
if ( width > 250 )
|
||||
li.animate( { marginLeft: ( width - 250 ) * -1 } );
|
||||
t.siblings('div').children('h4').children('a').text( widgetsL10n.cancel );
|
||||
}
|
||||
t.animate( { height: 'toggle' } );
|
||||
};
|
||||
fixWebkit : function(n) {
|
||||
n = n ? 'none' : '';
|
||||
$('body').css({
|
||||
WebkitUserSelect: n,
|
||||
KhtmlUserSelect: n
|
||||
});
|
||||
},
|
||||
|
||||
return li.children('div.widget-control').each( widgetAnim ).end();
|
||||
};
|
||||
|
||||
// onclick for edit/cancel links
|
||||
var editClick = function() {
|
||||
var q = wpAjax.unserialize( this.href );
|
||||
// if link is in available widgets list, make sure it points to the current sidebar
|
||||
if ( ( q.sidebar && q.sidebar == $('#sidebar').val() ) || q.add ) {
|
||||
var w = q.edit || q.add;
|
||||
toggleWidget( $('#current-sidebar .widget-control-list input[name^="widget-id"][value=' + w + ']').parents('li:first'), false ).blur();
|
||||
addEvents : function(sc) {
|
||||
sc = sc || document;
|
||||
$('a.widget-action', sc).click(function(){
|
||||
$(this).parents('.widget-top').siblings('.widget-inside').toggle();
|
||||
return false;
|
||||
} else if ( q.sidebar ) { // otherwise, redirect to correct page
|
||||
return true;
|
||||
});
|
||||
$('.widget-control-save', sc).click(function(){
|
||||
wpWidgets.save( $(this).parents('form').serializeArray(), $(this).parents('.widgets-holder-wrap').attr('id'), 0, this );
|
||||
return false;
|
||||
});
|
||||
$('.widget-control-remove', sc).click(function(){
|
||||
wpWidgets.save( $(this).parents('form').serializeArray(), $(this).parents('.widgets-holder-wrap').attr('id'), 1, this );
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
// If link is in current widgets list, just open the form
|
||||
toggleWidget( $(this).parents('li:first'), true ).blur();
|
||||
return false;
|
||||
};
|
||||
};
|
||||
$(document).ready(function(){wpWidgets.init();});
|
||||
|
||||
// onclick for add links
|
||||
var addClick = function() {
|
||||
var oldLi = $(this).parents('li:first').find('ul.widget-control-info li');
|
||||
var newLi = oldLi.clone();
|
||||
|
||||
if ( newLi.html().match( /%i%/ ) ) {
|
||||
// supplid form is a template, replace %i% by unique id
|
||||
var i = $('#generated-time').val() + increment.toString();
|
||||
increment++;
|
||||
newLi.html( newLi.html().replace( /%i%/g, i ) );
|
||||
} else {
|
||||
$(this).text( widgetsL10n.edit ).unbind().click( editClick );
|
||||
// save form content in textarea so we don't have any conflicting HTML ids
|
||||
oldLi.html( '<textarea>' + oldLi.html() + '</textarea>' );
|
||||
}
|
||||
|
||||
// add event handlers
|
||||
addWidgetControls( newLi );
|
||||
|
||||
// add widget to sidebar sortable
|
||||
widgetSortable.append( newLi ).SortableAddItem( newLi[0] );
|
||||
|
||||
// increment widget counter
|
||||
var n = parseInt( $('#widget-count').text(), 10 ) + 1;
|
||||
$('#widget-count').text( n.toString() )
|
||||
|
||||
lameWidgetReminder();
|
||||
return false;
|
||||
};
|
||||
|
||||
// add event handlers to all links found in context
|
||||
var addWidgetControls = function( context ) {
|
||||
if ( !context )
|
||||
context = document;
|
||||
|
||||
$('a.widget-control-edit', context).click( editClick );
|
||||
|
||||
// onclick for save links
|
||||
$('a.widget-control-save', context).click( function() {
|
||||
lameWidgetReminder();
|
||||
toggleWidget( $(this).parents('li:first'), false ).blur()
|
||||
return false;
|
||||
} );
|
||||
|
||||
// onclick for remove links
|
||||
$('a.widget-control-remove', context).click( function() {
|
||||
var w = $(this).parents('li:first').find('input[name^="widget-id"]').val();
|
||||
$(this).parents('li:first').remove();
|
||||
var t = $('#widget-list ul#widget-control-info-' + w + ' textarea');
|
||||
t.parent().html( t.text() ).parents('li.widget-list-item:first').children( 'h4' ).children('a.widget-action')
|
||||
.show().text( widgetsL10n.add ).unbind().click( addClick );
|
||||
var n = parseInt( $('#widget-count').text(), 10 ) - 1;
|
||||
$('#widget-count').text( n.toString() )
|
||||
return false;
|
||||
} );
|
||||
}
|
||||
|
||||
addWidgetControls();
|
||||
|
||||
$('a.widget-control-add').click( addClick );
|
||||
|
||||
var widgetSortable;
|
||||
var widgetSortableInit = function() {
|
||||
try { // a hack to make sortables work in jQuery 1.2+ and IE7
|
||||
$('#current-sidebar .widget-control-list').SortableDestroy();
|
||||
} catch(e) {}
|
||||
widgetSortable = $('#current-sidebar .widget-control-list').Sortable( {
|
||||
accept: 'widget-sortable',
|
||||
helperclass: 'sorthelper',
|
||||
handle: 'h4.widget-title',
|
||||
onStop: widgetSortableInit
|
||||
} );
|
||||
}
|
||||
|
||||
// initialize sortable
|
||||
widgetSortableInit();
|
||||
|
||||
});
|
||||
})(jQuery);
|
||||
|
|
|
@ -1 +1 @@
|
|||
jQuery(function(e){e(".noscript-action").remove();var a=false;var h=function(){if(a){return}window.onbeforeunload=function(){return widgetsL10n.lamerReminder};e("h2:first").after('<div class="updated"><p>'+widgetsL10n.lameReminder+"</p></div>");e("#current-widgets .submit input[name=save-widgets]").css("background-color","#ffffe0").click(function(){window.onbeforeunload=null});a=true};var j=1;var g=function(k,m){var l=k.find("input.widget-width").val();var n=e.browser.msie?function(){var o=e(this);if(o.is(":visible")){if(m){o.find(":input:enabled").not('[name="widget-id[]"], [name*="[submit]"]').attr("disabled","disabled")}k.css("marginLeft",0);o.siblings("div").children("h4").children("a").text(widgetsL10n.edit)}else{o.find(":disabled").attr("disabled","");if(l>250){k.css("marginLeft",(l-250)*-1)}o.siblings("div").children("h4").children("a").text(widgetsL10n.cancel)}o.toggle()}:function(){var o=e(this);if(o.is(":visible")){if(m){o.find(":input:enabled").not('[name="widget-id[]"], [name*="[submit]"]').attr("disabled","disabled")}if(l>250){k.animate({marginLeft:0})}o.siblings("div").children("h4").children("a").text(widgetsL10n.edit)}else{o.find(":disabled").attr("disabled","");if(l>250){k.animate({marginLeft:(l-250)*-1})}o.siblings("div").children("h4").children("a").text(widgetsL10n.cancel)}o.animate({height:"toggle"})};return k.children("div.widget-control").each(n).end()};var b=function(){var l=wpAjax.unserialize(this.href);if((l.sidebar&&l.sidebar==e("#sidebar").val())||l.add){var k=l.edit||l.add;g(e('#current-sidebar .widget-control-list input[name^="widget-id"][value='+k+"]").parents("li:first"),false).blur();return false}else{if(l.sidebar){return true}}g(e(this).parents("li:first"),true).blur();return false};var c=function(){var o=e(this).parents("li:first").find("ul.widget-control-info li");var l=o.clone();if(l.html().match(/%i%/)){var k=e("#generated-time").val()+j.toString();j++;l.html(l.html().replace(/%i%/g,k))}else{e(this).text(widgetsL10n.edit).unbind().click(b);o.html("<textarea>"+o.html()+"</textarea>")}f(l);i.append(l).SortableAddItem(l[0]);var m=parseInt(e("#widget-count").text(),10)+1;e("#widget-count").text(m.toString());h();return false};var f=function(k){if(!k){k=document}e("a.widget-control-edit",k).click(b);e("a.widget-control-save",k).click(function(){h();g(e(this).parents("li:first"),false).blur();return false});e("a.widget-control-remove",k).click(function(){var l=e(this).parents("li:first").find('input[name^="widget-id"]').val();e(this).parents("li:first").remove();var m=e("#widget-list ul#widget-control-info-"+l+" textarea");m.parent().html(m.text()).parents("li.widget-list-item:first").children("h4").children("a.widget-action").show().text(widgetsL10n.add).unbind().click(c);var o=parseInt(e("#widget-count").text(),10)-1;e("#widget-count").text(o.toString());return false})};f();e("a.widget-control-add").click(c);var i;var d=function(){try{e("#current-sidebar .widget-control-list").SortableDestroy()}catch(k){}i=e("#current-sidebar .widget-control-list").Sortable({accept:"widget-sortable",helperclass:"sorthelper",handle:"h4.widget-title",onStop:d})};d()});
|
||||
var wpWidgets;(function(a){wpWidgets={init:function(){var b;a("h3.sidebar-name").click(function(){var d=a(this).siblings(".widgets-sortables");if(d.is(":visible")){d.hide().sortable("disable")}else{d.show().sortable("enable").sortable("refresh")}a(this).siblings("#widget-list").toggle()});this.addEvents();a("#widget-list .widget").draggable({connectToSortable:".widgets-sortables",handle:".widget-title",distance:2,tolerance:"pointer",helper:"clone",start:function(){wpWidgets.fixWebkit(1)},stop:function(d,c){if(b){a(b).hide()}b="";wpWidgets.fixWebkit()}});a(".widgets-sortables").sortable({placeholder:"widget-placeholder",connectWith:".widgets-sortables",items:".widget",handle:".widget-title",cursor:"move",distance:2,tolerance:"pointer",opacity:0.65,start:function(d,c){wpWidgets.fixWebkit(1)},stop:function(f,c){var d=c.item.find("input.add_new").val(),i=c.item.find("input.multi_number").val(),h=c.item.attr("id"),g=a(this).parent().attr("id");if(d){if("multi"==d){c.item.html(c.item.html().replace(/<[^<>]+>/g,function(e){return e.replace(/__i__/g,i)}));c.item.attr("id",h.replace(/__i__/g,i));i++;a("li#"+h).find("input.multi_number").val(i)}else{if("single"==d){c.item.attr("id","new-"+h);b="li#"+h}}wpWidgets.addEvents(c.item);wpWidgets.save(c.item.find("form").serializeArray(),g,0);c.item.find("input.add_new").val("")}wpWidgets.saveOrder(g);wpWidgets.fixWebkit()},receive:function(d,c){if(!a(this).is(":visible")){a(this).sortable("cancel")}}}).not(":visible").sortable("disable")},saveOrder:function(c){a("#"+c+" .ajax-feedback").css("visibility","visible");var b={action:"widgets-order",savewidgets:a("#_wpnonce_widgets").val()};a(".widgets-sortables").each(function(){b[a(this).parent().attr("id")]=a(this).sortable("toArray").join(",")});a.post(ajaxurl,b,function(){a(".ajax-feedback").css("visibility","hidden")})},save:function(e,f,c,d){var b;f=f||"";a("#"+f+" .ajax-feedback").css("visibility","visible");b={action:"save-widget",savewidgets:a("#_wpnonce_widgets").val(),sidebar:f};if(c){b.delete_widget=1}a.map(e,function(h,g){b[h.name]=h.value});a.post(ajaxurl,b,function(g){var h;a(".ajax-feedback").css("visibility","hidden");if(!d){return}if(c){a(d).parents("li.widget").remove();if(!b.widget_number){h=b["widget-id"];a("#available-widgets .widget-id").each(function(){if(a(this).val()==h){a(this).parents("li.widget").show()}})}}else{a(d).parents(".widget-inside").hide()}})},fixWebkit:function(b){b=b?"none":"";a("body").css({WebkitUserSelect:b,KhtmlUserSelect:b})},addEvents:function(b){b=b||document;a("a.widget-action",b).click(function(){a(this).parents(".widget-top").siblings(".widget-inside").toggle();return false});a(".widget-control-save",b).click(function(){wpWidgets.save(a(this).parents("form").serializeArray(),a(this).parents(".widgets-holder-wrap").attr("id"),0,this);return false});a(".widget-control-remove",b).click(function(){wpWidgets.save(a(this).parents("form").serializeArray(),a(this).parents(".widgets-holder-wrap").attr("id"),1,this);return false})}};a(document).ready(function(){wpWidgets.init()})})(jQuery);
|
|
@ -15,7 +15,7 @@ require_once(ABSPATH . 'wp-admin/includes/widgets.php');
|
|||
if ( ! current_user_can('switch_themes') )
|
||||
wp_die( __( 'Cheatin’ uh?' ));
|
||||
|
||||
wp_enqueue_script( array( 'wp-lists', 'admin-widgets' ) );
|
||||
wp_enqueue_script('admin-widgets');
|
||||
wp_admin_css( 'widgets' );
|
||||
|
||||
do_action( 'sidebar_admin_setup' );
|
||||
|
@ -23,14 +23,72 @@ do_action( 'sidebar_admin_setup' );
|
|||
$title = __( 'Widgets' );
|
||||
$parent_file = 'themes.php';
|
||||
|
||||
// $sidebar = What sidebar are we editing?
|
||||
if ( isset($_GET['sidebar']) && isset($wp_registered_sidebars[$_GET['sidebar']]) ) {
|
||||
$sidebar = attribute_escape( $_GET['sidebar'] );
|
||||
} elseif ( is_array($wp_registered_sidebars) && !empty($wp_registered_sidebars) ) {
|
||||
// By default we look at the first defined sidebar
|
||||
$sidebar = array_shift( $keys = array_keys($wp_registered_sidebars) );
|
||||
} else {
|
||||
// If no sidebars, die.
|
||||
// register the inactive_widgets area as sidebar
|
||||
register_sidebar(array(
|
||||
'name' => '',
|
||||
'id' => 'wp_inactive_widgets',
|
||||
'before_widget' => '',
|
||||
'after_widget' => '',
|
||||
'before_title' => '',
|
||||
'after_title' => '',
|
||||
));
|
||||
|
||||
// These are the widgets grouped by sidebar
|
||||
$sidebars_widgets = wp_get_sidebars_widgets();
|
||||
if ( empty( $sidebars_widgets ) )
|
||||
$sidebars_widgets = wp_get_widget_defaults();
|
||||
|
||||
// look for "lost" widgets, perhaps run only after changin themes
|
||||
function retrieve_widgets() {
|
||||
global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets;
|
||||
|
||||
$key_sidebars = array_keys( (array) $wp_registered_sidebars);
|
||||
$key_widgets = array_keys($sidebars_widgets);
|
||||
if ( count($key_widgets) > count($key_sidebars) ) {
|
||||
$changed_sidebars = array_diff( $key_widgets, $key_sidebars );
|
||||
foreach ( $changed_sidebars as $lost ) {
|
||||
if ( is_array($sidebars_widgets[$lost]) )
|
||||
$sidebars_widgets['wp_inactive_widgets'] = array_merge( (array) $sidebars_widgets['wp_inactive_widgets'], $sidebars_widgets[$lost] );
|
||||
unset($sidebars_widgets[$lost]);
|
||||
}
|
||||
}
|
||||
|
||||
$shown_widgets = array();
|
||||
foreach ( $sidebars_widgets as $sidebar ) {
|
||||
if ( is_array($sidebar) )
|
||||
$shown_widgets = array_merge($shown_widgets, $sidebar);
|
||||
}
|
||||
|
||||
$all_widgets = array();
|
||||
foreach ( $wp_registered_widget_updates as $key => $val ) {
|
||||
if ( isset($val['id_base']) )
|
||||
$all_widgets[] = $val['id_base'];
|
||||
else
|
||||
$all_widgets[] = $key;
|
||||
}
|
||||
|
||||
$all_widgets = array_unique($all_widgets);
|
||||
|
||||
$lost_widgets = array();
|
||||
foreach ( $all_widgets as $name ) {
|
||||
$data = get_option( str_replace('-', '_', "widget_$name") );
|
||||
if ( is_array($data) ) {
|
||||
foreach ( $data as $num => $value ) {
|
||||
if ( !is_numeric($num) ) // skip single widgets, some don't delete their settings
|
||||
continue;
|
||||
if ( is_array($value) && !in_array("$name-$num", $shown_widgets, true) )
|
||||
$lost_widgets[] = "$name-$num";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']);
|
||||
wp_set_sidebars_widgets($sidebars_widgets);
|
||||
}
|
||||
retrieve_widgets();
|
||||
|
||||
if ( count($wp_registered_sidebars) == 1 ) {
|
||||
// If only the "wp_inactive_widgets" is defined the theme has no sidebars, die.
|
||||
require_once( 'admin-header.php' );
|
||||
?>
|
||||
|
||||
|
@ -48,172 +106,7 @@ if ( isset($_GET['sidebar']) && isset($wp_registered_sidebars[$_GET['sidebar']])
|
|||
exit;
|
||||
}
|
||||
|
||||
// These are the widgets grouped by sidebar
|
||||
$sidebars_widgets = wp_get_sidebars_widgets();
|
||||
if ( empty( $sidebars_widgets ) )
|
||||
$sidebars_widgets = wp_get_widget_defaults();
|
||||
|
||||
// for the sake of PHP warnings
|
||||
if ( empty( $sidebars_widgets[$sidebar] ) )
|
||||
$sidebars_widgets[$sidebar] = array();
|
||||
|
||||
$http_post = 'post' == strtolower($_SERVER['REQUEST_METHOD']);
|
||||
|
||||
// We're updating a sidebar
|
||||
if ( $http_post && isset($sidebars_widgets[$_POST['sidebar']]) ) {
|
||||
check_admin_referer( 'edit-sidebar_' . $_POST['sidebar'] );
|
||||
|
||||
/* Hack #1
|
||||
* The widget_control is overloaded. It updates the widget's options AND echoes out the widget's HTML form.
|
||||
* Since we want to update before sending out any headers, we have to catch it with an output buffer,
|
||||
*/
|
||||
ob_start();
|
||||
/* There can be multiple widgets of the same type, but the widget_control for that
|
||||
* widget type needs only be called once if it's a multi-widget.
|
||||
*/
|
||||
$already_done = array();
|
||||
|
||||
foreach ( $wp_registered_widget_updates as $name => $control ) {
|
||||
if ( in_array( $control['callback'], $already_done ) )
|
||||
continue;
|
||||
|
||||
if ( is_callable( $control['callback'] ) ) {
|
||||
call_user_func_array( $control['callback'], $control['params'] );
|
||||
$control_output = ob_get_contents();
|
||||
if ( false !== strpos( $control_output, '%i%' ) ) // if it's a multi-widget, only call control function once.
|
||||
$already_done[] = $control['callback'];
|
||||
}
|
||||
|
||||
ob_clean();
|
||||
}
|
||||
ob_end_clean();
|
||||
|
||||
// Prophylactic. Take out empty ids.
|
||||
if ( isset($_POST['widget-id']) ) {
|
||||
foreach ( (array) $_POST['widget-id'] as $key => $val ) {
|
||||
if ( !$val )
|
||||
unset($_POST['widget-id'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the key numbering and store
|
||||
$new_sidebar = isset( $_POST['widget-id'] ) && is_array( $_POST['widget-id'] ) ? array_values( $_POST['widget-id'] ) : array();
|
||||
$sidebars_widgets[$_POST['sidebar']] = $new_sidebar;
|
||||
wp_set_sidebars_widgets( $sidebars_widgets );
|
||||
|
||||
wp_redirect( add_query_arg( 'message', 'updated' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
// What widget (if any) are we editing
|
||||
$edit_widget = -1;
|
||||
|
||||
$query_args = array('add', 'remove', 'key', 'edit', '_wpnonce', 'message', 'base' );
|
||||
|
||||
if ( isset($_GET['add']) && $_GET['add'] ) {
|
||||
// Add to the end of the sidebar
|
||||
$control_callback;
|
||||
if ( isset($wp_registered_widgets[$_GET['add']]) ) {
|
||||
check_admin_referer( "add-widget_$_GET[add]" );
|
||||
$sidebars_widgets[$sidebar][] = $_GET['add'];
|
||||
wp_set_sidebars_widgets( $sidebars_widgets );
|
||||
} elseif ( isset($_GET['base']) && isset($_GET['key']) ) { // It's a multi-widget
|
||||
check_admin_referer( "add-widget_$_GET[add]" );
|
||||
// Copy minimal info from an existing instance of this widget to a new instance
|
||||
foreach ( $wp_registered_widget_controls as $control ) {
|
||||
if ( $_GET['base'] === $control['id_base'] ) {
|
||||
$control_callback = $control['callback'];
|
||||
$num = (int) $_GET['key'];
|
||||
$control['params'][0]['number'] = $num;
|
||||
$control['id'] = $control['id_base'] . '-' . $num;
|
||||
$wp_registered_widget_controls[$control['id']] = $control;
|
||||
$sidebars_widgets[$sidebar][] = $control['id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// it's a multi-widget. The only way to add multi-widgets without JS is to actually submit POST content...
|
||||
// so here we go
|
||||
if ( is_callable( $control_callback ) ) {
|
||||
require_once( 'admin-header.php' );
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h2><?php _e( 'Add Widget' ); ?></h2>
|
||||
<br />
|
||||
<form action="<?php echo clean_url( remove_query_arg( $query_args ) ); ?>" method="post">
|
||||
|
||||
<ul class="widget-control-list">
|
||||
<li class="widget-list-control-item">
|
||||
<div class="widget-top">
|
||||
<h4 class="widget-title"><?php echo $control['name']; ?></h4>
|
||||
</div>
|
||||
<div class="widget-control" style="display: block;">
|
||||
<?php
|
||||
call_user_func_array( $control_callback, $control['params'] );
|
||||
?>
|
||||
<div class="widget-control-actions">
|
||||
<input type="submit" class="button" value="<?php _e( 'Add Widget' ); ?>" />
|
||||
<input type="hidden" id='sidebar' name='sidebar' value="<?php echo $sidebar; ?>" />
|
||||
<?php wp_nonce_field ( 'edit-sidebar_' . $sidebar );
|
||||
foreach ( $sidebars_widgets[$sidebar] as $sidebar_widget_id ) : ?>
|
||||
<input type="hidden" name='widget-id[]' value="<?php echo $sidebar_widget_id; ?>" />
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
require_once( 'admin-footer.php' );
|
||||
exit;
|
||||
}
|
||||
wp_redirect( remove_query_arg( $query_args ) );
|
||||
exit;
|
||||
} elseif ( isset($_GET['remove']) && $_GET['remove'] && isset($_GET['key']) && is_numeric($_GET['key']) ) {
|
||||
// Remove from sidebar the widget of type $_GET['remove'] and in position $_GET['key']
|
||||
$key = (int) $_GET['key'];
|
||||
if ( -1 < $key && ( $keys = array_keys($sidebars_widgets[$sidebar], $_GET['remove']) ) && in_array($key, $keys) ) {
|
||||
check_admin_referer( "remove-widget_$_GET[remove]" );
|
||||
unset($sidebars_widgets[$sidebar][$key]);
|
||||
$sidebars_widgets[$sidebar] = array_values($sidebars_widgets[$sidebar]);
|
||||
wp_set_sidebars_widgets( $sidebars_widgets );
|
||||
}
|
||||
wp_redirect( remove_query_arg( $query_args ) );
|
||||
exit;
|
||||
} elseif ( isset($_GET['edit']) && $_GET['edit'] && isset($_GET['key']) && is_numeric($_GET['key']) ) {
|
||||
// Edit widget of type $_GET['edit'] and position $_GET['key']
|
||||
$key = (int) $_GET['key'];
|
||||
if ( -1 < $key && ( $keys = array_keys($sidebars_widgets[$sidebar], $_GET['edit']) ) && in_array($key, $keys) )
|
||||
$edit_widget = $key;
|
||||
}
|
||||
|
||||
// Total number of registered sidebars
|
||||
$sidebar_widget_count = count($sidebars_widgets[$sidebar]);
|
||||
|
||||
// This is sort of lame since "widget" won't be converted to "widgets" in the JS
|
||||
if ( 1 < $sidebars_count = count($wp_registered_sidebars) )
|
||||
$sidebar_info_text = _n( 'You are using %1$s widget in the "%2$s" sidebar.', 'You are using %1$s widgets in the "%2$s" sidebar.', $sidebar_widget_count );
|
||||
else
|
||||
$sidebar_info_text = _n( 'You are using %1$s widget in the sidebar.', 'You are using %1$s widgets in the sidebar.', $sidebar_widget_count );
|
||||
|
||||
|
||||
$sidebar_info_text = sprintf( wp_specialchars( $sidebar_info_text ), "<span id='widget-count'>$sidebar_widget_count</span>", $wp_registered_sidebars[$sidebar]['name'] );
|
||||
|
||||
$page = isset($_GET['apage']) ? abs( (int) $_GET['apage'] ) : 1;
|
||||
|
||||
/* TODO: Paginate widgets list
|
||||
$page_links = paginate_links( array(
|
||||
'base' => add_query_arg( 'apage', '%#%' ),
|
||||
'format' => '',
|
||||
'total' => ceil(($total = 105 )/ 10),
|
||||
'current' => $page
|
||||
));
|
||||
*/
|
||||
$page_links = ' ';
|
||||
|
||||
/*
|
||||
// Unsanitized!
|
||||
$widget_search = isset($_GET['s']) ? $_GET['s'] : false;
|
||||
|
||||
|
@ -223,6 +116,7 @@ $show_values = array(
|
|||
'unused' => __( 'Show unused widgets' ),
|
||||
'used' => __( 'Show used widgets' )
|
||||
);
|
||||
*/
|
||||
|
||||
$show = isset($_GET['show']) && isset($show_values[$_GET['show']]) ? attribute_escape( $_GET['show'] ) : false;
|
||||
|
||||
|
@ -236,10 +130,16 @@ require_once( 'admin-header.php' ); ?>
|
|||
<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<div id="message" class="updated"><p>This page is not 100% ready, please use only on test installations.</p></div>
|
||||
|
||||
|
||||
<div class="wrap">
|
||||
<?php screen_icon(); ?>
|
||||
<h2><?php echo wp_specialchars( $title ); ?></h2>
|
||||
|
||||
|
||||
<!--
|
||||
<form id="widgets-filter" action="" method="get">
|
||||
|
||||
<div class="widget-liquid-left-holder">
|
||||
|
@ -247,13 +147,13 @@ require_once( 'admin-header.php' ); ?>
|
|||
<h3><label for="show"><?php _e('Available Widgets'); ?></label></h3>
|
||||
<div class="nav">
|
||||
<select name="show" id="show">
|
||||
<?php foreach ( $show_values as $show_value => $show_text ) : $show_value = attribute_escape( $show_value ); ?>
|
||||
<option value='<?php echo $show_value; ?>'<?php selected( $show_value, $show ); ?>><?php echo wp_specialchars( $show_text ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
<?php //foreach ( $show_values as $show_value => $show_text ) : $show_value = attribute_escape( $show_value ); ?>
|
||||
<option value='<?php //echo $show_value; ?>'<?php //selected( $show_value, $show ); ?>><?php //echo wp_specialchars( $show_text ); ?></option>
|
||||
<?php //endforeach; ?>
|
||||
</select>
|
||||
<input type="submit" value="<?php _e('Show' ); ?>" class="button-secondary" />
|
||||
<p class="pagenav">
|
||||
<?php echo $page_links; ?>
|
||||
<?php // echo $page_links; ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -264,9 +164,9 @@ require_once( 'admin-header.php' ); ?>
|
|||
|
||||
<div class="nav">
|
||||
<select id="sidebar-selector" name="sidebar">
|
||||
<?php foreach ( $wp_registered_sidebars as $sidebar_id => $registered_sidebar ) : $sidebar_id = attribute_escape( $sidebar_id ); ?>
|
||||
<option value='<?php echo $sidebar_id; ?>'<?php selected( $sidebar_id, $sidebar ); ?>><?php echo wp_specialchars( $registered_sidebar['name'] ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
<?php //foreach ( $wp_registered_sidebars as $sidebar_id => $registered_sidebar ) : $sidebar_id = attribute_escape( $sidebar_id ); ?>
|
||||
<option value='<?php //echo $sidebar_id; ?>'<?php selected( $sidebar_id, $open_sidebar ); ?>><?php //echo wp_specialchars( $registered_sidebar['name'] ); ?></option>
|
||||
<?php //endforeach; ?>
|
||||
</select>
|
||||
<input type="submit" value="<?php _e('Show' ); ?>" class="button-secondary" />
|
||||
</div>
|
||||
|
@ -274,56 +174,58 @@ require_once( 'admin-header.php' ); ?>
|
|||
</div>
|
||||
|
||||
</form>
|
||||
-->
|
||||
|
||||
<div id="widget-content" class="widget-liquid-left-holder">
|
||||
<div class="widget-liquid-left">
|
||||
<div id="widgets-left">
|
||||
<div id="available-widgets" class="widgets-holder-wrap">
|
||||
<h3 class="sidebar-name"><?php _e('Available Widgets'); ?></h3>
|
||||
<?php wp_list_widgets(); ?>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
|
||||
<div id="available-widgets" class="widget-liquid-left">
|
||||
|
||||
<?php wp_list_widgets( $show, $widget_search ); // This lists all the widgets for the query ( $show, $search ) ?>
|
||||
|
||||
<div class="nav">
|
||||
<p class="pagenav">
|
||||
<?php echo $page_links; ?>
|
||||
</p>
|
||||
<div id="wp_inactive_widgets" class="widgets-holder-wrap">
|
||||
<h3 class="sidebar-name"><?php _e('Inactive Widgets'); ?>
|
||||
<span><img src="images/loading-publish.gif" class="ajax-feedback" title="" alt="" /></span></h3>
|
||||
<?php wp_list_widget_controls('wp_inactive_widgets'); ?>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form id="widget-controls" action="" method="post">
|
||||
|
||||
<!--
|
||||
<div id="current-widgets-head" class="widget-liquid-right">
|
||||
|
||||
<div id="sidebar-info">
|
||||
<p><?php echo $sidebar_info_text; ?></p>
|
||||
<p><?php //echo $sidebar_info_text; ?></p>
|
||||
<p><?php _e( 'Add more from the Available Widgets section.' ); ?></p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
-->
|
||||
|
||||
<div id="current-widgets" class="widget-liquid-right">
|
||||
<div id="current-sidebar">
|
||||
|
||||
<?php wp_list_widget_controls( $sidebar ); // Show the control forms for each of the widgets in this sidebar ?>
|
||||
|
||||
</div>
|
||||
|
||||
<p class="submit">
|
||||
<input type="hidden" id='sidebar' name='sidebar' value="<?php echo $sidebar; ?>" />
|
||||
<input type="hidden" id="generated-time" name="generated-time" value="<?php echo time() - 1199145600; // Jan 1, 2008 ?>" />
|
||||
<input type="submit" name="save-widgets" class="button-primary" value="<?php _e( 'Save Changes' ); ?>" />
|
||||
<div class="widget-liquid-right">
|
||||
<?php
|
||||
wp_nonce_field( 'edit-sidebar_' . $sidebar );
|
||||
?>
|
||||
</p>
|
||||
$i = 0;
|
||||
foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) {
|
||||
if ( 'wp_inactive_widgets' == $sidebar )
|
||||
continue;
|
||||
?>
|
||||
<div id="<?php echo attribute_escape( $sidebar ); ?>" class="widgets-holder-wrap">
|
||||
<h3 class="sidebar-name"><?php echo wp_specialchars( $registered_sidebar['name'] ); ?>
|
||||
<span><img src="images/loading-publish.gif" class="ajax-feedback" title="" alt="" /></span></h3>
|
||||
<?php wp_list_widget_controls( $sidebar, $i ); // Show the control forms for each of the widgets in this sidebar ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$i++;
|
||||
} ?>
|
||||
</div>
|
||||
<form action="" method="post">
|
||||
<?php wp_nonce_field( 'save-sidebar-widgets', '_wpnonce_widgets', false ); ?>
|
||||
</form>
|
||||
<br class="clear" />
|
||||
|
||||
</div>
|
||||
|
||||
<?php do_action( 'sidebar_admin_page' ); ?>
|
||||
|
||||
<?php require_once( 'admin-footer.php' ); ?>
|
||||
|
||||
|
||||
<?php
|
||||
do_action( 'sidebar_admin_page' );
|
||||
require_once( 'admin-footer.php' );
|
||||
|
|
|
@ -1544,19 +1544,20 @@ table.form-table td .updated {
|
|||
clear: left;
|
||||
}
|
||||
|
||||
.ui-sortable .postbox h3 {
|
||||
cursor: pointer;
|
||||
.widget .widget-top,
|
||||
.postbox h3 {
|
||||
cursor: move;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-khtml-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.ui-sortable .postbox .hndle span {
|
||||
.postbox .hndle span {
|
||||
padding: 6px 0;
|
||||
}
|
||||
|
||||
.ui-sortable .postbox .hndle {
|
||||
.postbox .hndle {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
|
@ -1569,7 +1570,7 @@ table.form-table td .updated {
|
|||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.meta-box-sortables .postbox .handlediv {
|
||||
.postbox .handlediv {
|
||||
float: right;
|
||||
width: 23px;
|
||||
height: 26px;
|
||||
|
@ -1590,9 +1591,9 @@ table.form-table td .updated {
|
|||
line-height: 1;
|
||||
}
|
||||
|
||||
.metabox-holder .postbox,
|
||||
#poststuff .postbox,
|
||||
#poststuff .stuffbox {
|
||||
.widget,
|
||||
.postbox,
|
||||
.stuffbox {
|
||||
margin-bottom: 20px;
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
|
@ -1603,9 +1604,10 @@ table.form-table td .updated {
|
|||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.metabox-holder .postbox h3,
|
||||
#poststuff .postbox h3,
|
||||
#poststuff .stuffbox h3 {
|
||||
.widget .widget-top,
|
||||
.postbox h3,
|
||||
.postbox h3,
|
||||
.stuffbox h3 {
|
||||
-moz-border-radius: 6px 6px 0 0;
|
||||
-webkit-border-top-right-radius: 6px;
|
||||
-webkit-border-top-left-radius: 6px;
|
||||
|
@ -3050,3 +3052,8 @@ p.popular-tags a {
|
|||
.stuffbox .editcomment {
|
||||
clear: none;
|
||||
}
|
||||
|
||||
.ajax-feedback {
|
||||
visibility: hidden;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ class WP_Widget_Links extends WP_Widget {
|
|||
?>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('category'); ?>">
|
||||
<select id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>" style="width: 97%;" />
|
||||
<select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
|
||||
<option value=""><?php _e('All Links'); ?></option>
|
||||
<?php
|
||||
foreach ( $link_cats as $link_cat ) {
|
||||
|
@ -149,7 +149,8 @@ class WP_Widget_Links extends WP_Widget {
|
|||
. '>' . $link_cat->name . "</option>\n";
|
||||
}
|
||||
?>
|
||||
</select></label><br />
|
||||
</select></label></p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('images'); ?>">
|
||||
<input class="checkbox" type="checkbox" <?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" /> <?php _e('Show Link Image'); ?></label><br />
|
||||
<label for="<?php echo $this->get_field_id('name'); ?>">
|
||||
|
@ -184,6 +185,12 @@ class WP_Widget_Search extends WP_Widget {
|
|||
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
function form( $instance ) { ?>
|
||||
<input name="<?php echo $this->get_field_name('title'); ?>" type="hidden" value="" />
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -882,7 +889,7 @@ function wp_widget_rss_control($widget_args) {
|
|||
$url = '';
|
||||
$items = 10;
|
||||
$error = false;
|
||||
$number = '%i%';
|
||||
$number = '__i__';
|
||||
$show_summary = 0;
|
||||
$show_author = 0;
|
||||
$show_date = 0;
|
||||
|
|
|
@ -330,15 +330,8 @@ function wp_default_scripts( &$scripts ) {
|
|||
$scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox' ), '20090114' );
|
||||
$scripts->add_data( 'media-upload', 'group', 1 );
|
||||
|
||||
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'interface' ), '20090106' );
|
||||
$scripts->localize( 'admin-widgets', 'widgetsL10n', array(
|
||||
'add' => __('Add'),
|
||||
'edit' => __('Edit'),
|
||||
'cancel' => __('Cancel'),
|
||||
'lameReminder' => __('Remember to click the "Save Changes" button at the bottom of the Current Widgets column after you\'re all done!'),
|
||||
'lamerReminder' => __("You're about to leave without having saved your changes!"),
|
||||
'l10n_print_after' => 'try{convertEntities(widgetsL10n);}catch(e){};'
|
||||
));
|
||||
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable' ), '20090411' );
|
||||
$scripts->add_data( 'admin-widgets', 'group', 1 );
|
||||
|
||||
$scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), '20090102' );
|
||||
$scripts->add_data( 'word-count', 'group', 1 );
|
||||
|
@ -425,21 +418,21 @@ function wp_default_styles( &$styles ) {
|
|||
|
||||
$rtl_styles = array( 'global', 'colors', 'dashboard', 'ie', 'install', 'login', 'media', 'theme-editor', 'upload', 'widgets', 'press-this', 'plugin-install', 'farbtastic' );
|
||||
|
||||
$styles->add( 'wp-admin', '/wp-admin/wp-admin.css', array(), '20090405' );
|
||||
$styles->add( 'wp-admin', '/wp-admin/wp-admin.css', array(), '20090411' );
|
||||
$styles->add_data( 'wp-admin', 'rtl', '/wp-admin/rtl.css' );
|
||||
|
||||
$styles->add( 'ie', '/wp-admin/css/ie.css', array(), '20090407' );
|
||||
$styles->add( 'ie', '/wp-admin/css/ie.css', array(), '20090411' );
|
||||
$styles->add_data( 'ie', 'conditional', 'lte IE 7' );
|
||||
|
||||
$styles->add( 'colors', true, array(), '20090405' ); // Register "meta" stylesheet for admin colors
|
||||
$styles->add( 'colors', true, array(), '20090411' ); // Register "meta" stylesheet for admin colors
|
||||
$styles->add( 'colors-fresh', '/wp-admin/css/colors-fresh.css', array(), '20081210'); // for login.php. Is there a better way?
|
||||
$styles->add_data( 'colors-fresh', 'rtl', true );
|
||||
$styles->add( 'colors-classic', '/wp-admin/css/colors-classic.css', array(), '20081210');
|
||||
$styles->add_data( 'colors-classic', 'rtl', true );
|
||||
|
||||
$styles->add( 'global', '/wp-admin/css/global.css', array(), '20090407' );
|
||||
$styles->add( 'global', '/wp-admin/css/global.css', array(), '20090411' );
|
||||
$styles->add( 'media', '/wp-admin/css/media.css', array(), '20090325' );
|
||||
$styles->add( 'widgets', '/wp-admin/css/widgets.css', array(), '20081210' );
|
||||
$styles->add( 'widgets', '/wp-admin/css/widgets.css', array(), '20090411' );
|
||||
$styles->add( 'dashboard', '/wp-admin/css/dashboard.css', array(), '20090305' );
|
||||
$styles->add( 'install', '/wp-admin/css/install.css', array(), '20081210' );
|
||||
$styles->add( 'theme-editor', '/wp-admin/css/theme-editor.css', array(), '20081210' );
|
||||
|
|
|
@ -49,10 +49,11 @@ class WP_Widget {
|
|||
*
|
||||
* This function should check that $new_instance is set correctly.
|
||||
* The newly calculated value of $instance should be returned.
|
||||
* If "false" is returned, the instance won't be saved/updated.
|
||||
*
|
||||
* @param array $new_instance New settings for this instance as input by the user via form()
|
||||
* @param array $old_instance Old settings for this instance
|
||||
* @return array Settings to save
|
||||
* @return array Settings to save or bool false to cancel saving
|
||||
*/
|
||||
function update($new_instance, $old_instance) {
|
||||
return $new_instance;
|
||||
|
@ -191,35 +192,34 @@ class WP_Widget {
|
|||
else
|
||||
$this_sidebar = array();
|
||||
|
||||
foreach ( $this_sidebar as $_widget_id ) {
|
||||
// Remove all widgets of this type from the sidebar. We'll add the
|
||||
// new data in a second. This makes sure we don't get any duplicate
|
||||
// data since widget ids aren't necessarily persistent across multiple
|
||||
// updates
|
||||
if ( $this->_get_display_callback() == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
|
||||
$number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
|
||||
if( !in_array( $this->id_base . '-' . $number, (array)$_POST['widget-id'] ) ) {
|
||||
// the widget has been removed.
|
||||
if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
|
||||
// Delete the settings for this instance of the widget
|
||||
if ( isset($_POST['widget-id']) )
|
||||
$del_id = $_POST['widget-id'];
|
||||
else
|
||||
return;
|
||||
|
||||
if ( $this->_get_display_callback() == $wp_registered_widgets[$del_id]['callback'] && isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) {
|
||||
$number = $wp_registered_widgets[$del_id]['params'][0]['number'];
|
||||
|
||||
if ( $this->id_base . '-' . $number == $del_id ) {
|
||||
unset($all_instances[$number]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
foreach ( (array) $_POST['widget-' . $this->id_base] as $number => $new_instance ) {
|
||||
$new_instance = stripslashes_deep($new_instance);
|
||||
$this->_set($number);
|
||||
|
||||
if ( !isset($new_instance['submit']) )
|
||||
continue;
|
||||
|
||||
if ( isset($all_instances[$number]) )
|
||||
$instance = $this->update($new_instance, $all_instances[$number]);
|
||||
else
|
||||
$instance = $this->update($new_instance, array());
|
||||
|
||||
if ( !empty($instance) )
|
||||
if ( false !== $instance )
|
||||
$all_instances[$number] = $instance;
|
||||
}
|
||||
}
|
||||
|
||||
$this->save_settings($all_instances);
|
||||
$this->updated = true;
|
||||
|
@ -236,8 +236,8 @@ class WP_Widget {
|
|||
$all_instances = $this->get_settings();
|
||||
|
||||
if ( -1 == $widget_args['number'] ) {
|
||||
// We echo out a form where 'number' can be set later via JS
|
||||
$this->_set('%i%');
|
||||
// We echo out a form where 'number' can be set later
|
||||
$this->_set('__i__');
|
||||
$instance = array();
|
||||
} else {
|
||||
$this->_set($widget_args['number']);
|
||||
|
@ -245,15 +245,12 @@ class WP_Widget {
|
|||
}
|
||||
|
||||
$this->form($instance);
|
||||
?>
|
||||
<input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />
|
||||
<?php
|
||||
}
|
||||
|
||||
/** Helper function: Registers a single instance. */
|
||||
function _register_one($number = -1) {
|
||||
wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) );
|
||||
_register_widget_update_callback( $this->id, $this->name, $this->_get_update_callback(), $this->control_options, array( 'number' => $number ) );
|
||||
_register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) );
|
||||
_register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) );
|
||||
}
|
||||
|
||||
|
@ -579,10 +576,11 @@ function wp_register_widget_control($id, $name, $control_callback, $options = ar
|
|||
global $wp_registered_widget_controls, $wp_registered_widget_updates;
|
||||
|
||||
$id = strtolower($id);
|
||||
$update_id = preg_replace( '/-[0-9]+$/', '', $id );
|
||||
|
||||
if ( empty($control_callback) ) {
|
||||
unset($wp_registered_widget_controls[$id]);
|
||||
unset($wp_registered_widget_updates[$id]);
|
||||
unset($wp_registered_widget_updates[$update_id]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -602,36 +600,34 @@ function wp_register_widget_control($id, $name, $control_callback, $options = ar
|
|||
);
|
||||
$widget = array_merge($widget, $options);
|
||||
|
||||
$wp_registered_widget_controls[$id] = $wp_registered_widget_updates[$id] = $widget;
|
||||
$wp_registered_widget_controls[$id] = $widget;
|
||||
|
||||
if ( isset($wp_registered_widget_updates[$update_id]) )
|
||||
return;
|
||||
|
||||
if ( isset($widget['params'][0]['number']) )
|
||||
$widget['params'][0]['number'] = -1;
|
||||
|
||||
unset($widget['width'], $widget['height'], $widget['name'], $widget['id']);
|
||||
$wp_registered_widget_updates[$update_id] = $widget;
|
||||
}
|
||||
|
||||
function _register_widget_update_callback($id, $name, $update_callback, $options = array()) {
|
||||
function _register_widget_update_callback($id_base, $update_callback, $options = array()) {
|
||||
global $wp_registered_widget_updates;
|
||||
|
||||
$id = strtolower($id);
|
||||
|
||||
if ( empty($update_callback) ) {
|
||||
unset($wp_registered_widget_updates[$id]);
|
||||
if ( isset($wp_registered_widget_updates[$id_base]) ) {
|
||||
if ( empty($update_callback) )
|
||||
unset($wp_registered_widget_updates[$id_base]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset($wp_registered_widget_updates[$id]) && !did_action( 'widgets_init' ) )
|
||||
return;
|
||||
|
||||
$defaults = array('width' => 250, 'height' => 200 ); // height is never used
|
||||
$options = wp_parse_args($options, $defaults);
|
||||
$options['width'] = (int) $options['width'];
|
||||
$options['height'] = (int) $options['height'];
|
||||
|
||||
$widget = array(
|
||||
'name' => $name,
|
||||
'id' => $id,
|
||||
'callback' => $update_callback,
|
||||
'params' => array_slice(func_get_args(), 4)
|
||||
'params' => array_slice(func_get_args(), 3)
|
||||
);
|
||||
$widget = array_merge($widget, $options);
|
||||
|
||||
$wp_registered_widget_updates[$id] = $widget;
|
||||
$widget = array_merge($widget, $options);
|
||||
$wp_registered_widget_updates[$id_base] = $widget;
|
||||
}
|
||||
|
||||
function _register_widget_form_callback($id, $name, $form_callback, $options = array()) {
|
||||
|
@ -647,7 +643,7 @@ function _register_widget_form_callback($id, $name, $form_callback, $options = a
|
|||
if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) )
|
||||
return;
|
||||
|
||||
$defaults = array('width' => 250, 'height' => 200 ); // height is never used
|
||||
$defaults = array('width' => 250, 'height' => 200 );
|
||||
$options = wp_parse_args($options, $defaults);
|
||||
$options['width'] = (int) $options['width'];
|
||||
$options['height'] = (int) $options['height'];
|
||||
|
|
Loading…
Reference in New Issue