| 1 |
<?php |
| 2 |
/** |
| 3 |
* Widgets |
| 4 |
* |
| 5 |
* @package Cooked |
| 6 |
* @subpackage Widgets |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly |
| 11 |
if ( ! defined( 'ABSPATH' ) ) |
| 12 |
exit; |
| 13 |
|
| 14 |
require_once 'widgets/init.php'; |
| 15 |
|
| 16 |
class Cooked_Widgets { |
| 17 |
|
| 18 |
public function __construct() { |
| 19 |
add_action( 'widgets_init', [ &$this, 'register_widgets' ], 10, 1 ); |
| 20 |
} |
| 21 |
|
| 22 |
public function register_widgets() { |
| 23 |
$widgets = apply_filters( 'cooked_widgets', [ |
| 24 |
'Cooked_Widget_Nutrition', |
| 25 |
'Cooked_Widget_Search', |
| 26 |
'Cooked_Widget_Recipe_List', |
| 27 |
'Cooked_Widget_Recipe_Categories', |
| 28 |
'Cooked_Widget_Recipe_Card', |
| 29 |
] ); |
| 30 |
if ( ! empty( $widgets ) ) : |
| 31 |
foreach ( $widgets as $widget ) : |
| 32 |
register_widget( $widget ); |
| 33 |
endforeach; |
| 34 |
endif; |
| 35 |
} |
| 36 |
|
| 37 |
public static function recipe_finder( $field_id = '', $field_name = '', $included = '' ) { |
| 38 |
$button_title = ( ! empty( $included ) ? __( 'Edit Recipe(s)...', 'cooked' ) : __( 'Choose recipe(s)...', 'cooked' ) ); |
| 39 |
echo '<div style="margin:-10px 0 0 0;"><a href="#" class="button cooked-recipe-finder-show" id="' . esc_attr( $field_id ) . '-SHOW">' . esc_html( $button_title ) . '</a></div>'; |
| 40 |
echo '<select multiple class="widefat cooked-recipe-finder" id="' . esc_attr( $field_id ) . '" name="' . esc_attr( $field_name ) . '" placeholder="' . __( 'Choose recipe(s)...', 'cooked' ) . '">'; |
| 41 |
if ( ! empty( $included ) ) : |
| 42 |
foreach ( $included as $recipe ) : |
| 43 |
$recipe_status = get_post_status( $recipe ); |
| 44 |
if ( $recipe_status === 'publish' ) : |
| 45 |
$_recipe = Cooked_Recipes::get( $recipe, true, false, false, true ); |
| 46 |
echo '<option selected="selected" value="' . esc_attr( $_recipe['id'] ) . '">' . esc_html( $_recipe['title'] ) . '</option>'; |
| 47 |
endif; |
| 48 |
endforeach; |
| 49 |
endif; |
| 50 |
echo '</select>'; |
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
|