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 / functions.php
Created September 21, 2015 12:28
wp-login.php page redirect
<?php
/**
* Redirect from wp-login.php
* @link http://stackoverflow.com/a/1976804/1743124
*/
function mayeenulislam_wp_login_redirect(){
if( isset($_GET['action']) && $_GET['action'] == 'register' ) {
wp_redirect( home_url('/register') ); //i.e. http://example.com/register
exit();
} else if( isset($_GET['action']) && $_GET['action'] == 'lostpassword' ) {
# ----------------------------------------------------------------------
# | Compression |
# ----------------------------------------------------------------------
<IfModule mod_deflate.c>
# Force compression for mangled `Accept-Encoding` request headers
# https://developer.yahoo.com/blogs/ydn/pushing-beyond-gzipping-25601.html
<IfModule mod_setenvif.c>
@mayeenulislam
mayeenulislam / show-wordpress-db-queries.php
Last active November 1, 2015 09:05
Show WordPress database queries at the footer only to the admin if WP_DEBUG is enabled
<?php
/**
* db QUERIES
* Prerequisite: define('SAVEQUERIES', true)
*/
function nano_enqueue_db_queries() {
global $wpdb;
echo '<h2>Database Last Query</h2>';
echo $wpdb->last_query;
echo '<hr>';
@mayeenulislam
mayeenulislam / Connection fails fallback with PHP file read
Last active January 4, 2016 06:38
Check the latest jQuery library from the server. If fails, load the library from the local directory.
<?php
/**
* According to the lhrec_106's answer at StackOverflow
* http://stackoverflow.com/a/17339542/1743124
*/
$jQueryLatestURI = "http://code.jquery.com/jquery-latest.min.js";
@$connection = fopen( $jQueryLatestURI, "r" );
@mayeenulislam
mayeenulislam / functions.php
Created February 16, 2016 06:59 — forked from hasinhayder/functions.php
Redirect WordPress posts to the editor if someone types /edit at the end of the permalink
<?php
function init_url_rewrite_rule(){
add_rewrite_endpoint( 'edit',EP_PERMALINK | EP_PAGES | EP_ATTACHMENT );
if(get_option("EDIT_REWRITE_RULE")!=1){
flush_rewrite_rules();
update_option("EDIT_REWRITE_RULE",1);
}
}
function redirect_edit_url(){
@mayeenulislam
mayeenulislam / reset-wordpress-db-password.php
Created February 16, 2016 17:28
Change mySQL password without SQL manager or PHPmyAdmin for WordPress
<?php
/**
* Tutorial by: nanodesigns (@nanodesigns)
* URL: http://tuts.nanodesignsbd.com/change-wordpress-password-without-sql-manager/
* by: Mayeenul Islam (@mayeenulislam)
*/
//Connect to mySQL First
$connection = mysql_connect('DB_HOST','DB_USER','DB_PASSWORD');
<?php
$data_dir = 'c:/server/www/dev/data/';
$releases = [ ];
foreach ( range( 3.2, 4.0, 0.1 ) as $version ) {
$version = number_format( $version, 1 );
$data = json_decode( file_get_contents( $data_dir . $version . '.json' ), true );
$groups = wp_list_pluck( $data['groups'], 'data' );
@mayeenulislam
mayeenulislam / liner.css
Created August 4, 2016 04:23
Display Inline horizontal rule using simple CSS flex design (Source: https://codepen.io/oaviv/pen/GqXwYp | Author: Ohad)
/** Source: https://codepen.io/oaviv/pen/GqXwYp | Author: Ohad **/
body {
padding: 50px;
background-color: #11151C;
color: #7D4E57;
line-height: 170%;
font-family: sans-serif;
}
body .container {
@mayeenulislam
mayeenulislam / scroll.css
Created August 4, 2016 11:51
CSS Only scroll indicator
/** Source: http://codepen.io/MadeByMike/pen/ZOrEmr | Author: Mike (http://codepen.io/MadeByMike) **/
html, body {
margin: 0;
}
header {
position: fixed;
top: 0;
height: 125px;
@mayeenulislam
mayeenulislam / WP: post_is_in_descendant_category
Last active December 4, 2016 16:25
WordPress: post_is_in_descendant_category function (Source: Codex)
<?php
/**
* Tests if any of a post's assigned categories are descendants of target categories
*
* @param int|array $cats The target categories. Integer ID or array of integer IDs
* @param int|object $_post The post. Omit to test the current post in the Loop or main query
* @return bool True if at least 1 of the post's categories is a descendant of any of the target categories
* @see get_term_by() You can get a category by name or slug, then pass ID to this function
* @uses get_term_children() Passes $cats
* @uses in_category() Passes $_post (can be empty)