Skip to content

Instantly share code, notes, and snippets.

View govindak's full-sized avatar

Govinda Khatiwada govindak

View GitHub Profile
// SPDX-License-Identifier: Unlicensed
/*
Welcome to AAG
The Official Token for the AagTokens Community!
@govindak
govindak / download.php
Created December 21, 2019 09:30
wordpress downloader
<?php
// Download utility
ini_set("memory_limit", "-1");
set_time_limit(0);
function shailan_get_file( $url, $target ){
echo "<h3>Downloading file..</h3><br />";
if( FALSE !== file_put_contents( $target . "/" . basename($url), file_get_contents( $url ) ) ){
return $target . "/" . basename($url);
}
@govindak
govindak / gist:7435288
Last active April 25, 2019 03:54
Get the featured image by page ID in WordPress
<?php
//page id
$page_id = "5"; //example
if (has_post_thumbnail($page_id) ):
$image = wp_get_attachment_image_src( get_post_thumbnail_id($page_id), 'single-post-thumbnail' );
endif;
$image_URI = $image[0];
@govindak
govindak / foreachloop
Created September 27, 2018 17:46
foreach loop odd/even
<?php $counter = "";
foreach ( $columns_values as $columns_value ) {
$counter +=1;
// all my var stuff here
?>
<?php if($counter == 1) { ?>
<div class="columns-wrapper odd">
function my_form_shortcode() {
ob_start();
get_template_part('my_form_template');
return ob_get_clean();
}
add_shortcode( 'my_form_shortcode', 'my_form_shortcode' );
@govindak
govindak / functions.php
Created February 19, 2018 18:43
add active class wp menu
add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
function special_nav_class ($classes, $item) {
if (in_array('current-menu-item', $classes) ){
$classes[] = 'active ';
}
return $classes;
}
@govindak
govindak / gist:31dbbfb84d7a24337a0a80fa25068755
Created August 18, 2016 02:51
Memberpress Create transaction programatically.
$sub = new MeprSubscription();
$sub->user_id = $user_ID;
$sub->product_id = 123;
$sub->price = 12.99;
$sub->total = 12.99;
$sub->period = 1;
$sub->period_type = 'months';
$sub->status = MeprSubscription::$active_str;
$sub_id = $sub->store();
@govindak
govindak / auto_enroll.php
Created August 17, 2016 19:39 — forked from supercleanse/auto_enroll.php
Automatically create a lifetime transaction for a specific product each time a user registers.
<?php
if(is_plugin_active('memberpress/memberpress.php')) {
add_action( 'user_register', 'mp_auto_enroll' );
//add_action( 'gform_user_registered', 'mp_auto_enroll', 10, 4 );
function mp_auto_enroll($user_id, $user_config=array(), $entry='', $user_pass='') {
$txn = new MeprTransaction();
$txn->user_id = $user_id;
@govindak
govindak / custom_post_type_cf7_dropdown.php
Created May 24, 2016 10:52 — forked from alkrauss48/custom_post_type_cf7_dropdown.php
Adding a custom Wordpress shortcode for building a dynamic dropdown of post type titles with Contact Form 7
wpcf7_add_shortcode('postdropdown', 'createbox', true);
function createbox(){
global $post;
extract( shortcode_atts( array( 'post_type' => 'some_post_type',), $atts ) );
$args = array('post_type' => $post_type );
$myposts = get_posts( $args );
$output = "<select name='postType' id='postType' onchange='document.getElementById(\"postType\").value=this.value;'><option></option>";
foreach ( $myposts as $post ) : setup_postdata($post);
$title = get_the_title();
$output .= "<option value='$title'> $title </option>";
@govindak
govindak / Functions.php
Created November 12, 2013 18:00 — forked from barbwiredmedia/Functions.php
wordpress breadcrumbs
//Bread crumbs created
function wordpress_breadcrumbs() {
$delimiter = '|';
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
if ( !is_home() && !is_front_page() || is_paged() ) {
echo '<div id="crumbs">';
global $post;
if ( is_page() && !$post->post_parent ) {
echo $currentBefore;