This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function memberpress__get_all_memberships( $user_id = false ){ | |
if( class_exists('MeprUser') ){ | |
if( ! $user_id ){ | |
$user_id = get_current_user_id(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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. |