Skip to content

Instantly share code, notes, and snippets.

@carlodaniele
carlodaniele / tinymce-example-plugin.php
Created December 3, 2016 08:47
An example WP plugin to show how to register TinyMCE plugins in WordPress
<?php
/**
* @package TinyMCE_example_plugin
* @version 1.0
*/
/*
Plugin Name: TinyMCE example plugin
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This is an example plugin
Author: Your Name
@carlodaniele
carlodaniele / build-custom-query.php
Last active November 6, 2022 10:36
Build a custom query with pre_get_posts
<?php
/**
* Build a custom query
*
* @param $query obj The WP_Query instance (passed by reference)
*
* @link https://codex.wordpress.org/Class_Reference/WP_Query
* @link https://codex.wordpress.org/Class_Reference/WP_Meta_Query
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
*/
@carlodaniele
carlodaniele / block.json
Last active September 28, 2022 18:14
An example Gutenberg block (not for production)
{
"apiVersion": 2,
"name": "my-affiliate-plugin/my-affiliate-block",
"version": "0.1.0",
"title": "Affiliate Block",
"category": "design",
"icon": "money",
"keywords": [ "kinsta", "affiliate", "money" ],
"description": "An example block for Kinsta readers",
"supports": {
@carlodaniele
carlodaniele / custom_menu_admin.php
Last active May 26, 2022 20:32
A basic plugin showing how to add menu metaboxes to admin menu page
<?php
/**
* @package Custom_menu_admin
* @version 1.0
*/
/*
Plugin Name: Custom menu admin
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This is an example plugin
Author: Carlo Daniele
@carlodaniele
carlodaniele / kinsta_users.php
Last active December 14, 2021 21:40
A plugin for registering a custom post type with a specific set of capabilities
<?php
/**
* @package Kinsta_users
* @version 1.0
*/
/*
Plugin Name: Kinsta users
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This is an example plugin
Author: Carlo Daniele
<?php
/**
* Prints style element
*/
function myplugin_custom_css() {
$output = '<style> #wpadminbar #wp-admin-bar-editor-menu .ab-icon:before { content: "\f322"; top: 2px; } </style>';
echo $output;
}
add_action( 'wp_head', 'myplugin_custom_css' );
@carlodaniele
carlodaniele / login-logo.php
Created February 28, 2016 08:47
Login page logo customization
<?php
/**
* Replace default login logo with custom image
*
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/login_head
*/
function my_login_logo() {
echo '<style type="text/css">.login h1 a { background-image:url('. get_stylesheet_directory_uri() .'/imgs/super_wp.png); }</style>';
}
add_action('login_head', 'my_login_logo');
@carlodaniele
carlodaniele / custom-book-author-query.php
Created March 16, 2016 20:28
Build a custom meta query
<?php
/**
* Build a custom query
*
* @param $query obj The WP_Query instance (passed by reference)
*
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
*/
function myplugin_pre_get_posts( $query ) {
// check if the user is requesting an admin page
@carlodaniele
carlodaniele / cd-hide-wordpress-version.php
Last active September 23, 2021 16:01
This plugin hides all WP versions from the head of the document and anables auto updates. It could be placed in /wp-content/mu-plugin folder
<?php
/**
* @package CD Hide WordPress Version
* @version 1.0
*/
/*
Plugin Name: CD Hide WordPress Version
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This plugin removes the version number from WordPress pages
Author: Carlo Daniele
@carlodaniele
carlodaniele / food-example-plugin-2.php
Created November 15, 2016 20:59
An example for WPMU readers
<?php
/**
* @package Food_example_plugin_2
* @version 1.0
*/
/*
Plugin Name: Food example plugin 2
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This is an example plugin for WPMU DEV readers
Author: Carlo Daniele