PluginProbe
Cooked – Recipe Management / 1.11.4
Cooked – Recipe Management v1.11.4
1.16.1 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 All 37 releases
cooked / includes / class.cooked-enqueues.php

class.cooked-enqueues.php in Cooked – Recipe Management 1.11.4, at includes/class.cooked-enqueues.php

114 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Enqueues
4 *
5 * @package Cooked
6 * @subpackage Enqueues
7 * @since 1.0.0
8 */
9
10 // Exit if accessed directly
11 if (!defined('ABSPATH')) exit;
12
13 /**
14 * Cooked_Post_Types Class
15 *
16 * This class handles the post type creation.
17 *
18 * @since 1.0.0
19 */
20 class Cooked_Enqueues {
21
22 function __construct() {
23 add_action('wp_enqueue_scripts', [&$this, 'enqueues'], 10, 1);
24 add_action('wp_enqueue_scripts', [&$this, 'css_colors'], 11);
25 add_action('wp_enqueue_scripts', [&$this, 'css_responsive'], 11);
26 add_action('wp_footer', [&$this, 'footer_enqueues']);
27 }
28
29 public function enqueues($hook) {
30 global $_cooked_settings;
31
32 $browse_page_id = !empty($_cooked_settings['browse_page']) ? $_cooked_settings['browse_page'] : false;
33 $browse_page = get_post($browse_page_id);
34 $browse_recipes_slug = !empty($browse_page) ? $browse_page->post_name : '';
35
36 $cooked_js_vars = [
37 'ajax_url' => admin_url('admin-ajax.php'),
38 'timer_sound' => apply_filters('cooked_timer_sound_mp3', COOKED_URL . 'assets/audio/ding.mp3'),
39 'permalink_structure' => get_option('permalink_structure'),
40 'site_url' => get_site_url(),
41 'browse_page' => $browse_page_id,
42 'front_page' => get_option( 'page_on_front' ),
43 'browse_recipes_slug' => $browse_recipes_slug,
44 'recipe_category_slug' => !isset($_cooked_settings['recipe_category_permalink']) ? 'recipe-category' : $_cooked_settings['recipe_category_permalink'],
45 'recipe_cooking_method_slug' => !isset($_cooked_settings['recipe_cooking_method_permalink']) ? 'cooking-method' : $_cooked_settings['recipe_cooking_method_permalink'],
46 'recipe_cuisine_slug' => !isset($_cooked_settings['recipe_cuisine_permalink']) ? 'cuisine' : $_cooked_settings['recipe_cuisine_permalink'],
47 'recipe_tags_slug' => !isset($_cooked_settings['recipe_tag_permalink']) ? 'recipe-tag' : $_cooked_settings['recipe_tag_permalink'],
48 'recipe_diet_slug' => !isset($_cooked_settings['recipe_diet_permalink']) ? 'diet' : $_cooked_settings['recipe_diet_permalink'],
49 ];
50
51 $cooked_i18n_js_vars = [
52 'i18n_timer' => __('Timer', 'cooked'),
53 ];
54
55 $min = COOKED_DEV ? '' : '.min';
56
57 wp_enqueue_style('cooked-essentials', COOKED_URL . 'assets/admin/css/essentials' . $min . '.css', [], COOKED_VERSION);
58 wp_enqueue_style('cooked-icons', COOKED_URL . 'assets/css/icons' . $min . '.css', [], COOKED_VERSION);
59 wp_enqueue_style('cooked-styling', COOKED_URL . 'assets/css/style' . $min . '.css', [], COOKED_VERSION );
60 wp_register_style('cooked-fotorama', COOKED_URL . 'assets/css/fotorama/fotorama.min.css', [], '4.6.4');
61 wp_register_script('cooked-fotorama', COOKED_URL . 'assets/js/fotorama/fotorama' . $min . '.js', ['jquery'], '4.6.4');
62 wp_register_script('cooked-timer', COOKED_URL . 'assets/js/timer/jquery.simple.timer' . $min . '.js', ['jquery'], '0.0.5');
63 wp_register_script('cooked-nosleep', COOKED_URL . 'assets/js/nosleep/NoSleep' . $min . '.js', [], '0.12.0');
64
65 // Compatibility with the Bridge Theme.
66 if (!defined('QODE_ROOT')) {
67 wp_register_script('cooked-appear', COOKED_URL . 'assets/js/appear/jquery.appear' . $min . '.js', ['jquery'], '0.3.6');
68 }
69
70 wp_enqueue_script('wp-sanitize');
71 wp_register_script('cooked-functions', COOKED_URL . 'assets/js/cooked-functions' . $min . '.js', ['jquery', 'wp-sanitize'], COOKED_VERSION);
72 wp_localize_script('cooked-functions', 'cooked_functions_i18n_js_vars', $cooked_i18n_js_vars);
73 wp_add_inline_script( 'cooked-functions', 'const cooked_functions_js_vars = ' . json_encode( $cooked_js_vars ) . ';', 'before' );
74 }
75
76 public function css_colors() {
77 if (!isset($_GET['print'])) {
78 $file = COOKED_DIR . 'assets/css/colors.php';
79 $css = self::get_dynamic_css($file);
80 wp_add_inline_style('cooked-styling', $css);
81 }
82 }
83
84 public function css_responsive() {
85 if (!isset($_GET['print'])) {
86 $file = COOKED_DIR . 'assets/css/responsive.php';
87 $css = self::get_dynamic_css($file);
88 wp_add_inline_style('cooked-styling', $css);
89 }
90 }
91
92 public static function get_dynamic_css($file = false) {
93 if (!$file || $file && !file_exists($file)) return;
94
95 ob_start();
96 include $file;
97 $css = ob_get_clean();
98 $compressed_css = self::compress_css($css);
99
100 return $compressed_css;
101 }
102
103 public static function compress_css($css) {
104 // Remove tabs, spaces, newlines, etc.
105 $css = str_replace(["\r\n", "\r", "\n", "\t", ' ', ' ', ' '], '', $css);
106 return $css;
107 }
108
109 public function footer_enqueues() {
110 wp_enqueue_script('cooked-functions');
111 }
112
113 }
114