Skip to content

Instantly share code, notes, and snippets.

Andrija dev-masta

Block or report user

Report or block dev-masta

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dev-masta
dev-masta / mepr-active-memberships.php
Created Sep 5, 2018
Get a list of the current user's active MemberPress Subscriptions
View mepr-active-memberships.php
<?php
function memberpress__get_all_memberships( $user_id = false ){
if( class_exists('MeprUser') ){
if( ! $user_id ){
$user_id = get_current_user_id();
}
@dev-masta
dev-masta / example.php
Created Sep 3, 2018
WP MemberPress - get list of memberships that can access a restricted content
View example.php
<?php
$the_post_object = get_post( $post_id );
$access_list = MeprRule::get_access_list( $the_post_object );
$product_ids = (isset($access_list['membership']) && !empty($access_list['membership'])) ? $access_list['membership'] : array();
/*
$acces_list returns: ["membership" => [1,2], "member" =>["foo"]]
$products_ids contains an array of Membership IDs that can access this content
@dev-masta
dev-masta / write_log.php
Created Sep 3, 2018
Short WP function that is used to output custom data to debug.log
View write_log.php
<?php
function write_log ( $log, $text = "write_log: ", $delete = false ) {
if( $delete ){
unlink( WP_CONTENT_DIR . '/debug.log' );
}
if ( is_array( $log ) || is_object( $log ) ) {
error_log( $text . PHP_EOL . print_r( $log, true ) );
@dev-masta
dev-masta / enqueue.php
Last active Aug 26, 2018
My way to enqueue scripts in WordPress and load from cache only if the file is not changed
View enqueue.php
<?php
// In plugins
// ----------
$and_js_ver = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'js/main.js' ));
wp_enqueue_script( 'and_js', plugins_url( 'js/main.js', __FILE__ ), array(), $and_js_ver );
$and_css_ver = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'style.css' ));
wp_register_style( 'and_css', plugins_url( 'style.css', __FILE__ ), array(), $and_css_ver );
@dev-masta
dev-masta / bayesian.sql
Last active Aug 14, 2016
The Bayesian estimate formula useful for sorting the ratings properly
View bayesian.sql
/*
The problem is described here: http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
And the formula is from IMDB: http://stackoverflow.com/a/1411268/5108832
It's a Bayesian estimate.
This is the formula that is used to sort the ratings:
( (avg_num_votes * avg_rating) + (this_num_votes * this_rating) ) / (avg_num_votes + this_num_votes)
In this example, the sample data are 9 posts (much like the WordPress posts) with a 5 star ratings.
You can’t perform that action at this time.