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
/*
Just copy the following code in functions.php file into your theme.
*/
add_action('after_setup_theme','window_mag_retina_script');
function window_mag_retina_script(){
wp_enqueue_script( 'retina-js', 'https://cdnjs.cloudflare.com/ajax/libs/retina.js/2.1.3/retina.min.js', array( 'jquery' ), '1.0', true );
}
/**
@DevWael
DevWael / wp widget based on unyson options.php
Created January 29, 2018 13:47
wordpress widget based on unyson framework options
<?php
class Widget_Online_Support extends WP_Widget {
/**
* Widget constructor.
*/
private $options;
private $prefix;
function __construct() {
@DevWael
DevWael / wp_login_form.php
Last active October 2, 2018 01:06
WordPress Login/Out Form
<?php
function prefix_login_form( $login_only = 0 ) {
global $user_ID, $user_level, $user_identity;
$redirect = site_url();
if ( $user_ID ) : ?>
<?php if ( empty( $login_only ) ): ?>
<div class="user-login">
<div class="author-avatar"><?php echo get_avatar( $user_ID, $size = '80' ); ?></div>
<p class="welcome-text"><?php esc_html_e( 'Welcome', 'window-mag' ); ?>
<strong><?php echo $user_identity ?></strong> .</p>
@DevWael
DevWael / get_ulike_posts.php
Last active June 5, 2018 19:37
Get Post Ids of Liked from user which is not saved in user meta and cannot be get by get_user_meta() function Works with plugin (WP ULike) https://wordpress.org/plugins/wp-ulike/
<?php
//Works only with wordpress plugin (WP ULike) url: https://wordpress.org/plugins/wp-ulike/
function prefix_get_posts_liked_by_current_user( $user_id = '' ) {
if ( function_exists( 'wp_ulike' ) ) {
global $wpdb;
$result = array();
if ( ! $user_id ) {
$user_ID = get_current_user_id();
}
$likes = $wpdb->get_results( "
@DevWael
DevWael / wpml_translated_object.php
Last active February 3, 2019 05:06
Get the translated post id of the given object id (the object id can be a post type or category or tag etc...)(WPML only)
<?php
function prefix_lang_object_ids($object_id, $type) {
if( is_array( $object_id ) ){
$translated_object_ids = array();
foreach ( $object_id as $id ) {
$translated_object_ids[] = apply_filters( 'wpml_object_id', $id, $type, true, $current_language );
}
return $translated_object_ids;
} else {
@DevWael
DevWael / opengraph support.php
Last active June 7, 2018 14:41
Adding Open Graph Meta Data in WordPress Using Official Facebook Plugin
<?php
add_filter('language_attributes', 'aprefix_add_opengraph_doctype');
function aprefix_add_opengraph_doctype( $output ) {
return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
}
add_action( 'wp_head', 'prefix_insert_fb_in_head', 5 );
function prefix_insert_fb_in_head() {
global $post;
if ( !is_singular()) //if it is not a post or a page
@DevWael
DevWael / additional_woocommerce_booking_cost.php
Last active June 19, 2018 22:46
Add additional cost to Woocommerce booking cost during price calculation depending Persons Count and on ACF Meta Box Result
<?php
add_filter( 'booking_form_calculated_booking_cost', 'prefix_calculate_prices_based_on_cars_count', 10, 3 );
function prefix_calculate_prices_based_on_cars_count( $cost, $book_obj, $posted ) {
$additional_cost = 198.6; //Change Cost Here
if ( 'public-tour' == get_field( 'oks-tour-type', $book_obj->product->id ) ) {
if ( $posted['wc_bookings_field_persons'] >= 1 && $posted['wc_bookings_field_persons'] <= 5 ) {
return $cost + $additional_cost;
} elseif ( $posted['wc_bookings_field_persons'] >= 6 && $posted['wc_bookings_field_persons'] <= 10 ) {
return $cost + ( $additional_cost * 2 );
@DevWael
DevWael / filter_removal_without_class_access.php
Last active June 28, 2018 18:01
Remove Class Filter Without Access to Class Object
<?php
/**
* Remove Class Filter Without Access to Class Object
*
* In order to use the core WordPress remove_filter() on a filter added with the callback
* to a class, you either have to have access to that class object, or it has to be a call
* to a static method. This method allows you to remove filters with a callback to a class
* you don't have access to.
*
* Works with WordPress 1.2+ (4.7+ support added 9-19-2016)
@DevWael
DevWael / egyptian_cities_array.php
Created August 15, 2018 05:26
This function returns all Egyptian cities
<?php
function prefix_egyptian_cities() {
$cities = array(
'10th of Ramadan',
'15th of May',
'6th of October',
'Abnub',
'Abu Hammad',
'Abu Hummus',
'Abu Kebir',
@DevWael
DevWael / create_log_file.php
Created September 24, 2018 16:49
function to create log file to test data in backend (Development Purposes Only)
<?php
function dev_log( $log_data ) {
$log_file_name = "log";
if ( ! file_exists( $log_file_name ) ) {
mkdir( $log_file_name, 0777, true );
}
$log_file_data = $log_file_name . '/log_' . date( 'd-M-Y' ) . '.log';
file_put_contents( $log_file_data, $log_data . "\n", FILE_APPEND );
}
//For wordpress developers: put this function into your plugin or theme (functions.php) and call it to test your data