Skip to content

Instantly share code, notes, and snippets.

View PCianes's full-sized avatar
🏠
Working from home

Pablo Cianes PCianes

🏠
Working from home
View GitHub Profile
@PCianes
PCianes / index.html
Last active February 14, 2020 15:13
Bouncing balls// source https://jsbin.com/xoqejok
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Bouncing balls</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>bouncing balls</h1>
<canvas></canvas>
@PCianes
PCianes / index.html
Created February 14, 2020 07:06
JavaScript for WordPress Writing JavaScript in the Browser // source https://jsbin.com/jedukem
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Writing JavaScript in the Browser">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="style.css" media="screen">
<title>JavaScript for WordPress</title>
<style id="jsbin-css">
form {
@PCianes
PCianes / admin_category_cpt.php
Last active July 9, 2017 21:48
Add a Custom Column in Posts and Custom Post Types Admin Screen
<?php
// Attention name filter & action: change "slug-cpt"
add_filter('manage_slug-cpt_posts_columns', 'pc_columns_head');
add_action('manage_slug-cpt_posts_custom_column', 'pc_columns_content', 10, 2);
// ADD NEW COLUMN
function pc_columns_head($defaults) {
$defaults['categorias'] = 'Categorías';
return $defaults;
}
@PCianes
PCianes / filter_query_loop.php
Last active July 8, 2017 22:41
Filter the query: filter content of posts accoring to post title and meta value
<?php
// To plugin or functions.php
add_filter( 'posts_where', 'your_title_func', 10, 2 );
function your_title_func( $where, &$the_query )
{
global $wpdb;
if ( $search_title = $the_query->get( 'search_title' ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( like_escape( $search_title ) ) . '%\'';
}
@PCianes
PCianes / example.php
Created July 8, 2017 21:23
Shortcode into php with ob_start()
<?php ob_start(); ?>
<CENTER>
<FORM>
<input type="button" value="Submit">
</FORM>
</CENTER>
<?php $to_lock = ob_get_contents(); ob_end_clean(); ?>
@PCianes
PCianes / wc_icon_status.php
Last active July 8, 2017 19:46
Adding a WooCommerce Custom Order Status
<?php
/**
* Adds icons for any custom order statuses
**/
add_action( 'wp_print_scripts', 'pc_add_custom_order_status_icon' );
function pc_add_custom_order_status_icon() {
if( ! is_admin() ) {
return;
}
@PCianes
PCianes / capability.php
Created July 8, 2017 15:42
Add capability to user or role
<?php
// Example 1
function add_cap_upload_files_to_user_id() {
$user = new WP_User( $user_id );
$user->add_cap( 'upload_files' );
}
add_action( 'admin_init', 'add_cap_upload_files_to_user_id');
// Example 2
function allow_contrib_upload() {
@PCianes
PCianes / display_post_states.php
Last active July 8, 2017 14:32
Add Custom Post States to WordPress posts and pages
<?php
add_filter('display_post_states', 'pc_custom_post_states', 10 , 2);
function pc_custom_post_states($states, $post) {
if( ('page'==get_post_type($post->ID)) && ('page-templates/custom-page-template.php'==get_page_template_slug($post->ID)) ) {
$states[] = __('Custom state');
}
return $states;
}
<?php
// Example SQL Get a custom field
SELECT meta_value
FROM wp_postmeta
WHERE post_id IN (8) AND meta_key = 'subtitle';
add_action( 'genesis_entry_header', 'pc_render_the_subtitle', 11 );
function pc_render_the_subtitle() {
$subtitle = get_post_meta( get_the_ID(), 'subtitle', true );
if ( ! $subtitle ) {
@PCianes
PCianes / class-static-user.php
Created July 5, 2017 11:27
PHP Object-Oriented Programming (OOP) for WordPress
<?php
/**
* User Blueprint
*
* @package PCianes\OOPSandbox
* @since 1.0.0
* @author Pablo Cianes
* @link https://pablocianes.com
* @license GNU-2.0+
*/