Skip to content

Instantly share code, notes, and snippets.

View aslamdoctor's full-sized avatar
💭
Always working but happy to talk 👍

Aslam Doctor aslamdoctor

💭
Always working but happy to talk 👍
View GitHub Profile
@aslamdoctor
aslamdoctor / wordpress-cf7-mail-tag.php
Created January 5, 2022 10:43
Snippet : Add dynamic data to Contact form 7 email
<?php
add_filter('wpcf7_special_mail_tags', 'add_prospectus_link_to_email', 10, 3);
function add_prospectus_link_to_email($output, $name, $html)
{
$name = preg_replace('/^wpcf7\./', '_', $name); // for back-compat
if ('prospectus' == $name) {
$prospectus = get_field('prospectus', 'options');
return $prospectus['url'];
}
@aslamdoctor
aslamdoctor / xampp-mysql-fix.txt
Created October 12, 2021 01:06
XAMPP MySQL Shutdown Fix
1. Rename the folder `mysql/data` to `mysql/data_old` (you can use any name)
2. Create a new folder `mysql/data`
3. Copy the content that resides in `mysql/backup` to the new `mysql/data` folder
4. Copy all your database folders that are in `mysql/data_old` to `mysql/data` (skipping the mysql, performance_schema, and phpmyadmin folders from data_old)
5. Finally copy the `ibdata1` and `my.ini` files from `mysql/data_old` and replace it inside `mysql/data` folder
6. Start MySQL from XAMPP control panel
@aslamdoctor
aslamdoctor / youtube_id_from_url.php
Created October 11, 2021 15:51 — forked from ghalusa/youtube_id_regex.php
Extract the YouTube Video ID from a URL in PHP
<?php
// Here is a sample of the URLs this regex matches: (there can be more content after the given URL that will be ignored)
// http://youtu.be/dQw4w9WgXcQ
// http://www.youtube.com/embed/dQw4w9WgXcQ
// http://www.youtube.com/watch?v=dQw4w9WgXcQ
// http://www.youtube.com/?v=dQw4w9WgXcQ
// http://www.youtube.com/v/dQw4w9WgXcQ
// http://www.youtube.com/e/dQw4w9WgXcQ
// http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcQ
@aslamdoctor
aslamdoctor / wordpress-sort-by-stock.php
Created September 29, 2021 14:05
Snippet : Woocommerce show out of stock orders last
<?php
add_action( 'pre_get_posts', function( $query ) {
if ( $query->is_main_query() && is_woocommerce() && ( is_shop() || is_product_category() || is_product_tag() ) ) {
if( $query->get( 'orderby' ) == 'menu_order title' ) { // only change default sorting
$query->set( 'orderby', 'meta_value' );
$query->set( 'order', 'ASC' );
$query->set( 'meta_key', '_stock_status' );
}
}
});
@aslamdoctor
aslamdoctor / wordpress-ajax-add-to-cart.md
Last active August 28, 2021 03:32
Snippet: Woocommerce Ajax add to cart
// Ajax add to cart on the product page
var $warp_fragment_refresh = {
    url: wc_cart_fragments_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'get_refreshed_fragments' ),
    type: 'POST',
    success: function( data ) {
        if ( data && data.fragments ) {

            $.each( data.fragments, function( key, value ) {
                $( key ).replaceWith( value );
@aslamdoctor
aslamdoctor / wordpress-change-blog-permalinks.php
Created August 25, 2021 11:43
Snippet: Change blog permalinks in WordPress
@aslamdoctor
aslamdoctor / wordpress-upscale-images.php
Created August 25, 2021 11:42
Snippet: Upscale images in WordPress
<?php
/* Thumbnail upscale
/* ------------------------------------ */
function wpmix_thumbnail_upscale( $default, $orig_w, $orig_h, $new_w, $new_h, $crop ){
if ( !$crop ) return null; // let the wordpress default function handle this
$aspect_ratio = $orig_w / $orig_h;
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
$crop_w = round($new_w / $size_ratio);
@aslamdoctor
aslamdoctor / wordpress-navwalker.php
Last active July 24, 2023 15:12
Snippet: Nav walker class in WordPress
<?php
class Topmenu_Walker extends Walker_Nav_Menu {
// Displays start of an element. E.g '<li> Item Name'
function start_el(&$output, $item, $depth=0, $args=array(), $id = 0) {
$object = $item->object;
$type = $item->type;
$title = $item->title;
$description = $item->description;
$permalink = $item->url;
@aslamdoctor
aslamdoctor / wordpress-setup-widgets.php
Last active August 17, 2021 07:37
Snippet : Setup Widgets in WordPress
<?php
// Setup Widgets
function wpmix_widgets(){
register_sidebar(array(
'name' => __('Sidebar Widgets','wpmix'),
'id' => 'wpmix_sidebar-widgets',
'description' => __('These are widgets for the sidebar.', 'wpmix'),
'before_widget' => '<div id="%1$s" class="the-widget %2$s col-md-4">',
'after_widget' => '</div>',
@aslamdoctor
aslamdoctor / wordpress-filter-search.php
Created August 17, 2021 07:14
Snippet : Filter Search result in WordPress
<?php
//========== Filter Search result ==========
function wpmix_search_filter($query) {
/* if ($query->is_search) {
$query->set('post_type', array('post'));
} */
return $query;
}
add_filter( 'pre_get_posts', 'wpmix_search_filter' );