Skip to content

Instantly share code, notes, and snippets.

View stuart-sequeira's full-sized avatar

Stuart Sequeira stuart-sequeira

View GitHub Profile
@stuart-sequeira
stuart-sequeira / metabox-entity-constructor.php
Last active October 21, 2021 18:29
Metabox Output Handler Class
<?php
/**
* Your class to construct the metabox output
*
* Class must have a public function `handle` that can receive the $extraValue
* and a NF submission.
*
* Output of handle method is a \NinjaForms\Includes\Entities\MetaboxOutputEntity with two properties:
*
@stuart-sequeira
stuart-sequeira / main-plugin-file.php
Last active October 21, 2021 18:26
Adding a Handler to the Extra Value Keys for Output of a Metabox
<?php
add_filter('nf_react_table_extra_value_keys', 'nfAddMetabox');
/**
* Add a metabox constructor to the react.js submissions page
*
* @param array $metaboxHandlers
* @return array
*/
function nfAddMetabox(array $metaboxHandlers): array
@stuart-sequeira
stuart-sequeira / extractingResponse
Created July 3, 2020 17:33
From the raw response, check for exception and extract useful information such that response is always known entity
<?php
$rawResponse = wp_remote_request($this->url, $this->httpArgs);
if (is_wp_error($rawResponse)) {
$this->responseData->setType('error');
$this->responseData->setMessage($rawResponse->get_error_message());
} else {
$this->responseData->setResponse(json_encode($rawResponse));
}
@stuart-sequeira
stuart-sequeira / SampleRemoteRequest
Created July 3, 2020 17:12
Abstracting wp_remote_request, a contract can be built off this to use any other HTTP client
<?php
namespace NFAmoCrm\EmailCRM\AmoCrm\Handlers;
use NFMailchimp\EmailCRM\Shared\Entities\ResponseData;
/**
* Make an HTTP request
*
*/