Skip to content

Instantly share code, notes, and snippets.

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

Deepak Gupta raftaar1191

🏠
Working from home
View GitHub Profile
@raftaar1191
raftaar1191 / functions.php
Created May 31, 2024 10:35
Limit search results to WooCommerce Products only in frontend
/**
* Only allow the product CPT to be search on the golbal search page
*
* @param WP_Query $query The WP_Query instance (passed by reference).
*/
function tometal_filter_search_only_products( $query ) {
if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
$query->set( 'post_type', 'product' );
}
@raftaar1191
raftaar1191 / functions.php
Last active May 30, 2024 09:18
Get Draft post for non login user as well via WP REST API
/**
* Filter to alter the rest_query args to add draft and filter
*
* @param array $args Array of arguments for WP_Query.
* @param WP_REST_Request $request The REST API request.
*
* @return array $args Array of arguments for WP_Query.
*/
function lubus_custom_allow_drafts_in_rest_query( $args, $request ) {
@raftaar1191
raftaar1191 / functions.php
Created May 30, 2024 07:51
Generate the post slug for the draft testimonial (CPT) as well
/**
* Generate the post slug for the draft post as well
*
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
* @param bool $update Whether this is an existing post being updated.
**/
function lubus_generate_slug_for_draft_post( $post_id, $post, $update ) {
// If the post is a draft and has no slug.
@raftaar1191
raftaar1191 / functions.php
Created April 19, 2024 15:04
Only show the admin user list when deleting a user and assing his content
function delete_user_account( $query_args ) {
// Use this array to specify multiple roles to show in dropdown
$query_args['role__in'] = array( 'administrator' );
// Unset the 'who' as this defaults to the 'author' role
unset( $query_args['who'] );
return $query_args;
}
@raftaar1191
raftaar1191 / pretty-link-creation.php
Created April 1, 2024 05:50 — forked from DumahX/pretty-link-creation.php
Creating new pretty links through code
@raftaar1191
raftaar1191 / functions.php
Created October 18, 2023 07:02
How can I limit the activity feed to show 10 posts, then the load more appears?
function limit_activities_displayed( $retval ) {
$isMob = is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "mobile"));
if ($isMob) {
$retval['per_page'] = 15;
}
else {
$retval['per_page'] = 5;
}
return $retval;
}
@raftaar1191
raftaar1191 / functions.php
Created October 12, 2023 08:28
Fix for Not able to comment on Other User Activity Post in PHP version 8.2
remove_action( 'bp_activity_after_email_content', 'bb_gif_activity_after_email_content' );
@raftaar1191
raftaar1191 / functions.php
Created October 11, 2023 08:53
Change/Update place holder of the login input of BuddyBoss login page
/**
* Update the place holder into the login page
*/
function acrosswp_custom_bb_login_head_callback() {
?>
<script>
jQuery( document ).ready( function ($) {
jQuery( 'form#loginform #user_login' ).attr( 'placeholder', "Custom Email" );
});
@raftaar1191
raftaar1191 / functions.php
Created October 4, 2023 06:56
Do not allow activity to get posted without any Media
/**
* Add content into the post
*/
function acrosswp_nouveau_ajax_post_update_custom() {
if ( ! is_user_logged_in() || empty( $_POST['_wpnonce_post_update'] ) || ! wp_verify_nonce( $_POST['_wpnonce_post_update'], 'post_update' ) ) {
wp_send_json_error();
}
// check activity toolbar options if one of them is set, activity can be empty.
@raftaar1191
raftaar1191 / courses-courses.php
Last active September 6, 2023 12:45
Courses page in Group show the 1 courses in listing format not like a single page courses format
<?php
$ld_group_id = bp_ld_sync( 'buddypress' )->helpers->getLearndashGroupId( bp_get_current_group_id() );
if ( $ld_group_id ) {
$post_label_prefix = 'group';
$meta = learndash_get_setting( $ld_group_id );
$post_price_type = ( isset( $meta[ $post_label_prefix . '_price_type' ] ) ) ? $meta[ $post_label_prefix . '_price_type' ] : '';
$post_price = ( isset( $meta[ $post_label_prefix . '_price' ] ) ) ? $meta[ $post_label_prefix . '_price' ] : '';
// format the Course price to be proper XXX.YY no leading dollar signs or other values.