Skip to content

Instantly share code, notes, and snippets.

View BhargavBhandari90's full-sized avatar
🏠
Working from home

Bhargav(Bunty) BhargavBhandari90

🏠
Working from home
View GitHub Profile
@BhargavBhandari90
BhargavBhandari90 / image-cropper.php
Created January 29, 2023 18:37
Image Cropper With PLUpload & JCrop
<?php
/**
* Enqueues the css and js required by the Image Crop.
*/
function blp_core_cover_image_scripts() {
wp_enqueue_script( 'jcrop', array( 'jquery' ) );
wp_enqueue_script( 'plupload', array(), false, false );
wp_enqueue_style( 'jcrop' );
}
@BhargavBhandari90
BhargavBhandari90 / image_editor.php
Created January 23, 2023 16:54
WordPress Image Editor
<?php
add_shortcode( 'post_list', 'bunty_shortcode' );
function bunty_shortcode( $attr ) {
ob_start();
include_once ABSPATH . 'wp-admin/includes/image-edit.php';
@BhargavBhandari90
BhargavBhandari90 / user_custom_profile_field.php
Last active January 12, 2023 01:05
Add custom profile field to edit user profile
<?php
/**
* Add user profile extra fields.
*
* @param object $user
* @return void
*/
function buntywp_extra_user_profile_fields( $user ) {
$extra_field = get_user_meta( $user->ID, 'extra_field', true );
@BhargavBhandari90
BhargavBhandari90 / add-tab-user-profile.php
Last active September 23, 2022 18:49
Add tab to user profile
<?php
/**
* Add custom sub-tab on groups page.
*/
function buddyboss_custom_user_tab() {
// Avoid fatal errors when plugin is not available.
if ( ! function_exists( 'bp_core_new_nav_item' ) ||
! function_exists( 'bp_loggedin_user_domain' ) ||
empty( get_current_user_id() ) ) {
@BhargavBhandari90
BhargavBhandari90 / custom_elementor_display_condition.php
Created August 23, 2022 17:32
Set BB groups in elementor Display Conditions
<?php
add_action(
'elementor/theme/register_conditions',
function( $conditions_manager ) {
class Page_Template_Condition extends ElementorPro\Modules\ThemeBuilder\Conditions\Condition_Base {
public static function get_type() {
return 'singular';
}
@BhargavBhandari90
BhargavBhandari90 / get_ip.php
Last active December 23, 2021 19:05
Get IP
<?php
/**
* Function to return ip address
*
* @return string IP Address.
*/
function get_ip_address() {
$ipaddress = '';
if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) {
@BhargavBhandari90
BhargavBhandari90 / acf_custom_setting.php
Created December 14, 2021 18:34
ACF get custom setting.
<?php
/**
* Get custom settings. This works for group type field only.
*
* @param string $tab
* @param string $field
*
* @return void
*/
@BhargavBhandari90
BhargavBhandari90 / add_http_auth.php
Created December 6, 2021 09:21
Add HTTP auth to perticular file PHP.
<?php
// Http auth start.
$valid_passwords = array( 'bunty' => 'Bunty@123' ); // Key is username and value is password.
$valid_users = array_keys( $valid_passwords ); // Get all usernames from $valid_passwords array.
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
// Check if user is valid.
$validated = ( in_array( $user, $valid_users ) ) && ( $pass == $valid_passwords[ $user ] );
@BhargavBhandari90
BhargavBhandari90 / acf_timezone.php
Last active November 28, 2021 11:29
Add custom ACF field type - ACF Timezone field type
<?php
class acf_field_timezone extends acf_field {
/*
* __construct
*
* This function will setup the field type data
*
@BhargavBhandari90
BhargavBhandari90 / dynamic_option_acf.php
Created November 28, 2021 07:48
Dynamic options for ACF field
<?php
/**
* Set user roles as an option.
*
* @param array $field
* @return array
*/
function load_roles( $field ) {