Skip Navigation

[Closed] There has been a critical error on this website: creating custiom post type

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 1 year, 5 months ago.

Assisted by: Nigel.

Author
Posts
#2640961

I am trying to create a new Post of a custom type and I get the error "There has been a critical error on this website" on both create and edit of this post type with PHP 8.0 or 8.2.

hidden link

If I downgrade to PHP 7.4 then it works!

PHP Fatal error: Uncaught Error: Call to undefined function each() in /nas/content/live/nakedalmstage/wp-content/toolset-customizations/toolset_options_ordering.php:27\nStack trace:\n#0 /nas/content/live/nakedalmstage/wp-includes/class-wp-hook.php(310): func_dynamic_populate(Array, 'Training Timezo...', 'select')\n#1 /nas/content/live/nakedalmstage/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array)\n#2 /nas/content/live/nakedalmstage/wp-content/plugins/types/vendor/toolset/toolset-common/toolset-forms/classes/class.select.php(105): apply_filters('wpt_field_optio...', Array, 'Training Timezo...', 'select')\n#3 /nas/content/live/nakedalmstage/wp-content/plugins/types/vendor/toolset/toolset-common/toolset-forms/classes/class.form_factory.php(309): WPToolset_Field_Select->metaform()\n#4 /nas/content/live/nakedalmstage/wp-content/plugins/types/vendor/toolset/toolset-common/toolset-forms/bootstrap.php(66): FormFactory->metaform(Array, 'wpcf[training-t...', Array)\n#5 /nas/content/live/nakedalmstage/wp-content/plugins/types/vendor/toolset/toolset-common/toolset-forms/api.php(25): WPToolset_Forms_Bootstrap->field('post', Array, Array)\n#6 /nas/content/live/nakedalmstage/wp-content/plugins/types/vendor/toolset/types/embedded/includes/fields-post.php(277): wptoolset_form_field('post', Array, Array)\n#7 /nas/content/live/nakedalmstage/wp-content/plugins/types/vendor/toolset/types/embedded/admin.php(105): wpcf_add_meta_boxes('trainings', Object(WP_Post))\n#8 /nas/content/live/nakedalmstage/wp-includes/class-wp-hook.php(310): wpcf_admin_add_meta_boxes('trainings', Object(WP_Post))\n#9 /nas/content/live/nakedalmstage/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters(NULL, Array)\n#10 /nas/content/live/nakedalmstage/wp-includes/plugin.php(517): WP_Hook->do_action(Array)\n#11 /nas/content/live/nakedalmstage/wp-admin/includes/meta-boxes.php(1715): do_action('add_meta_boxes', 'trainings', Object(WP_Post))\n#12 /nas/content/live/nakedalmstage/wp-admin/edit-form-advanced.php(271): register_and_do_post_meta_boxes(Object(WP_Post))\n#13 /nas/content/live/nakedalmstage/wp-admin/post-new.php(75): require('/nas/content/li...')\n#14 {main}\n thrown in /nas/content/live/nakedalmstage/wp-content/toolset-customizations/toolset_options_ordering.php on line 27, referer: <em><u>hidden link</u></em>
#2641065

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

It looks like the error comes from custom code you would have added at Toolset > Settings > Custom Code in a snippet called toolset_options_ordering.php.

I suggest you de-activate that snippet, and then you should be able to create a post type.

What does the snippet do? Where did you get the code?

#2641069

Genius! Well SPotted!

<?php
/**
* New custom code snippet (replace this with snippet description).
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.
add_filter( 'wpt_field_options', 'func_dynamic_populate', 10, 3);
function func_dynamic_populate( $options, $title, $type ){
global $wpdb;
switch( $title ){
case 'Training Timezone':

$OptionsArray = timezone_identifiers_list();

$timezones = array(
array('#value' => '', '#title' => '----timezone----'),
array('#value' => 'Europe/London', '#title' => 'Europe/London'),
array('#value' => 'America/New_York', '#title' => 'America/New_York'),
array('#value' => 'America/Chicago', '#title' => 'America/Chicago'),
array('#value' => 'America/Los_Angeles', '#title' => 'America/Los_Angeles'),
array('#value' => 'UTC', '#title' => 'UTC')
);
asort($timezones);
while (list ($key, $row) = each ($OptionsArray) ){
$newtimezone = array('#value' => $row, '#title' => $row);
if (!in_array($newtimezone, $timezones))
{
$timezones[] = $newtimezone;
}
}

//echo '<pre>'; print_r($options); echo '</pre>';
$options = $timezones;
break;
}
return $options;
}

I guess there is something in here that not available in PHP 8.0+

Do you know what it is?

#2641255

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

The problem is the use of the PHP function each(), which was removed in PHP 8: hidden link

Typically you would replace it with a foreach loop.

It's not obvious to me what the code is doing so I can't recommend how to update it.

The topic ‘[Closed] There has been a critical error on this website: creating custiom post type’ is closed to new replies.