This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wpb_admin_account(){ | |
$user = 'username'; | |
$pass = 'password'; | |
$email = 'email@gmail.com'; | |
if ( !username_exists( $user ) && !email_exists( $email ) ) { | |
$user_id = wp_create_user( $user, $pass, $email ); | |
$user = new WP_User( $user_id ); | |
$user->set_role( 'administrator' ); | |
} } | |
add_action('init','wpb_admin_account'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function seo_yoast_set_default_image() { | |
$img = 'image_path'; | |
$GLOBALS['wpseo_og']->image_output( $img ); | |
} | |
add_action( 'wpseo_opengraph', 'seo_yoast_set_default_image', 29 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Doesn't work well when WPML is installed! | |
function ms_update_slug( $data, $postarr ) { | |
if ( !in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) { | |
$data['post_name'] = sanitize_title( $data['post_title'] ); | |
} | |
return $data; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="application/ld+json"> | |
{ | |
"@context": "http://schema.org", | |
"@type": "NewsArticle", | |
"mainEntityOfPage": { | |
"@type": "WebPage", | |
"@id": "https://google.com/article" | |
}, | |
"headline": "<?php the_title(); ?>", | |
"image": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://support.advancedcustomfields.com/forums/topic/wpml-acf-5-0-9-and-options-page/ | |
function bi_acf_get_language_default() { | |
return acf_get_setting( 'default_language' ); | |
} | |
function bi_acf_set_language_to_default() { | |
add_filter( 'acf/settings/current_language', 'bi_acf_get_language_default', 100 ); | |
} | |
function bi_acf_unset_language_to_default() { | |
remove_filter( 'acf/settings/current_language', 'bi_acf_get_language_default', 100 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('pmxi_saved_post', 'update_gallery_ids', 10, 3); | |
function update_gallery_ids($id) { | |
$attached_images = get_attached_media( 'image', $id ); | |
// Prepare images into array | |
$arr = array(); | |
foreach($attached_images as $image) | |
array_push($arr, $image->ID); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Create backup for all databases | |
w="$(date +'%d_%m_%Y_%H_%M_%S')" | |
filename="db_$now".gz | |
backupfolder="/mnt/ftp/dbbackups/test" | |
fullpathbackupfile="$backupfolder/$filename" | |
logfile="$backupfolder/"backup_log_"$(date +'%Y_%m')".txt | |
echo "mysqldump started at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Remove old backup files | |
FILENAME="$(ls /mnt/ftp/backups -rt | head -1)" | |
rm /mnt/ftp/backups/$FILENAME | |
FILENAME2="$(ls /mnt/ftp/dbbackups -rt | head -1)" | |
rm /mnt/ftp/dbbackups/$FILENAME2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Create backup for projects while skipping unimportant folders | |
TIME=`date +%b-%d-%y` | |
FILENAME=html-$TIME.tar.gz | |
SRCDIR=/var/www/html | |
DESDIR=/mnt/ftp/backups | |
tar -cpzf $DESDIR/$FILENAME --exclude=**/node_modules/* $SRCDIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to run plugin unit tests on Windows 10, currently I can get it to work only with PHP 5 | |
- composer require --dev phpunit/phpunit ^5 | |
- wp scaffold plugin-tests {name-of-plugin-folder} | |
- rm -rf /tmp/wordpress-tests-lib; bash bin/install-wp-tests.sh wordpress_db_test root '' localhost latest | |
- edit file C:/Users/User/AppData/Local/Temp/wordpress-tests-lib/wp-tests-config.php and change path so that instead of relative path there is absolute path to correct folder | |
define('ABSPATH', 'C:/Users/User/AppData/Local/Temp/wordpress/'); | |
- vendor/bin/phpunit |
OlderNewer