Пример #1
0
 /**
  * Add filter to 'the_title' hook
  *
  * We need to filter the menu item title but **not** regular post titles.
  * Thus, we're adding the filter when `wp_nav_menu()` is called.
  *
  * @since 0.1.0
  * @link  http://codex.wordpress.org/Plugin_API/Action_Reference/wp_nav_menu_args Filter: wp_nav_menu_args/999/2
  * @param array $args Not used
  *
  * @return array
  */
 public function _add_menu_item_title_filter($args)
 {
     $menu_id = Menu_Icons::get_nav_menu_id($args);
     if (false !== $menu_id) {
         $this->menu_settings = Menu_Icons_Settings::get_menu_settings($menu_id);
         add_filter('the_title', array($this, '_filter_menu_item_title'), 999, 2);
     }
     return $args;
 }
Пример #2
0
    /**
     * Print fields
     *
     * @since   0.1.0
     * @access  protected
     * @uses    add_action() Calls 'menu_icons_before_fields' hook
     * @uses    add_action() Calls 'menu_icons_after_fields' hook
     * @wp_hook action       menu_item_custom_fields/10/3
     *
     * @param object $item  Menu item data object.
     * @param int    $depth Nav menu depth.
     * @param array  $args  Menu item args.
     * @param int    $id    Nav menu ID.
     *
     * @return string Form fields
     */
    public static function _fields($id, $item, $depth, $args)
    {
        if (!class_exists('Kucrut_Form_Field')) {
            require_once Menu_Icons::get('dir') . 'includes/library/form-fields.php';
        }
        $type_ids = array_values(array_filter(array_keys(self::_get_types())));
        $input_id = sprintf('menu-icons-%d', $item->ID);
        $input_name = sprintf('menu-icons[%d]', $item->ID);
        $current = wp_parse_args(Menu_Icons::get_meta($item->ID), Menu_Icons_Settings::get_menu_settings(Menu_Icons_Settings::get_current_menu_id()));
        ?>
			<div class="field-icon description-wide menu-icons-wrap">
				<?php 
        /**
         * Allow plugins/themes to inject HTML before menu icons' fields
         *
         * @param object $item  Menu item data object.
         * @param int    $depth Nav menu depth.
         * @param array  $args  Menu item args.
         * @param int    $id    Nav menu ID.
         *
         */
        do_action('menu_icons_before_fields', $item, $depth, $args, $id);
        ?>
				<div class="easy">
					<p class="description submitbox">
						<label><?php 
        esc_html_e('Icon:', 'menu-icons');
        ?>
</label>
						<?php 
        printf('<a id="menu-icons-%1$d-select" class="_select" title="%2$s" data-id="%1$d" data-text="%2$s">%3$s</a>', esc_attr__($item->ID), esc_attr__('Select', 'menu-icons'), self::_get_preview($item->ID, $current));
        ?>
						<?php 
        printf('<a id="menu-icons-%1$s-remove" class="_remove hidden submitdelete" data-id="%1$s">%2$s</a>', esc_attr($item->ID), esc_html__('Remove', 'menu-icons'));
        ?>
					</p>
				</div>
				<div class="original hidden">
					<p class="description">
						<label for="<?php 
        echo esc_attr($input_id);
        ?>
-type"><?php 
        esc_html_e('Icon type', 'menu-icons');
        ?>
</label>
						<?php 
        printf('<select id="%s-type" name="%s[type]" class="_type hasdep" data-dep-scope="div.menu-icons-wrap" data-dep-children=".field-icon-child" data-key="type">', esc_attr($input_id), esc_attr($input_name));
        ?>
							<?php 
        foreach (self::_get_types() as $id => $props) {
            ?>
								<?php 
            printf('<option value="%s"%s>%s</option>', esc_attr($id), selected(isset($current['type']) && $id === $current['type'], true, false), esc_html($props['label']));
            ?>
							<?php 
        }
        ?>
						</select>
					</p>

					<?php 
        foreach (self::_get_types() as $props) {
            ?>
						<?php 
            if (!empty($props['field_cb']) && is_callable($props['field_cb'])) {
                ?>
							<?php 
                call_user_func_array($props['field_cb'], array($item->ID, $current));
                ?>
						<?php 
            }
            ?>
					<?php 
        }
        ?>

					<?php 
        foreach (self::_get_fields($current) as $field) {
            $field = Kucrut_Form_Field::create($field, array('keys' => array('menu-icons', $item->ID), 'inline_description' => true));
            ?>
						<p class="description field-icon-child" data-dep-on='<?php 
            echo wp_json_encode($type_ids);
            ?>
'>
							<?php 
            printf('<label for="%s">%s</label>', esc_attr($field->id), esc_html($field->label));
            ?>
							<?php 
            $field->render();
            ?>
						</p>
					<?php 
        }
        ?>
				</div>
				<?php 
        /**
         * Allow plugins/themes to inject HTML after menu icons' fields
         *
         * @param object $item  Menu item data object.
         * @param int    $depth Nav menu depth.
         * @param array  $args  Menu item args.
         * @param int    $id    Nav menu ID.
         *
         */
        do_action('menu_icons_after_fields', $item, $depth, $args, $id);
        ?>
			</div>
		<?php 
    }
Пример #3
0
    /**
     * Print fields
     *
     * @since   0.1.0
     * @access  protected
     * @uses    add_action() Calls 'menu_icons_before_fields' hook
     * @uses    add_action() Calls 'menu_icons_after_fields' hook
     * @wp_hook action       menu_item_custom_fields
     *
     * @param object $item  Menu item data object.
     * @param int    $depth Nav menu depth.
     * @param array  $args  Menu item args.
     * @param int    $id    Nav menu ID.
     *
     * @return string Form fields
     */
    public static function _fields($id, $item, $depth, $args)
    {
        $input_id = sprintf('menu-icons-%d', $item->ID);
        $input_name = sprintf('menu-icons[%d]', $item->ID);
        $menu_settings = Menu_Icons_Settings::get_menu_settings(Menu_Icons_Settings::get_current_menu_id());
        $meta = Menu_Icons_Meta::get($item->ID, $menu_settings);
        $fields = self::_get_menu_item_fields($meta);
        ?>
			<div class="field-icon description-wide menu-icons-wrap" data-id="<?php 
        echo json_encode($item->ID);
        ?>
">
				<?php 
        /**
         * Allow plugins/themes to inject HTML before menu icons' fields
         *
         * @param object $item  Menu item data object.
         * @param int    $depth Nav menu depth.
         * @param array  $args  Menu item args.
         * @param int    $id    Nav menu ID.
         *
         */
        do_action('menu_icons_before_fields', $item, $depth, $args, $id);
        ?>
				<p class="description submitbox">
					<label><?php 
        esc_html_e('Icon:', 'menu-icons');
        ?>
</label>
					<?php 
        printf('<a class="_select">%s</a>', esc_html__('Select', 'menu-icons'));
        ?>
					<?php 
        printf('<a class="_remove submitdelete hidden">%s</a>', esc_html__('Remove', 'menu-icons'));
        ?>
				</p>
				<div class="_settings hidden">
					<?php 
        foreach ($fields as $field) {
            printf('<label>%1$s: <input type="text" name="%2$s" class="_mi-%3$s" value="%4$s" /></label><br />', esc_html($field['label']), esc_attr("{$input_name}[{$field['id']}]"), esc_attr($field['id']), esc_attr($field['value']));
        }
        // The fields below will not be saved. They're only used for the preview.
        printf('<input type="hidden" class="_mi-url" value="%s" />', esc_attr($meta['url']));
        ?>
				</div>
				<?php 
        /**
         * Allow plugins/themes to inject HTML after menu icons' fields
         *
         * @param object $item  Menu item data object.
         * @param int    $depth Nav menu depth.
         * @param array  $args  Menu item args.
         * @param int    $id    Nav menu ID.
         *
         */
        do_action('menu_icons_after_fields', $item, $depth, $args, $id);
        ?>
			</div>
		<?php 
    }