Alternative to eval()

I have a widget in Wordpress which uses eval() in the code but this is switched off on the server and so can’t be used. I was wondering if anyone could give me some assistance with respect to changing the following code so that it doens’t use eval. I’m just a beginner but am willing to learn so any help would be appreciated.

function widget( $args, $instance ) {
	extract($args);
	$title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance );
	$text = apply_filters( 'widget_execphp', $instance['text'], $instance );
	echo $before_widget;
	if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } 
		ob_start();
		eval('?>'.$text);
		$text = ob_get_contents();
		ob_end_clean();
		?>			
		<div class="execphpwidget"><?php echo $instance['filter'] ? wpautop($text) : $text; ?></div>
	<?php
	echo $after_widget;
}

You can’t “switch off” a function. What error is it giving you?

You absolutely can. Check your php.ini file, you will see this:

; This directive allows you to disable certain functions for security reasons.
; It receives a comma-delimited list of function names. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
; http://php.net/disable-functions
disable_functions =

OP, I don’t know much about wordpress other than it is HIGHLY insecure and easily hacked. The use of eval() is a likely cause. Sorry I don’t have an answer for you.

Sponsor our Newsletter | Privacy Policy | Terms of Service