PluginProbe
Cooked – Recipe Management / trunk
Cooked – Recipe Management vtrunk
1.16.0 1.15.0 trunk 1.10.0 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.12.0 1.13.0 1.14.0 1.7.10 1.7.11 1.7.12 1.7.13 1.7.15.1 1.7.15.3 1.7.15.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 All 36 releases
cooked / includes / class.cooked-widgets.php

class.cooked-widgets.php in Cooked – Recipe Management trunk, at includes/class.cooked-widgets.php

54 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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