Skip to content

Instantly share code, notes, and snippets.

View gicolek's full-sized avatar

Rafał Gicgier - Certified Codeable Expert Developer gicolek

View GitHub Profile
@gicolek
gicolek / prefix-woo-ajax.php
Created November 23, 2013 20:57
Woo Commerce custom add to cart ajax handler
<?php
add_action( 'woocommerce_ajax_added_to_cart', 'ac_add_product_custom_field' );
/**
*
* @hook woocommerce_ajax_added_to_cart
*/
function ac_add_product_custom_field($product_id) {
@gicolek
gicolek / gtps.php
Created November 6, 2013 14:32
Get post id from shortcode
<?php
add_shortcode( 'table', 'ssl_table_shortcode' );
/**
* Render ACF table shortcode given several parameters
*/
function ssl_table_shortcode($atts) {
global $post;
// extract the necessary attributes
@gicolek
gicolek / fancy.js
Created April 29, 2013 18:46
Powelek
(function($) {
"use strict";
var Site = {
basePrice: 0, //$('.ginput_amount').val(),
gfield_original_title: "",
gformId: 22,
init: function() {
Site.selectChangeEvents();
@gicolek
gicolek / paginacja.php
Created April 15, 2013 12:36
paginacj
<?php
/**
* Generate the navigation for blog listing pages
*
* @global obj $wp_query
*/
function bg_page_navi($query = null, $paged = null) {
?>
<ul class="page-navi">
<?php
@gicolek
gicolek / ajax-form-wp.php
Created March 21, 2013 12:56
Sample Ajax Form WP
<?php
/**
* Validate data and send mail.
*
* @see http://codex.wordpress.org/Function_Reference/wp_mail
* @return {int} Status of message:
* -2 => Invalid data
* -1 => Failed to send
* 1 => OK
@gicolek
gicolek / bcwpsc.php
Created March 18, 2013 17:02
How not to code WP shortcodes
<?php
$output = '';
if ( $related_posts->have_posts() ){
$out .= '<h3> Related Posts</h3>';
$out .= '<ul>';
while ( $related_posts->have_posts() ){
$related_posts->the_post();
$out .= '<li><a href="'.the_permalink().'">'.get_the_title().'</a></li>';
@gicolek
gicolek / ocwps.php
Created March 18, 2013 16:50
Output Control WP Shortcode
<?php
add_shortcode( 'list-posts', 'smoney_list_posts' );
function smoney_list_posts($atts, $content = null) {
extract( shortcode_atts( array(
'numb' => 5,
), $atts ) );
if ( !is_page() ) {
$out = 'This shortcode can only be used on a page';
@gicolek
gicolek / corg.php
Created March 18, 2013 16:46
Code organization
// sth above
<?php if ( $related_posts->have_posts() ): ?>
<h3> Related Posts</h3>
<ul>
<?php while ( $related_posts->have_posts() ): $related_posts->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
@gicolek
gicolek / blah.php
Created February 6, 2013 16:47
Handle ajax requests (omitting admin-ajax.php)
<?php
function _foo_handle_ajax_request_for_db_data() {
$path = parse_url (site_url());
if ( parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) === $path['path'] . '/sth' ) {
status_header(200);
// do sth
exit ;
@gicolek
gicolek / gf-ldtable.php
Last active September 2, 2017 16:31
Gravity Forms modify lead detail table
<?php
function update() {
global $wpdb;
// get the lead detail table name
$lead_details_table_name = RGFormsModel::get_lead_details_table_name();
// as stored in the $lead_details_table_name * 10