Skip to content

Instantly share code, notes, and snippets.

View awps's full-sized avatar
🎯
Focusing

Andrei Surdu awps

🎯
Focusing
View GitHub Profile
@awps
awps / get_page_by_title_wp_query.php
Created June 25, 2023 23:39
Alternative to the deprecated `get_page_by_title`, using WP_Query
<?php
function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {
$query = new WP_Query(
array(
'post_type' => $post_type,
'title' => $page_title,
'post_status' => 'all',
'posts_per_page' => 1,
'no_found_rows' => true,
'ignore_sticky_posts' => true,
@awps
awps / sassas.md
Last active February 14, 2023 09:11 — forked from AdamMarsden/sassas.md
Sass Architecture Structure

Sass Architecture Structure

sass/
|
|– base/
|   |– _reset.scss       # Reset/normalize
|   |– _typography.scss  # Typography rules
|   ...                  # Etc…
|
@awps
awps / pixelToPercent.tsx
Created August 9, 2022 14:19
Pixel to Percent TypeScript/Javascript
export const pixelToPercent = (pixelNumber: number, containerSize: number) => {
const percent = 100 / containerSize * pixelNumber;
if (percent > 100) {
return 100;
} else if (percent < 0) {
return 0;
}
return Math.round((percent + Number.EPSILON) * 100) / 100;
@awps
awps / anyToArray.ts
Last active June 6, 2022 09:40
Convert any value to array. Typescript
export const anyToArray = (value: any) => {
if (!value){
return [];
}
if (Array.isArray(value)){
return [...value];
}
if (typeof value === 'object'){
@awps
awps / PostBlocks.php
Created December 10, 2021 10:50
How to modify the Gutenberg blocks from post content with PHP
<?php
namespace ZeroWP;
class PostBlocks
{
/**
* @param \WP_Post|int $post
* @param callable $callback
*
<?php
$flags = \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS;
$iterator = new \FilesystemIterator(__DIR__, $flags);
foreach ($iterator as $path => $item) {
if ($item->isDir()) {
$muPath = trailingslashit($path);
$fileName = basename($item->getFileName());
$filePath = "{$muPath}/{$fileName}.php";
@awps
awps / ContactFormProcessing.php
Last active December 16, 2018 17:38
A very simple, yet complete, AJAX contact form for WordPress.
<?php
class ContactFormProcessing
{
protected $action = 'example_contact_form';
public function ajaxInit()
{
add_action("wp_ajax_{$this->action}", [$this, 'process']);
add_action("wp_ajax_nopriv_{$this->action}", [$this, 'process']);
}
<?php
function everyTimeFrame($totalMinutes = 4, $lastSeconds = 16)
{
$time = [];
for ($i = 0; $i <= 59; $i++) {
for ($j = 0; $j <= $totalMinutes; $j++) {
$second = strlen($i) > 1 ? $i : "0{$i}";
import Util from './util'
import Swipe from './swipe'
class Slider {
constructor( slider_el, options = {} ) {
// Default options
this.opt = {
inactiveClass: 'inactive-slide',
speed: 5000,
startAt: 0,
class Person {
constructor($name){
this._name = $name;
}
getName(){
return `Hello ${this._name}`;
}
}