Skip to content

Instantly share code, notes, and snippets.

@vishalbasnet23
vishalbasnet23 / functions.php
Created October 31, 2014 08:57
User Registration Front End WordPress with Ajax
<?php
add_action('wp_ajax_register_user_front_end', 'register_user_front_end', 0);
add_action('wp_ajax_nopriv_register_user_front_end', 'register_user_front_end');
function register_user_front_end() {
$new_user_name = stripcslashes($_POST['new_user_name']);
$new_user_email = stripcslashes($_POST['new_user_email']);
$new_user_password = $_POST['new_user_password'];
$user_nice_name = strtolower($_POST['new_user_email']);
$user_data = array(
'user_login' => $new_user_name,
#!/bin/bash
sudo apt-get install -y devilspie
mkdir -p ~/.devilspie
echo '
(if (contains (window_class) "Code")
(begin
(spawn_async (str "xprop -id " (window_xid) " -f _KDE_NET_WM_BLUR_BEHIND_REGION 32c -set _KDE_NET_WM_BLUR_BEHIND_REGION 0 "))
(spawn_async (str "xprop -id " (window_xid) " -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY 0xD8000000"))
@vishalbasnet23
vishalbasnet23 / Readme.txt
Created December 15, 2014 11:20
Custom Activation Link on Sign Up WordPress
Step by step guide.
First Phase:
1.First create a html form with first name, last name and email field for signing up process.( Remember the action of the form it has to be the page slug of email confirmation page that you will be creating at in next phase. )
Second Phase :
1.Create a Page ( Remember the slug has to be the same of that of action of the form of phase one ) and assign the template template-confirmation-mail.php
2.This page is responsible for generating unqiue hash key and sending that hash key along with the user's new account credentials to their email.
3.Remember the link of the activation_link has to the link to the email-verification template, which we will be creating in next phase.
Third Phase :
1. Create a page and assign it to Email Verification Template.( Remember this template has to be assigned to the page that you sent in the mail in previous step )
2. This page is responsilble matching that unqiue key sent on the email once new user visit that page.
@vishalbasnet23
vishalbasnet23 / functions.php
Created October 31, 2014 09:16
User Login form Front End WordPress
<?php function login_form_frontend($args = array()) {
$defaults = array('echo' => true,
'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // Default redirect is back to the current page
'form_id' => 'loginformfrontend',
'label_username' => __('Username'),
'label_password' => __('Password'),
'label_remember' => __('Remember Me'),
'label_log_in' => __('SIGN IN'),
'id_username' => 'user_login',
'id_password' => 'user_pass',
@vishalbasnet23
vishalbasnet23 / functions.php
Created February 19, 2015 06:18
Simple Post View Counter WordPress
<?php
/**
* Post view Count
*/
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
function wpb_set_post_views($postID) {
$count_key = 'wpb_post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
@vishalbasnet23
vishalbasnet23 / functions.php
Last active December 2, 2021 17:39
Append async to wp_enqueue_script
<?php
function advanced_asyc_scripts($url) {
if ( strpos( $url, '#asyncload') === false ) {
return $url;
} else if ( is_admin() ) {
return str_replace( '#asyncload', '', $url );
} else {
return str_replace( '#asyncload', '', $url )."' async='async' defer='defer";
}
}
@vishalbasnet23
vishalbasnet23 / readme.md
Created April 21, 2016 12:02 — forked from hitautodestruct/readme.md
Generate a custom structure for Wordpress menus.

This gist is for showing an example of a custom wordpress menu.

If you want to get more from the menu item simply have a look at the $item object. i.e:

// Will return a large object with lots of props like title, url, description, id etc.
var_dump( $item );

This code works on Wordpress 4.1.1 as of 31st of March 2015

@vishalbasnet23
vishalbasnet23 / functions.php
Created June 28, 2016 07:51
Create WooCommerce Subscription and activate Subscription for a user programatically.
<?php
function cpm_create_order($customer_data, $the_customer) {
global $woocommerce;
$product_id = $customer_data['sub_product'];
$variation_id = $customer_data['sub_variation'];
$user_first_name = $customer_data['first_name'];
$user_last_name = $customer_data['last_name'];
$user_email = $customer_data['user_email'];
$billing_email = $customer_data['user_email'];
$billing_state = $customer_data['cpm_state'];
@vishalbasnet23
vishalbasnet23 / functions.php
Created June 19, 2017 03:17
Add filter by name to WP REST Posts End Point.
<?php
add_action( 'rest_api_init', 'rest_api_filter_add_filters' );
/**
* Add the necessary filter to each post type
**/
function rest_api_filter_add_filters() {
foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
add_filter( 'rest_' . $post_type->name . '_query', 'rest_api_filter_add_filter_param', 10, 2 );
}
}
@vishalbasnet23
vishalbasnet23 / OAuth.php
Created December 16, 2014 10:47
Twitter Feed By Hashtag with PHP
<?php
// vim: foldmethod=marker
/* Generic exception class
*/
if (!class_exists('OAuthException')) {
class OAuthException extends Exception {
// pass
}
}