From 97c4594520f63e5341cc31a8e18f6cbe6efee6f9 Mon Sep 17 00:00:00 2001 From: Alana Martin Date: Fri, 21 Sep 2018 12:36:47 -0400 Subject: [PATCH 01/13] bypass empty BU Text widgets in class count via filter --- functions.php | 37 +++++++++++++++++++++++++++++++++++++ inc/extras.php | 16 ++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/functions.php b/functions.php index 74173f8f..8ca0df05 100755 --- a/functions.php +++ b/functions.php @@ -704,6 +704,43 @@ function r_enqueue_fancy_gallery() { wp_enqueue_style( 'lightgallery' ); } +/** + * Filter used to prevent incrementing CSS widget class count if a BU Text Widget is empty. + * + * @since 2.1.9 + * + * @param bool $is_widget_empty Defaults to false, assumes widget has content. + * @param array $params An array of Widget options info. + * + * @return bool $is_widget_empty The status of content for the widget. + */ +function r_is_bu_text_widget_empty( $is_widget_empty, $params ) { + $widget_name = $params[0]['widget_name']; + + if ( 'BU Text' === $widget_name ) { + $widget_instance = $params[1]['number']; + $meta_key = '_bu_text_widget_' . $widget_instance; + $widget_meta = get_post_meta( get_the_ID(), $meta_key, true ); + + if ( empty( $widget_meta['content'] ) ) { + $is_widget_empty = true; + } + } + return $is_widget_empty; +} + +/** + * Adds the empty widget check filter if the BU Text Widget plugin is active. + * + * @since 2.1.9 + */ +function r_bu_text_widget_loaded() { + if ( is_plugin_active( 'bu-text-widget/bu-text-widget.php' ) ) { + add_filter( 'responsive_is_widget_empty', 'r_is_bu_text_widget_empty', 10, 2 ); + } +} +add_action( 'after_setup_theme', 'r_bu_text_widget_loaded' ); + /** * Remove the news template when BU_News_Page_Template does not exist. * diff --git a/inc/extras.php b/inc/extras.php index a1616950..ebfbe415 100755 --- a/inc/extras.php +++ b/inc/extras.php @@ -166,6 +166,22 @@ function responsive_widget_counts( $params ) { return $params; } + /** + * Filters the $is_widget_empty variable. + * + * @since 2.1.9 + * + * @params bool $is_widget_empty The empty/full status of the widget content. + * + * @params array $params An array of widget options. + */ + $is_widget_empty = apply_filters( 'responsive_is_widget_empty', $is_widget_empty = false, $params ); + + // Don't increment static widget counter if widget is empty because it will not be displayed. + if ( $is_widget_empty ) { + return $params; + } + // Initialize or increment our static widget counter by one for this widget. if ( array_key_exists( $current_sidebar, $widget_counter ) ) { $widget_counter[ $current_sidebar ] ++; From 9abb02b7f55a2bf41fa07d128882069ee306ebe0 Mon Sep 17 00:00:00 2001 From: Alana Martin Date: Fri, 21 Sep 2018 15:12:38 -0400 Subject: [PATCH 02/13] add filter to check for empty BU links widget. --- functions.php | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index 8ca0df05..fba5c2fa 100755 --- a/functions.php +++ b/functions.php @@ -730,7 +730,7 @@ function r_is_bu_text_widget_empty( $is_widget_empty, $params ) { } /** - * Adds the empty widget check filter if the BU Text Widget plugin is active. + * Adds an empty widget check filter if the BU Text Widget plugin is active. * * @since 2.1.9 */ @@ -741,6 +741,43 @@ function r_bu_text_widget_loaded() { } add_action( 'after_setup_theme', 'r_bu_text_widget_loaded' ); +/** + * Filter used to prevent incrementing CSS widget class count if a BU Links Widget is empty. + * + * @since 2.1.9 + * + * @param bool $is_widget_empty Defaults to false, assumes widget has content. + * @param array $params An array of Widget options info. + * + * @return bool $is_widget_empty The status of content for the widget. + */ +function r_is_bu_links_widget_empty( $is_widget_empty, $params ) { + $widget_name = $params[0]['widget_name']; + + if ( 'BU Links' === $widget_name ) { + $widget_instance = $params[1]['number']; + $meta_key = '_bu_links_' . $widget_instance; + $widget_meta = get_post_meta( get_the_ID(), $meta_key, true ); + + if ( ! is_array( $widget_meta ) ) { + $is_widget_empty = true; + } + } + return $is_widget_empty; +} + +/** + * Adds an empty widget check filter if the BU Link plugin is active. + * + * @since 2.1.9 + */ +function r_bu_link_widget_loaded() { + if ( is_plugin_active( 'link-lists/link-lists.php' ) ) { + add_filter( 'responsive_is_widget_empty', 'r_is_bu_links_widget_empty', 10, 2 ); + } +} +add_action( 'after_setup_theme', 'r_bu_link_widget_loaded' ); + /** * Remove the news template when BU_News_Page_Template does not exist. * From 5e425e85e5b3c4531fc357eb27f7245aa15687d7 Mon Sep 17 00:00:00 2001 From: Alana Martin Date: Fri, 21 Sep 2018 16:09:41 -0400 Subject: [PATCH 03/13] update change log --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3d4c6d8..fd70dd0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +# unreleased +- Fixes #45 New filters added to correct widget count classes for each widget. +- Created new filter `responsive_is_widget_empty` to help check for empty widgets. +- Added `r_is_bu_text_widget_empty()` using is `responsive_is_widget_empty` to check for empty BU Text Widgets. +- Added `r_bu_text_widget_loaded()` to conditionally load `r_is_bu_text_widget_empty()` only if plugin is loaded. +- Added `r_is_bu_links_widget_empty()` using is `responsive_is_widget_empty` to check for empty BU Links Widgets. +- Added `r_bu_link_widget_loaded()` to conditionally load `r_is_bu_links_widget_empty()` only if plugin is loaded. + # 2.1.8 - Added new template tag, `responsive_the_title()`, intended to output the page title From a45570d10781b274d6c02fe464359ab68e65beb6 Mon Sep 17 00:00:00 2001 From: Alana Martin Date: Mon, 24 Sep 2018 15:05:59 -0400 Subject: [PATCH 04/13] include plugins directory for when not in admin area --- functions.php | 1 + 1 file changed, 1 insertion(+) diff --git a/functions.php b/functions.php index fba5c2fa..44cdc225 100755 --- a/functions.php +++ b/functions.php @@ -772,6 +772,7 @@ function r_is_bu_links_widget_empty( $is_widget_empty, $params ) { * @since 2.1.9 */ function r_bu_link_widget_loaded() { + require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if ( is_plugin_active( 'link-lists/link-lists.php' ) ) { add_filter( 'responsive_is_widget_empty', 'r_is_bu_links_widget_empty', 10, 2 ); } From f8c8f4cc056dc0b78a650c4ed76d7cc4c096da78 Mon Sep 17 00:00:00 2001 From: Alana Martin Date: Mon, 24 Sep 2018 15:22:15 -0400 Subject: [PATCH 05/13] add plugin paths to second filter change long formatting --- CHANGELOG.md | 14 +++++++++----- functions.php | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd70dd0c..cbff8f51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,15 @@ # unreleased - Fixes #45 New filters added to correct widget count classes for each widget. -- Created new filter `responsive_is_widget_empty` to help check for empty widgets. -- Added `r_is_bu_text_widget_empty()` using is `responsive_is_widget_empty` to check for empty BU Text Widgets. -- Added `r_bu_text_widget_loaded()` to conditionally load `r_is_bu_text_widget_empty()` only if plugin is loaded. -- Added `r_is_bu_links_widget_empty()` using is `responsive_is_widget_empty` to check for empty BU Links Widgets. -- Added `r_bu_link_widget_loaded()` to conditionally load `r_is_bu_links_widget_empty()` only if plugin is loaded. +- Created filter `responsive_is_widget_empty` to help check for empty widgets. +- Added `r_is_bu_text_widget_empty()` using is `responsive_is_widget_empty` + to check for empty BU Text Widgets. +- Added `r_bu_text_widget_loaded()` to conditionally load + `r_is_bu_text_widget_empty()` only if plugin is loaded. +- Added `r_is_bu_links_widget_empty()` using is `responsive_is_widget_empty` + to check for empty BU Links Widgets. +- Added `r_bu_link_widget_loaded()` to conditionally load + `r_is_bu_links_widget_empty()` only if plugin is loaded. # 2.1.8 diff --git a/functions.php b/functions.php index 44cdc225..042f3671 100755 --- a/functions.php +++ b/functions.php @@ -735,6 +735,7 @@ function r_is_bu_text_widget_empty( $is_widget_empty, $params ) { * @since 2.1.9 */ function r_bu_text_widget_loaded() { + require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if ( is_plugin_active( 'bu-text-widget/bu-text-widget.php' ) ) { add_filter( 'responsive_is_widget_empty', 'r_is_bu_text_widget_empty', 10, 2 ); } From 295ed4b77b91327e04816d2840af11560f8361b3 Mon Sep 17 00:00:00 2001 From: Alana Martin Date: Mon, 24 Sep 2018 15:28:17 -0400 Subject: [PATCH 06/13] fix trailing spaces --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbff8f51..a258700d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,13 +3,13 @@ # unreleased - Fixes #45 New filters added to correct widget count classes for each widget. - Created filter `responsive_is_widget_empty` to help check for empty widgets. -- Added `r_is_bu_text_widget_empty()` using is `responsive_is_widget_empty` +- Added `r_is_bu_text_widget_empty()` using is `responsive_is_widget_empty` to check for empty BU Text Widgets. -- Added `r_bu_text_widget_loaded()` to conditionally load +- Added `r_bu_text_widget_loaded()` to conditionally load `r_is_bu_text_widget_empty()` only if plugin is loaded. -- Added `r_is_bu_links_widget_empty()` using is `responsive_is_widget_empty` +- Added `r_is_bu_links_widget_empty()` using is `responsive_is_widget_empty` to check for empty BU Links Widgets. -- Added `r_bu_link_widget_loaded()` to conditionally load +- Added `r_bu_link_widget_loaded()` to conditionally load `r_is_bu_links_widget_empty()` only if plugin is loaded. # 2.1.8 From 400134be7f02a59624285f87cb64884c35e26016 Mon Sep 17 00:00:00 2001 From: Alana Martin Date: Mon, 24 Sep 2018 15:48:43 -0400 Subject: [PATCH 07/13] coding standards fixes --- CHANGELOG.md | 1 + functions.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a258700d..381a0827 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog # unreleased + - Fixes #45 New filters added to correct widget count classes for each widget. - Created filter `responsive_is_widget_empty` to help check for empty widgets. - Added `r_is_bu_text_widget_empty()` using is `responsive_is_widget_empty` diff --git a/functions.php b/functions.php index 042f3671..5c4af054 100755 --- a/functions.php +++ b/functions.php @@ -735,7 +735,7 @@ function r_is_bu_text_widget_empty( $is_widget_empty, $params ) { * @since 2.1.9 */ function r_bu_text_widget_loaded() { - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); + require_once ABSPATH . 'wp-admin/includes/plugin.php'; if ( is_plugin_active( 'bu-text-widget/bu-text-widget.php' ) ) { add_filter( 'responsive_is_widget_empty', 'r_is_bu_text_widget_empty', 10, 2 ); } @@ -773,7 +773,7 @@ function r_is_bu_links_widget_empty( $is_widget_empty, $params ) { * @since 2.1.9 */ function r_bu_link_widget_loaded() { - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); + require_once ABSPATH . 'wp-admin/includes/plugin.php'; if ( is_plugin_active( 'link-lists/link-lists.php' ) ) { add_filter( 'responsive_is_widget_empty', 'r_is_bu_links_widget_empty', 10, 2 ); } From 60cfaa6244cbd4f8a18dbd084b7e609202a75ed3 Mon Sep 17 00:00:00 2001 From: Alana Martin Date: Thu, 27 Sep 2018 14:36:19 -0400 Subject: [PATCH 08/13] update links widget empty check to include inheritance of widgets from parents. --- functions.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index 5c4af054..fe59d5bd 100755 --- a/functions.php +++ b/functions.php @@ -753,15 +753,32 @@ function r_bu_text_widget_loaded() { * @return bool $is_widget_empty The status of content for the widget. */ function r_is_bu_links_widget_empty( $is_widget_empty, $params ) { + $widget_name = $params[0]['widget_name']; if ( 'BU Links' === $widget_name ) { $widget_instance = $params[1]['number']; $meta_key = '_bu_links_' . $widget_instance; $widget_meta = get_post_meta( get_the_ID(), $meta_key, true ); + $ancestor_ids = get_post_ancestors( get_the_ID() ); if ( ! is_array( $widget_meta ) ) { - $is_widget_empty = true; + // The post has no parents so we can safely say the widget is empty. + if ( empty( $ancestor_ids ) ) { + $is_widget_empty = true; + } else { + $is_widget_empty = true; // Assume the widget is empty unless we prove otherwise. + foreach ( $ancestor_ids as $key => $ancestor_id ) { + // Check to see if widget exists on each parent and is set to show children. + $parent_widget_meta = get_post_meta( $ancestor_id, $meta_key, true ); + if ( is_array( $parent_widget_meta ) && array_key_exists( 'show', $parent_widget_meta ) ) { + if ( 'Yes' === $parent_widget_meta['show'] ) { + $is_widget_empty = false; + break; + } + } + } + } } } return $is_widget_empty; From b207f8f85ca3e51eb381acf6f5172f7e1c601708 Mon Sep 17 00:00:00 2001 From: Alana Martin Date: Thu, 27 Sep 2018 17:03:54 -0400 Subject: [PATCH 09/13] update text widget check for ancestors --- functions.php | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/functions.php b/functions.php index fe59d5bd..c0fa16b2 100755 --- a/functions.php +++ b/functions.php @@ -715,15 +715,34 @@ function r_enqueue_fancy_gallery() { * @return bool $is_widget_empty The status of content for the widget. */ function r_is_bu_text_widget_empty( $is_widget_empty, $params ) { - $widget_name = $params[0]['widget_name']; + $widget_name = $params[0]['widget_name']; + $ancestor_ids = get_post_ancestors( get_the_ID() ); if ( 'BU Text' === $widget_name ) { - $widget_instance = $params[1]['number']; - $meta_key = '_bu_text_widget_' . $widget_instance; - $widget_meta = get_post_meta( get_the_ID(), $meta_key, true ); + $widget_instance = $params[1]['number']; + $meta_key = '_bu_text_widget_' . $widget_instance; + $widget_meta = get_post_meta( get_the_ID(), $meta_key, true ); + $show_on_children = '_bu_text_widget_show_on_children_' . $widget_instance; if ( empty( $widget_meta['content'] ) ) { - $is_widget_empty = true; + $is_widget_empty = true; // Assume the widget is empty unless we prove otherwise. + + if ( ! empty( $ancestor_ids ) ) { + foreach ( $ancestor_ids as $key => $ancestor_id ) { + // Check to see if widget exists on ancestors and is set to show children. + $parent_widget_meta = get_post_meta( $ancestor_id, $meta_key, true ); + $parent_widget_show_on = get_post_meta( $ancestor_id, $show_on_children, true ); + if ( 'Yes' === $parent_widget_show_on ) { + if ( ! empty( $parent_widget_meta['content'] ) ) { + // This matches the way the plugin currently works. + // We only go to the 1st parent that says `Yes` show + // on children, regardless if content is available. + $is_widget_empty = false; + break; + } + } + } + } } } return $is_widget_empty; From 68a6e5d6d540631d7c108b588fae3e80e86281e3 Mon Sep 17 00:00:00 2001 From: Alana Martin Date: Fri, 28 Sep 2018 13:24:14 -0400 Subject: [PATCH 10/13] clarify comments, remove unused $key variable, --- functions.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/functions.php b/functions.php index c0fa16b2..ddaba5f2 100755 --- a/functions.php +++ b/functions.php @@ -719,24 +719,26 @@ function r_is_bu_text_widget_empty( $is_widget_empty, $params ) { $ancestor_ids = get_post_ancestors( get_the_ID() ); if ( 'BU Text' === $widget_name ) { - $widget_instance = $params[1]['number']; - $meta_key = '_bu_text_widget_' . $widget_instance; - $widget_meta = get_post_meta( get_the_ID(), $meta_key, true ); - $show_on_children = '_bu_text_widget_show_on_children_' . $widget_instance; + $widget_instance = $params[1]['number']; + $meta_key = '_bu_text_widget_' . $widget_instance; + $widget_meta = get_post_meta( get_the_ID(), $meta_key, true ); + $show_children_meta_key = '_bu_text_widget_show_on_children_' . $widget_instance; if ( empty( $widget_meta['content'] ) ) { - $is_widget_empty = true; // Assume the widget is empty unless we prove otherwise. + // The widget is empty. Assume we don't have ancestor widgets to + // show unless we prove otherwise. + $is_widget_empty = true; if ( ! empty( $ancestor_ids ) ) { - foreach ( $ancestor_ids as $key => $ancestor_id ) { + foreach ( $ancestor_ids as $ancestor_id ) { // Check to see if widget exists on ancestors and is set to show children. - $parent_widget_meta = get_post_meta( $ancestor_id, $meta_key, true ); - $parent_widget_show_on = get_post_meta( $ancestor_id, $show_on_children, true ); - if ( 'Yes' === $parent_widget_show_on ) { + $parent_widget_meta = get_post_meta( $ancestor_id, $meta_key, true ); + $show_on_children = get_post_meta( $ancestor_id, $show_children_meta_key, true ); + if ( 'Yes' === $show_on_children ) { if ( ! empty( $parent_widget_meta['content'] ) ) { // This matches the way the plugin currently works. // We only go to the 1st parent that says `Yes` show - // on children, regardless if content is available. + // on children, regardless if content is empty. $is_widget_empty = false; break; } @@ -772,7 +774,6 @@ function r_bu_text_widget_loaded() { * @return bool $is_widget_empty The status of content for the widget. */ function r_is_bu_links_widget_empty( $is_widget_empty, $params ) { - $widget_name = $params[0]['widget_name']; if ( 'BU Links' === $widget_name ) { @@ -782,12 +783,13 @@ function r_is_bu_links_widget_empty( $is_widget_empty, $params ) { $ancestor_ids = get_post_ancestors( get_the_ID() ); if ( ! is_array( $widget_meta ) ) { - // The post has no parents so we can safely say the widget is empty. if ( empty( $ancestor_ids ) ) { + // The post has no parents so we can safely say the widget is empty. $is_widget_empty = true; } else { - $is_widget_empty = true; // Assume the widget is empty unless we prove otherwise. - foreach ( $ancestor_ids as $key => $ancestor_id ) { + // Assume no parent widgets to display unless we prove otherwise. + $is_widget_empty = true; + foreach ( $ancestor_ids as $ancestor_id ) { // Check to see if widget exists on each parent and is set to show children. $parent_widget_meta = get_post_meta( $ancestor_id, $meta_key, true ); if ( is_array( $parent_widget_meta ) && array_key_exists( 'show', $parent_widget_meta ) ) { From c20989f7888ff11a2502a3b8e479deb4f9491c68 Mon Sep 17 00:00:00 2001 From: Alana Martin Date: Fri, 28 Sep 2018 14:53:43 -0400 Subject: [PATCH 11/13] fix for empty parent with display on children true --- functions.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index ddaba5f2..e93b449b 100755 --- a/functions.php +++ b/functions.php @@ -735,13 +735,19 @@ function r_is_bu_text_widget_empty( $is_widget_empty, $params ) { $parent_widget_meta = get_post_meta( $ancestor_id, $meta_key, true ); $show_on_children = get_post_meta( $ancestor_id, $show_children_meta_key, true ); if ( 'Yes' === $show_on_children ) { - if ( ! empty( $parent_widget_meta['content'] ) ) { + if ( empty( $parent_widget_meta['content'] ) ) { // This matches the way the plugin currently works. // We only go to the 1st parent that says `Yes` show // on children, regardless if content is empty. + // Here content is empty so we just break and + // keep the widget empty status as true. + break; + } else { + // This parent is set to show & has content. $is_widget_empty = false; break; } + } } } From 8b6b665ff3b84398853c92bdf47703ab327e0120 Mon Sep 17 00:00:00 2001 From: Alana Martin Date: Tue, 20 Nov 2018 15:10:25 -0500 Subject: [PATCH 12/13] refactor for BU Text Reprint widget --- functions.php | 67 +++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/functions.php b/functions.php index 878e90d1..e2ea864b 100755 --- a/functions.php +++ b/functions.php @@ -715,39 +715,48 @@ function r_enqueue_fancy_gallery() { * @return bool $is_widget_empty The status of content for the widget. */ function r_is_bu_text_widget_empty( $is_widget_empty, $params ) { - $widget_name = $params[0]['widget_name']; - $ancestor_ids = get_post_ancestors( get_the_ID() ); - if ( 'BU Text' === $widget_name ) { - $widget_instance = $params[1]['number']; - $meta_key = '_bu_text_widget_' . $widget_instance; - $widget_meta = get_post_meta( get_the_ID(), $meta_key, true ); - $show_children_meta_key = '_bu_text_widget_show_on_children_' . $widget_instance; + $widget_name = $params[0]['widget_name']; - if ( empty( $widget_meta['content'] ) ) { - // The widget is empty. Assume we don't have ancestor widgets to - // show unless we prove otherwise. - $is_widget_empty = true; + if ( 'BU Text Reprint' !== $widget_name && 'BU Text' !== $widget_name ) { + return $is_widget_empty; + } - if ( ! empty( $ancestor_ids ) ) { - foreach ( $ancestor_ids as $ancestor_id ) { - // Check to see if widget exists on ancestors and is set to show children. - $parent_widget_meta = get_post_meta( $ancestor_id, $meta_key, true ); - $show_on_children = get_post_meta( $ancestor_id, $show_children_meta_key, true ); - if ( 'Yes' === $show_on_children ) { - if ( empty( $parent_widget_meta['content'] ) ) { - // This matches the way the plugin currently works. - // We only go to the 1st parent that says `Yes` show - // on children, regardless if content is empty. - // Here content is empty so we just break and - // keep the widget empty status as true. - break; - } else { - // This parent is set to show & has content. - $is_widget_empty = false; - break; - } + if ( 'BU Text Reprint' === $widget_name ) { + $widget_instance = $params[1]['number']; + $reprint_option = get_option( 'widget_bu-text-reprint' ); + $widget_instance = $reprint_option[ $widget_instance ]['source_id']; + } else { + $widget_instance = $params[1]['number']; + } + $meta_key = '_bu_text_widget_' . $widget_instance; + $widget_meta = get_post_meta( get_the_ID(), $meta_key, true ); + $ancestor_ids = get_post_ancestors( get_the_ID() ); + $show_children_meta_key = '_bu_text_widget_show_on_children_' . $widget_instance; + + if ( empty( $widget_meta['content'] ) ) { + // The widget is empty. Assume we don't have ancestor widgets to + // show unless we prove otherwise. + $is_widget_empty = true; + + if ( ! empty( $ancestor_ids ) ) { + foreach ( $ancestor_ids as $ancestor_id ) { + // Check to see if widget exists on ancestors and is set to show children. + $parent_widget_meta = get_post_meta( $ancestor_id, $meta_key, true ); + $show_on_children = get_post_meta( $ancestor_id, $show_children_meta_key, true ); + if ( 'Yes' === $show_on_children ) { + if ( empty( $parent_widget_meta['content'] ) ) { + // This matches the way the plugin currently works. + // We only go to the 1st parent that says `Yes` show + // on children, regardless if content is empty. + // Here content is empty so we just break and + // keep the widget empty status as true. + break; + } else { + // This parent is set to show & has content. + $is_widget_empty = false; + break; } } } From eb1922ecc470853d2a5105329b85bcf5377b7625 Mon Sep 17 00:00:00 2001 From: Alana Martin Date: Tue, 20 Nov 2018 15:36:52 -0500 Subject: [PATCH 13/13] refactor to include checks for BU Links Reprint widget --- functions.php | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/functions.php b/functions.php index e2ea864b..7b7b1dc6 100755 --- a/functions.php +++ b/functions.php @@ -791,32 +791,42 @@ function r_bu_text_widget_loaded() { function r_is_bu_links_widget_empty( $is_widget_empty, $params ) { $widget_name = $params[0]['widget_name']; - if ( 'BU Links' === $widget_name ) { + if ( 'BU Links' !== $widget_name && 'BU Links Reprint' !== $widget_name ) { + return $is_widget_empty; + } + + if ( 'BU Links Reprint' === $widget_name ) { + $widget_instance = $params[1]['number']; + $reprint_option = get_option( 'widget_bu-links-reprint' ); + $widget_instance = $reprint_option[ $widget_instance ]['source_id']; + } else { $widget_instance = $params[1]['number']; - $meta_key = '_bu_links_' . $widget_instance; - $widget_meta = get_post_meta( get_the_ID(), $meta_key, true ); - $ancestor_ids = get_post_ancestors( get_the_ID() ); - - if ( ! is_array( $widget_meta ) ) { - if ( empty( $ancestor_ids ) ) { - // The post has no parents so we can safely say the widget is empty. - $is_widget_empty = true; - } else { - // Assume no parent widgets to display unless we prove otherwise. - $is_widget_empty = true; - foreach ( $ancestor_ids as $ancestor_id ) { - // Check to see if widget exists on each parent and is set to show children. - $parent_widget_meta = get_post_meta( $ancestor_id, $meta_key, true ); - if ( is_array( $parent_widget_meta ) && array_key_exists( 'show', $parent_widget_meta ) ) { - if ( 'Yes' === $parent_widget_meta['show'] ) { - $is_widget_empty = false; - break; - } + } + + $meta_key = '_bu_links_' . $widget_instance; + $widget_meta = get_post_meta( get_the_ID(), $meta_key, true ); + $ancestor_ids = get_post_ancestors( get_the_ID() ); + + if ( ! is_array( $widget_meta ) ) { + if ( empty( $ancestor_ids ) ) { + // The post has no parents so we can safely say the widget is empty. + $is_widget_empty = true; + } else { + // Assume no parent widgets to display unless we prove otherwise. + $is_widget_empty = true; + foreach ( $ancestor_ids as $ancestor_id ) { + // Check to see if widget exists on each parent and is set to show children. + $parent_widget_meta = get_post_meta( $ancestor_id, $meta_key, true ); + if ( is_array( $parent_widget_meta ) && array_key_exists( 'show', $parent_widget_meta ) ) { + if ( 'Yes' === $parent_widget_meta['show'] ) { + $is_widget_empty = false; + break; } } } } } + return $is_widget_empty; }