0

If I add the following:

      function MYTHEME_preprocess_user_picture(&$variables) { 
      $variables['user_picture'] = theme('image_style', array('style_name' => 'thumbnail_scale_n_crop_120_x_120', 'path' => $filepath, 'alt' => $alt, 'title' => $alt));
}

to my comment.tpl.php (the purpose of which is to use an image style on the comment author's picture,) I get a WSOD with the following message:

Fatal error: Cannot redeclare MYTHEME_preprocess_user_picture() (previously declared in /home3/zc1/public_html/sites/all/themes/mytheme/comment.tpl.php:8) in /home3/zc1/public_html/sites/all/themes/mytheme/comment.tpl.php on line 12

Now, I know this error normally indicates a duplicate of the function. But in this case it seems to indicate that the duplication is in the same comment.tpl.php file. And I can't see it.

Here is the file, with the added code included:

<?php ?>
<div class="<?php print $classes . ' ' . $zebra; ?>"<?php print $attributes; ?>>

<?php
  function MYTHEME_preprocess_user_picture(&$variables) { 
$variables['user_picture'] = theme('image_style', array('style_name' => 'thumbnail_scale_n_crop_120_x_120', 'path' => $filepath, 'alt' => $alt, 'title' => $alt));
} ?>
<?php print $picture ?> 
<span class="submitted"><?php print $submitted ?></span>
   <span class="signature">
  <?php print $signature ?>
</span>
<div class="content"<?php print $content_attributes; ?>>
<?php if ($new): ?>
  <span class="new"><?php print drupal_ucfirst($new) ?></span>
<?php endif; ?>
    <?php hide($content['links']); print render($content); ?>
<?php if ($signature): ?>
<?php endif; ?>
  </div>

<?php print render($content['links']) ?>
</div>

Any idea what's going on?

This is Drupal 7 and I use Bartik.

Any and all help is greatly appreciated. Thank you. :)

1

First of all you cannot write preprocess functions inside tpl.php.. It should go into your active theme template.php file.. Please see using preprocess functions in D.O.

Fatal error clearly says you have redclared same function twice."Cannot redeclare MYTHEME_preprocess_user_picture()" . Search for "MYTHEME_preprocess_user_picture" in your entire Drupal codebase and make sure you remove both of them since you need to rename "MYTHEME" to your active theme name. In your case it should be "bartik". So your function should be..

function bartik_preprocess_user_picture(&$variables) { 
      $variables['user_picture'] = theme('image_style', array('style_name' => 'thumbnail_scale_n_crop_120_x_120', 'path' => $filepath, 'alt' => $alt, 'title' => $alt));
}

Above code should go into the theme template.php file.. To see the changes you need to clear cache by navigating to "admin/config/development/performance" or using drush command

drush cc
1

Change function signature with 'function bartik_preprocess_user_picture(&$variables)' and put this function in template.php. Don't forget to clear the cache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.