Skip to content

Commit

Permalink
Add setting for menu location
Browse files Browse the repository at this point in the history
  • Loading branch information
bonny committed Jan 24, 2025
1 parent db205dc commit 1e920cf
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 13 deletions.
32 changes: 32 additions & 0 deletions inc/class-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,38 @@ public static function setting_show_as_menu_page() {
return (bool) $setting;
}

/**
* Returns the location of the main simple history menu page.
* Valid locations are:
* - 'top' = Below dashboard and Jetpack and similar top level menu items.
* - 'bottom' = Below settings and similar bottom level menu items.
*
* Defaults to 'top'.
*
* @return string Location of the main menu page.
*/
public static function setting_menu_page_location() {
$option_slug = 'simple_history_menu_page_location';
$setting = get_option( $option_slug );

// If it does not exist, then default so the option can auto-load.
if ( false === $setting ) {
$setting = 'top';
update_option( $option_slug, $setting, true );
}

/**
* Filter to control the placement of Simple History in the Admin Menu.
*
* @since 5.5.2
*
* @param string $setting Either 'top' for placement below dashboard or 'bottom' for placement below settings.
*/
$setting = apply_filters( 'simple_history/admin_menu_location', $setting );

return $setting;
}

/**
* Returns true if Simple History can be shown in the admin bar
*
Expand Down
14 changes: 13 additions & 1 deletion inc/services/class-admin-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ public function add_main_admin_pages() {
return;
}

$admin_page_location = Helpers::setting_menu_page_location();
$admin_page_position = '';
switch ( $admin_page_location ) {
case 'bottom':
$admin_page_position = 80;
break;
case 'top':
default:
$admin_page_position = 3.5;
break;
}

// Add History page as a main menu item, at the root.
// For example Jetpack adds itself at prio 3. We add it at prio 3.5 to be below Jetpack but above posts.
add_menu_page(
Expand All @@ -52,7 +64,7 @@ public function add_main_admin_pages() {
// Logo SVG image is same as in AdminBarQuickView.scss.
// Source is 'simple-history-wp-admin-bar-icon-20x20-no-clippath.svg'.
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHZpZXdCb3g9Ii0yIC0yIDI0ID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IvPgogICAgPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik05LjI5ODA4IDYuMTcwNzZDOS4yOTgwOCA1Ljc3MzA3IDkuNTk5NTkgNS40NTA2OCA5Ljk3MTUxIDUuNDUwNjhDMTAuMzQzNCA1LjQ1MDY4IDEwLjY0NDkgNS43NzMwNyAxMC42NDQ5IDYuMTcwNzZWMTAuNTIyOUwxMy42ODY3IDEyLjUwMzZDMTQuMDAzNyAxMi43MTAxIDE0LjEwMDggMTMuMTU0NCAxMy45MDIyIDEzLjQ4OTdDMTMuNzA4NCAxMy44MTY4IDEzLjMwNTMgMTMuOTE3NSAxMi45OTYxIDEzLjcxNjFMOS4yOTgwOCAxMS4zMDgxVjYuMTcwNzZaIiBmaWxsPSJibGFjayIvPgo8L3N2Zz4K',
'3.5'
$admin_page_position
// 3.5 = Below dashboard and jetpack
// 5 = Below posts.
// 60 = Appearance
Expand Down
38 changes: 26 additions & 12 deletions inc/services/class-setup-settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public function add_settings() {
)
);

// Setting for showing in admin bar.
register_setting(
$settings_general_option_group,
'simple_history_show_in_admin_bar',
Expand All @@ -158,6 +159,16 @@ public function add_settings() {
)
);

// Setting for menu page location.
register_setting(
$settings_general_option_group,
'simple_history_menu_page_location',
array(
'sanitize_callback' => 'sanitize_text_field',
)
);

// Output for where to show history, in dashboard, admin bar.
add_settings_field(
'simple_history_show_where',
Helpers::get_settings_field_title_output( __( 'Show history', 'simple-history' ), 'visibility' ),
Expand All @@ -173,7 +184,8 @@ public function add_settings() {
$settings_menu_slug,
$settings_section_general_id
);
// Number if items to show on the history page.

// Output for number if items to show on the history page.
add_settings_field(
'simple_history_number_of_items',
Helpers::get_settings_field_title_output( __( 'Items per page', 'simple-history' ), 'filter_list' ),
Expand Down Expand Up @@ -215,34 +227,36 @@ public function settings_section_output() {
* Settings field output for menu page location
*/
public function settings_field_menu_page_location() {
$show_as_menu_page = Helpers::setting_show_as_menu_page();
$location = Helpers::setting_menu_page_location();
$option_slug = 'simple_history_menu_page_location';
?>

<fieldset>
<label>
<input
type="radio"
name="menu_location"
value="Top of menu"
<?php // checked( $days_to_keep_log_type === 'keep_forever' ); ?>
type="radio"
name="<?php echo esc_attr( $option_slug ); ?>"
value="top"
<?php checked( $location === 'top' ); ?>
/>
At top (below Dashboard)
<?php esc_html_e( 'Top of menu', 'simple-history' ); ?>
</label>

<br />

<label>
<input
type="radio"
name="menu_location"
value="Bottom of menu"
<?php // checked( $days_to_keep_log_type === 'keep_forever' ); ?>
type="radio"
name="<?php echo esc_attr( $option_slug ); ?>"
value="bottom"
<?php checked( $location === 'bottom' ); ?>
/>
At bottom (below Settings)
<?php esc_html_e( 'Bottom of menu', 'simple-history' ); ?>
</label>
</fieldset>
<?php
}

/**
* Settings field for where to show the log, page or dashboard
*/
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ Read more at the [FAQ on the plugin website](https://simple-history.com/docs/faq

- Add filter `simple_history/show_admin_menu_page`.
- Add filter `simple_history/show_in_admin_bar`.
- Add filter `simple_history/admin_menu_location`.
- Decrease the icon size in the admin bar and main menu, to match the size of other icons. Props @hjalle.
- Add helper function `setting_show_as_menu_page()`.

Expand Down

0 comments on commit 1e920cf

Please sign in to comment.