Skip to content

Instantly share code, notes, and snippets.

View pbrocks's full-sized avatar

Paul Barthmaier pbrocks

View GitHub Profile
@pbrocks
pbrocks / code.js
Created July 5, 2018 22:21 — forked from MaruscaGabriel/code.js
DIVI theme JavaScript code snippets
//Open external links into new tab
<script type="text/javascript">
jQuery('a').filter(function () {
return this.hostname != window.location.hostname;
}).attr('target', '_blank');
</script>
//Adding Fly-in Animations To Any Divi Section, Row and Module
//thanks to Gino Quiroz : https://quiroz.co/adding-fly-in-animations-to-any-divi-module/
//Below are the CSS Class groups for each animation.
@pbrocks
pbrocks / customizer-links.php
Created July 5, 2018 22:19 — forked from slushman/customizer-links.php
How to link into the WordPress Customizer
<?php
//phpDoc for new PMPro function
/**
* A description of what the function does.
*
* @param {array, string, int, objext} {$variable_name} {Short description}
* @return {array, string, int, mixed, object} {$variable_name} {Short description}
*
* {@internal Any To-Dos etc.}
*
@pbrocks
pbrocks / a-notification-bar-for-limit-post-view.php
Created June 29, 2018 10:14
Used in conjunction with the PMPro Limit Post Views Add On, this recipe adds a notification bar to the bottom of the webpage which shows the number of remaining articles.
<?php
/**
* Notification bar when post views are being tracked and restricted by the Limit Post Views Add On
*/
function a_notification_bar_for_limit_post_view() {
// Check for past views. Needs to check if the post is locked at all by default.
if ( isset( $_COOKIE['pmpro_lpv_count'] ) ) {
global $current_user;
// Check cookie for views value.
@pbrocks
pbrocks / customize-pmpro-login-redirect-url.php
Created June 28, 2018 16:36
Redirect your members based on their PMPro subscription level. If any users aren't members, the site's home url is returned.
<?php
/**
* customize_pmpro_login_redirect_url Creates conditions for each level to have its own confirmation URL
*
* @param [type] $return_url Different URL for each level
* @param [type] $request URL the user is coming from, ie login url.
* @param [type] $user user data
* @return [type] The URL of the level for user logging in
*/
function customize_pmpro_login_redirect_url( $return_url, $request, $user ) {
@pbrocks
pbrocks / test-php-session-vars.php
Last active June 21, 2018 16:19 — forked from ideadude/test_php_session_vars.php
Test if PHP Session Variables are working.
<?php
session_start();
/**
* Test if PHP Session Variables are working.
* Step 1: Add this code into a custom plugin or in a PHP file you know is being executed.
* Step 2: Navigate to /?test=123. You should see a blank old value and 123 as the new value.
* Step 3: Navigate to /?test=456. You should see 123 as the old value and 456 as the new value.
* If you see a blank old value again, that means that session variables are not enabled or otherwise broken.
* If the timestamp at the top is not being updated, the page may be cached.
* Step 4: Remove this code.
@pbrocks
pbrocks / pmpro-hide-acf-fields.php
Last active June 18, 2018 15:15 — forked from kimcoleman/pmpro_hide_acf_fields.php
This code will filter ACF fields added to custom templates using the post's membership requirements.
<?php
/**
* pmpro_hide_acf_fields This code will filter ACF fields added to custom templates using the post's membership requirements.
*
* Add this code to your PMPro Customizations Plugin
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*
* https://www.advancedcustomfields.com/resources/acf-format_value/
*
* @param mixed $value Value which was loaded from the database
@pbrocks
pbrocks / pmpro-replacement-login-redirect.php
Created June 13, 2018 23:55
Replacement redirect for logins after TML update. This recipe will redirect PMPro admins to dashboard reports, single out subscribers to go to the Account page and everyone else to the Invoice page.
<?php
/**
* Redirect user based on user role after successful login.
*
* $pmpro_pages returns an array:
* * $pmpro_pages['account']
* * $pmpro_pages['billing']
* * $pmpro_pages['cancel']
* * $pmpro_pages['checkout']
* * $pmpro_pages['confirmation']
@pbrocks
pbrocks / pmpro-neato-account-page.php
Created June 11, 2018 06:31
Using this recipe, you can easily customize your membership account page by replacing the [pmpro_account] with [pmpro-neato-account-page]. To select to show only certain sections, add the sections to the shortcode, as in [pmpro-neato-account-page sections="membership,profile"/]
<?php
/**
* Create a custom shortcode to show membership account information
*
* Add this code to your PMPro Customizations Plugin - For more info on this visit:
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function pmpro_shortcode_account_customized( $atts, $content = null, $code = '' ) {
global $wpdb, $pmpro_msg, $pmpro_msgt, $pmpro_levels, $current_user, $levels;
@pbrocks
pbrocks / pmpro-core-views-report-reset.php
Created June 5, 2018 05:28
Use this recipe to reset your PMPro site's Logins and Views Report data.
<?php
/**
* Place this code in your Customizations plugin, not including the opening php tag on line 1.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
/**
* Create a menu to give us a place to perform the reset. I'm choosing a Dashboard menu purely for ease of access.
*/
add_action( 'admin_menu', 'core_reset_views_admin_page' );
function core_reset_views_admin_page() {