Skip to content

Instantly share code, notes, and snippets.

// Checks if there is any expiring members this month
if ( count( $expiring_members ) == 0 ) {
echo "No member is expiring in this month!";
return;
}
$labels_per_page = 14;
$no_of_pages = ceil( count( $expiring_members ) / $labels_per_page );
$index = 0;
$template_file = dirname( MPLUS_CE ) . '/assets/template.docx';
$upload_dir = wp_get_upload_dir();
$save_path = $upload_dir[ 'basedir' ] . '/expiring_memberships.docx';
$save_url = $upload_dir[ 'baseurl' ] . '/expiring_memberships.docx';
$document = new Mplus_PHPWord_Template( $template_file );
$countries = WC()->countries->get_countries();
for ( $i = 0; $i < $no_of_pages; $i++) {
// Adds a page to put the data in.
$document->add_page();
// Goes through each label (for each item).
for ( $j = 0; $j < $labels_per_page; $j++ ) {
/*
* Some variables to be used later.
* The values will be put later.
*/
$index2 = $j + 1;
require_once( dirname( MPLUS_CE ) . '/vendor/PHPWord/Template.php' );
class Mplus_PHPWord_Template extends PHPWord_Template
{
private $page_xml;
public function __construct( $strFilename ){
parent::__construct( $strFilename );
$this->page_xml = file_get_contents(dirname( MPLUS_CE ) . '/assets/page.txt');
}
@adnan360
adnan360 / yaost-primary-category.php
Last active November 7, 2018 05:27
Get Yoast SEO primary category
<?php
/**
* Gets Yoast SEO primary category.
*
* @param int $post_id ID of the product to get category of.
* @return string
*/
public function get_primary_cat( $post_id ) {
$cat_name = '';
if ( class_exists( 'WPSEO_Primary_Term' ) ) {
@adnan360
adnan360 / sass-tabbed-generate.sh
Last active November 30, 2018 05:22
For generating tabbed Sass output
#!/bin/bash
sassc -t expanded style.scss > style.css
sed -i -e 's/ / /g' style.css
# Save as .sh file on the same directory as the css. e.g. generate.sh
# chmod +x generate.sh
# ./generate.sh
# This method requires no tools, no hacks, no code edits etc. Easy and simple!
@adnan360
adnan360 / handle-server.sh
Last active January 2, 2019 10:48
Start or stop Apache server + Mysql server on different distros and setups
#!/bin/bash
# Arch Linux and Debian has different names for Apache service.
# Some people may like Mysql over Mariadb, which has different service
# names.
# This script detects which service is available and starts or stops it.
# So it basically lets you start or stop the server in one command.
# This is great for maintaining one piece of code that can be used on
# different distros.
# To use it, place the code below on your ~/.bashrc or if you have it,
@adnan360
adnan360 / python-invert.sh
Created January 6, 2019 09:29
Toggles a python script running (terminates if already running, runs otherwise)
#!/bin/bash
# This bash script (1) runs a python script if not already running
# or (2) kills the script if already running. Easily put, it inverts
# the running state of the script. Great for toggling GUI scripts.
# Run chmod +x python-invert.sh and then run this with the python
# script path as parameter: ./python-invert.sh path/to/script.py
script_name=${1}
@adnan360
adnan360 / save-and-close-confirmation.vim
Last active January 19, 2019 09:31
Ask if changes are unsaved and requests a filename to save it if the buffer was not saved anywhere (for VIM/NVIM). Convenient and neat!
" This code sets shortcuts for close buffer and save.
" They both work to let you know when a file has unsaved changes
" and offers you to give it a filename. We take this granted on
" modern text editors, but VIM does not have it by default.
" Tested in NeoVim, but should work with VIM as well.
" Put this on your ~/.vimrc for VIM and ~/.config/nvim/init.vim for
" neovim.
" Remaps 2 keyboard shortcuts
" Ctrl+W: for closing the buffer (and ask for confirmation, filename etc.)
" Ctrl+S: save (and ask for filename if not already saved
@adnan360
adnan360 / fonts.conf
Created February 23, 2019 09:53
Fix to show Bangla text with a specific font within Monospace text in linux
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!--
Config file to solve the problem that weird font shows when Bangla/Bengali
text appears within Monospace text. I had a debian install which was showing
Mitra Mono in place of Bengali text which was not great to look at. It will
show the Bengali text in SolaimanLipi font when Monospace text is shown.