Skip to content

Instantly share code, notes, and snippets.

View lunule's full-sized avatar

lunule lunule

  • Vigilante One
  • Brno
View GitHub Profile
@lunule
lunule / randomize_wp_query_post_order.php
Last active November 5, 2016 04:54 — forked from fikrirasyid/Randomizing WP_Query's Posts Order
WordPress | Randomize order of posts resulted from WP_Query().
<?php
/**
* Assuming you want 8 latest posts and excluding sticky posts
*/
$posts_args = array(
'ignore_sticky_posts' => true,
'posts_per_page' => 8
);
@lunule
lunule / wp-filters.php
Created February 19, 2017 19:25
How filters work in WordPress, aka how to make your plugins and functions extendable and the output easily modifiable. | +Tags: filter, filters, extend
<?php
function eyn_wb17_excerpt_from_content( $content, $wordlimit, $url, $readmore = 'Read More' ) {
// Action hook before any output!
do_action( 'eyn_wb17_before_excerpt' );
// Make the Read More text filterable
$readmore = apply_filters( 'eyn_wb17_excerpt_rmtext', $readmore );
@lunule
lunule / ajax_in_wordpress.js
Last active April 4, 2023 15:25 — forked from jackreichert/inputtitle_submit.js
Example showing how to use AJAX in WordPress
(function ($) {
$(document).ready(function () {
$('#next').click(function () {
$.ajax({
type: 'POST',
url: PT_Ajax.ajaxurl,
data: {
// wp ajax action
action: 'ajax-inputtitleSubmit',
@lunule
lunule / WooCommerce Custom Fields for Simple and Variable Products
Last active November 15, 2019 06:36 — forked from maddisondesigns/functions.php
WooCommerce Custom Fields for Simple & Variable Products
/*
* Add our Custom Fields to simple products
*/
function mytheme_woo_add_custom_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Text Field
@lunule
lunule / add-wordpress-settings-page.php
Created January 14, 2020 09:11 — forked from DavidWells/add-wordpress-settings-page.php
WordPress :: Add Settings Page with All Fields
<?php
/*
Plugin Name: Homepage Settings for BigBang
Plugin URI: http://www.inboundnow.com/
Description: Adds additional functionality to the big bang theme.
Author: David Wells
Author URI: http://www.inboundnow.com
*/
// Specify Hooks/Filters
<?php
$args = array(
'label' => '', // Text in Label
'class' => '',
'style' => '',
'wrapper_class' => '',
'value' => '', // if empty, retrieved from post meta where id is the meta_key
'id' => '', // required
'name' => '', //name will set from id if empty
@lunule
lunule / differentShitByDaytime.php
Last active April 26, 2020 16:00
[Different Shit by Daytime vs Nighttime] Displaying different shit if user's CLIENT's (not OS's which is unaltered even if she's using VPN!!!) current time says it's daytime/nighttime #daytime #nighttime #day #night #daylight #goldenhour #darkness #dark #light #geo #geoip #location #latitude #longitude
<?php
/**
* APIs and jQuery plugins used:
*
* Geo IP Lookup - to get longitude, latitude and time zone data by ip
* https://json.geoiplookup.io/
*
* Suncalc - Calculate Sun/Moon positions and phases
* https://github.com/mourner/suncalc
*
@lunule
lunule / getObjectSize.js
Last active August 20, 2020 20:56
[JavaScript - Get Object Size] #javascript #js #object #array #size #length
/**
* Get Object Size
* ----------------
* Function to validate the existence of each key in the object to get the number of valid keys.
*
* @see https://css-tricks.com/snippets/javascript/get-object-size/
*/
function objectSize(the_object) {
var object_size = 0;
@lunule
lunule / wc_memberships_membership_plan_Obj.txt
Last active July 31, 2020 06:14
[WooCommerce Memberships - membership plan object] #woocommerce-memberships #membership #object
MEMBERSHIP OBJECT
array(1) {
[0]=> object(WC_Memberships_User_Membership)#25232 (18) {
["id"]=> int(1828)
["plan_id"]=> int(1821)
["plan"]=> object(WC_Memberships_Membership_Plan)#25234 (14) {
@lunule
lunule / acf_update_special_field_types.php
Last active July 31, 2020 06:14
[ACF - update_field() for special (and not-so-special) field types] #acf #woocommerce-memberships #update_field #fields
function qsa_update_user_meta($customer_id) {
$cid = $customer_id;
$ms = wc_memberships_get_user_active_memberships( $cid );
if ( ! empty( $ms ) ) :
// We handle the first active membership as The Membership!!
$m = $ms[0];
$mid = $m->plan_id;