Skip to content

Instantly share code, notes, and snippets.

View yehudah's full-sized avatar

Yehuda Hassine yehudah

View GitHub Profile
@yehudah
yehudah / gist:a9bbc24808656ac59d6f8a3e281137c5
Created February 15, 2018 09:38
Fix Composer message: do not match its signature. This should indicate a man-in-the-middle attack
If you see this message when you run composer command:
do not match its signature. This should indicate a man-in-the-middle attack. Try running composer again and report this if you think it is a mistake.
From the command line run:
composer config --global repo.packagist composer https://packagist.org
@yehudah
yehudah / replace_to_embedded
Created August 9, 2017 07:45
Replace mail content images to embedded in WordPress
<?php
add_action( 'phpmailer_init', 'replace_to_embedded' );
function replace_to_embedded( $phpmailer ) {
$content = replace_img_src( $phpmailer->Body );
foreach ( $content['images'] as $image_url ) {
$path = parse_url( $image_url, PHP_URL_PATH );
$image_path = ABSPATH . $path;
$phpmailer->AddEmbeddedImage( $image_path, basename( $image_url ) );
@yehudah
yehudah / remove-password-enforce.php
Created February 26, 2017 19:34
Remove password enforce from password reset page after register
<?php
/*
Plugin Name: Remove Pass enforce
Version: 1.0
Author: Yehuda Hassine
License: GPL2
*/
add_action('login_enqueue_scripts', 'remove_pass_enforce', 11 );
function remove_pass_enforce() {
@yehudah
yehudah / dynamic-fb-og-image.php
Created March 20, 2016 10:55
Allow you to choose an image for facebook og.
<?php
/*
Plugin Name: Dynamic Facebook og image
Description: Allow you to choose an image for facebook og.
Author: Yehuda Hassine
Version: 1.0
*/
add_action('add_meta_boxes', 'fb_og_image_mb');
function fb_og_image_mb() {
@yehudah
yehudah / acf-get-field-key.php
Created December 10, 2015 09:12 — forked from mcguffin/acf-get-field-key.php
WordPress Advanced Custom Fields get field key from field name
<?php
/**
* Get field key for field name.
* Will return first matched acf field key for a give field name.
*
* ACF somehow requires a field key, where a sane developer would prefer a human readable field name.
* http://www.advancedcustomfields.com/resources/update_field/#field_key-vs%20field_name
*
* This function will return the field_key of a certain field.
@yehudah
yehudah / change-admin-lang-wpml
Last active August 29, 2015 14:23
Change admin language with wpml "fix"
<?php
global $pagenow;
if ( isset( $_GET['lang'] ) && is_admin() && $pagenow != 'post.php' ) {
$user_id = wp_get_current_user()->ID;
$lang = filter_var( $_GET['lang'], FILTER_SANITIZE_STRING );
update_user_meta( $user_id,'icl_admin_language', $lang );
$url = "http" . (($_SERVER['SERVER_PORT'] == 443) ? "s://" : "://") . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$redirect = esc_url( remove_query_arg( 'lang', $url ) );
@yehudah
yehudah / wp-get-remote-image
Created May 29, 2015 12:28
Add Wordpress Featured Image From A URL
function get_main_image( $image_url, $post_id ) {
$upload_dir = wp_upload_dir(); // Set upload folder
$image_data = file_get_contents($image_url); // Get image data
$filename = basename($image_url); // Create image file name
// Check folder permission and define file location
if( wp_mkdir_p( $upload_dir['path'] ) ) {
$file = $upload_dir['path'] . '/' . $filename;
/**
* Add the field to order emails
**/
add_filter('woocommerce_email_order_meta_keys', 'my_custom_checkout_field_order_meta_keys');
function my_custom_checkout_field_order_meta_keys( $keys ) {
$keys[‘My Field 1′] = ‘_my_field_1;
$keys[‘My Field 2′] = ‘_my_field_2′;
return $keys;
}
@yehudah
yehudah / select2-fix-jqueryui-dialog
Created May 3, 2015 09:49
fix select2 plugin inside jquery ui dialog
dialog = $( "#dialog-form" ).dialog({
autoOpen: true,
height: 300,
width: 450,
modal: true,
open: function () {
if ($.ui && $.ui.dialog && $.ui.dialog.prototype._allowInteraction) {
var ui_dialog_interaction = $.ui.dialog.prototype._allowInteraction;
$.ui.dialog.prototype._allowInteraction = function(e) {
if ($(e.target).closest('.select2-dropdown').length) return true;
@yehudah
yehudah / wp-words-to-tags
Created April 13, 2015 13:17
Hyperlink words matching your wordpress site tags, in your posts content.
<?php
/*
Plugin Name: Post Words To Tags.
Description: Hyperlink words matching your site tags in your posts content.
Author: Yehuda Hassine
Author URI: http://wpdevops.co.il
Version: 1.0
License: GPL2
*/