tag(); } wp_localize_script( 'tve-notifications-main', 'tve_notification', [ 'elements' => $elements, ] ); } /** * Include the notification controls component */ public static function tcb_output_components() { $path = TVE_TCB_ROOT_PATH . 'inc/views/notifications/components/'; $files = array_diff( scandir( $path ), [ '.', '..' ] ); foreach ( $files as $file ) { include $path . $file; } } /** * Enqueue scripts in the editor */ public static function editor_enqueue() { if ( Main::is_edit_screen() ) { tve_dash_enqueue_script( 'tve-notifications-editor', tve_editor_js( '/notifications-editor.min.js' ), [ 'jquery' ] ); } } /** * Insert the notification in every page */ public static function insert_notification_element() { if ( ! ( Main::is_preview_screen() || Main::is_edit_screen() ) ) { echo Main::get_notification_content( true, '', false, false ); } } /** * Update notification template with the selected one */ public static function update_template() { $id = filter_input( INPUT_POST, 'post_id', FILTER_SANITIZE_NUMBER_INT ); /* Un-set the previously set template */ $posts = get_posts( [ 'post_type' => Post_Type::NAME, 'fields' => 'ids', ] ); if ( ! empty( $posts ) ) { foreach ( $posts as $key => $postId ) { update_post_meta( $postId, 'default', 0 ); } } /* Set the selected template as default */ update_post_meta( $id, 'default', 1 ); } /** * Only load global variables in the Global Elements tab inside the Dashboard */ public static function add_global_variables() { if ( tve_get_current_screen_key() === 'admin_page_tcb_admin_dashboard' ) { tve_load_global_variables(); } } /* ###################################### FILTERS ###################################### */ /** * Add Notifications elements to the editor * * @param array $instances * * @return array */ public static function tcb_element_instances( $instances ) { if ( Main::is_edit_screen() || wp_doing_ajax() ) { $instances = array_merge( $instances, Main::$elements ); } return $instances; } /** * Remove cloud templates icon from the right sidebar * * @param bool $has_templates * * @return false */ public static function has_templates( $has_templates ) { if ( Post_Type::is_notification() ) { $has_templates = false; } return $has_templates; } /** * Add notification dependency * * @param $dependencies * * @return mixed */ public static function tve_main_js_dependencies( $dependencies ) { if ( Main::is_edit_screen() ) { $dependencies[] = 'tve-notifications-main'; } return $dependencies; } }