| | 132 | * Load a template part from a plugin |
| | 133 | * |
| | 134 | * Makes it easy for a plugin to reuse sections of code |
| | 135 | * |
| | 136 | * Includes the named template part if a name is specified then a |
| | 137 | * specialised part will be included. If the plugin contains no {slug}.php file |
| | 138 | * then no template will be included. |
| | 139 | * |
| | 140 | * The template is included using require, unless require_once is specified, so you may include the |
| | 141 | * same template part multiple times. |
| | 142 | * |
| | 143 | * For the $name parameter, if the file is called "{slug}-special.php" then specify |
| | 144 | * "special". |
| | 145 | * |
| | 146 | * @since 3.6.0 |
| | 147 | * @uses do_action() Calls 'get_plugin_part_{$slug}' action. |
| | 148 | * |
| | 149 | * @param string $plugin The slug name for the plugin |
| | 150 | * @param string $slug The slug name for the generic template. |
| | 151 | * @param string $name The name of the specialised template. |
| | 152 | * @param bool $require_once Whether to require_once or require. Default true. |
| | 153 | */ |
| | 154 | function get_plugin_part( $plugin, $slug, $name = null, $require_once = false ) { |
| | 155 | do_action( "get_plugin_part_{$slug}", $slug, $name ); |
| | 156 | |
| | 157 | $templates = array(); |
| | 158 | if ( ! empty( $name ) ) |
| | 159 | $templates[] = "{$plugin}/{$slug}-{$name}.php"; |
| | 160 | |
| | 161 | $templates[] = "{$plugin}/{$slug}.php"; |
| | 162 | |
| | 163 | $located = ''; |
| | 164 | foreach ( (array) $templates as $template_name ) { |
| | 165 | if ( ! $template_name ) |
| | 166 | continue; |
| | 167 | if ( file_exists( WP_PLUGIN_DIR . '/' . $template_name ) ) { |
| | 168 | $located = WP_PLUGIN_DIR . '/' . $template_name; |
| | 169 | break; |
| | 170 | } |
| | 171 | } |
| | 172 | |
| | 173 | if ( '' != $located ) { |
| | 174 | if ( $require_once ) |
| | 175 | require_once( $located ); |
| | 176 | else |
| | 177 | require( $located ); |
| | 178 | } |
| | 179 | |
| | 180 | return $located; |
| | 181 | } |
| | 182 | |
| | 183 | /** |