$id are applied to it. * @param mixed $var Additional variables passed to the functions hooked to $id. * * @return mixed The filtered value after all hooked functions are applied to it. */ function beans_apply_filters( $id, $value ) { $args = func_get_args(); // Return simple filter if no sub-hook is set. if ( !preg_match_all( '#\[(.*?)\]#', $args[0], $matches ) ) return call_user_func_array( 'apply_filters', $args ); $prefix = current( explode( '[', $args[0] ) ); $variable_prefix = $prefix; $suffix = preg_replace( '/^.*\]\s*/', '', $args[0] ); // Base filter. $args[0] = $prefix . $suffix; $value = call_user_func_array( 'apply_filters', $args ); foreach ( $matches[0] as $i => $subhook ) { $variable_prefix = $variable_prefix . $subhook; $levels = array( $prefix . $subhook . $suffix ); // Cascade sub-hooks. if ( $i > 0 ) { $levels[] = str_replace( $subhook, '', $id ); $levels[] = $variable_prefix . $suffix; } // Apply sub-hooks. foreach ( $levels as $level ) { $args[0] = $level; $args[1] = $value; $value = call_user_func_array( 'apply_filters', $args ); // Apply filter whithout square brackets for backwards compatibility. $args[0] = preg_replace( '#(\[|\])#', '', $args[0] ); $args[1] = $value; $value = call_user_func_array( 'apply_filters', $args ); } } return $value; } /** * Check if any filter has been registered for a hook. * * This function is similar to {@link http://codex.wordpress.org/Function_Reference/has_filters has_filters()} * with the exception of checking sub-hooks if it is told to do so. * * @since 1.0.0 * * @param string $id The filter ID. * @param callback|bool $callback Optional. The callback to check for. Default false. * * @return bool|int If $callback is omitted, returns boolean for whether the hook has * anything registered. When checking a specific function, the priority of that * hook is returned, or false if the function is not attached. When using the * $callback argument, this function may return a non-boolean value * that evaluates to false (e.g. 0), so use the === operator for testing the * return value. */ function beans_has_filters( $id, $callback = false ) { // Check simple filter if no subhook is set. if ( !preg_match_all( '#\[(.*?)\]#', $id, $matches ) ) return has_filter( $id, $callback ); $prefix = current( explode( '[', $id ) ); $variable_prefix = $prefix; $suffix = preg_replace( '/^.*\]\s*/', '', $id ); // Check base filter. if ( has_filter( $prefix . $suffix, $callback ) ) return true; foreach ( $matches[0] as $i => $subhook ) { $variable_prefix = $variable_prefix . $subhook; $levels = array( $prefix . $subhook . $suffix ); // Cascade sub-hooks. if ( $i > 0 ) { $levels[] = str_replace( $subhook, '', $id ); $levels[] = $variable_prefix . $suffix; } // Apply sub-hooks. foreach ( $levels as $level ) { if ( has_filter( $level, $callback ) ) return true; // Check filter whithout square brackets for backwards compatibility. if ( has_filter( preg_replace( '#(\[|\])#', '', $level ), $callback ) ) return true; } } return false; } /** * Add anonymous callback using a class since php 5.2 is still supported. * * @ignore */ function _beans_add_anonymous_filter( $id, $callback, $priority = 10, $args = 1 ) { require_once( BEANS_API_COMPONENTS_PATH . 'filters/class.php' ); new _Beans_Anonymous_Filters( $id, $callback, $priority, $args ); }