Skip to content

Instantly share code, notes, and snippets.

View DevWael's full-sized avatar
👨‍💻
WordPress-ing

Ahmad Wael DevWael

👨‍💻
WordPress-ing
View GitHub Profile
<?php
function prefix_phone_exist( $phone ) {
$args = array(
'fields' => 'ID',
'meta_query' => array(
array(
'key' => 'billing_phone', //Change this with the meta key that holds the phone number in user meta data
'value' => $phone,
'compare' => '='
)
@DevWael
DevWael / disable_posts.php
Created October 1, 2018 02:04
Disable Default Posts From WP
<?php
class Prefix_Disable_Posts {
public function __construct() {
global $pagenow;
/* checks the request and redirects to the dashboard */
add_action( 'init', array( __CLASS__, 'disallow_post_type_post' ) );
/* removes Post Type `Post` related menus from the sidebar menu */
add_action( 'admin_menu', array( __CLASS__, 'remove_post_type_post' ) );
if ( ! is_admin() && ( $pagenow != 'wp-login.php' ) ) {
@DevWael
DevWael / count_down_five_minutes.htm
Created October 30, 2018 03:37
Count down a disabled button for five minutes before enabling it to submit a form
<button type="submit" class="sms_submit" id="sms_submit" disabled>
Submit
<span id="count_down"></span>
</button>
<script>
var btn = document.getElementById("sms_submit");
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
@DevWael
DevWael / render_view.php
Last active November 18, 2018 20:07
Safe render a view and return html
<?php
/**
* Safe render a view and return html
* In view will be accessible only passed variables
* Use this function to not include files directly and to not give access to current context variables (like $this)
* @param string $file_path
* @param array $view_variables
* @param bool $return In some cases, for memory saving reasons, you can disable the use of output buffering
* @return string HTML
*/
@DevWael
DevWael / human_bytes.php
Created November 18, 2018 20:16
Convert bytes to human readable format
<?php
/**
* Convert bytes to human readable format
*
* @param integer $bytes Size in bytes to convert
* @param integer $precision
*
* @return string
*/
function prefix_human_bytes( $bytes, $precision = 2 ) {
@DevWael
DevWael / is_post_edit_page.php
Created November 18, 2018 20:17
If currently is a Post Edit page
<?php
/**
* If currently is a Post Edit page display/submit
* @return bool
*/
function is_post_edit_page() {
static $result = null;
if ( $result === null ) {
$result = false;
@DevWael
DevWael / get_image_sizes.php
Last active November 18, 2018 20:28
Return all images sizes register by add_image_size() merged with WordPress default image sizes.
<?php
/**
* Return all images sizes register by add_image_size() merged with
* WordPress default image sizes.
* @link https://codex.wordpress.org/Function_Reference/get_intermediate_image_sizes
*
* @param string $size
*
* @return array|bool
*/
@DevWael
DevWael / elementor_shortcodes.php
Created December 14, 2018 04:58
Insert Elementor pages and library templates anywhere using short codes.
<?php
/**
* Enable the use of short codes in text widgets.
*/
add_filter( 'widget_text', 'do_shortcode' );
add_filter( 'manage_elementor_library_posts_columns', 'prefix_edit_elementor_library_posts_columns' );
function prefix_edit_elementor_library_posts_columns( $columns ) {
$columns['prefix_shortcode_column'] = esc_html__( 'Shortcode', 'text_domain' );
@DevWael
DevWael / is_light_color.php
Created December 17, 2018 02:26
detect hex color is dark or light and return css class to use in to invert colors
<?php
function prefix_hex_is_light( $color ) {
if ( ! $color ) {
return false;
}
$hex = str_replace( '#', '', $color );
$c_r = hexdec( substr( $hex, 0, 2 ) );
$c_g = hexdec( substr( $hex, 2, 2 ) );
$c_b = hexdec( substr( $hex, 4, 2 ) );
@DevWael
DevWael / gulbfile.js
Created December 28, 2018 05:34
convert less to css and minify css with gulp 4
const gulp = require('gulp');
const uglifycss = require('gulp-uglifycss');
const less = require('gulp-less');
const rename = require('gulp-rename');
const path = require('path');
//convert less files to css file
gulp.task('less-to-css', function () {
return gulp.src('./*.less')
.pipe(less({