Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Partial template for content in page.php
*
* @package UnderStrap
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
@everaldomatias
everaldomatias / get-youtube-data.php
Created May 11, 2023 01:08
Get data from YouTube video
<?php
$api_key = 'YOUR_API_KEY';
$url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
$pattern = '/^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/';
preg_match($pattern, $url, $matches);
$video_id = $matches[7];
$url = "https://www.googleapis.com/youtube/v3/videos?id=$video_id&key=$api_key&part=snippet";
@everaldomatias
everaldomatias / dump.sh
Created April 13, 2023 20:12
Gerar dump SQL usando docker-compose e MariaDB
sudo docker-compose exec mariadb mysqldump -uwordpress -pwordpress wordpress > ./dump.sql
@everaldomatias
everaldomatias / gist:c7c19a0cbc0bef9cf42c60701ab932a2
Created April 13, 2023 11:03
Remove PDF Password in Linux using PDF Toolkit (Pdftk)
$ sudo apt install pdftk [On Debian, Ubuntu and Mint]
$ sudo yum install pdftk [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux]
$ sudo emerge -a app-text/pdftk [On Gentoo Linux]
$ sudo apk add pdftk [On Alpine Linux]
$ sudo pacman -S pdftk [On Arch Linux]
$ sudo zypper install pdftk [On OpenSUSE]
$ pdftk <path-to-protected-filename>.pdf input_pw <yourpassword> output <path-to-newfilename>.pdf
<?php
function custom_search_filter( $query ) {
global $wpdb;
if ( $query->is_search() && ! is_admin() ) {
$search_query = get_search_query();
$results = $wpdb->get_results(
$wpdb->prepare(
"SELECT p.ID, p.post_title, m.meta_value
FROM {$wpdb->prefix}posts AS p
.thumb {
position: relative;
&:before {
display: block;
content: "";
width: 100%;
// aspect-ratio: 16 / 9;
padding-top: (9 / 16) * 100%;
}
@everaldomatias
everaldomatias / query.php
Created December 6, 2022 14:43
WordPress: Combine meta_query and tax_query
<?php
$terms = [];
$args = [
'post_type' => 'your_post_type', // change this
'tax_query' => [
[
'taxonomy' => 'your_taxonomy', // change this
'terms' => $terms
<?php
// Utility data
$is_enrolled = apply_filters( 'tutor_alter_enroll_status', tutor_utils()->is_enrolled() );
$lesson_url = tutor_utils()->get_course_first_lesson();
$is_privileged_user = tutor_utils()->has_user_course_content_access();
$tutor_course_sell_by = apply_filters( 'tutor_course_sell_by', null );
$is_public = get_post_meta( get_the_ID(), '_tutor_is_public_course', true ) == 'yes';
// Monetization info
$monetize_by = tutor_utils()->get_option( 'monetize_by' );
@everaldomatias
everaldomatias / woocommerce.php
Created October 25, 2022 19:06
Add checkbox on register WooCommerce
<?php
// Add term and conditions check box on registration form
add_action( 'woocommerce_register_form', 'add_terms_and_conditions_to_registration', 20 );
function add_terms_and_conditions_to_registration() {
if ( wc_get_page_id( 'terms' ) > 0 && is_account_page() ) {
?>
<p class="form-row terms wc-terms-and-conditions">
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
@everaldomatias
everaldomatias / gist:d8e084c985f9ba23cb71d0f82a63c0ea
Last active October 21, 2022 19:08
Add message on WooCommerce login form
<?php
function custom_add_message_login_form() {
echo '<div class="form-login-message">';
echo 'Ao fazer login, você concorda com os <a href="">termos de serviço</a> e <a href="">política de privacidade</a> da <a href="' . home_url() . '">Escola</a>';
echo '</div>';
}
add_action( 'woocommerce_login_form_end', 'custom_add_message_login_form', 99 );