Skip to content

Instantly share code, notes, and snippets.

@marcelo2605
marcelo2605 / scroll div detect
Created October 1, 2014 12:17
Detectar o id de uma div durante scroll horizontal
var windowWidth = $( window ).width();
$(window).scroll(function() {
var winLeft = $(this).scrollLeft();
var left = $.grep($('.section'), function(item) {
return $(item).position().left <= winLeft + windowWidth/2;
});
var current = left.slice(-1)[0];
var currentId = $(current).attr('id');
if(!$('a[href$="'+currentId+'"]').hasClass('ativo')){
@marcelo2605
marcelo2605 / gist:b195243976cb9c7f3f53
Last active September 25, 2015 17:13 — forked from LinzardMac/gist:4b4bcbef09d72b777619
[WordPress] Override author drop down to include all users from all roles/ caps in post creation screens
/**
* override output of author drop down to include ALL user roles
*/
add_filter('wp_dropdown_users', 'include_all_users');
function include_all_users($output)
{
//set the $post global for checking user against author
global $post;
$users = get_users();
<?php
/**
* BuddyPress - Members Home
*
* @package BuddyPress
* @subpackage bp-legacy
*/
?>
require_once('PagSeguroLibrary/PagSeguroLibrary.php');
function generate_pagseguro($user_id){
// Instantiate a new payment request
$paymentRequest = new PagSeguroPaymentRequest();
// Set the currency
$paymentRequest->setCurrency("BRL");
@marcelo2605
marcelo2605 / functions.php
Created June 22, 2018 17:33
Add an audio description with the audio player.
add_filter('wp_audio_shortcode', function ($html, $atts, $audio, $post_id, $library) {
$media_id = attachment_url_to_postid($atts['mp3']);
if (0 !== $media_id) {
$content = get_post_field('post_content', $media_id);
$content = apply_filters('the_content', $content);
if (!empty($content)) {
$html = $html.'<div class="audio-description">'.$content.'</div>';
}
}
@marcelo2605
marcelo2605 / functions.php
Created August 2, 2018 16:09
Replace <p> by <figure> around images and make tables responsive using table-responsive Bootstrap class
/**
* Replace <p> by <figure> around images and make tables responsive using table-responsive Bootstrap class
*/
add_filter( 'the_content', function($content) {
$content = preg_replace('/<p>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\\/p>/s', '<figure class="content-image">$1</figure>', $content);
// Run only if is a singular post page
if (is_singular()) {
$content = preg_replace("/(<table(?s).*<\/table>)/i", "<div class='table-responsive'>$1</div>", $content);
}
@marcelo2605
marcelo2605 / functions.php
Created September 21, 2018 11:33
Filter "Recent posts" widget to show only posts that have the same category that current post.
/**
* Add parameter to Recent post widget
*/
add_filter('widget_posts_args', function($params){
$categories = get_the_category(get_the_ID());
$params['cat'] = $categories[0]->term_id;
return $params;
});
@marcelo2605
marcelo2605 / index.html
Created December 20, 2018 14:57
Open and close multiple dropdowns
<div class="dropdown">
<button class="dropdown-toggle" type="button">Dropdown</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Item 1</a>
<a class="dropdown-item" href="#">Item 2</a>
</div>
</div>
@marcelo2605
marcelo2605 / pagination.php
Created January 4, 2019 13:24
Pagination with custom wp_query
// more options here: https://codex.wordpress.org/Function_Reference/paginate_links
public static function getPagination($pages = null)
{
$args = array(
'prev_next' => false,
'type' => 'list'
);
if ($pages) {
@marcelo2605
marcelo2605 / functions.php
Created January 11, 2019 16:54
Register new order status on WooCommerce
/**
* Register new status
*
**/
add_action('init', function() {
register_post_status('wc-producao', array(
'label' => 'Em produção',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,