Hi everyone, Im developing a theme and require a function to be run just once when the theme is activated (and possibly another function to be run once when the theme is deactivated (but this is less important)).
Im basically trying to shift some image files from the theme's images directory to the site's file system when the theme is activated. Is it possible to have a function in the themes template.php that is only trigged on activation/deactivation??
The only solution I can think of for now is using some preprocess function that checks the file system to see if my directory exists, if it returns false, it then copies my images over. Does anyone know of a better way to achieve this?
Thanks
Comments
solved
Well it looks like I was perhaps too hasty with my post. I have solved my problem already.
In the case it benefits others ill quickly explain my issue and solution. I was trying to set the default user image with my theme, I thought the only way to do this was to use a function to copy the image from my theme directory to the site's file system, and then set the variable for the default user image path. Then I stumbled on the theme_preprocess_user_picture(&$variables) function that can easily solve this problem. The following code (which is from the D7 version of the nitobe theme) was a excellent guideline for me.
/**
* Preprocesses the user picture.
*
* If no default user picture is provided, and pictures are enabled, use the
* theme's default user picture.
*
* @param array &$variables
* The template arguments.
*/
function nitobe_preprocess_user_picture(&$variables) {
$account = $variables["account"];
if (empty($variables["user_picture"]) && (variable_get("user_pictures", 0) != 0)) {
$picture = nitobe_theme_path() . "/images/user-icon.jpg";
$name = $account->name ? $account->name :
variable_get("anonymous", t("Anonymous"));
$alt = t("@user's picture", array('@user' => $name));
$variables["user_picture"] =
theme("image", array("path" => $picture, "alt" => $alt, "title" => $alt));
// -- Link the picture if allowed.
if (!empty($account->uid) && user_access("access user profiles")) {
$attributes = array(
"attributes" => array(
"title" => t("View user profile."),
),
"html" => TRUE
);
$variables["user_picture"] =
l($variables["user_picture"], "user/{$account->uid}", $attributes);
}
}
}
I am not sure why you need
I am not sure why you need such custom code while Drupal already support a custom default user picture at account settings page: admin/config/people/accounts. So that extra code is just extra, IMHO.
love, light n laughter