Skip to content

Instantly share code, notes, and snippets.

View mayeenulislam's full-sized avatar
🤖
AI won't replace you

Mayeenul Islam mayeenulislam

🤖
AI won't replace you
View GitHub Profile
@mayeenulislam
mayeenulislam / wpmail_exceptions.php
Last active November 2, 2017 05:35 — forked from franz-josef-kaiser/wpmail_exceptions.php
WP Mail Error/Exception handling and SMTP settings. ALWAYS use the Kaiser's version - it's safer. This forked version is just to catch errors in the case of non-admin users.
<?php
/**
* NOTICE_____________________________________________________________________
* ALWAYS use the Kaiser's version - it's safer.
* This forked version is just to catch errors in the case of non-admin users.
* ---------------------------------------------------------------------------
*/
defined( 'ABSPATH' ) OR exit;
/**
<?php
add_action( 'pre-upload-ui', 'get_the_post_type' );
function get_the_post_type() {
$post_type = isset( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : 'post';
set_transient( 'attached_post_type', $post_type );
}
add_filter( 'intermediate_image_sizes_advanced', 'add_image_size_for_post_type', 10 );
function add_image_size_for_post_type( $sizes ) {
@mayeenulislam
mayeenulislam / bulk-fi-kb.php
Created November 24, 2017 14:14
Set a single featured image to all the NanoSupport Knowledgebase posts on activation. Before activating the plugin set the default post_thumbnail_id on line #19
<?php
/**
* Plugin Name: Bulk Featured Image (KB)
* Description: Set a single featured image to all the NanoSupport Knowledgebase posts on activation. Before activating the plugin set the default post_thumbnail_id on line #19.
* Plugin URI: http://nanodesignsbd.com/
* Author: Mayeenul Islam
* Author URI: http://nanodesignsbd.com/
* Version: 1.0.0
* License: GPL2
*/
@mayeenulislam
mayeenulislam / functions.php
Created March 30, 2018 05:25 — forked from lmartins/functions.php
By default WooCommerce redirects the user to the My Account page after a successful login. You may change this and use a custom URL based on the user role, like the Dashboard for admins and My Account page for customers. To do this, add this code at the end of the file functions.php located in wp-content/themes/your-theme-name/ https://support.w…
<?php
/**
* Redirect users to custom URL based on their role after login
*
* @param string $redirect
* @param object $user
* @return string
*/
function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
@mayeenulislam
mayeenulislam / wpse-restrict-unwanted-users.php
Last active June 22, 2018 16:27
WP Restrict Unwanted Users - restrict unwanted users from visiting the site (Link: https://wordpress.stackexchange.com/a/306082/22728)
<?php
/**
* Plugin Name: WPSE Restrict Unwanted Users
* Plugin URI: https://wordpress.stackexchange.com/a/306082/22728
* Description: Restrict unwanted users from visiting the site
* Author: Mayeenul Islam
* Version: 1.0.0
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
@mayeenulislam
mayeenulislam / .gitignore
Last active March 8, 2019 15:55
WordPress Debugging plugins I used to use in most of the development workflow
wp-content/plugins/debug-bar
wp-content/plugins/debug-bar-console
wp-content/plugins/debug-bar-cron
wp-content/plugins/debug-bar-list-dependencies
wp-content/plugins/debug-bar-post-types
wp-content/plugins/debug-bar-remote-requests
wp-content/plugins/debug-bar-shortcodes
wp-content/plugins/debug-bar-transients
wp-content/plugins/log-deprecated-notices
wp-content/plugins/log-viewer
@mayeenulislam
mayeenulislam / data.json
Last active July 10, 2019 17:08 — forked from hasinhayder/data.json
WP Quick Configurator Data
{
"themes": [],
"plugins": [
"elementor",
"happy-elementor-addons",
"contact-form-7",
"query-monitor",
"regenerate-thumbnails",
"debug-bar",
"debug-bar-console",
@mayeenulislam
mayeenulislam / RegEx.md
Last active October 30, 2019 11:28
Regular Expressions for HTML5 Patterns

HTML5 Regular Expressions

DateTime (12 Hour format with AM/PM)

([0-2][0-9]|(3)[0-1])(-)(((0)[0-9])|((1)[0-2]))(-)\d{4} (1[0-2]|0?[1-9]):[0-5][0-9] (AM|PM)

Example

<input type="text" class="form-control" value="" placeholder="Pick a datetime, e.g., 21-02-1952 12:59 PM" pattern="([0-2][0-9]|(3)[0-1])(-)(((0)[0-9])|((1)[0-2]))(-)\d{4} (1[0-2]|0?[1-9]):[0-5][0-9] (AM|PM)">
@mayeenulislam
mayeenulislam / command.sh
Last active February 11, 2020 11:27
Shell commands for Files utilities
# file mime type
file -b --mime-type 'filename has space in it.flv'
# Create dummy file with any defined size with valid mime_type
# file size in binary bytes
fsutil file createnew myfile.pdf 10485760
# Source: https://www.digitalcitizen.life/3-ways-create-random-dummy-files-windows-given-size
# Helpful converter: https://www.gbmb.org/
@mayeenulislam
mayeenulislam / install-wp-plugins.php
Created January 24, 2020 04:16 — forked from squarestar/install-wp-plugins.php
Programmatically install and activate wordpress plugins
<?php
/**
* Programmatically install and activate wordpress plugins
*
* Usage:
* 1. Edit the $pluginSlugs array at the beginning of this file to include the slugs of all the
* plugins you want to install and activate
* 2. Upload this file to the wordpress root directory (the same directory that contains the
* 'wp-admin' directory).
* 3. Navigate to <your-domain-wordpress-root>/install-wp-plugins.php (If wordpress is installed