HEX
Server: Apache
System: Linux efa57bbe-abb1-400d-2985-3b056fbc2701.secureserver.net 6.1.147-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 24 12:33:32 EDT 2025 x86_64
User: root (0)
PHP: 8.0.30.4
Disabled: NONE
Upload Files
File: /var/www/wp-content/mu-plugins/vendor/godaddy/mwc-core/src/API/Controllers/AccountController.php
<?php

namespace GoDaddy\WordPress\MWC\Core\API\Controllers;

use Exception;
use GoDaddy\WordPress\MWC\Common\API\Controllers\AbstractController;
use GoDaddy\WordPress\MWC\Common\Components\Contracts\ComponentContract;
use GoDaddy\WordPress\MWC\Common\Configuration\Configuration;
use GoDaddy\WordPress\MWC\Common\Platforms\Contracts\PlatformRepositoryContract;
use GoDaddy\WordPress\MWC\Common\Platforms\PlatformRepositoryFactory;
use WP_Error;
use WP_REST_Response;

/**
 * AccountController controller class.
 */
class AccountController extends AbstractController implements ComponentContract
{
    /**
     * AccountController constructor.
     */
    public function __construct()
    {
        $this->route = 'account';
    }

    /**
     * Initializes the controller.
     *
     * @return void
     */
    public function load() : void
    {
        $this->registerRoutes();
    }

    /**
     * Registers the API routes for the endpoints provided by the controller.
     */
    public function registerRoutes() : void
    {
        register_rest_route(
            $this->namespace, "/{$this->route}", [
                [
                    'methods'             => 'GET', // \WP_REST_Server::READABLE,
                    'callback'            => [$this, 'getItem'],
                    'permission_callback' => [$this, 'getItemsPermissionsCheck'],
                ],
                'schema' => [$this, 'getItemSchema'],
            ]
        );
    }

    /**
     * Gets the account information.
     *
     * @internal
     *
     * @return WP_REST_Response|WP_Error
     * @throws Exception
     */
    public function getItem()
    {
        $platformRepository = PlatformRepositoryFactory::getNewInstance()->getPlatformRepository();

        $hostingPlanName = $this->getHostingPlanName($platformRepository);

        return rest_ensure_response([
            'account' => [
                'privateLabelId'       => (int) $platformRepository->getResellerId() ?: null,
                'isVersioningManual'   => (bool) Configuration::get('features.extensions.versionSelect'),
                'isOnResellerAccount'  => $platformRepository->isReseller(),
                'managedWordPressPlan' => $hostingPlanName,
                'plan'                 => $hostingPlanName,
                'platform'             => $platformRepository->getPlatformName(),
                'customerId'           => $platformRepository->getGoDaddyCustomerId(),
                'federationPartnerId'  => $platformRepository->getGoDaddyCustomer()->getFederationPartnerId(),
            ],
        ]);
    }

    /**
     * Gets the name of the hosting plan.
     *
     * The frontend expects to receive `null` when the hosting plan name is unknown.
     *
     * @param PlatformRepositoryContract $platformRepository
     * @return string|null
     */
    protected function getHostingPlanName(PlatformRepositoryContract $platformRepository) : ?string
    {
        return $platformRepository->getPlan()->getName() ?: null;
    }

    /**
     * Gets the schema for REST items provided by the controller.
     *
     * @return array<string, mixed>
     */
    public function getItemSchema() : array
    {
        return [
            '$schema'    => 'http://json-schema.org/draft-04/schema#',
            'title'      => 'account',
            'type'       => 'object',
            'properties' => [
                'privateLabelId' => [
                    'description' => __('The reseller private label ID (1 means GoDaddy, so not a reseller).', 'mwc-core'),
                    'type'        => 'int',
                    'context'     => ['view', 'edit'],
                    'readonly'    => true,
                ],
                'isVersioningManual' => [
                    'description' => __('Whether the account can manually switch between extension versions.', 'mwc-core'),
                    'type'        => 'bool',
                    'context'     => ['view', 'edit'],
                    'readonly'    => true,
                ],
                'isOnResellerAccount' => [
                    'description' => __('Whether or not the site is sold by a reseller.', 'mwc-core'),
                    'type'        => 'bool',
                    'context'     => ['view', 'edit'],
                    'readonly'    => true,
                ],
                'plan' => [
                    'description' => __('The product plan the given account or site has purchased', 'mwc-core'),
                    'type'        => 'string',
                    'context'     => ['view'],
                    'readonly'    => true,
                ],
                'platform' => [
                    'description' => __('The hosting platform the given account or site is running on', 'mwc-core'),
                    'type'        => 'string',
                    'context'     => ['view'],
                    'readonly'    => true,
                ],
                'customerId' => [
                    'description' => __('The ID of the customer', 'mwc-core'),
                    'type'        => 'string',
                    'context'     => ['view'],
                    'readonly'    => true,
                ],
                'federationPartnerId' => [
                    'description' => __('The ID of the Federation Partner', 'mwc-core'),
                    'type'        => 'string',
                    'context'     => ['view'],
                    'readonly'    => true,
                ],
            ],
        ];
    }
}