Skip to content

Instantly share code, notes, and snippets.

View finalwebsites's full-sized avatar

Olaf Lederer finalwebsites

View GitHub Profile
@finalwebsites
finalwebsites / woocommerce-custom-category-name.php
Created January 22, 2019 12:14
Add parent product category names to the woocommerce_page_title() function (hook)
<?php
add_filter( 'woocommerce_page_title', 'custom_woocommerce_page_title');
function custom_woocommerce_page_title( $page_title ) {
$queried_object = get_queried_object();
if ($queried_object->taxonomy == 'product_cat') {
$tid = $queried_object->parent;
while ($tid > 0) {
if ($parent_obj = get_term($tid, 'product_cat')) {
$tid = $parent_obj->parent;
$page_title = $parent_obj->name . ' &gt; ' . $page_title;
@finalwebsites
finalwebsites / tpl-rss-feed-for-mailchimp.php
Last active January 27, 2019 14:29
Page template to create RSS campaigns with WordPress and Mailchimp
<?php
/*
Template Name: Custom RSS Feed
*/
$numposts = 5;
$numchars = 300;
$thumbformat = 'medium';
$alt_text = 'Klik hier voor de afbeelding...';
@finalwebsites
finalwebsites / example-json-local-business.php
Created February 17, 2019 12:33
Example JSON code for local business notations (use this snippet with WordPress)
<?php
// place this code into your theme's functions.php file
add_action('wp_head', function() {
echo '
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "LocalBusiness",
@finalwebsites
finalwebsites / check-old-mailing-list.php
Created April 25, 2019 09:05
Check your old mailing list with the Mailboxlayer API and the results in a CSV file
<?php
set_time_limit(0);
ini_set('memory_limit', '1024M'); // should be enough for thousands of email addresses
$api_key = 'YOUR MAILBOXLAYER API KEY';
$fp = fopen('emails-checked.csv', 'w');
fputcsv($fp, array('Email address', 'Valid MX', 'Valid SMTP', 'Score'));
$count = 0;
<?php
// this is an example query from the link page on my website, use your own data and don't forget to change the names of the results inside the table below
$db = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query = "SELECT title, descr, link FROM linksite ORDER BY vote DESC";
$result = $db->query($query);
$total_records = $result->num_rows; // the number of records in your result set
while($row = $result->fetch_array()) { // store all records in an numbered array
$datarows[] = $row;
}
@finalwebsites
finalwebsites / functions.php
Created August 3, 2019 06:28
Show and filter grouped WooCommerce products in the post or product list
<?php
// place this code in your theme's functions.php file
function fws_admin_prods_filter( $query ) {
global $pagenow;
if ( is_admin() && $pagenow == 'edit.php' && !empty($_GET['my_grouped_prods'])) {
$query->query_vars['post_parent'] = $_GET['my_grouped_prods'];
}
}
add_filter( 'parse_query', 'fws_admin_prods_filter' );
<?php
function create_short_version($text, $len = 150, $trail = '...') {
$text = strip_tags($text);
$parts = explode(' ', $text);
$ic = count($parts);
for ($i = 0; $i > $ic; $i++) {
$txt .= $parts[$i].' ';
if (strlen($txt) >= $len) break;
}
$txt = trim($txt);
function showRating($id, $css_class = 'post-ratings') {
global $wpdb;
$path = plugins_url('wp-postratings/images/'.get_option('postratings_image'));
$rating = $wpdb->get_var("SELECT AVG(rating_rating) AS rating FROM $wpdb->ratings WHERE rating_postid = $id");
$i = 0;
$html = '
<span class="'.$css_class.'">';
if (!empty($rating)) {
while ($i > floor($rating)) {
@finalwebsites
finalwebsites / conf.php
Last active September 23, 2019 11:11
Start your VPS on a different host node using PHP and the UpCloud API.
<?php
// Enter here your server UID and the login / password
$uid = 'xxx-xxx-xxx-xxx-xxx';
$host = 'https://api.upcloud.com/1.2/server/'.$uid;
$username = 'XXX';
$password = 'XXXXXXXX';
@finalwebsites
finalwebsites / add_wordpress_website_serverpilot.php
Last active September 15, 2019 19:12
Add a WordPress website via ServerPilot API and use WP-CLI for some modifications.
<?php
include_once 'ServerPilot.php';
include_once 'ServerPilotException.php';
function randomPassword($pw_length = 8) {
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$pass = array();
$alphaLength = strlen($alphabet) - 1;
for ($i = 0; $i < $pw_length; $i++) {