Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Rotsen Mark Acob webdevsuperfast

🏠
Working from home
View GitHub Profile
@webdevsuperfast
webdevsuperfast / functions.php
Created Apr 14, 2021
Redirect posts within a date range to new URL
View functions.php
<?php
/**
* Redirect posts within a date range to new URL with wp_redirect()
* @url https://paulund.co.uk/get-posts-between-certain-dates-wordpress-rest-api
*/
add_action( 'template_redirect', function() {
$args = array(
'date_query' => array(
array(
'after' => 'November 1, 2020',
@webdevsuperfast
webdevsuperfast / functions.php
Last active Apr 14, 2021
FluentForms Server-side Facebook Conversions API
View functions.php
<?php
/**
* Functions
*
* @package Facebook Conversions API
* @since 1.0
* @link https://rotsenacob.com/
* @author Rotsen Mark Acob <rotsenacob.com>
* @copyright Copyright (c) 2020, Rotsen Mark Acob
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
@webdevsuperfast
webdevsuperfast / functions.php
Last active Sep 20, 2020
Validate US Phone Number Format in Contact Form 7
View functions.php
<?php
// Validate Phone Numbers for US
function validate_phone( $phone ) {
return preg_match( "/^\(?([0-9]{3})\)?[-.●]?([0-9]{3})[-.●]?([0-9]{4})$/i", $phone ); // @link https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s02.html
}
add_filter( 'wpcf7_validate_tel', 'tc_validate_tel', 20, 2 );
add_filter( 'wpcf7_validate_tel*', 'tc_validate_tel', 20, 2 );
function tc_validate_tel( $result, $tag ) {
@webdevsuperfast
webdevsuperfast / functions.php
Last active Sep 20, 2020
Validate US ZIP Code with Zippopotamus and Contact Form 7
View functions.php
<?php
/**
* Functions
*
* @package Twenty Twenty Child
* @since 1.0
* @link https://rotsenacob.com
* @author Rotsen Mark Acob <rotsenacob.com>
* @copyright Copyright (c) 2020, Rotsen Mark Acob
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
View WordPress: Contactfrom 7 - modifys contactform 7's default 'select' value
// modifys contact form 7's default select value of --- to Please select...
function my_wpcf7_form_elements($html) {
$text = 'Please select...';
$html = str_replace('<option value="">---</option>', '<option value="">' . $text . '</option>', $html);
return $html;
}
add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');
// Modify multiple selects
function my_wpcf7_form_elements($html) {
View install_nodejs_and_yarn_homebrew.md
@webdevsuperfast
webdevsuperfast / README.md
Created Jun 19, 2020 — forked from hofmannsven/README.md
Storing WordPress files and database with WP-CLI on the server.
View README.md
@webdevsuperfast
webdevsuperfast / .zshrc
Created May 5, 2020
Oh-My-ZSH, Antigen configuration on MacOS
View .zshrc
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# Composer Path
export PATH="$PATH:$HOME/.composer/vendor/bin"
@webdevsuperfast
webdevsuperfast / README.md
Last active Mar 17, 2021
Various ways on creating WordPress backups without a plugin with SSH
View README.md

Backup WordPress Sites without Plugin

Method 1

  • Make sure SSH is enabled on client server.
  • Run ssh username@websitename.com
  • Run mysqldump -u dbusername -p dbname > backup_dbname.sql
  • Once inside run rsync -avz public_html/ testservername@testserver.com:public_html/testfolder
  • Log in to your test server using SSH.
  • Navigate to the test site folder with cd public_html/subdomain-folder.
  • Run find . -type f -exec chmod 644 {} \; for files.
  • Run find . -type d -exec chmod 755 {} \; for directories.
@webdevsuperfast
webdevsuperfast / .htaccess
Created Mar 7, 2020
WordPress load images from production
View .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# If images not found on development site, load from production
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^wp-content/uploads/[^/]+/.+\.(jpe?g|jpg|png|gif)$ https://example.com/$0 [R=302,L]