Skip to content

Instantly share code, notes, and snippets.

View kprajapatii's full-sized avatar

Kiran Prajapati kprajapatii

View GitHub Profile
@kprajapatii
kprajapatii / gd-kadence-template-fix.php
Last active March 29, 2022 07:51
GeoDirectory + Kadence Template Fix (file \themes\kadence\inc\components\layout\component.php)
public static function check_conditionals() {
$boxed = 'boxed';
$layout = 'normal';
$feature = 'hide';
$f_position = 'above';
$comments = 'hide';
$navigation = 'hide';
$title = 'normal';
$sidebar = 'disable';
$sidebar_id = static::PRIMARY_SIDEBAR_SLUG;
@kprajapatii
kprajapatii / userwp-logo-for-gd-post.php
Created August 21, 2020 10:58
Show logo in UsersWP profile listings tab for GeoDirectory posts.
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $post;
$user = uwp_get_displayed_user();
if ( has_post_thumbnail() ) {
$thumb_url = get_the_post_thumbnail_url( get_the_ID(), 'medium' );
} else {
@kprajapatii
kprajapatii / geodir-disable-bayesian-average-rating-sorting.php
Created June 11, 2020 15:18
Disable Bayesian average method to sort by ratings.
/**
* Disable Bayesian average method to sort by ratings.
*
* See https://www.google.com/search?q=bayesian+rating+sorting
*/
function gd_snippet_200611_disable_use_bayesian( $use_bayesian = true, $table = '' ) {
return false;
}
add_filter( 'geodir_use_bayesian', 'gd_snippet_200611_disable_use_bayesian', 10, 2 );
add_filter( 'gd_use_bayesian', 'gd_snippet_200611_disable_use_bayesian', 10, 2 );
@kprajapatii
kprajapatii / geodir-add-listing-prevent-specific-roles.php
Last active May 30, 2020 11:08
GeoDirectory: Prevent specific users roles to access add listing page (use any one snippet).
/**
* Prevent specific users roles to access add listing page.
*/
function gd_snippet_200530_prevent_add_listing( $output, $args, $widget_args, $content ) {
$role_to_hide = 'subscriber'; // User role prevented to add listing.
if ( ( $current_user = wp_get_current_user() ) ) {
if ( ! empty( $current_user ) && ! empty( $current_user->roles ) && in_array( $role_to_hide, $current_user->roles ) ) {
$output = __( 'You are not allowed to add a listing!', 'geodirectory' );
@kprajapatii
kprajapatii / geodir_shortcode_show_geodir_here_links.php
Created May 29, 2020 14:13
[geodir_shortcode_show_geodir_here_links]
@kprajapatii
kprajapatii / geodir-prevent-email-phone-in-description.php
Last active May 27, 2020 04:57
GeoDirectory: Prevent email & phone in add listing description.
/**
* Prevent email & phone in add listing description.
*/
function gd_snippet_200525_prevent_email_phone_in_description() {
if ( ! geodir_is_page( 'add-listing' ) ) {
return;
}
?>
<script type="text/javascript">
jQuery(function($) {
@kprajapatii
kprajapatii / geodir-pull-address-from-last-post.php
Created May 22, 2020 05:26
For new listing pull address data from last post created by user.
/**
* For new listing pull address data from last post created by user.
*/
function gd_snippet_200522_data_from_last_post( $html, $field ) {
global $wpdb, $post, $gd_post;
if ( ! empty( $gd_post ) && empty( $gd_post->street ) && empty( $gd_post->latitude ) && empty( $gd_post->longitude ) && ( $user_id = get_current_user_id() && geodir_is_page( 'add-listing' ) && ! empty( $gd_post->post_status ) && $gd_post->post_status == 'auto-draft' && ! empty( $gd_post->post_type ) && geodir_is_gd_post_type( $gd_post->post_type ) && GeoDir_Post_types::supports( $gd_post->post_type, 'location' ) ) ) {
$table = geodir_db_cpt_table( $gd_post->post_type );
$_gd_post = $wpdb->get_row( "SELECT * FROM `{$table}` AS pd INNER JOIN `{$wpdb->posts}` AS p ON p.ID = pd.post_id WHERE ( p.post_status = 'publish' OR p.post_status = 'pending' ) ORDER BY pd.post_id DESC LIMIT 1" );
/**
* Delete Unused Image Sizes.
*
* - Go to yoursite.com/?__check_image_sizes=1
* - Click on DELETE NOW
*
* NOTE: TAKE BACKUP FIRST
*/
function gd_snippet_check_image_sizes() {
global $wpdb;
@kprajapatii
kprajapatii / GeoDirectory-export-fix-ambiguous_post_category.php
Created November 8, 2019 05:36
[GeoDirectory] Fix database error "WordPress database error Column 'post_category' in field list is ambiguous for query"
/**
* CSV Export: Fix database error "WordPress database error Column 'post_category' in field list is ambiguous for query".
*/
function gd_snippet_20190827_imex_export_posts_query( $query, $post_type ) {
$table = geodir_db_cpt_table( $post_type );
$query = str_replace( ",post_category", ",{$table}.post_category", $query );
$query = str_replace( ",`post_category`", ",`{$table}`.`post_category`", $query );
return $query;
@kprajapatii
kprajapatii / [GeoDirectory] Create event from data via script.php
Last active November 8, 2017 22:39
[GeoDirectory] Create event from data via script
<?php
function _gd_custom_create_event_from_data() {
global $wpdb, $gd_session;
$gd_post = array();
$gd_post['post_type'] = 'gd_event';
$gd_post['status'] = 'publish';
$gd_post['title'] = 'Italian Market Festival';
$gd_post['content'] = 'There is so much great eating in and around the Italian Market that you will want to return again and again.';