Skip to content

Instantly share code, notes, and snippets.

@macbookandrew
Last active November 25, 2018 01:05
Show Gist options
  • Save macbookandrew/d40a416c65c615e0e15e1b6fd0645a67 to your computer and use it in GitHub Desktop.
Save macbookandrew/d40a416c65c615e0e15e1b6fd0645a67 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Menu Image + DevDMBootstrap3 Fix
* Plugin URI: https://gist.github.com/macbookandrew/d40a416c65c615e0e15e1b6fd0645a67
* Description: Fixes Menu Image PLugin used with DevDMBootstrap3 themes
* Author: Andrew Minion/Pressed Solutions
* Author URI: https://pressedsolutions.com/
* Requires WP: 4.4.0
* Requires PHP: 7.0
* Version: 1.0.0
*
* @package Menu_Image_Fix
*/
add_action(
'after_setup_theme', function () {
if ( class_exists( 'Menu_Image_Plugin' ) && class_exists( 'wp_bootstrap_navwalker' ) ) {
/**
* Fix Menu Image when used with DevDMBootstrap3.
*
* @package Menu_Image_Fix
*/
class Menu_Image_Plugin_DevDmBootstrap extends Menu_Image_Plugin {
/**
* Kick things off.
*/
public function __construct() {
add_filter( 'walker_nav_menu_start_el', array( $this, 'fix_bootstrap_menu' ), 10, 4 );
}
/**
* Fix for wp_bootstrap_navwalker.
*
* The `wp_bootstrap_navwalker` class doesn’t apply the `nav_menu_item_title` filter.
*
* @param string $item_output The menu item’s starting HTML output.
* @param WP_Post $item Menu item data object.
* @param int $depth Depth of menu item; useful for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*
* @return string The menu item’s starting HTML.
*/
public function fix_bootstrap_menu( string $item_output, WP_Post $item, int $depth, stdClass $args ) {
$title_with_image = $this->menu_image_nav_menu_item_title_filter( $item->title, $item, $depth, $args );
return str_replace( '>' . $item->title . '<', '>' . $title_with_image . '<', $item_output );
}
}
new Menu_Image_Plugin_DevDmBootstrap();
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment