Skip to content

Instantly share code, notes, and snippets.

View meetawahab's full-sized avatar
🎯
Focusing

Abdul Wahab meetawahab

🎯
Focusing
View GitHub Profile
@meetawahab
meetawahab / pe-customize-controls.css
Created February 21, 2017 05:38 — forked from OriginalEXE/pe-customize-controls.css
Extending WordPress Customizer Panels and Sections to allow nesting
.in-sub-panel #customize-theme-controls .customize-pane-child.current-panel-parent,
#customize-theme-controls .customize-pane-child.current-section-parent {
-webkit-transform: translateX(-100%);
-ms-transform: translateX(-100%);
transform: translateX(-100%);
}
@meetawahab
meetawahab / create-admin-user.php
Last active September 28, 2019 06:40
Create a new admin user in WordPress through code. You just need to change the variables and drop the file in the mu-plugins directory or add the following code in active theme's functions.php, then reload the homepage in WordPress. The new user will be created. Remove the file/code after that.
<?php
add_action( 'init', 'aw610_create_user' );
function aw610_create_user() {
$username = 'admin';
$password = 'password';
$email_address = 'email@domain.com';
if ( ! username_exists( $username ) ) {
/**
* Enable svg mime type support.
* @param $mimes
* @return $mimes
*/
function loginpress_mime_types( $mimes ) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
@meetawahab
meetawahab / redirect-referral-url.php
Last active January 1, 2020 06:54
Redirect user to the referrer page after login to the WordPress site.
<?php
add_filter( 'login_redirect', function ( $redirect_to, $requested_redirect_to, $user ) {
if ( ! $requested_redirect_to ) {
$redirect_to = wp_get_referer();
}
return $redirect_to;
}, 10, 3 );
@meetawahab
meetawahab / custom-registration-fields.php
Created January 1, 2020 06:52
Add First Name & Last Name field on the WordPress registration form.
<?php
add_action( 'register_form', 'loginpress_plugin_register_form_custom_field' );
function loginpress_plugin_register_form_custom_field() {
$first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : '';
$last_name = ( ! empty( $_POST['last_name'] ) ) ? trim( $_POST['last_name'] ) : ''; ?>
<p>
<label for="first_name">
<?php _e( 'First Name', 'loginpress' ) ?><br />
@meetawahab
meetawahab / change-default-sender-name-email.php
Last active February 24, 2020 06:08
Changing Default Sender Name and Email.
<?php
// Function to change email address.
function ab610_sender_email( $original_email_address ) {
return 'your_email@example.com';
}
// Function to change sender name.
function ab610_sender_name( $original_email_from ) {
return 'Site or Your Name';
}
@meetawahab
meetawahab / redirect-cpt-single.php
Last active March 13, 2020 06:32
Redirect all Single Posts of a Custom Post Type using template_redirect Function
<?php
add_action( 'template_redirect', 'redirect_your_post_type_single' );
function redirect_your_post_type_single(){
if ( ! is_singular( 'YOUR-CUSTOM-POST-TYPE' ) )
return;
wp_redirect( get_page_link( YOUR-PAGE-ID ), 301 );
// or
// wp_redirect( get_post_type_archive_link( 'ANOTHER-CUSTOM-POST-TYPE' ), 301 );
@meetawahab
meetawahab / price-with-variation-in-dropdown.php
Last active June 26, 2020 10:37
Show Price along with WooCommerce variation in drop-down.
<?php
add_filter( 'woocommerce_variation_option_name', 'ab610_display_price_in_variation_option_name' );
function ab610_display_price_in_variation_option_name( $term ) {
global $wpdb, $product;
$result = $wpdb->get_col( "SELECT slug FROM {$wpdb->prefix}terms WHERE name = '$term'" );
$term_slug = ( !empty( $result ) ) ? $result[0] : $term;
@meetawahab
meetawahab / index.php
Last active June 26, 2020 10:37
Turn off the new user email notification for user.
<?php
function ab610_wp_new_user_notification_email( $wp_new_user_notification ) {
$wp_new_user_notification['to'] = '';
return $wp_new_user_notification;
}
add_filter( 'wp_new_user_notification_email', 'ab610_wp_new_user_notification_email' );
// We can use `wp_new_user_notification_email_admin` filter for turn off the admin notification.
@meetawahab
meetawahab / style.css
Created August 5, 2020 06:12
Remove WordPress registration link from login forms through custom CSS.
/** For removing "|" symbol, that fall between 2 links. */
.login-action-login #nav, .login-action-lostpassword #nav {
font-size: 0;
}
/** For removing registration link on login form. */
.login-action-login #nav a:first-child{
display: none;
}
/** For removing registration link on lost password form. */
.login-action-lostpassword #nav a:nth-child(2){