|
| 1 | +# WordPress Fns |
| 2 | + |
| 3 | +A collection of functions to help with WordPress theme & plugin development. |
| 4 | + |
| 5 | +# Install |
| 6 | + |
| 7 | +Install from Composer: |
| 8 | + |
| 9 | +```bash |
| 10 | +composer require ed-itsolutions/wordpress-fns |
| 11 | +``` |
| 12 | + |
| 13 | +Then add `require('vendor/autoload.php');` to the top of your `functions.php`. |
| 14 | + |
| 15 | +# Functions |
| 16 | + |
| 17 | +## wordpress_fns_as_filter($functionName, $priority = 10, $args = 1) |
| 18 | + |
| 19 | +Adds the named function `$functionName` as a filter with the same name. |
| 20 | + |
| 21 | +## wordpress_fns_featured_image_at_size($postId, $imageSize) |
| 22 | + |
| 23 | +Returns the given posts `$postId` featured image at size `$imageSize`. |
| 24 | + |
| 25 | +Returns `false` if the post does not have a featured image. |
| 26 | + |
| 27 | +## wordpress_fns_get_attachment_id_from_url($url) |
| 28 | + |
| 29 | +Returns the id of the attachment from the url. Extremely useful when working with meta boxes etc... that store an images URL instead of its attachment id. |
| 30 | + |
| 31 | +Returns `false` if no attachment could be found. |
| 32 | + |
| 33 | +## wordpress_fns_get_page_sub_menu_items($pageId, $menuName) |
| 34 | + |
| 35 | +Returns an array of menu items that are the direct desendants of the supplied page `$pageId` on the menu `$menuName`. |
| 36 | + |
| 37 | +Returns an empty array if it couldn't find the menu item for the supplied page. |
| 38 | + |
| 39 | +## wordpress_fns_header_or_featured_image($imageSize) |
| 40 | + |
| 41 | +If the page has a featured image that image at the given size `$imageSize` will be returned, otherwise it returns the header image set in the customizer. |
| 42 | + |
| 43 | +# Contributing |
| 44 | + |
| 45 | +We welcome PRs to this project. If you have a function or improvement feel free to add them. |
| 46 | + |
| 47 | +We ask that: |
| 48 | + |
| 49 | + - All functions be prefixed with `wordpress_fns_`. |
| 50 | + - All functions return `false` instead of throwing an error or null. |
| 51 | + - Don't add actions or filters, if users want to use a function as a filter they can do it themselves. |
0 commit comments