I'm trying to make my old Wordpress theme to work in PHP version 7.4 yet I'm having some issues doing it the right way. Problem relates to data from custom fields not being saved or accessible. Everything works fine with PHP version 5.4 so I know it's related to PHP 7.4
For example I have this in my functions.php
<?php
$themename = "WTB Game";
$shortname = "tg";
$options = array (
array( "name" => "336*280 Adcode",
"desc" => "Paste your 336*280 Adcode code.",
"id" => $shortname."_336_280",
"type" => "textarea"),
);
Now I have this separate php file called ad-336-280.php using the following code:
<?
global $options;
foreach ($options as $value) {
if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}
?>
<div class="ad336">
<? if ($tg_336_280) { ?>
<? echo stripslashes($tg_336_280); ?>
<? } else { ?>
<img src="<?php bloginfo('stylesheet_directory'); ?>/ads/336-280.gif" alt="" />
<? } ?>
</div>
Inside my single.php wordpress file I'm calling this file using:
<div class="ad336">
<?php include (TEMPLATEPATH . '/ads/ad-336-280.php'); ?>
</div>
yet it will only display the picture(.gif) storred inside /ads/336-280.gif as default instead of the actual text/code I'm writing in the custom field text area.
Using the ${$value['id']} = $value['std']; instead of $$value['id'] = $value['std']; does not solve the problem so I struggle to understand what could it be.
I also attach a piece of code inside my functions.php that relates to saving the data once the custom field is filled and the save button is pressed.
function mytheme_add_admin() {
global $themename, $shortname, $options;
if ( $_GET['page'] == basename(__FILE__) ) {
if ( 'save' == $_REQUEST['action'] ) {
foreach ($options as $value) {
update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
foreach ($options as $value) {
if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } }
header("Location: themes.php?page=functions.php&saved=true");
die;
} else if( 'reset' == $_REQUEST['action'] ) {
foreach ($options as $value) {
delete_option( $value['id'] ); }
header("Location: themes.php?page=functions.php&reset=true");
die;
}
}
add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
}
and
function mytheme_admin() {
global $themename, $shortname, $options;
if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
?>
Looking forward for some help in order to figure it out. Kind regards to those who can help.