• I’ve inherited a WP site that has a custom theme written about 8 years ago. Very little updates were implemented on this server (running WP 5.1.6 and PHP 5.3). We’re migrating the site to a new server with current releases (WP 5.5.1 and PHP 7.3). Unfortunately, there are a number of deprecated issues within the custom theme and going back to the original developer is not possible.

    I’m don’t work with WP or have any background in the use of PHP for websites so I am struggling sometimes with the most basic premises. I do code in python and can get around in html/css – which appears entirely useless here.

    I’ve been able to track down and fix a number of the issues and thought I was out of the woods since I was only getting Warnings. But, when I actually closed the interface and then log into the admin page – it just displays the white screen with the following Warnings.

    Warning: Declaration of wp_option_choose_color_scheme::render() should be compatible with wp_option::render($field_html, $colspan = false) in /home/usnvc/public_html/wp-content/themes/usnvc/lib/theme-options/choose-color-scheme.php on line 38

    Warning: Cannot modify header information – headers already sent by (output started at /home/usnvc/public_html/wp-content/themes/usnvc/lib/theme-options/choose-color-scheme.php:0) in /home/usnvc/public_html/wp-login.php on line 521

    Warning: Cannot modify header information – headers already sent by (output started at /home/usnvc/public_html/wp-content/themes/usnvc/lib/theme-options/choose-color-scheme.php:0) in /home/usnvc/public_html/wp-login.php on line 537

    Warning: Cannot modify header information – headers already sent by (output started at /home/usnvc/public_html/wp-content/themes/usnvc/lib/theme-options/choose-color-scheme.php:0) in /home/usnvc/public_html/wp-includes/functions.php on line 6270

    Warning: Cannot modify header information – headers already sent by (output started at /home/usnvc/public_html/wp-content/themes/usnvc/lib/theme-options/choose-color-scheme.php:0) in /home/usnvc/public_html/wp-includes/pluggable.php on line 958

    Warning: Cannot modify header information – headers already sent by (output started at /home/usnvc/public_html/wp-content/themes/usnvc/lib/theme-options/choose-color-scheme.php:0) in /home/usnvc/public_html/wp-includes/pluggable.php on line 959

    Warning: Cannot modify header information – headers already sent by (output started at /home/usnvc/public_html/wp-content/themes/usnvc/lib/theme-options/choose-color-scheme.php:0) in /home/usnvc/public_html/wp-includes/pluggable.php on line 960

    Warning: Cannot modify header information – headers already sent by (output started at /home/usnvc/public_html/wp-content/themes/usnvc/lib/theme-options/choose-color-scheme.php:0) in /home/usnvc/public_html/wp-includes/pluggable.php on line 1296

    Warning: Cannot modify header information – headers already sent by (output started at /home/usnvc/public_html/wp-content/themes/usnvc/lib/theme-options/choose-color-scheme.php:0) in /home/usnvc/public_html/wp-includes/pluggable.php on line 1299

    Now I know enough that I’m not going to edit the base files so, clearly, my issue is in the choose-color-scheme.php in the first warning. And clearly, it’s telling me the declaration of wp_option_choose_color_scheme::render() should be compatible with wp_option::render($field_thtml, $colspan = false). My problem is I don’t recognize things in the code.

    <?php
    class color_scheme {
    	var $name;
    	var $colors = array();
    	
    	function color_scheme($name) {
    	    $this->name = $name;
    	}
    	function add_color($hex_code) {
    	    $this->colors[] = intval($hex_code, 16);
    	}
    	function add_colors($colors) {
    	    foreach ($colors as $color) {
    	    	$this->add_color($color);
    	    }
    	}
    	function get_sorted_colors() {
    	    sort($this->colors);
    	    $hex_colors = array();
    	    foreach ($this->colors as $decimal) {
    	    	$hex_colors[] = sprintf('%06X', $decimal);
    	    }
    	    return $hex_colors;
    	}
    }
    class wp_option_choose_color_scheme extends wp_option {
    	var $color_schemes = array();
    	
    	function add_color_scheme($color_scheme) {
    	    $this->color_schemes[] = $color_scheme;
    	}
    	function add_color_schemes($color_schemes) {
    	    foreach ($color_schemes as $color_scheme) {
    	    	$this->add_color_scheme($color_scheme);
    	    }
    	}
    	
    	function render() {
    		$html = '';
    	    foreach ($this->color_schemes as $color_scheme) {
    	    	$html .= '<div class="color-option">';
    	    	$checked = '';
    	    	if ($this->value==$color_scheme->name) {
    	    		$checked = 'checked';
    	    	}
    	    	$html .= '<input type="radio" name="' . $this->name . '" ' . $checked . ' class="tog" value="' . $color_scheme->name . '" id="' . $color_scheme->name . '" />';
    	    	$html .= '<table class="color-palette">';
    	    	$html .= '<tr>';
    	    	foreach ($color_scheme->get_sorted_colors() as $color) {
    	    		$html .= '<td style="background: #' . $color . '">&nbsp;</td>';
    	    	}
    	    	$html .= '</tr>';
    	    	$html .= '</table>';
    	    	$html .= '</div>';
    	    	$html .= '<label for="' . $color_scheme->name . '">' . $color_scheme->name . '</label>';
    	    }
    	    return wp_option::render($html);
    	}
    }
    ?>

    Any help would be appreciated. I promise to retain what I learn.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @stevefactor,

    If your main issue is admin access. Then you can simply disable WP_DEBUG in wp-config.php by setting the value to false. These don’t affect your site in any way.

    However, the problem is that sometimes the above does not work.
    That can happen most times on cheap shared hosts that force displaying PHP warnings and notices.
    In that case, you can replace this line from your wp-config.php file:

    define('WP_DEBUG', false);

    with this:

    ini_set('display_errors','Off');
    ini_set('error_reporting', E_ALL );
    define('WP_DEBUG', false);
    define('WP_DEBUG_DISPLAY', false);

    I hope that helps.

    Have a nice day ??

    Thread Starter stevefactor

    (@stevefactor)

    Thanks. I’m aware I can turn off the warnings and that warnings don’t typically crash the site, but I’m a bit worried that the mere presentation of the warnings is enough to shut down admin access. Then I have to back into the admin area by renaming the theme and then restoring that theme’s name. That is an odd behavior that I’d like to fix.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘no admin access with custom theme’ is closed to new replies.