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 / 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 ) {
@BhargavBhandari90
BhargavBhandari90 / acf_setting_page.php
Last active October 25, 2021 13:37
Add Setting page for ACF
<?php
/**
* Add Setting page for ACF
*
* @return void
*/
function buntywp_acf_setting_pages() {
// Bail, if anything goes wrong.
@BhargavBhandari90
BhargavBhandari90 / change_rest_api_reposne.php
Last active July 30, 2021 17:28
Change REST API Response in WordPress
<?php
/**
* Change the REST response
*
* @param object $rest_ensure_response
* @param object $instance
* @param object $request
* @return object
*/
@BhargavBhandari90
BhargavBhandari90 / body_class_filter.php
Last active July 8, 2021 17:29
Add class to body in WordPress
<?php
function wp_custom_body_class( $classes ) {
if ( is_single() ) {
$classes[] = 'buntywp';
}
return $classes;
}
@BhargavBhandari90
BhargavBhandari90 / add_protocol_in_post_content.php
Last active December 12, 2020 09:23
Add a protocol to URLs from WordPress post content
<?php
/**
* Fix the URLs from the content.
*
* This function will add protocol to URLs which has no protocol added.
*
* For example,
*
* google.com --> http://google.com
@BhargavBhandari90
BhargavBhandari90 / change_tab_lable_bb.php
Created November 24, 2020 14:16
Change Profile Tab Labels of BuddyPress/BuddyBoss
<?php
/**
* Change label to Followed for Suscriptions.
*
* @return void
*/
function bb_forum_profile_menu_tabs() {
// Handle fatal error in case of plugin not available