_doing_it_wrong example

/** * Converts a screen string to a screen object. * * @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 ) {
    if ( ! class_exists( 'WP_Screen' ) ) {
        _doing_it_wrong(
            'convert_to_screen(), add_meta_box()',
            sprintf(
                /* translators: 1: wp-admin/includes/template.php, 2: add_meta_box(), 3: add_meta_boxes */
                __( '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'
        );
        return (object) array(
            

    public function remove_panel( $id ) {
        // Removing core components this way is _doing_it_wrong().         if ( in_array( $id$this->components, true ) ) {
            _doing_it_wrong(
                __METHOD__,
                sprintf(
                    /* translators: 1: Panel ID, 2: Link to 'customize_loaded_components' filter reference. */
                    __( 'Removing %1$s manually will cause PHP warnings. Use the %2$s filter instead.' ),
                    $id,
                    sprintf(
                        '<a href="%1$s">%2$s</a>',
                        esc_url( 'https://developer.wordpress.org/reference/hooks/customize_loaded_components/' ),
                        '<code>customize_loaded_components</code>'
                    )
                ),
                

function register_rest_route( $route_namespace$route$args = array()$override = false ) {
    if ( empty( $route_namespace ) ) {
        /* * Non-namespaced routes are not allowed, with the exception of the main * and namespace indexes. If you really need to register a * non-namespaced route, call `WP_REST_Server::register_route` directly. */
        _doing_it_wrong( 'register_rest_route', __( 'Routes must be namespaced with plugin or theme name and version.' ), '4.4.0' );
        return false;
    } elseif ( empty( $route ) ) {
        _doing_it_wrong( 'register_rest_route', __( 'Route must be specified.' ), '4.4.0' );
        return false;
    }

    $clean_namespace = trim( $route_namespace, '/' );

    if ( $clean_namespace !== $route_namespace ) {
        _doing_it_wrong( __FUNCTION__, __( 'Namespace must not start or end with a slash.' ), '5.4.2' );
    }

    

function register_uninstall_hook( $file$callback ) {
    if ( is_array( $callback ) && is_object( $callback[0] ) ) {
        _doing_it_wrong( __FUNCTION__, __( 'Only a static class method or function can be used in an uninstall hook.' ), '3.1.0' );
        return;
    }

    /* * The option should not be autoloaded, because it is not needed in most * cases. Emphasis should be put on using the 'uninstall.php' way of * uninstalling the plugin. */
    $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
    $plugin_basename       = plugin_basename( $file );

    

    protected function get_views_links( $link_data = array() ) {
        if ( ! is_array( $link_data ) ) {
            _doing_it_wrong(
                __METHOD__,
                sprintf(
                    /* translators: %s: The $link_data argument. */
                    __( 'The %s argument must be an array.' ),
                    '<code>$link_data</code>'
                ),
                '6.1.0'
            );

            return array( '' );
        }

        
'validate_callback' => array( $this, 'check_template' ),
            ),
        );

        $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );

        foreach ( $taxonomies as $taxonomy ) {
            $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;

            if ( array_key_exists( $base$schema['properties'] ) ) {
                $taxonomy_field_name_with_conflict = ! empty( $taxonomy->rest_base ) ? 'rest_base' : 'name';
                _doing_it_wrong(
                    'register_taxonomy',
                    sprintf(
                        /* translators: 1: The taxonomy name, 2: The property name, either 'rest_base' or 'name', 3: The conflicting value. */
                        __( 'The "%1$s" taxonomy "%2$s" property (%3$s) conflicts with an existing property on the REST API Posts Controller. Specify a custom "rest_base" when registering the taxonomy to avoid this error.' ),
                        $taxonomy->name,
                        $taxonomy_field_name_with_conflict,
                        $base
                    ),
                    '5.4.0'
                );
            }

            
if ( ! in_array( $name$this->deprecated_properties, true ) ) {
            $this->{$name} = $value;
            return;
        }

        $new_name = $name . '_handles';

        if ( is_array( $value ) ) {
            $filtered = array_filter( $value, 'is_string' );

            if ( count( $filtered ) !== count( $value ) ) {
                    _doing_it_wrong(
                        __METHOD__,
                        sprintf(
                            /* translators: %s: The '$value' argument. */
                            __( 'The %s argument must be a string or a string array.' ),
                            '<code>$value</code>'
                        ),
                        '6.1.0'
                    );
            }

            $this->{$new_name} = array_values( $filtered );
            

    protected $schema;

    /** * Registers the routes for the objects of the controller. * * @since 4.7.0 * * @see register_rest_route() */
    public function register_routes() {
        _doing_it_wrong(
            'WP_REST_Controller::register_routes',
            /* translators: %s: register_routes() */
            sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ),
            '4.7.0'
        );
    }

    /** * Checks if a given request has access to get items. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */
if ( empty( $icon_url ) ) {
        $icon_url   = 'dashicons-admin-generic';
        $icon_class = 'menu-icon-generic ';
    } else {
        $icon_url   = set_url_scheme( $icon_url );
        $icon_class = '';
    }

    $new_menu = array( $menu_title$capability$menu_slug$page_title, 'menu-top ' . $icon_class . $hookname$hookname$icon_url );

    if ( null !== $position && ! is_numeric( $position ) ) {
        _doing_it_wrong(
            __FUNCTION__,
            sprintf(
                /* translators: %s: add_menu_page() */
                __( 'The seventh parameter passed to %s should be numeric representing menu position.' ),
                '<code>add_menu_page()</code>'
            ),
            '6.0.0'
        );
        $position = null;
    }

    
foreach ( $sitemaps as $entry ) {
            $sitemap = $sitemap_index->addChild( 'sitemap' );

            // Add each element as a child node to the <sitemap> entry.             foreach ( $entry as $name => $value ) {
                if ( 'loc' === $name ) {
                    $sitemap->addChild( $nameesc_url( $value ) );
                } elseif ( 'lastmod' === $name ) {
                    $sitemap->addChild( $nameesc_xml( $value ) );
                } else {
                    _doing_it_wrong(
                        __METHOD__,
                        sprintf(
                            /* translators: %s: List of element names. */
                            __( 'Fields other than %s are not currently supported for the sitemap index.' ),
                            implode( ',', array( 'loc', 'lastmod' ) )
                        ),
                        '5.5.0'
                    );
                }
            }
        }

        
public function localize( $handle$object_name$l10n ) {
        if ( 'jquery' === $handle ) {
            $handle = 'jquery-core';
        }

        if ( is_array( $l10n ) && isset( $l10n['l10n_print_after'] ) ) { // back compat, preserve the code in 'l10n_print_after' if present.             $after = $l10n['l10n_print_after'];
            unset( $l10n['l10n_print_after'] );
        }

        if ( ! is_array( $l10n ) ) {
            _doing_it_wrong(
                __METHOD__,
                sprintf(
                    /* translators: 1: $l10n, 2: wp_add_inline_script() */
                    __( 'The %1$s parameter must be an array. To pass arbitrary data to scripts, use the %2$s function instead.' ),
                    '<code>$l10n</code>',
                    '<code>wp_add_inline_script()</code>'
                ),
                '5.7.0'
            );

            if ( false === $l10n ) {
                
if ( is_array( $value ) && isset( $value['ref'] ) ) {
            $value_path = explode( '.', $value['ref'] );
            $ref_value  = _wp_array_get( $theme_json$value_path );
            // Only use the ref value if we find anything.             if ( ! empty( $ref_value ) && is_string( $ref_value ) ) {
                $value = $ref_value;
            }

            if ( is_array( $ref_value ) && isset( $ref_value['ref'] ) ) {
                $path_string      = json_encode( $path );
                $ref_value_string = json_encode( $ref_value );
                _doing_it_wrong(
                    'get_property_value',
                    sprintf(
                        /* translators: 1: theme.json, 2: Value name, 3: Value path, 4: Another value name. */
                        __( 'Your %1$s file uses a dynamic value (%2$s) for the path at %3$s. However, the value at %3$s is also a dynamic value (pointing to %4$s) and pointing to another dynamic value is not supported. Please update %3$s to point directly to %4$s.' ),
                        'theme.json',
                        $ref_value_string,
                        $path_string,
                        $ref_value['ref']
                    ),
                    '6.1.0'
                );
            }
case 'delete_post':
        case 'delete_page':
            if ( ! isset( $args[0] ) ) {
                if ( 'delete_post' === $cap ) {
                    /* translators: %s: Capability name. */
                    $message = __( 'When checking for the %s capability, you must always check it against a specific post.' );
                } else {
                    /* translators: %s: Capability name. */
                    $message = __( 'When checking for the %s capability, you must always check it against a specific page.' );
                }

                _doing_it_wrong(
                    __FUNCTION__,
                    sprintf( $message, '<code>' . $cap . '</code>' ),
                    '6.1.0'
                );

                $caps[] = 'do_not_allow';
                break;
            }

            $post = get_post( $args[0] );
            if ( ! $post ) {
                

    public function is_allowed_dir( $dir ) {
        if ( is_string( $dir ) ) {
            $dir = trim( $dir );
        }

        if ( ! is_string( $dir ) || '' === $dir ) {
            _doing_it_wrong(
                __METHOD__,
                sprintf(
                    /* translators: %s: The "$dir" argument. */
                    __( 'The "%s" argument must be a non-empty string.' ),
                    '$dir'
                ),
                '6.2.0'
            );

            return false;
        }

        

function get_user_count( $network_id = null ) {
    if ( ! is_multisite() && null !== $network_id ) {
        _doing_it_wrong(
            __FUNCTION__,
            sprintf(
                /* translators: %s: $network_id */
                __( 'Unable to pass %s if not using multisite.' ),
                '<code>$network_id</code>'
            ),
            '6.0.0'
        );
    }

    return (int) get_network_option( $network_id, 'user_count', -1 );
}
Home | Imprint | This part of the site doesn't use cookies.