Skip to content

Instantly share code, notes, and snippets.

View klihelp's full-sized avatar
🎯
Focusing on life and money farm

klihelp

🎯
Focusing on life and money farm
View GitHub Profile
<?php
/**
* Make an internal REST request
*
* @global WP_REST_Server $wp_rest_server ResponseHandler instance (usually WP_REST_Server).
* @param $request_or_method WP_REST_Request|string A WP_REST_Request object or a request method
* @param $path (optional) if the path is not specific in the rest request, specify it here
* @param $data (optional) option data for the request.
* @return WP_Error|mixed
@joehoyle
joehoyle / private-wp-api.php
Created October 14, 2015 18:37
Only allow access to the API for authenticated requests
<?php
add_filter( 'rest_pre_dispatch', function() {
if ( ! is_user_logged_in() ) {
return new WP_Error( 'not-logged-in', 'API Requests are only supported for authenticated requests', array( 'status' => 401 ) );
}
} );
@yoren
yoren / extra.php
Last active August 3, 2016 19:35
Cookie Authentication In A AngularJS WordPress Theme
<?php
// The following function is from: https://github.com/WP-API/WP-API/blob/2.0-beta4/extras.php#L84-L136
/**
* Check for errors when using cookie-based authentication.
*
* WordPress' built-in cookie authentication is always active
* for logged in users. However, the API has to check nonces
* for each request to ensure users are not vulnerable to CSRF.
*
* @global mixed $wp_rest_auth_cookie
@yoren
yoren / functions-1.php
Last active February 18, 2016 04:17
Upgrading Your AngularJS Theme To Work With WP API V2
<?php
function my_rest_prepare_post( $data, $post, $request ) {
$_data = $data->data;
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$thumbnail = wp_get_attachment_image_src( $thumbnail_id );
$_data['featured_image_thumbnail_url'] = $thumbnail[0];
$data->data = $_data;
@rugor
rugor / wp-gallery-attributes
Last active January 19, 2016 20:50
Add data attributes to wordpress gallery image srcs #rugor #st
@joehoyle
joehoyle / wp-api-batch.php
Last active March 7, 2024 02:13
Batch endpoint for the WP REST API
<?php
/**
* Plugin Name: WP REST API Batch Requests
* Description: Enabled a multi / batch requests endpoint for the WP RES API
* Author: Joe Hoyle
* Version: 1.0-alpha1
* Plugin URI: https://github.com/WP-API/WP-API
* License: GPL2+
*/
@mikejolley
mikejolley / ipn-test.php
Last active September 5, 2024 01:54
Quick snippet/plugin/dropin to test IPN support
<?php
/**
* Plugin Name: PayPal Sandbox IPN Tester
* Description: Pings the IPN endpoint to see if your server can connect. Just head to <a href="/?ipn-test=1">yoursite.com/?ipn-test=1</a> whilst logged in as admin.
* Version: 1.0.0
* Author: WooThemes
* Requires at least: 4.1
* Tested up to: 4.3
*/
if ( ! defined( 'ABSPATH' ) ) {
@MindyPostoff
MindyPostoff / order-notes-required.php
Last active July 31, 2020 13:16
Make the Order Notes field required in the WooCommerce Checkout
// Place this code in your theme's functions.php file
// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['order']['order_comments']['required'] = true;
return $fields;
}
@Jany-M
Jany-M / WP_is_plugin_active.php
Created August 12, 2015 14:54
[WordPress] Check from Frontend/Theme if a plugin is active
<?php // Check from theme if a plugin is active - Place in functions.php or similar
if(!function_exists('plugin_is_active')) {
function plugin_is_active($plugin_folder, $plugin_file) {
if(!isset($plugin_file) || $plugin_file == '') $plugin_file = $plugin_folder;
return in_array($plugin_folder.'/'.$plugin_file.'.php', apply_filters('active_plugins', get_option('active_plugins')));
}
}
?>