Skip to content

Instantly share code, notes, and snippets.

View mohsinrasool's full-sized avatar
💪

Mohsin Rasool mohsinrasool

💪
View GitHub Profile
@mohsinrasool
mohsinrasool / VCF attachment in Contact Form 7
Created May 8, 2017 16:21
VCF attachment in Contact Form 7
/**
* Generate VCF from form's data and send as attachment for admin, in Contact Form 7
*
*/
add_action('wpcf7_before_send_mail', 'wpcf7_add_attachment');
function wpcf7_add_attachment($contact_form) {
global $_POST;
$submission = WPCF7_Submission::get_instance();
$vcf_dir = WP_CONTENT_DIR.'/uploads/2017/04/';
@mohsinrasool
mohsinrasool / month-directive.js
Created July 9, 2015 12:40
An AngularJS directive to generate dropdown of months
/**
* Usage <year-select range=10 offset=0 />
*
*
*/
app.directive('monthSelect',function(){
return {
@mohsinrasool
mohsinrasool / wp-fix-cloudflare-ssl.php
Created March 20, 2018 17:27
WordPress Fix for soft SSL provided by Cloudflare
<?php
/**
* Add following snippet in functions.php of your active theme. it should fix both admin and frontend.
*/
function ms_admin_head() {
echo '<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">';
}
add_action( 'admin_print_styles', 'ms_admin_head', 1 );
add_action( 'wp_head', 'ms_admin_head', 1 );
@mohsinrasool
mohsinrasool / meticulous-product-categories-widget.php
Last active January 12, 2018 09:42
This plugin adds a woocommerce product category widget. Requires WooCommerce
<?php
/**
* Plugin Name: Meticulous Product Categories Widget
* Description: This plugin adds a woocommerce product category widget. Requires WooCommerce
* Version: 1.0
* Author: Meticulous Solutions
* Author URI: http://MeticulouSolutions.com
* License: GPL2
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
@mohsinrasool
mohsinrasool / patch.php
Created December 20, 2017 18:32
Fixing get_country() on null for woocommerce-gateways-country-limiter by WPML
// Change filter_country function to following
function filter_by_country($payment_gateways){
$woocommerce = function_exists('WC') ? WC() : $GLOBALS['woocommerce'];
if($woocommerce == null || $woocommerce->customer == null )
return $payment_gateways;
$customer_country = $woocommerce->customer->get_country();
@mohsinrasool
mohsinrasool / ftp-delete-files.php
Created February 4, 2015 15:27
This script deletes all the provided files from FTP server. It helps when server is being compromised and several malicious files has been detected. It happend to one of my hosting on iPage
<?php
/**
* This script deletes all the provided files from FTP server.
*
* Application: This script helps when server is being compromised and several malicious files has detected. Some common spams are
*
* HG.PHP.Shell.25968.UNOFFICIAL
* JCDEF.Obfus.CreateFunc.BackDoorEval-23
* JCDEF.Obfus.CreateFunc.BackDoorEval-26
* JCDEF.Obfus.CreateFunc.BackDoorEval-21
@mohsinrasool
mohsinrasool / gravity_form_gtm_tracking.php
Created October 18, 2015 19:32
To track the submission of gravity forms and generate an event through Google Tag Manager, you can utilize the following code, It adds the onclick event to the submit button of the gravity form. So, whenever the submit button is clicked an event is sent to Google Server. You need to do two things to use this code
function add_conversion_tracking_code($button, $form) {
$dom = new DOMDocument();
$dom->loadHTML($button);
$input = $dom->getElementsByTagName('input')->item(0);
if ($input->hasAttribute('onclick')) {
$input->setAttribute("onclick","ga('send', 'event', { eventCategory: 'GTM_Category', eventAction: 'GTM_Action', eventLabel: 'GTM_Label'});".$input->getAttribute("onclick"));
} else {
$input->setAttribute("onclick","ga('send', 'event', { eventCategory: 'GTM_Category', eventAction: 'GTM_Action', eventLabel: 'GTM_Label'});");
}
return $dom->saveHtml();
@mohsinrasool
mohsinrasool / wp-upme-sync-user-meta-fields.php
Created July 29, 2016 12:08
Map WordPress user meta fields to UPME meta fields
<?php
$wp_user_query = new WP_User_Query( array( 'role' => 'Subscriber', 'fields' => 'all') );
$authors = $wp_user_query->get_results();
if (!empty($authors)) {
echo '<ul>';
$fields = array(
'Membership Category' => 'custom_field_1',
@mohsinrasool
mohsinrasool / shortcode_weather_forecast.php
Created June 29, 2016 15:04
WordPress shortcode to fetch and display weather forecast
function weather_forecast_func( $atts ) {
$atts = shortcode_atts( array(
'city' => 'Kingston, ON'
), $atts );
// delete_transient( 'weather_forecast' );
if ( false === ( $weather_forecast = get_transient( 'weather_forecast' ) ) ) {
// $weather_forecast_raw = get_transient( 'weather_forecast_raw' );
@mohsinrasool
mohsinrasool / fix-divi-slider-double-load.css
Last active June 23, 2016 18:36
Issue: Fix double animation of Divi slider
.et_pb_slides .et_pb_slide:first-child .et_pb_slide_description {
display:none;
}