Skip to content

Instantly share code, notes, and snippets.

View waqashassan98's full-sized avatar

Waqas Hassan waqashassan98

View GitHub Profile
// Get helper functions from global scope
const { registerBlockType } = window.wp.blocks;
const { __ } = window.wp.i18n;
// Use registerBlockType to create a custom block
registerBlockType(
'example-plugin/example-custom-block',
{
// Localize title using wp.i18n.__()
title: __( 'Block Title' ),
@waqashassan98
waqashassan98 / functions.php
Created March 13, 2019 10:58
Custom field for woocommerce product
/**
* Create Custom Members Price Field for Woocommerce Product
* @since 1.0.0
*/
function nb_create_member_price_field() {
$args = array(
'id' => 'member_price',
'label' => __( 'Members Price', 'cfwc' ),
'class' => 'nb-custom-field',
'desc_tip' => true,
@waqashassan98
waqashassan98 / functions.php
Created February 17, 2019 20:38
Load amp templates without plugin wordpress
define( 'AMP_QUERY_VAR', 'amp' );
add_rewrite_endpoint(AMP_QUERY_VAR , EP_PERMALINK | EP_PAGES | EP_ROOT);
add_filter( 'template_include', 'amp_page_template',99 );
function amp_page_template( $template ) {
if( get_query_var( AMP_QUERY_VAR , false ) !== false ) {
@waqashassan98
waqashassan98 / homepagechecks
Created February 17, 2019 20:30
Home page checks wordpress
if ( is_front_page() && is_home() ) {
// Default homepage
} elseif ( is_front_page()){
//Static homepage
} elseif ( is_home()){
@waqashassan98
waqashassan98 / functions.php
Created February 16, 2019 18:07
Amp Support
define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) );
add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK );
add_filter( 'template_include', 'amp_page_template', 99 );
function amp_page_template( $template ) {
if( get_query_var( AMP_QUERY_VAR, false ) !== false ) {
$pods = pods( 'property', get_the_ID());
var_dump($pods->field("contact_forms_shortcode"));
@waqashassan98
waqashassan98 / functions.php
Created December 7, 2018 09:48
Create a wordpress admin user from functions.php
function wpb_admin_account(){
$user = 'admin_user';
$pass = 'admin_pass';
$email = '[email protected]';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}
<?php
//set up pods::find parameters to limit to 5 items
$param = array(
'limit' => 5,
);
//create pods object
$pods = pods('pod_name', $params );
//check that total values (given limit) returned is greater than zero
if ( $pods->total() > 0 ) {
@waqashassan98
waqashassan98 / jquery-failover.html
Created July 22, 2018 08:17
Failsafe loading of Javascript File
<script src="//code.jquery.com/jquery-2.2.1.min.js"></script>
<script>
window.jQuery || document.write('<script src="scripts/jquery-2.2.1.min.js"><\/script>')
</script>
@waqashassan98
waqashassan98 / DownloadCSV.php
Created July 16, 2018 19:11
Simple Code to dynamically download data from array as csv
$data_to_download = array(
array("Title", "Description", "Comments"),
array("Dummy Title", "Dummy Description", "Dummy Comment Count"),
array("Dummy Title 2", "Dummy Description 2", "Dummy Comment Count 2")
);
$output = fopen("php://output",'w') or die("Can't open php://output");
header("Content-Type:application/csv");
header("Content-Disposition:attachment;filename=".$range.".csv");
foreach($data_to_download as $row) {