a problem with adding PHP to template with UDT Topic is solved

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
offsidetrap
New Member
New Member
Posts: 0
Joined: Thu May 29, 2025 9:12 pm

a problem with adding PHP to template with UDT

Post by offsidetrap »

Hello all, I wonder if you could help me.

I am trying to add some PHP to my template using a UDT but when I submit I just see a blank white page. The blank page loaded is editusertag.php

There is quite a lot of PHP code but through trial and error I have managed to narrow down the problem to these 2 lines (edited slightly for privacy reasons):

require 'path-to-file.php';
use class\CLASS;

There is no error shown on screen or in browser dev tools, any ideas would be greatly appreciated.
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1785
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: a problem with adding PHP to template with UDT

Post by DIGI3 »

There is a bug in the current version where it processes the submitted code instead of just verifying it, so any PHP errors in your code or anything not parsable in admin will cause it to white screen on submit.

Best option for now is to use a plugin instead of a UDT - then you should only get errors on the page you call it on. See /lib/plugins/ for examples, and put yours in /assets/plugins.
Not getting the answer you need? CMSMS support options
User avatar
webform
Power Poster
Power Poster
Posts: 503
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: a problem with adding PHP to template with UDT

Post by webform »

My work around to handle the bug in UDT, is to create the UDT with only a PHP comment and then submit the full PHP code in the cms_userplugins table in phpMyAdmin.
Just remember to Clear Cache in System Maintenance after submitting the PHP code, so the UDT loads the code.
User avatar
creopard
Forum Members
Forum Members
Posts: 92
Joined: Fri Nov 10, 2017 10:25 am
Location: .de
Contact:

Re: a problem with adding PHP to template with UDT

Post by creopard »

just for reference: https://dev.cmsmadesimple.org/bug/view/12749

This bug has already been fixed in the trunk, hasn't it?
file \admin\editusertag.php line 98

instead of

Code: Select all

    try
    {
      eval($code);
      ob_get_clean();
    };
it's now:

Code: Select all

    try
    {
      # let's try to eval the code but not execute it
      $tmp = 'return;' . $code;
      eval($tmp);
      ob_get_clean();
    }
Post Reply

Return to “CMSMS Core”