Skip to content

Instantly share code, notes, and snippets.

View waqashassan98's full-sized avatar

Waqas Hassan waqashassan98

View GitHub Profile
@waqashassan98
waqashassan98 / youtube api embed.php
Created May 20, 2019 13:08
Youtube API Embed, Auto Start on scroll to its position and resonsive video
<!-- Style -->
<style>
#y_video_container{
position: relative;
width: 100%;
height: 0;
padding-bottom: 56.25%;
}
#y_video_container>iframe{
position: absolute;
@waqashassan98
waqashassan98 / autoload_snippet.php
Last active August 1, 2019 12:48
Autoloading Classes PHP
<?php
//src: https://www.php.net/manual/en/function.spl-autoload-register.php
// Example to auto-load class files from multiple directories using the SPL_AUTOLOAD_REGISTER method.
// It auto-loads any file it finds starting with class.<classname>.php (LOWERCASE), eg: class.from.php, class.db.php
spl_autoload_register(function($class_name) {
// Define an array of directories in the order of their priority to iterate through.
$dirs = array(
'project/', // Project specific classes (+Core Overrides)
@waqashassan98
waqashassan98 / gist:72c7d2527d56cf3a172d006d7161e845
Created September 23, 2019 10:54
checkbox styling with custom image. Works with labels
.class_checkbox {
display:none;
}
.class_checkbox + label:before{
background:url('/img/checkbox.png') no-repeat;
width: 42px!important;
height: 43px!important;
@waqashassan98
waqashassan98 / wp-cache.php
Created November 20, 2019 11:51
Add and retrieve objects from wp cache
<?php
function get_post_count( $post_status = 'publish' ) {
$cache_key = 'post_count_'. $post_status;
$_posts = wp_cache_get( $cache_key );
if ( false === $_posts ) {
$_posts = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = %s",
$post_status
));
@waqashassan98
waqashassan98 / Revealing-Module-Pattern.md
Created November 22, 2019 05:56 — forked from zcaceres/Revealing-Module-Pattern.md
Using the Revealing Module Pattern in Javascript

The Revealing Module Pattern in Javascript

Zach Caceres

Javascript does not have the typical 'private' and 'public' specifiers of more traditional object oriented languages like C# or Java. However, you can achieve the same effect through the clever application of Javascript's function-level scoping. The Revealing Module pattern is a design pattern for Javascript applications that elegantly solves this problem.

The central principle of the Revealing Module pattern is that all functionality and variables should be hidden unless deliberately exposed.

Let's imagine we have a music application where a musicPlayer.js file handles much of our user's experience. We need to access some methods, but shouldn't be able to mess with other methods or variables.

Using Function Scope to Create Public and Private Methods

<?php
/**
* All items of a POD (CPT)
**/
$params = array(
'limit' => -1,
);
$prods_pod = pods( 'im_products', $params );
if( false != $prods_pod && $prods_pod->total_found()>0 ){
@waqashassan98
waqashassan98 / SchemaValidator.php
Created July 23, 2020 18:17
Custom Wordpress Rest API Schema Validator - Limited Cases
<?php
class SchemaValidator{
public function validate_structure($params, $schema){
$errors = array();
foreach($schema as $key => $object){
//check if present if required
if(isset($object["required"]) && true == $object["required"]){
@waqashassan98
waqashassan98 / freshdesk-api.php
Created August 19, 2020 21:06
freshdesk API ticket with custom field and attachment
<?php
$api_key = esc_attr( get_option('freshdesk_tickets_api_key') );
$password = "x";
$yourdomain = "youdomain";
$custom_fields = array("bio" => esc_attr($_REQUEST['bio']) );
$ticket_payload = array(
'name' => esc_attr($_REQUEST['name']),
'email' => esc_attr($_REQUEST['email']),
@waqashassan98
waqashassan98 / simple-pods-plugin.php
Created November 24, 2020 14:47 — forked from Shelob9/simple-pods-plugin.php
Simple plugin for safely adding code for extending Pods. Instructions: 1) Create a folder in your plugins file. 2) Add this file and a second file, called 'custom-code.php' to it. 3) Add custom code to custom-code.php. 4) Activate plugin. For a complete Pods plugin starter plugin, see: https://github.com/pods-framework/pods-extend
<?php
/*
Plugin Name: Pods Starter Plugin
Version: 0.0.1
License: GPL v2 or later
*/
//note: change 'slug' to your own custom prefix.
add_action( 'plugins_loaded', 'slug_extend_safe_activate');
function slug_extend_safe_activate() {
@waqashassan98
waqashassan98 / functions.php
Created November 26, 2020 18:14 — forked from mastef/functions.php
Pods : How to add Custom Admin Table Columns to a Pods ACT
<?php
/*
only important name is the filter name :
pods_admin_ui_PODNAME
if your pods is called "client" then call it
pods_admin_ui_client
you can rename all functions to your liking
*/
add_filter( 'pods_admin_ui_PODNAME', 'custom_admin_table_columns_for_PODNAME' );