Skip to content

Instantly share code, notes, and snippets.

@oterox
oterox / remove_menu_items.php
Created Jul 14, 2019
WordPress Hide admin menu based on user role
View remove_menu_items.php
<?php
/* check if user is administrator - only show downloads menu if is admin */
add_action( 'admin_init', 'ox_remove_menu_pages' );
function ox_remove_menu_pages() {
global $user_ID;
//if the user is NOT an administrator remove the menu for downloads
if ( !current_user_can( 'administrator' ) ) { //change role or capability here
remove_menu_page( 'edit.php?post_type=wpdmpro' ); //change menu item here
}
}
@oterox
oterox / redirect-emails.php
Created Jul 14, 2019
Redirect All Emails on Staging Site
View redirect-emails.php
add_filter( 'wp_mail', 'ox_redirect_email_filter', 10, 1 );
function ox_redirect_email_filter( $args ) {
// Get original To address
$original_to = $args['to'];
// Send to developer only
$args['to'] = 'oterox@developer.com';
@oterox
oterox / proveedores_api.php
Created Jul 13, 2019
wp_remote_get proveedores API
View proveedores_api.php
$response = wp_remote_get( 'http://192.168.1.9:8080/users' );
if ( is_array( $response ) ) {
$body = wp_remote_retrieve_body( $response );
$data = json_decode( $body );
if( ! empty( $data ) ) {
echo '<ul>';
foreach( $data->objects as $product ) {
@oterox
oterox / scroll-anchor.js
Last active May 30, 2019
Scroll anchor jquery
View scroll-anchor.js
$(window).load(function(){
// Quitamos el # del hash
var hash = location.hash.replace('#','');
//Si hay un hash es que vamos a mostrar un tipo de pista
if(hash != ''){
//Hacemos scroll al id que viene en el hash y le quitamos 50px para que aparezca debajo del menú
$('html, body').animate({ scrollTop: $('#' + hash).offset().top - 50}, 1000);
}
@oterox
oterox / class-wc-api-custom.php
Last active Apr 28, 2019
Cutom API class woocommerce
View class-wc-api-custom.php
<?php
class WC_API_Custom extends WC_API_Resource {
protected $base = '/experiences';
public function register_routes( $routes ) {
$routes[ $this->base ] = array(
array( array( $this, 'get_experiences' ), WC_API_Server::READABLE )
);
return $routes;
@oterox
oterox / functions.php
Created Apr 28, 2019
WP Rest API cpt
View functions.php
/**
* Add REST API support to an already registered post type.
*/
add_filter( 'register_post_type_args', 'my_post_type_args', 10, 2 );
function my_post_type_args( $args, $post_type ) {
if ( 'destination' === $post_type ) {
$args['show_in_rest'] = true;
@oterox
oterox / rewrites.php
Last active Oct 10, 2018
Custom rewrite rules
View rewrites.php
add_filter('post_type_link', 'ox_post_type_link', 1, 3);
function ox_post_type_link( $link, $post = 0 ){
if ( $post->post_type == 'plan' ){
$terms = wp_get_object_terms( $post->ID, 'tax_destination' );
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0]))
$taxonomy_slug = $terms[0]->slug;
return home_url( $taxonomy_slug .'/' . $post->post_name );
View demo-core.php
<?php
/**
* Plugin Name: ox Core
* Plugin URI: https://github.com/citricamente/ox-core
* Version: 0.2
* Author: Citricamente
* License: GPL2
* Text Domain: barcelo-core
* Domain Path: /languages
*/
@oterox
oterox / snnipets.php
Last active Jun 13, 2016
woocommerce snippets
View snnipets.php
<?php
add_filter('add_to_cart_redirect', 'themeprefix_add_to_cart_redirect');
function themeprefix_add_to_cart_redirect() {
global $woocommerce;
$checkout_url = $woocommerce->cart->get_checkout_url();
return $checkout_url;
}
//Add New Pay Button Text