Plugin Directory

Changeset 3370335


Ignore:
Timestamp:
09/30/2025 10:45:03 AM (5 months ago)
Author:
aihimel
Message:

v1.0.2

Location:
easy-menu-manager
Files:
34 added
1 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • easy-menu-manager/trunk/composer.json

    r3091276 r3370335  
    1515        }
    1616    ],
    17     "minimum-stability": "stable"
     17    "require-dev": {
     18        "squizlabs/php_codesniffer": "^3.9",
     19        "wp-coding-standards/wpcs": "^3.1"
     20    },
     21    "minimum-stability": "stable",
     22    "config": {
     23        "allow-plugins": {
     24            "dealerdirect/phpcodesniffer-composer-installer": true
     25        }
     26    }
    1827}
  • easy-menu-manager/trunk/easy-menu-manager.php

    r3091276 r3370335  
    22/**
    33 * Plugin Name: Easy Menu Manager
    4  * Version: 1.0.1
     4 * Version: 1.0.2
    55 * Author: Aftabul Islam
    66 * Author URI: https://profiles.wordpress.org/aihimel/
     
    88 * Requires at least: 5.8
    99 * Requires PHP: 7.2
    10  *
    1110 * Text Domain: easy-menu-manager
    1211 * Domain Path: /languages/
    13  *
    1412 * Description: A menu manager plugin for WordPress
    15  *
    1613 * License: GPLv3
    1714 */
     
    1916defined( 'ABSPATH' ) || exit;
    2017
    21 require_once( 'vendor/autoload.php' );
     18require_once 'vendor/autoload.php';
    2219
    23 WCPress\EasyMenuManager\EasyMenuManager::init();
     20use WCPress\EasyMenuManager\EasyMenuManager;
     21
     22EasyMenuManager::init();
  • easy-menu-manager/trunk/includes/Assets.php

    r3091276 r3370335  
    2424    public function __construct() {
    2525        // Registering assets
    26         add_action( 'admin_enqueue_scripts', [ $this, 'registerStyle'] );
    27         add_action( 'admin_enqueue_scripts', [ $this, 'registerScript'] );
     26        add_action( 'admin_enqueue_scripts', [ $this, 'register_style' ] );
     27        add_action( 'admin_enqueue_scripts', [ $this, 'register_script' ] );
    2828
    2929        // Loading assets
    30         add_action( 'admin_enqueue_scripts', [ $this, 'loadSelectizeOnNavMenuPage' ] );
     30        add_action( 'admin_enqueue_scripts', [ $this, 'load_selectize' ] );
    3131    }
    3232
     
    3838     * @return void
    3939     */
    40     public function registerStyle() {
     40    public function register_style() {
    4141        wp_register_style(
    42             Assets::SELECTIZE_STYLE,
     42            self::SELECTIZE_STYLE,
    4343            EASY_MENU_MANAGER_ROOT_URL . 'assets/lib/selectize/0.15.2/selectize.default.min.css',
    4444            [],
     
    5454     * @return void
    5555     */
    56     public function registerScript() {
     56    public function register_script() {
    5757        wp_register_script(
    58             Assets::SELECTIZE_SCRIPT,
     58            self::SELECTIZE_SCRIPT,
    5959            EASY_MENU_MANAGER_ROOT_URL . 'assets/lib/selectize/0.15.2/selectize.min.js',
    6060            [ 'jquery' ],
     
    6363        );
    6464        wp_register_script(
    65             Assets::NAVIGATION_SCRIPT,
     65            self::NAVIGATION_SCRIPT,
    6666            EASY_MENU_MANAGER_ROOT_URL . 'assets/js/navigation.js',
    67             [ Assets::SELECTIZE_SCRIPT ],
    68             ( EasyMenuManager::init() )->getVersionString(),
     67            [ self::SELECTIZE_SCRIPT ],
     68            ( EasyMenuManager::init() )->get_version_string(),
    6969            true
    7070        );
     
    7878     * @return void
    7979     */
    80     public function loadSelectizeOnNavMenuPage() {
     80    public function load_selectize() {
    8181        global $pagenow;
    82         if ( is_admin() && $pagenow === 'nav-menus.php' ) {
    83             wp_enqueue_style( Assets::SELECTIZE_STYLE );
    84             wp_enqueue_script( Assets::SELECTIZE_SCRIPT );
    85             wp_enqueue_script( Assets::NAVIGATION_SCRIPT );
     82        if ( is_admin() && 'nav-menus.php' === $pagenow ) {
     83            wp_enqueue_style( self::SELECTIZE_STYLE );
     84            wp_enqueue_script( self::SELECTIZE_SCRIPT );
     85            wp_enqueue_script( self::NAVIGATION_SCRIPT );
    8686        }
    8787    }
  • easy-menu-manager/trunk/includes/Constants.php

    r3091276 r3370335  
    2525     * @return void
    2626     */
    27     public static function declareDynamicConstants() {
     27    public static function declare_dynamic_constants() {
    2828        defined( 'EASY_MENU_MANAGER_ROOT_PATH' )
    2929            || define(
    3030                'EASY_MENU_MANAGER_ROOT_PATH',
    31                 dirname( __FILE__ ) . '/../'
     31                __DIR__ . '/../'
    3232        );
    3333        defined( 'EASY_MENU_MANAGER_ROOT_URL' )
  • easy-menu-manager/trunk/includes/EasyMenuManager.php

    r3091276 r3370335  
    4343     */
    4444    private function __construct() {
    45         Constants::declareDynamicConstants();
     45        Constants::declare_dynamic_constants();
    4646        $this->container['assets'] = new Assets();
    4747        $this->container['menu_fields'] = new MenuFields();
     
    5757     */
    5858    public static function init(): EasyMenuManager {
    59         if ( empty( EasyMenuManager::$self ) ) {
    60             EasyMenuManager::$self = new EasyMenuManager();
     59        if ( empty( self::$self ) ) {
     60            self::$self = new EasyMenuManager();
    6161        }
    62         return EasyMenuManager::$self;
     62        return self::$self;
    6363    }
    6464
     
    7070     * @return array
    7171     */
    72     public function getContainer(): array {
     72    public function get_container(): array {
    7373        return $this->container;
    7474    }
     
    8181     * @return string
    8282     */
    83     public function getVersionString(): string {
     83    public function get_version_string(): string {
    8484        return $this->version_string;
    8585    }
     
    9292     * @return int
    9393     */
    94     public function getVersionInt(): int {
     94    public function get_version_int(): int {
    9595        return $this->version_number;
    9696    }
    97 
    9897}
  • easy-menu-manager/trunk/includes/FilterMenuFields.php

    r3091276 r3370335  
    1919     */
    2020    public function __construct() {
    21         add_filter( 'wp_nav_menu_objects', [ $this, 'filterMenuByRoles' ] );
     21        add_filter( 'wp_nav_menu_objects', [ $this, 'filter_menu_by_roles' ] );
    2222    }
    2323
     
    3131     * @return array
    3232     */
    33     public function filterMenuByRoles( $items ): array {
     33    public function filter_menu_by_roles( array $items ): array {
    3434        foreach ( $items as $key => $item ) {
    3535            // Get selected roles for the current menu item
    3636            $selected_roles = get_post_meta( $item->ID, MenuFields::ALLOWED_ROLES_META_KEY, true );
    3737            // If roles are selected and user doesn't have any of those roles, remove the menu item
    38             if ( ! empty( $selected_roles ) && ! $this->currentUserCanAny( $selected_roles ) ) {
     38            if ( ! empty( $selected_roles ) && ! $this->current_user_can_any( $selected_roles ) ) {
    3939                unset( $items[ $key ] );
    4040            }
     
    5353     * @return bool
    5454     */
    55     protected function currentUserCanAny( $roles ): bool {
     55    protected function current_user_can_any( array $roles ): bool {
    5656        $user = wp_get_current_user();
    5757        foreach ($roles as $role) {
    58             if (in_array($role, $user->roles)) {
     58            if ( in_array( $role, $user->roles, true ) ) {
    5959                return true;
    6060            }
     
    6262        return false;
    6363    }
    64 
    6564}
  • easy-menu-manager/trunk/includes/MenuFields.php

    r3091276 r3370335  
    2525    const NONCE_KEY = Constants::PREFIX . 'menu_nonce_key';
    2626
    27 //  const ROLE_KEY
    28 
    2927    /**
    3028     * Initializing the hooks
     
    3533     */
    3634    public function __construct() {
    37         add_action( 'wp_nav_menu_item_custom_fields', [ $this, 'addFields' ] );
    38         add_action( 'wp_update_nav_menu_item', [ $this, 'saveFields' ], 10, 2 );
     35        add_action( 'wp_nav_menu_item_custom_fields', [ $this, 'add_fields' ] );
     36        add_action( 'wp_update_nav_menu_item', [ $this, 'save_fields' ], 10, 2 );
    3937    }
    4038
     
    4846     * @return void
    4947     */
    50     public function addFields( $item_id ) {
     48    public function add_fields( $item_id ) {
    5149        $user_roles = get_editable_roles();
    52         $selected_roles = get_post_meta( $item_id, MenuFields::ALLOWED_ROLES_META_KEY, true );
     50        $selected_roles = get_post_meta( $item_id, self::ALLOWED_ROLES_META_KEY, true );
    5351        $selected_roles = is_array( $selected_roles ) ? $selected_roles : array();
    5452        $template_loader = TemplateLoader::init();
    55         $template_loader->loadTemplate( 'nav-menu-fieldset.php', 'nav-menu-fieldset', [
     53        $template_loader->load_template( 'nav-menu-fieldset.php', 'nav-menu-fieldset', [
    5654            'item_id' => $item_id,
    5755            'user_roles' => $user_roles,
     
    7068     * @return void
    7169     */
    72     public function saveFields( $menu_id, $menu_item_db_id ) {
     70    public function save_fields( $menu_id, $menu_item_db_id ) {
    7371        $nonce_key = self::NONCE_KEY . '_' . $menu_item_db_id;
    7472        // Nonce check
    75         if(
     73        if (
    7674            ! isset( $_POST[ $nonce_key ] )
    7775            || ! wp_verify_nonce(
     
    8684            update_post_meta(
    8785                $menu_item_db_id,
    88                 MenuFields::ALLOWED_ROLES_META_KEY,
     86                self::ALLOWED_ROLES_META_KEY,
    8987                array_map(
    9088                    'sanitize_text_field',
     
    9391            );
    9492        } else {
    95             update_post_meta( $menu_item_db_id, MenuFields::ALLOWED_ROLES_META_KEY, [] );
     93            update_post_meta( $menu_item_db_id, self::ALLOWED_ROLES_META_KEY, [] );
    9694        }
    9795    }
  • easy-menu-manager/trunk/includes/TemplateLoader.php

    r3091276 r3370335  
    1717    protected function __construct() {}
    1818
    19     public static function init() {
    20         if ( empty( TemplateLoader::$self ) ) {
    21             TemplateLoader::$self = new TemplateLoader();
     19    public static function init(): TemplateLoader {
     20        if ( empty( self::$self ) ) {
     21            self::$self = new self();
    2222        }
    23         return TemplateLoader::$self;
     23        return self::$self;
    2424    }
    2525
     
    3535     * @return void
    3636     */
    37     public function loadTemplate( string $file, string $name = '', array $args = [] ) {
    38         $template_root_path = apply_filters( 'easy_menu_manager_template_root_path', TemplateLoader::TEMPLATE_FOLDER_PATH, $file, $name, $args );
     37    public function load_template( string $file, string $name = '', array $args = [] ) {
     38        $template_root_path = apply_filters( 'easy_menu_manager_template_root_path', self::TEMPLATE_FOLDER_PATH, $file, $name, $args );
    3939        $file = apply_filters( 'easy_menu_manager_template_file', $file, $name, $args );
    4040        $args = apply_filters( 'easy_menu_manager_template_args', $args, $file, $name );
    41         $file_path = TemplateLoader::TEMPLATE_FOLDER_PATH . $file;
     41        $file_path = self::TEMPLATE_FOLDER_PATH . $file;
    4242        if ( file_exists( $file_path ) ) {
    4343            extract( $args );
     
    4545        }
    4646    }
    47 
    4847}
  • easy-menu-manager/trunk/readme.txt

    r3093004 r3370335  
    11=== Easy Menu Manager ===
    22Contributors: aihimel
    3 Tags: easy menu manager, menu manager
    4 Requires at least: 5.2
    5 Tested up to: 6.4
     3Tags: menu, menu manager, user roles, restrict menu, menu visibility, role based menu
     4Requires at least: 5.8
     5Tested up to: 6.8
    66Requires PHP: 7.2
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88License: GPL-3.0-or-later
    9 License URI: http://www.gnu.org/licenses/gpl-3.0.html
     9License URI: https://www.gnu.org/licenses/gpl-3.0.html
    1010
    11 Managing menu for different user roles. Only the selected role(s) will see the menu in action.
     11A simple yet powerful plugin to control menu item visibility based on user roles.
    1212
    13 == Used 3rd Party Resources ==
    14 + [Slelectize2](https://github.com/selectize/selectize.js/)
     13== Description ==
     14
     15Easy Menu Manager provides a seamless way to manage your WordPress navigation menus by restricting menu items to specific user roles. With this plugin, you can easily control which menu items are visible to different users, such as logged-in users, logged-out users, or specific roles like 'Administrator', 'Editor', or 'Subscriber'.
     16
     17This is particularly useful for membership sites, e-commerce stores, or any WordPress site that has different user roles with different levels of access to content.
     18
     19The plugin integrates a user-friendly multi-select dropdown into the WordPress menu editor, allowing you to select one or more user roles for each menu item. If no roles are selected, the menu item will be visible to all users.
     20
     21== Features ==
     22
     23*   **Restrict Menu Item by User Role:** Easily show or hide menu items based on user roles.
     24*   **Multiple Role Support:** Assign multiple user roles to a single menu item.
     25*   **Simple User Interface:** A simple multi-select dropdown is added to each menu item in the menu editor.
     26*   **Lightweight and Efficient:** The plugin is lightweight and does not affect your site's performance.
     27*   **Seamless Integration:** Integrates seamlessly with the WordPress menu management system.
     28*   **Developer Friendly:** The plugin is built with developers in mind, with proper hooks and filters.
     29
     30== Installation ==
     31
     321.  Upload the `easy-menu-manager` folder to the `/wp-content/plugins/` directory.
     332.  Activate the plugin through the 'Plugins' menu in WordPress.
     343.  Go to Appearance > Menus.
     354.  Click on any menu item to expand its options.
     365.  You will see a new field called "Only Visible to Roles".
     376.  Select the user roles that should be able to see the menu item.
     387.  Save the menu.
     39
     40== Frequently Asked Questions ==
     41
     42= What happens if I don't select any role for a menu item? =
     43
     44If you don't select any role for a menu item, it will be visible to all users, both logged-in and logged-out.
     45
     46= Can I select multiple roles for a single menu item? =
     47
     48Yes, you can select multiple roles. The menu item will be visible to users who have any of the selected roles.
     49
     50= Does this plugin work with custom user roles? =
     51
     52Yes, it works with any custom user roles created by other plugins or by your theme.
     53
     54== Screenshots ==
     55
     561.  The "Only Visible to Roles" field in the menu item settings.
    1557
    1658== Changelog ==
    1759
    18 = 1.0.0 (23 May, 2024) =
    19 * ✅ **Feature:** Initial release
     60= 1.0.1 ( 30 September, 2025 ) =
     61* Fix: fatal error on some installations issue fixed
     62
     63= 1.0.0 =
     64* Feature: Initial release
     65
     66== Used 3rd Party Resources ==
     67* [Selectize.js](https://github.com/selectize/selectize.js/)
  • easy-menu-manager/trunk/templates/nav-menu-fieldset.php

    r3091276 r3370335  
    88 */
    99
     10use WCPress\EasyMenuManager\MenuFields;
     11
    1012defined( 'ABSPATH' ) || exit;
    1113
     
    1618        <?php esc_html_e('Only Visible to Roles:', 'easy-menu-manager' ); ?><br/>
    1719        <select
    18       id="edit-menu-item-custom-<?php echo esc_attr( $item_id ); ?>"
    19       class="widefat code edit-menu-item-custom"
    20       name="menu-item-custom[<?php echo esc_attr( $item_id ); ?>][]"
    21       multiple="multiple"
     20        id="edit-menu-item-custom-<?php echo esc_attr( $item_id ); ?>"
     21        class="widefat code edit-menu-item-custom"
     22        name="menu-item-custom[<?php echo esc_attr( $item_id ); ?>][]"
     23        multiple="multiple"
    2224    >
    23             <?php foreach ( $user_roles as $role_key => $role ) : ?>
    24                 <option value="<?php echo esc_attr( $role_key ); ?>" <?php selected( in_array( $role_key, $selected_roles ) ); ?>>
    25                     <?php echo esc_html( $role['name'] ); ?>
     25            <?php foreach ( $user_roles as $role_key => $user_role ) : ?>
     26                <option value="<?php echo esc_attr( $role_key ); ?>" <?php selected( in_array( $role_key, $selected_roles, true ) ); ?>>
     27                    <?php echo esc_html( $user_role['name'] ); ?>
    2628                </option>
    2729            <?php endforeach; ?>
    28       <?php wp_nonce_field( $nonce_id, $nonce_id ); ?>
     30        <?php wp_nonce_field( $nonce_id, $nonce_id ); ?>
    2931        </select>
    3032    </label>
  • easy-menu-manager/trunk/vendor/autoload.php

    r3091276 r3370335  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderInit8090253aa1337032da9d0bf1809a0bf0::getLoader();
     25return ComposerAutoloaderInitb1121f9484383058140b52f2b3d382e4::getLoader();
  • easy-menu-manager/trunk/vendor/composer/InstalledVersions.php

    r3091276 r3370335  
    3232     */
    3333    private static $installed;
     34
     35    /**
     36     * @var bool
     37     */
     38    private static $installedIsLocalDir;
    3439
    3540    /**
     
    310315        self::$installed = $data;
    311316        self::$installedByVendor = array();
     317
     318        // when using reload, we disable the duplicate protection to ensure that self::$installed data is
     319        // always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
     320        // so we have to assume it does not, and that may result in duplicate data being returned when listing
     321        // all installed packages for example
     322        self::$installedIsLocalDir = false;
    312323    }
    313324
     
    323334
    324335        $installed = array();
     336        $copiedLocalDir = false;
    325337
    326338        if (self::$canGetVendors) {
     339            $selfDir = strtr(__DIR__, '\\', '/');
    327340            foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
     341                $vendorDir = strtr($vendorDir, '\\', '/');
    328342                if (isset(self::$installedByVendor[$vendorDir])) {
    329343                    $installed[] = self::$installedByVendor[$vendorDir];
     
    331345                    /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
    332346                    $required = require $vendorDir.'/composer/installed.php';
    333                     $installed[] = self::$installedByVendor[$vendorDir] = $required;
    334                     if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
    335                         self::$installed = $installed[count($installed) - 1];
     347                    self::$installedByVendor[$vendorDir] = $required;
     348                    $installed[] = $required;
     349                    if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
     350                        self::$installed = $required;
     351                        self::$installedIsLocalDir = true;
    336352                    }
     353                }
     354                if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
     355                    $copiedLocalDir = true;
    337356                }
    338357            }
     
    351370        }
    352371
    353         if (self::$installed !== array()) {
     372        if (self::$installed !== array() && !$copiedLocalDir) {
    354373            $installed[] = self::$installed;
    355374        }
  • easy-menu-manager/trunk/vendor/composer/autoload_real.php

    r3091276 r3370335  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit8090253aa1337032da9d0bf1809a0bf0
     5class ComposerAutoloaderInitb1121f9484383058140b52f2b3d382e4
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInit8090253aa1337032da9d0bf1809a0bf0', 'loadClassLoader'), true, true);
     25        spl_autoload_register(array('ComposerAutoloaderInitb1121f9484383058140b52f2b3d382e4', 'loadClassLoader'), true, true);
    2626        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    27         spl_autoload_unregister(array('ComposerAutoloaderInit8090253aa1337032da9d0bf1809a0bf0', 'loadClassLoader'));
     27        spl_autoload_unregister(array('ComposerAutoloaderInitb1121f9484383058140b52f2b3d382e4', 'loadClassLoader'));
    2828
    2929        require __DIR__ . '/autoload_static.php';
    30         call_user_func(\Composer\Autoload\ComposerStaticInit8090253aa1337032da9d0bf1809a0bf0::getInitializer($loader));
     30        call_user_func(\Composer\Autoload\ComposerStaticInitb1121f9484383058140b52f2b3d382e4::getInitializer($loader));
    3131
    3232        $loader->register(true);
  • easy-menu-manager/trunk/vendor/composer/autoload_static.php

    r3091276 r3370335  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit8090253aa1337032da9d0bf1809a0bf0
     7class ComposerStaticInitb1121f9484383058140b52f2b3d382e4
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    2828    {
    2929        return \Closure::bind(function () use ($loader) {
    30             $loader->prefixLengthsPsr4 = ComposerStaticInit8090253aa1337032da9d0bf1809a0bf0::$prefixLengthsPsr4;
    31             $loader->prefixDirsPsr4 = ComposerStaticInit8090253aa1337032da9d0bf1809a0bf0::$prefixDirsPsr4;
    32             $loader->classMap = ComposerStaticInit8090253aa1337032da9d0bf1809a0bf0::$classMap;
     30            $loader->prefixLengthsPsr4 = ComposerStaticInitb1121f9484383058140b52f2b3d382e4::$prefixLengthsPsr4;
     31            $loader->prefixDirsPsr4 = ComposerStaticInitb1121f9484383058140b52f2b3d382e4::$prefixDirsPsr4;
     32            $loader->classMap = ComposerStaticInitb1121f9484383058140b52f2b3d382e4::$classMap;
    3333
    3434        }, null, ClassLoader::class);
  • easy-menu-manager/trunk/vendor/composer/installed.json

    r3091276 r3370335  
    11{
    22    "packages": [],
    3     "dev": true,
     3    "dev": false,
    44    "dev-package-names": []
    55}
  • easy-menu-manager/trunk/vendor/composer/installed.php

    r3091276 r3370335  
    22    'root' => array(
    33        'name' => 'wcpress/easy-menu-manager',
    4         'pretty_version' => 'dev-develop',
    5         'version' => 'dev-develop',
    6         'reference' => '8678c9d126869811b9e428c6d03544f7fef382cd',
     4        'pretty_version' => '1.0.0+no-version-set',
     5        'version' => '1.0.0.0',
     6        'reference' => null,
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
    99        'aliases' => array(),
    10         'dev' => true,
     10        'dev' => false,
    1111    ),
    1212    'versions' => array(
    1313        'wcpress/easy-menu-manager' => array(
    14             'pretty_version' => 'dev-develop',
    15             'version' => 'dev-develop',
    16             'reference' => '8678c9d126869811b9e428c6d03544f7fef382cd',
     14            'pretty_version' => '1.0.0+no-version-set',
     15            'version' => '1.0.0.0',
     16            'reference' => null,
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.