Skip to content

Instantly share code, notes, and snippets.

View Artisan-Asad's full-sized avatar
Reverse engineering

Asad Shahbaz Artisan-Asad

Reverse engineering
View GitHub Profile
/**
* Force login.
*/
add_action('template_redirect', function () {
if (!is_user_logged_in() && !is_404()) {
auth_redirect();
exit;
}
});
const DocumentReady = (e) => {
if (document.readyState === "complete" || document.readyState === "interactive") {
setTimeout(e, 1);
} else {
document.addEventListener("DOMContentLoaded", e);
}
}
DocumentReady( () => {
});
@Artisan-Asad
Artisan-Asad / create-admin-user.php
Created September 28, 2019 06:40 — forked from meetawahab/create-admin-user.php
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 ) ) {
public static function sort_array( $array ) {
usort($array, array( 'self', 'sort_fallback' ) );
return $array;
}
private static function sort_fallback( $a, $b ) {
return $b[1] - $a[1];
}
$('html, body').animate({
scrollTop: $('#filter-location-name').offset().top - $('#top-header').outerHeight() - $('#main-header').outerHeight() - 10
}, 1000);
@Artisan-Asad
Artisan-Asad / divi.css
Created November 22, 2018 11:46
Divi full width pages with no sidebar
/*** Take out the divider line between content and sidebar ***/
#main-content .container:before {
background: none;
}
/*** Expand the content area to fullwidth ***/
@media (min-width: 981px){
#left-area {
width: 100% !important;
max-width: 800px;
@Artisan-Asad
Artisan-Asad / scroll-shadow.js
Created August 18, 2018 10:56
Give shadow to upper element on scroll
$('.scroll-container').on('scroll',function(e) {
var currentScrollPosition= $('.scroll-container').scrollTop() + $('.scroll-container').height();
if (currentScrollPosition == $('.scroll-container').height()) {
$('.fe-mdm-favorites').removeClass('shadow-bottom');
} else {
$('.fe-mdm-favorites').addClass('shadow-bottom');
}
});
@Artisan-Asad
Artisan-Asad / attachment_id.php
Created July 24, 2018 10:43
WordPress find attachment id from URL
function get_attachment_id_from_url( $attachment_url = '' ) {
global $wpdb;
$attachment_id = false;
// If there is no url, return.
if ( '' == $attachment_url )
return;
// Get the upload directory paths
@Artisan-Asad
Artisan-Asad / varify_youtube.php
Last active July 24, 2018 10:42
Verify youtube link in PHP application
function get_youtube_id( $video_url ){
if( (preg_match('/http:\/\/(www\.)*youtube\.com\/.*/',$video_url)) || (preg_match('/http:\/\/(www\.)*youtu\.be\/.*/',$video_url)) )
{
$video_id = ( preg_match( '%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $video_url, $match ) ) ? $match[1] : false;
return $video_id;
} else
{
return false;
}
@Artisan-Asad
Artisan-Asad / gist:47b9f29422c58d2fd76923117ff70975
Created July 19, 2018 07:27
Regular expression to test if a URL is a WordPress plugin repository URL
'|^http[s]?://wordpress\.org/(?:extend/)?plugins/|'