Skip to content

Instantly share code, notes, and snippets.

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

Ronald Huereca ronalfy

🏠
Working from home
View GitHub Profile
@ronalfy
ronalfy / cpt-template-contructor-area.php
Created May 19, 2016 20:30
Custom Post Type Templates Constructor Area
<?php
/*
Plugin Name: CPT Templates
Plugin URI: http://www.riversportokc.org/
Description: Create Custom Post Type Templates
Author: BigWing Interactive
Version: 1.0.0
Requires at least: 4.1
Author URI: http://bigwing.com
Contributors: ronalfy, bigwing
@ronalfy
ronalfy / cpt-template-init.php
Created May 19, 2016 20:31
Custom Post Types Template Init
<?php
public function init() {
add_action( 'add_meta_boxes', array( &$this, 'register_meta_boxes' ) );
$labels = array(
'name' => 'Galleries',
'singular_name' => 'Gallery',
'menu_name' => 'Galleries',
'name_admin_bar' => 'Galleries',
'add_new' => 'Add New',
'add_new_item' => 'Add New Gallery',
@ronalfy
ronalfy / post_type_choose_templates.php
Created May 19, 2016 20:32
Custom Post Type Template post_type_choose_templates
<?php
public function post_type_choose_templates() {
global $post;
$theme = wp_get_theme();
$post_types_templates_directory = $theme->get_stylesheet_directory() . '/cpt-templates/' . $post->post_type;
$files = self::scandir( $post_types_templates_directory, array( 'php' ) );
$current_page_template = get_post_meta( $post->ID, '_wp_page_template', true );
if ( ! $current_page_template ) {
$current_page_template = 'none';
}
@ronalfy
ronalfy / maybe_get_cpt_template.php
Last active May 19, 2016 20:33
Custom Post Type Templates maybe_get_cpt_template
<?php
public function maybe_get_cpt_template( $original_template ) {
$object = get_queried_object();
// Check if post type template
if ( is_object( $object ) && is_a( $object, 'WP_Post' ) && in_array( $object->post_type, $this->post_types ) ) {
$maybe_template = get_post_meta( $object->ID, '_wp_page_template', true );
if ( $maybe_template ) {
$template = get_query_template( $object->post_type, $maybe_template );
if ( file_exists( $template ) ) {
return $template;
@ronalfy
ronalfy / save_post.php
Last active May 19, 2016 20:34
Custom Post Type Templates save_post
<?php
public function save_post( $post_id ) {
if ( wp_is_post_revision( $post_id ) )
return;
if ( isset( $_POST[ 'post_type_page_template' ] ) ) {
$template = sanitize_text_field( $_POST[ 'post_type_page_template' ] );
if ( 'none' == $template ) {
delete_post_meta( $post_id, '_wp_page_template' );
} else {
@ronalfy
ronalfy / scan-dir.php
Created May 19, 2016 20:35
Custom Post Type Templates
<?php
private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) {
if ( ! is_dir( $path ) )
return false;
if ( $extensions ) {
$extensions = (array) $extensions;
$_extensions = implode( '|', $extensions );
}
@ronalfy
ronalfy / gravity-forms-gtm.php
Created September 15, 2016 20:37
Google Tag Manager for Gravity Forms
<?php
add_action( 'gform_after_submission', 'braums_after_submission', 10, 2 );
function braums_after_submission( $entry, $form ) {
?>
<script>
function braums_datalayer_push() {
var form_submission = sessionStorage.getItem('entry_<?php echo absint( $entry[ 'id' ] ); ?>');
if ( null == form_submission ) {
if ( typeof( dataLayer ) != 'undefined' ) {
dataLayer.push({'event': 'BWTrackEvent',
@ronalfy
ronalfy / mpp-bp.php
Last active April 6, 2022 03:46
User Profile Picture With BuddyPress
add_filter( 'bp_core_fetch_avatar', 'mpp_bp_avatar', 10, 2 );
function mpp_bp_avatar( $img, $params ) {
// Determine if user has an avatar override
$avatar_override = get_user_option( 'metronet_avatar_override', $params[ 'item_id' ] );
if ( !$avatar_override || $avatar_override != 'on' ) return $img;
$profile_post_id = absint( get_user_option( 'metronet_post_id', $params[ 'item_id' ] ) );
if ( 0 === $profile_post_id || 'mt_pp' !== get_post_type( $profile_post_id ) ) {
@ronalfy
ronalfy / allow-users-to-view-network.php
Created June 14, 2017 20:31
WP Force Login - Multisite - Allow All Logged In Users to View Network
<?php
/*
* Multisite for https://wordpress.org/plugins/wp-force-login/
* Allows all users of the network to view all sites and posts on the network
* Intended to be used as an mu-plugin
*/
add_action( 'template_redirect', function() {
if ( is_user_logged_in() ) {
remove_action('template_redirect', 'v_forcelogin');
}
@ronalfy
ronalfy / gform_add_page_event_label.php
Created June 30, 2018 15:34
Add Page to Event Label
<?php
add_filter( 'gform_pagination_event_label', 'ronalfy_gform_pagination_event_label', 10, 4 );
function ronalfy_gform_pagination_event_label( $label, $form, $source_page_number, $current_page_number ) {
$event_label = sprintf( '%s::%d::%d', esc_html( $_SERVER['REQUEST_URI'] ), absint( $source_page_number ), absint( $current_page_number ) );
return $event_label;
}
?>