How to : control a valide album file name in theme options


In my new theme, I want to allow a specific album as a slider on the home page.

In my themeoptions.php, I want to manage if this album name exists or not.

I am probably tired, but my code doesn't work as usual, and I don't know why: I have an error when I test if the album is an object (line 6 of the following code).

can you help me to solve my issue?
I would really appreciate.

function getOptionsSupported() {
$msg = '';
$zpB_homepage_album_filename = getOption('zpB_homepage_album_filename');
if (!empty($zpB_homepage_album_filename)) {
$album = newAlbum($zpB_homepage_album_filename);
if (!is_object($album) || !$album->exists) {
$msg = '

' . gettext('You need to provide a valid Album filename.') . '


return array(
gettext('Homepage') => array('order' => 0, 'key' => 'zpB_homepage', 'type' => OPTION_TYPE_CHECKBOX, 'desc' => gettext_th("Display a home page, with a slider of 5 random picts, the gallery description and the latest news.", 'zpBootstrap')),
gettext('Use this album for homepage slider') => array(
'order' => 2,
'key' => 'zpB_homepage_album_filename',
'multilingual' => 0,
'desc' => gettext_th('Album file name for the homepage slider: enter the full filename of the Album to use for the homepage slider. If empty, the whole gallery will be used for the slider.', 'zpBootstrap') . $msg),

gettext('Random pictures for homepage slider') => array('order' => 4, 'key' => 'zpB_homepage_random_pictures', 'type' => OPTION_TYPE_TEXTBOX, 'multilingual' => 0, 'desc' => gettext_th('Number of random pictures to use for the homepage slider.', 'zpBootstrap')),
gettext('Archive View') => array('order' => 12, 'key' => 'zpB_show_archive', 'type' => OPTION_TYPE_CHECKBOX, 'desc' => gettext_th("Display a link to the Archive list.", 'zpBootstrap')),
gettext('Tags') => array('order' => 14, 'key' => 'zpB_show_tags', 'type' => OPTION_TYPE_CHECKBOX, 'desc' => gettext_th("Check to show a tag cloud in Archive list, with all the tags of the gallery.", 'zpBootstrap')),
gettext('Exif') => array('order' => 16, 'key' => 'zpB_show_exif', 'type' => OPTION_TYPE_CHECKBOX, 'desc' => gettext_th("Show the EXIF Data on Image page. Remember you have to check EXIFs data you want to show on options>image>information EXIF.", 'zpBootstrap'))


  • You are using an OR operation where you really want an AND operation. If you use `if (!is_object($album) || !$album->exists) {` PHP will evaluate both expressions and the second will fail.

    You want `if (!is_object($album) && !$album->exists) {`

    You probably were tired:)
  • thanks Stephen.
    but no, it doesn't solve the issue
    if I use your code, I have this error in my deggug log:

    {712604:Mon, 24 Jul 2017 16:07:01 GMT} Zenphoto v1.4.14[f5b47da52feacae4e5e081b977e60ee0b2fe1bc5]
    USER ERROR: Invalid album instantiation: images/images-home-page.a does not exist. in /home/avbo7291/public_html/zenphoto_test/zp-core/class-album.php on line 1221
    trigger_error called from Album->_albumCheck (class-album.php [1221])
    from Album->__construct (class-album.php [1192])
    from newAlbum (class-album.php [25])
    from ThemeOptions->getOptionsSupported (themeoptions.php [57])
    from admin-options.php [2518]
  • I found a way by using quiet mode of album contruct

    $album = newAlbum($zpB_homepage_album_filename, false, true);
    if (!is_object($album) || !$album->exists) {
    $msg = '

    ' . gettext('You need to provide a valid album filename.') . '

    it seems to be enougth for my basic tests in admin theme options.
  • acrylian Administrator
    That parameter set to false would be the right way. You could alternatively provide a dropdown selector option of actually existing albums to choose from. That would be the best usability wise. However the check is still neeeded in case albums are removed later or renamed etc so the selected does not work anymore.
Sign In or Register to comment.