Skip to content

Instantly share code, notes, and snippets.

View alordiel's full-sized avatar
🛶
Požuri polako

a.vasilev alordiel

🛶
Požuri polako
View GitHub Profile
@alordiel
alordiel / logout.php
Created December 20, 2021 15:44
Hardcoded log out for appPresser
public function api_logout( $request ) {
do_action( 'appp_logout_header' );
if( ! defined('DOING_AJAX') ) {
define('DOING_AJAX', true);
}
wp_logout();
@alordiel
alordiel / is_admin_user.php
Created May 17, 2021 15:58
WordPress: check if user is an adminstrator only by the wordpress_logged_in cookie (in case we need to do this check too early in the initialization of WP).
function is_user_administrator(): bool {
if ( function_exists( 'get_site_option' ) ) {
$siteurl = get_site_option( 'siteurl' );
if ( $siteurl ) {
global $wpdb;
$cookie_hash = 'wordpress_logged_in_' . md5( $siteurl );
if ( ! isset( $_COOKIE[ $cookie_hash ] ) ) {
return false;
}
@alordiel
alordiel / gulpfile.js
Last active March 12, 2020 11:30
Starter Gulp (SASS and JS compiler, autoprefixer, babel, minifier)
'use strict';
const gulp = require( 'gulp' );
const sass = require( 'gulp-sass' );
const csso = require( 'gulp-csso' );
const concat = require( 'gulp-concat' );
const uglify = require( 'gulp-uglify');
const autoprefixer = require( 'gulp-autoprefixer' );
const notify = require( 'gulp-notify' );
const babel = require( 'gulp-babel' );
@alordiel
alordiel / un-gzip-all-filer.sh
Created January 16, 2020 11:31
Bash script to unarchive files from folders
#!/bin/bash
FILES=$(find public_html -type f -name '*.gz')
for f in $FILES
do
gzip -d $f
# take action on each file.
done
@alordiel
alordiel / disable-autoupdate.php
Created August 14, 2019 06:38
Disable autoupdate and updates for paid plugins
<?php
define( 'automatic_updater_disabled', true );
define( 'wp_auto_update_core', false );
add_filter('site_transient_update_plugins', 'remove_update_notification');
function remove_update_notification($value)
{
unset($value->response['memberpress/memberpress.php']);
@alordiel
alordiel / add-capabilities.php
Created July 1, 2019 14:44
[WordPress] Add capability for single user or role
add_action( 'admin_init', 'add_theme_caps');
function add_theme_caps() {
// add single role capability
$role = get_role( 'administrator' );
$role->add_cap( 'manage_phrases' );
// add single user capability
$user = new WP_User( 4766 );
$user->add_cap( 'manage_phrases' );
}
@alordiel
alordiel / split-full-date-to-parts .sql
Last active May 30, 2019 09:24
MySQL query to split DATE into Year, Month, Day, Hour and record in relative columns
UPDATE `events` as EE
LEFT JOIN events as EE1
ON EE.ID = EE1.ID
SET EE.Year = YEAR(EE1.created),
EE.Month = MONTH(EE1.created),
EE.Day = DAY(EE1.created),
EE.Hour = TIME(EE1.created),
EE.DayOfWeek = DAYOFWEEK(EE1.created)
@alordiel
alordiel / smoothScrollToId.js
Last active April 10, 2019 15:12
Smooth pure js scroll to ID
scrollTo (id) {
window.scrollTo({
top: document.getElementById(id).offsetTop,
left: 0,
behavior: 'smooth'
});
}
// Doesn't work in IE
//https://developer.mozilla.org/en-US/docs/Web/API/Window/scroll
@alordiel
alordiel / smoothScrollTop.js
Created April 10, 2019 14:33
Smooth scroll to top
const scrollToTop = () => {
const c = document.documentElement.scrollTop || document.body.scrollTop;
if (c > 0) {
window.requestAnimationFrame(scrollToTop);
window.scrollTo(0, c - c / 8);
}
};
scrollToTop();
// https://stackoverflow.com/questions/15935318/smooth-scroll-to-top
@alordiel
alordiel / remove-pass-change-email.php
Created August 22, 2018 14:25
WordPress: remove the password change notification email
<?pgp
add_action( 'wp_head', 'remove_notificationpassword_emails',100 );
function remove_notificationpassword_emails() {
remove_action( 'after_password_reset', 'wp_password_change_notification', 11 );
add_filter( 'send_password_change_email', '__return_false' );
}
add_filter( 'send_password_change_email', '__return_false' );