Title: Speed Bumps
Author: Daniel Bachhuber
Published: <strong>23 de juliol de 2015</strong>
Last modified: 17 de desembre de 2016

---

Cerca extensions

Aquesta extensió **no s’ha provat en les darreres 3 versions majors del WordPress**.
Segurament no està mantinguda o suportada, i pot tenir problemes de compatibilitat
quan s’usa en versions recents del WordPress.

![](https://s.w.org/plugins/geopattern-icon/speed-bumps.svg)

# Speed Bumps

 Per [Daniel Bachhuber](https://profiles.wordpress.org/danielbachhuber/)

[Baixa](https://downloads.wordpress.org/plugin/speed-bumps.0.2.0.zip)

 * [Detalls](https://ca.wordpress.org/plugins/speed-bumps/#description)
 * [Ressenyes](https://ca.wordpress.org/plugins/speed-bumps/#reviews)
 *  [Instal·lació](https://ca.wordpress.org/plugins/speed-bumps/#installation)
 * [Desenvolupament](https://ca.wordpress.org/plugins/speed-bumps/#developers)

 [Suport](https://wordpress.org/support/plugin/speed-bumps/)

## Descripció

Speed Bumps inserts speed bumps into site content based on business needs. This 
plugin requires code-level configuration.

Need a 300×250 unit inserted 3 paragraphs down on every story greater than 9 paragraphs
long? Speed Bumps makes seemingly complex business requests like this simple to 
implement within your WordPress environment.

Any number of speed bumps can be registered, from graphical elements to advertising
units to recirculation modules. Each speed bump inherits a default set of overridable
rules, and the speed bump can also dictate its own logic regarding acceptable placement.

To report bugs or feature requests, [please use Github issues](https://github.com/fusioneng/speed-bumps).

## Instal·lació

It’s a plugin! Install it like any other.

Onec you’ve installed the plugin, you’ll have to register one or more speed bumps
in order for it to have any effect. You’ll also have to specifically call Speed 
Bumps to filter your content – the plugin doesn’t attach any filters to `the_content`
or other hooks by itself.

The simplest way to have Speed Bumps process all of your content and insert speed
bumps into content everywhere is simply adding the filter following registration:

    ```
    register_speed_bump( 'speed_bump_sample', array(
        'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; },
    ));
    add_filter( 'the_content', 'insert_speed_bumps', 1 );
    ```

This registration results in the `string_to_inject` value being injected at the 
first opportunity based on the default rules (e.g. on posts longer than 1200 characters,
following the third paragraph OR following the paragraph which contains the 75th
word, whichever comes later).

Let’s say you wanted the speed bump higher in the content. You could modify the `
from_start` parameter to declare that the speed bump can be inserted after the first
paragraph (yes, like good engineers, we prefer zero-based indexing).

    ```
    register_speed_bump( 'speed_bump_sample', array(
        'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; },
        'from_start' => 0,
    ));
    ```

You can also selectively insert speed bumps into a string of content by calling 
Speed Bumps directly:

    ```
    echo insert_speed_bumps( $content_to_be_inserted_into );
    ```

## PMF

  What are the default rules?

The default options for speed bumps are currently:

 * Never insert in a post fewer than 8 paragraphs long, or fewer than 1200 characters.
 * Never insert before the the third paragraph, or before 75 words into the post.
 * Never insert fewer than 3 paragraphs or 75 words from the end of the article.
 * At least one paragraph from an iframe or embed.
 * At least two paragraphs from an image.
 * At least one paragraph from any other speed bump in the post.

  How to add more specific rules?

Adding a custom rule for a speed bump is a matter of defining a function and hooking
it to the `speed_bumps_{id}_constraints` filter. The function hooked to that filter
will receive several arguments to determine the state of the content, surrounding
paragraphs, and other context, and can return `false` to block insertion.

Simple, stupid example: You have a speed bump called «rickroll» which inserts a 
beautiful musical video throughout your content. You _really_ need this viral bump(
publisher’s words, not yours) so you disable minimum content length and the rules
regarding acceptable speed bump distance from start/end of the post. Greedy!

    ```
    register_speed_bump( 'rickroll', array(
        'string_to_inject' => function() { return ''; },
        'minimum_content_length' => false,
        'from_start' => false,
        'from_end' => false,
    ));
    add_filter( 'the_content', 'insert_speed_bumps', 1 );
    ```

But, maybe that’s a little too extreme. You want to show it in certain situations,
say, only when the previous paragraph contains the phrase ‘give {something} up’.
Here’s how you would achieve that:

    ```
    add_filter( 'speed_bumps_rickroll_constraints', 'give_you_up', 10, 4 );

    function give_you_up( $can_insert, $context, $args, $already_inserted ) {
        if ( ! preg_match( '/give [^ ]+ up/i', $context['prev_paragraph'] ) ) {
            $can_insert = false;
        }
        return $can_insert;
    }
    ```

You could also disable it altogether with this filter (although why you would disable
so soon after addition, only Rick Astley himself could answer):

    ```
    add_filter( 'speed_bumps_rickroll_constraints', '__return_false' );
    ```

  How to remove default rules?

Each rule is hooked to that speed bump’s «constraints» filter. To remove a rule,
simply remove the filter which defines that rule, like these lines which remove 
the default rules for your speed bump:

    ```
    remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::content_is_long_enough_to_insert' );
    remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::meets_minimum_distance_from_start' );
    remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::meets_minimum_distance_from_end' );
    remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Content\Injection::less_than_maximum_number_of_inserts' );
    remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Content\Injection::meets_minimum_distance_from_other_inserts' );
    remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Elements\Element_Constraints::meets_minimum_distance_from_elements' );
    ```

## Ressenyes

No hi ha ressenyes per a aquesta extensió.

## Col·laboradors i desenvolupadors

«Speed Bumps» és programari de codi obert. La següent gent ha col·laborat en aquesta
extensió.

Col·laboradors

 *   [ Daniel Bachhuber ](https://profiles.wordpress.org/danielbachhuber/)
 *   [ fusionengineering ](https://profiles.wordpress.org/fusionengineering/)
 *   [ goldenapples ](https://profiles.wordpress.org/goldenapples/)
 *   [ noppanit ](https://profiles.wordpress.org/noppanit/)

[Traduïu «Speed Bumps» a la vostra llengua.](https://translate.wordpress.org/projects/wp-plugins/speed-bumps)

### Interessats en el desenvolupament?

[Navegueu pel codi](https://plugins.trac.wordpress.org/browser/speed-bumps/), baixeu-
vos el [repositori SVN](https://plugins.svn.wordpress.org/speed-bumps/), o subscriviu-
vos al [registre de desenvolupament](https://plugins.trac.wordpress.org/log/speed-bumps/)
per [fisl de subscripció RSS](https://plugins.trac.wordpress.org/log/speed-bumps/?limit=100&mode=stop_on_copy&format=rss).

## Registre de canvis

#### 0.2.0 (December 15, 2016)

 * Compatability: Remove direct $wp_filter access for WP 4.7 compatability.
 * Compatability: Fix issues throwing warnings in PHP7.
 * Feature: Add «last ditch fallback» option for speed bump registration.
 * Feature: Add filter around speed bump insertion content.
 * Performance: Unregister speed bumps when global constraints prevent them being
   inserted.
 * Performance: Unregister speed bumps after inserting them the maximum number of
   times.
 * Performance: Allow speed bump constraint filters to short-circuit other filters
   at an insertion point, or to skip all remaining insertion points in a document.

#### 0.1.0 (July 23, 2015)

 * Initial release.
 * [Full release notes](http://fusion.net/story/170253/meet-speed-bumps-our-newest-open-source-release/)

## Meta

 *  Versió **0.2.0**
 *  Darrera actualització **fa 10 anys**
 *  Instal·lacions actives **40+**
 *  Versió del WordPress ** 4.2 o posterior **
 *  Provada fins a **4.7.33**
 *  Idioma
 * [English (US)](https://wordpress.org/plugins/speed-bumps/)
 * Etiquetes
 * [advertising](https://ca.wordpress.org/plugins/tags/advertising/)[content](https://ca.wordpress.org/plugins/tags/content/)
 *  [Vista avançada](https://ca.wordpress.org/plugins/speed-bumps/advanced/)

## Valoracions

Encara no s'ha enviat cap ressenya.

[Your review](https://wordpress.org/support/plugin/speed-bumps/reviews/#new-post)

[Visualitzeu totes les ressenyes](https://wordpress.org/support/plugin/speed-bumps/reviews/)

## Col·laboradors

 *   [ Daniel Bachhuber ](https://profiles.wordpress.org/danielbachhuber/)
 *   [ fusionengineering ](https://profiles.wordpress.org/fusionengineering/)
 *   [ goldenapples ](https://profiles.wordpress.org/goldenapples/)
 *   [ noppanit ](https://profiles.wordpress.org/noppanit/)

## Suport

Teniu quelcom a dir? Necessiteu ajuda?

 [Visualitza els fòrums de suport](https://wordpress.org/support/plugin/speed-bumps/)