Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Always working but happy to talk 👍

Aslam D aslamdoctor

💭
Always working but happy to talk 👍
View GitHub Profile
@aslamdoctor
aslamdoctor / wordpress-transient-api-example.php
Created Jun 11, 2022
Snippet : WordPress Transient API Usage Example
View wordpress-transient-api-example.php
<?php
// Get only those services that has people assigned and store them into cache
if ( false === ( $available_services_array = get_transient( 'available_services_array' ) ) ) {
$available_services_array = array();
$services = new WP_Query(
array(
'post_type' => array( 'service' ),
'posts_per_page' => '500',
'post_status' => array( 'publish' ),
'order' => 'ASC',
@aslamdoctor
aslamdoctor / wordpress-debug-ajax.php
Created Jun 8, 2022
Snippet : Debug ajax response by calling it from browser url
View wordpress-debug-ajax.php
<?php
add_action( 'wp_ajax_testttt', 'testttt' );
function testttt() {
$our_people = new WP_Query(
array(
'post_type' => array( 'people' ),
'posts_per_page' => '4',
'post_status' => array( 'publish' ),
'orderby' => 'rand',
'meta_query' => array(
@aslamdoctor
aslamdoctor / wordpress-social-share.php
Last active Jun 6, 2022
Snippet : Social sharing links for WordPress Single Post
View wordpress-social-share.php
<ul class="sharing-links">
<li>
<a href="javascript:window.open('https://www.linkedin.com/cws/share?url=<?php the_permalink(); ?>', 'linkedin_share', 'height=320, width=640, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');"><span class="sr-only">Share on LinkedIn</span><i class="fab fa-linkedin-in"></i></a>
</li>
<li>
<a href="javascript:window.open('http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>&amp;t=<?php echo urlencode(get_the_title()); ?>', 'facebook_share', 'height=320, width=640, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');"><span class="sr-only">Share on Facebook</span><i class="fab fa-facebook-f"></i></a>
</li>
<li>
<a href="javascript:window.open('http://twitter.com/share?url=<?php the_permalink(); ?>', 'twitter_share', 'height=320, width=640, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');"><span class="sr-only">Share on
@aslamdoctor
aslamdoctor / gist:8b3f1e5b80a568aa47376ffec6d3b5d3
Last active May 25, 2022
Compress video for Web using ffmpeg
@aslamdoctor
aslamdoctor / wordpress-youtube-vimeo-embed.php
Created Mar 16, 2022
Snippet : Get embed code from video url for youtube or vimeo
View wordpress-youtube-vimeo-embed.php
<?php
// ========= Get embed code from video url for youtube or vimeo =============
function wpmix_get_video_embed( $url ) {
$video_type = wpmix_get_video_type( $url );
if ( $video_type == 'youtube' ) {
$video_id = wpmix_get_youtube_id( $url );
return '<div class="embed-responsive embed-responsive-16by9">
<iframe width="1268" height="713" src="https://www.youtube.com/embed/' . $video_id . '" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>';
} elseif ( $video_type == 'vimeo' ) {
@aslamdoctor
aslamdoctor / woocommerce-delete-failed-orders.sql
Last active Mar 15, 2022
WooCommerce : Delete all failed orders
View woocommerce-delete-failed-orders.sql
-- Below queries are just to check the failed order records:
SELECT * FROM `wp_woocommerce_order_itemmeta` WHERE order_item_id IN (SELECT order_item_id FROM `wp_woocommerce_order_items` WHERE order_id IN (SELECT ID FROM wp_posts WHERE post_type = 'shop_order' AND post_status='wc-failed'))
SELECT * FROM `wp_woocommerce_order_items` WHERE order_id IN (SELECT ID FROM wp_posts WHERE post_type = 'shop_order' AND post_status='wc-failed')
SELECT * FROM wp_comments WHERE comment_type = 'order_note' AND comment_post_ID IN(SELECT ID FROM wp_posts WHERE post_type = 'shop_order' AND post_status='wc-failed')
SELECT * FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_type = 'shop_order' AND post_status='wc-failed')
@aslamdoctor
aslamdoctor / woocommerce-product-image-alt-text.php
Created Jan 25, 2022
Woocommerce : Change image alt text to product name
View woocommerce-product-image-alt-text.php
<?php
/**
* Change image alt text to product name
*/
add_filter('wp_get_attachment_image_attributes', 'wpmix_attachement_image_attributes', 20, 2);
function wpmix_attachement_image_attributes( $attr, $attachment ){
// Get post parent
$parent = get_post_field( 'post_parent', $attachment);
View teaser.scss
.teaser {
padding: 2em;
&__title {
font-size: 2em;
}
&__learn-more {
border: 1px solid $color-border;
}
@aslamdoctor
aslamdoctor / xampp-mysql-fix.txt
Created Oct 12, 2021
XAMPP MySQL Shutdown Fix
View xampp-mysql-fix.txt
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 Oct 11, 2021 — forked from ghalusa/youtube_id_regex.php
Extract the YouTube Video ID from a URL in PHP
View youtube_id_from_url.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