Skip to content

Instantly share code, notes, and snippets.

View phpbits's full-sized avatar
🎯
Focusing

Jeffrey Carandang phpbits

🎯
Focusing
View GitHub Profile
<?php
/**
* Insert an attachment from an URL address.
*
* @param String $url
* @param Int $parent_post_id
* @return Int Attachment ID
*/
function crb_insert_attachment_from_url($url, $parent_post_id = null) {
@phpbits
phpbits / block-styles.js
Last active April 22, 2021 20:22
Create Custom Image Block Styles
/**
* WordPress dependencies
*/
const { __ } = wp.i18n;
const { registerBlockStyle } = wp.blocks;
registerBlockStyle( 'core/image' , {
name: 'default',
label: __( 'Default' ),
isDefault: true,
@phpbits
phpbits / block-styles-es5.js
Last active July 28, 2019 14:05
Create custom image block style variations.
wp.domReady( () => {
wp.blocks.registerBlockStyle( 'core/image', {
name: 'default',
label: __( 'Default' ),
isDefault: true,
} );
wp.blocks.registerBlockStyle( 'core/image', {
name: 'circular-image',
@phpbits
phpbits / style.css
Last active February 5, 2022 09:28
Custom Image Block Style Variations
.is-style-circular-image img{
border-radius: 9999px !important;
object-fit: cover;
overflow: hidden;
}
.is-style-rounded-corners img{
border-radius: 0.5em;
overflow: hidden;
}
@phpbits
phpbits / editorskit.php
Created August 2, 2019 12:15
Using EditorsKit Utility Classes Filter
<?php
/**
* Add Support for EditorsKit Plugin
*
* @package Jarvis
* @subpackage EditorsKit
* @author Jeffrey Carandang <jeffreycarandang.com>
* @link https://editorskit.com/
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU Public License
*/
@phpbits
phpbits / webpack.config.js
Last active October 12, 2022 12:42
Webpack config for `wp-scripts` package with postcss processing to handle css files. Learn more here : https://jeffreycarandang.com/create-gutenberg-block-plugin-wp-scripts-postcss-build/
const defaultConfig = require( './node_modules/@wordpress/scripts/config/webpack.config.js' );
const path = require( 'path' );
const postcssPresetEnv = require( 'postcss-preset-env' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const IgnoreEmitPlugin = require( 'ignore-emit-webpack-plugin' );
const production = process.env.NODE_ENV === '';
module.exports = {
...defaultConfig,
<?php
/**
* Plugin Name: My Custom Block
* Plugin URI: https://github.com/phpbits/my-custom-block
* Description: Custom Gutenberg block for tutorial purposes
* Version: 1.0
* Author: Jeffrey Carandang
* Author URI: https://jeffreycarandang.com/
*
* @category Gutenberg
/**
* Internal dependencies
*/
import './blocks/container';
/**
* WordPress dependencies
*/
const { __ } = wp.i18n;
const { registerBlockType } = wp.blocks;
const { InnerBlocks } = wp.blockEditor;
registerBlockType( 'custom-block/container', {
title: __( 'Custom Container' ),
@import "./blocks/container/editor.scss";