Changeset 50995
- Timestamp:
- 05/25/2021 08:26:21 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-widget-factory.php
r50994 r50995 103 103 } 104 104 } 105 106 /** 107 * Returns the registered WP_Widget object for the given widget type. 108 * 109 * @since 5.8.0 110 * 111 * @param string $id_base Widget type ID. 112 * @return WP_Widget|null 113 */ 114 public function get_widget_object( $id_base ) { 115 foreach ( $this->widgets as $widget_object ) { 116 if ( $widget_object->id_base === $id_base ) { 117 return $widget_object; 118 } 119 } 120 121 return null; 122 } 105 123 } -
trunk/src/wp-includes/default-widgets.php
r50994 r50995 64 64 /** WP_Widget_Custom_HTML class */ 65 65 require_once ABSPATH . WPINC . '/widgets/class-wp-widget-custom-html.php'; 66 67 /** WP_Widget_Block class */ 68 require_once ABSPATH . WPINC . '/widgets/class-wp-widget-block.php'; -
trunk/src/wp-includes/rest-api.php
r50994 r50995 312 312 // Plugins. 313 313 $controller = new WP_REST_Plugins_Controller(); 314 $controller->register_routes(); 315 316 // Sidebars. 317 $controller = new WP_REST_Sidebars_Controller(); 318 $controller->register_routes(); 319 320 // Widget Types. 321 $controller = new WP_REST_Widget_Types_Controller(); 322 $controller->register_routes(); 323 324 // Widgets. 325 $controller = new WP_REST_Widgets_Controller(); 314 326 $controller->register_routes(); 315 327 -
trunk/src/wp-includes/widgets.php
r50994 r50995 358 358 * @since 5.3.0 Formalized the existing and already documented `...$params` parameter 359 359 * by adding it to the function signature. 360 * @since 5.8.0 Added show_instance_in_rest option. 360 361 * 361 362 * @global array $wp_registered_widgets Uses stored registered widgets. … … 370 371 * Optional. An array of supplementary widget options for the instance. 371 372 * 372 * @type string $classname Class name for the widget's HTML container. Default is a shortened 373 * version of the output callback name. 374 * @type string $description Widget description for display in the widget administration 375 * panel and/or theme. 373 * @type string $classname Class name for the widget's HTML container. Default is a shortened 374 * version of the output callback name. 375 * @type string $description Widget description for display in the widget administration 376 * panel and/or theme. 377 * @type bool $show_instance_in_rest Whether to show the widget's instance settings in the REST API. 378 * Only available for WP_Widget based widgets. 376 379 * } 377 380 * @param mixed ...$params Optional additional parameters to pass to the callback function when it's called. … … 1797 1800 register_widget( 'WP_Widget_Custom_HTML' ); 1798 1801 1802 register_widget( 'WP_Widget_Block' ); 1803 1799 1804 /** 1800 1805 * Fires after all default WordPress widgets have been registered. … … 1804 1809 do_action( 'widgets_init' ); 1805 1810 } 1811 1812 /** 1813 * Converts a widget ID into its id_base and number components. 1814 * 1815 * @since 5.8.0 1816 * 1817 * @param string $id Widget ID. 1818 * @return array Array containing a widget's id_base and number components. 1819 */ 1820 function wp_parse_widget_id( $id ) { 1821 $parsed = array(); 1822 1823 if ( preg_match( '/^(.+)-(\d+)$/', $id, $matches ) ) { 1824 $parsed['id_base'] = $matches[1]; 1825 $parsed['number'] = (int) $matches[2]; 1826 } else { 1827 // Likely an old single widget. 1828 $parsed['id_base'] = $id; 1829 } 1830 1831 return $parsed; 1832 } 1833 1834 /** 1835 * Finds the sidebar that a given widget belongs to. 1836 * 1837 * @since 5.8.0 1838 * 1839 * @param string $widget_id The widget id to look for. 1840 * @return string|null The found sidebar's id, or null if it was not found. 1841 */ 1842 function wp_find_widgets_sidebar( $widget_id ) { 1843 foreach ( wp_get_sidebars_widgets() as $sidebar_id => $widget_ids ) { 1844 foreach ( $widget_ids as $maybe_widget_id ) { 1845 if ( $maybe_widget_id === $widget_id ) { 1846 return (string) $sidebar_id; 1847 } 1848 } 1849 } 1850 1851 return null; 1852 } 1853 1854 /** 1855 * Assigns a widget to the given sidebar. 1856 * 1857 * @since 5.8.0 1858 * 1859 * @param string $widget_id The widget id to assign. 1860 * @param string $sidebar_id The sidebar id to assign to. If empty, the widget won't be added to any sidebar. 1861 */ 1862 function wp_assign_widget_to_sidebar( $widget_id, $sidebar_id ) { 1863 $sidebars = wp_get_sidebars_widgets(); 1864 1865 foreach ( $sidebars as $maybe_sidebar_id => $widgets ) { 1866 foreach ( $widgets as $i => $maybe_widget_id ) { 1867 if ( $widget_id === $maybe_widget_id && $sidebar_id !== $maybe_sidebar_id ) { 1868 unset( $sidebars[ $maybe_sidebar_id ][ $i ] ); 1869 // We could technically break 2 here, but continue looping in case the id is duplicated. 1870 continue 2; 1871 } 1872 } 1873 } 1874 1875 if ( $sidebar_id ) { 1876 $sidebars[ $sidebar_id ][] = $widget_id; 1877 } 1878 1879 wp_set_sidebars_widgets( $sidebars ); 1880 } 1881 1882 /** 1883 * Calls the render callback of a widget and returns the output. 1884 * 1885 * @since 5.8.0 1886 * 1887 * @param string $widget_id Widget ID. 1888 * @param string $sidebar_id Sidebar ID. 1889 * @return string 1890 */ 1891 function wp_render_widget( $widget_id, $sidebar_id ) { 1892 global $wp_registered_widgets, $wp_registered_sidebars; 1893 1894 if ( ! isset( $wp_registered_widgets[ $widget_id ] ) ) { 1895 return ''; 1896 } 1897 1898 if ( isset( $wp_registered_sidebars[ $sidebar_id ] ) ) { 1899 $sidebar = $wp_registered_sidebars[ $sidebar_id ]; 1900 } elseif ( 'wp_inactive_widgets' === $sidebar_id ) { 1901 $sidebar = array(); 1902 } else { 1903 return ''; 1904 } 1905 1906 $params = array_merge( 1907 array( 1908 array_merge( 1909 $sidebar, 1910 array( 1911 'widget_id' => $widget_id, 1912 'widget_name' => $wp_registered_widgets[ $widget_id ]['name'], 1913 ) 1914 ), 1915 ), 1916 (array) $wp_registered_widgets[ $widget_id ]['params'] 1917 ); 1918 1919 // Substitute HTML `id` and `class` attributes into `before_widget`. 1920 $classname_ = ''; 1921 foreach ( (array) $wp_registered_widgets[ $widget_id ]['classname'] as $cn ) { 1922 if ( is_string( $cn ) ) { 1923 $classname_ .= '_' . $cn; 1924 } elseif ( is_object( $cn ) ) { 1925 $classname_ .= '_' . get_class( $cn ); 1926 } 1927 } 1928 $classname_ = ltrim( $classname_, '_' ); 1929 $params[0]['before_widget'] = sprintf( $params[0]['before_widget'], $widget_id, $classname_ ); 1930 1931 /** This filter is documented in wp-includes/widgets.php */ 1932 $params = apply_filters( 'dynamic_sidebar_params', $params ); 1933 1934 $callback = $wp_registered_widgets[ $widget_id ]['callback']; 1935 1936 ob_start(); 1937 1938 /** This filter is documented in wp-includes/widgets.php */ 1939 do_action( 'dynamic_sidebar', $wp_registered_widgets[ $widget_id ] ); 1940 1941 if ( is_callable( $callback ) ) { 1942 call_user_func_array( $callback, $params ); 1943 } 1944 1945 return ob_get_clean(); 1946 } 1947 1948 /** 1949 * Calls the control callback of a widget and returns the output. 1950 * 1951 * @since 5.8.0 1952 * 1953 * @param string $id Widget ID. 1954 * @return string|null 1955 */ 1956 function wp_render_widget_control( $id ) { 1957 global $wp_registered_widget_controls; 1958 1959 if ( ! isset( $wp_registered_widget_controls[ $id ]['callback'] ) ) { 1960 return null; 1961 } 1962 1963 $callback = $wp_registered_widget_controls[ $id ]['callback']; 1964 $params = $wp_registered_widget_controls[ $id ]['params']; 1965 1966 ob_start(); 1967 1968 if ( is_callable( $callback ) ) { 1969 call_user_func_array( $callback, $params ); 1970 } 1971 1972 return ob_get_clean(); 1973 } -
trunk/src/wp-includes/widgets/class-wp-nav-menu-widget.php
r50994 r50995 26 26 'description' => __( 'Add a navigation menu to your sidebar.' ), 27 27 'customize_selective_refresh' => true, 28 'show_instance_in_rest' => true, 28 29 ); 29 30 parent::__construct( 'nav_menu', __( 'Navigation Menu' ), $widget_ops ); -
trunk/src/wp-includes/widgets/class-wp-widget-archives.php
r50994 r50995 27 27 'description' => __( 'A monthly archive of your site’s Posts.' ), 28 28 'customize_selective_refresh' => true, 29 'show_instance_in_rest' => true, 29 30 ); 30 31 parent::__construct( 'archives', __( 'Archives' ), $widget_ops ); -
trunk/src/wp-includes/widgets/class-wp-widget-calendar.php
r50994 r50995 34 34 'description' => __( 'A calendar of your site’s posts.' ), 35 35 'customize_selective_refresh' => true, 36 'show_instance_in_rest' => true, 36 37 ); 37 38 parent::__construct( 'calendar', __( 'Calendar' ), $widget_ops ); -
trunk/src/wp-includes/widgets/class-wp-widget-categories.php
r50994 r50995 27 27 'description' => __( 'A list or dropdown of categories.' ), 28 28 'customize_selective_refresh' => true, 29 'show_instance_in_rest' => true, 29 30 ); 30 31 parent::__construct( 'categories', __( 'Categories' ), $widget_ops ); -
trunk/src/wp-includes/widgets/class-wp-widget-custom-html.php
r50994 r50995 46 46 'description' => __( 'Arbitrary HTML code.' ), 47 47 'customize_selective_refresh' => true, 48 'show_instance_in_rest' => true, 48 49 ); 49 50 $control_ops = array( -
trunk/src/wp-includes/widgets/class-wp-widget-media.php
r50994 r50995 60 60 'description' => __( 'A media item.' ), 61 61 'customize_selective_refresh' => true, 62 'show_instance_in_rest' => true, 62 63 'mime_type' => '', 63 64 ) -
trunk/src/wp-includes/widgets/class-wp-widget-meta.php
r50994 r50995 29 29 'description' => __( 'Login, RSS, & WordPress.org links.' ), 30 30 'customize_selective_refresh' => true, 31 'show_instance_in_rest' => true, 31 32 ); 32 33 parent::__construct( 'meta', __( 'Meta' ), $widget_ops ); -
trunk/src/wp-includes/widgets/class-wp-widget-pages.php
r50994 r50995 27 27 'description' => __( 'A list of your site’s Pages.' ), 28 28 'customize_selective_refresh' => true, 29 'show_instance_in_rest' => true, 29 30 ); 30 31 parent::__construct( 'pages', __( 'Pages' ), $widget_ops ); -
trunk/src/wp-includes/widgets/class-wp-widget-recent-comments.php
r50994 r50995 27 27 'description' => __( 'Your site’s most recent comments.' ), 28 28 'customize_selective_refresh' => true, 29 'show_instance_in_rest' => true, 29 30 ); 30 31 parent::__construct( 'recent-comments', __( 'Recent Comments' ), $widget_ops ); -
trunk/src/wp-includes/widgets/class-wp-widget-recent-posts.php
r50994 r50995 27 27 'description' => __( 'Your site’s most recent Posts.' ), 28 28 'customize_selective_refresh' => true, 29 'show_instance_in_rest' => true, 29 30 ); 30 31 parent::__construct( 'recent-posts', __( 'Recent Posts' ), $widget_ops ); -
trunk/src/wp-includes/widgets/class-wp-widget-rss.php
r50994 r50995 26 26 'description' => __( 'Entries from any RSS or Atom feed.' ), 27 27 'customize_selective_refresh' => true, 28 'show_instance_in_rest' => true, 29 28 30 ); 29 31 $control_ops = array( -
trunk/src/wp-includes/widgets/class-wp-widget-search.php
r50994 r50995 27 27 'description' => __( 'A search form for your site.' ), 28 28 'customize_selective_refresh' => true, 29 'show_instance_in_rest' => true, 29 30 ); 30 31 parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops ); -
trunk/src/wp-includes/widgets/class-wp-widget-tag-cloud.php
r50994 r50995 26 26 'description' => __( 'A cloud of your most used tags.' ), 27 27 'customize_selective_refresh' => true, 28 'show_instance_in_rest' => true, 28 29 ); 29 30 parent::__construct( 'tag_cloud', __( 'Tag Cloud' ), $widget_ops ); -
trunk/src/wp-includes/widgets/class-wp-widget-text.php
r50994 r50995 35 35 'description' => __( 'Arbitrary text.' ), 36 36 'customize_selective_refresh' => true, 37 'show_instance_in_rest' => true, 37 38 ); 38 39 $control_ops = array( -
trunk/src/wp-settings.php
r50994 r50995 266 266 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-application-passwords-controller.php'; 267 267 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-site-health-controller.php'; 268 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-sidebars-controller.php'; 269 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-widget-types-controller.php'; 270 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-widgets-controller.php'; 268 271 require ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-meta-fields.php'; 269 272 require ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-comment-meta-fields.php'; -
trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php
r50994 r50995 135 135 '/wp/v2/plugins/(?P<plugin>[^.\/]+(?:\/[^.\/]+)?)', 136 136 '/wp/v2/block-directory/search', 137 '/wp/v2/sidebars', 138 '/wp/v2/sidebars/(?P<id>[\w-]+)', 139 '/wp/v2/widget-types', 140 '/wp/v2/widget-types/(?P<id>[a-zA-Z0-9_-]+)', 141 '/wp/v2/widget-types/(?P<id>[a-zA-Z0-9_-]+)/encode', 142 '/wp/v2/widgets', 143 '/wp/v2/widgets/(?P<id>[\w\-]+)', 137 144 '/wp-site-health/v1', 138 145 '/wp-site-health/v1/tests/background-updates', -
trunk/tests/qunit/fixtures/wp-api-generated.js
r50994 r50995 6417 6417 ] 6418 6418 }, 6419 "/wp/v2/sidebars": { 6420 "namespace": "wp/v2", 6421 "methods": [ 6422 "GET" 6423 ], 6424 "endpoints": [ 6425 { 6426 "methods": [ 6427 "GET" 6428 ], 6429 "args": { 6430 "context": { 6431 "description": "Scope under which the request is made; determines fields present in response.", 6432 "type": "string", 6433 "enum": [ 6434 "view", 6435 "embed", 6436 "edit" 6437 ], 6438 "default": "view", 6439 "required": false 6440 } 6441 } 6442 } 6443 ], 6444 "_links": { 6445 "self": [ 6446 { 6447 "href": "http://example.org/index.php?rest_route=/wp/v2/sidebars" 6448 } 6449 ] 6450 } 6451 }, 6452 "/wp/v2/sidebars/(?P<id>[\\w-]+)": { 6453 "namespace": "wp/v2", 6454 "methods": [ 6455 "GET", 6456 "POST", 6457 "PUT", 6458 "PATCH" 6459 ], 6460 "endpoints": [ 6461 { 6462 "methods": [ 6463 "GET" 6464 ], 6465 "args": { 6466 "id": { 6467 "description": "The id of a registered sidebar", 6468 "type": "string", 6469 "required": false 6470 }, 6471 "context": { 6472 "description": "Scope under which the request is made; determines fields present in response.", 6473 "type": "string", 6474 "enum": [ 6475 "view", 6476 "embed", 6477 "edit" 6478 ], 6479 "default": "view", 6480 "required": false 6481 } 6482 } 6483 }, 6484 { 6485 "methods": [ 6486 "POST", 6487 "PUT", 6488 "PATCH" 6489 ], 6490 "args": { 6491 "widgets": { 6492 "description": "Nested widgets.", 6493 "type": "array", 6494 "items": { 6495 "type": [ 6496 "object", 6497 "string" 6498 ] 6499 }, 6500 "required": false 6501 } 6502 } 6503 } 6504 ] 6505 }, 6506 "/wp/v2/widget-types": { 6507 "namespace": "wp/v2", 6508 "methods": [ 6509 "GET" 6510 ], 6511 "endpoints": [ 6512 { 6513 "methods": [ 6514 "GET" 6515 ], 6516 "args": { 6517 "context": { 6518 "description": "Scope under which the request is made; determines fields present in response.", 6519 "type": "string", 6520 "enum": [ 6521 "view", 6522 "embed", 6523 "edit" 6524 ], 6525 "default": "view", 6526 "required": false 6527 } 6528 } 6529 } 6530 ], 6531 "_links": { 6532 "self": [ 6533 { 6534 "href": "http://example.org/index.php?rest_route=/wp/v2/widget-types" 6535 } 6536 ] 6537 } 6538 }, 6539 "/wp/v2/widget-types/(?P<id>[a-zA-Z0-9_-]+)": { 6540 "namespace": "wp/v2", 6541 "methods": [ 6542 "GET" 6543 ], 6544 "endpoints": [ 6545 { 6546 "methods": [ 6547 "GET" 6548 ], 6549 "args": { 6550 "id": { 6551 "description": "The widget type id.", 6552 "type": "string", 6553 "required": false 6554 }, 6555 "context": { 6556 "description": "Scope under which the request is made; determines fields present in response.", 6557 "type": "string", 6558 "enum": [ 6559 "view", 6560 "embed", 6561 "edit" 6562 ], 6563 "default": "view", 6564 "required": false 6565 } 6566 } 6567 } 6568 ] 6569 }, 6570 "/wp/v2/widget-types/(?P<id>[a-zA-Z0-9_-]+)/encode": { 6571 "namespace": "wp/v2", 6572 "methods": [ 6573 "POST" 6574 ], 6575 "endpoints": [ 6576 { 6577 "methods": [ 6578 "POST" 6579 ], 6580 "args": { 6581 "id": { 6582 "description": "The widget type id.", 6583 "type": "string", 6584 "required": true 6585 }, 6586 "instance": { 6587 "description": "Current instance settings of the widget.", 6588 "type": "object", 6589 "required": false 6590 }, 6591 "form_data": { 6592 "description": "Serialized widget form data to encode into instance settings.", 6593 "type": "string", 6594 "required": false 6595 } 6596 } 6597 } 6598 ] 6599 }, 6600 "/wp/v2/widgets": { 6601 "namespace": "wp/v2", 6602 "methods": [ 6603 "GET", 6604 "POST" 6605 ], 6606 "endpoints": [ 6607 { 6608 "methods": [ 6609 "GET" 6610 ], 6611 "args": { 6612 "context": { 6613 "description": "Scope under which the request is made; determines fields present in response.", 6614 "type": "string", 6615 "enum": [ 6616 "view", 6617 "embed", 6618 "edit" 6619 ], 6620 "default": "view", 6621 "required": false 6622 }, 6623 "sidebar": { 6624 "description": "The sidebar to return widgets for.", 6625 "type": "string", 6626 "required": false 6627 } 6628 } 6629 }, 6630 { 6631 "methods": [ 6632 "POST" 6633 ], 6634 "args": { 6635 "id": { 6636 "description": "Unique identifier for the widget.", 6637 "type": "string", 6638 "required": false 6639 }, 6640 "id_base": { 6641 "description": "The type of the widget. Corresponds to ID in widget-types endpoint.", 6642 "type": "string", 6643 "required": false 6644 }, 6645 "sidebar": { 6646 "default": "wp_inactive_widgets", 6647 "description": "The sidebar the widget belongs to.", 6648 "type": "string", 6649 "required": true 6650 }, 6651 "instance": { 6652 "description": "Instance settings of the widget, if supported.", 6653 "type": "object", 6654 "properties": { 6655 "encoded": { 6656 "description": "Base64 encoded representation of the instance settings.", 6657 "type": "string", 6658 "context": [ 6659 "view", 6660 "edit", 6661 "embed" 6662 ] 6663 }, 6664 "hash": { 6665 "description": "Cryptographic hash of the instance settings.", 6666 "type": "string", 6667 "context": [ 6668 "view", 6669 "edit", 6670 "embed" 6671 ] 6672 }, 6673 "raw": { 6674 "description": "Unencoded instance settings, if supported.", 6675 "type": "object", 6676 "context": [ 6677 "view", 6678 "edit", 6679 "embed" 6680 ] 6681 } 6682 }, 6683 "required": false 6684 }, 6685 "form_data": { 6686 "description": "URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only.", 6687 "type": "string", 6688 "required": false 6689 } 6690 } 6691 } 6692 ], 6693 "_links": { 6694 "self": [ 6695 { 6696 "href": "http://example.org/index.php?rest_route=/wp/v2/widgets" 6697 } 6698 ] 6699 } 6700 }, 6701 "/wp/v2/widgets/(?P<id>[\\w\\-]+)": { 6702 "namespace": "wp/v2", 6703 "methods": [ 6704 "GET", 6705 "POST", 6706 "PUT", 6707 "PATCH", 6708 "DELETE" 6709 ], 6710 "endpoints": [ 6711 { 6712 "methods": [ 6713 "GET" 6714 ], 6715 "args": { 6716 "context": { 6717 "description": "Scope under which the request is made; determines fields present in response.", 6718 "type": "string", 6719 "enum": [ 6720 "view", 6721 "embed", 6722 "edit" 6723 ], 6724 "default": "view", 6725 "required": false 6726 } 6727 } 6728 }, 6729 { 6730 "methods": [ 6731 "POST", 6732 "PUT", 6733 "PATCH" 6734 ], 6735 "args": { 6736 "id": { 6737 "description": "Unique identifier for the widget.", 6738 "type": "string", 6739 "required": false 6740 }, 6741 "id_base": { 6742 "description": "The type of the widget. Corresponds to ID in widget-types endpoint.", 6743 "type": "string", 6744 "required": false 6745 }, 6746 "sidebar": { 6747 "description": "The sidebar the widget belongs to.", 6748 "type": "string", 6749 "required": false 6750 }, 6751 "instance": { 6752 "description": "Instance settings of the widget, if supported.", 6753 "type": "object", 6754 "properties": { 6755 "encoded": { 6756 "description": "Base64 encoded representation of the instance settings.", 6757 "type": "string", 6758 "context": [ 6759 "view", 6760 "edit", 6761 "embed" 6762 ] 6763 }, 6764 "hash": { 6765 "description": "Cryptographic hash of the instance settings.", 6766 "type": "string", 6767 "context": [ 6768 "view", 6769 "edit", 6770 "embed" 6771 ] 6772 }, 6773 "raw": { 6774 "description": "Unencoded instance settings, if supported.", 6775 "type": "object", 6776 "context": [ 6777 "view", 6778 "edit", 6779 "embed" 6780 ] 6781 } 6782 }, 6783 "required": false 6784 }, 6785 "form_data": { 6786 "description": "URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only.", 6787 "type": "string", 6788 "required": false 6789 } 6790 } 6791 }, 6792 { 6793 "methods": [ 6794 "DELETE" 6795 ], 6796 "args": { 6797 "force": { 6798 "description": "Whether to force removal of the widget, or move it to the inactive sidebar.", 6799 "type": "boolean", 6800 "required": false 6801 } 6802 } 6803 } 6804 ] 6805 }, 6419 6806 "/wp/v2/block-directory/search": { 6420 6807 "namespace": "wp/v2",
Note: See TracChangeset
for help on using the changeset viewer.