Jump to content

How to define custom buttons in admin area?


Remitur

Recommended Posts

Inside a Registrar module, you have the AdminCustomButtonArray() function that allows to define custom buttons in admin area for custom domain functions... but what if I need to define a button of the very same kind, but outside of a registrar module?
(The issue is that the registrar module is encrypted, so I have no way to use AdminCustomButtonArray() function...)

 

Link to comment
Share on other sites

With a majority of the different module types in WHMCS (such as Provisioning or Registrar), every service, domain, etc. can only be tied to a single module. If that module is closed source / encrypted, an alternate solution is needed for adding custom content to the admin area. Addon modules can be used to change content on a variety of pages in both the admin area and client area. This includes pages with content normally handled by specific types of modules such as domains or services. By creating a custom addon module,  you can utilize hooks for modifying the admin area such as the following:

AdminAreaPage - Runs on every admin area page load.
AdminClientDomainsTabFields - Executes when a domain is being viewed in the Admin area.
AdminClientServicesTabFields - Executes when a service is being viewed in the Admin area.
AdminClientDomainsTabFieldsSave - Executes when the Domains tab in the Admin area is being saved.
AdminClientServicesTabFieldsSave - Executes when the Services tab in the Admin area is being saved. 

For example, the code below will add two custom buttons to each service. Some additional logic could be added to filter this to specific service types as well:

/modules/addons/new_custom_addon/hooks.php

<?php

// Add some custom buttons in the admin area for all services
add_hook('AdminClientServicesTabFields', 1, function($vars) {

	// Get current service ID from the vars passed to this function
	$serviceId = $vars['id'];

	// Build the HTML to be displayed on each service
	$customButtonHTML = '' .
		'<div id="customSectionId">' . "\n".
		'	<button type="button" class="btn btn-default" onclick="alert(\'Button 1 clicked on Service \' + ' . $serviceId . ')" id="customBtnId1">Button 1</button>' . "\n".
		'	<button type="button" class="btn btn-default" onclick="alert(\'Button 2 clicked on Service \' + ' . $serviceId . ')" id="customBtnId2">Button 2</button>' . "\n".
		'</div>' . "\n".
	'';

	// Display the result
	return array(
		'Custom Buttons' => $customButtonHTML
	);
});

 

Edited by SethMcCauley
Code formatting cleanup
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated