2007-05-25 03:16:21 -04:00
< ? php
2008-10-01 21:03:26 -04:00
/**
* Template WordPress Administration API .
*
* A Big Mess . Also some neat functions that are nicely written .
*
* @ package WordPress
* @ subpackage Administration
*/
2007-05-25 03:16:21 -04:00
2016-08-31 12:31:29 -04:00
/** Walker_Category_Checklist class */
2020-02-06 01:33:11 -05:00
require_once ABSPATH . 'wp-admin/includes/class-walker-category-checklist.php' ;
2016-08-31 12:31:29 -04:00
/** WP_Internal_Pointers class */
2020-02-06 01:33:11 -05:00
require_once ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php' ;
2016-08-31 12:31:29 -04:00
2015-11-20 02:24:30 -05:00
//
2020-01-28 19:45:18 -05:00
// Category Checklists.
2015-11-20 02:24:30 -05:00
//
2007-05-25 03:16:21 -04:00
2015-11-20 02:24:30 -05:00
/**
2022-03-28 05:45:06 -04:00
* Outputs an unordered list of checkbox input elements labeled with category names .
2015-11-20 02:24:30 -05:00
*
* @ since 2.5 . 1
*
* @ see wp_terms_checklist ()
*
2021-01-05 12:16:11 -05:00
* @ param int $post_id Optional . Post to generate a categories checklist for . Default 0.
* $selected_cats must not be an array . Default 0.
* @ param int $descendants_and_self Optional . ID of the category to output along with its descendants .
* Default 0.
* @ param int [] | false $selected_cats Optional . Array of category IDs to mark as checked . Default false .
* @ param int [] | false $popular_cats Optional . Array of category IDs to receive the " popular-category " class .
* Default false .
* @ param Walker $walker Optional . Walker object to use to build the output .
* Default is a Walker_Category_Checklist instance .
* @ param bool $checked_ontop Optional . Whether to move checked items out of the hierarchy and to
* the top of the list . Default true .
2015-11-20 02:24:30 -05:00
*/
function wp_category_checklist ( $post_id = 0 , $descendants_and_self = 0 , $selected_cats = false , $popular_cats = false , $walker = null , $checked_ontop = true ) {
2017-11-30 18:11:00 -05:00
wp_terms_checklist (
2018-08-16 21:51:36 -04:00
$post_id ,
array (
2017-11-30 18:11:00 -05:00
'taxonomy' => 'category' ,
'descendants_and_self' => $descendants_and_self ,
'selected_cats' => $selected_cats ,
'popular_cats' => $popular_cats ,
'walker' => $walker ,
'checked_ontop' => $checked_ontop ,
)
);
2015-11-20 02:24:30 -05:00
}
/**
2022-03-28 05:45:06 -04:00
* Outputs an unordered list of checkbox input elements labelled with term names .
2015-11-20 02:24:30 -05:00
*
* Taxonomy - independent version of wp_category_checklist () .
*
* @ since 3.0 . 0
* @ since 4.4 . 0 Introduced the `$echo` argument .
*
* @ param int $post_id Optional . Post ID . Default 0.
* @ param array | string $args {
* Optional . Array or string of arguments for generating a terms checklist . Default empty array .
*
* @ type int $descendants_and_self ID of the category to output along with its descendants .
* Default 0.
2018-03-25 14:10:32 -04:00
* @ type int [] $selected_cats Array of category IDs to mark as checked . Default false .
* @ type int [] $popular_cats Array of category IDs to receive the " popular-category " class .
2015-11-20 02:24:30 -05:00
* Default false .
2022-04-29 15:28:09 -04:00
* @ type Walker $walker Walker object to use to build the output . Default empty which
* results in a Walker_Category_Checklist instance being used .
2015-11-20 02:24:30 -05:00
* @ type string $taxonomy Taxonomy to generate the checklist for . Default 'category' .
* @ type bool $checked_ontop Whether to move checked items out of the hierarchy and to
* the top of the list . Default true .
* @ type bool $echo Whether to echo the generated markup . False to return the markup instead
* of echoing it . Default true .
* }
2020-01-11 13:32:05 -05:00
* @ return string HTML list of input elements .
2015-11-20 02:24:30 -05:00
*/
function wp_terms_checklist ( $post_id = 0 , $args = array () ) {
2017-11-30 18:11:00 -05:00
$defaults = array (
2015-11-20 02:24:30 -05:00
'descendants_and_self' => 0 ,
2017-11-30 18:11:00 -05:00
'selected_cats' => false ,
'popular_cats' => false ,
'walker' => null ,
'taxonomy' => 'category' ,
'checked_ontop' => true ,
'echo' => true ,
2015-11-20 02:24:30 -05:00
);
/**
2016-05-22 14:01:30 -04:00
* Filters the taxonomy terms checklist arguments .
2015-11-20 02:24:30 -05:00
*
* @ since 3.4 . 0
*
* @ see wp_terms_checklist ()
*
2021-11-18 08:50:05 -05:00
* @ param array | string $args An array or string of arguments .
* @ param int $post_id The post ID .
2015-11-20 02:24:30 -05:00
*/
$params = apply_filters ( 'wp_terms_checklist_args' , $args , $post_id );
2019-07-24 20:48:58 -04:00
$parsed_args = wp_parse_args ( $params , $defaults );
2015-11-20 02:24:30 -05:00
2019-07-24 20:48:58 -04:00
if ( empty ( $parsed_args [ 'walker' ] ) || ! ( $parsed_args [ 'walker' ] instanceof Walker ) ) {
2015-11-20 02:24:30 -05:00
$walker = new Walker_Category_Checklist ;
} else {
2019-07-24 20:48:58 -04:00
$walker = $parsed_args [ 'walker' ];
2015-11-20 02:24:30 -05:00
}
2019-07-24 20:48:58 -04:00
$taxonomy = $parsed_args [ 'taxonomy' ];
$descendants_and_self = ( int ) $parsed_args [ 'descendants_and_self' ];
2015-11-20 02:24:30 -05:00
$args = array ( 'taxonomy' => $taxonomy );
2017-11-30 18:11:00 -05:00
$tax = get_taxonomy ( $taxonomy );
2015-11-20 02:24:30 -05:00
$args [ 'disabled' ] = ! current_user_can ( $tax -> cap -> assign_terms );
2019-07-24 20:48:58 -04:00
$args [ 'list_only' ] = ! empty ( $parsed_args [ 'list_only' ] );
2015-11-20 02:24:30 -05:00
2019-07-24 20:48:58 -04:00
if ( is_array ( $parsed_args [ 'selected_cats' ] ) ) {
2020-08-26 22:48:06 -04:00
$args [ 'selected_cats' ] = array_map ( 'intval' , $parsed_args [ 'selected_cats' ] );
2015-11-20 02:24:30 -05:00
} elseif ( $post_id ) {
$args [ 'selected_cats' ] = wp_get_object_terms ( $post_id , $taxonomy , array_merge ( $args , array ( 'fields' => 'ids' ) ) );
} else {
$args [ 'selected_cats' ] = array ();
}
2019-08-02 23:35:56 -04:00
2019-07-24 20:48:58 -04:00
if ( is_array ( $parsed_args [ 'popular_cats' ] ) ) {
2020-08-26 22:48:06 -04:00
$args [ 'popular_cats' ] = array_map ( 'intval' , $parsed_args [ 'popular_cats' ] );
2015-11-20 02:24:30 -05:00
} else {
2017-11-30 18:11:00 -05:00
$args [ 'popular_cats' ] = get_terms (
2018-08-16 21:51:36 -04:00
array (
2019-08-02 23:35:56 -04:00
'taxonomy' => $taxonomy ,
2017-11-30 18:11:00 -05:00
'fields' => 'ids' ,
'orderby' => 'count' ,
'order' => 'DESC' ,
'number' => 10 ,
'hierarchical' => false ,
)
);
2015-11-20 02:24:30 -05:00
}
2019-08-02 23:35:56 -04:00
2015-11-20 02:24:30 -05:00
if ( $descendants_and_self ) {
2017-11-30 18:11:00 -05:00
$categories = ( array ) get_terms (
2018-08-16 21:51:36 -04:00
array (
2019-08-02 23:35:56 -04:00
'taxonomy' => $taxonomy ,
2017-11-30 18:11:00 -05:00
'child_of' => $descendants_and_self ,
'hierarchical' => 0 ,
'hide_empty' => 0 ,
)
);
$self = get_term ( $descendants_and_self , $taxonomy );
2015-11-20 02:24:30 -05:00
array_unshift ( $categories , $self );
} else {
2019-08-02 23:35:56 -04:00
$categories = ( array ) get_terms (
array (
'taxonomy' => $taxonomy ,
'get' => 'all' ,
)
);
2015-11-20 02:24:30 -05:00
}
$output = '' ;
2019-07-24 20:48:58 -04:00
if ( $parsed_args [ 'checked_ontop' ] ) {
2020-01-28 19:45:18 -05:00
// Post-process $categories rather than adding an exclude to the get_terms() query
// to keep the query the same across all posts (for any query cache).
2015-11-20 02:24:30 -05:00
$checked_categories = array ();
2017-11-30 18:11:00 -05:00
$keys = array_keys ( $categories );
2015-11-20 02:24:30 -05:00
foreach ( $keys as $k ) {
2020-04-09 11:43:10 -04:00
if ( in_array ( $categories [ $k ] -> term_id , $args [ 'selected_cats' ], true ) ) {
2017-11-30 18:11:00 -05:00
$checked_categories [] = $categories [ $k ];
unset ( $categories [ $k ] );
2015-11-20 02:24:30 -05:00
}
}
2020-01-28 19:45:18 -05:00
// Put checked categories on top.
2019-09-15 07:35:56 -04:00
$output .= $walker -> walk ( $checked_categories , 0 , $args );
2015-11-20 02:24:30 -05:00
}
2020-01-28 19:45:18 -05:00
// Then the rest of them.
2019-09-15 07:35:56 -04:00
$output .= $walker -> walk ( $categories , 0 , $args );
2015-11-20 02:24:30 -05:00
2019-07-24 20:48:58 -04:00
if ( $parsed_args [ 'echo' ] ) {
2015-11-20 02:24:30 -05:00
echo $output ;
}
return $output ;
}
/**
2022-03-28 05:45:06 -04:00
* Retrieves a list of the most popular terms from the specified taxonomy .
2015-11-20 02:24:30 -05:00
*
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
* If the `$display` argument is true then the elements for a list of checkbox
2015-11-20 02:24:30 -05:00
* `<input>` elements labelled with the names of the selected terms is output .
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
* If the `$post_ID` global is not empty then the terms associated with that
2015-11-20 02:24:30 -05:00
* post will be marked as checked .
*
* @ since 2.5 . 0
*
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
* @ param string $taxonomy Taxonomy to retrieve terms from .
* @ param int $default_term Optional . Not used .
* @ param int $number Optional . Number of terms to retrieve . Default 10.
* @ param bool $display Optional . Whether to display the list as well . Default true .
2019-11-05 16:30:03 -05:00
* @ return int [] Array of popular term IDs .
2015-11-20 02:24:30 -05:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
function wp_popular_terms_checklist ( $taxonomy , $default_term = 0 , $number = 10 , $display = true ) {
2015-11-20 02:24:30 -05:00
$post = get_post ();
2017-11-30 18:11:00 -05:00
if ( $post && $post -> ID ) {
$checked_terms = wp_get_object_terms ( $post -> ID , $taxonomy , array ( 'fields' => 'ids' ) );
} else {
2015-11-20 02:24:30 -05:00
$checked_terms = array ();
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
$terms = get_terms (
2018-08-16 21:51:36 -04:00
array (
2019-08-02 23:35:56 -04:00
'taxonomy' => $taxonomy ,
2017-11-30 18:11:00 -05:00
'orderby' => 'count' ,
'order' => 'DESC' ,
'number' => $number ,
'hierarchical' => false ,
)
);
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
$tax = get_taxonomy ( $taxonomy );
2015-11-20 02:24:30 -05:00
$popular_ids = array ();
2020-04-09 11:43:10 -04:00
2015-11-20 02:24:30 -05:00
foreach ( ( array ) $terms as $term ) {
$popular_ids [] = $term -> term_id ;
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
if ( ! $display ) { // Hack for Ajax use.
2015-11-20 02:24:30 -05:00
continue ;
2017-11-30 18:11:00 -05:00
}
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
2017-11-30 18:11:00 -05:00
$id = " popular- $taxonomy - $term->term_id " ;
2020-04-09 11:43:10 -04:00
$checked = in_array ( $term -> term_id , $checked_terms , true ) ? 'checked="checked"' : '' ;
2015-11-20 02:24:30 -05:00
?>
< li id = " <?php echo $id ; ?> " class = " popular-category " >
< label class = " selectit " >
< input id = " in-<?php echo $id ; ?> " type = " checkbox " < ? php echo $checked ; ?> value="<?php echo (int) $term->term_id; ?>" <?php disabled( ! current_user_can( $tax->cap->assign_terms ) ); ?> />
< ? php
/** This filter is documented in wp-includes/category-template.php */
2017-08-03 12:13:44 -04:00
echo esc_html ( apply_filters ( 'the_category' , $term -> name , '' , '' ) );
2015-11-20 02:24:30 -05:00
?>
</ label >
</ li >
< ? php
}
return $popular_ids ;
}
/**
* Outputs a link category checklist element .
*
* @ since 2.5 . 1
*
* @ param int $link_id
*/
function wp_link_category_checklist ( $link_id = 0 ) {
$default = 1 ;
$checked_categories = array ();
if ( $link_id ) {
$checked_categories = wp_get_link_cats ( $link_id );
2020-01-28 19:45:18 -05:00
// No selected categories, strange.
2015-11-20 02:24:30 -05:00
if ( ! count ( $checked_categories ) ) {
$checked_categories [] = $default ;
}
} else {
$checked_categories [] = $default ;
}
2017-11-30 18:11:00 -05:00
$categories = get_terms (
2018-08-16 21:51:36 -04:00
array (
2019-08-02 23:35:56 -04:00
'taxonomy' => 'link_category' ,
2017-11-30 18:11:00 -05:00
'orderby' => 'name' ,
'hide_empty' => 0 ,
)
);
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
if ( empty ( $categories ) ) {
2015-11-20 02:24:30 -05:00
return ;
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
foreach ( $categories as $category ) {
$cat_id = $category -> term_id ;
/** This filter is documented in wp-includes/category-template.php */
2017-11-30 18:11:00 -05:00
$name = esc_html ( apply_filters ( 'the_category' , $category -> name , '' , '' ) );
2020-04-09 11:43:10 -04:00
$checked = in_array ( $cat_id , $checked_categories , true ) ? ' checked="checked"' : '' ;
2017-11-30 18:11:00 -05:00
echo '<li id="link-category-' , $cat_id , '"><label for="in-link-category-' , $cat_id , '" class="selectit"><input value="' , $cat_id , '" type="checkbox" name="link_category[]" id="in-link-category-' , $cat_id , '"' , $checked , '/> ' , $name , '</label></li>' ;
2015-11-20 02:24:30 -05:00
}
}
/**
* Adds hidden fields with the data for use in the inline editor for posts and pages .
*
* @ since 2.7 . 0
*
* @ param WP_Post $post Post object .
*/
2017-11-30 18:11:00 -05:00
function get_inline_data ( $post ) {
$post_type_object = get_post_type_object ( $post -> post_type );
if ( ! current_user_can ( 'edit_post' , $post -> ID ) ) {
2015-11-20 02:24:30 -05:00
return ;
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
$title = esc_textarea ( trim ( $post -> post_title ) );
echo '
< div class = " hidden " id = " inline_' . $post->ID . ' " >
< div class = " post_title " > ' . $title . ' </ div > ' .
/** This filter is documented in wp-admin/edit-tag-form.php */
'<div class="post_name">' . apply_filters ( 'editable_slug' , $post -> post_name , $post ) . ' </ div >
< div class = " post_author " > ' . $post->post_author . ' </ div >
< div class = " comment_status " > ' . esc_html( $post->comment_status ) . ' </ div >
< div class = " ping_status " > ' . esc_html( $post->ping_status ) . ' </ div >
< div class = " _status " > ' . esc_html( $post->post_status ) . ' </ div >
< div class = " jj " > ' . mysql2date( ' d ', $post->post_date, false ) . ' </ div >
< div class = " mm " > ' . mysql2date( ' m ', $post->post_date, false ) . ' </ div >
< div class = " aa " > ' . mysql2date( ' Y ', $post->post_date, false ) . ' </ div >
< div class = " hh " > ' . mysql2date( ' H ', $post->post_date, false ) . ' </ div >
< div class = " mn " > ' . mysql2date( ' i ', $post->post_date, false ) . ' </ div >
< div class = " ss " > ' . mysql2date( ' s ', $post->post_date, false ) . ' </ div >
< div class = " post_password " > ' . esc_html( $post->post_password ) . ' </ div > ' ;
Posts, Post Types: Add support for post type templates.
WordPress has supported custom page templates for over 12 years, allowing developers to create various layouts for specific pages.
While this feature is very helpful, it has always been limited to the 'page' post type and not was not available to other post types.
By opening up the page template functionality to all post types, we continue to improve the template hierarchy's flexibility.
In addition to the `Template Name` file header, the post types supported by a template can be specified using `Template Post Type: post, foo, bar`.
When at least one template exists for a post type, the 'Post Attributes' meta box will be displayed in the back end, without the need to add post type support for `'page-attributes'`. 'Post Attributes' can be customized per post type using the `'attributes'` label when registering a post type.
Props johnbillion, Mte90, dipesh.kakadiya, swissspidy.
Fixes #18375.
Built from https://develop.svn.wordpress.org/trunk@38951
git-svn-id: http://core.svn.wordpress.org/trunk@38894 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-10-26 04:07:30 -04:00
if ( $post_type_object -> hierarchical ) {
2015-11-20 02:24:30 -05:00
echo '<div class="post_parent">' . $post -> post_parent . '</div>' ;
Posts, Post Types: Add support for post type templates.
WordPress has supported custom page templates for over 12 years, allowing developers to create various layouts for specific pages.
While this feature is very helpful, it has always been limited to the 'page' post type and not was not available to other post types.
By opening up the page template functionality to all post types, we continue to improve the template hierarchy's flexibility.
In addition to the `Template Name` file header, the post types supported by a template can be specified using `Template Post Type: post, foo, bar`.
When at least one template exists for a post type, the 'Post Attributes' meta box will be displayed in the back end, without the need to add post type support for `'page-attributes'`. 'Post Attributes' can be customized per post type using the `'attributes'` label when registering a post type.
Props johnbillion, Mte90, dipesh.kakadiya, swissspidy.
Fixes #18375.
Built from https://develop.svn.wordpress.org/trunk@38951
git-svn-id: http://core.svn.wordpress.org/trunk@38894 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-10-26 04:07:30 -04:00
}
2015-11-20 02:24:30 -05:00
2016-11-13 02:42:31 -05:00
echo '<div class="page_template">' . ( $post -> page_template ? esc_html ( $post -> page_template ) : 'default' ) . '</div>' ;
2015-11-20 02:24:30 -05:00
Posts, Post Types: Add support for post type templates.
WordPress has supported custom page templates for over 12 years, allowing developers to create various layouts for specific pages.
While this feature is very helpful, it has always been limited to the 'page' post type and not was not available to other post types.
By opening up the page template functionality to all post types, we continue to improve the template hierarchy's flexibility.
In addition to the `Template Name` file header, the post types supported by a template can be specified using `Template Post Type: post, foo, bar`.
When at least one template exists for a post type, the 'Post Attributes' meta box will be displayed in the back end, without the need to add post type support for `'page-attributes'`. 'Post Attributes' can be customized per post type using the `'attributes'` label when registering a post type.
Props johnbillion, Mte90, dipesh.kakadiya, swissspidy.
Fixes #18375.
Built from https://develop.svn.wordpress.org/trunk@38951
git-svn-id: http://core.svn.wordpress.org/trunk@38894 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-10-26 04:07:30 -04:00
if ( post_type_supports ( $post -> post_type , 'page-attributes' ) ) {
2015-11-20 02:24:30 -05:00
echo '<div class="menu_order">' . $post -> menu_order . '</div>' ;
Posts, Post Types: Add support for post type templates.
WordPress has supported custom page templates for over 12 years, allowing developers to create various layouts for specific pages.
While this feature is very helpful, it has always been limited to the 'page' post type and not was not available to other post types.
By opening up the page template functionality to all post types, we continue to improve the template hierarchy's flexibility.
In addition to the `Template Name` file header, the post types supported by a template can be specified using `Template Post Type: post, foo, bar`.
When at least one template exists for a post type, the 'Post Attributes' meta box will be displayed in the back end, without the need to add post type support for `'page-attributes'`. 'Post Attributes' can be customized per post type using the `'attributes'` label when registering a post type.
Props johnbillion, Mte90, dipesh.kakadiya, swissspidy.
Fixes #18375.
Built from https://develop.svn.wordpress.org/trunk@38951
git-svn-id: http://core.svn.wordpress.org/trunk@38894 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-10-26 04:07:30 -04:00
}
2015-11-20 02:24:30 -05:00
$taxonomy_names = get_object_taxonomies ( $post -> post_type );
2020-04-09 11:43:10 -04:00
2017-11-30 18:11:00 -05:00
foreach ( $taxonomy_names as $taxonomy_name ) {
2015-11-20 02:24:30 -05:00
$taxonomy = get_taxonomy ( $taxonomy_name );
2022-03-10 13:22:01 -05:00
if ( ! $taxonomy -> show_in_quick_edit ) {
continue ;
}
if ( $taxonomy -> hierarchical ) {
2015-11-20 02:24:30 -05:00
$terms = get_object_term_cache ( $post -> ID , $taxonomy_name );
if ( false === $terms ) {
$terms = wp_get_object_terms ( $post -> ID , $taxonomy_name );
2016-05-26 00:50:27 -04:00
wp_cache_add ( $post -> ID , wp_list_pluck ( $terms , 'term_id' ), $taxonomy_name . '_relationships' );
2015-11-20 02:24:30 -05:00
}
$term_ids = empty ( $terms ) ? array () : wp_list_pluck ( $terms , 'term_id' );
echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post -> ID . '">' . implode ( ',' , $term_ids ) . '</div>' ;
2022-03-10 13:22:01 -05:00
} else {
2015-11-20 02:24:30 -05:00
$terms_to_edit = get_terms_to_edit ( $post -> ID , $taxonomy_name );
if ( ! is_string ( $terms_to_edit ) ) {
$terms_to_edit = '' ;
}
2017-11-30 18:11:00 -05:00
echo '<div class="tags_input" id="' . $taxonomy_name . '_' . $post -> ID . '">'
2015-11-20 02:24:30 -05:00
. esc_html ( str_replace ( ',' , ', ' , $terms_to_edit ) ) . '</div>' ;
}
}
2017-11-30 18:11:00 -05:00
if ( ! $post_type_object -> hierarchical ) {
echo '<div class="sticky">' . ( is_sticky ( $post -> ID ) ? 'sticky' : '' ) . '</div>' ;
}
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
if ( post_type_supports ( $post -> post_type , 'post-formats' ) ) {
2015-11-20 02:24:30 -05:00
echo '<div class="post_format">' . esc_html ( get_post_format ( $post -> ID ) ) . '</div>' ;
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
2018-02-09 10:55:32 -05:00
/**
* Fires after outputting the fields for the inline editor for posts and pages .
*
2018-07-16 11:27:25 -04:00
* @ since 4.9 . 8
2018-02-09 10:55:32 -05:00
*
* @ param WP_Post $post The current post object .
* @ param WP_Post_Type $post_type_object The current post ' s post type object .
*/
do_action ( 'add_inline_data' , $post , $post_type_object );
2015-11-20 02:24:30 -05:00
echo '</div>' ;
}
/**
* Outputs the in - line comment reply - to form in the Comments list table .
*
* @ since 2.7 . 0
*
* @ global WP_List_Table $wp_list_table
*
* @ param int $position
* @ param bool $checkbox
* @ param string $mode
* @ param bool $table_row
*/
function wp_comment_reply ( $position = 1 , $checkbox = false , $mode = 'single' , $table_row = true ) {
global $wp_list_table ;
/**
2016-05-22 14:01:30 -04:00
* Filters the in - line comment reply - to form output in the Comments
2015-11-20 02:24:30 -05:00
* list table .
*
* Returning a non - empty value here will short - circuit display
* of the in - line comment - reply form in the Comments list table ,
* echoing the returned value instead .
*
* @ since 2.7 . 0
*
* @ see wp_comment_reply ()
*
* @ param string $content The reply - to form content .
* @ param array $args An array of default args .
*/
2017-11-30 18:11:00 -05:00
$content = apply_filters (
2018-08-16 21:51:36 -04:00
'wp_comment_reply' ,
'' ,
array (
2017-11-30 18:11:00 -05:00
'position' => $position ,
'checkbox' => $checkbox ,
'mode' => $mode ,
)
);
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
if ( ! empty ( $content ) ) {
2015-11-20 02:24:30 -05:00
echo $content ;
return ;
}
if ( ! $wp_list_table ) {
2020-02-09 11:55:09 -05:00
if ( 'single' === $mode ) {
2017-11-30 18:11:00 -05:00
$wp_list_table = _get_list_table ( 'WP_Post_Comments_List_Table' );
2015-11-20 02:24:30 -05:00
} else {
2017-11-30 18:11:00 -05:00
$wp_list_table = _get_list_table ( 'WP_Comments_List_Table' );
2015-11-20 02:24:30 -05:00
}
}
2018-08-16 21:51:36 -04:00
?>
2015-11-20 02:24:30 -05:00
< form method = " get " >
2018-08-16 21:51:36 -04:00
< ? php if ( $table_row ) : ?>
2015-11-20 02:24:30 -05:00
< table style = " display:none; " >< tbody id = " com-reply " >< tr id = " replyrow " class = " inline-edit-row " style = " display:none; " >< td colspan = " <?php echo $wp_list_table->get_column_count (); ?> " class = " colspanchange " >
< ? php else : ?>
< div id = " com-reply " style = " display:none; " >< div id = " replyrow " style = " display:none; " >
< ? php endif ; ?>
< fieldset class = " comment-reply " >
< legend >
< span class = " hidden " id = " editlegend " >< ? php _e ( 'Edit Comment' ); ?> </span>
< span class = " hidden " id = " replyhead " >< ? php _e ( 'Reply to Comment' ); ?> </span>
< span class = " hidden " id = " addhead " >< ? php _e ( 'Add new Comment' ); ?> </span>
</ legend >
< div id = " replycontainer " >
< label for = " replycontent " class = " screen-reader-text " >< ? php _e ( 'Comment' ); ?> </label>
< ? php
$quicktags_settings = array ( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
2017-11-30 18:11:00 -05:00
wp_editor (
2018-08-16 21:51:36 -04:00
'' ,
'replycontent' ,
array (
2017-11-30 18:11:00 -05:00
'media_buttons' => false ,
'tinymce' => false ,
'quicktags' => $quicktags_settings ,
)
);
2015-11-20 02:24:30 -05:00
?>
</ div >
< div id = " edithead " style = " display:none; " >
< div class = " inside " >
2017-11-30 18:11:00 -05:00
< label for = " author-name " >< ? php _e ( 'Name' ); ?> </label>
2015-11-20 02:24:30 -05:00
< input type = " text " name = " newcomment_author " size = " 50 " value = " " id = " author-name " />
</ div >
< div class = " inside " >
2017-11-30 18:11:00 -05:00
< label for = " author-email " >< ? php _e ( 'Email' ); ?> </label>
2015-11-20 02:24:30 -05:00
< input type = " text " name = " newcomment_author_email " size = " 50 " value = " " id = " author-email " />
</ div >
< div class = " inside " >
2017-11-30 18:11:00 -05:00
< label for = " author-url " >< ? php _e ( 'URL' ); ?> </label>
2015-11-20 02:24:30 -05:00
< input type = " text " id = " author-url " name = " newcomment_author_url " class = " code " size = " 103 " value = " " />
</ div >
</ div >
2017-10-02 17:52:52 -04:00
< div id = " replysubmit " class = " submit " >
2019-02-20 17:09:50 -05:00
< p class = " reply-submit-buttons " >
2019-02-20 18:37:50 -05:00
< button type = " button " class = " save button button-primary " >
2017-10-02 17:52:52 -04:00
< span id = " addbtn " style = " display: none; " >< ? php _e ( 'Add Comment' ); ?> </span>
< span id = " savebtn " style = " display: none; " >< ? php _e ( 'Update Comment' ); ?> </span>
< span id = " replybtn " style = " display: none; " >< ? php _e ( 'Submit Reply' ); ?> </span>
2019-02-20 18:37:50 -05:00
</ button >
< button type = " button " class = " cancel button " >< ? php _e ( 'Cancel' ); ?> </button>
2017-10-02 17:52:52 -04:00
< span class = " waiting spinner " ></ span >
</ p >
< div class = " notice notice-error notice-alt inline hidden " >
< p class = " error " ></ p >
</ div >
</ div >
2015-11-20 02:24:30 -05:00
< input type = " hidden " name = " action " id = " action " value = " " />
< input type = " hidden " name = " comment_ID " id = " comment_ID " value = " " />
< input type = " hidden " name = " comment_post_ID " id = " comment_post_ID " value = " " />
< input type = " hidden " name = " status " id = " status " value = " " />
< input type = " hidden " name = " position " id = " position " value = " <?php echo $position ; ?> " />
< input type = " hidden " name = " checkbox " id = " checkbox " value = " <?php echo $checkbox ? 1 : 0; ?> " />
2017-11-30 18:11:00 -05:00
< input type = " hidden " name = " mode " id = " mode " value = " <?php echo esc_attr( $mode ); ?> " />
2015-11-20 02:24:30 -05:00
< ? php
wp_nonce_field ( 'replyto-comment' , '_ajax_nonce-replyto-comment' , false );
2017-11-30 18:11:00 -05:00
if ( current_user_can ( 'unfiltered_html' ) ) {
wp_nonce_field ( 'unfiltered-html-comment' , '_wp_unfiltered_html_comment' , false );
}
2015-11-20 02:24:30 -05:00
?>
</ fieldset >
2018-08-16 21:51:36 -04:00
< ? php if ( $table_row ) : ?>
2015-11-20 02:24:30 -05:00
</ td ></ tr ></ tbody ></ table >
2018-08-16 21:51:36 -04:00
< ? php else : ?>
2015-11-20 02:24:30 -05:00
</ div ></ div >
2018-08-16 21:51:36 -04:00
< ? php endif ; ?>
2015-11-20 02:24:30 -05:00
</ form >
2018-08-16 21:51:36 -04:00
< ? php
2015-11-20 02:24:30 -05:00
}
/**
2022-03-28 05:45:06 -04:00
* Outputs 'undo move to Trash' text for comments .
2015-11-20 02:24:30 -05:00
*
* @ since 2.9 . 0
*/
function wp_comment_trashnotice () {
2018-08-16 21:51:36 -04:00
?>
2015-11-20 02:24:30 -05:00
< div class = " hidden " id = " trash-undo-holder " >
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
< div class = " trash-undo-inside " >
< ? php
2020-06-25 08:43:07 -04:00
/* translators: %s: Comment author, filled by Ajax. */
2020-02-09 23:12:07 -05:00
printf ( __ ( 'Comment by %s moved to the Trash.' ), '<strong></strong>' );
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
?>
< span class = " undo untrash " >< a href = " # " >< ? php _e ( 'Undo' ); ?> </a></span>
</ div >
2015-11-20 02:24:30 -05:00
</ div >
< div class = " hidden " id = " spam-undo-holder " >
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
< div class = " spam-undo-inside " >
< ? php
2020-06-25 08:43:07 -04:00
/* translators: %s: Comment author, filled by Ajax. */
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
printf ( __ ( 'Comment by %s marked as spam.' ), '<strong></strong>' );
?>
< span class = " undo unspam " >< a href = " # " >< ? php _e ( 'Undo' ); ?> </a></span>
</ div >
2015-11-20 02:24:30 -05:00
</ div >
2018-08-16 21:51:36 -04:00
< ? php
2015-11-20 02:24:30 -05:00
}
/**
* Outputs a post ' s public meta data in the Custom Fields meta box .
*
* @ since 1.2 . 0
*
* @ param array $meta
*/
function list_meta ( $meta ) {
2020-01-28 19:45:18 -05:00
// Exit if no meta.
2015-11-20 02:24:30 -05:00
if ( ! $meta ) {
echo '
< table id = " list-table " style = " display: none; " >
< thead >
< tr >
< th class = " left " > ' . _x( ' Name ', ' meta name ' ) . ' </ th >
< th > ' . __( ' Value ' ) . ' </ th >
</ tr >
</ thead >
< tbody id = " the-list " data - wp - lists = " list:meta " >
< tr >< td ></ td ></ tr >
</ tbody >
2020-01-28 19:45:18 -05:00
</ table > ' ; // TBODY needed for list-manipulation JS.
2015-11-20 02:24:30 -05:00
return ;
}
$count = 0 ;
2018-08-16 21:51:36 -04:00
?>
2015-11-20 02:24:30 -05:00
< table id = " list-table " >
< thead >
< tr >
2017-11-30 18:11:00 -05:00
< th class = " left " >< ? php _ex ( 'Name' , 'meta name' ); ?> </th>
< th >< ? php _e ( 'Value' ); ?> </th>
2015-11-20 02:24:30 -05:00
</ tr >
</ thead >
< tbody id = 'the-list' data - wp - lists = 'list:meta' >
2018-08-16 21:51:36 -04:00
< ? php
foreach ( $meta as $entry ) {
echo _list_meta_row ( $entry , $count );
}
?>
2015-11-20 02:24:30 -05:00
</ tbody >
</ table >
2018-08-16 21:51:36 -04:00
< ? php
2015-11-20 02:24:30 -05:00
}
/**
* Outputs a single row of public meta data in the Custom Fields meta box .
*
* @ since 2.5 . 0
*
* @ param array $entry
* @ param int $count
* @ return string
*/
function _list_meta_row ( $entry , & $count ) {
static $update_nonce = '' ;
2017-11-30 18:11:00 -05:00
if ( is_protected_meta ( $entry [ 'meta_key' ], 'post' ) ) {
2015-11-20 02:24:30 -05:00
return '' ;
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
if ( ! $update_nonce ) {
2015-11-20 02:24:30 -05:00
$update_nonce = wp_create_nonce ( 'add-meta' );
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
$r = '' ;
++ $count ;
if ( is_serialized ( $entry [ 'meta_value' ] ) ) {
if ( is_serialized_string ( $entry [ 'meta_value' ] ) ) {
// This is a serialized string, so we should display it.
$entry [ 'meta_value' ] = maybe_unserialize ( $entry [ 'meta_value' ] );
} else {
// This is a serialized array/object so we should NOT display it.
-- $count ;
return '' ;
}
}
2017-11-30 18:11:00 -05:00
$entry [ 'meta_key' ] = esc_attr ( $entry [ 'meta_key' ] );
2020-01-28 19:45:18 -05:00
$entry [ 'meta_value' ] = esc_textarea ( $entry [ 'meta_value' ] ); // Using a <textarea />.
2017-11-30 18:11:00 -05:00
$entry [ 'meta_id' ] = ( int ) $entry [ 'meta_id' ];
2015-11-20 02:24:30 -05:00
$delete_nonce = wp_create_nonce ( 'delete-meta_' . $entry [ 'meta_id' ] );
$r .= " \n \t <tr id='meta- { $entry [ 'meta_id' ] } '> " ;
$r .= " \n \t \t <td class='left'><label class='screen-reader-text' for='meta- { $entry [ 'meta_id' ] } -key'> " . __ ( 'Key' ) . " </label><input name='meta[ { $entry [ 'meta_id' ] } ][key]' id='meta- { $entry [ 'meta_id' ] } -key' type='text' size='20' value=' { $entry [ 'meta_key' ] } ' /> " ;
$r .= " \n \t \t <div class='submit'> " ;
$r .= get_submit_button ( __ ( 'Delete' ), 'deletemeta small' , " deletemeta[ { $entry [ 'meta_id' ] } ] " , false , array ( 'data-wp-lists' => " delete:the-list:meta- { $entry [ 'meta_id' ] } ::_ajax_nonce= $delete_nonce " ) );
$r .= " \n \t \t " ;
$r .= get_submit_button ( __ ( 'Update' ), 'updatemeta small' , " meta- { $entry [ 'meta_id' ] } -submit " , false , array ( 'data-wp-lists' => " add:the-list:meta- { $entry [ 'meta_id' ] } ::_ajax_nonce-add-meta= $update_nonce " ) );
2017-11-30 18:11:00 -05:00
$r .= '</div>' ;
2015-11-20 02:24:30 -05:00
$r .= wp_nonce_field ( 'change-meta' , '_ajax_nonce' , false , false );
2017-11-30 18:11:00 -05:00
$r .= '</td>' ;
2015-11-20 02:24:30 -05:00
$r .= " \n \t \t <td><label class='screen-reader-text' for='meta- { $entry [ 'meta_id' ] } -value'> " . __ ( 'Value' ) . " </label><textarea name='meta[ { $entry [ 'meta_id' ] } ][value]' id='meta- { $entry [ 'meta_id' ] } -value' rows='2' cols='30'> { $entry [ 'meta_value' ] } </textarea></td> \n \t </tr> " ;
return $r ;
}
/**
* Prints the form in the Custom Fields meta box .
*
* @ since 1.2 . 0
*
* @ global wpdb $wpdb WordPress database abstraction object .
*
* @ param WP_Post $post Optional . The post being edited .
*/
function meta_form ( $post = null ) {
global $wpdb ;
$post = get_post ( $post );
/**
2016-05-22 14:01:30 -04:00
* Filters values for the meta key dropdown in the Custom Fields meta box .
2015-11-20 02:24:30 -05:00
*
* Returning a non - null value will effectively short - circuit and avoid a
* potentially expensive query against postmeta .
*
* @ since 4.4 . 0
*
* @ param array | null $keys Pre - defined meta keys to be used in place of a postmeta query . Default null .
2015-11-23 12:15:29 -05:00
* @ param WP_Post $post The current post object .
2015-11-20 02:24:30 -05:00
*/
2015-11-23 12:15:29 -05:00
$keys = apply_filters ( 'postmeta_form_keys' , null , $post );
2015-11-20 02:24:30 -05:00
if ( null === $keys ) {
/**
2016-05-22 14:01:30 -04:00
* Filters the number of custom fields to retrieve for the drop - down
2015-11-20 02:24:30 -05:00
* in the Custom Fields meta box .
*
* @ since 2.1 . 0
*
* @ param int $limit Number of custom fields to retrieve . Default 30.
*/
$limit = apply_filters ( 'postmeta_form_limit' , 30 );
2020-05-08 12:36:18 -04:00
$keys = $wpdb -> get_col (
$wpdb -> prepare (
" SELECT DISTINCT meta_key
FROM $wpdb -> postmeta
WHERE meta_key NOT BETWEEN '_' AND '_z'
HAVING meta_key NOT LIKE % s
ORDER BY meta_key
LIMIT % d " ,
$wpdb -> esc_like ( '_' ) . '%' ,
$limit
)
);
2015-11-20 02:24:30 -05:00
}
if ( $keys ) {
natcasesort ( $keys );
$meta_key_input_id = 'metakeyselect' ;
} else {
$meta_key_input_id = 'metakeyinput' ;
}
2018-08-16 21:51:36 -04:00
?>
2017-11-30 18:11:00 -05:00
< p >< strong >< ? php _e ( 'Add New Custom Field:' ); ?> </strong></p>
2015-11-20 02:24:30 -05:00
< table id = " newmeta " >
< thead >
< tr >
2017-11-30 18:11:00 -05:00
< th class = " left " >< label for = " <?php echo $meta_key_input_id ; ?> " >< ? php _ex ( 'Name' , 'meta name' ); ?> </label></th>
< th >< label for = " metavalue " >< ? php _e ( 'Value' ); ?> </label></th>
2015-11-20 02:24:30 -05:00
</ tr >
</ thead >
< tbody >
< tr >
< td id = " newmetaleft " class = " left " >
2018-08-16 21:51:36 -04:00
< ? php if ( $keys ) { ?>
2015-11-20 02:24:30 -05:00
< select id = " metakeyselect " name = " metakeyselect " >
< option value = " #NONE# " >< ? php _e ( '— Select —' ); ?> </option>
2018-08-16 21:51:36 -04:00
< ? php
foreach ( $keys as $key ) {
if ( is_protected_meta ( $key , 'post' ) || ! current_user_can ( 'add_post_meta' , $post -> ID , $key ) ) {
continue ;
}
echo " \n <option value=' " . esc_attr ( $key ) . " '> " . esc_html ( $key ) . '</option>' ;
}
?>
2015-11-20 02:24:30 -05:00
</ select >
< input class = " hide-if-js " type = " text " id = " metakeyinput " name = " metakeyinput " value = " " />
< a href = " #postcustomstuff " class = " hide-if-no-js " onclick = " jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false; " >
2017-11-30 18:11:00 -05:00
< span id = " enternew " >< ? php _e ( 'Enter new' ); ?> </span>
< span id = " cancelnew " class = " hidden " >< ? php _e ( 'Cancel' ); ?> </span></a>
2015-11-20 02:24:30 -05:00
< ? php } else { ?>
< input type = " text " id = " metakeyinput " name = " metakeyinput " value = " " />
< ? php } ?>
</ td >
< td >< textarea id = " metavalue " name = " metavalue " rows = " 2 " cols = " 25 " ></ textarea ></ td >
</ tr >
< tr >< td colspan = " 2 " >
< div class = " submit " >
2018-08-16 21:51:36 -04:00
< ? php
submit_button (
__ ( 'Add Custom Field' ),
'' ,
'addmeta' ,
false ,
array (
'id' => 'newmeta-submit' ,
'data-wp-lists' => 'add:the-list:newmeta' ,
)
);
?>
2015-11-20 02:24:30 -05:00
</ div >
2018-08-16 21:51:36 -04:00
< ? php wp_nonce_field ( 'add-meta' , '_ajax_nonce-add-meta' , false ); ?>
2015-11-20 02:24:30 -05:00
</ td ></ tr >
</ tbody >
</ table >
2018-08-16 21:51:36 -04:00
< ? php
2015-11-20 02:24:30 -05:00
}
/**
2022-03-28 05:45:06 -04:00
* Prints out HTML form date elements for editing post or comment publish date .
2015-11-20 02:24:30 -05:00
*
* @ since 0.71
* @ since 4.4 . 0 Converted to use get_comment () instead of the global `$comment` .
*
2019-08-03 21:46:55 -04:00
* @ global WP_Locale $wp_locale WordPress date and time locale object .
2015-11-20 02:24:30 -05:00
*
* @ param int | bool $edit Accepts 1 | true for editing the date , 0 | false for adding the date .
* @ param int | bool $for_post Accepts 1 | true for applying the date to a post , 0 | false for a comment .
* @ param int $tab_index The tabindex attribute to add . Default 0.
* @ param int | bool $multi Optional . Whether the additional fields and buttons should be added .
* Default 0 | false .
*/
function touch_time ( $edit = 1 , $for_post = 1 , $tab_index = 0 , $multi = 0 ) {
global $wp_locale ;
$post = get_post ();
2017-11-30 18:11:00 -05:00
if ( $for_post ) {
2020-05-08 12:36:18 -04:00
$edit = ! ( in_array ( $post -> post_status , array ( 'draft' , 'pending' ), true ) && ( ! $post -> post_date_gmt || '0000-00-00 00:00:00' === $post -> post_date_gmt ) );
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
$tab_index_attribute = '' ;
2017-11-30 18:11:00 -05:00
if ( ( int ) $tab_index > 0 ) {
2015-11-20 02:24:30 -05:00
$tab_index_attribute = " tabindex= \" $tab_index\ " " ;
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
2020-01-28 19:45:18 -05:00
// @todo Remove this?
2015-11-20 02:24:30 -05:00
// echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
2017-11-30 18:11:00 -05:00
$post_date = ( $for_post ) ? $post -> post_date : get_comment () -> comment_date ;
2019-03-07 04:12:51 -05:00
$jj = ( $edit ) ? mysql2date ( 'd' , $post_date , false ) : current_time ( 'd' );
$mm = ( $edit ) ? mysql2date ( 'm' , $post_date , false ) : current_time ( 'm' );
$aa = ( $edit ) ? mysql2date ( 'Y' , $post_date , false ) : current_time ( 'Y' );
$hh = ( $edit ) ? mysql2date ( 'H' , $post_date , false ) : current_time ( 'H' );
$mn = ( $edit ) ? mysql2date ( 'i' , $post_date , false ) : current_time ( 'i' );
$ss = ( $edit ) ? mysql2date ( 's' , $post_date , false ) : current_time ( 's' );
$cur_jj = current_time ( 'd' );
$cur_mm = current_time ( 'm' );
$cur_aa = current_time ( 'Y' );
$cur_hh = current_time ( 'H' );
$cur_mn = current_time ( 'i' );
2015-11-20 02:24:30 -05:00
2020-10-23 11:05:09 -04:00
$month = '<label><span class="screen-reader-text">' . __ ( 'Month' ) . '</span><select class="form-required" ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . " > \n " ;
2017-11-30 18:11:00 -05:00
for ( $i = 1 ; $i < 13 ; $i = $i + 1 ) {
$monthnum = zeroise ( $i , 2 );
2015-11-20 02:24:30 -05:00
$monthtext = $wp_locale -> get_month_abbrev ( $wp_locale -> get_month ( $i ) );
2017-11-30 18:11:00 -05:00
$month .= " \t \t \t " . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected ( $monthnum , $mm , false ) . '>' ;
2019-09-02 20:41:05 -04:00
/* translators: 1: Month number (01, 02, etc.), 2: Month abbreviation. */
2015-11-20 02:24:30 -05:00
$month .= sprintf ( __ ( '%1$s-%2$s' ), $monthnum , $monthtext ) . " </option> \n " ;
}
$month .= '</select></label>' ;
2020-10-23 11:05:09 -04:00
$day = '<label><span class="screen-reader-text">' . __ ( 'Day' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" class="form-required" /></label>' ;
$year = '<label><span class="screen-reader-text">' . __ ( 'Year' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" class="form-required" /></label>' ;
$hour = '<label><span class="screen-reader-text">' . __ ( 'Hour' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" class="form-required" /></label>' ;
$minute = '<label><span class="screen-reader-text">' . __ ( 'Minute' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" class="form-required" /></label>' ;
2015-11-20 02:24:30 -05:00
echo '<div class="timestamp-wrap">' ;
2019-09-02 20:41:05 -04:00
/* translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute. */
2019-09-08 19:24:56 -04:00
printf ( __ ( '%1$s %2$s, %3$s at %4$s:%5$s' ), $month , $day , $year , $hour , $minute );
2015-11-20 02:24:30 -05:00
echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />' ;
2017-11-30 18:11:00 -05:00
if ( $multi ) {
return ;
}
2015-11-20 02:24:30 -05:00
echo " \n \n " ;
2020-04-09 11:43:10 -04:00
2015-11-20 02:24:30 -05:00
$map = array (
'mm' => array ( $mm , $cur_mm ),
'jj' => array ( $jj , $cur_jj ),
'aa' => array ( $aa , $cur_aa ),
'hh' => array ( $hh , $cur_hh ),
'mn' => array ( $mn , $cur_mn ),
);
2020-04-09 11:43:10 -04:00
2015-11-20 02:24:30 -05:00
foreach ( $map as $timeunit => $value ) {
list ( $unit , $curr ) = $value ;
echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . " \n " ;
$cur_timeunit = 'cur_' . $timeunit ;
echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $curr . '" />' . " \n " ;
}
2018-08-16 21:51:36 -04:00
?>
2015-11-20 02:24:30 -05:00
< p >
2017-11-30 18:11:00 -05:00
< a href = " #edit_timestamp " class = " save-timestamp hide-if-no-js button " >< ? php _e ( 'OK' ); ?> </a>
< a href = " #edit_timestamp " class = " cancel-timestamp hide-if-no-js button-cancel " >< ? php _e ( 'Cancel' ); ?> </a>
2015-11-20 02:24:30 -05:00
</ p >
2018-08-16 21:51:36 -04:00
< ? php
2015-11-20 02:24:30 -05:00
}
/**
2022-03-28 05:45:06 -04:00
* Prints out option HTML elements for the page templates drop - down .
2015-11-20 02:24:30 -05:00
*
* @ since 1.5 . 0
Posts, Post Types: Add support for post type templates.
WordPress has supported custom page templates for over 12 years, allowing developers to create various layouts for specific pages.
While this feature is very helpful, it has always been limited to the 'page' post type and not was not available to other post types.
By opening up the page template functionality to all post types, we continue to improve the template hierarchy's flexibility.
In addition to the `Template Name` file header, the post types supported by a template can be specified using `Template Post Type: post, foo, bar`.
When at least one template exists for a post type, the 'Post Attributes' meta box will be displayed in the back end, without the need to add post type support for `'page-attributes'`. 'Post Attributes' can be customized per post type using the `'attributes'` label when registering a post type.
Props johnbillion, Mte90, dipesh.kakadiya, swissspidy.
Fixes #18375.
Built from https://develop.svn.wordpress.org/trunk@38951
git-svn-id: http://core.svn.wordpress.org/trunk@38894 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-10-26 04:07:30 -04:00
* @ since 4.7 . 0 Added the `$post_type` parameter .
2015-11-20 02:24:30 -05:00
*
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
* @ param string $default_template Optional . The template file name . Default empty .
* @ param string $post_type Optional . Post type to get templates for . Default 'post' .
2015-11-20 02:24:30 -05:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
function page_template_dropdown ( $default_template = '' , $post_type = 'page' ) {
Posts, Post Types: Add support for post type templates.
WordPress has supported custom page templates for over 12 years, allowing developers to create various layouts for specific pages.
While this feature is very helpful, it has always been limited to the 'page' post type and not was not available to other post types.
By opening up the page template functionality to all post types, we continue to improve the template hierarchy's flexibility.
In addition to the `Template Name` file header, the post types supported by a template can be specified using `Template Post Type: post, foo, bar`.
When at least one template exists for a post type, the 'Post Attributes' meta box will be displayed in the back end, without the need to add post type support for `'page-attributes'`. 'Post Attributes' can be customized per post type using the `'attributes'` label when registering a post type.
Props johnbillion, Mte90, dipesh.kakadiya, swissspidy.
Fixes #18375.
Built from https://develop.svn.wordpress.org/trunk@38951
git-svn-id: http://core.svn.wordpress.org/trunk@38894 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-10-26 04:07:30 -04:00
$templates = get_page_templates ( null , $post_type );
2020-04-09 11:43:10 -04:00
2015-11-20 02:24:30 -05:00
ksort ( $templates );
2020-04-09 11:43:10 -04:00
2015-11-20 02:24:30 -05:00
foreach ( array_keys ( $templates ) as $template ) {
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
$selected = selected ( $default_template , $templates [ $template ], false );
2017-11-30 18:11:00 -05:00
echo " \n \t <option value=' " . esc_attr ( $templates [ $template ] ) . " ' $selected > " . esc_html ( $template ) . '</option>' ;
2015-11-20 02:24:30 -05:00
}
}
/**
2022-03-28 05:45:06 -04:00
* Prints out option HTML elements for the page parents drop - down .
2015-11-20 02:24:30 -05:00
*
* @ since 1.5 . 0
* @ since 4.4 . 0 `$post` argument was added .
*
* @ global wpdb $wpdb WordPress database abstraction object .
*
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
* @ param int $default_page Optional . The default page ID to be pre - selected . Default 0.
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$parent` parameter to `$parent_page` in `parent_dropdown()`.
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55650.
Built from https://develop.svn.wordpress.org/trunk@53364
git-svn-id: http://core.svn.wordpress.org/trunk@52953 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-05-07 13:16:13 -04:00
* @ param int $parent_page Optional . The parent page ID . Default 0.
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
* @ param int $level Optional . Page depth level . Default 0.
* @ param int | WP_Post $post Post ID or WP_Post object .
2020-01-21 19:33:04 -05:00
* @ return void | false Void on success , false if the page has no children .
2015-11-20 02:24:30 -05:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$parent` parameter to `$parent_page` in `parent_dropdown()`.
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55650.
Built from https://develop.svn.wordpress.org/trunk@53364
git-svn-id: http://core.svn.wordpress.org/trunk@52953 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-05-07 13:16:13 -04:00
function parent_dropdown ( $default_page = 0 , $parent_page = 0 , $level = 0 , $post = null ) {
2015-11-20 02:24:30 -05:00
global $wpdb ;
2020-05-08 12:36:18 -04:00
2017-11-30 18:11:00 -05:00
$post = get_post ( $post );
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$parent` parameter to `$parent_page` in `parent_dropdown()`.
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55650.
Built from https://develop.svn.wordpress.org/trunk@53364
git-svn-id: http://core.svn.wordpress.org/trunk@52953 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-05-07 13:16:13 -04:00
$items = $wpdb -> get_results (
$wpdb -> prepare (
" SELECT ID, post_parent, post_title
FROM $wpdb -> posts
WHERE post_parent = % d AND post_type = 'page'
ORDER BY menu_order " ,
$parent_page
)
);
2015-11-20 02:24:30 -05:00
if ( $items ) {
foreach ( $items as $item ) {
// A page cannot be its own parent.
2020-05-08 12:36:18 -04:00
if ( $post && $post -> ID && ( int ) $item -> ID === $post -> ID ) {
2015-11-20 02:24:30 -05:00
continue ;
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
$pad = str_repeat ( ' ' , $level * 3 );
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
$selected = selected ( $default_page , $item -> ID , false );
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
echo " \n \t <option class='level- $level ' value=' $item->ID ' $selected > $pad " . esc_html ( $item -> post_title ) . '</option>' ;
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
parent_dropdown ( $default_page , $item -> ID , $level + 1 );
2015-11-20 02:24:30 -05:00
}
} else {
return false ;
}
}
/**
2022-03-28 05:45:06 -04:00
* Prints out option HTML elements for role selectors .
2015-11-20 02:24:30 -05:00
*
* @ since 2.1 . 0
*
* @ param string $selected Slug for the role that should be already selected .
*/
function wp_dropdown_roles ( $selected = '' ) {
$r = '' ;
$editable_roles = array_reverse ( get_editable_roles () );
foreach ( $editable_roles as $role => $details ) {
2017-11-30 18:11:00 -05:00
$name = translate_user_role ( $details [ 'name' ] );
2020-01-28 19:45:18 -05:00
// Preselect specified role.
2020-05-08 12:36:18 -04:00
if ( $selected === $role ) {
2017-03-24 10:53:46 -04:00
$r .= " \n \t <option selected='selected' value=' " . esc_attr ( $role ) . " '> $name </option> " ;
} else {
$r .= " \n \t <option value=' " . esc_attr ( $role ) . " '> $name </option> " ;
}
2015-11-20 02:24:30 -05:00
}
2017-03-24 10:53:46 -04:00
echo $r ;
2015-11-20 02:24:30 -05:00
}
/**
2022-07-21 05:24:10 -04:00
* Outputs the form used by the importers to accept the data to be imported .
2015-11-20 02:24:30 -05:00
*
* @ since 2.0 . 0
*
* @ param string $action The action attribute for the form .
*/
function wp_import_upload_form ( $action ) {
/**
2016-05-22 14:01:30 -04:00
* Filters the maximum allowed upload size for import files .
2015-11-20 02:24:30 -05:00
*
* @ since 2.3 . 0
*
* @ see wp_max_upload_size ()
*
* @ param int $max_upload_size Allowed upload size . Default 1 MB .
*/
2017-11-30 18:11:00 -05:00
$bytes = apply_filters ( 'import_upload_size_limit' , wp_max_upload_size () );
$size = size_format ( $bytes );
2015-11-20 02:24:30 -05:00
$upload_dir = wp_upload_dir ();
if ( ! empty ( $upload_dir [ 'error' ] ) ) :
2017-11-30 18:11:00 -05:00
?>
< div class = " error " >< p >< ? php _e ( 'Before you can upload your import file, you will need to fix the following error:' ); ?> </p>
< p >< strong >< ? php echo $upload_dir [ 'error' ]; ?> </strong></p></div>
2021-06-21 00:30:56 -04:00
< ? php
2015-11-20 02:24:30 -05:00
else :
2018-08-16 21:51:36 -04:00
?>
2015-11-20 02:24:30 -05:00
< form enctype = " multipart/form-data " id = " import-upload-form " method = " post " class = " wp-upload-form " action = " <?php echo esc_url( wp_nonce_url( $action , 'import-upload' ) ); ?> " >
< p >
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
< ? php
printf (
'<label for="upload">%s</label> (%s)' ,
__ ( 'Choose a file from your computer:' ),
2019-09-02 20:41:05 -04:00
/* translators: %s: Maximum allowed file size. */
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
sprintf ( __ ( 'Maximum size: %s' ), $size )
);
?>
2015-11-20 02:24:30 -05:00
< input type = " file " id = " upload " name = " import " size = " 25 " />
< input type = " hidden " name = " action " value = " save " />
< input type = " hidden " name = " max_file_size " value = " <?php echo $bytes ; ?> " />
</ p >
2018-08-16 21:51:36 -04:00
< ? php submit_button ( __ ( 'Upload file and import' ), 'primary' ); ?>
2015-11-20 02:24:30 -05:00
</ form >
2018-08-16 21:51:36 -04:00
< ? php
2015-11-20 02:24:30 -05:00
endif ;
}
/**
* Adds a meta box to one or more screens .
*
* @ since 2.5 . 0
* @ since 4.4 . 0 The `$screen` parameter now accepts an array of screen IDs .
*
* @ global array $wp_meta_boxes
*
* @ param string $id Meta box ID ( used in the 'id' attribute for the meta box ) .
* @ param string $title Title of the meta box .
* @ param callable $callback Function that fills the box with the desired content .
* The function should echo its output .
* @ param string | array | WP_Screen $screen Optional . The screen or screens on which to show the box
* ( such as a post type , 'link' , or 'comment' ) . Accepts a single
* screen ID , WP_Screen object , or array of screen IDs . Default
2017-10-02 17:52:52 -04:00
* is the current screen . If you have used add_menu_page () or
2017-06-30 00:18:43 -04:00
* add_submenu_page () to create a new screen ( and hence screen_id ),
* make sure your menu slug conforms to the limits of sanitize_key ()
* otherwise the 'screen' menu may not correctly render on your page .
2020-10-10 16:40:05 -04:00
* @ param string $context Optional . The context within the screen where the box
2015-11-20 02:24:30 -05:00
* should display . Available contexts vary from screen to
* screen . Post edit screen contexts include 'normal' , 'side' ,
* and 'advanced' . Comments screen contexts include 'normal'
* and 'side' . Menus meta boxes ( accordion sections ) all use
* the 'side' context . Global default is 'advanced' .
2020-10-10 16:40:05 -04:00
* @ param string $priority Optional . The priority within the context where the box should show .
* Accepts 'high' , 'core' , 'default' , or 'low' . Default 'default' .
2015-11-20 02:24:30 -05:00
* @ param array $callback_args Optional . Data that should be set as the $args property
* of the box array ( which is the second parameter passed
* to your callback ) . Default null .
*/
function add_meta_box ( $id , $title , $callback , $screen = null , $context = 'advanced' , $priority = 'default' , $callback_args = null ) {
global $wp_meta_boxes ;
if ( empty ( $screen ) ) {
$screen = get_current_screen ();
} elseif ( is_string ( $screen ) ) {
$screen = convert_to_screen ( $screen );
} elseif ( is_array ( $screen ) ) {
foreach ( $screen as $single_screen ) {
add_meta_box ( $id , $title , $callback , $single_screen , $context , $priority , $callback_args );
}
}
if ( ! isset ( $screen -> id ) ) {
return ;
}
$page = $screen -> id ;
2017-11-30 18:11:00 -05:00
if ( ! isset ( $wp_meta_boxes ) ) {
2015-11-20 02:24:30 -05:00
$wp_meta_boxes = array ();
2017-11-30 18:11:00 -05:00
}
if ( ! isset ( $wp_meta_boxes [ $page ] ) ) {
$wp_meta_boxes [ $page ] = array ();
}
if ( ! isset ( $wp_meta_boxes [ $page ][ $context ] ) ) {
$wp_meta_boxes [ $page ][ $context ] = array ();
}
foreach ( array_keys ( $wp_meta_boxes [ $page ] ) as $a_context ) {
foreach ( array ( 'high' , 'core' , 'default' , 'low' ) as $a_priority ) {
if ( ! isset ( $wp_meta_boxes [ $page ][ $a_context ][ $a_priority ][ $id ] ) ) {
2015-11-20 02:24:30 -05:00
continue ;
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
2020-05-09 08:26:12 -04:00
// If a core box was previously removed, don't add.
if ( ( 'core' === $priority || 'sorted' === $priority )
&& false === $wp_meta_boxes [ $page ][ $a_context ][ $a_priority ][ $id ]
) {
return ;
}
2015-11-20 02:24:30 -05:00
2020-05-09 08:26:12 -04:00
// If a core box was previously added by a plugin, don't add.
if ( 'core' === $priority ) {
2015-11-20 02:24:30 -05:00
/*
2020-05-09 08:26:12 -04:00
* If the box was added with default priority , give it core priority
* to maintain sort order .
2015-11-20 02:24:30 -05:00
*/
2020-05-08 12:36:18 -04:00
if ( 'default' === $a_priority ) {
2017-11-30 18:11:00 -05:00
$wp_meta_boxes [ $page ][ $a_context ][ 'core' ][ $id ] = $wp_meta_boxes [ $page ][ $a_context ][ 'default' ][ $id ];
unset ( $wp_meta_boxes [ $page ][ $a_context ][ 'default' ][ $id ] );
2015-11-20 02:24:30 -05:00
}
return ;
}
2020-05-09 08:26:12 -04:00
2020-01-28 19:45:18 -05:00
// If no priority given and ID already present, use existing priority.
2017-11-30 18:11:00 -05:00
if ( empty ( $priority ) ) {
2015-11-20 02:24:30 -05:00
$priority = $a_priority ;
2017-11-30 18:11:00 -05:00
/*
2020-05-09 08:26:12 -04:00
* Else , if we 're adding to the sorted priority, we don' t know the title
* or callback . Grab them from the previously added context / priority .
*/
2020-05-08 12:36:18 -04:00
} elseif ( 'sorted' === $priority ) {
2017-11-30 18:11:00 -05:00
$title = $wp_meta_boxes [ $page ][ $a_context ][ $a_priority ][ $id ][ 'title' ];
$callback = $wp_meta_boxes [ $page ][ $a_context ][ $a_priority ][ $id ][ 'callback' ];
$callback_args = $wp_meta_boxes [ $page ][ $a_context ][ $a_priority ][ $id ][ 'args' ];
2015-11-20 02:24:30 -05:00
}
2020-05-08 12:36:18 -04:00
2020-01-28 19:45:18 -05:00
// An ID can be in only one priority and one context.
2020-05-08 12:36:18 -04:00
if ( $priority !== $a_priority || $context !== $a_context ) {
2017-11-30 18:11:00 -05:00
unset ( $wp_meta_boxes [ $page ][ $a_context ][ $a_priority ][ $id ] );
}
2015-11-20 02:24:30 -05:00
}
}
2017-11-30 18:11:00 -05:00
if ( empty ( $priority ) ) {
2015-11-20 02:24:30 -05:00
$priority = 'low' ;
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
if ( ! isset ( $wp_meta_boxes [ $page ][ $context ][ $priority ] ) ) {
$wp_meta_boxes [ $page ][ $context ][ $priority ] = array ();
}
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
$wp_meta_boxes [ $page ][ $context ][ $priority ][ $id ] = array (
'id' => $id ,
'title' => $title ,
'callback' => $callback ,
'args' => $callback_args ,
);
2015-11-20 02:24:30 -05:00
}
2018-12-17 16:52:53 -05:00
/**
2022-03-28 05:45:06 -04:00
* Renders a " fake " meta box with an information message ,
2018-12-17 16:52:53 -05:00
* shown on the block editor , when an incompatible meta box is found .
*
* @ since 5.0 . 0
*
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
* @ param mixed $data_object The data object being rendered on this screen .
* @ param array $box {
2018-12-17 16:52:53 -05:00
* Custom formats meta box arguments .
*
* @ type string $id Meta box 'id' attribute .
* @ type string $title Meta box title .
* @ type callable $old_callback The original callback for this meta box .
* @ type array $args Extra meta box arguments .
* }
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
function do_block_editor_incompatible_meta_box ( $data_object , $box ) {
2018-12-17 16:52:53 -05:00
$plugin = _get_plugin_from_callback ( $box [ 'old_callback' ] );
$plugins = get_plugins ();
echo '<p>' ;
if ( $plugin ) {
2019-09-02 20:41:05 -04:00
/* translators: %s: The name of the plugin that generated this meta box. */
Administration: Replace contracted verb forms for better consistency.
This changeset replaces contracted verb forms like `doesn't`, `can't`, or `isn't` with non-contracted forms like `does not`, `cannot`, or `is not`, for better consistency across the WordPress administration. It also updates some corresponding unit tests strings.
Props Presskopp, socalchristina, aandrewdixon, francina, SergeyBiryukov, JeffPaul, audrasjb, hellofromTonya.
Fixes #38913.
See #39176.
Built from https://develop.svn.wordpress.org/trunk@52978
git-svn-id: http://core.svn.wordpress.org/trunk@52567 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-22 12:25:03 -04:00
printf ( __ ( 'This meta box, from the %s plugin, is not compatible with the block editor.' ), " <strong> { $plugin [ 'Name' ] } </strong> " );
2018-12-17 16:52:53 -05:00
} else {
Administration: Replace contracted verb forms for better consistency.
This changeset replaces contracted verb forms like `doesn't`, `can't`, or `isn't` with non-contracted forms like `does not`, `cannot`, or `is not`, for better consistency across the WordPress administration. It also updates some corresponding unit tests strings.
Props Presskopp, socalchristina, aandrewdixon, francina, SergeyBiryukov, JeffPaul, audrasjb, hellofromTonya.
Fixes #38913.
See #39176.
Built from https://develop.svn.wordpress.org/trunk@52978
git-svn-id: http://core.svn.wordpress.org/trunk@52567 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-22 12:25:03 -04:00
_e ( 'This meta box is not compatible with the block editor.' );
2018-12-17 16:52:53 -05:00
}
echo '</p>' ;
if ( empty ( $plugins [ 'classic-editor/classic-editor.php' ] ) ) {
if ( current_user_can ( 'install_plugins' ) ) {
2021-05-25 16:14:59 -04:00
$install_url = wp_nonce_url (
self_admin_url ( 'plugin-install.php?tab=favorites&user=wordpressdotorg&save=0' ),
'save_wporg_username_' . get_current_user_id ()
2019-07-17 21:33:57 -04:00
);
2021-05-25 16:14:59 -04:00
echo '<p>' ;
/* translators: %s: A link to install the Classic Editor plugin. */
printf ( __ ( 'Please install the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), esc_url ( $install_url ) );
2018-12-17 16:52:53 -05:00
echo '</p>' ;
}
} elseif ( is_plugin_inactive ( 'classic-editor/classic-editor.php' ) ) {
if ( current_user_can ( 'activate_plugins' ) ) {
2021-05-25 16:14:59 -04:00
$activate_url = wp_nonce_url (
self_admin_url ( 'plugins.php?action=activate&plugin=classic-editor/classic-editor.php' ),
'activate-plugin_classic-editor/classic-editor.php'
);
2018-12-17 16:52:53 -05:00
echo '<p>' ;
/* translators: %s: A link to activate the Classic Editor plugin. */
printf ( __ ( 'Please activate the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), esc_url ( $activate_url ) );
echo '</p>' ;
}
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
} elseif ( $data_object instanceof WP_Post ) {
2019-07-11 02:01:58 -04:00
$edit_url = add_query_arg (
array (
'classic-editor' => '' ,
'classic-editor__forget' => '' ,
),
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
get_edit_post_link ( $data_object )
2019-07-11 02:01:58 -04:00
);
2018-12-17 16:52:53 -05:00
echo '<p>' ;
/* translators: %s: A link to use the Classic Editor plugin. */
printf ( __ ( 'Please open the <a href="%s">classic editor</a> to use this meta box.' ), esc_url ( $edit_url ) );
echo '</p>' ;
}
}
2015-11-20 02:24:30 -05:00
/**
2018-12-17 16:52:53 -05:00
* Internal helper function to find the plugin from a meta box callback .
*
* @ since 5.0 . 0
*
* @ access private
*
* @ param callable $callback The callback function to check .
* @ return array | null The plugin that the callback belongs to , or null if it doesn ' t belong to a plugin .
*/
function _get_plugin_from_callback ( $callback ) {
try {
if ( is_array ( $callback ) ) {
$reflection = new ReflectionMethod ( $callback [ 0 ], $callback [ 1 ] );
} elseif ( is_string ( $callback ) && false !== strpos ( $callback , '::' ) ) {
$reflection = new ReflectionMethod ( $callback );
} else {
$reflection = new ReflectionFunction ( $callback );
}
} catch ( ReflectionException $exception ) {
// We could not properly reflect on the callable, so we abort here.
return null ;
}
// Don't show an error if it's an internal PHP function.
if ( ! $reflection -> isInternal () ) {
// Only show errors if the meta box was registered by a plugin.
$filename = wp_normalize_path ( $reflection -> getFileName () );
$plugin_dir = wp_normalize_path ( WP_PLUGIN_DIR );
2020-04-09 11:43:10 -04:00
2018-12-17 16:52:53 -05:00
if ( strpos ( $filename , $plugin_dir ) === 0 ) {
$filename = str_replace ( $plugin_dir , '' , $filename );
$filename = preg_replace ( '|^/([^/]*/).*$|' , '\\1' , $filename );
$plugins = get_plugins ();
2020-04-09 11:43:10 -04:00
2018-12-17 16:52:53 -05:00
foreach ( $plugins as $name => $plugin ) {
if ( strpos ( $name , $filename ) === 0 ) {
return $plugin ;
}
}
}
}
return null ;
}
/**
* Meta - Box template function .
2015-11-20 02:24:30 -05:00
*
* @ since 2.5 . 0
*
* @ global array $wp_meta_boxes
*
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
* @ param string | WP_Screen $screen The screen identifier . If you have used add_menu_page () or
* add_submenu_page () to create a new screen ( and hence screen_id )
* make sure your menu slug conforms to the limits of sanitize_key ()
* otherwise the 'screen' menu may not correctly render on your page .
* @ param string $context The screen context for which to display meta boxes .
* @ param mixed $data_object Gets passed to the meta box callback function as the first parameter .
* Often this is the object that ' s the focus of the current screen ,
* for example a `WP_Post` or `WP_Comment` object .
2020-05-08 12:36:18 -04:00
* @ return int Number of meta_boxes .
2015-11-20 02:24:30 -05:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
function do_meta_boxes ( $screen , $context , $data_object ) {
2015-11-20 02:24:30 -05:00
global $wp_meta_boxes ;
static $already_sorted = false ;
2017-11-30 18:11:00 -05:00
if ( empty ( $screen ) ) {
2015-11-20 02:24:30 -05:00
$screen = get_current_screen ();
2017-11-30 18:11:00 -05:00
} elseif ( is_string ( $screen ) ) {
2015-11-20 02:24:30 -05:00
$screen = convert_to_screen ( $screen );
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
$page = $screen -> id ;
$hidden = get_hidden_meta_boxes ( $screen );
2018-06-27 22:37:51 -04:00
printf ( '<div id="%s-sortables" class="meta-box-sortables">' , esc_attr ( $context ) );
2015-11-20 02:24:30 -05:00
2020-01-28 19:45:18 -05:00
// Grab the ones the user has manually sorted.
// Pull them out of their previous context/priority and into the one the user chose.
2019-07-01 08:52:01 -04:00
$sorted = get_user_option ( " meta-box-order_ $page " );
2020-04-09 11:43:10 -04:00
2019-07-01 08:52:01 -04:00
if ( ! $already_sorted && $sorted ) {
2015-11-20 02:24:30 -05:00
foreach ( $sorted as $box_context => $ids ) {
foreach ( explode ( ',' , $ids ) as $id ) {
if ( $id && 'dashboard_browser_nag' !== $id ) {
add_meta_box ( $id , null , null , $screen , $box_context , 'sorted' );
}
}
}
}
$already_sorted = true ;
$i = 0 ;
if ( isset ( $wp_meta_boxes [ $page ][ $context ] ) ) {
foreach ( array ( 'high' , 'sorted' , 'core' , 'default' , 'low' ) as $priority ) {
2017-11-30 18:11:00 -05:00
if ( isset ( $wp_meta_boxes [ $page ][ $context ][ $priority ] ) ) {
2015-11-20 02:24:30 -05:00
foreach ( ( array ) $wp_meta_boxes [ $page ][ $context ][ $priority ] as $box ) {
2020-05-08 12:36:18 -04:00
if ( false === $box || ! $box [ 'title' ] ) {
2015-11-20 02:24:30 -05:00
continue ;
2017-11-30 18:11:00 -05:00
}
2018-12-13 20:18:38 -05:00
2018-12-14 04:42:53 -05:00
$block_compatible = true ;
2018-12-14 06:02:53 -05:00
if ( is_array ( $box [ 'args' ] ) ) {
2018-12-14 04:39:51 -05:00
// If a meta box is just here for back compat, don't show it in the block editor.
if ( $screen -> is_block_editor () && isset ( $box [ 'args' ][ '__back_compat_meta_box' ] ) && $box [ 'args' ][ '__back_compat_meta_box' ] ) {
continue ;
}
2018-12-13 20:18:38 -05:00
2018-12-14 04:39:51 -05:00
if ( isset ( $box [ 'args' ][ '__block_editor_compatible_meta_box' ] ) ) {
$block_compatible = ( bool ) $box [ 'args' ][ '__block_editor_compatible_meta_box' ];
unset ( $box [ 'args' ][ '__block_editor_compatible_meta_box' ] );
}
2018-12-13 20:18:38 -05:00
2018-12-17 16:52:53 -05:00
// If the meta box is declared as incompatible with the block editor, override the callback function.
if ( ! $block_compatible && $screen -> is_block_editor () ) {
$box [ 'old_callback' ] = $box [ 'callback' ];
$box [ 'callback' ] = 'do_block_editor_incompatible_meta_box' ;
}
2018-12-14 04:39:51 -05:00
if ( isset ( $box [ 'args' ][ '__back_compat_meta_box' ] ) ) {
$block_compatible = $block_compatible || ( bool ) $box [ 'args' ][ '__back_compat_meta_box' ];
unset ( $box [ 'args' ][ '__back_compat_meta_box' ] );
}
2018-12-13 20:18:38 -05:00
}
2015-11-20 02:24:30 -05:00
$i ++ ;
2018-12-16 22:21:21 -05:00
// get_hidden_meta_boxes() doesn't apply in the block editor.
2020-04-04 23:02:11 -04:00
$hidden_class = ( ! $screen -> is_block_editor () && in_array ( $box [ 'id' ], $hidden , true ) ) ? ' hide-if-js' : '' ;
2017-11-30 18:11:00 -05:00
echo '<div id="' . $box [ 'id' ] . '" class="postbox ' . postbox_classes ( $box [ 'id' ], $page ) . $hidden_class . '" ' . '>' . " \n " ;
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 09:00:02 -04:00
echo '<div class="postbox-header">' ;
echo '<h2 class="hndle">' ;
if ( 'dashboard_php_nag' === $box [ 'id' ] ) {
echo '<span aria-hidden="true" class="dashicons dashicons-warning"></span>' ;
echo '<span class="screen-reader-text">' . __ ( 'Warning:' ) . ' </span>' ;
}
2020-10-08 17:15:13 -04:00
echo $box [ 'title' ];
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 09:00:02 -04:00
echo " </h2> \n " ;
2020-05-08 12:36:18 -04:00
if ( 'dashboard_browser_nag' !== $box [ 'id' ] ) {
2017-11-30 18:11:00 -05:00
$widget_title = $box [ 'title' ];
2016-07-05 11:22:29 -04:00
2017-11-30 18:11:00 -05:00
if ( is_array ( $box [ 'args' ] ) && isset ( $box [ 'args' ][ '__widget_basename' ] ) ) {
$widget_title = $box [ 'args' ][ '__widget_basename' ];
2016-07-05 11:22:29 -04:00
// Do not pass this parameter to the user callback function.
2017-11-30 18:11:00 -05:00
unset ( $box [ 'args' ][ '__widget_basename' ] );
2016-07-05 11:22:29 -04:00
}
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 09:00:02 -04:00
echo '<div class="handle-actions hide-if-no-js">' ;
2020-10-27 06:47:12 -04:00
echo '<button type="button" class="handle-order-higher" aria-disabled="false" aria-describedby="' . $box [ 'id' ] . '-handle-order-higher-description">' ;
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 09:00:02 -04:00
echo '<span class="screen-reader-text">' . __ ( 'Move up' ) . '</span>' ;
echo '<span class="order-higher-indicator" aria-hidden="true"></span>' ;
echo '</button>' ;
echo '<span class="hidden" id="' . $box [ 'id' ] . '-handle-order-higher-description">' . sprintf (
/* translators: %s: Meta box title. */
__ ( 'Move %s box up' ),
$widget_title
) . '</span>' ;
2020-10-27 06:47:12 -04:00
echo '<button type="button" class="handle-order-lower" aria-disabled="false" aria-describedby="' . $box [ 'id' ] . '-handle-order-lower-description">' ;
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 09:00:02 -04:00
echo '<span class="screen-reader-text">' . __ ( 'Move down' ) . '</span>' ;
echo '<span class="order-lower-indicator" aria-hidden="true"></span>' ;
echo '</button>' ;
echo '<span class="hidden" id="' . $box [ 'id' ] . '-handle-order-lower-description">' . sprintf (
/* translators: %s: Meta box title. */
__ ( 'Move %s box down' ),
$widget_title
) . '</span>' ;
2017-02-14 13:42:46 -05:00
echo '<button type="button" class="handlediv" aria-expanded="true">' ;
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
echo '<span class="screen-reader-text">' . sprintf (
2020-01-20 10:43:04 -05:00
/* translators: %s: Meta box title. */
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
__ ( 'Toggle panel: %s' ),
$widget_title
) . '</span>' ;
2015-11-20 02:24:30 -05:00
echo '<span class="toggle-indicator" aria-hidden="true"></span>' ;
echo '</button>' ;
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 09:00:02 -04:00
echo '</div>' ;
2015-11-20 02:24:30 -05:00
}
Accessibility: Allow post boxes on the Dashboard and Classic Editor pages to be reordered by using the keyboard.
So far, it has been possible to rearrange into a new order the post boxes (also known as "widgets" on the Dashboard and "meta boxes" on the Edit post page) only by using a pointing device, for example a mouse.
This change adds new controls and functionality to allow the boxes to be rearranged also with the keyboard. Additionally, audible messages are sent to the admin ARIA live region to notify screen reader users of the reorder action result.
Props joedolson, anevins, antpb, audrasjb, xkon, MarcoZ, karmatosed, afercia.
Fixes #39074.
Built from https://develop.svn.wordpress.org/trunk@48373
git-svn-id: http://core.svn.wordpress.org/trunk@48142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 09:00:02 -04:00
echo '</div>' ;
2015-11-20 02:24:30 -05:00
echo '<div class="inside">' . " \n " ;
2018-12-13 20:18:38 -05:00
2018-12-14 04:42:53 -05:00
if ( WP_DEBUG && ! $block_compatible && 'edit' === $screen -> parent_base && ! $screen -> is_block_editor () && ! isset ( $_GET [ 'meta-box-loader' ] ) ) {
2018-12-17 16:52:53 -05:00
$plugin = _get_plugin_from_callback ( $box [ 'callback' ] );
if ( $plugin ) {
?>
< div class = " error inline " >
< p >
< ? php
2019-09-02 20:41:05 -04:00
/* translators: %s: The name of the plugin that generated this meta box. */
Administration: Replace contracted verb forms for better consistency.
This changeset replaces contracted verb forms like `doesn't`, `can't`, or `isn't` with non-contracted forms like `does not`, `cannot`, or `is not`, for better consistency across the WordPress administration. It also updates some corresponding unit tests strings.
Props Presskopp, socalchristina, aandrewdixon, francina, SergeyBiryukov, JeffPaul, audrasjb, hellofromTonya.
Fixes #38913.
See #39176.
Built from https://develop.svn.wordpress.org/trunk@52978
git-svn-id: http://core.svn.wordpress.org/trunk@52567 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-22 12:25:03 -04:00
printf ( __ ( 'This meta box, from the %s plugin, is not compatible with the block editor.' ), " <strong> { $plugin [ 'Name' ] } </strong> " );
2018-12-17 16:52:53 -05:00
?>
</ p >
</ div >
< ? php
2018-12-13 20:18:38 -05:00
}
}
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
call_user_func ( $box [ 'callback' ], $data_object , $box );
2015-11-20 02:24:30 -05:00
echo " </div> \n " ;
echo " </div> \n " ;
}
}
}
}
2017-11-30 18:11:00 -05:00
echo '</div>' ;
2015-11-20 02:24:30 -05:00
return $i ;
}
/**
* Removes a meta box from one or more screens .
*
* @ since 2.6 . 0
* @ since 4.4 . 0 The `$screen` parameter now accepts an array of screen IDs .
*
* @ global array $wp_meta_boxes
*
* @ param string $id Meta box ID ( used in the 'id' attribute for the meta box ) .
* @ param string | array | WP_Screen $screen The screen or screens on which the meta box is shown ( such as a
* post type , 'link' , or 'comment' ) . Accepts a single screen ID ,
* WP_Screen object , or array of screen IDs .
2016-05-23 16:57:28 -04:00
* @ param string $context The context within the screen where the box is set to display .
* Contexts vary from screen to screen . Post edit screen contexts
* include 'normal' , 'side' , and 'advanced' . Comments screen contexts
* include 'normal' and 'side' . Menus meta boxes ( accordion sections )
* all use the 'side' context .
2015-11-20 02:24:30 -05:00
*/
function remove_meta_box ( $id , $screen , $context ) {
global $wp_meta_boxes ;
if ( empty ( $screen ) ) {
$screen = get_current_screen ();
} elseif ( is_string ( $screen ) ) {
$screen = convert_to_screen ( $screen );
} elseif ( is_array ( $screen ) ) {
foreach ( $screen as $single_screen ) {
remove_meta_box ( $id , $single_screen , $context );
}
}
if ( ! isset ( $screen -> id ) ) {
return ;
}
$page = $screen -> id ;
2017-11-30 18:11:00 -05:00
if ( ! isset ( $wp_meta_boxes ) ) {
2015-11-20 02:24:30 -05:00
$wp_meta_boxes = array ();
2017-11-30 18:11:00 -05:00
}
if ( ! isset ( $wp_meta_boxes [ $page ] ) ) {
$wp_meta_boxes [ $page ] = array ();
}
if ( ! isset ( $wp_meta_boxes [ $page ][ $context ] ) ) {
$wp_meta_boxes [ $page ][ $context ] = array ();
}
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
foreach ( array ( 'high' , 'core' , 'default' , 'low' ) as $priority ) {
$wp_meta_boxes [ $page ][ $context ][ $priority ][ $id ] = false ;
}
2015-11-20 02:24:30 -05:00
}
/**
2019-01-17 20:03:50 -05:00
* Meta Box Accordion Template Function .
2015-11-20 02:24:30 -05:00
*
2016-05-22 13:22:27 -04:00
* Largely made up of abstracted code from do_meta_boxes (), this
2015-11-20 02:24:30 -05:00
* function serves to build meta boxes as list items for display as
* a collapsible accordion .
*
* @ since 3.6 . 0
*
* @ uses global $wp_meta_boxes Used to retrieve registered meta boxes .
*
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
* @ param string | object $screen The screen identifier .
* @ param string $context The screen context for which to display accordion sections .
* @ param mixed $data_object Gets passed to the section callback function as the first parameter .
2020-05-08 12:36:18 -04:00
* @ return int Number of meta boxes as accordion sections .
2015-11-20 02:24:30 -05:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
function do_accordion_sections ( $screen , $context , $data_object ) {
2015-11-20 02:24:30 -05:00
global $wp_meta_boxes ;
2013-03-15 09:16:38 -04:00
2015-11-20 02:24:30 -05:00
wp_enqueue_script ( 'accordion' );
2017-11-30 18:11:00 -05:00
if ( empty ( $screen ) ) {
2015-11-20 02:24:30 -05:00
$screen = get_current_screen ();
2017-11-30 18:11:00 -05:00
} elseif ( is_string ( $screen ) ) {
2015-11-20 02:24:30 -05:00
$screen = convert_to_screen ( $screen );
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
$page = $screen -> id ;
2018-12-10 23:45:23 -05:00
$hidden = get_hidden_meta_boxes ( $screen );
2015-11-20 02:24:30 -05:00
?>
< div id = " side-sortables " class = " accordion-container " >
< ul class = " outer-border " >
< ? php
2017-11-30 18:11:00 -05:00
$i = 0 ;
2015-11-20 02:24:30 -05:00
$first_open = false ;
if ( isset ( $wp_meta_boxes [ $page ][ $context ] ) ) {
foreach ( array ( 'high' , 'core' , 'default' , 'low' ) as $priority ) {
if ( isset ( $wp_meta_boxes [ $page ][ $context ][ $priority ] ) ) {
foreach ( $wp_meta_boxes [ $page ][ $context ][ $priority ] as $box ) {
2020-05-08 12:36:18 -04:00
if ( false === $box || ! $box [ 'title' ] ) {
2015-11-20 02:24:30 -05:00
continue ;
2017-11-30 18:11:00 -05:00
}
2020-05-08 12:36:18 -04:00
2015-11-20 02:24:30 -05:00
$i ++ ;
2020-04-04 23:02:11 -04:00
$hidden_class = in_array ( $box [ 'id' ], $hidden , true ) ? 'hide-if-js' : '' ;
2015-11-20 02:24:30 -05:00
$open_class = '' ;
if ( ! $first_open && empty ( $hidden_class ) ) {
$first_open = true ;
$open_class = 'open' ;
}
?>
< li class = " control-section accordion-section <?php echo $hidden_class ; ?> <?php echo $open_class ; ?> <?php echo esc_attr( $box['id'] ); ?> " id = " <?php echo esc_attr( $box['id'] ); ?> " >
< h3 class = " accordion-section-title hndle " tabindex = " 0 " >
< ? php echo esc_html ( $box [ 'title' ] ); ?>
< span class = " screen-reader-text " >< ? php _e ( 'Press return or enter to open this section' ); ?> </span>
</ h3 >
< div class = " accordion-section-content <?php postbox_classes( $box['id'] , $page ); ?> " >
< div class = " inside " >
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
< ? php call_user_func ( $box [ 'callback' ], $data_object , $box ); ?>
2015-11-20 02:24:30 -05:00
</ div ><!-- . inside -->
</ div ><!-- . accordion - section - content -->
</ li ><!-- . accordion - section -->
< ? php
}
}
}
}
?>
</ ul ><!-- . outer - border -->
</ div ><!-- . accordion - container -->
< ? php
return $i ;
}
/**
2022-03-28 05:45:06 -04:00
* Adds a new section to a settings page .
2015-11-20 02:24:30 -05:00
*
* Part of the Settings API . Use this to define new settings sections for an admin page .
* Show settings sections in your admin page callback function with do_settings_sections () .
2019-01-17 20:03:50 -05:00
* Add settings fields to your section with add_settings_field () .
2015-11-20 02:24:30 -05:00
*
* The $callback argument should be the name of a function that echoes out any
* content you want to show at the top of the settings section before the actual
* fields . It can output nothing if you want .
*
* @ since 2.7 . 0
Administration: Allow to wrap Settings sections with custom HTML content.
This changeset improves the `add_settings_section()` function to allow developers to pass extra HTML mark-up to be rendered before and after the settings section. Extra argument `$args` can now be passed to the function, and is an array that can contain the following items:
- `before_section`: HTML content to prepend to the section's HTML output. Receives the section's class name provided with the `section_class` argument via an optional `%s` placeholder. Default empty.
- `after_section`: HTML content to append to the section's HTML output. Default empty.
- `section_class`: The class name to use for the section. Used by `before_section` if a `%s` placeholder is present. Default empty.
The HTML passed using these extra arguments is escaped using `wp_kses_post()` just before rendering. This changeset also provides a set of unit tests for this new feature.
Props griffinjt, nacin, scribu, ross_ritchey, ryan, chriscct7, palmiak, rehanali, costdev, martinkrcho, chaion07, audrasjb, hellofromtonya.
Fixes #17851.
Built from https://develop.svn.wordpress.org/trunk@54247
git-svn-id: http://core.svn.wordpress.org/trunk@53806 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-20 05:59:12 -04:00
* @ since 6.1 . 0 Added an `$args` parameter for the section ' s HTML wrapper and class name .
2015-11-20 02:24:30 -05:00
*
2020-07-23 03:39:02 -04:00
* @ global array $wp_settings_sections Storage array of all settings sections added to admin pages .
2015-11-20 02:24:30 -05:00
*
2016-02-23 13:05:27 -05:00
* @ param string $id Slug - name to identify the section . Used in the 'id' attribute of tags .
* @ param string $title Formatted title of the section . Shown as the heading for the section .
* @ param callable $callback Function that echos out any content at the top of the section ( between heading and fields ) .
* @ param string $page The slug - name of the settings page on which to show the section . Built - in pages include
* 'general' , 'reading' , 'writing' , 'discussion' , 'media' , etc . Create your own using
* add_options_page ();
Administration: Allow to wrap Settings sections with custom HTML content.
This changeset improves the `add_settings_section()` function to allow developers to pass extra HTML mark-up to be rendered before and after the settings section. Extra argument `$args` can now be passed to the function, and is an array that can contain the following items:
- `before_section`: HTML content to prepend to the section's HTML output. Receives the section's class name provided with the `section_class` argument via an optional `%s` placeholder. Default empty.
- `after_section`: HTML content to append to the section's HTML output. Default empty.
- `section_class`: The class name to use for the section. Used by `before_section` if a `%s` placeholder is present. Default empty.
The HTML passed using these extra arguments is escaped using `wp_kses_post()` just before rendering. This changeset also provides a set of unit tests for this new feature.
Props griffinjt, nacin, scribu, ross_ritchey, ryan, chriscct7, palmiak, rehanali, costdev, martinkrcho, chaion07, audrasjb, hellofromtonya.
Fixes #17851.
Built from https://develop.svn.wordpress.org/trunk@54247
git-svn-id: http://core.svn.wordpress.org/trunk@53806 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-20 05:59:12 -04:00
* @ param array $args {
* Arguments used to create the settings section .
*
* @ type string $before_section HTML content to prepend to the section ' s HTML output .
* Receives the section ' s class name as `%s` . Default empty .
* @ type string $after_section HTML content to append to the section ' s HTML output . Default empty .
* @ type string $section_class The class name to use for the section . Default empty .
* }
2015-11-20 02:24:30 -05:00
*/
Administration: Allow to wrap Settings sections with custom HTML content.
This changeset improves the `add_settings_section()` function to allow developers to pass extra HTML mark-up to be rendered before and after the settings section. Extra argument `$args` can now be passed to the function, and is an array that can contain the following items:
- `before_section`: HTML content to prepend to the section's HTML output. Receives the section's class name provided with the `section_class` argument via an optional `%s` placeholder. Default empty.
- `after_section`: HTML content to append to the section's HTML output. Default empty.
- `section_class`: The class name to use for the section. Used by `before_section` if a `%s` placeholder is present. Default empty.
The HTML passed using these extra arguments is escaped using `wp_kses_post()` just before rendering. This changeset also provides a set of unit tests for this new feature.
Props griffinjt, nacin, scribu, ross_ritchey, ryan, chriscct7, palmiak, rehanali, costdev, martinkrcho, chaion07, audrasjb, hellofromtonya.
Fixes #17851.
Built from https://develop.svn.wordpress.org/trunk@54247
git-svn-id: http://core.svn.wordpress.org/trunk@53806 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-20 05:59:12 -04:00
function add_settings_section ( $id , $title , $callback , $page , $args = array () ) {
2015-11-20 02:24:30 -05:00
global $wp_settings_sections ;
Administration: Allow to wrap Settings sections with custom HTML content.
This changeset improves the `add_settings_section()` function to allow developers to pass extra HTML mark-up to be rendered before and after the settings section. Extra argument `$args` can now be passed to the function, and is an array that can contain the following items:
- `before_section`: HTML content to prepend to the section's HTML output. Receives the section's class name provided with the `section_class` argument via an optional `%s` placeholder. Default empty.
- `after_section`: HTML content to append to the section's HTML output. Default empty.
- `section_class`: The class name to use for the section. Used by `before_section` if a `%s` placeholder is present. Default empty.
The HTML passed using these extra arguments is escaped using `wp_kses_post()` just before rendering. This changeset also provides a set of unit tests for this new feature.
Props griffinjt, nacin, scribu, ross_ritchey, ryan, chriscct7, palmiak, rehanali, costdev, martinkrcho, chaion07, audrasjb, hellofromtonya.
Fixes #17851.
Built from https://develop.svn.wordpress.org/trunk@54247
git-svn-id: http://core.svn.wordpress.org/trunk@53806 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-20 05:59:12 -04:00
$defaults = array (
'id' => $id ,
'title' => $title ,
'callback' => $callback ,
'before_section' => '' ,
'after_section' => '' ,
'section_class' => '' ,
);
$section = wp_parse_args ( $args , $defaults );
2020-05-08 12:36:18 -04:00
if ( 'misc' === $page ) {
2017-11-30 18:11:00 -05:00
_deprecated_argument (
2018-08-16 21:51:36 -04:00
__FUNCTION__ ,
'3.0.0' ,
2017-11-30 18:11:00 -05:00
sprintf (
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
/* translators: %s: misc */
2017-11-30 18:11:00 -05:00
__ ( 'The "%s" options group has been removed. Use another settings group.' ),
2017-01-29 06:50:41 -05:00
'misc'
)
);
2015-11-20 02:24:30 -05:00
$page = 'general' ;
}
2020-05-08 12:36:18 -04:00
if ( 'privacy' === $page ) {
2017-11-30 18:11:00 -05:00
_deprecated_argument (
2018-08-16 21:51:36 -04:00
__FUNCTION__ ,
'3.5.0' ,
2017-11-30 18:11:00 -05:00
sprintf (
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
/* translators: %s: privacy */
2017-11-30 18:11:00 -05:00
__ ( 'The "%s" options group has been removed. Use another settings group.' ),
2017-01-29 06:50:41 -05:00
'privacy'
)
);
2015-11-20 02:24:30 -05:00
$page = 'reading' ;
}
Administration: Allow to wrap Settings sections with custom HTML content.
This changeset improves the `add_settings_section()` function to allow developers to pass extra HTML mark-up to be rendered before and after the settings section. Extra argument `$args` can now be passed to the function, and is an array that can contain the following items:
- `before_section`: HTML content to prepend to the section's HTML output. Receives the section's class name provided with the `section_class` argument via an optional `%s` placeholder. Default empty.
- `after_section`: HTML content to append to the section's HTML output. Default empty.
- `section_class`: The class name to use for the section. Used by `before_section` if a `%s` placeholder is present. Default empty.
The HTML passed using these extra arguments is escaped using `wp_kses_post()` just before rendering. This changeset also provides a set of unit tests for this new feature.
Props griffinjt, nacin, scribu, ross_ritchey, ryan, chriscct7, palmiak, rehanali, costdev, martinkrcho, chaion07, audrasjb, hellofromtonya.
Fixes #17851.
Built from https://develop.svn.wordpress.org/trunk@54247
git-svn-id: http://core.svn.wordpress.org/trunk@53806 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-20 05:59:12 -04:00
$wp_settings_sections [ $page ][ $id ] = $section ;
2015-11-20 02:24:30 -05:00
}
/**
2022-03-28 05:45:06 -04:00
* Adds a new field to a section of a settings page .
2015-11-20 02:24:30 -05:00
*
* Part of the Settings API . Use this to define a settings field that will show
* as part of a settings section inside a settings page . The fields are shown using
2021-02-25 07:02:03 -05:00
* do_settings_fields () in do_settings_sections () .
2015-11-20 02:24:30 -05:00
*
* The $callback argument should be the name of a function that echoes out the
2020-06-28 10:02:06 -04:00
* HTML input tags for this setting field . Use get_option () to retrieve existing
2015-11-20 02:24:30 -05:00
* values to show .
*
* @ since 2.7 . 0
* @ since 4.2 . 0 The `$class` argument was added .
*
2020-07-23 03:39:02 -04:00
* @ global array $wp_settings_fields Storage array of settings fields and info about their pages / sections .
2015-11-20 02:24:30 -05:00
*
2016-02-23 13:05:27 -05:00
* @ param string $id Slug - name to identify the field . Used in the 'id' attribute of tags .
* @ param string $title Formatted title of the field . Shown as the label for the field
* during output .
* @ param callable $callback Function that fills the field with the desired form inputs . The
* function should echo its output .
* @ param string $page The slug - name of the settings page on which to show the section
* ( general , reading , writing , ... ) .
* @ param string $section Optional . The slug - name of the section of the settings page
* in which to show the box . Default 'default' .
* @ param array $args {
2015-11-20 02:24:30 -05:00
* Optional . Extra arguments used when outputting the field .
*
* @ type string $label_for When supplied , the setting title will be wrapped
* in a `<label>` element , its `for` attribute populated
* with this value .
* @ type string $class CSS Class to be added to the `<tr>` element when the
* field is output .
* }
*/
2017-11-30 18:11:00 -05:00
function add_settings_field ( $id , $title , $callback , $page , $section = 'default' , $args = array () ) {
2015-11-20 02:24:30 -05:00
global $wp_settings_fields ;
2020-05-08 12:36:18 -04:00
if ( 'misc' === $page ) {
2017-11-30 18:11:00 -05:00
_deprecated_argument (
2018-08-16 21:51:36 -04:00
__FUNCTION__ ,
'3.0.0' ,
2017-11-30 18:11:00 -05:00
sprintf (
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
/* translators: %s: misc */
2017-11-30 18:11:00 -05:00
__ ( 'The "%s" options group has been removed. Use another settings group.' ),
2017-01-29 06:50:41 -05:00
'misc'
)
);
2015-11-20 02:24:30 -05:00
$page = 'general' ;
}
2020-05-08 12:36:18 -04:00
if ( 'privacy' === $page ) {
2017-11-30 18:11:00 -05:00
_deprecated_argument (
2018-08-16 21:51:36 -04:00
__FUNCTION__ ,
'3.5.0' ,
2017-11-30 18:11:00 -05:00
sprintf (
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
/* translators: %s: privacy */
2017-11-30 18:11:00 -05:00
__ ( 'The "%s" options group has been removed. Use another settings group.' ),
2017-01-29 06:50:41 -05:00
'privacy'
)
);
2015-11-20 02:24:30 -05:00
$page = 'reading' ;
}
2017-11-30 18:11:00 -05:00
$wp_settings_fields [ $page ][ $section ][ $id ] = array (
'id' => $id ,
'title' => $title ,
'callback' => $callback ,
'args' => $args ,
);
2015-11-20 02:24:30 -05:00
}
/**
2022-07-21 05:24:10 -04:00
* Prints out all settings sections added to a particular settings page .
2015-11-20 02:24:30 -05:00
*
* Part of the Settings API . Use this in a settings page callback function
* to output all the sections and fields that were added to that $page with
* add_settings_section () and add_settings_field ()
*
2020-07-23 03:39:02 -04:00
* @ global array $wp_settings_sections Storage array of all settings sections added to admin pages .
* @ global array $wp_settings_fields Storage array of settings fields and info about their pages / sections .
2015-11-20 02:24:30 -05:00
* @ since 2.7 . 0
*
2019-01-17 20:03:50 -05:00
* @ param string $page The slug name of the page whose settings sections you want to output .
2015-11-20 02:24:30 -05:00
*/
function do_settings_sections ( $page ) {
global $wp_settings_sections , $wp_settings_fields ;
2017-11-30 18:11:00 -05:00
if ( ! isset ( $wp_settings_sections [ $page ] ) ) {
2015-11-20 02:24:30 -05:00
return ;
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
foreach ( ( array ) $wp_settings_sections [ $page ] as $section ) {
Administration: Allow to wrap Settings sections with custom HTML content.
This changeset improves the `add_settings_section()` function to allow developers to pass extra HTML mark-up to be rendered before and after the settings section. Extra argument `$args` can now be passed to the function, and is an array that can contain the following items:
- `before_section`: HTML content to prepend to the section's HTML output. Receives the section's class name provided with the `section_class` argument via an optional `%s` placeholder. Default empty.
- `after_section`: HTML content to append to the section's HTML output. Default empty.
- `section_class`: The class name to use for the section. Used by `before_section` if a `%s` placeholder is present. Default empty.
The HTML passed using these extra arguments is escaped using `wp_kses_post()` just before rendering. This changeset also provides a set of unit tests for this new feature.
Props griffinjt, nacin, scribu, ross_ritchey, ryan, chriscct7, palmiak, rehanali, costdev, martinkrcho, chaion07, audrasjb, hellofromtonya.
Fixes #17851.
Built from https://develop.svn.wordpress.org/trunk@54247
git-svn-id: http://core.svn.wordpress.org/trunk@53806 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-20 05:59:12 -04:00
if ( '' !== $section [ 'before_section' ] ) {
if ( '' !== $section [ 'section_class' ] ) {
echo wp_kses_post ( sprintf ( $section [ 'before_section' ], esc_attr ( $section [ 'section_class' ] ) ) );
} else {
echo wp_kses_post ( $section [ 'before_section' ] );
}
}
2017-11-30 18:11:00 -05:00
if ( $section [ 'title' ] ) {
2015-11-20 02:24:30 -05:00
echo " <h2> { $section [ 'title' ] } </h2> \n " ;
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
if ( $section [ 'callback' ] ) {
2015-11-20 02:24:30 -05:00
call_user_func ( $section [ 'callback' ], $section );
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
if ( ! isset ( $wp_settings_fields ) || ! isset ( $wp_settings_fields [ $page ] ) || ! isset ( $wp_settings_fields [ $page ][ $section [ 'id' ] ] ) ) {
2015-11-20 02:24:30 -05:00
continue ;
2017-11-30 18:11:00 -05:00
}
2019-05-24 17:56:54 -04:00
echo '<table class="form-table" role="presentation">' ;
2015-11-20 02:24:30 -05:00
do_settings_fields ( $page , $section [ 'id' ] );
echo '</table>' ;
Administration: Allow to wrap Settings sections with custom HTML content.
This changeset improves the `add_settings_section()` function to allow developers to pass extra HTML mark-up to be rendered before and after the settings section. Extra argument `$args` can now be passed to the function, and is an array that can contain the following items:
- `before_section`: HTML content to prepend to the section's HTML output. Receives the section's class name provided with the `section_class` argument via an optional `%s` placeholder. Default empty.
- `after_section`: HTML content to append to the section's HTML output. Default empty.
- `section_class`: The class name to use for the section. Used by `before_section` if a `%s` placeholder is present. Default empty.
The HTML passed using these extra arguments is escaped using `wp_kses_post()` just before rendering. This changeset also provides a set of unit tests for this new feature.
Props griffinjt, nacin, scribu, ross_ritchey, ryan, chriscct7, palmiak, rehanali, costdev, martinkrcho, chaion07, audrasjb, hellofromtonya.
Fixes #17851.
Built from https://develop.svn.wordpress.org/trunk@54247
git-svn-id: http://core.svn.wordpress.org/trunk@53806 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-20 05:59:12 -04:00
if ( '' !== $section [ 'after_section' ] ) {
echo wp_kses_post ( $section [ 'after_section' ] );
}
2015-11-20 02:24:30 -05:00
}
}
/**
2022-03-28 05:45:06 -04:00
* Prints out the settings fields for a particular settings section .
2015-11-20 02:24:30 -05:00
*
* Part of the Settings API . Use this in a settings page to output
* a specific section . Should normally be called by do_settings_sections ()
* rather than directly .
*
2020-07-23 03:39:02 -04:00
* @ global array $wp_settings_fields Storage array of settings fields and their pages / sections .
2015-11-20 02:24:30 -05:00
*
* @ since 2.7 . 0
*
2018-10-02 12:23:25 -04:00
* @ param string $page Slug title of the admin page whose settings fields you want to show .
* @ param string $section Slug title of the settings section whose fields you want to show .
2015-11-20 02:24:30 -05:00
*/
2017-11-30 18:11:00 -05:00
function do_settings_fields ( $page , $section ) {
2015-11-20 02:24:30 -05:00
global $wp_settings_fields ;
2017-11-30 18:11:00 -05:00
if ( ! isset ( $wp_settings_fields [ $page ][ $section ] ) ) {
2015-11-20 02:24:30 -05:00
return ;
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
foreach ( ( array ) $wp_settings_fields [ $page ][ $section ] as $field ) {
2015-11-20 02:24:30 -05:00
$class = '' ;
if ( ! empty ( $field [ 'args' ][ 'class' ] ) ) {
$class = ' class="' . esc_attr ( $field [ 'args' ][ 'class' ] ) . '"' ;
}
echo " <tr { $class } > " ;
if ( ! empty ( $field [ 'args' ][ 'label_for' ] ) ) {
echo '<th scope="row"><label for="' . esc_attr ( $field [ 'args' ][ 'label_for' ] ) . '">' . $field [ 'title' ] . '</label></th>' ;
} else {
echo '<th scope="row">' . $field [ 'title' ] . '</th>' ;
}
echo '<td>' ;
2017-11-30 18:11:00 -05:00
call_user_func ( $field [ 'callback' ], $field [ 'args' ] );
2015-11-20 02:24:30 -05:00
echo '</td>' ;
echo '</tr>' ;
}
}
/**
2022-03-28 05:45:06 -04:00
* Registers a settings error to be displayed to the user .
2015-11-20 02:24:30 -05:00
*
* Part of the Settings API . Use this to show messages to users about settings validation
* problems , missing settings or anything else .
*
* Settings errors should be added inside the $sanitize_callback function defined in
* register_setting () for a given setting to give feedback about the submission .
*
* By default messages will show immediately after the submission that generated the error .
* Additional calls to settings_errors () can be used to show errors even when the settings
* page is first accessed .
*
* @ since 3.0 . 0
2019-08-15 19:01:55 -04:00
* @ since 5.3 . 0 Added `warning` and `info` as possible values for `$type` .
2015-11-20 02:24:30 -05:00
*
2022-08-11 10:03:09 -04:00
* @ global array [] $wp_settings_errors Storage array of errors registered during this pageload
2015-11-20 02:24:30 -05:00
*
2019-01-17 20:03:50 -05:00
* @ param string $setting Slug title of the setting to which this error applies .
2015-11-20 02:24:30 -05:00
* @ param string $code Slug - name to identify the error . Used as part of 'id' attribute in HTML output .
* @ param string $message The formatted message text to display to the user ( will be shown inside styled
* `<div>` and `<p>` tags ) .
2019-08-15 19:01:55 -04:00
* @ param string $type Optional . Message type , controls HTML class . Possible values include 'error' ,
* 'success' , 'warning' , 'info' . Default 'error' .
2015-11-20 02:24:30 -05:00
*/
function add_settings_error ( $setting , $code , $message , $type = 'error' ) {
global $wp_settings_errors ;
$wp_settings_errors [] = array (
'setting' => $setting ,
'code' => $code ,
'message' => $message ,
2017-11-30 18:11:00 -05:00
'type' => $type ,
2015-11-20 02:24:30 -05:00
);
}
/**
2022-03-28 05:45:06 -04:00
* Fetches settings errors registered by add_settings_error () .
2015-11-20 02:24:30 -05:00
*
* Checks the $wp_settings_errors array for any errors declared during the current
* pageload and returns them .
*
* If changes were just submitted ( $_GET [ 'settings-updated' ]) and settings errors were saved
* to the 'settings_errors' transient then those errors will be returned instead . This
* is used to pass errors back across pageloads .
*
* Use the $sanitize argument to manually re - sanitize the option before returning errors .
* This is useful if you have errors or notices you want to show even when the user
2016-05-23 13:28:27 -04:00
* hasn 't submitted data (i.e. when they first load an options page, or in the {@see ' admin_notices ' }
* action hook ) .
2015-11-20 02:24:30 -05:00
*
* @ since 3.0 . 0
*
2022-08-11 10:03:09 -04:00
* @ global array [] $wp_settings_errors Storage array of errors registered during this pageload
2015-11-20 02:24:30 -05:00
*
2020-07-22 20:52:05 -04:00
* @ param string $setting Optional . Slug title of a specific setting whose errors you want .
* @ param bool $sanitize Optional . Whether to re - sanitize the setting value before returning errors .
2020-08-08 08:39:06 -04:00
* @ return array {
* Array of settings errors .
*
* @ type string $setting Slug title of the setting to which this error applies .
* @ type string $code Slug - name to identify the error . Used as part of 'id' attribute in HTML output .
* @ type string $message The formatted message text to display to the user ( will be shown inside styled
* `<div>` and `<p>` tags ) .
* @ type string $type Optional . Message type , controls HTML class . Possible values include 'error' ,
* 'success' , 'warning' , 'info' . Default 'error' .
* }
2015-11-20 02:24:30 -05:00
*/
function get_settings_errors ( $setting = '' , $sanitize = false ) {
global $wp_settings_errors ;
/*
* If $sanitize is true , manually re - run the sanitization for this option
* This allows the $sanitize_callback from register_setting () to run , adding
* any settings errors you want to show by default .
*/
2017-11-30 18:11:00 -05:00
if ( $sanitize ) {
2015-11-20 02:24:30 -05:00
sanitize_option ( $setting , get_option ( $setting ) );
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
// If settings were passed back from options.php then use them.
if ( isset ( $_GET [ 'settings-updated' ] ) && $_GET [ 'settings-updated' ] && get_transient ( 'settings_errors' ) ) {
$wp_settings_errors = array_merge ( ( array ) $wp_settings_errors , get_transient ( 'settings_errors' ) );
delete_transient ( 'settings_errors' );
}
// Check global in case errors have been added on this pageload.
2017-11-10 17:30:56 -05:00
if ( empty ( $wp_settings_errors ) ) {
2015-11-20 02:24:30 -05:00
return array ();
2017-11-10 17:30:56 -05:00
}
2015-11-20 02:24:30 -05:00
// Filter the results to those of a specific setting if one was set.
if ( $setting ) {
$setting_errors = array ();
2020-04-09 11:43:10 -04:00
2015-11-20 02:24:30 -05:00
foreach ( ( array ) $wp_settings_errors as $key => $details ) {
2020-05-08 12:36:18 -04:00
if ( $setting === $details [ 'setting' ] ) {
2017-11-30 18:11:00 -05:00
$setting_errors [] = $wp_settings_errors [ $key ];
}
2015-11-20 02:24:30 -05:00
}
2020-04-09 11:43:10 -04:00
2015-11-20 02:24:30 -05:00
return $setting_errors ;
}
return $wp_settings_errors ;
}
/**
2022-03-28 05:45:06 -04:00
* Displays settings errors registered by add_settings_error () .
2015-11-20 02:24:30 -05:00
*
* Part of the Settings API . Outputs a div for each error retrieved by
2016-05-02 00:00:28 -04:00
* get_settings_errors () .
2015-11-20 02:24:30 -05:00
*
* This is called automatically after a settings page based on the
* Settings API is submitted . Errors should be added during the validation
2016-05-02 00:00:28 -04:00
* callback function for a setting defined in register_setting () .
2015-11-20 02:24:30 -05:00
*
2016-05-02 00:00:28 -04:00
* The $sanitize option is passed into get_settings_errors () and will
2015-11-20 02:24:30 -05:00
* re - run the setting sanitization
* on its current value .
*
* The $hide_on_update option will cause errors to only show when the settings
* page is first loaded . if the user has already saved new values it will be
* hidden to avoid repeating messages already shown in the default error
* reporting after submission . This is useful to show general errors like
* missing settings when the user arrives at the settings page .
*
* @ since 3.0 . 0
2019-08-15 19:01:55 -04:00
* @ since 5.3 . 0 Legacy `error` and `updated` CSS classes are mapped to
* `notice-error` and `notice-success` .
2015-11-20 02:24:30 -05:00
*
2018-10-02 12:23:25 -04:00
* @ param string $setting Optional slug title of a specific setting whose errors you want .
2015-11-20 02:24:30 -05:00
* @ param bool $sanitize Whether to re - sanitize the setting value before returning errors .
2016-05-02 00:00:28 -04:00
* @ param bool $hide_on_update If set to true errors will not be shown if the settings page has
* already been submitted .
2015-11-20 02:24:30 -05:00
*/
function settings_errors ( $setting = '' , $sanitize = false , $hide_on_update = false ) {
2017-11-30 18:11:00 -05:00
if ( $hide_on_update && ! empty ( $_GET [ 'settings-updated' ] ) ) {
2015-11-20 02:24:30 -05:00
return ;
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
$settings_errors = get_settings_errors ( $setting , $sanitize );
2017-11-30 18:11:00 -05:00
if ( empty ( $settings_errors ) ) {
2015-11-20 02:24:30 -05:00
return ;
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
$output = '' ;
2020-04-09 11:43:10 -04:00
2015-11-20 02:24:30 -05:00
foreach ( $settings_errors as $key => $details ) {
2019-08-15 19:01:55 -04:00
if ( 'updated' === $details [ 'type' ] ) {
$details [ 'type' ] = 'success' ;
}
2020-04-04 23:02:11 -04:00
if ( in_array ( $details [ 'type' ], array ( 'error' , 'success' , 'warning' , 'info' ), true ) ) {
2019-08-21 20:22:56 -04:00
$details [ 'type' ] = 'notice-' . $details [ 'type' ];
}
2019-08-15 19:01:55 -04:00
$css_id = sprintf (
'setting-error-%s' ,
2019-08-21 20:22:56 -04:00
esc_attr ( $details [ 'code' ] )
2019-08-15 19:01:55 -04:00
);
$css_class = sprintf (
2019-08-21 20:22:56 -04:00
'notice %s settings-error is-dismissible' ,
esc_attr ( $details [ 'type' ] )
2019-08-15 19:01:55 -04:00
);
$output .= " <div id=' $css_id ' class=' $css_class '> \n " ;
$output .= " <p><strong> { $details [ 'message' ] } </strong></p> " ;
$output .= " </div> \n " ;
2015-11-20 02:24:30 -05:00
}
2020-04-09 11:43:10 -04:00
2015-11-20 02:24:30 -05:00
echo $output ;
}
/**
* Outputs the modal window used for attaching media to posts or pages in the media - listing screen .
*
* @ since 2.7 . 0
*
* @ param string $found_action
*/
2017-11-30 18:11:00 -05:00
function find_posts_div ( $found_action = '' ) {
2018-08-16 21:51:36 -04:00
?>
2015-11-20 02:24:30 -05:00
< div id = " find-posts " class = " find-box " style = " display: none; " >
< div id = " find-posts-head " class = " find-box-head " >
2016-01-15 17:29:25 -05:00
< ? php _e ( 'Attach to existing content' ); ?>
2017-05-23 13:58:43 -04:00
< button type = " button " id = " find-posts-close " >< span class = " screen-reader-text " >< ? php _e ( 'Close media attachment panel' ); ?> </span></button>
2015-11-20 02:24:30 -05:00
</ div >
< div class = " find-box-inside " >
< div class = " find-box-search " >
< ? php if ( $found_action ) { ?>
2017-11-30 18:11:00 -05:00
< input type = " hidden " name = " found_action " value = " <?php echo esc_attr( $found_action ); ?> " />
2015-11-20 02:24:30 -05:00
< ? php } ?>
< input type = " hidden " name = " affected " id = " affected " value = " " />
< ? php wp_nonce_field ( 'find-posts' , '_ajax_nonce' , false ); ?>
< label class = " screen-reader-text " for = " find-posts-input " >< ? php _e ( 'Search' ); ?> </label>
< input type = " text " id = " find-posts-input " name = " ps " value = " " />
< span class = " spinner " ></ span >
< input type = " button " id = " find-posts-search " value = " <?php esc_attr_e( 'Search' ); ?> " class = " button " />
< div class = " clear " ></ div >
</ div >
< div id = " find-posts-response " ></ div >
</ div >
< div class = " find-box-buttons " >
2016-09-28 15:54:28 -04:00
< ? php submit_button ( __ ( 'Select' ), 'primary alignright' , 'find-posts-submit' , false ); ?>
2015-11-20 02:24:30 -05:00
< div class = " clear " ></ div >
</ div >
</ div >
2018-08-16 21:51:36 -04:00
< ? php
2015-11-20 02:24:30 -05:00
}
/**
2016-05-22 13:22:27 -04:00
* Displays the post password .
2015-11-20 02:24:30 -05:00
*
2020-06-28 10:02:06 -04:00
* The password is passed through esc_attr () to ensure that it is safe for placing in an HTML attribute .
2015-11-20 02:24:30 -05:00
*
* @ since 2.7 . 0
*/
function the_post_password () {
$post = get_post ();
2017-11-30 18:11:00 -05:00
if ( isset ( $post -> post_password ) ) {
2015-11-20 02:24:30 -05:00
echo esc_attr ( $post -> post_password );
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
}
/**
2022-03-28 05:45:06 -04:00
* Gets the post title .
2015-11-20 02:24:30 -05:00
*
* The post title is fetched and if it is blank then a default string is
* returned .
*
* @ since 2.7 . 0
*
* @ param int | WP_Post $post Optional . Post ID or WP_Post object . Default is global $post .
* @ return string The post title if set .
*/
function _draft_or_post_title ( $post = 0 ) {
$title = get_the_title ( $post );
2017-11-30 18:11:00 -05:00
if ( empty ( $title ) ) {
2015-11-20 02:24:30 -05:00
$title = __ ( '(no title)' );
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
return esc_html ( $title );
}
/**
2016-05-22 13:22:27 -04:00
* Displays the search query .
2015-11-20 02:24:30 -05:00
*
2016-05-22 13:22:27 -04:00
* A simple wrapper to display the " s " parameter in a `GET` URI . This function
* should only be used when the_search_query () cannot .
2015-11-20 02:24:30 -05:00
*
* @ since 2.7 . 0
*/
function _admin_search_query () {
2017-11-30 18:11:00 -05:00
echo isset ( $_REQUEST [ 's' ] ) ? esc_attr ( wp_unslash ( $_REQUEST [ 's' ] ) ) : '' ;
2015-11-20 02:24:30 -05:00
}
/**
2022-03-28 05:45:06 -04:00
* Generic Iframe header for use with Thickbox .
2015-11-20 02:24:30 -05:00
*
* @ since 2.7 . 0
*
* @ global string $hook_suffix
* @ global string $admin_body_class
2019-08-03 21:46:55 -04:00
* @ global WP_Locale $wp_locale WordPress date and time locale object .
2015-11-20 02:24:30 -05:00
*
* @ param string $title Optional . Title of the Iframe page . Default empty .
* @ param bool $deprecated Not used .
*/
function iframe_header ( $title = '' , $deprecated = false ) {
show_admin_bar ( false );
global $hook_suffix , $admin_body_class , $wp_locale ;
2017-11-30 18:11:00 -05:00
$admin_body_class = preg_replace ( '/[^a-z0-9_-]+/i' , '-' , $hook_suffix );
2015-11-20 02:24:30 -05:00
$current_screen = get_current_screen ();
2019-07-09 01:45:58 -04:00
header ( 'Content-Type: ' . get_option ( 'html_type' ) . '; charset=' . get_option ( 'blog_charset' ) );
2015-11-20 02:24:30 -05:00
_wp_admin_html_begin ();
2018-08-16 21:51:36 -04:00
?>
2017-11-30 18:11:00 -05:00
< title >< ? php bloginfo ( 'name' ); ?> › <?php echo $title; ?> — <?php _e( 'WordPress' ); ?></title>
2018-08-16 21:51:36 -04:00
< ? php
wp_enqueue_style ( 'colors' );
?>
2015-11-20 02:24:30 -05:00
< script type = " text/javascript " >
External Libraries: Further fix jQuery deprecations in WordPress core.
Follow-up to [50001], [50270], [50367], [50383], [50410], [50420], [50429], [50547].
Props chaion07, Clorith, costdev, desrosj, malthert, peterwilsoncc, presskopp, promz, sabernhardt, SergeyBiryukov, toro_unit, wpnomad.
Fixes #51519.
Built from https://develop.svn.wordpress.org/trunk@52285
git-svn-id: http://core.svn.wordpress.org/trunk@51877 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-30 12:18:01 -05:00
addLoadEvent = function ( func ){ if ( typeof jQuery !== 'undefined' ) jQuery ( function (){ func ();}); else if ( typeof wpOnload !== 'function' ){ wpOnload = func ;} else { var oldonload = wpOnload ; wpOnload = function (){ oldonload (); func ();}}};
2015-11-20 02:24:30 -05:00
function tb_close (){ var win = window . dialogArguments || opener || parent || top ; win . tb_remove ();}
2020-10-29 14:03:11 -04:00
var ajaxurl = '<?php echo esc_js( admin_url( ' admin - ajax . php ', ' relative ' ) ); ?>' ,
pagenow = '<?php echo esc_js( $current_screen->id ); ?>' ,
typenow = '<?php echo esc_js( $current_screen->post_type ); ?>' ,
adminpage = '<?php echo esc_js( $admin_body_class ); ?>' ,
thousandsSeparator = '<?php echo esc_js( $wp_locale->number_format[' thousands_sep '] ); ?>' ,
decimalPoint = '<?php echo esc_js( $wp_locale->number_format[' decimal_point '] ); ?>' ,
2015-11-20 02:24:30 -05:00
isRtl = < ? php echo ( int ) is_rtl (); ?> ;
</ script >
2018-08-16 21:51:36 -04:00
< ? php
/** This action is documented in wp-admin/admin-header.php */
do_action ( 'admin_enqueue_scripts' , $hook_suffix );
2015-11-20 02:24:30 -05:00
2018-08-16 21:51:36 -04:00
/** This action is documented in wp-admin/admin-header.php */
2019-08-22 15:08:55 -04:00
do_action ( " admin_print_styles- { $hook_suffix } " ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
2015-11-20 02:24:30 -05:00
2018-08-16 21:51:36 -04:00
/** This action is documented in wp-admin/admin-header.php */
do_action ( 'admin_print_styles' );
2015-11-20 02:24:30 -05:00
2018-08-16 21:51:36 -04:00
/** This action is documented in wp-admin/admin-header.php */
2019-08-22 15:08:55 -04:00
do_action ( " admin_print_scripts- { $hook_suffix } " ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
2015-11-20 02:24:30 -05:00
2018-08-16 21:51:36 -04:00
/** This action is documented in wp-admin/admin-header.php */
do_action ( 'admin_print_scripts' );
2015-11-20 02:24:30 -05:00
2018-08-16 21:51:36 -04:00
/** This action is documented in wp-admin/admin-header.php */
2019-08-22 15:08:55 -04:00
do_action ( " admin_head- { $hook_suffix } " ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
2015-11-20 02:24:30 -05:00
2018-08-16 21:51:36 -04:00
/** This action is documented in wp-admin/admin-header.php */
do_action ( 'admin_head' );
2015-11-20 02:24:30 -05:00
2018-08-16 21:51:36 -04:00
$admin_body_class .= ' locale-' . sanitize_html_class ( strtolower ( str_replace ( '_' , '-' , get_user_locale () ) ) );
2015-11-20 02:24:30 -05:00
2018-08-16 21:51:36 -04:00
if ( is_rtl () ) {
$admin_body_class .= ' rtl' ;
}
2015-11-20 02:24:30 -05:00
2018-08-16 21:51:36 -04:00
?>
2015-11-20 02:24:30 -05:00
</ head >
2018-08-16 21:51:36 -04:00
< ? php
/**
* @ global string $body_id
*/
2019-07-05 01:21:56 -04:00
$admin_body_id = isset ( $GLOBALS [ 'body_id' ] ) ? 'id="' . $GLOBALS [ 'body_id' ] . '" ' : '' ;
/** This filter is documented in wp-admin/admin-header.php */
$admin_body_classes = apply_filters ( 'admin_body_class' , '' );
$admin_body_classes = ltrim ( $admin_body_classes . ' ' . $admin_body_class );
2018-08-16 21:51:36 -04:00
?>
2019-07-05 01:21:56 -04:00
< body < ? php echo $admin_body_id ; ?> class="wp-admin wp-core-ui no-js iframe <?php echo $admin_body_classes; ?>">
2015-11-20 02:24:30 -05:00
< script type = " text/javascript " >
( function (){
var c = document . body . className ;
c = c . replace ( / no - js / , 'js' );
document . body . className = c ;
})();
</ script >
2018-08-16 21:51:36 -04:00
< ? php
2015-11-20 02:24:30 -05:00
}
/**
2022-03-28 05:45:06 -04:00
* Generic Iframe footer for use with Thickbox .
2015-11-20 02:24:30 -05:00
*
* @ since 2.7 . 0
*/
function iframe_footer () {
/*
* We ' re going to hide any footer output on iFrame pages ,
* but run the hooks anyway since they output JavaScript
* or other needed content .
*/
2016-04-21 11:17:27 -04:00
/**
* @ global string $hook_suffix
*/
global $hook_suffix ;
?>
2015-11-20 02:24:30 -05:00
< div class = " hidden " >
2018-08-16 21:51:36 -04:00
< ? php
2015-11-20 02:24:30 -05:00
/** This action is documented in wp-admin/admin-footer.php */
2016-04-21 11:17:27 -04:00
do_action ( 'admin_footer' , $hook_suffix );
/** This action is documented in wp-admin/admin-footer.php */
2019-08-22 15:08:55 -04:00
do_action ( " admin_print_footer_scripts- { $hook_suffix } " ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
2015-11-20 02:24:30 -05:00
/** This action is documented in wp-admin/admin-footer.php */
do_action ( 'admin_print_footer_scripts' );
2018-08-16 21:51:36 -04:00
?>
2015-11-20 02:24:30 -05:00
</ div >
2021-03-18 10:13:08 -04:00
< script type = " text/javascript " > if ( typeof wpOnload === 'function' ) wpOnload (); </ script >
2015-11-20 02:24:30 -05:00
</ body >
</ html >
2018-08-16 21:51:36 -04:00
< ? php
2015-11-20 02:24:30 -05:00
}
/**
2022-03-28 05:45:06 -04:00
* Echoes or returns the post states as HTML .
2019-09-25 17:51:58 -04:00
*
* @ since 2.7 . 0
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
* @ since 5.3 . 0 Added the `$display` parameter and a return value .
2019-09-25 17:51:58 -04:00
*
2019-09-25 20:57:58 -04:00
* @ see get_post_states ()
2019-09-25 17:51:58 -04:00
*
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
* @ param WP_Post $post The post to retrieve states for .
* @ param bool $display Optional . Whether to display the post states as an HTML string .
* Default true .
2019-09-25 20:57:58 -04:00
* @ return string Post states string .
2019-09-25 17:51:58 -04:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
function _post_states ( $post , $display = true ) {
2019-09-25 17:51:58 -04:00
$post_states = get_post_states ( $post );
$post_states_string = '' ;
if ( ! empty ( $post_states ) ) {
$state_count = count ( $post_states );
2021-09-26 20:37:01 -04:00
$i = 0 ;
2019-09-25 17:51:58 -04:00
$post_states_string .= ' — ' ;
2020-04-09 11:43:10 -04:00
2019-09-25 17:51:58 -04:00
foreach ( $post_states as $state ) {
2021-09-26 20:37:01 -04:00
++ $i ;
Coding Standards: Use more meaningful variable names for output in the admin.
This renames some variables for clarity, per the [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions Naming Conventions]:
> Don’t abbreviate variable names unnecessarily; let the code be unambiguous and self-documenting.
* `$out` is renamed to `$output` in various list table methods and admin functions.
* `$sep` is renamed to `$separator` in various list table methods and admin functions.
This affects:
* `WP_Comments_List_Table::handle_row_actions()`
* `WP_List_Table::row_actions()`
* `WP_Media_List_Table::column_default()`
* `WP_MS_Sites_List_Table::site_states()`
* `WP_MS_Users_List_Table::column_blogs()`
* `WP_Terms_List_Table::column_name()`
* `_wp_dashboard_recent_comments_row()`
* `image_align_input_fields()`
* `image_size_input_fields()`
* `wp_doc_link_parse()`
* `_post_states()`
* `_media_states()`
Follow-up to [8653], [8692], [8864], [8910], [8911], [8916], [9103], [9153], [10607], [15491], [17793], [32644], [54070].
Props mukesh27, costdev.
See #56448, #55647.
Built from https://develop.svn.wordpress.org/trunk@54071
git-svn-id: http://core.svn.wordpress.org/trunk@53630 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-05 13:19:09 -04:00
$separator = ( $i < $state_count ) ? ', ' : '' ;
2020-05-08 12:36:18 -04:00
Coding Standards: Use more meaningful variable names for output in the admin.
This renames some variables for clarity, per the [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions Naming Conventions]:
> Don’t abbreviate variable names unnecessarily; let the code be unambiguous and self-documenting.
* `$out` is renamed to `$output` in various list table methods and admin functions.
* `$sep` is renamed to `$separator` in various list table methods and admin functions.
This affects:
* `WP_Comments_List_Table::handle_row_actions()`
* `WP_List_Table::row_actions()`
* `WP_Media_List_Table::column_default()`
* `WP_MS_Sites_List_Table::site_states()`
* `WP_MS_Users_List_Table::column_blogs()`
* `WP_Terms_List_Table::column_name()`
* `_wp_dashboard_recent_comments_row()`
* `image_align_input_fields()`
* `image_size_input_fields()`
* `wp_doc_link_parse()`
* `_post_states()`
* `_media_states()`
Follow-up to [8653], [8692], [8864], [8910], [8911], [8916], [9103], [9153], [10607], [15491], [17793], [32644], [54070].
Props mukesh27, costdev.
See #56448, #55647.
Built from https://develop.svn.wordpress.org/trunk@54071
git-svn-id: http://core.svn.wordpress.org/trunk@53630 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-05 13:19:09 -04:00
$post_states_string .= " <span class='post-state'> { $state } { $separator } </span> " ;
2019-09-25 17:51:58 -04:00
}
}
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
if ( $display ) {
2019-09-25 17:51:58 -04:00
echo $post_states_string ;
}
return $post_states_string ;
}
2020-07-26 06:51:06 -04:00
/**
* Retrieves an array of post states from a post .
*
* @ since 5.3 . 0
*
* @ param WP_Post $post The post to retrieve states for .
* @ return string [] Array of post state labels keyed by their state .
*/
function get_post_states ( $post ) {
$post_states = array ();
if ( isset ( $_REQUEST [ 'post_status' ] ) ) {
$post_status = $_REQUEST [ 'post_status' ];
} else {
$post_status = '' ;
}
if ( ! empty ( $post -> post_password ) ) {
$post_states [ 'protected' ] = _x ( 'Password protected' , 'post status' );
}
if ( 'private' === $post -> post_status && 'private' !== $post_status ) {
$post_states [ 'private' ] = _x ( 'Private' , 'post status' );
}
if ( 'draft' === $post -> post_status ) {
if ( get_post_meta ( $post -> ID , '_customize_changeset_uuid' , true ) ) {
$post_states [] = __ ( 'Customization Draft' );
} elseif ( 'draft' !== $post_status ) {
$post_states [ 'draft' ] = _x ( 'Draft' , 'post status' );
}
} elseif ( 'trash' === $post -> post_status && get_post_meta ( $post -> ID , '_customize_changeset_uuid' , true ) ) {
$post_states [] = _x ( 'Customization Draft' , 'post status' );
}
if ( 'pending' === $post -> post_status && 'pending' !== $post_status ) {
$post_states [ 'pending' ] = _x ( 'Pending' , 'post status' );
}
if ( is_sticky ( $post -> ID ) ) {
$post_states [ 'sticky' ] = _x ( 'Sticky' , 'post status' );
}
if ( 'future' === $post -> post_status ) {
$post_states [ 'scheduled' ] = _x ( 'Scheduled' , 'post status' );
}
if ( 'page' === get_option ( 'show_on_front' ) ) {
2020-10-08 17:15:13 -04:00
if ( ( int ) get_option ( 'page_on_front' ) === $post -> ID ) {
2020-07-26 06:51:06 -04:00
$post_states [ 'page_on_front' ] = _x ( 'Front Page' , 'page label' );
}
2020-10-08 17:15:13 -04:00
if ( ( int ) get_option ( 'page_for_posts' ) === $post -> ID ) {
2020-07-26 06:51:06 -04:00
$post_states [ 'page_for_posts' ] = _x ( 'Posts Page' , 'page label' );
}
}
2020-10-08 17:15:13 -04:00
if ( ( int ) get_option ( 'wp_page_for_privacy_policy' ) === $post -> ID ) {
2020-07-26 06:51:06 -04:00
$post_states [ 'page_for_privacy_policy' ] = _x ( 'Privacy Policy Page' , 'page label' );
}
/**
* Filters the default post display states used in the posts list table .
*
* @ since 2.8 . 0
* @ since 3.6 . 0 Added the `$post` parameter .
2020-08-31 09:32:04 -04:00
* @ since 5.5 . 0 Also applied in the Customizer context . If any admin functions
* are used within the filter , their existence should be checked
* with `function_exists()` before being used .
2020-07-26 06:51:06 -04:00
*
* @ param string [] $post_states An array of post display states .
* @ param WP_Post $post The current post object .
*/
return apply_filters ( 'display_post_states' , $post_states , $post );
}
2015-11-20 02:24:30 -05:00
/**
2020-07-22 20:48:06 -04:00
* Outputs the attachment media states as HTML .
2019-09-25 20:57:58 -04:00
*
* @ since 3.2 . 0
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
* @ since 5.6 . 0 Added the `$display` parameter and a return value .
2019-09-25 20:57:58 -04:00
*
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
* @ param WP_Post $post The attachment post to retrieve states for .
* @ param bool $display Optional . Whether to display the post states as an HTML string .
* Default true .
2020-10-19 23:14:06 -04:00
* @ return string Media states string .
2015-11-20 02:24:30 -05:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
function _media_states ( $post , $display = true ) {
2020-10-20 09:29:08 -04:00
$media_states = get_media_states ( $post );
2020-10-19 23:14:06 -04:00
$media_states_string = '' ;
if ( ! empty ( $media_states ) ) {
$state_count = count ( $media_states );
2021-09-26 20:37:01 -04:00
$i = 0 ;
2020-10-19 23:14:06 -04:00
$media_states_string .= ' — ' ;
foreach ( $media_states as $state ) {
2021-09-26 20:37:01 -04:00
++ $i ;
Coding Standards: Use more meaningful variable names for output in the admin.
This renames some variables for clarity, per the [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions Naming Conventions]:
> Don’t abbreviate variable names unnecessarily; let the code be unambiguous and self-documenting.
* `$out` is renamed to `$output` in various list table methods and admin functions.
* `$sep` is renamed to `$separator` in various list table methods and admin functions.
This affects:
* `WP_Comments_List_Table::handle_row_actions()`
* `WP_List_Table::row_actions()`
* `WP_Media_List_Table::column_default()`
* `WP_MS_Sites_List_Table::site_states()`
* `WP_MS_Users_List_Table::column_blogs()`
* `WP_Terms_List_Table::column_name()`
* `_wp_dashboard_recent_comments_row()`
* `image_align_input_fields()`
* `image_size_input_fields()`
* `wp_doc_link_parse()`
* `_post_states()`
* `_media_states()`
Follow-up to [8653], [8692], [8864], [8910], [8911], [8916], [9103], [9153], [10607], [15491], [17793], [32644], [54070].
Props mukesh27, costdev.
See #56448, #55647.
Built from https://develop.svn.wordpress.org/trunk@54071
git-svn-id: http://core.svn.wordpress.org/trunk@53630 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-05 13:19:09 -04:00
$separator = ( $i < $state_count ) ? ', ' : '' ;
2020-10-19 23:14:06 -04:00
Coding Standards: Use more meaningful variable names for output in the admin.
This renames some variables for clarity, per the [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions Naming Conventions]:
> Don’t abbreviate variable names unnecessarily; let the code be unambiguous and self-documenting.
* `$out` is renamed to `$output` in various list table methods and admin functions.
* `$sep` is renamed to `$separator` in various list table methods and admin functions.
This affects:
* `WP_Comments_List_Table::handle_row_actions()`
* `WP_List_Table::row_actions()`
* `WP_Media_List_Table::column_default()`
* `WP_MS_Sites_List_Table::site_states()`
* `WP_MS_Users_List_Table::column_blogs()`
* `WP_Terms_List_Table::column_name()`
* `_wp_dashboard_recent_comments_row()`
* `image_align_input_fields()`
* `image_size_input_fields()`
* `wp_doc_link_parse()`
* `_post_states()`
* `_media_states()`
Follow-up to [8653], [8692], [8864], [8910], [8911], [8916], [9103], [9153], [10607], [15491], [17793], [32644], [54070].
Props mukesh27, costdev.
See #56448, #55647.
Built from https://develop.svn.wordpress.org/trunk@54071
git-svn-id: http://core.svn.wordpress.org/trunk@53630 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-05 13:19:09 -04:00
$media_states_string .= " <span class='post-state'> { $state } { $separator } </span> " ;
2020-10-19 23:14:06 -04:00
}
}
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$echo` parameter to `$display` in:
* `wp_popular_terms_checklist()`
* `_post_states()`
* `_media_states()`
* Renames the `$default` parameter to `$default_term` in `wp_popular_terms_checklist()`.
* Renames the `$default` parameter to `$default_template` in `page_template_dropdown()`.
* Renames the `$default` parameter to `$default_page` in `parent_dropdown()`.
* Renames the `$object` parameter to `$data_object` in:
* `do_block_editor_incompatible_meta_box()`
* `do_meta_boxes()`
* `do_accordion_sections()`
* Amends the `$item_object` parameter in other functions for consistency:
* `wp_nav_menu_item_post_type_meta_box()`
* `wp_nav_menu_item_taxonomy_meta_box()`
* `_wp_nav_menu_meta_box_object()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53220
git-svn-id: http://core.svn.wordpress.org/trunk@52809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-19 11:13:08 -04:00
if ( $display ) {
2020-10-19 23:14:06 -04:00
echo $media_states_string ;
}
return $media_states_string ;
}
/**
* Retrieves an array of media states from an attachment .
*
* @ since 5.6 . 0
*
* @ param WP_Post $post The attachment to retrieve states for .
* @ return string [] Array of media state labels keyed by their state .
*/
function get_media_states ( $post ) {
2020-06-23 19:34:06 -04:00
static $header_images ;
2015-11-20 02:24:30 -05:00
$media_states = array ();
2017-11-30 18:11:00 -05:00
$stylesheet = get_option ( 'stylesheet' );
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
if ( current_theme_supports ( 'custom-header' ) ) {
$meta_header = get_post_meta ( $post -> ID , '_wp_attachment_is_custom_header' , true );
2016-10-19 19:03:31 -04:00
if ( is_random_header_image () ) {
2020-06-23 19:34:06 -04:00
if ( ! isset ( $header_images ) ) {
$header_images = wp_list_pluck ( get_uploaded_header_images (), 'attachment_id' );
}
2016-10-19 19:03:31 -04:00
2020-05-08 12:36:18 -04:00
if ( $meta_header === $stylesheet && in_array ( $post -> ID , $header_images , true ) ) {
2016-10-19 19:03:31 -04:00
$media_states [] = __ ( 'Header Image' );
}
} else {
$header_image = get_header_image ();
2020-01-28 19:45:18 -05:00
// Display "Header Image" if the image was ever used as a header image.
2020-02-09 11:55:09 -05:00
if ( ! empty ( $meta_header ) && $meta_header === $stylesheet && wp_get_attachment_url ( $post -> ID ) !== $header_image ) {
2016-10-19 19:03:31 -04:00
$media_states [] = __ ( 'Header Image' );
}
2020-01-28 19:45:18 -05:00
// Display "Current Header Image" if the image is currently the header image.
2020-02-09 11:55:09 -05:00
if ( $header_image && wp_get_attachment_url ( $post -> ID ) === $header_image ) {
2016-10-19 19:03:31 -04:00
$media_states [] = __ ( 'Current Header Image' );
}
}
2020-10-19 14:32:07 -04:00
if ( get_theme_support ( 'custom-header' , 'video' ) && has_header_video () ) {
$mods = get_theme_mods ();
if ( isset ( $mods [ 'header_video' ] ) && $post -> ID === $mods [ 'header_video' ] ) {
$media_states [] = __ ( 'Current Header Video' );
}
}
2015-11-20 02:24:30 -05:00
}
2017-11-30 18:11:00 -05:00
if ( current_theme_supports ( 'custom-background' ) ) {
$meta_background = get_post_meta ( $post -> ID , '_wp_attachment_is_custom_background' , true );
2016-10-19 19:03:31 -04:00
2020-02-09 11:55:09 -05:00
if ( ! empty ( $meta_background ) && $meta_background === $stylesheet ) {
2015-11-20 02:24:30 -05:00
$media_states [] = __ ( 'Background Image' );
2016-10-19 19:03:31 -04:00
$background_image = get_background_image ();
2020-02-09 11:55:09 -05:00
if ( $background_image && wp_get_attachment_url ( $post -> ID ) === $background_image ) {
2016-10-19 19:03:31 -04:00
$media_states [] = __ ( 'Current Background Image' );
}
}
2015-11-20 02:24:30 -05:00
}
2020-05-08 12:36:18 -04:00
if ( ( int ) get_option ( 'site_icon' ) === $post -> ID ) {
2015-11-20 02:24:30 -05:00
$media_states [] = __ ( 'Site Icon' );
}
2020-05-08 12:36:18 -04:00
if ( ( int ) get_theme_mod ( 'custom_logo' ) === $post -> ID ) {
Customize: Introduce Logo support for themes.
Allows a common theme feature to have a common implementation provided by core and available in a consistent location for users.
See https://make.wordpress.org/core/2016/02/24/theme-logo-support/
Props kwight, enejb, jeherve, bhubbard, samhotchkiss, zinigor, eliorivero, adamsilverstein, melchoyce, ryan, mikeschroder, westonruter, pento, karmatosed, celloexpressions, obenland.
See #33755.
Built from https://develop.svn.wordpress.org/trunk@36698
git-svn-id: http://core.svn.wordpress.org/trunk@36665 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-24 17:10:26 -05:00
$media_states [] = __ ( 'Logo' );
}
2015-11-20 02:24:30 -05:00
/**
2016-05-22 14:01:30 -04:00
* Filters the default media display states for items in the Media list table .
2015-11-20 02:24:30 -05:00
*
* @ since 3.2 . 0
2017-01-20 00:20:41 -05:00
* @ since 4.8 . 0 Added the `$post` parameter .
2015-11-20 02:24:30 -05:00
*
2018-03-25 14:10:32 -04:00
* @ param string [] $media_states An array of media states . Default 'Header Image' ,
* 'Background Image' , 'Site Icon' , 'Logo' .
* @ param WP_Post $post The current attachment object .
2015-11-20 02:24:30 -05:00
*/
2021-04-28 14:55:05 -04:00
return apply_filters ( 'display_media_states' , $media_states , $post );
2015-11-20 02:24:30 -05:00
}
/**
2022-03-28 05:45:06 -04:00
* Tests support for compressing JavaScript from PHP .
2015-11-20 02:24:30 -05:00
*
* Outputs JavaScript that tests if compression from PHP works as expected
* and sets an option with the result . Has no effect when the current user
* is not an administrator . To run the test again the option 'can_compress_scripts'
* has to be deleted .
*
* @ since 2.8 . 0
*/
function compression_test () {
2018-08-16 21:51:36 -04:00
?>
2015-11-20 02:24:30 -05:00
< script type = " text/javascript " >
2016-03-30 14:21:25 -04:00
var compressionNonce = < ? php echo wp_json_encode ( wp_create_nonce ( 'update_can_compress_scripts' ) ); ?> ;
2015-11-20 02:24:30 -05:00
var testCompression = {
get : function ( test ) {
var x ;
if ( window . XMLHttpRequest ) {
x = new XMLHttpRequest ();
} else {
try { x = new ActiveXObject ( 'Msxml2.XMLHTTP' );} catch ( e ){ try { x = new ActiveXObject ( 'Microsoft.XMLHTTP' );} catch ( e ){};}
}
if ( x ) {
x . onreadystatechange = function () {
var r , h ;
if ( x . readyState == 4 ) {
r = x . responseText . substr ( 0 , 18 );
h = x . getResponseHeader ( 'Content-Encoding' );
testCompression . check ( r , h , test );
}
};
2016-03-30 14:21:25 -04:00
x . open ( 'GET' , ajaxurl + '?action=wp-compression-test&test=' + test + '&_ajax_nonce=' + compressionNonce + '&' + ( new Date ()) . getTime (), true );
2015-11-20 02:24:30 -05:00
x . send ( '' );
}
},
check : function ( r , h , test ) {
if ( ! r && ! test )
this . get ( 1 );
if ( 1 == test ) {
if ( h && ( h . match ( / deflate / i ) || h . match ( / gzip / i ) ) )
this . get ( 'no' );
else
this . get ( 2 );
return ;
}
if ( 2 == test ) {
2020-05-16 14:42:12 -04:00
if ( '"wpCompressionTest' === r )
2015-11-20 02:24:30 -05:00
this . get ( 'yes' );
else
this . get ( 'no' );
}
}
};
testCompression . check ();
</ script >
2018-08-16 21:51:36 -04:00
< ? php
2015-11-20 02:24:30 -05:00
}
/**
* Echoes a submit button , with provided text and appropriate class ( es ) .
*
* @ since 3.1 . 0
*
* @ see get_submit_button ()
*
* @ param string $text The text of the button ( defaults to 'Save Changes' )
* @ param string $type Optional . The type and CSS class ( es ) of the button . Core values
2017-01-20 15:37:42 -05:00
* include 'primary' , 'small' , and 'large' . Default 'primary' .
2015-11-20 02:24:30 -05:00
* @ param string $name The HTML name of the submit button . Defaults to " submit " . If no
* id attribute is given in $other_attributes below , $name will be
* used as the button ' s id .
* @ param bool $wrap True if the output button should be wrapped in a paragraph tag ,
2019-01-17 20:03:50 -05:00
* false otherwise . Defaults to true .
2015-11-20 02:24:30 -05:00
* @ param array | string $other_attributes Other attributes that should be output with the button , mapping
* attributes to their values , such as setting tabindex to 1 , etc .
* These key / value attribute pairs will be output as attribute = " value " ,
* where attribute is the key . Other attributes can also be provided
* as a string such as 'tabindex="1"' , though the array format is
* preferred . Default null .
*/
function submit_button ( $text = null , $type = 'primary' , $name = 'submit' , $wrap = true , $other_attributes = null ) {
echo get_submit_button ( $text , $type , $name , $wrap , $other_attributes );
}
/**
2022-03-28 05:45:06 -04:00
* Returns a submit button , with provided text and appropriate class .
2015-11-20 02:24:30 -05:00
*
* @ since 3.1 . 0
*
* @ param string $text Optional . The text of the button . Default 'Save Changes' .
2017-01-20 15:37:42 -05:00
* @ param string $type Optional . The type and CSS class ( es ) of the button . Core values
* include 'primary' , 'small' , and 'large' . Default 'primary large' .
2015-11-20 02:24:30 -05:00
* @ param string $name Optional . The HTML name of the submit button . Defaults to " submit " .
* If no id attribute is given in $other_attributes below , `$name` will
* be used as the button 's id. Default ' submit ' .
* @ param bool $wrap Optional . True if the output button should be wrapped in a paragraph
* tag , false otherwise . Default true .
* @ param array | string $other_attributes Optional . Other attributes that should be output with the button ,
* mapping attributes to their values , such as `array( 'tabindex' => '1' )` .
* These attributes will be output as `attribute="value"` , such as
* `tabindex="1"` . Other attributes can also be provided as a string such
* as `tabindex="1"` , though the array format is typically cleaner .
* Default empty .
* @ return string Submit button HTML .
*/
function get_submit_button ( $text = '' , $type = 'primary large' , $name = 'submit' , $wrap = true , $other_attributes = '' ) {
2017-11-30 18:11:00 -05:00
if ( ! is_array ( $type ) ) {
2015-11-20 02:24:30 -05:00
$type = explode ( ' ' , $type );
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
$button_shorthand = array ( 'primary' , 'small' , 'large' );
2017-11-30 18:11:00 -05:00
$classes = array ( 'button' );
2020-04-09 11:43:10 -04:00
2015-11-20 02:24:30 -05:00
foreach ( $type as $t ) {
2017-11-30 18:11:00 -05:00
if ( 'secondary' === $t || 'button-secondary' === $t ) {
2015-11-20 02:24:30 -05:00
continue ;
2017-11-30 18:11:00 -05:00
}
2020-04-09 11:43:10 -04:00
2020-04-04 23:02:11 -04:00
$classes [] = in_array ( $t , $button_shorthand , true ) ? 'button-' . $t : $t ;
2015-11-20 02:24:30 -05:00
}
2020-04-09 11:43:10 -04:00
2016-09-28 15:54:28 -04:00
// Remove empty items, remove duplicate items, and finally build a string.
$class = implode ( ' ' , array_unique ( array_filter ( $classes ) ) );
2015-11-20 02:24:30 -05:00
$text = $text ? $text : __ ( 'Save Changes' );
2020-01-28 19:45:18 -05:00
// Default the id attribute to $name unless an id was specifically provided in $other_attributes.
2015-11-20 02:24:30 -05:00
$id = $name ;
if ( is_array ( $other_attributes ) && isset ( $other_attributes [ 'id' ] ) ) {
$id = $other_attributes [ 'id' ];
unset ( $other_attributes [ 'id' ] );
}
$attributes = '' ;
if ( is_array ( $other_attributes ) ) {
foreach ( $other_attributes as $attribute => $value ) {
2020-01-28 19:45:18 -05:00
$attributes .= $attribute . '="' . esc_attr ( $value ) . '" ' ; // Trailing space is important.
2015-11-20 02:24:30 -05:00
}
2020-01-28 19:45:18 -05:00
} elseif ( ! empty ( $other_attributes ) ) { // Attributes provided as a string.
2015-11-20 02:24:30 -05:00
$attributes = $other_attributes ;
}
// Don't output empty name and id attributes.
$name_attr = $name ? ' name="' . esc_attr ( $name ) . '"' : '' ;
2017-11-30 18:11:00 -05:00
$id_attr = $id ? ' id="' . esc_attr ( $id ) . '"' : '' ;
2015-11-20 02:24:30 -05:00
2017-11-30 18:11:00 -05:00
$button = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr ( $class );
$button .= '" value="' . esc_attr ( $text ) . '" ' . $attributes . ' />' ;
2015-11-20 02:24:30 -05:00
if ( $wrap ) {
$button = '<p class="submit">' . $button . '</p>' ;
}
return $button ;
}
2016-08-31 11:22:31 -04:00
/**
2022-07-21 05:24:10 -04:00
* Prints out the beginning of the admin HTML header .
*
2016-08-31 11:22:31 -04:00
* @ global bool $is_IE
*/
2015-11-20 02:24:30 -05:00
function _wp_admin_html_begin () {
2016-08-31 11:22:31 -04:00
global $is_IE ;
2015-11-20 02:24:30 -05:00
$admin_html_class = ( is_admin_bar_showing () ) ? 'wp-toolbar' : '' ;
2017-11-30 18:11:00 -05:00
if ( $is_IE ) {
2019-07-09 01:45:58 -04:00
header ( 'X-UA-Compatible: IE=edge' );
2017-11-30 18:11:00 -05:00
}
2015-11-20 02:24:30 -05:00
2018-08-16 21:51:36 -04:00
?>
2015-11-20 02:24:30 -05:00
<! DOCTYPE html >
2020-06-22 17:26:16 -04:00
< html class = " <?php echo $admin_html_class ; ?> "
2018-08-15 02:22:26 -04:00
< ? php
2020-07-07 10:57:02 -04:00
/**
* Fires inside the HTML tag in the admin header .
*
* @ since 2.2 . 0
*/
2018-08-15 02:22:26 -04:00
do_action ( 'admin_xml_ns' );
language_attributes ();
?>
Administration: Remove any CSS related to Internet Explorer versions 6 – 10.
In WordPress 3.2 support for IE6 was dropped, IE7 followed a few versions later. With the 4.8 release, WordPress officially ended support for Internet Explorer versions 8, 9, and 10. Yet, we still have shipped CSS for the unsupported IE versions....until now! Goodbye to ie.css and star hacks!
* Removes ie.css and `ie` style handle.
* Removes IE specific class names and any related CSS.
* Drops support for IE8 and older in `wp_customize_support_script()`.
* Updates compatibility mode for CSS minification to `ie11`.
Props ayeshrajans, isabel_brison, afercia, netweb, peterwilsoncc, ocean90.
Fixes #17232, #46015.
Built from https://develop.svn.wordpress.org/trunk@47771
git-svn-id: http://core.svn.wordpress.org/trunk@47547 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-05-06 16:15:07 -04:00
>
2015-11-20 02:24:30 -05:00
< head >
2017-11-30 18:11:00 -05:00
< meta http - equiv = " Content-Type " content = " <?php bloginfo( 'html_type' ); ?>; charset=<?php echo get_option( 'blog_charset' ); ?> " />
2018-08-16 21:51:36 -04:00
< ? php
2015-11-20 02:24:30 -05:00
}
/**
2022-03-28 05:45:06 -04:00
* Converts a screen string to a screen object .
2015-11-20 02:24:30 -05:00
*
* @ since 3.0 . 0
*
* @ param string $hook_name The hook name ( also known as the hook suffix ) used to determine the screen .
* @ return WP_Screen Screen object .
*/
function convert_to_screen ( $hook_name ) {
2016-08-27 22:25:27 -04:00
if ( ! class_exists ( 'WP_Screen' ) ) {
2017-10-18 11:46:52 -04:00
_doing_it_wrong (
'convert_to_screen(), add_meta_box()' ,
sprintf (
2018-03-11 12:44:34 -04:00
/* translators: 1: wp-admin/includes/template.php, 2: add_meta_box(), 3: add_meta_boxes */
2017-10-18 11:46:52 -04:00
__ ( 'Likely direct inclusion of %1$s in order to use %2$s. This is very wrong. Hook the %2$s call into the %3$s action instead.' ),
'<code>wp-admin/includes/template.php</code>' ,
'<code>add_meta_box()</code>' ,
'<code>add_meta_boxes</code>'
),
'3.3.0'
);
2017-11-30 18:11:00 -05:00
return ( object ) array (
'id' => '_invalid' ,
'base' => '_are_belong_to_us' ,
);
2015-11-20 02:24:30 -05:00
}
return WP_Screen :: get ( $hook_name );
}
/**
2022-07-21 05:24:10 -04:00
* Outputs the HTML for restoring the post data from DOM storage
2015-11-20 02:24:30 -05:00
*
* @ since 3.6 . 0
* @ access private
*/
function _local_storage_notice () {
?>
2016-06-16 23:02:29 -04:00
< div id = " local-storage-notice " class = " hidden notice is-dismissible " >
2015-11-20 02:24:30 -05:00
< p class = " local-restore " >
2016-06-16 23:02:29 -04:00
< ? php _e ( 'The backup of this post in your browser is different from the version below.' ); ?>
2017-11-30 18:11:00 -05:00
< button type = " button " class = " button restore-backup " >< ? php _e ( 'Restore the backup' ); ?> </button>
2015-11-20 02:24:30 -05:00
</ p >
2016-06-16 23:02:29 -04:00
< p class = " help " >
< ? php _e ( 'This will replace the current editor content with the last backup version. You can use undo and redo in the editor to get the old content back or to return to the restored version.' ); ?>
2015-11-20 02:24:30 -05:00
</ p >
</ div >
< ? php
}
/**
2022-03-28 05:45:06 -04:00
* Outputs a HTML element with a star rating for a given rating .
2015-11-20 02:24:30 -05:00
*
* Outputs a HTML element with the star rating exposed on a 0. . 5 scale in
* half star increments ( ie . 1 , 1.5 , 2 stars ) . Optionally , if specified , the
* number of ratings may also be displayed by passing the $number parameter .
*
* @ since 3.8 . 0
* @ since 4.4 . 0 Introduced the `echo` parameter .
*
* @ param array $args {
* Optional . Array of star ratings arguments .
*
2017-07-29 16:35:45 -04:00
* @ type int | float $rating The rating to display , expressed in either a 0.5 rating increment ,
* or percentage . Default 0.
* @ type string $type Format that the $rating is in . Valid values are 'rating' ( default ),
* or , 'percent' . Default 'rating' .
* @ type int $number The number of ratings that makes up this rating . Default 0.
* @ type bool $echo Whether to echo the generated markup . False to return the markup instead
* of echoing it . Default true .
2015-11-20 02:24:30 -05:00
* }
2017-07-29 16:35:45 -04:00
* @ return string Star rating HTML .
2015-11-20 02:24:30 -05:00
*/
function wp_star_rating ( $args = array () ) {
2019-07-24 20:48:58 -04:00
$defaults = array (
2015-11-20 02:24:30 -05:00
'rating' => 0 ,
'type' => 'rating' ,
'number' => 0 ,
'echo' => true ,
);
2019-07-24 20:48:58 -04:00
$parsed_args = wp_parse_args ( $args , $defaults );
2015-11-20 02:24:30 -05:00
2020-01-28 19:45:18 -05:00
// Non-English decimal places when the $rating is coming from a string.
2019-07-24 20:48:58 -04:00
$rating = ( float ) str_replace ( ',' , '.' , $parsed_args [ 'rating' ] );
2015-11-20 02:24:30 -05:00
2020-01-28 19:45:18 -05:00
// Convert percentage to star rating, 0..5 in .5 increments.
2019-07-24 20:48:58 -04:00
if ( 'percent' === $parsed_args [ 'type' ] ) {
2015-11-20 02:24:30 -05:00
$rating = round ( $rating / 10 , 0 ) / 2 ;
}
2020-01-28 19:45:18 -05:00
// Calculate the number of each type of star needed.
2017-11-30 18:11:00 -05:00
$full_stars = floor ( $rating );
$half_stars = ceil ( $rating - $full_stars );
2015-11-20 02:24:30 -05:00
$empty_stars = 5 - $full_stars - $half_stars ;
2019-07-24 20:48:58 -04:00
if ( $parsed_args [ 'number' ] ) {
2019-09-02 20:41:05 -04:00
/* translators: 1: The rating, 2: The number of ratings. */
2019-07-24 20:48:58 -04:00
$format = _n ( '%1$s rating based on %2$s rating' , '%1$s rating based on %2$s ratings' , $parsed_args [ 'number' ] );
$title = sprintf ( $format , number_format_i18n ( $rating , 1 ), number_format_i18n ( $parsed_args [ 'number' ] ) );
2015-11-20 02:24:30 -05:00
} else {
2019-09-02 20:41:05 -04:00
/* translators: %s: The rating. */
2015-11-20 02:24:30 -05:00
$title = sprintf ( __ ( '%s rating' ), number_format_i18n ( $rating , 1 ) );
}
2017-11-30 18:11:00 -05:00
$output = '<div class="star-rating">' ;
2015-11-20 02:24:30 -05:00
$output .= '<span class="screen-reader-text">' . $title . '</span>' ;
2016-04-30 10:33:29 -04:00
$output .= str_repeat ( '<div class="star star-full" aria-hidden="true"></div>' , $full_stars );
$output .= str_repeat ( '<div class="star star-half" aria-hidden="true"></div>' , $half_stars );
$output .= str_repeat ( '<div class="star star-empty" aria-hidden="true"></div>' , $empty_stars );
2015-11-20 02:24:30 -05:00
$output .= '</div>' ;
2019-07-24 20:48:58 -04:00
if ( $parsed_args [ 'echo' ] ) {
2015-11-20 02:24:30 -05:00
echo $output ;
}
return $output ;
}
/**
2021-06-15 11:50:58 -04:00
* Outputs a notice when editing the page for posts ( internal use only ) .
2015-11-20 02:24:30 -05:00
*
* @ ignore
* @ since 4.2 . 0
*/
function _wp_posts_page_notice () {
2021-06-15 11:50:58 -04:00
printf (
'<div class="notice notice-warning inline"><p>%s</p></div>' ,
__ ( 'You are currently editing the page that shows your latest posts.' )
);
2015-11-20 02:24:30 -05:00
}
Editor: Ensure that the block editor can be used on the page post type.
Additionally, add a notice for when you are editing the "latest posts" page.
Fixes #45537.
Props cameronjonesweb, swissspidy, hannahmalcolm, Fantasy1125, ArnaudBan, grantmkin, youknowriad, knutsp, SergeyBiryukov, audrasjb, whyisjake.
Built from https://develop.svn.wordpress.org/trunk@51116
git-svn-id: http://core.svn.wordpress.org/trunk@50725 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-08 18:38:58 -04:00
/**
2021-06-15 11:50:58 -04:00
* Outputs a notice when editing the page for posts in the block editor ( internal use only ) .
Editor: Ensure that the block editor can be used on the page post type.
Additionally, add a notice for when you are editing the "latest posts" page.
Fixes #45537.
Props cameronjonesweb, swissspidy, hannahmalcolm, Fantasy1125, ArnaudBan, grantmkin, youknowriad, knutsp, SergeyBiryukov, audrasjb, whyisjake.
Built from https://develop.svn.wordpress.org/trunk@51116
git-svn-id: http://core.svn.wordpress.org/trunk@50725 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-08 18:38:58 -04:00
*
* @ ignore
* @ since 5.8 . 0
*/
function _wp_block_editor_posts_page_notice () {
wp_add_inline_script (
'wp-notices' ,
sprintf (
'wp.data.dispatch( "core/notices" ).createWarningNotice( "%s", { isDismissible: false } )' ,
__ ( 'You are currently editing the page that shows your latest posts.' )
),
'after'
);
}