Skip to content

Instantly share code, notes, and snippets.

View eguicciardi's full-sized avatar

Emanuele Guicciardi eguicciardi

View GitHub Profile
@eguicciardi
eguicciardi / drupal_7_password
Created June 11, 2013 08:04
Drupal 7 - New password generation
<?php
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once 'includes/password.inc';
echo user_hash_password('givenpassword');
die();
@eguicciardi
eguicciardi / htaccess_redirection
Created November 8, 2013 15:25
Drupal 7 .htaccess 301 Redirection example
RewriteRule ^NEW_PATH$ OLD_URL [R=301,L]
@eguicciardi
eguicciardi / hello_world_dom_ready.js
Last active December 30, 2015 03:09
Hello World DOM Ready
jQuery(document).ready(function($){
alert("Hello World!");
});
@eguicciardi
eguicciardi / beahavior_1.js
Last active December 30, 2015 03:19
Drupal 7.x behaviors snippet
Drupal.behaviors.NomeModuloCustom = {
attach: function (context, settings) {
$('h1').addClass('.titolone');
}
}
Drupal.behaviors.makeMeSmelly = {
attach: function (context, settings) {
// Questo codice viene eseguito solo una volta
context.once(function() {
$('h1', this).addClass('.titolone');
}
// Questo invece viene eseguito ad ogni richiesta
$('h1').addClass('.titoloneone');
}
@eguicciardi
eguicciardi / drupal_js.js
Created December 24, 2013 14:07
drupal_add_js()
drupal_add_js(array('myModule' => array('key' => 'value')), 'setting');
@eguicciardi
eguicciardi / ajaurl.js
Created March 25, 2014 13:33
Wordpress AjaxURL
<script type="text/javascript">
var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
</script>
@eguicciardi
eguicciardi / d7_password_reset.php
Last active February 22, 2017 21:46
Function to reset a user's password
<?php
function password_reset(){
global $user;
$hashthepass = 'password'; /* Your password value*/
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$hashthepass = user_hash_password(trim($hashthepass));
if (!$hashthepass) {
@eguicciardi
eguicciardi / drupal_batch_drush_example.php
Last active November 2, 2020 02:17
Drupal 7.x Batch API example tied with a Drush command
<?php
function mymodule_setup_batch($start=1, $stop=100000) {
$dataset = array(); // A very large dataset
$chunks = array_chunk($dataset, 20); // Divide the dataset
$operations = array();
$count_chunks = count($chunks);
$i = 1;
@eguicciardi
eguicciardi / wpm_get_post.php
Created April 18, 2019 15:03
Wordpress + WPML + get_posts() get by current language or force language
/* Example args for get_posts() */
$query_args = array(
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'publish',
'suppress_filters' => false
);