Changeset 1556474
- Timestamp:
- 12/17/2016 12:00:10 AM (8 years ago)
- Location:
- speed-bumps
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
speed-bumps/tags/0.2.0/README.md
r1556451 r1556474 28 28 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: 29 29 30 ``` 31 register_speed_bump( 'speed_bump_sample', array( 32 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; }, 33 )); 34 add_filter( 'the_content', 'insert_speed_bumps', 1 ); 35 ``` 30 register_speed_bump( 'speed_bump_sample', array( 31 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; }, 32 )); 33 add_filter( 'the_content', 'insert_speed_bumps', 1 ); 34 36 35 37 36 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). 38 37 39 38 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). 40 ``` 41 register_speed_bump( 'speed_bump_sample', array(42 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; },43 'from_start' => 0,44 ));45 ``` 39 40 register_speed_bump( 'speed_bump_sample', array( 41 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; }, 42 'from_start' => 0, 43 )); 44 46 45 47 46 You can also selectively insert speed bumps into a string of content by calling Speed Bumps directly: 48 47 49 ``` 50 echo insert_speed_bumps( $content_to_be_inserted_into );51 ``` 48 49 echo insert_speed_bumps( $content_to_be_inserted_into ); 50 52 51 53 52 ## Frequently Asked Questions ## … … 70 69 **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! 71 70 72 ``` 73 register_speed_bump( 'rickroll', array( 74 'string_to_inject' => function() { return '<iframe width="420" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>'; }, 75 'minimum_content_length' => false, 76 'from_start' => false, 77 'from_end' => false, 78 )); 79 add_filter( 'the_content', 'insert_speed_bumps', 1 ); 80 ``` 71 register_speed_bump( 'rickroll', array( 72 'string_to_inject' => function() { return '<iframe width="420" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>'; }, 73 'minimum_content_length' => false, 74 'from_start' => false, 75 'from_end' => false, 76 )); 77 add_filter( 'the_content', 'insert_speed_bumps', 1 ); 78 81 79 82 80 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: 83 81 84 ``` 85 add_filter( 'speed_bumps_rickroll_constraints', 'give_you_up', 10, 4 ); 82 add_filter( 'speed_bumps_rickroll_constraints', 'give_you_up', 10, 4 ); 83 84 function give_you_up( $can_insert, $context, $args, $already_inserted ) { 85 if ( ! preg_match( '/give [^ ]+ up/i', $context['prev_paragraph'] ) ) { 86 $can_insert = false; 87 } 88 return $can_insert; 89 } 86 90 87 function give_you_up( $can_insert, $context, $args, $already_inserted ) {88 if ( ! preg_match( '/give [^ ]+ up/i', $context['prev_paragraph'] ) ) {89 $can_insert = false;90 }91 return $can_insert;92 }93 ```94 91 95 92 You could also disable it altogether with this filter (although why you would disable so soon after addition, only Rick Astley himself could answer): 96 93 97 ``` 98 add_filter( 'speed_bumps_rickroll_constraints', '__return_false' );99 ``` 94 95 add_filter( 'speed_bumps_rickroll_constraints', '__return_false' ); 96 100 97 101 98 ### How to remove default rules? ### … … 103 100 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: 104 101 105 ``` 106 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::content_is_long_enough_to_insert' );107 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::meets_minimum_distance_from_start' );108 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::meets_minimum_distance_from_end' );109 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Content\Injection::less_than_maximum_number_of_inserts' );110 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Content\Injection::meets_minimum_distance_from_other_inserts' );111 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Elements\Element_Constraints::meets_minimum_distance_from_elements' );112 ``` 102 103 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::content_is_long_enough_to_insert' ); 104 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::meets_minimum_distance_from_start' ); 105 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::meets_minimum_distance_from_end' ); 106 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Content\Injection::less_than_maximum_number_of_inserts' ); 107 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Content\Injection::meets_minimum_distance_from_other_inserts' ); 108 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Elements\Element_Constraints::meets_minimum_distance_from_elements' ); 109 113 110 114 111 ## Changelog ## -
speed-bumps/tags/0.2.0/readme.txt
r1556451 r1556474 27 27 28 28 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: 29 30 ``` 29 ` 31 30 register_speed_bump( 'speed_bump_sample', array( 32 31 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; }, 33 32 )); 34 33 add_filter( 'the_content', 'insert_speed_bumps', 1 ); 35 ` ``34 ` 36 35 37 36 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). 38 37 39 38 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). 40 ` ``39 ` 41 40 register_speed_bump( 'speed_bump_sample', array( 42 41 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; }, 43 42 'from_start' => 0, 44 43 )); 45 ` ``44 ` 46 45 47 46 You can also selectively insert speed bumps into a string of content by calling Speed Bumps directly: 48 47 49 ` ``48 ` 50 49 echo insert_speed_bumps( $content_to_be_inserted_into ); 51 ` ``50 ` 52 51 53 52 == Frequently Asked Questions == … … 69 68 70 69 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! 71 72 ``` 70 ` 73 71 register_speed_bump( 'rickroll', array( 74 72 'string_to_inject' => function() { return '<iframe width="420" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>'; }, … … 78 76 )); 79 77 add_filter( 'the_content', 'insert_speed_bumps', 1 ); 80 ` ``78 ` 81 79 82 80 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: 83 84 ``` 81 ` 85 82 add_filter( 'speed_bumps_rickroll_constraints', 'give_you_up', 10, 4 ); 86 83 … … 91 88 return $can_insert; 92 89 } 93 ` ``90 ` 94 91 95 92 You could also disable it altogether with this filter (although why you would disable so soon after addition, only Rick Astley himself could answer): 96 93 97 ` ``94 ` 98 95 add_filter( 'speed_bumps_rickroll_constraints', '__return_false' ); 99 ` ``96 ` 100 97 101 98 = How to remove default rules? = … … 103 100 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: 104 101 105 ` ``102 ` 106 103 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::content_is_long_enough_to_insert' ); 107 104 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::meets_minimum_distance_from_start' ); … … 110 107 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Content\Injection::meets_minimum_distance_from_other_inserts' ); 111 108 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Elements\Element_Constraints::meets_minimum_distance_from_elements' ); 112 ` ``109 ` 113 110 114 111 == Changelog == -
speed-bumps/trunk/README.md
r1556451 r1556474 28 28 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: 29 29 30 ``` 31 register_speed_bump( 'speed_bump_sample', array( 32 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; }, 33 )); 34 add_filter( 'the_content', 'insert_speed_bumps', 1 ); 35 ``` 30 register_speed_bump( 'speed_bump_sample', array( 31 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; }, 32 )); 33 add_filter( 'the_content', 'insert_speed_bumps', 1 ); 34 36 35 37 36 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). 38 37 39 38 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). 40 ``` 41 register_speed_bump( 'speed_bump_sample', array(42 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; },43 'from_start' => 0,44 ));45 ``` 39 40 register_speed_bump( 'speed_bump_sample', array( 41 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; }, 42 'from_start' => 0, 43 )); 44 46 45 47 46 You can also selectively insert speed bumps into a string of content by calling Speed Bumps directly: 48 47 49 ``` 50 echo insert_speed_bumps( $content_to_be_inserted_into );51 ``` 48 49 echo insert_speed_bumps( $content_to_be_inserted_into ); 50 52 51 53 52 ## Frequently Asked Questions ## … … 70 69 **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! 71 70 72 ``` 73 register_speed_bump( 'rickroll', array( 74 'string_to_inject' => function() { return '<iframe width="420" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>'; }, 75 'minimum_content_length' => false, 76 'from_start' => false, 77 'from_end' => false, 78 )); 79 add_filter( 'the_content', 'insert_speed_bumps', 1 ); 80 ``` 71 register_speed_bump( 'rickroll', array( 72 'string_to_inject' => function() { return '<iframe width="420" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>'; }, 73 'minimum_content_length' => false, 74 'from_start' => false, 75 'from_end' => false, 76 )); 77 add_filter( 'the_content', 'insert_speed_bumps', 1 ); 78 81 79 82 80 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: 83 81 84 ``` 85 add_filter( 'speed_bumps_rickroll_constraints', 'give_you_up', 10, 4 ); 82 add_filter( 'speed_bumps_rickroll_constraints', 'give_you_up', 10, 4 ); 83 84 function give_you_up( $can_insert, $context, $args, $already_inserted ) { 85 if ( ! preg_match( '/give [^ ]+ up/i', $context['prev_paragraph'] ) ) { 86 $can_insert = false; 87 } 88 return $can_insert; 89 } 86 90 87 function give_you_up( $can_insert, $context, $args, $already_inserted ) {88 if ( ! preg_match( '/give [^ ]+ up/i', $context['prev_paragraph'] ) ) {89 $can_insert = false;90 }91 return $can_insert;92 }93 ```94 91 95 92 You could also disable it altogether with this filter (although why you would disable so soon after addition, only Rick Astley himself could answer): 96 93 97 ``` 98 add_filter( 'speed_bumps_rickroll_constraints', '__return_false' );99 ``` 94 95 add_filter( 'speed_bumps_rickroll_constraints', '__return_false' ); 96 100 97 101 98 ### How to remove default rules? ### … … 103 100 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: 104 101 105 ``` 106 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::content_is_long_enough_to_insert' );107 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::meets_minimum_distance_from_start' );108 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::meets_minimum_distance_from_end' );109 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Content\Injection::less_than_maximum_number_of_inserts' );110 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Content\Injection::meets_minimum_distance_from_other_inserts' );111 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Elements\Element_Constraints::meets_minimum_distance_from_elements' );112 ``` 102 103 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::content_is_long_enough_to_insert' ); 104 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::meets_minimum_distance_from_start' ); 105 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::meets_minimum_distance_from_end' ); 106 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Content\Injection::less_than_maximum_number_of_inserts' ); 107 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Content\Injection::meets_minimum_distance_from_other_inserts' ); 108 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Elements\Element_Constraints::meets_minimum_distance_from_elements' ); 109 113 110 114 111 ## Changelog ## -
speed-bumps/trunk/readme.txt
r1556460 r1556474 27 27 28 28 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: 29 30 `register_speed_bump( 'speed_bump_sample', array(29 ` 30 register_speed_bump( 'speed_bump_sample', array( 31 31 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; }, 32 32 )); … … 37 37 38 38 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). 39 40 `register_speed_bump( 'speed_bump_sample', array(39 ` 40 register_speed_bump( 'speed_bump_sample', array( 41 41 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; }, 42 42 'from_start' => 0, … … 46 46 You can also selectively insert speed bumps into a string of content by calling Speed Bumps directly: 47 47 48 `echo insert_speed_bumps( $content_to_be_inserted_into ); 48 ` 49 echo insert_speed_bumps( $content_to_be_inserted_into ); 49 50 ` 50 51 … … 67 68 68 69 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! 69 70 `register_speed_bump( 'rickroll', array(70 ` 71 register_speed_bump( 'rickroll', array( 71 72 'string_to_inject' => function() { return '<iframe width="420" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>'; }, 72 73 'minimum_content_length' => false, … … 78 79 79 80 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: 80 81 `add_filter( 'speed_bumps_rickroll_constraints', 'give_you_up', 10, 4 );81 ` 82 add_filter( 'speed_bumps_rickroll_constraints', 'give_you_up', 10, 4 ); 82 83 83 84 function give_you_up( $can_insert, $context, $args, $already_inserted ) { … … 91 92 You could also disable it altogether with this filter (although why you would disable so soon after addition, only Rick Astley himself could answer): 92 93 93 `add_filter( 'speed_bumps_rickroll_constraints', '__return_false' ); 94 ` 95 add_filter( 'speed_bumps_rickroll_constraints', '__return_false' ); 94 96 ` 95 97
Note: See TracChangeset
for help on using the changeset viewer.