Skip to content

Instantly share code, notes, and snippets.

@junaidtk
junaidtk / Add admin user through code
Created November 13, 2018 17:55
How to add new admin user through the code snipppets
We can add new admin user by using below code. it will be helpfull if we forget the admin details of the website.
add_action('init', 'add_new_admin_user');
function add_new_admin_user() {
$username = 'testuser';
$email = '[email protected]';
$password = 'password';
$user_id = username_exists( $username );
if ( !$user_id && email_exists($email) == false ) {
@junaidtk
junaidtk / Form Tips
Created November 29, 2018 07:40
Form Handling
if(isset($_POST['submit'])){
var_dump($_POST);
}
?>
<form method="post">
<input type="test" name="test">
<input type="test2" name="test2">
<div class="ttt" style="display: none;">
<input type="j1" name="j1" value="ttt">
<input type="j2" name="j2" value="yyy">
@junaidtk
junaidtk / Step to configure woocommerce Sandbox checkout
Last active January 1, 2019 06:12
Woocommerce checkout using Paypal sandbox
For setting up the paypal checkout in woocommerce, we must have a paypal account.
The following are the steps to test paypal sandbox checkout in the woocommerce.
1. first we need to create a paypal account.
2. Then we goes to the https://developer.paypal.com/ page and check the sandbox area. Where we can see the buyer account and facilitator account.
3. Here we can add new buyer and facilitator account if required.
@junaidtk
junaidtk / Display all hooks used in an WordPress page
Last active July 2, 2019 13:19
Show all hooks in the WP page
This code will display all hooks used in a page for wordpress website.
$debug_tags = array();
add_action( 'all', function ( $tag ) {
global $debug_tags;
if ( in_array( $tag, $debug_tags ) ) {
return;
}
echo "<pre>" . $tag . "</pre>";
$debug_tags[] = $tag;
@junaidtk
junaidtk / Check javascript variable contain a valid data
Created January 16, 2019 10:03
Check a javascript variable is valid one
In javascript, to check a variable contain a valid data or not, we can use the below code.
var value;
if(value){
// do something
}
If the variable doesn't contain a valid value it may have following 6 type of content.
This checking will valid if the variable is already defined.
@junaidtk
junaidtk / New post type and taxonomy creation in WP
Last active January 17, 2019 17:07
WP Post type creation from function.php
For creating a new post types in wordpress admin panel we can use below function in init hook.
function theme_posttype() {
register_post_type('portfolio', array('label' => 'Works',
'description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'page',
'hierarchical' => false,
@junaidtk
junaidtk / Isotop filtering for portfolio section
Created January 17, 2019 17:16
Portfolio section as masonry isotop
<div class="container-fluid">
<div class="row">
<!-- <div class="section-head text-center col-sm-12">
<h4>My Work</h4>
<p>...</p>
</div> -->
<?php
$terms = get_terms( array(
'taxonomy' => 'work-category',
'hide_empty' => false,
@junaidtk
junaidtk / Static methods and properties
Last active January 23, 2019 09:33
Static methods and properties in PHP OOP
Static means they are unchanging.
static function means, it is a function namespaced by the name of its class.
To make a function static, we need to add the key work static in the function definition.
Like
public static function(){
// Statement.
@junaidtk
junaidtk / esc_html and reverse
Created January 29, 2019 03:50
wordpresss esc_html and its reverse opperation.
esc_html():
It is wordpress function used to convert the html element to html entity.
Refer the below eg:
$html = esc_html( '<a href="http://www.example.com/">A link</a>' );
so $html contain
&lt;a href=&quot;http://www.example.com/&quot;&gt;A link&lt;/a&gt;
The output will display like below.
@junaidtk
junaidtk / Post type menu in admin submenu
Created February 8, 2019 03:48
Add post type menu as admin_sub_menu
// 1. when registering a custom post type set show_in_menu to false,
function ttlm_register_team_custom_type() {
$labels = array(
'name' => _x( 'Teams', 'post type general name', 'your-plugin-textdomain' ),
'singular_name' => _x( 'Team', 'post type singular name', 'your-plugin-textdomain' ),
'menu_name' => _x( 'Teams', 'admin menu', 'your-plugin-textdomain' ),
'name_admin_bar' => _x( 'Team', 'add new on admin bar', 'your-plugin-textdomain' ),
'add_new' => _x( 'Add New', 'team', 'your-plugin-textdomain' ),
'add_new_item' => __( 'Add New Team', 'your-plugin-textdomain' ),
'new_item' => __( 'New Team', 'your-plugin-textdomain' ),