Skip to content

Instantly share code, notes, and snippets.

View jcamp's full-sized avatar

Jonathan jcamp

View GitHub Profile
@jcamp
jcamp / next_last_payment_dates_members_list.php
Created May 27, 2021 09:52 — forked from kimcoleman/next_last_payment_dates_members_list.php
Adds last payment date and next payment date to the members list and export CSV in Paid Memberships Pro (PMPro).
<?php
/**
* Adds last payment date and next payment date to the members list and export CSV.
* Note that "last payment" value will get the last order in "success", "cancelled", or "" status. (Oddly enough, cancelled here means that the membership was cancelled, not the order.)
*
* The "next payment" value is an estimate based on the billing cycle of the subscription and the last order date. It may be off from the actual recurring date set at the gateway, especially if the subscription was updated at the gateway.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
@jcamp
jcamp / get-image-urls.js
Created May 26, 2020 10:13 — forked from tobek/get-image-urls.js
Save images from chrome inspector/dev tools network tab
/* open up chrome dev tools (Menu > More tools > Developer tools)
* go to network tab, refresh the page, wait for images to load (on some sites you may have to scroll down to the images for them to start loading)
* right click/ctrl click on any entry in the network log, select Copy > Copy All as HAR
* open up JS console and enter: var har = [paste]
* (pasting could take a while if there's a lot of requests)
* paste the following JS code into the console
* copy the output, paste into a text file
* open up a terminal in same directory as text file, then: wget -i [that file]
*/
@jcamp
jcamp / nav_goback.js
Created August 15, 2018 14:07
Simulate a goback link for navigation (jQuery)
$(document).ready(function(){
$('a.back').click(function(){
parent.history.back();
return false;
});
});
@jcamp
jcamp / write_log.php
Created August 13, 2018 16:45
Very simple logging to a file by calling 'write_log' in our php code (wordpress edition)
<?php
// Taken pretty much from https://www.elegantthemes.com/blog/tips-tricks/using-the-wordpress-debug-log
// error_log info on php site - http://php.net/manual/en/function.error-log.php
// Just stick this function in your functions.php if you like :)
if ( ! function_exists('write_log')) {
function write_log ( $log ) {
if ( is_array( $log ) || is_object( $log ) ) {
// error_log - Sends an error message to the web server's error log or to a file.
error_log( print_r( $log, true ) );
@jcamp
jcamp / functions_enqueue_child_theme.php
Created August 13, 2018 16:40
Wordpress enqueue styles with child styles (takes into account Bootstrap in this case load bootstrap and then override)
<?php
// Basically we need to make sure we load ALL our stylesheets for our child theme AFTER bootstrap
// that way we can override bootstrap without using crappy !important overrides, etc.
// This sample uses the transportex theme but just replace that for your own theme.
function my_theme_enqueue_styles() {
$parent_style = 'transportex-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
@jcamp
jcamp / show_hide_cookie_law.html
Created August 3, 2018 10:28
Show and hide cookie law using cookies
@jcamp
jcamp / ajax_form_submit.js
Last active August 3, 2018 10:24
Use Ajax to check form fields and submit
var isHttps = location.protocol.match(/https/);
var http = isHttps ? 'https://' : 'http://';
var site_url = http + location.host + '/yoursite';
$(function(){
$('#form-btn').on('click',function(event){
var email_test = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var form_name = $('#form-name').val();
var form_email = $('#form-email').val();
@jcamp
jcamp / http_or_not.js
Created August 3, 2018 10:18
Check and set js variable if running http or https
var isHttps = location.protocol.match(/https/);
var http = isHttps ? 'https://' : 'http://';
var site_url = http + location.host + '/webpage';
@jcamp
jcamp / limittext.php
Created July 25, 2018 14:41
PHP function - Truncate string to a number of words and add elipse for read more...
<?php
function limit_text($text, $limit) {
if (str_word_count($text, 0) > $limit) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$limit]) . '...';
}
return $text;
}
@jcamp
jcamp / add_custom_types.php
Created July 7, 2018 10:47 — forked from barbwiredmedia/add_custom_types.php
Wordpress_Make Archives.php Include Custom Post Types - Archives.php only shows content of type 'post', but you can alter it to include custom post types. http://css-tricks.com/snippets/wordpress/make-archives-php-include-custom-post-types/
//functions.php
function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'your-custom-post-type-here'
));
return $query;
}
}