WordPress.org

Make WordPress Core

Ticket #18769: 18769.diff

File 18769.diff, 5.0 KB (added by sharifkiberu, 3 years ago)

change the get_submit_button() to include the page 'source' of a button so that we can add custom behaviour for specific pages. This will help us check if the site_url has been changed on the 'General Settings Page' thereby providing a warning or guidelines on how to relocate the site!

  • src/wp-admin/includes/template.php

     
    558558        $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']}' />";
    559559
    560560        $r .= "\n\t\t<div class='submit'>";
    561         $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" ) );
     561        $r .= get_submit_button( array( ['text' => __( 'Delete' ), 'type' => 'deletemeta small', 'name' => "deletemeta[{$entry['meta_id']}]", 'wrap' => false, 'other_attributes' => array( 'data-wp-lists' => "delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce" ),'source' => ''] ) );
    562562        $r .= "\n\t\t";
    563         $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" ) );
     563        $r .= get_submit_button( array( ['text' => __( 'Update' ), 'type' => 'updatemeta small', 'name' => "meta-{$entry['meta_id']}-submit", 'wrap' => false, 'other_attributes' => array( 'data-wp-lists' => "add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta=$update_nonce" ),'source' => ''] ) );
    564564        $r .= "</div>";
    565565        $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
    566566        $r .= "</td>";
     
    19381938 *                                       as a string such as 'tabindex="1"', though the array format is
    19391939 *                                       preferred. Default null.
    19401940 */
    1941 function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) {
    1942         echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
     1941function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null, $source = null ) {
     1942        $args = array([
     1943                'text' => $text,
     1944                'type' => $type,
     1945                'name' => $name,
     1946                'wrap' => $wrap,
     1947                'other_attributes' => $other_attributes,
     1948                'source' => $source
     1949                ]);
     1950        echo get_submit_button( $args );
    19431951}
    19441952
    19451953/**
    19461954 * Returns a submit button, with provided text and appropriate class
    19471955 *
    1948  * @since 3.1.0
     1956 * @since this patch
    19491957 *
    1950  * @param string       $text             Optional. The text of the button. Default 'Save Changes'.
    1951  * @param string       $type             Optional. The type and CSS class(es) of the button. Core values
    1952  *                                       include 'primary', 'small', and 'large'. Default 'primary large'.
    1953  * @param string       $name             Optional. The HTML name of the submit button. Defaults to "submit".
    1954  *                                       If no id attribute is given in $other_attributes below, `$name` will
    1955  *                                       be used as the button's id. Default 'submit'.
    1956  * @param bool         $wrap             Optional. True if the output button should be wrapped in a paragraph
    1957  *                                       tag, false otherwise. Default true.
    1958  * @param array|string $other_attributes Optional. Other attributes that should be output with the button,
    1959  *                                       mapping attributes to their values, such as `array( 'tabindex' => '1' )`.
    1960  *                                       These attributes will be output as `attribute="value"`, such as
    1961  *                                       `tabindex="1"`. Other attributes can also be provided as a string such
    1962  *                                       as `tabindex="1"`, though the array format is typically cleaner.
    1963  *                                       Default empty.
     1958 * @param array of arguments (required)
     1959 *                      arguments include : text, type, name, wrap, other_attributes, and source
     1960                        `source` is new. It helps identify the source or page on which the button
     1961                        exists. This is to enable add custom funcionality for different pages. In
     1962                        this case, we can make a pop up warning the user who wants to change the
     1963                        site url, or guide them on how best they can relocate to new address!
     1964 *
    19641965 * @return string Submit button HTML.
    19651966 */
    1966 function get_submit_button( $text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '' ) {
     1967function get_submit_button( $args = array() ) {
     1968        //set variables
     1969        $text = isset( $args['text'] ) ? $args['text'] : '';
     1970        $type = isset( $args['type'] ) ? $args['type'] : 'primary large';
     1971        $name = isset( $args['name'] ) ? $args['name'] : 'submit';
     1972        $wrap = isset( $args['wrap'] ) ? $args['wrap'] : true;
     1973        $other_attributes = isset( $args['other_attributes'] ) ? $args['other_attributes'] : '';
     1974        $source = isset( $args['source'] ) ? $args['source'] : '';
     1975
    19671976        if ( ! is_array( $type ) )
    19681977                $type = explode( ' ', $type );
    19691978