Skip to content

Instantly share code, notes, and snippets.

View Pamps's full-sized avatar

Darren Lambert Pamps

View GitHub Profile
@Pamps
Pamps / get_post_count_for_term_and_post_type.php
Last active January 25, 2023 13:48
WordPress: How to get the post count for a term and post type. Found out more at https://www.darrenlambert.com/wordpress-how-to-get-the-post-count-for-a-term-and-post-type/
/**
* Returns the number of posts for a term in a taxonomy, for a post type
* Found out more at https://www.darrenlambert.com/wordpress-how-to-get-the-post-count-for-a-term-and-post-type/
* @param string $post_type
* @param string $taxonomy
* @return int count
*/
function get_post_count_for_term_and_post_type( $term_id, $taxonomy, $post_type ) {
// Build the args
@Pamps
Pamps / bitbucket-pipelines.yml
Last active November 13, 2022 16:44
Example Bitbucket Pipeline CI script to deploy a PHP/WordPress website using FTP.
# Auto deploy staging to staging
# Manual deploy master to production
image: php:7.1.29
pipelines:
branches:
staging:
- step:
name: Deploy to Staging
script:
@Pamps
Pamps / 3 digit country code list
Created September 2, 2022 16:51
3 digit country code list, useful for ACF
AFG : Afghanistan
ALA : Åland Islands
ALB : Albania
DZA : Algeria
ASM : American Samoa
AND : Andorra
AGO : Angola
AIA : Anguilla
ATA : Antarctica
ATG : Antigua and Barbuda
@Pamps
Pamps / various
Last active April 29, 2022 15:58
Default WordPress setup
in wp-config.php
define( 'DISALLOW_FILE_EDIT', true ); // disable file editor
define( 'WP_POST_REVISIONS', 10 ); // keep last 10 revisions
in functions.php
add_filter( 'auto_update_plugin', '__return_true' ); // auto update plugins
@Pamps
Pamps / country_is_in_europe.php
Created July 10, 2018 16:58
Returns if a country is in Europe, in PHP
<?php
// Returns if a country is in Europe
// Pass in country name or code e.g. 'Spain' or 'ES'.
function country_is_in_europe( $country ) {
// Our list of countries
$countries = array(
'AT' => 'Austria',
'BE' => 'Belgium',
@Pamps
Pamps / .gitlab-ci.yml
Last active February 11, 2021 15:13
My default GitLab CI FTP deploy for WordPress sites, works well on SiteGround, SpeedyDot and others
deploy:
script:
- apt-get update -qq && apt-get install -y -qq lftp
- lftp -c "set ftp:ssl-allow no; open -u $USERNAME,$PASSWORD $HOST; mirror -Rnv ./ public_html/ --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
only:
- master
@Pamps
Pamps / add-admin-user-to-wordpress.php
Last active February 11, 2021 15:13
Add WordPress admin user via functions.php
<?php
// Add admin user
add_action( 'init', function () {
$username = 'admin';
$password = 'password';
$email_address = 'webmaster@mydomain.com';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
@Pamps
Pamps / MacMySqlBackup.sh
Last active February 11, 2021 15:13
Dump MySql (MAMP) database tables to Dropbox for daily backups.
#!/bin/bash
#--------------------------------------------------------------------------
# Daily MySQL dump on OSX to use in conjuction with Time Machine
#
# 1) Save this file in some appropriate location like /usr/sbin/dbbackup.sh
# 2) Make sure it is executable: sudo chmod +x /usr/sbin/dbbackup.sh
# 3) Create the backup directory: mkdir ~/dbdumps
# 4) Create the cron entry to run it daily by executing the following:
# sudo echo "47 5 * * * /usr/sbin/dbbackup.sh" >> /usr/lib/cron/tabs/root
# (This will run the script at 05:47 am each day)
@Pamps
Pamps / gist:d5fb83f474ea4b39eab1370f1fbbbcf5
Created January 24, 2020 16:27
Gitlab CI file with 3 manual deploy options
# Manual deployment to staging
# Manual deployment to CSB and AG
deploy-to-staging:
script:
- apt-get update -qq && apt-get install -y -qq lftp
- lftp -c "set ftp:ssl-allow no; open -u $USERNAME,'$PASSWORD' $HOST; mirror -Rnv ./ public_html/wp-content/ --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
only:
- master
when: manual
@Pamps
Pamps / wordpress-set-new-post-title-placeholder.php
Last active November 1, 2019 08:23
Change the WordPress New Post title placeholder
<?php
// Add this to your theme functions.php file, or in a plugin file
// This example shows how to change the title field placeholder
// Post types titles
function cpm_change_default_title( $title ) {
$screen = get_current_screen();
if ( 'product' == $screen->post_type ) { // Change product for your post_type (.e.g post, page, etc)