Skip to content

Commit

Permalink
Adjust Menus for Multisite (#27)
Browse files Browse the repository at this point in the history
* Changes to be committed:
	modified:   README.md
	modified:   classes/PluginInstall.class.php
	modified:   classes/ThemeInstall.class.php
	modified:   classicpress-directory-integration.php

Adjust Menus when Multisite (Offer in Network Admin)

* Update README.md

Account for menu item name change and remove changelog

---------

Co-authored-by: EliteStarServices <digtek@elite-star-services.com>
Co-authored-by: SIMONE FIORAVANTI <simospa@gieffeedizioni.it>
  • Loading branch information
3 people authored May 13, 2024
1 parent 421243a commit defd77d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#### Plugins from ClassicPress Directory now can be installed using the "Install CP Plugins" menu under "Plugins" menu.

#### Themes from ClassicPress Directory now can be installed using the "CP Themes" menu under "Appearance" menu.
#### Themes from ClassicPress Directory now can be installed using the "Install CP Themes" menu under "Appearance" menu.

## WP-CLI commands

Expand Down
9 changes: 7 additions & 2 deletions classes/PluginInstall.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ class PluginInstall
public function __construct()
{
// Add menu under plugins.
add_action('admin_menu', [$this, 'create_menu'], 100);
if (is_multisite()) {
add_action('network_admin_menu', [$this, 'create_menu'], 100);
add_action('network_admin_menu', [$this, 'rename_menu']);
} else {
add_action('admin_menu', [$this, 'create_menu'], 100);
add_action('admin_menu', [$this, 'rename_menu']);
}
add_action('admin_enqueue_scripts', [$this, 'styles']);
add_action('admin_enqueue_scripts', [$this, 'scripts']);
add_action('admin_menu', [$this, 'rename_menu']);
}

public function styles($hook)
Expand Down
21 changes: 18 additions & 3 deletions classes/ThemeInstall.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ class ThemeInstall

public function __construct()
{
// Add menu under Appearance.
add_action('admin_menu', [$this, 'create_menu'], 100);
// Add Menu Items.
if (is_multisite()) {
add_action('network_admin_menu', [$this, 'create_menu'], 100);
add_action('network_admin_menu', [$this, 'rename_menu']);
} else {
add_action('admin_menu', [$this, 'create_menu'], 100);
}
add_action('admin_enqueue_scripts', [$this, 'styles']);
add_action('admin_enqueue_scripts', [$this, 'scripts']);
}
Expand Down Expand Up @@ -47,7 +52,7 @@ public function create_menu()
$this->page = add_submenu_page(
'themes.php',
esc_html__('ClassicPress Themes', 'classicpress-directory-integration'),
esc_html__('CP Themes', 'classicpress-directory-integration'),
esc_html__('Install CP Themes', 'classicpress-directory-integration'),
'install_themes',
'classicpress-directory-integration-theme-install',
[$this, 'render_menu'],
Expand All @@ -58,6 +63,16 @@ public function create_menu()
add_action('load-' . $this->page, [$this, 'install_action']);
}

public function rename_menu() {
global $submenu;
foreach ( $submenu['themes.php'] as $key => $value ) {
if($value[2] !== 'theme-install.php') {
continue;
}
$submenu['themes.php'][$key][0] = esc_html__('Install WP Themes', 'classicpress-directory-integration'); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
}
}

// Get all installed ClassicPress Themes
// This function is different from the one in ThemeUpdate class
// and considers a theme from the dir not only if it has UpdateURI
Expand Down
2 changes: 1 addition & 1 deletion classicpress-directory-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* -----------------------------------------------------------------------------
* Plugin Name: ClassicPress Directory Integration
* Description: Install and update plugins from ClassicPress directory and keep ClassicPress themes updated.
* Version: 0.3.1
* Version: 0.3.2
* Author: ClassicPress Contributors
* Author URI: https://www.classicpress.net
* Plugin URI: https://www.classicpress.net
Expand Down

0 comments on commit defd77d

Please sign in to comment.