Title: Speed Bumps
Author: Daniel Bachhuber
Published: <strong>2015 年 7 月 23 日</strong>
Last modified: 2016 年 12 月 17 日

---

搜尋外掛

這個外掛**並未在最新的 3 個 WordPress 主要版本上進行測試**。開發者可能不再對這個
外掛進行維護或提供技術支援，並可能會與更新版本的 WordPress 產生使用上的相容性問題。

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

# Speed Bumps

 由 [Daniel Bachhuber](https://profiles.wordpress.org/danielbachhuber/) 開發

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

 * [詳細資料](https://tw.wordpress.org/plugins/speed-bumps/#description)
 * [使用者評論](https://tw.wordpress.org/plugins/speed-bumps/#reviews)
 *  [安裝方式](https://tw.wordpress.org/plugins/speed-bumps/#installation)
 * [開發資訊](https://tw.wordpress.org/plugins/speed-bumps/#developers)

 [技術支援](https://wordpress.org/support/plugin/speed-bumps/)

## 外掛說明

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).

## 安裝方式

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 );
    ```

## 常見問題集

  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' );
    ```

## 使用者評論

這個外掛目前沒有任何使用者評論。

## 參與者及開發者

以下人員參與了開源軟體〈Speed Bumps〉的開發相關工作。

參與者

 *   [ 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/)

[將〈Speed Bumps〉外掛本地化為台灣繁體中文版](https://translate.wordpress.org/projects/wp-plugins/speed-bumps)

### 對開發相關資訊感興趣？

任何人均可[瀏覽程式碼](https://plugins.trac.wordpress.org/browser/speed-bumps/)、
查看 [SVN 存放庫](https://plugins.svn.wordpress.org/speed-bumps/)，或透過 [RSS](https://plugins.trac.wordpress.org/log/speed-bumps/?limit=100&mode=stop_on_copy&format=rss)
訂閱[開發記錄](https://plugins.trac.wordpress.org/log/speed-bumps/)。

## 變更記錄

#### 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/)

## 中繼資料

 *  版本 **0.2.0**
 *  最後更新 **9 年前**
 *  啟用安裝數 **30+**
 *  WordPress 版本需求 ** 4.2 或更新版本 **
 *  已測試相容的 WordPress 版本 **4.7.33**
 *  語言
 * [English (US)](https://wordpress.org/plugins/speed-bumps/)
 * 標籤:
 * [advertising](https://tw.wordpress.org/plugins/tags/advertising/)[content](https://tw.wordpress.org/plugins/tags/content/)
 *  [進階檢視](https://tw.wordpress.org/plugins/speed-bumps/advanced/)

## 評分

這個項目尚無任何評論記錄。

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

[查看全部使用者評論](https://wordpress.org/support/plugin/speed-bumps/reviews/)

## 參與者

 *   [ 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/)

## 技術支援

使用者可在技術支援論壇提出意見反應或使用問題。

 [檢視技術支援論壇](https://wordpress.org/support/plugin/speed-bumps/)