Skip to content

Instantly share code, notes, and snippets.

@mahfelwp
mahfelwp / yz_include_members_directory_by_verified.php
Last active February 3, 2020 10:09
Include users only with "yz_account_verified" ##meta_key and "on" ##meta_value on members directory at Youzer plugin and also buddypress
<?php
/**
* Members Directory - Include Users By Meta_key & Meta_value
*/
function yz_include_members_directory_by_verified( $loop ) {
if ( ! bp_is_members_directory() ) {
return $loop;
}
@mahfelwp
mahfelwp / remove_action_from_class.php
Created April 18, 2019 21:23
Access to Private Property of Class And Remove Action From Class
<?php
/**
* Access to Private Property of Class And Remove Action From Class
* add_action pirority is very important => 9
*/
function remove_action_from_class(){
global $Youzer;
$myClassReflection = new ReflectionClass( get_class( $Youzer ) );
$secret = $myClassReflection->getProperty('instance');
$secret->setAccessible(true);
@mahfelwp
mahfelwp / add_new_column_to_plugin_table_in_new_version.php
Last active June 3, 2019 15:43
Add new column to plugin table in new version
<?php
final class Plugin_Name {
private function __construct() {
register_activation_hook( __FILE__, array( $this, 'plugin_activation' ) );
}
public function plugin_activation() {
if ( get_option( 'plugin_version' ) != PLUGIN_VERSION ) {
@mahfelwp
mahfelwp / bp_force_user_to_set_profile_avatar.php
Created June 23, 2019 09:50
Force user to choose pic for profile avatar in buddypress
<?php
function bp_force_user_to_set_profile_avatar() {
if ( ! is_user_logged_in() ) {
return;
}
$user_id = get_current_user_id();
if ( ! bp_get_user_has_avatar( $user_id ) && bp_current_action() != 'change-avatar' ) {
@mahfelwp
mahfelwp / yz_verified_users_count_shortcode.php
Created June 23, 2019 09:54
Verified users count shortcode in Youzer plugin
<?php
function yz_verified_users_count_shortcode( $atts = null ){
global $wpdb;
// Get Args.
$args = shortcode_atts(
array(
'verified' => 'on',
), $atts, 'yz_verified_users_count' );
@mahfelwp
mahfelwp / display_random_vip_users.php
Last active March 30, 2020 14:56
display random vip users (by subscription level on Restrict Content Pro)
<?php
function random_user_query( &$query )
{
$query->query_orderby = "ORDER BY RAND()";
}
function display_random_vip_users( $atts ) {
@mahfelwp
mahfelwp / get_all_users_id_with_custom_subscription_level.php
Created June 24, 2019 09:22
Get all users id with custom subscription(membership) level
<?php
function get_all_users_id_by_membership_level_id() {
$memberships = rcp_get_memberships( array(
'status' => 'active',
'object_id' => 2 // Membership Levels ID
) );
foreach ($memberships as $membership) {
<?php
$countries = array (
"افغانستان",
"جزایر آلند",
"آلبانی",
"الجزایر",
"ساموای آمریکا",
"آندورا",
"آنگولا",
"آنگویلا",
@mahfelwp
mahfelwp / parseUrl.js
Last active September 29, 2019 18:18
Simple function for work with Url in Javascript without regxp
// For more information you can see this url: https://developer.mozilla.org/en-US/docs/Web/API/URL
let parseUrl = (url) => {
let parser = document.createElement('a');
parser.href = url;
return parser;
}
let url = parseUrl("http://username:[email protected]:3000/deploy/?search=test#hash");
url.protocol; // => "http:"
@mahfelwp
mahfelwp / convert.php
Created January 24, 2020 22:01
Convert activity product date to shamsi(jalali) - youzer plugin
<?php
function convert_activity_product_date_to_shamsi($args , $product){
if( ! function_exists('parsidate') || get_locale() != 'fa_IR' ) {
return false;
}
$args['date'] = parsidate("Y-m-d", $product->get_date_created()->format( 'F j, Y' ), "per");
return $args;