Richard Castera - Explorations in Software Development
Richard Castera - Explorations in Software Development
Browsing Category
Resources
Resources Scripts

Drupal – Check if a User has a specific role

March 4, 2010 1 Comment

Here is a quick way to determine if a user has a specific role:

PHP
1
2
3
4
5
6
7
8
<?php
  // Bring the user object into scope.
  global $user;
  // Check to see if $user has the administrator user role.
  if (in_array('administrator', array_values($user->roles))) {
    // Do something.
  }
?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Drupal – Adding Javascript to your module

March 3, 2010 1 Comment

When creating your own Drupal module, you may need to add some styling or Javascript to improve the usability of your module. Here is how to do it.

PHP
1
drupal_add_js(drupal_get_path('module', 'MODULE_NAME') . '/common.js');

Similarly you can add CSS to your module as well

PHP
1
drupal_add_css(drupal_get_path('module', 'MODULE_NAME') . '/styles.css');
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Drupal – Use hook_form_alter() to set redirect path on the form

March 2, 2010 2 Comments

One popular use of this hook is to change the destination of a form submission. Here is how it is accomplished:

PHP
1
2
3
4
5
6
7
8
9
10
11
<?php
function YOURMODULE_form_alter($form_id, &$form) {
  switch ($form['#id']) {
    case 'node-form':
       if ($form['type']['#value'] == 'story') {
         $form['#redirect'] = 'new/url';
       }
     break;
  }
}
?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Excellent Analytics – Import Google Analytics into Excel

March 1, 2010 2 Comments

I ran into this nice Excel Plugin that lets you import web analytics data from Google Analytics into a spreadsheet. It’s an open source project and 100% free to download and use for individuals and businesses.

Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

WordPress – List Scheduled Posts

February 28, 2010 2 Comments

If you ever wanted to show you readers posts that are scheduled to be published, here’s how to do it.

PHP
1
2
3
4
5
6
7
8
<?php
$result = new WP_Query('post_status=future&order=DESC&showposts=5');
if ($result->have_posts()) {
    while ($result->have_posts()) : $result->the_post(); ?>
        <?php the_title(); ?>
    <?php endwhile;
}
?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

CSS – Cross Browser Opacity

February 27, 2010 1 Comment

A little hack to set Cross-Browser opacity.

CSS
1
2
3
4
5
6
7
.setOpacity {
      opacity: .75; /* Standard: FF gt 1.5, Opera, Safari */
      filter: alpha(opacity=75); /* IE lt 8 */
      -ms-filter: "alpha(opacity=75)"; /* IE 8 */
      -khtml-opacity: .75; /* Safari 1.x */
      -moz-opacity: .75; /* FF lt 1.5, Netscape */
}
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

WordPress – Disable Auto Save

February 24, 2010 1 Comment

WordPress’s Auto-Save feature is a really nice but there are some drawbacks… this feature increases your database usage. So for those of you that are on really bad shared hosting accounts or just want to turn it off, here’s a quick way of doing it.

Open and insert the following line in your wp-config.php file.

PHP
1
define('WP_POST_REVISIONS', false);

Another method is to remove all of the entries from the database from time to time. You can do tun this query to do it:

PHP
1
DELETE FROM wp_posts WHERE post_type = "revision";
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Prototype JS – Determine if an object exists in the page loaded

February 23, 2010 No Comments

I’m so use to using jQuery that I usually don’t have to look up documentation on how to use certain functions. They almost come naturally because it’s so English-like! Unfortunately Magento uses Prototype as it’s native choice of Javascript Frameworks. I sure wish they would have chosenjQuery! I think they would have more people jumping on their platform. I’m sure they have a good choice for it. Anyway, here’s how to check:

JavaScript
1
2
3
if ($('id_of_element') != undefined) {
    alert('Object exists.');
}
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Magento – Check if a User is logged in

February 23, 2010 6 Comments

You may want to check if a user is logged in with Magento, possibly to display a link or promotional item. Here’s how to do it:

PHP
1
2
3
4
5
6
7
8
<?php
if ($this->helper('customer')->isLoggedIn()) {
    echo("Anonymous user");
}
else {
    echo("Authenticated user");
}
?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Magento – How to Display the Product SKU

February 23, 2010 4 Comments

Magento is a pretty flexible platform. That flexibility comes with a price though; You have to be knowledgeable of the functions that are available to you to utilize. Finding or knowing them is a challenge though. Here is one of those such functions that you may need to display the product Sku on a category page.

PHP
1
<?php echo($_product->getSku()); ?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Page 2 of 9«1234»...Last »

About me

Hello, my name is Richard Castera. I have more than 12 years of experience architecting, implementing, leading and launching large scale, high performance software products in a fast-paced agile environment.

Popular Posts

Magento – Display new products on the home page

May 20, 2009

How to Fix “Internet Explorer Cannot Open the Internet Site- Operation Aborted” Error

May 9, 2009

PHP – Convert Array to Object with stdClass

July 5, 2009

Categories

  • Home Automation
  • Resources
  • Scripts
  • SEO
  • Thoughts
  • Web Server

Tags

Apache Apple Bash CSS Drupal Free home automation htaccess Java Javascript Magento PHP raspberry pi SEO SQL thoughts Wordpress

© 2019 copyright Richard Castera // All rights reserved