Tag: snippets

Bridging the Gap between PHP 5.3 and 8.2

This week I got finally got involved with maintaining the languishing TCPDF library on Github. Long overdue. Embarrassingly long overdue, since I’ve based one of my businesses on this open source gem for nearly ten years now. The author, Nicola Asuni, has been working for many years on a successor to TCPDF, but it is stalled… likely due to the usual reasons: life and cash. I can relate. I’ve been sitting on a huge WP plugin project for two years now, desperately trying to move it forward while life happens and I’m forced to prioritize support for my paying customers. A couple years ago an eager young programmer, William Desportes, hopped onto the TCPDF GitHub and made an incredible fork which would have really helped bring TCPDF into this decade. It needed massaging to work with PHP 8.0+ and he continue reading…

EDD Stripe v3.0 Sticks It To Ya

Easy Digital Downloads (EDD) seems to be going the route of Freemius, etc., where you can use their open source plugin(s), but not without significant overhead. Except Freemius isn’t open source. 🤷‍♀️ With only a small share of the WP users needing file management plugins using their plugin and not a competitor’s, it’s a surprising move. Stripe Gets Pricey If you’re not paying for their annual license, or let your license term lapse, and wish to take payments with Stripe, you’re going to pay Stripe fees, plus a 3% “application fee” which EDD funnels off your sale using Stripe Connect. This fee used to be 2% until v.3.0. Now it’s 3% — that’s significant! With version 3.0 of EDD Stripe, EDD moved their entire Stripe integration over to Stripe Connect, which means all the sales on your private site go continue reading…

Fix Easy Digital Downloads to Increase Sales

Over the years I’ve sure appreciated having Easy Digital Downloads (EDD) plugin to platform my plugin sales. It’s pretty cool, and handles most my needs including software licensing. However, I have had numerous little issues with the plugin. I apply each update with trepidation, because some changes (“upgrades”) have caused abrupt slumps in my sales. Of course the developers are well-meaning, and I’m sure these upgrades are in fact upgrades for certain people. But it’s becoming more and more clear that even though I’m a paying subscriber of EDD, their developers might not be “in touch” with the my reality or my customers’ realities. There are things a customer just. does. not. want. to. see. when. shopping. Case in Point With the latest updates to the Stripe payment gateway plugin, EDD moved to the new API and allows small text continue reading…

Set up a Weekly (weekend) autoresponder

Years ago I set up an autoresponder to let people know I’m probably not around on Saturday and Sunday. It’s still running, and flawlessly, so I thought I’d share how I set it up using cPanel cron and FTP/File Manager. I got this idea originally from David Heath-Whyte’s blog, but adjusted it a little bit. It might help you to see two examples if you want to set this up yourself and aren’t quite sure how. Sometimes having the same thing explained twice by two different people helps! Note: this advice only works for people with self-hosted email. Gmail, Hotmail, Yahoo! etc., look elsewhere. Also, you’ll need hosting with access to a cPanel. Step 1: Set up and compose your Autoresponder email Head over to your cPanel (“control panel”). Most hosting accounts will have a control panel of some sort, continue reading…

Prorated Software Upgrade Crack

It’s amazing how some customers’ behavior can highlight innovative ways of saving money. It never occurred to me until I started selling software, and managing annual software licenses, that there’s a pretty simple way to save money when trying to renew software licenses, without a coupon. Many businesses pro-rate license upgrades, and prorate them by date, such that the closer you come to expiration, the cheaper an upgrade gets. So a frugal move to make is to wait until just days before your software license expires, then upgrade to the next level up… for a tiny fraction of what it would cost to renew the lesser license currently held. VoilĂ  – we now have better access for another year, for cheaper than a straight renewal! While this is pretty cool for the customer, this is a big problem for software continue reading…

Ways to harden your WordPress website without using bulky plugins

You can add security plugins to your website, but if you don’t know exactly what they’re doing, not only can you silently break things, but you can slow down your site with a lot of extra code. They’re great, but it’s not like there isn’t risk in blindly activating any plugin. I develop plugins and try to predict how things can go wrong, so I know just how bewildering the number of things that can go wrong feels. When I can simplify things on my own sites, I always go that route. I recently decided to stop using a security plugin because I’ve implemented security measures of my own, and my server handles SSL redirection. I love the Really Simple SSL plugin but didn’t need it in this particular instance. Really Simple SSL had a couple nice features I decided continue reading…

Send Easy Digital Downloads Transactions to Wave Apps without Zapier

I wrote a little WordPress plugin that connects Easy Digital Downloads (EDD) to Wave Apps bookkeeping using the Wave GraphQL API. If you are accepting Stripe payments using EDD’s Stripe extension or PayPal Payments using EDD’s PayPal Commerce Pro, this EDD extension will automatically move bookkeeping data into your Wave Apps transactions using Wave’s GraphQL API. It saves a ton of data-entry, and picks up where a free Zapier account leaves off. In the plugin settings panel, you start by entering your Wave “full access token.” Get a token by creating an application in the Wave Apps developer portal. Once saved, this token allows the plugin to query its associated businesses. Choose your business (most cases there will only be one), and click save again. Now you can map your payment accounts and your download products to those matching in continue reading…

Different Watermark on First Page

Brought to you by a longtime user, Jake, is the following snippet, which allows for a different watermark on the first page than all other pages: function jakes_custom_overlay_function( $page, $watermark, $o_X_margin, $o_Y_margin, $cell_width ) { // Only do an overlay on the first page $start_page = empty( $watermark->settings[‘start_page’] ) ? 1 : intval( $watermark->settings[‘start_page’] ); if ( $page === $start_page ) { $ishtml = false; // If watermark has HTML Multicell needs HTML argument if ( $watermark->overlay != strip_tags( $watermark->overlay ) || strpos( $watermark->overlay, ‘opacity:’ ) !== false ) { $ishtml = true; } $watermark->pdf->MultiCell( $cell_width, 1, $watermark->overlay, 0, ”, false, 1, $o_X_margin, $o_Y_margin, true, 0, $ishtml, false, $watermark->size[‘h’], ‘T’, false ); } } add_action( ‘wwpdf_custom_overlay_function’, ‘jakes_custom_overlay_function’, 10, 5 ); WaterWoo loops through each PDF page with TCPDF to apply watermarks. What this PHP code says is that if inside continue reading…

PDF Stamper improvements

Not only are we actively maintaining all our plugins, but we have been trickling out improvements… realized while we work on the successor to our PDF stamping plugins. For example, with version 1.2 of PDF Stamper (and v1.3 of EDDiStamper) there is better handling of PDF pages of varying size, in order to keep stamps inside the page boundaries, where you want them. These improvements occur as parent library improvements occur, and as we learn and grow! Oftentimes people wish to create their own dynamic shortcodes for stamping customer/user data on PDF files. We’ve made that easier with the filter hook ‘woostamper_filter_shortcodes.’ This hook allows you to adjust how stamping shortcodes (such as [FIRSTNAME], [EMAIL] etc) are parsed. Here is some example code showing how this filter might be used to prefer the WordPress user profile data over WooCommerce order continue reading…

A Side Project

Things have gotten nuts for just about everyone lately, us included. Luckily the Little Package plugins are stable and they can sit tight for a bit. I can focus on customer support… and helping to run my partner’s business. He lost his longtime secretary to the task of Covid-19 era homeschooling, and I have stepped in to help while we see what this quarter brings. So, I’m very busy, very very busy. Luckily programming for the web lends itself well to streamlining a business, and we’ve been able to automate some bits. Last week I spent some hours over two days writing some code which replaces heaps of manual data entry for his business, practically replacing a full-time employee. At first I did this using Zapier. We found Zapier a couple months ago, and it’s pretty cool. I was playing continue reading…

Watermark Width on a PDF

A customer just brought up an interesting point: since the watermark width (“cell width” in TCPDF terms) is determined by the PDF page width, won’t a line of text be a “little short” (limited) if the watermark is rotated diagonally? Since it would take a lot of math with a few variables (page size, mainly) to determine the max cell width based on degree of rotation, I just included a new filter in WaterWoo instead. It’s called ‘wwpdf_cell_width’. (Hey, I like math but it’s still really smokey in California and getting hard to think.) The following code is a simple example of an attempt to override the cell width with 300mm, which should work on pages larger than A4. The code includes a fallback if it won’t work. add_filter( ‘wwpdf_cell_width’, ‘my_custom_cell_width_function’, 10, 2 ); function my_custom_cell_width_function( $cell_width, $page_size ) { continue reading…

Sharing Passwords

That title probably caught your attention because… when do we ever share passwords? Actually, we do, a lot. Website administrators often have to share passwords with users and customers who have just been issued a password. Generally that is done automatically, without the administrator ever having any idea what password was shared. You know, for security. And this is something to think about for administrators who are passwording PDF files just before delivery. How will you let the end user know what the PDF password is? In case you’re stumped, here are some ideas for how to get that information across if you’re running a WooCommerce shop. The simple way WooCommerce has a setting for each product under the “Advanced” tab called “Purchase Note.” You can put details for the customer here and it will show on the order confirmation continue reading…

Printing a barcode or QR Code on a PDF

If you are or even if you are not using WooCommerce or Easy Digital Downloads but are still programming in PHP, I am available to consult on your TCPDF barcoding project to get it running. Get in touch!   The WaterWoo PDF Premium and EDDiMark PDF plugins can add barcodes and QR codes to PDFs dynamically upon download request via WooCommerce or Easy Digital Downloads. This is because both WordPress plugins use TCPDF to write PDF content, and TCPDF allows for barcode creation. Though this blog post might also be helpful for someone just trying to figure out how to write a barcode with TCPDF and PHP, these instructions are more geared toward a WordPress developer wishing to add 1D or 2D barcodes to existing PDF files. For WaterWoo, use the ‘wwpdf_add_barcode’ filter hook in the plugin (located in classes/wwpdf-watermark.php). continue reading…

Custom Fonts with WooStamper (SetaStamper)

The SetaPDF library which PDF Stamper is built on allows quite a bit of font customization to be done. More on SetaPDF and font manipulations. For the meantime, a quick tutorial on how to get other fonts beyond the three packaged with the plugin (Times, Courier, and Helvetica). Start by finding a TrueType font (.ttf) file which suits your needs. Try to keep the file size small, subsetting if necessary so that your server isn’t bogged down managing a large font file while trying to manipulate your PDF. Upload the file to your wp-content/uploads directory, somewhere it won’t get overwritten. It makes sense to use the woostamper folder, so we’ve gone ahead and done that below. Arimo is a TrueType font which works for our purposes, so we have uploaded it to a folder “arimo.” Look at the function below continue reading…

Adding Custom Fonts to EDDiStamper

All three new Stamper plugins (EDDiStamper, PDF Stamper, and Download Monitor Stamper) come with the three standard PDF fonts: Helvetica, Times New Roman, and Courier. Not much to get excited about, I know. Whereas EDDiMark and WaterWoo (plugins based on TCPDF, not SetaPDF-Stamper) have built-in font uploaders with more instant gratification, the integration with Seta is a bit more complicated, and so you’ll need to use a little code. Whether you add the code into a custom plugin, your child theme functions.php file, or by using the more plug-n-play Code Snippets plugin doesn’t matter. Before using the following example code, we have started by creating a “fonts” folder inside the wp-content/uploads/eddistamper/ folder. We put our Comic Sans (yes!) TTF file inside the fonts folder. You can see that path reflected in line 6 of the code below. So, put the continue reading…

Beyond Stamping PDFs with Custom Fonts

If you have tried to use the included font uploader in WaterWoo or EDDiMark, most the time you will be satisfied. It makes it very easy to add and watermark PDFs in nearly any font.

Unfortunately for some users whose languages require special characters, those characters might not be mapped in the font definition files and the dreaded ??????? or â–Żâ–Żâ–Żâ–Żâ–Żâ–Żâ–Ż will show. That’s stressful!

Phone Number as PDF Password

A customer asked about maybe using a customer’s phone number as the PDF password instead of their email or an admin-chosen string. Here is some example code which will get that done. Make sure to test it, and customize ad-lib to suit your purposes. function waterwoo_use_phone_as_password( $password, $order_id ) { $phone = ”; // start by maybe getting phone number from order ID $order = wc_get_order( $order_id ); $order_data = $order->get_data(); $phone = $order_data[‘billing’][‘phone’]; if ( ! isset( $phone ) || $phone == ” ) { // no phone number yet, try seeing if user is logged in and has a saved phone number: if ( is_user_logged_in() ) { $user = wp_get_current_user(); $phone = get_user_meta( $user->ID, ‘billing_phone’, true ) ? get_user_meta( $user->ID, ‘billing_phone’, true ) : ”; } } // you might want to manipulate the phone number to remove continue reading…

Brazilian Shops can Watermark CPF

You can add your own shortcodes to WaterWoo PDF Premium for on-the-fly customized watermarks. One request from a Brazilian customer was for a shortcode for the Cadastro de Pessoas FĂ­sicas (CPF). This is a taxpayer identification number all citizens of Brazil must use to shop online within Brasil. We created the shortcode [BILLING_CPF] to import any customer’s CPF number into their watermarked (personalized) PDF. Here is the code to add to a (child) theme functions.php file: function fetch_custom_checkout_field( $input, $order_id, $product_id ) { // first we need to get the order object from the order id // you can get a lot of info from the order object ( $order in this case) $order = wc_get_order( $order_id ); // The CPF plugin stores CPFs in WooCommerce order meta, making it easy to fetch // you might want to do testing continue reading…

Little Package