Skip to content

Instantly share code, notes, and snippets.

View Alimir's full-sized avatar
👀
looking for purest...

Ali Mirzaei Alimir

👀
looking for purest...
View GitHub Profile
@Alimir
Alimir / wp-ulike-pro.php
Last active December 12, 2020 20:31
wp ulike activity comment filter
<?php
function wp_ulike_pro_activity_comment_filter( $content, $wp_ulike_query, $query_args ){
global $wpdb;
if ( is_multisite() ) {
$bp_prefix = 'base_prefix';
} else {
$bp_prefix = 'prefix';
}
@Alimir
Alimir / wp-ulike.php
Last active December 12, 2020 20:32
wp ulike medipress example
<?php
//show it on single media page
add_action( 'mpp_media_meta', 'mpp_wpulike_show_button' );
//show it in lightbox
add_action( 'mpp_lightbox_media_meta', 'mpp_wpulike_show_button' );
function mpp_wpulike_show_button() {
echo wp_ulike('put');
}
@Alimir
Alimir / wp-ulike.php
Last active December 12, 2020 20:32
wp ulike custom hreview
<?php
function wp_ulike_pro_custom_hreview( $content ){
global $post;
if( is_singular() && 0 != ( $counter = wp_ulike_get_post_likes( $post->ID ) ) ){
$content .= sprintf('<div style="display:none" class="hreview-aggregate">
<div class=item>
<p class="fn">%s</p>
</div>
@Alimir
Alimir / wp-ulike.php
Last active December 12, 2020 20:32
wp ulike midnight restrict
<?php
function wp_ulike_pro_custom_stop_listener(){
date_default_timezone_set('Europe/Berlin');
$current_time = date("h:i a");
$begin = "09:00 am";
$end = "11:00 pm";
$date1 = DateTime::createFromFormat('H:i a', $current_time);
$date2 = DateTime::createFromFormat('H:i a', $begin);
@Alimir
Alimir / wp-ulike.php
Last active December 12, 2020 20:33
wp ulike user category restict
<?php
function wp_ulike_pro_custom_stop_listener( $id, $type ){
$categories = get_the_terms( $id, 'category' );
$terms_array = wp_list_pluck($categories, 'slug');
$current_user = get_current_user_id();
if( ! $current_user ){
return;
@Alimir
Alimir / wp-ulike.php
Created December 12, 2020 20:34
wp ulike restrict user cookie
<?php
function wp_ulike_pro_custom_restrict_user( $args ){
$settings_type = new wp_ulike_setting_type( $args['type'] );
if( isset( $_COOKIE ) ){
foreach( $_COOKIE as $key => $val ){
if( strpos( $key, $settings_type->getCookieName() ) !== false) {
throw new \Exception( WP_Ulike_Pro_Options::getNoticeMessage( 'invalid_permission', 'sample permission message' ) );
}
@Alimir
Alimir / wp-ulike.php
Last active December 12, 2020 20:35
wp ulike custom query for top activities
<?php
function wpulike_custom_activity_shortcode ( $atts ) {
global $wpdb;
if ( is_multisite() ) {
$bp_prefix = 'base_prefix';
} else {
$bp_prefix = 'prefix';
}
@Alimir
Alimir / wp-ulike.php
Created December 12, 2020 20:38
add wp ulike button in elementor top posts widget
<?php
// Add custom id for elementor top posts widget query, and then put it in sample hook. e.g.
// "elementor/query/custom_query_id"
function wp_ulike_pro_add_custom_button_to_widget( $data, $widget ){
add_filter( 'the_excerpt', function( $content ){
return $content . do_shortcode('[wp_ulike]');
}, 10 );
}
add_action( "elementor/query/custom_query_id", 'wp_ulike_pro_add_custom_button_to_widget', 10, 2 );
@Alimir
Alimir / wp-ulike.php
Created December 20, 2020 14:11
wp ulike filter content auto display by category
<?php
function wp_ulike_custom_content_filter( $button, $content ){
if ( in_the_loop() && is_main_query() && is_singular() && has_category( array('uncategorized') ) ){
return $button;
}
return $content;
}
add_filter( 'wp_ulike_the_content', 'wp_ulike_custom_content_filter', 2, 10 );
@Alimir
Alimir / wp-ulike.php
Created December 20, 2020 15:20
Hide auto display on certain pages in WP ULike
<?php
function wp_ulike_custom_content_filter( $button, $content ){
if ( in_the_loop() && is_main_query() && is_page( array( 'terms-of-service', 'privacy-policy', 'contact', 'about' ) ) ){
return $content;
}
return $button;
}
add_filter( 'wp_ulike_the_content', 'wp_ulike_custom_content_filter', 2, 10 );