Changeset 2064744
- Timestamp:
- 04/07/2019 11:08:26 PM (7 years ago)
- Location:
- wp-frontend-helper
- Files:
-
- 2 edited
-
tags/1.0/readme.txt (modified) (3 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-frontend-helper/tags/1.0/readme.txt
r2064270 r2064744 1 === Plugin Name===1 === WP Frontend Helper === 2 2 Contributors: riccardooliva 3 3 Tags: frontend, development … … 7 7 Stable tag: 1.0 8 8 License: MIT 9 Tested up to: 5.1.1 9 10 10 11 A set of handful tools to ease your life as a frontend WP developer. … … 18 19 19 20 ## Managing assets efficiently 20 This plugin wraps the default WordPress methods which enqueue/dequeue/register/deregister your scripts and styles, adding 21 new handy filters you can hook to, which name is declared dynamically. You can get an instance of the helper by applying 22 the `wpfh/get_assets_manager` filter: 21 This plugin wraps the default WordPress methods which enqueue/dequeue/register/deregister your scripts and styles, adding new handy filters you can hook to, which name is declared dynamically. You can get an instance of the helper simply by applying a filter. 23 22 24 ```php 25 $assets_manager = apply_filters( 'wpfh/get_assets_manager' , '' ); 26 ``` 27 28 With the result object, you can start managing your assets. here is a list of methods you can use and the resulting filter 29 names. 30 31 | Wpfh method | WP method | Applied filters | 32 | ------------------- | ---------------------- | ------------------------------------------------------------ | 33 | `enqueue_script` | `wp_enqueue_script` | `wpfh/on_script_enqueue`, `wpfh/on_SCRIPTNAME_enqueue` | 34 | `enqueue_style` | `wp_enqueue_style` | `wpfh/on_style_enqueue`, `wpfh/on_STYLENAME_enqueue` | 35 | `register_script` | `wp_register_script` | `wpfh/on_script_register`, `wpfh/on_SCRIPTNAME_enqueue` | 36 | `register_style` | `wp_register_style` | `wpfh/on_style_register`, `wpfh/on_STYLENAME_register` | 37 | `dequeue_script` | `wp_dequeue_script` | `wpfh/on_script_dequeue`, `wpfh/on_SCRIPTNAME_dequeue` | 38 | `dequeue_style` | `wp_dequeue_style` | `wpfh/on_style_dequeue`, `wpfh/on_STYLENAME_dequeue` | 39 | `deregister_script` | `wp_deregister_script` | `wpfh/on_script_deregister`, `wpfh/on_SCRIPTNAME_deregister` | 40 | `deregister_style` | `wp_deregister_style` | `wpfh/on_style_deregister`, `wpfh/on_STYLENAME_deregister` | 41 42 Each `Wpfh` method accepts three arguments: 43 * `array $args`: the arguments that will be passed to the corresponding wp method; 44 * `bool|Callable $condition`: _(optional)_ a `true/false` value of a closure that will be evaluated 45 * `array $condition_args`: _(optional)_ array of arguments that will be passed to the closure, if required. 46 47 An example would be: 48 49 ```php 50 $wpfh->enqueue_style( [ 'bootstrap', '/path/to/boostrap.css' ], is_page_template( 'home' ) ); 51 ``` 52 53 Or, a more complex one: 54 55 ```php 56 $condition = function ( string $template_one, string $template_two ) { 57 return is_page_template( $template_one ) || is_page_template( $template_two ); 58 }; 59 $wpfh->enqueue_style( [ 'bootstrap', '/path/to/boostrap.css' ], $condition, [ 'home', 'blog' ] ); 60 $wpfh->enqueue_script( [ 'jquery', '/path/to/jquery.css' ], $condition, [ 'who-am-i', 'contacts' ] ); 61 ``` 62 63 Of course these are simple examples but this kind of helpers can save you a lot of repetitions, especially if you are 64 trying to optimize every page of your website. Other than the examples above, you can also *save predefined conditions* 65 which you can apply over and over simply by calling them. For example: 66 67 ```php 68 $wpfh->save_condition( 'a_condition_saved_before', true ); // Can also register custom Callables 69 $wpfh->enqueue_script([ 'vue-component', '/path/to/vuecomponent.js' ], $wpfh->apply_condition( 'a_condition_saved_before' ) ); 70 71 // Meanwhile, somewhere else (or in the same file, you choose): 72 add_filter( 'wpfh/on_vue-component_enqueue', function() { 73 $wpfh = apply_filters( 'wpfh/get_assets_manager' , '' ); 74 $wpfh->enqueue_script([ 'vue', '/path/to/vue.js' ]); 75 }, 9 ); // Priority 9 is here to ensure that Vue is enqueued BEFORE its component 76 ``` 23 Each time, for example, you enqueue a "myscript" script using this plugin methods, the "ons_script_enqueue" ant the "on_myscript_enqueue" filters will be applied. You can also save a set of conditions which willò execute the due asset enqueue/dequeue and so on only if it evaluates to true. 24 For code examples and more extensive documentation please head to the github repository: https://github.com/riccardooliva91/wordpress-frontend-helper/wiki 77 25 78 26 ## How can this plugin help? -
wp-frontend-helper/trunk/readme.txt
r2064267 r2064744 1 === Plugin Name===1 === WP Frontend Helper === 2 2 Contributors: riccardooliva 3 3 Tags: frontend, development … … 7 7 Stable tag: 1.0 8 8 License: MIT 9 Tested up to: 5.1.1 9 10 10 11 A set of handful tools to ease your life as a frontend WP developer. … … 18 19 19 20 ## Managing assets efficiently 20 This plugin wraps the default WordPress methods which enqueue/dequeue/register/deregister your scripts and styles, adding 21 new handy filters you can hook to, which name is declared dynamically. You can get an instance of the helper by applying 22 the `wpfh/get_assets_manager` filter: 21 This plugin wraps the default WordPress methods which enqueue/dequeue/register/deregister your scripts and styles, adding new handy filters you can hook to, which name is declared dynamically. You can get an instance of the helper simply by applying a filter. 23 22 24 ```php 25 $assets_manager = apply_filters( 'wpfh/get_assets_manager' , '' ); 26 ``` 27 28 With the result object, you can start managing your assets. here is a list of methods you can use and the resulting filter 29 names. 30 31 | Wpfh method | WP method | Applied filters | 32 | ------------------- | ---------------------- | ------------------------------------------------------------ | 33 | `enqueue_script` | `wp_enqueue_script` | `wpfh/on_script_enqueue`, `wpfh/on_SCRIPTNAME_enqueue` | 34 | `enqueue_style` | `wp_enqueue_style` | `wpfh/on_style_enqueue`, `wpfh/on_STYLENAME_enqueue` | 35 | `register_script` | `wp_register_script` | `wpfh/on_script_register`, `wpfh/on_SCRIPTNAME_enqueue` | 36 | `register_style` | `wp_register_style` | `wpfh/on_style_register`, `wpfh/on_STYLENAME_register` | 37 | `dequeue_script` | `wp_dequeue_script` | `wpfh/on_script_dequeue`, `wpfh/on_SCRIPTNAME_dequeue` | 38 | `dequeue_style` | `wp_dequeue_style` | `wpfh/on_style_dequeue`, `wpfh/on_STYLENAME_dequeue` | 39 | `deregister_script` | `wp_deregister_script` | `wpfh/on_script_deregister`, `wpfh/on_SCRIPTNAME_deregister` | 40 | `deregister_style` | `wp_deregister_style` | `wpfh/on_style_deregister`, `wpfh/on_STYLENAME_deregister` | 41 42 Each `Wpfh` method accepts three arguments: 43 * `array $args`: the arguments that will be passed to the corresponding wp method; 44 * `bool|Callable $condition`: _(optional)_ a `true/false` value of a closure that will be evaluated 45 * `array $condition_args`: _(optional)_ array of arguments that will be passed to the closure, if required. 46 47 An example would be: 48 49 ```php 50 $wpfh->enqueue_style( [ 'bootstrap', '/path/to/boostrap.css' ], is_page_template( 'home' ) ); 51 ``` 52 53 Or, a more complex one: 54 55 ```php 56 $condition = function ( string $template_one, string $template_two ) { 57 return is_page_template( $template_one ) || is_page_template( $template_two ); 58 }; 59 $wpfh->enqueue_style( [ 'bootstrap', '/path/to/boostrap.css' ], $condition, [ 'home', 'blog' ] ); 60 $wpfh->enqueue_script( [ 'jquery', '/path/to/jquery.css' ], $condition, [ 'who-am-i', 'contacts' ] ); 61 ``` 62 63 Of course these are simple examples but this kind of helpers can save you a lot of repetitions, especially if you are 64 trying to optimize every page of your website. Other than the examples above, you can also *save predefined conditions* 65 which you can apply over and over simply by calling them. For example: 66 67 ```php 68 $wpfh->save_condition( 'a_condition_saved_before', true ); // Can also register custom Callables 69 $wpfh->enqueue_script([ 'vue-component', '/path/to/vuecomponent.js' ], $wpfh->apply_condition( 'a_condition_saved_before' ) ); 70 71 // Meanwhile, somewhere else (or in the same file, you choose): 72 add_filter( 'wpfh/on_vue-component_enqueue', function() { 73 $wpfh = apply_filters( 'wpfh/get_assets_manager' , '' ); 74 $wpfh->enqueue_script([ 'vue', '/path/to/vue.js' ]); 75 }, 9 ); // Priority 9 is here to ensure that Vue is enqueued BEFORE its component 76 ``` 23 Each time, for example, you enqueue a "myscript" script using this plugin methods, the "ons_script_enqueue" ant the "on_myscript_enqueue" filters will be applied. You can also save a set of conditions which willò execute the due asset enqueue/dequeue and so on only if it evaluates to true. 24 For code examples and more extensive documentation please head to the github repository: https://github.com/riccardooliva91/wordpress-frontend-helper/wiki 77 25 78 26 ## How can this plugin help?
Note: See TracChangeset
for help on using the changeset viewer.