Skip to content

Instantly share code, notes, and snippets.

@eudesgit
eudesgit / class-acf-image-upload.php
Last active January 31, 2023 14:40
WordPress - Uploading images to Advanced Custom Fields (AFC)
<?php
class ACF_Image_Upload {
public $post_id;
function update_acf ( ) {
$attach_id = $this->get_image_attach_id('my-image.jpg');
// Saving image
@eudesgit
eudesgit / class-plugin-template-include.php
Last active February 13, 2018 19:20
WordPress plugin to make plugin's own Page Templates available to the website.
<?php
class Plugin_Templates_Loader {
/**
* Templates folder inside the plugin
*/
private $templates_dir;
/**
@eudesgit
eudesgit / wp-plugin-template-name.php
Created February 13, 2018 19:26
How to get WP file header data for a page template
<?php
// Gets Template Name from the file
$filedata = get_file_data($full_path, array(
'Template Name' => 'Template Name',
));
@eudesgit
eudesgit / wp-plugin-filtering-page-templates.php
Last active February 13, 2018 19:28
How to make outside the theme page templates available for use
<?php
/**
* theme_page_templates Filter callback
*
* Merges plugins' template with theme's, making them available for the user
*
* @param array $theme_templates
* @return array $theme_templates
*/
function register_plugin_templates ( $theme_templates ) {
@eudesgit
eudesgit / wp-plugin-filtering-rendering-page-template.php
Created February 13, 2018 19:36
WordPress: How to filter the Page Template that is being rendered.
<?php
/**
* template_include Filter callback
*
* Include plugin's template if there's one chosen for the rendering page
*
* @param string $template path
* @return string $template path
*/
public function add_template_filter ( $template ) {
@eudesgit
eudesgit / wp-plugin-gutenberg-block.php
Last active November 13, 2018 18:58
Registers the scripts and styles to create a WordPress Gutenberg block
<?php
/**
* Registers a Gutenberg block JS script and its styles
*
* @since 1.0.0
* @return void
*/
public function register_block_action ( ) {
$block_name = 'my_block';
@eudesgit
eudesgit / wp-gutenberg-simple-block.js
Last active November 13, 2018 19:01
Creates a simple WordPress Gutenberg block that makes a red title
/**
* Simple block
*
* Creates a simple block that makes a red title
*
* @requires Gutenberg 4.3
*/
// Required components
const { registerBlockType } = wp.blocks; // registerBlockType function that creates a block
@eudesgit
eudesgit / wp-gutenberg-editable-block.js
Last active May 8, 2018 13:42
Creates a simple editable WordPress Gutenberg block that makes a link
/**
* Simple editable block sample
*
* Creates an editable block to make a link
*/
// Required components
const { __ } = wp.i18n;
const { registerBlockType, RichText, source } = wp.blocks;
@eudesgit
eudesgit / wp-gutenberg-inspected-block.js
Last active May 8, 2018 14:09
Creates a simple editable WordPress Gutenberg block with Inspector controls that makes a button link
/**
* Simple editable block with inspection controls
*
* Creates an editable block to make a link button, but with inspection controlls on the sidebar
*/
/**
* Required components
*/
@eudesgit
eudesgit / wp-plugin-gutenberg-server-block.php
Created April 3, 2018 18:25
Registers the scripts and styles to create a WordPress Gutenberg block that is rendered on PHP
<?php
/**
* Registers the dynamic server side block JS script and its styles
*
* @since 1.0.0
* @return void
*/
public function register_dynamic_block_action ( ) {
$block_name = 'block-dynamic';