Skip to content

Instantly share code, notes, and snippets.

@gmazzap
gmazzap / Controller.php
Last active December 28, 2024 16:23
WordPress plugin to ease the creation of virtual pages.
<?php
namespace GM\VirtualPages;
/**
* @author Giuseppe Mazzapica <[email protected]>
* @license http://opensource.org/licenses/MIT MIT
*/
class Controller implements ControllerInterface {
private $pages;
@keithdevon
keithdevon / relevanssi-custom-functions.php
Last active January 25, 2024 12:51
Relevanssi job search
// filter relevanssi based on job_region query
add_filter('relevanssi_modify_wp_query', 'region_tax_query');
function region_tax_query($query) {
$tax_query = array();
if (!empty($query->query_vars['job_region'])) {
$tax_query[] = array(
'taxonomy' => 'region',
'field' => 'id',
'terms' => $query->query_vars['job_region']
@ScreamingDev
ScreamingDev / push-media.php
Created November 3, 2014 14:11
Import images in the uploads folder to the WordPress Media
<?php
define( 'DOING_AJAX', true );
define( 'WP_ADMIN', true );
define( 'WP_IMPORTING', true );
$err = array();
/** Load WordPress Bootstrap */
require_once '../../../../wp-load.php';
@nicomollet
nicomollet / wp_auto_install.sh
Last active October 23, 2024 23:23
WP-CLI auto install script
#!/bin/bash
# Default options
LOCALE="fr_FR"
DB_HOST='localhost'
VIRUSTOTAL_KEY='YOUR_KEY'
printf "Name of the project? cf My Project: "
read PROJECT_NAME
@matheuseduardo
matheuseduardo / get-page-by-slug.php
Last active November 20, 2024 21:12 — forked from micahblu/gist:5786794
get_page_by_slug - wordpress
<?php
/**
* Retrieve a page given its slug.
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $page_slug Page slug
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A.
* Default OBJECT.
* @param string|array $post_type Optional. Post type or array of post types. Default 'page'.
<?php
class WP_Metatags {
private static $tags = array();
public static function set_tag( $handle, $content, $type = 'name' ) {
if ( ! is_array( self::$tags ) ) {
return new WP_Error( 'metatags_already_printed', __( 'The HTML `meta` tags have already been printed.' ) );
}
@vstm
vstm / gist:12cb0b79462e254b7d5c
Last active January 23, 2024 22:06
Debug wp_oembed-problems
<?php
require_once("wp-load.php");
add_action('http_api_debug', 'test_http_api_debug', 10, 5);
add_filter('oembed_remote_get_args', 'test_oembed_remote_get_args', 10, 2);
add_filter('oembed_fetch_url', 'test_oembed_fetch_url', 10, 3);
$embed_code = wp_oembed_get('http://vimeo.com/75343493');
<?php
/*
* If you already have something in your functions.php, please remove these first few lines
*/
// Usage tribe_is_past_event( $event_id )
function tribe_is_past_event( $event = null ){
if ( ! tribe_is_event( $event ) ){
return false;
}
$event = tribe_events_get_event( $event );
@TimBHowe
TimBHowe / woocommerce-variation-grid-add-cart.php
Last active September 27, 2021 18:24
Include this in your theme to allow WooCommerce variable products to be displayed in a grid format with each variation having there own quantity and add to cart button, rather then the drop-down options. This should be include in your themes function file.
<?php
/**
* Woocommerce Custom Variation Output
*
* The following function allow for the theme to display product variations in a grid format.
* This code could be moved to a plugin but is in the theme function file as it used the
* themes grid system.
*
* @package WooGrid
* @since WooGrid 1.2
new WP_Error( $code, $message );
new WP_Error( $code, $message, array( 'status' => 400 ) );
new WP_Error( $code, __( 'Invalid existing meta data for action.' ), array( 'status' => 400 ) );
new WP_Error( $code, __( 'Invalid provided meta data for action.' ), array( 'status' => 400 ) );
new WP_Error( 'forbidden', 'You are not allowed to do this', array( 'status' => 403 ) );
new WP_Error( 'invalid-method', __( 'Method not implemented. Must be over-ridden in subclass.' ), array( 'status' => 405 ) );
new WP_Error( 'json_missing_callback_param', sprintf( __( 'Missing parameter %s' ), $param->getName() ), array( 'status' => 400 ) );
new WP_Error( 'rest_already_deleted', __( 'The post has already been deleted.' ), array( 'status' => 410 ) );
new WP_Error( 'rest_cannot_assign_sticky', __( 'You do not have permission to make posts sticky.' ), array( 'status' => 403 ) );
new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to post on this site.' ), array( 'status' => 400 ) );