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
@DevWael
DevWael / routing.php
Last active February 24, 2019 13:34
Wrapper for the WordPress WP Rewrite system
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
//forked from this repo: https://github.com/humanmade/hm-rewrite
/**
* Should we flush WP rewrite rules automatically?
*/
//todo set this to false on production
defined( 'HM_REWRITE_AUTOFLUSH' ) or define( 'HM_REWRITE_AUTOFLUSH', true );
@DevWael
DevWael / post_content.php
Created February 3, 2019 05:07
Get WordPress Post Content by post id
<?php
/**
* Get post content by id
* @param $post_id
*
* @return mixed|string
*/
function dw_get_content( $post_id ) {
$content_post = get_post( $post_id );
$content = $content_post->post_content;
@DevWael
DevWael / add_smtp_to_wp.php
Created January 28, 2019 12:30
add smtp email server details to WordPress
<?php
add_action( 'phpmailer_init', 'dw_phpmailer_init' );
function dw_phpmailer_init( PHPMailer $phpmailer ) {
$phpmailer->Host = 'mail.host';
$phpmailer->Port = 2525; // could be different
$phpmailer->Username = 'username'; // if required
$phpmailer->Password = 'password'; // if required
$phpmailer->SMTPAuth = true; // if required
// $phpmailer->SMTPSecure = 'ssl'; // enable if required, 'tls' is another possible value
@DevWael
DevWael / egypt_governorates.php
Last active January 25, 2019 23:02
(WordPress) Return all Egyptian Governorates into Assoc array php
<?php
//Return all Egyptian Governorates into Assoc array php
//by Bbioon.com
function dw_egypt_governorate() {
$arr = [
'Alexandria',
'Aswan',
'Asyut',
'Beheira',
'Beni Suef',
@DevWael
DevWael / print_r.php
Last active January 31, 2019 06:01
beautifully styled print_r function
<?php
function print_rr( $param ) {
?>
<style>
div.advanced_print_r {
direction: ltr;
max-height: 500px;
overflow-y: scroll;
background: #10192d;
margin: 50px 30px;
@DevWael
DevWael / phone_numbers.php
Created January 6, 2019 07:24
data set of the phone numbers for each country (ISO 3166)
<?php
function phone_numbers_iso3166(){
return array (
0 =>
array (
'alpha2' => 'US',
'alpha3' => 'USA',
'country_code' => '1',
'country_name' => 'United States',
{
"page-1": [
{
"name": "\u0627\u0628\u062d\u0627\u062b \u0639\u0644\u0645\u064a\u0629 (34)",
"link": "https:\/\/www.yellowpages.com.eg\/ar\/condensed-category\/%D8%A7%D8%A8%D8%AD%D8%A7%D8%AB-%D8%B9%D9%84%D9%85%D9%8A%D8%A9"
},
{
"name": "\u0627\u0628\u0631\u0627\u062c \u062a\u0628\u0631\u064a\u062f \u0648\u062a\u0647\u0648\u064a\u0629 (39)",
"link": "https:\/\/www.yellowpages.com.eg\/ar\/condensed-category\/%D8%A7%D8%A8%D8%B1%D8%A7%D8%AC-%D8%AA%D8%A8%D8%B1%D9%8A%D8%AF-%D9%88%D8%AA%D9%87%D9%88%D9%8A%D8%A9"
},
@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({
@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 / 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' );