Skip to content

Instantly share code, notes, and snippets.

View sarathlal-old's full-sized avatar
🎯
Focusing

Sarathlal N sarathlal-old

🎯
Focusing
View GitHub Profile
file in server
<?php
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output("testsuccess.pdf",'F');
@sarathlal-old
sarathlal-old / template-htmltest.php
Created March 14, 2018 05:01
WordPress theme HTML testing template
<?php
/*
Template Name: HTML Test
*/
get_header();
?>
<h1>HTML tags with lorem ipsum...</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>
add_action( 'pre_get_posts', 'custom_post_type_archive' );
function custom_post_type_archive( $query ) {
if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'gallery' ) ) {
$query->set( 'posts_per_page', '12' );
$query->set( 'orderby', 'menu_order' );
$query->set( 'order', 'ASC' );
}
find . ! -name 'file.txt' -type f -exec rm -f {} +
will remove all regular files (recursively, including hidden ones) except file.txt. To remove directories, change -type f to -type d and add -r option to rm.
https://www.dev4press.com/blog/tutorials/2017/url-rewriting-custom-post-types-date-archive/
Date archives are very useful if you want to list your posts only for the specified year, month or day. But, they only work with posts, and not with the custom post types.
Year archive: http://www.example.com/2011/
Month archive: http://www.example.com/2010/10/
Day archive: http://www.example.com/2012/02/22/
<?php
/*
Template Name: archive
*/
get_header();
wp_enqueue_script('magnific');
add_action('wp_footer', 'san_scripts', 21);
function san_scripts() {
@sarathlal-old
sarathlal-old / Gmail SMTP & WordPress
Last active April 4, 2019 05:26
Configure Gmail account & SMTP plugin to send SMTP emails from WordPress
1. Install SMTP Plugins
https://wordpress.org/plugins/search/SMTP/
2. Configure Plugins
* Outgoing Mail (SMTP) Server: smtp.gmail.com
* Use Authentication: Yes
* Use Secure Connection: Yes (TLS or SSL)
* Username: your Gmail account (e.g. [email protected])
@sarathlal-old
sarathlal-old / gist:22a003f3965eaae40b3fe6b32812c36c
Last active July 27, 2018 13:53
Get WoCommerce orders of a specific customer
$customer_id = get_current_user_id();
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => $customer_id,
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
//'post_status' => array('wc-completed'),
) );
Why WordPress not using session in PHP. Reason and the better alternatives.
https://pressjitsu.com/blog/wordpress-sessions-performance/
https://techgirlkb.guru/2017/08/wordpress-doesnt-use-php-sessions-neither/
/*
* For latest WooCommerce Rest API
* Add a referanse field to the Order API response.
*/
function prefix_wc_rest_prepare_order_object( $response, $object, $request ) {
// Get the value
$referanse_meta_field = ( $value = get_post_meta($object->get_id(), '_billing_referanse', true) ) ? $value : '';
$response->data['referanse'] = $referanse_meta_field;