Skip to content

Instantly share code, notes, and snippets.

View himanshuahuja96's full-sized avatar
💭
Sitecore and WordPress Ninja

himanshuahuja96

💭
Sitecore and WordPress Ninja
View GitHub Profile
@himanshuahuja96
himanshuahuja96 / redirect-new-domain-301.php
Created December 13, 2020 17:13
WordPress Redirect to New domain from old using php
<?php
function redirect_to_new_domain(){
if( (strpos($_SERVER['HTTP_HOST'], 'domain.com') !== false) || (strpos($_SERVER['HTTP_HOST'],'www.domain.com')!== false) ){
wp_redirect( 'https://www.new-domain.com'.$_SERVER['REQUEST_URI'] , 301);
exit;
}
}
add_action("init","redirect_to_new_domain");
<?php
//github plugin url: https://github.com/hissy/rs-csv-importer
//wp plugin directory url: http://wordpress.org/plugins/really-simple-csv-importer/
//add to your functions.php in current child theme or create a child theme using any plugin/website
function really_simple_csv_importer_save_meta_filter( $meta, $post, $is_update ) {
if( isset($meta['header_image']) ){
include_once( ABSPATH . 'wp-admin/includes/image.php' );
@himanshuahuja96
himanshuahuja96 / wordpress_override_password_form.php
Created March 19, 2020 13:41 — forked from dmjarvis/wordpress_override_password_form.php
How to override the default WordPress page or post protection form (pre WP 3.4)
<?php
function my_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form class="protected-post-form" action="' . get_option( 'siteurl' ) . '/wp-pass.php" method="post">
' . __( "To view this protected post, enter the password below:" ) . '
<label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
</form>
';
return $o;
@himanshuahuja96
himanshuahuja96 / mepr-active-memberships.php
Created March 11, 2020 08:39 — forked from andrija-naglic/mepr-active-memberships.php
Get a list of the current user's active MemberPress Subscriptions
<?php
function memberpress__get_all_memberships( $user_id = false ){
if( class_exists('MeprUser') ){
if( ! $user_id ){
$user_id = get_current_user_id();
}
/**
* Returns a user meta value
* Usage [um_user user_id="" meta_key="" ] // leave user_id empty if you want to retrive the current user's meta value.
* meta_key is the field name that you've set in the UM form builder
* You can modify the return meta_value with filter hook 'um_user_shortcode_filter__{$meta_key}'
*/
function um_user_shortcode( $atts ) {
$atts = extract( shortcode_atts( array(
'user_id' => get_current_user_id(),
'meta_key' => '',
@himanshuahuja96
himanshuahuja96 / woo-checkout.php
Created February 13, 2020 12:45 — forked from Bobz-zg/woo-checkout.php
Pre-populate Woocommerce checkout fields
<?php
/**
* Pre-populate Woocommerce checkout fields
* Note that this filter populates shipping_ and billing_ fields with a different meta field eg 'first_name'
*/
add_filter('woocommerce_checkout_get_value', function($input, $key ) {
global $current_user;
switch ($key) :
@himanshuahuja96
himanshuahuja96 / remove-image-title-attribute.js
Created October 29, 2019 08:18
remove image title attribute on hover
$( document ).ready(function() {
$("classNameOrID").hover(function(){
// Get the current title
var title = $(this).attr("title");
// Store it in a temporary attribute
$(this).attr("tmp_title", title);
// Set the title to nothing so we don't see the tooltips
@himanshuahuja96
himanshuahuja96 / fixfatal-godaddy-wp-managed.php
Created September 22, 2019 17:36
Fixes Godaddy fatal error caused in WordPress Managed Hosting (gd-system-plugin error if wrong password is entered)
<?php
/**
* Plugin Name: Godaddy Login error on Wrong Password
* Version: 0.1
* Plugin URI: https://www.fiverr.com/wppluginexpert
* Description: TO FIX THE GODADDAYBUG
* Author: WPPLUGINEXPERT
* Author URI: https://www.fiverr.com/wppluginexpert
* Requires at least: 4.0
* Tested up to: 5.2.3
@himanshuahuja96
himanshuahuja96 / functions.php
Created September 22, 2019 17:15 — forked from tripflex/functions.php
WordPress Remove Filter (remove_filter converted to remove_class_filter) to remove Filter/Action without Class Object access. Works with WordPress 1.2+ (4.7+ support added 9-19-2016)
<?php
/**
* Make sure the function does not exist before defining it
*/
if( ! function_exists( 'remove_class_filter' ) ){
/**
* Remove Class Filter Without Access to Class Object
*
* In order to use the core WordPress remove_filter() on a filter added with the callback
@himanshuahuja96
himanshuahuja96 / theme-my-login-filter-error.php
Last active August 17, 2019 11:16
Theme my login custom error message filter
function myfunctiontoaddmailme($errors){
$withoutLostPassword = '';
if( $errors === '<strong>ERROR</strong>: Invalid username. <a href="https://nicolethemathlady.com/my-account/lost-password/">Lost your password?</a>' ){
$withoutLostPassword = '<strong>ERROR</strong>: Not Sure about the Username?, Then <a href="mailto:[email protected]?subject=Account Issue">Mail Me!</a> ';
$errors = $withoutLostPassword;
}
else if( $errors === '<strong>ERROR</strong>: Invalid email address. <a href="https://nicolethemathlady.com/my-account/lost-password/">Lost your password?</a>' ){
$withoutLostPassword = '<strong>ERROR</strong>: Not Sure about the Email?, Then <a href="mailto:[email protected]?subject=Account Issue">Mail Me!</a> ';
$errors = $withoutLostPassword;
}