| @@ -75,46 +75,50 @@ | ||
| 75 | 75 | */ |
| 76 | 76 | public function remove( $tag, $function_to_remove, $priority = 10 ) { |
| 77 | 77 | global $wp_filter; |
| 78 | 78 | |
| 79 | - if ( is_array( $function_to_remove ) ) { | |
| 80 | - if ( empty( $wp_filter[ $tag ] ) ) { | |
| 81 | - return; | |
| 82 | - } | |
| 79 | + try { | |
| 80 | + if ( is_array( $function_to_remove ) ) { | |
| 81 | + if ( empty( $wp_filter[ $tag ] ) ) { | |
| 82 | + return; | |
| 83 | + } | |
| 83 | 84 | |
| 84 | - $callbacks = $wp_filter[ $tag ]->callbacks; | |
| 85 | - if ( ! $callbacks ) { | |
| 86 | - return; | |
| 87 | - } | |
| 88 | - | |
| 89 | - $priorities = array_keys( $callbacks ); | |
| 90 | - | |
| 91 | - foreach ( $priorities as $priority1 ) { | |
| 92 | - | |
| 93 | - if ( $priority !== '*' && $priority !== $priority1 ) { | |
| 94 | - continue; | |
| 85 | + $callbacks = $wp_filter[ $tag ]->callbacks; | |
| 86 | + if ( ! $callbacks ) { | |
| 87 | + return; | |
| 95 | 88 | } |
| 96 | 89 | |
| 97 | - if ( empty( $callbacks[ $priority1 ] ) ) { | |
| 98 | - continue; | |
| 99 | - } | |
| 90 | + $priorities = array_keys( $callbacks ); | |
| 100 | 91 | |
| 101 | - foreach ( $callbacks[ $priority1 ] as $callback ) { | |
| 92 | + foreach ( $priorities as $priority1 ) { | |
| 102 | 93 | |
| 103 | - if ( ! $callback['function'][0] instanceof LP_Template_Callback ) { | |
| 94 | + if ( $priority !== '*' && $priority !== $priority1 ) { | |
| 104 | 95 | continue; |
| 105 | 96 | } |
| 106 | 97 | |
| 107 | - if ( $callback['function'][0]->get_args() !== $function_to_remove[1] ) { | |
| 98 | + if ( empty( $callbacks[ $priority1 ] ) ) { | |
| 108 | 99 | continue; |
| 109 | 100 | } |
| 110 | 101 | |
| 111 | - remove_action( $tag, $callback['function'], $priority1 ); | |
| 102 | + foreach ( $callbacks[ $priority1 ] as $callback ) { | |
| 103 | + | |
| 104 | + if ( ! $callback['function'][0] instanceof LP_Template_Callback ) { | |
| 105 | + continue; | |
| 106 | + } | |
| 107 | + | |
| 108 | + if ( $callback['function'][0]->get_args() !== $function_to_remove[1] ) { | |
| 109 | + continue; | |
| 110 | + } | |
| 111 | + | |
| 112 | + remove_action( $tag, $callback['function'], $priority1 ); | |
| 113 | + } | |
| 112 | 114 | } |
| 115 | + | |
| 116 | + return; | |
| 117 | + | |
| 113 | 118 | } |
| 119 | + } catch ( Throwable $e ) { | |
| 114 | 120 | |
| 115 | - return; | |
| 116 | - | |
| 117 | 121 | } |
| 118 | 122 | |
| 119 | 123 | /** |
| 120 | 124 | * $function_to_remove === '*' will remove all functions hooked into a hook |
| @@ -166,45 +170,47 @@ | ||
| 166 | 170 | if ( empty( $wp_filter[ $tag ] ) ) { |
| 167 | 171 | return; |
| 168 | 172 | } |
| 169 | 173 | |
| 170 | - $callbacks = $wp_filter[ $tag ]->callbacks; | |
| 174 | + try { | |
| 175 | + $callbacks = $wp_filter[ $tag ]->callbacks; | |
| 171 | 176 | |
| 172 | - if ( ! $callbacks ) { | |
| 173 | - return; | |
| 174 | - } | |
| 175 | - | |
| 176 | - $priorities = array_keys( $callbacks ); | |
| 177 | - | |
| 178 | - foreach ( $priorities as $priority1 ) { | |
| 179 | - | |
| 180 | - if ( $priority !== '*' && $priority !== $priority1 ) { | |
| 181 | - continue; | |
| 177 | + if ( ! $callbacks ) { | |
| 178 | + return; | |
| 182 | 179 | } |
| 183 | 180 | |
| 184 | - if ( empty( $callbacks[ $priority1 ] ) ) { | |
| 185 | - continue; | |
| 186 | - } | |
| 181 | + $priorities = array_keys( $callbacks ); | |
| 187 | 182 | |
| 188 | - foreach ( $callbacks[ $priority1 ] as $callback ) { | |
| 183 | + foreach ( $priorities as $priority1 ) { | |
| 189 | 184 | |
| 190 | - if ( ! $callback['function'][0] instanceof LP_Template_Callback ) { | |
| 185 | + if ( $priority !== '*' && $priority !== $priority1 ) { | |
| 191 | 186 | continue; |
| 192 | 187 | } |
| 193 | 188 | |
| 194 | - if ( $callback['function'][1] !== 'callback' ) { | |
| 189 | + if ( empty( $callbacks[ $priority1 ] ) ) { | |
| 195 | 190 | continue; |
| 196 | 191 | } |
| 197 | 192 | |
| 198 | - if ( $callback['function'][0]->get_template() !== $function ) { | |
| 199 | - continue; | |
| 193 | + foreach ( $callbacks[ $priority1 ] as $callback ) { | |
| 194 | + | |
| 195 | + if ( ! $callback['function'][0] instanceof LP_Template_Callback ) { | |
| 196 | + continue; | |
| 197 | + } | |
| 198 | + | |
| 199 | + if ( $callback['function'][1] !== 'callback' ) { | |
| 200 | + continue; | |
| 201 | + } | |
| 202 | + | |
| 203 | + if ( $callback['function'][0]->get_template() !== $function ) { | |
| 204 | + continue; | |
| 205 | + } | |
| 206 | + | |
| 207 | + remove_action( $tag, $callback['function'], $priority1 ); | |
| 200 | 208 | } |
| 201 | - | |
| 202 | - remove_action( $tag, $callback['function'], $priority1 ); | |
| 203 | 209 | } |
| 210 | + } catch ( Throwable $e ) { | |
| 211 | + error_log( __METHOD__ . ': ' . $e->getMessage() ); | |
| 204 | 212 | } |
| 205 | - | |
| 206 | - return; | |
| 207 | 213 | } |
| 208 | 214 | |
| 209 | 215 | /** |
| 210 | 216 | * @return LP_Template |