Skip to content

Instantly share code, notes, and snippets.

View mflisikowski's full-sized avatar
🎯
Focusing

Mateusz Flisikowski mflisikowski

🎯
Focusing
View GitHub Profile
@mflisikowski
mflisikowski / function.php
Created July 20, 2020 22:06 — forked from nandomoreirame/function.php
WordPress REST API send email SMTP in with PHPMailer
<?php
function sendWithPhpMailer($subject, $body, $reply) {
require(ABSPATH . WPINC . '/class-phpmailer.php');
require(ABSPATH . WPINC . '/class-smtp.php');
// date_default_timezone_set( 'America/Sao_Paulo' );
$blogname = wp_strip_all_tags( trim( get_option( 'blogname' ) ) );
$smtpHost = wp_strip_all_tags( trim( get_option( 'smtp_host' ) ) );
<?php
/**
* Adapted from https://wordpress.stackexchange.com/a/191974/8591
*
* Send mail, similar to PHP's mail
*
* A true return value does not automatically mean that the user received the
* email successfully. It just only means that the method used was able to
* process the request without any errors.
*
<?php
add_action('rest_api_init', function () {
register_rest_route( 'contact/v1', 'send', [
'methods' => 'POST',
'callback' => 'api_send_contact_form'
]);
});
function api_send_contact_form( $request ) {
@mflisikowski
mflisikowski / custom-fields.php
Created July 20, 2020 21:56 — forked from nandomoreirame/custom-fields.php
Add custom post meta to WordPress REST API
<?php
function get_custom_post_meta_cb($object, $field_name, $request) {
return get_post_meta( $object['id'], $field_name, true );
}
function get_custom_post_meta_cb_the_content($object, $field_name, $request) {
return apply_filters( 'the_content', get_post_meta( $object['id'], $field_name, true ) );
}
@mflisikowski
mflisikowski / metabox-page.php
Created July 20, 2020 21:56 — forked from nandomoreirame/metabox-page.php
add custom metabox per page
<?php
function theme_metabox_per_page() {
global $pagenow;
if ( $pagenow == 'post.php' ) {
$page_id = ( $_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['post_ID'] ) ? $_POST['post_ID'] : $_GET['post'];
if ( $page_id ) {
$page_slug = get_post_field( 'post_name', $page_id );
@mflisikowski
mflisikowski / throttle.js
Created May 12, 2020 05:46 — forked from beaucharman/throttle.js
An ES6 implementation of the throttle function. "Throttling enforces a maximum number of times a function can be called over time. As in 'execute this function at most once every 100 milliseconds.'" - CSS-Tricks (https://css-tricks.com/the-difference-between-throttling-and-debouncing/)
function throttle(callback, wait, immediate = false) {
let timeout = null
let initialCall = true
return function() {
const callNow = immediate && initialCall
const next = () => {
callback.apply(this, arguments)
timeout = null
}
@mflisikowski
mflisikowski / debounce.js
Created May 12, 2020 05:40 — forked from beaucharman/debounce.js
An ES6 implementation of the debounce function. "Debouncing enforces that a function not be called again until a certain amount of time has passed without it being called. As in 'execute this function only if 100 milliseconds have passed without it being called.'" - CSS-Tricks (https://css-tricks.com/the-difference-between-throttling-and-debounc…
function debounce(callback, wait, immediate = false) {
let timeout = null
return function() {
const callNow = immediate && !timeout
const next = () => callback.apply(this, arguments)
clearTimeout(timeout)
timeout = setTimeout(next, wait)
@mflisikowski
mflisikowski / cloudSettings
Last active April 16, 2020 08:40
Visual Studio Code Settings Sync Gist - ENP
{"lastUpload":"2020-04-16T08:40:00.656Z","extensionVersion":"v3.4.3"}
@mflisikowski
mflisikowski / easing.js
Created March 31, 2020 22:42 — forked from gre/easing.js
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
// no easing, no acceleration
linear: t => t,
// accelerating from zero velocity
easeInQuad: t => t*t,
// decelerating to zero velocity
@mflisikowski
mflisikowski / truncate_text.js
Created June 26, 2019 11:22
truncate text fun
const truncateText = (
str,
len = 42,
end = '...',
words = true,
regex = /[-.*+?^${}()|[\]\\]/g,
after = ' ',
) => {
const replaced = str.replace(regex, '');
const string = replaced.substr(0, len);