Skip to content

Instantly share code, notes, and snippets.

View MatthieuScarset's full-sized avatar
🤷‍♂️
Probably me

MattGyver MatthieuScarset

🤷‍♂️
Probably me
View GitHub Profile
@MatthieuScarset
MatthieuScarset / gist:162735b0796e82159e8f
Created July 16, 2015 07:35
Drupal - Select and update all users by role
<?php
// Select and update user by role
$role = user_role_load_by_name('blogger');
$query = 'SELECT ur.uid FROM {users_roles} AS ur WHERE ur.rid = :rid';
$result = db_query($query, array(':rid' => $role->rid));
$uids = $result->fetchCol();
$users = user_load_multiple($uids);
foreach($users as $user) {
// $user->field_to_update['und'][0]['value'] = 1;
// user_save($user);
@MatthieuScarset
MatthieuScarset / gist:7cbdab8b99c84451c858
Last active August 29, 2015 14:26
Drupal - Export $field and $instance
// Export fields and their instances
// for Drupal module development
// @see http://steindom.com/articles/exporting-and-creating-field-definitions-drupal-7
$entity_type = 'node';
$field_name = 'field_gallery_user_lname';
$bundle_name = 'gallery';
$info_config = field_info_field($field_name);
$info_instance = field_info_instance($entity_type, $field_name, $bundle_name);
$order_id = 8442; // change this to your order_id value
$order = commerce_order_load($order_id);
$shipping_profile_id = $order->commerce_customer_shipping[LANGUAGE_NONE][0]['profile_id'];
$address_shipping_profile = commerce_customer_profile_load($shipping_profile_id);
$as = $address_shipping_profile->commerce_customer_address['und'][0];
$billing_profile_id = $order->commerce_customer_billing[LANGUAGE_NONE][0]['profile_id'];
$address_billing_profile = commerce_customer_profile_load($billing_profile_id);
$ab = $address_billing_profile->commerce_customer_address['und'][0];
@MatthieuScarset
MatthieuScarset / gist:4709ec3bee691c1c7707
Created November 12, 2015 14:45
Load all Drupal Commerce License
$q = db_select('commerce_license', 'l');
// $q->condition('l.type', your_type');
// $q->condition('l.status', 2); // 2 = active
$q->fields('l', array('license_id') );
$lids = $q->execute()->fetchCol();
$ls = entity_load('commerce_license', $lids);
dpm($ls);
foreach($ls as $l){
$info = $l->wrapper->getPropertyInfo();
@MatthieuScarset
MatthieuScarset / gist:831d77bedc6338e66d00
Created December 16, 2015 16:54
make an element clickable
// How to use?
makeClick($('.clickable')); //Make things clickable
/*
* Make an HTML element clickable
* Usefull for a fully clickable div without to wrap it in a <a>
* @param $el jQuery DOM object(s)
* return void
*/
function makeClick($el) {
@MatthieuScarset
MatthieuScarset / encode_file64
Last active February 15, 2016 08:05
PHP - encode_file64
<?php
// Encode a file to base64
function encode_file64($path, $print = false) {
$file = file_get_contents($path);
$e = base64_encode($file);
if( $print )
print ($e);
return $e;
}
@MatthieuScarset
MatthieuScarset / error.module
Created February 25, 2016 10:37
Drupal - Go to error page
/*
* Redirect to error page
* @param $site string Wether is for mobile or desktop site
* @param $err_code int Error code
* @param $path bool|string Force a path for redirection
* @see http://www.kobashicomputing.com/creating-custom-drupal-6-error-pages
* @return header()
*/
function _goto_error_page($site = 'mobile', $err_code = 404, $path = false) {
$variable_name = ($site == 'mobile') ? "site_mobile_$err_code" : "site_$err_code";
@MatthieuScarset
MatthieuScarset / JS - Get header
Created March 15, 2016 09:12
Get current page's header in Javascript
var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
req.getResponseHeader('Date');
@MatthieuScarset
MatthieuScarset / WP - Plugin Dev - Show errors after activation
Last active June 19, 2016 08:13
WordPress - Show plugin activation errors
function show_activation_error() {
update_option( 'plugin_error', ob_get_contents() );
$error = get_option( 'plugin_error' );
wp_die($error);
}
add_action( 'activated_plugin', 'show_activation_error' );
{
"name": "drupal/drupal",
"description": "Drupal is an open source content management platform powering millions of websites and applications.",
"type": "project",
"license": "GPL-2.0+",
"require": {
"composer/installers": "^1.0.21",
"wikimedia/composer-merge-plugin": "~1.3",
"drupal/field_collection": "^8",
"drupal/panels":"^8",