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 / admin_notice.php
Last active January 11, 2019 08:22
Admin notices (avisos panel administración)
<?php
/**
* Some example snippets for the control of notices in WordPress admin panel
*
* @package PCianes\AdminUtilities
* @since 1.0.0
* @author PCianes
* @license GNU General Public License 2.0+
*/
namespace PCianes\AdminUtilities;
@PCianes
PCianes / strings_utilities.php
Last active June 30, 2017 11:16
Some example snippets for the control of strings
<?php
/**
* Some snippets for the control of strings
*
* @package PCianes\StringsUtilities
* @since 1.0.0
* @author PCianes
* @license GNU General Public License 2.0+
*/
@PCianes
PCianes / GENESIS.php
Last active July 1, 2017 21:27
Genesis Utilities
<?php
/**
* Change the read more link -> post.php
*
* @package PCianes\GenesisUtilities
* @since 1.0.0
* @author Pablo Cianes
* @license GNU General Public License 2.0+
*/
@PCianes
PCianes / _breakpoints.scss
Last active July 3, 2017 11:02
Neat Breakpoints
// Native CSS breakpoint
@media screen and (max-width: 1023px) {
// styles
}
// Device size breakpoint
@media screen and (max-width: $screen-size--medium) {
// styles
}
@PCianes
PCianes / UTF-8.php
Created July 4, 2017 15:26
PHP Notes
<?php
namespace PCianes;
// use str_replace all the time instead of Regex instructions.
add_filter( 'the_content', __NAMESPACE__ . '\filter_the_content', 99 );
function filter_the_content( $content ) {
$encoding = 'UTF-8';
$needle = 'verlängert';
@PCianes
PCianes / namespace-2.php
Created July 5, 2017 09:39
Migrate from prefixing convention to PHP namespacing
<?php
/**
* Description
*
* @package ${NAMESPACE}
* @since 1.0.0
* @author hellofromTonya
* @link https://KnowTheCode.io
* @license GNU-2.0+
*/
@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+
*/
<?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 / 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;
}
@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() {