localize example


function wp_localize_script( $handle$object_name$l10n ) {
    global $wp_scripts;

    if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
        _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
        return false;
    }

    return $wp_scripts->localize( $handle$object_name$l10n );
}

/** * Sets translated strings for a script. * * Works only if the script has already been registered. * * @see WP_Scripts::set_translations() * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. * * @since 5.0.0 * @since 5.1.0 The `$domain` parameter was made optional. * * @param string $handle Script handle the textdomain will be attached to. * @param string $domain Optional. Text domain. Default 'default'. * @param string $path Optional. The full file path to the directory containing translation files. * @return bool True if the text domain was successfully localized, false otherwise. */
if ( ! $guessurl ) {
        $guessed_url = true;
        $guessurl    = wp_guess_url();
    }

    $scripts->base_url        = $guessurl;
    $scripts->content_url     = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : '';
    $scripts->default_version = get_bloginfo( 'version' );
    $scripts->default_dirs    = array( '/wp-admin/js/', '/wp-includes/js/' );

    $scripts->add( 'utils', "/wp-includes/js/utils$suffix.js" );
    did_action( 'init' ) && $scripts->localize(
        'utils',
        'userSettings',
        array(
            'url'    => (string) SITECOOKIEPATH,
            'uid'    => (string) get_current_user_id(),
            'time'   => (string) time(),
            'secure' => (string) ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) ),
        )
    );

    $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array( 'jquery', 'hoverIntent', 'utils' ), false, 1 );
    
Home | Imprint | This part of the site doesn't use cookies.