Skip to content

Instantly share code, notes, and snippets.

@websupporter
websupporter / upload-a-file.MD
Created June 15, 2017 14:34
Upload a file using the WordPress REST API

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

@websupporter
websupporter / change-oembed-output.php
Last active February 1, 2022 15:36
Change the oEmbed output of WordPress
<?php
add_filter( 'oembed_response_data', 'fwe_oembed_response_data', 11, 4 );
function fwe_oembed_response_data( $data, $post, $width, $height ){
if ( ! is_object( $post ) )
return $data;
if( ! has_post_thumbnail( $post->ID ) )
return $data;
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$image = wp_get_attachment_image_src( $thumbnail_id, 'full' );
@websupporter
websupporter / oembed-youtube-thumbnails.php
Last active May 8, 2020 05:21
Replace the Youtube embed with a thumbnail
<?php
add_filter( 'oembed_result', 'fwe_oembed_result', 10, 3 );
function fwe_oembed_result( $result, $url, $args ){
//Uebernommen aus wp-includes/class-oembed.php
//L38ff
$youtube_regex = array(
'#http://((m|www)\.)?youtube\.com/watch.*#i',
'#https://((m|www)\.)?youtube\.com/watch.*#i',
'#http://youtu\.be/.*#i',
'#https://youtu\.be/.*#i',
add_action('init',
function() {
unregister_block_type('core/latest-posts');
register_block_type(
'core/latest-posts',
array(
'attributes' => array(
'categories' => array(
'type' => 'string',
),
<?php
$upgrading = time();
<?php
/**
* Plugin Name: Deactivate WordPress
* Author: David Remer
* Description: Do use with care. Actually: Do not use!
**/
function deactivate_wordpress() {
remove_action( 'all', 'deactivate_wordpress' );
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteRule . /index.html [L]
</IfModule>
# END WordPress
<!doctype html>
<html>
<head>
<title>Deaktiviert</title>
</head>
<body>
<p>Diese Seite wurde deaktivert.</p>
</body>
</html>
<?php
function wpcodex_hide_email_shortcode( $atts , $content = null ) {
if ( ! is_email( $content ) ) {
return;
}
return '<a href="mailto:' . antispambot( $content ) . '">' . antispambot( $content ) . '</a>';
}
add_shortcode( 'email', 'wpcodex_hide_email_shortcode' );
<?php
echo antispambot( 'max.mustermann@example.com' );
// Real output: &#109;ax.&#109;&#117;s&#116;erma&#110;&#110;&#64;&#101;&#120;a&#109;&#112;le&#46;&#99;om
?>