WordPress.org

Ready to get started?Download WordPress

Forums

WordPress and encoding errors in AJAX and XMLRPC (2 posts)

  1. Sergey.S.Betke
    Member
    Posted 2 years ago #

    When the initiative is set in php.ini encodings other than coding blog, watching the problem with the encoding of XMLRPC applications (for example - Live Writer) and in all admin-AJAX responses.

    To resolve the error:

    • file wp-includes/class-IXR.php, now:
      function output($xml)
      {
            $xml = '<?xml version="1.0"?>'."\n".$xml;
            $length = strlen($xml);
            header('Connection: close');
            header('Content-Type: text/xml;', true);
            header('Content-Length: '.$length);
            header('Date: '.date('r'));
            echo $xml;
            exit;
      }

      correct version:

      function output($xml)
      {
            $xml = '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'."\n".$xml;
            $length = strlen($xml);
            header('Connection: close');
            header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
            header('Content-Length: '.$length);
            header('Date: '.date(DATE_RFC1123));
            echo $xml;
            exit;
      }
    • wp-includes/class-wp-admin-ajax-response.php, now:
      function send() {
          header('Content-Type: text/xml');
          echo "<?xml version='1.0' standalone='yes'?><wp_ajax>";
          foreach ( (array) $this->responses as $response )
              echo $response;
          echo '</wp_ajax>';
          die();
      }

      correct version:

      function send() {
          $xml = "<?xml version='1.0' encoding='" . get_option('blog_charset') . "' standalone='yes'?><wp_ajax>";
          foreach ( (array) $this->responses as $response )
              $xml .= $response;
          $xml .= '</wp_ajax>';
          $length = strlen($xml);
          header('Content-Type: text/xml; charset=' . get_option('blog_charset'));
          header('Content-Length: '.$length);
          header('Date: '.date(DATE_RFC1123));
          echo $xml;
          die();
      }
  2. Sergey.S.Betke
    Member
    Posted 2 years ago #

    And when updated plugins. wp-admin/includes/template.php now:

    function iframe_header( $title = '', $limit_styles = false ) {
        show_admin_bar( false );
        global $hook_suffix, $current_screen, $current_user, $admin_body_class, $wp_locale;
        $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
        $admin_body_class .= ' iframe';  
    
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
    <head>
    <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
    <title><?php bloginfo('name') ?> &rsaquo; <?php echo $title ?> — <?php _e('WordPress'); ?></title>
    <?php

    correct version:

    function iframe_header( $title = '', $limit_styles = false ) {
        show_admin_bar( false );
        global $hook_suffix, $current_screen, $current_user, $admin_body_class, $wp_locale;
        $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
        $admin_body_class .= ' iframe';
    
        header('Connection: close');
        header('Content-Type: text/html; charset=' . get_option('blog_charset'), true);
        header('Expires: '.date(DATE_RFC1123));
        header('Date: '.date(DATE_RFC1123));
        header('Cache-Control: no-store, no-cache, must-revalidate');
        header('Cache-Control: post-check=0, pre-check=0', FALSE);
        header('Pragma: no-cache');
    
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
    <head>
    <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
    <title><?php bloginfo('name') ?> &rsaquo; <?php echo $title ?> — <?php _e('WordPress'); ?></title>
    <?php

Topic Closed

This topic has been closed to new replies.

About this Topic