Forum
function in admin.php breaking dashboard in custom App
Hi,
I made an Admin Styling App for Perch (GitHub), which works great except when the "dashboard" is enabled in the admin Settings.
It seems like if I add any kind of function to the admin.php
in the custom App, the dashboard breaks.
Am I doing something wrong?
Here is the full code in admin.php
in the Admin Style app.
<?php
$this->register_app('jaygeorge_perch_admin_style', 'Admin Style', 1, 'An app that styles the Perch admin', 1.0);
$this->require_version('jaygeorge_perch_admin_style', '2.8');
$this->add_setting('jaygeorge_perch_admin_style_external_font_stylesheet', 'External Font Stylesheet', 'text', false,'','This is an optional stylesheet include for loading something like Typekit or Google Fonts e.g. https://use.typekit.net/dsl0pss.css');
$this->add_create_page('jaygeorge_perch_admin_style', 'edit');
$API = new PerchAPI(1.0, 'jaygeorge_perch_admin_style');
function get_external_font_stylesheet() {
$API = new PerchAPI(1.0, 'jaygeorge_perch_admin_style');
$external_font_stylesheet = $API->get('Settings')->get('jaygeorge_perch_admin_style_external_font_stylesheet')->val();
return $external_font_stylesheet;
}
$Perch = Perch::fetch();
// We need to separate variables.css out so that the login.css can make use of it (which is loaded outside the app, so it can be available before the admin is loaded)
$Perch->add_css($API->app_path() . '/variables.css');
$Perch->add_css($API->app_path() . '/standard-admin.css');
$Perch->add_css('/perch/addons/plugins/ui/custom-admin.css');
$Perch->add_css(get_external_font_stylesheet());
$Perch->add_head_content('<link rel="shortcut icon" href="/perch/addons/plugins/ui/favicon.ico">');
How does it break?
Hi sorry for the late reply—I didn't get a notification that you had replied; I only noticed because I randomly checked the forum.
The error I'm getting is just a 500 blank page error whenever I add a function to admin.php and enable the dashboard.
Here's a 1 min video showing this happening.
What's the actual error in your error log?
Thanks for the quick reply.
I found this in the php error log:
…which suggests that maybe it's trying to call the
admin.php
file twice?Your dashboard file needs to return a callable, which when called returns the HTML output of your widget.
I'd suggest a format like:
I don't have a dashboard.php file in the app I developed :-/
Do I need one?
Throw an empty placeholder file in there.
Hmm yeah that's not making any difference unfortunately, still the same errors coming from admin.php.
Are you declaring functions in your
admin.php
file?Yes I am.
So I am adding an external font stylesheet in the
admin.php
with a function as follows:but even just
function test() {}
will break the dashboard.It works great in general throughout the admin…except in the dashboard view, where the page breaks.
I would do this:
Unless you're using that global function elsewhere, there's no need for it. There's also no need to
return
the function declaration - I'm surprised that works at all.That worked great, thank you