first commit
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import Deactivation from './classes/Deactivation';
|
||||
|
||||
class Core {
|
||||
|
||||
constructor() {
|
||||
new Deactivation();
|
||||
}
|
||||
}
|
||||
|
||||
new Core();
|
||||
@@ -0,0 +1,84 @@
|
||||
export default class Deactivation {
|
||||
|
||||
constructor() {
|
||||
if ( ! this.set_vars() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.set_events();
|
||||
}
|
||||
|
||||
set_vars() {
|
||||
this.button_open = document.querySelector( '[data-slug="{__PLUGIN_SLUG__}"] a[href*="action=deactivate"]' );
|
||||
this.modal_wrapper = document.querySelector( '[data-wpdesk-deactivation-modal="{__PLUGIN_SLUG__}"]' );
|
||||
if ( ! this.button_open || ! this.modal_wrapper ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.button_close = this.modal_wrapper.querySelector( '[data-wpdesk-deactivation-modal-button-close]' );
|
||||
this.button_submit = this.modal_wrapper.querySelector( '[data-wpdesk-deactivation-modal-button-submit]' );
|
||||
this.button_skip = this.modal_wrapper.querySelector( '[data-wpdesk-deactivation-modal-button-skip]' );
|
||||
this.form_wrapper = this.modal_wrapper.querySelector( '[data-wpdesk-deactivation-modal-form]' );
|
||||
|
||||
this.events = {
|
||||
open_modal: this.open_modal.bind( this ),
|
||||
};
|
||||
this.settings = {
|
||||
delay_click_deactivate: 10,
|
||||
};
|
||||
this.status = {
|
||||
is_sent: false,
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
set_events() {
|
||||
this.button_open.addEventListener( 'click', this.events.open_modal );
|
||||
|
||||
this.modal_wrapper.addEventListener( 'click', this.close_modal.bind( this, false ) );
|
||||
this.button_close.addEventListener( 'click', this.close_modal.bind( this, false ) );
|
||||
this.button_skip.addEventListener( 'click', this.close_modal.bind( this, true ) );
|
||||
this.form_wrapper.addEventListener( 'click', ( e ) => { e.stopPropagation(); } );
|
||||
|
||||
this.form_wrapper.addEventListener( 'submit', this.init_form_submission.bind( this ) );
|
||||
}
|
||||
|
||||
open_modal( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
this.button_open.removeEventListener( 'click', this.events.open_modal );
|
||||
this.modal_wrapper.removeAttribute( 'hidden' );
|
||||
}
|
||||
|
||||
close_modal( is_deactivation, e = null ) {
|
||||
e && e.preventDefault();
|
||||
const { delay_click_deactivate } = this.settings;
|
||||
|
||||
this.modal_wrapper.setAttribute( 'hidden', 'hidden' );
|
||||
if ( is_deactivation ) {
|
||||
setTimeout( () => { this.button_open.click(); }, delay_click_deactivate );
|
||||
}
|
||||
}
|
||||
|
||||
init_form_submission( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
this.form_wrapper.removeEventListener( 'submit', this.events.submit_form );
|
||||
this.close_modal( true );
|
||||
setTimeout( this.submit_form.bind( this ), 0 );
|
||||
}
|
||||
|
||||
submit_form() {
|
||||
if ( this.status.is_sent ) {
|
||||
return;
|
||||
}
|
||||
this.status.is_sent = true;
|
||||
|
||||
const url = this.form_wrapper.getAttribute( 'action' );
|
||||
const request = new XMLHttpRequest();
|
||||
|
||||
request.open( 'POST', url, true );
|
||||
request.send( new FormData( this.form_wrapper ) );
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
!function(){"use strict";var t,e={364:function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var e=function(){function e(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.set_vars()&&this.set_events()}var n,i,o;return n=e,(i=[{key:"set_vars",value:function(){if(this.button_open=document.querySelector('[data-slug="<?php echo $plugin_slug; ?>"] a[href*="action=deactivate"]'),this.modal_wrapper=document.querySelector('[data-wpdesk-deactivation-modal="<?php echo $plugin_slug; ?>"]'),this.button_open&&this.modal_wrapper)return this.button_close=this.modal_wrapper.querySelector("[data-wpdesk-deactivation-modal-button-close]"),this.button_submit=this.modal_wrapper.querySelector("[data-wpdesk-deactivation-modal-button-submit]"),this.button_skip=this.modal_wrapper.querySelector("[data-wpdesk-deactivation-modal-button-skip]"),this.form_wrapper=this.modal_wrapper.querySelector("[data-wpdesk-deactivation-modal-form]"),this.events={open_modal:this.open_modal.bind(this)},this.settings={delay_click_deactivate:10},this.status={is_sent:!1},!0}},{key:"set_events",value:function(){this.button_open.addEventListener("click",this.events.open_modal),this.modal_wrapper.addEventListener("click",this.close_modal.bind(this,!1)),this.button_close.addEventListener("click",this.close_modal.bind(this,!1)),this.button_skip.addEventListener("click",this.close_modal.bind(this,!0)),this.form_wrapper.addEventListener("click",(function(t){t.stopPropagation()})),this.form_wrapper.addEventListener("submit",this.init_form_submission.bind(this))}},{key:"open_modal",value:function(t){t.preventDefault(),this.button_open.removeEventListener("click",this.events.open_modal),this.modal_wrapper.removeAttribute("hidden")}},{key:"close_modal",value:function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;n&&n.preventDefault();var i=this.settings.delay_click_deactivate;this.modal_wrapper.setAttribute("hidden","hidden"),t&&setTimeout((function(){e.button_open.click()}),i)}},{key:"init_form_submission",value:function(t){t.preventDefault(),this.form_wrapper.removeEventListener("submit",this.events.submit_form),this.close_modal(!0),setTimeout(this.submit_form.bind(this),0)}},{key:"submit_form",value:function(){if(!this.status.is_sent){this.status.is_sent=!0;var t=this.form_wrapper.getAttribute("action"),e=new XMLHttpRequest;e.open("POST",t,!0),e.send(new FormData(this.form_wrapper))}}}])&&t(n.prototype,i),o&&t(n,o),e}();new function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),new e}},109:function(){}},n={};function i(t){var o=n[t];if(void 0!==o)return o.exports;var r=n[t]={exports:{}};return e[t](r,r.exports,i),r.exports}i.m=e,t=[],i.O=function(e,n,o,r){if(!n){var s=1/0;for(l=0;l<t.length;l++){n=t[l][0],o=t[l][1],r=t[l][2];for(var a=!0,u=0;u<n.length;u++)(!1&r||s>=r)&&Object.keys(i.O).every((function(t){return i.O[t](n[u])}))?n.splice(u--,1):(a=!1,r<s&&(s=r));if(a){t.splice(l--,1);var c=o();void 0!==c&&(e=c)}}return e}r=r||0;for(var l=t.length;l>0&&t[l-1][2]>r;l--)t[l]=t[l-1];t[l]=[n,o,r]},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},function(){var t={861:0,33:0};i.O.j=function(e){return 0===t[e]};var e=function(e,n){var o,r,s=n[0],a=n[1],u=n[2],c=0;if(s.some((function(e){return 0!==t[e]}))){for(o in a)i.o(a,o)&&(i.m[o]=a[o]);if(u)var l=u(i)}for(e&&e(n);c<s.length;c++)r=s[c],i.o(t,r)&&t[r]&&t[r][0](),t[s[c]]=0;return i.O(l)},n=self.webpackChunkwp_wpdesk_deactivation_modal=self.webpackChunkwp_wpdesk_deactivation_modal||[];n.forEach(e.bind(null,0)),n.push=e.bind(null,n.push.bind(n))}(),i.O(void 0,[33],(function(){return i(364)}));var o=i.O(void 0,[33],(function(){return i(109)}));o=i.O(o)}();
|
||||
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "wpdesk\/wp-wpdesk-deactivation-modal",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mateusz Gbiorczyk",
|
||||
"email": "mateusz.gbiorczyk@wpdesk.net"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"FcfVendor\\WPDesk\\DeactivationModal\\": "src"
|
||||
}
|
||||
},
|
||||
"prefer-stable": true,
|
||||
"extra": {
|
||||
"text-domain": "wp-wpdesk-deactivation-modal",
|
||||
"translations-folder": "lang",
|
||||
"po-files": {
|
||||
"pl_PL": "pl_PL.po"
|
||||
},
|
||||
"assets-values": {
|
||||
"plugin-slug": {
|
||||
"search": "{__PLUGIN_SLUG__}",
|
||||
"replace": "<?php echo $plugin_slug; ?>"
|
||||
}
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit\/phpunit": "<7",
|
||||
"10up\/wp_mock": "*",
|
||||
"wpdesk\/wp-code-sniffer": "^1.2"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm install && npm run prod",
|
||||
"phpcs": "phpcs",
|
||||
"phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never",
|
||||
"phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage",
|
||||
"post-install-cmd": [
|
||||
"echo #!\/bin\/sh > .git\/hooks\/pre-commit",
|
||||
"echo:>> .git\/hooks\/pre-commit",
|
||||
"echo echo \"Building assets...\" >> .git\/hooks\/pre-commit",
|
||||
"echo composer run build >> .git\/hooks\/pre-commit",
|
||||
"echo git add assets\/ >> .git\/hooks\/pre-commit"
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"wpdesk\/wp-wpdesk-tracker": "^2.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Exception;
|
||||
|
||||
class DuplicatedFormOptionKeyException extends \Exception
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Exception;
|
||||
|
||||
class DuplicatedFormValueKeyException extends \Exception
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Exception;
|
||||
|
||||
class ReservedFormOptionKeyException extends \Exception
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Exception;
|
||||
|
||||
class SenderRequestFailedException extends \Exception
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Exception;
|
||||
|
||||
class UnknownFormOptionKeyException extends \Exception
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal;
|
||||
|
||||
interface Hookable
|
||||
{
|
||||
/**
|
||||
* Init hooks (actions and filters).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function hooks();
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal;
|
||||
|
||||
use FcfVendor\WPDesk\DeactivationModal\Model\FormOptions;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Model\FormTemplate;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Model\FormValues;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Sender\Sender;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Service\AssetsPrinterService;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Service\RequestSenderService;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Service\TemplateGeneratorService;
|
||||
/**
|
||||
* Manages the modal displayed when the plugin is deactivated.
|
||||
*/
|
||||
class Modal
|
||||
{
|
||||
const MODAL_TEMPLATE_PATH = __DIR__ . '/../templates/modal.php';
|
||||
const MODAL_ASSETS_PATH_CSS = __DIR__ . '/../assets/build/css/styles.css';
|
||||
const MODAL_ASSETS_PATH_JS = __DIR__ . '/../assets/build/js/scripts.js';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_slug;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $form_template;
|
||||
/**
|
||||
* @var FormOptions
|
||||
*/
|
||||
private $form_options;
|
||||
/**
|
||||
* @var FormValues
|
||||
*/
|
||||
private $form_values;
|
||||
/**
|
||||
* @var Sender
|
||||
*/
|
||||
private $request_sender;
|
||||
/**
|
||||
* @param string $plugin_slug Example: "plugin-name".
|
||||
* @param FormTemplate $form_template Information about the the deactivation modal template.
|
||||
* @param FormOptions $form_options List of plugin deactivation reasons to choose from.
|
||||
* @param FormValues $form_values Values sent in the request that reports the plugin deactivation.
|
||||
* @param Sender $request_sender Sends a request with a plugin deactivation report.
|
||||
*/
|
||||
public function __construct(string $plugin_slug, \FcfVendor\WPDesk\DeactivationModal\Model\FormTemplate $form_template, \FcfVendor\WPDesk\DeactivationModal\Model\FormOptions $form_options, \FcfVendor\WPDesk\DeactivationModal\Model\FormValues $form_values, \FcfVendor\WPDesk\DeactivationModal\Sender\Sender $request_sender)
|
||||
{
|
||||
$this->plugin_slug = $plugin_slug;
|
||||
$this->form_template = $form_template;
|
||||
$this->form_options = $form_options;
|
||||
$this->form_values = $form_values;
|
||||
$this->request_sender = $request_sender;
|
||||
(new \FcfVendor\WPDesk\DeactivationModal\Service\AssetsPrinterService($this->plugin_slug))->hooks();
|
||||
(new \FcfVendor\WPDesk\DeactivationModal\Service\TemplateGeneratorService($this->plugin_slug, $this->form_template, $this->form_options, $this->form_values))->hooks();
|
||||
(new \FcfVendor\WPDesk\DeactivationModal\Service\RequestSenderService($this->plugin_slug, $this->form_options, $this->form_values, $this->request_sender))->hooks();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Model;
|
||||
|
||||
use FcfVendor\WPDesk\DeactivationModal\Exception\DuplicatedFormOptionKeyException;
|
||||
/**
|
||||
* Default list of plugin deactivation reason for plugins using older libraries.
|
||||
*/
|
||||
class DefaultFormOptions extends \FcfVendor\WPDesk\DeactivationModal\Model\FormOptions
|
||||
{
|
||||
/**
|
||||
* @throws DuplicatedFormOptionKeyException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->set_option(new \FcfVendor\WPDesk\DeactivationModal\Model\FormOption('plugin_stopped_working', 10, \__('The plugin suddenly stopped working', 'flexible-checkout-fields')));
|
||||
$this->set_option(new \FcfVendor\WPDesk\DeactivationModal\Model\FormOption('broke_my_site', 20, \__('The plugin broke my site', 'flexible-checkout-fields')));
|
||||
$this->set_option(new \FcfVendor\WPDesk\DeactivationModal\Model\FormOption('found_better_plugin', 30, \__('I found a better plugin', 'flexible-checkout-fields'), null, \__('What\'s the plugin\'s name?', 'flexible-checkout-fields')));
|
||||
$this->set_option(new \FcfVendor\WPDesk\DeactivationModal\Model\FormOption('plugin_for_short_period', 40, \__('I only needed the plugin for a short period', 'flexible-checkout-fields')));
|
||||
$this->set_option(new \FcfVendor\WPDesk\DeactivationModal\Model\FormOption('no_longer_need', 50, \__('I no longer need the plugin', 'flexible-checkout-fields')));
|
||||
$this->set_option(new \FcfVendor\WPDesk\DeactivationModal\Model\FormOption('temporary_deactivation', 60, \__('It\'s a temporary deactivation (I\'m just debugging an issue)', 'flexible-checkout-fields')));
|
||||
$this->set_option(new \FcfVendor\WPDesk\DeactivationModal\Model\FormOption('other', 70, \__('Other', 'flexible-checkout-fields'), null, \__('Kindly tell us the reason so we can improve', 'flexible-checkout-fields')));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Model;
|
||||
|
||||
/**
|
||||
* Stores information about the selectable reason of the plugin deactivation.
|
||||
*/
|
||||
class FormOption
|
||||
{
|
||||
/**
|
||||
* @var string Key of the deactivation reason.
|
||||
*/
|
||||
private $key;
|
||||
/**
|
||||
* @var int Order priority (ascending).
|
||||
*/
|
||||
private $priority;
|
||||
/**
|
||||
* @var string Label of the reason option.
|
||||
*/
|
||||
private $label;
|
||||
/**
|
||||
* @var string|null Message visible after selecting the reason in the form (may contain HTML).
|
||||
*/
|
||||
private $message;
|
||||
/**
|
||||
* @var string|null Label of additional question (visible after selecting the reason in the form).
|
||||
*/
|
||||
private $question;
|
||||
/**
|
||||
* @param string $key Key of the deactivation reason.
|
||||
* @param int $priority Order priority (ascending).
|
||||
* @param string $label Label of the reason option.
|
||||
* @param string|null $message Message visible after selecting the reason in the form (may contain HTML).
|
||||
* @param string|null $question Label of additional question (visible after selecting the reason in the form).
|
||||
*/
|
||||
public function __construct(string $key, int $priority, string $label, string $message = null, string $question = null)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->priority = $priority;
|
||||
$this->label = $label;
|
||||
$this->message = $message;
|
||||
$this->question = $question;
|
||||
}
|
||||
public function get_key() : string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
public function get_priority() : int
|
||||
{
|
||||
return $this->priority;
|
||||
}
|
||||
/**
|
||||
* @param int $priority Order priority (ascending).
|
||||
*/
|
||||
public function set_priority(int $priority) : self
|
||||
{
|
||||
$this->priority = $priority;
|
||||
return $this;
|
||||
}
|
||||
public function get_label() : string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
/**
|
||||
* @param string $label Label of the reason option.
|
||||
*/
|
||||
public function set_label(string $label) : self
|
||||
{
|
||||
$this->label = $label;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_message()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
/**
|
||||
* @param string|null $message Message visible after selecting the reason in the form (may contain HTML).
|
||||
*/
|
||||
public function set_message(string $message = null) : self
|
||||
{
|
||||
$this->message = $message;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_question()
|
||||
{
|
||||
return $this->question;
|
||||
}
|
||||
/**
|
||||
* @param string|null $question Label of additional question (visible after selecting the reason in the form).
|
||||
*/
|
||||
public function set_question(string $question = null) : self
|
||||
{
|
||||
$this->question = $question;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Model;
|
||||
|
||||
use FcfVendor\WPDesk\DeactivationModal\Exception\DuplicatedFormOptionKeyException;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Exception\ReservedFormOptionKeyException;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Exception\UnknownFormOptionKeyException;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Sender\DataWpdeskSender;
|
||||
/**
|
||||
* Manages the list of deactivation reason in the form.
|
||||
*/
|
||||
class FormOptions
|
||||
{
|
||||
/**
|
||||
* @var FormOption[]
|
||||
*/
|
||||
private $options = [];
|
||||
/**
|
||||
* @param FormOption $new_option .
|
||||
*
|
||||
* @throws DuplicatedFormOptionKeyException
|
||||
* @throws ReservedFormOptionKeyException
|
||||
*/
|
||||
public function set_option(\FcfVendor\WPDesk\DeactivationModal\Model\FormOption $new_option) : self
|
||||
{
|
||||
if ($new_option->get_key() === \FcfVendor\WPDesk\DeactivationModal\Sender\DataWpdeskSender::NO_REASON_CHOSEN_KEY) {
|
||||
throw new \FcfVendor\WPDesk\DeactivationModal\Exception\ReservedFormOptionKeyException(\FcfVendor\WPDesk\DeactivationModal\Sender\DataWpdeskSender::NO_REASON_CHOSEN_KEY);
|
||||
}
|
||||
foreach ($this->options as $option) {
|
||||
if ($option->get_key() === $new_option->get_key()) {
|
||||
throw new \FcfVendor\WPDesk\DeactivationModal\Exception\DuplicatedFormOptionKeyException($new_option->get_key());
|
||||
}
|
||||
}
|
||||
$this->options[] = $new_option;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @param string $option_key .
|
||||
*
|
||||
* @throws UnknownFormOptionKeyException
|
||||
*/
|
||||
public function delete_option(string $option_key) : self
|
||||
{
|
||||
foreach ($this->options as $option_index => $option) {
|
||||
if ($option->get_key() === $option_key) {
|
||||
unset($this->options[$option_index]);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
throw new \FcfVendor\WPDesk\DeactivationModal\Exception\UnknownFormOptionKeyException($option_key);
|
||||
}
|
||||
/**
|
||||
* @param string $option_key .
|
||||
* @param callable $update_callback Example: "function ( FormOption $option ) { }".
|
||||
*
|
||||
* @throws UnknownFormOptionKeyException
|
||||
*/
|
||||
public function update_option(string $option_key, callable $update_callback) : self
|
||||
{
|
||||
foreach ($this->options as $option) {
|
||||
if ($option->get_key() === $option_key) {
|
||||
\call_user_func($update_callback, $option);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
throw new \FcfVendor\WPDesk\DeactivationModal\Exception\UnknownFormOptionKeyException($option_key);
|
||||
}
|
||||
/**
|
||||
* @return FormOption[]
|
||||
*/
|
||||
public function get_options() : array
|
||||
{
|
||||
$options = $this->options;
|
||||
\usort($options, function (\FcfVendor\WPDesk\DeactivationModal\Model\FormOption $option_a, \FcfVendor\WPDesk\DeactivationModal\Model\FormOption $option_b) {
|
||||
return $option_a->get_priority() <=> $option_b->get_priority();
|
||||
});
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Model;
|
||||
|
||||
/**
|
||||
* Stores information about the the deactivation modal template.
|
||||
*/
|
||||
class FormTemplate
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $form_title;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $form_desc;
|
||||
/**
|
||||
* @param string $plugin_name The full name of the plugin.
|
||||
*/
|
||||
public function __construct(string $plugin_name)
|
||||
{
|
||||
$this->set_form_title(\sprintf(
|
||||
/* translators: %1$s: plugin name */
|
||||
\__('You are deactivating %1$s plugin', 'flexible-checkout-fields'),
|
||||
$plugin_name
|
||||
));
|
||||
$this->set_form_desc(\__('If you have a moment, please let us know why you are deactivating plugin (anonymous feedback):', 'flexible-checkout-fields'));
|
||||
}
|
||||
public function set_form_title(string $form_title) : self
|
||||
{
|
||||
$this->form_title = $form_title;
|
||||
return $this;
|
||||
}
|
||||
public function get_form_title() : string
|
||||
{
|
||||
return $this->form_title;
|
||||
}
|
||||
public function set_form_desc(string $form_desc) : self
|
||||
{
|
||||
$this->form_desc = $form_desc;
|
||||
return $this;
|
||||
}
|
||||
public function get_form_desc() : string
|
||||
{
|
||||
return $this->form_desc;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Model;
|
||||
|
||||
/**
|
||||
* Stores information about the additional value sent in the request reporting plugin deactivation.
|
||||
*/
|
||||
class FormValue
|
||||
{
|
||||
/**
|
||||
* @var string Key of the additional value.
|
||||
*/
|
||||
private $key;
|
||||
/**
|
||||
* @var callable A function that returns a text value.
|
||||
*/
|
||||
private $value_callback;
|
||||
/**
|
||||
* @param string $key Key of the additional value.
|
||||
* @param callable $value_callback A function that returns a text value.
|
||||
*/
|
||||
public function __construct(string $key, callable $value_callback)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->value_callback = $value_callback;
|
||||
}
|
||||
public function get_key() : string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
public function get_value_callback() : callable
|
||||
{
|
||||
return $this->value_callback;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Model;
|
||||
|
||||
use FcfVendor\WPDesk\DeactivationModal\Exception\DuplicatedFormValueKeyException;
|
||||
/**
|
||||
* It manages the list of additional information sent in the request reporting plugin deactivation.
|
||||
*/
|
||||
class FormValues
|
||||
{
|
||||
/**
|
||||
* @var FormValue[]
|
||||
*/
|
||||
private $values = [];
|
||||
/**
|
||||
* @param FormValue $new_value .
|
||||
*
|
||||
* @throws DuplicatedFormValueKeyException
|
||||
*/
|
||||
public function set_value(\FcfVendor\WPDesk\DeactivationModal\Model\FormValue $new_value) : self
|
||||
{
|
||||
foreach ($this->values as $value) {
|
||||
if ($value->get_key() === $new_value->get_key()) {
|
||||
throw new \FcfVendor\WPDesk\DeactivationModal\Exception\DuplicatedFormValueKeyException($new_value->get_key());
|
||||
}
|
||||
}
|
||||
$this->values[] = $new_value;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @return FormValue[]
|
||||
*/
|
||||
public function get_values() : array
|
||||
{
|
||||
return $this->values;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Model;
|
||||
|
||||
/**
|
||||
* Stores information containing request data reporting plugin deactivation.
|
||||
*/
|
||||
class RequestData
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_slug;
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $reason_key = null;
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $additional_info = null;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $additional_data = [];
|
||||
/**
|
||||
* @param string $plugin_slug .
|
||||
*/
|
||||
public function __construct(string $plugin_slug)
|
||||
{
|
||||
$this->plugin_slug = $plugin_slug;
|
||||
}
|
||||
public function get_plugin_slug() : string
|
||||
{
|
||||
return $this->plugin_slug;
|
||||
}
|
||||
public function set_reason_key(string $reason_key = null) : self
|
||||
{
|
||||
$this->reason_key = $reason_key;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_reason_key()
|
||||
{
|
||||
return $this->reason_key;
|
||||
}
|
||||
public function set_additional_info(string $additional_info = null) : self
|
||||
{
|
||||
$this->additional_info = $additional_info;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_additional_info()
|
||||
{
|
||||
return $this->additional_info;
|
||||
}
|
||||
public function set_additional_data(array $additional_data) : self
|
||||
{
|
||||
$this->additional_data = $additional_data;
|
||||
return $this;
|
||||
}
|
||||
public function set_additional_data_item(string $data_key, string $data_value) : self
|
||||
{
|
||||
$this->additional_data[$data_key] = $data_value;
|
||||
return $this;
|
||||
}
|
||||
public function get_additional_data() : array
|
||||
{
|
||||
return $this->additional_data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Sender;
|
||||
|
||||
use FcfVendor\WPDesk\DeactivationModal\Exception\SenderRequestFailedException;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Model\RequestData;
|
||||
use WPDesk_Tracker_Sender;
|
||||
use FcfVendor\WPDesk_Tracker_Sender_Wordpress_To_WPDesk;
|
||||
/**
|
||||
* Sends a deactivation report to data.wpdesk.org.
|
||||
*/
|
||||
class DataWpdeskSender implements \FcfVendor\WPDesk\DeactivationModal\Sender\Sender
|
||||
{
|
||||
const HOOK_TRACKER_DEACTIVATION_DATA = 'wpdesk_tracker_deactivation_data';
|
||||
const NO_REASON_CHOSEN_KEY = 'null';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_file_name;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_name;
|
||||
/**
|
||||
* @var WPDesk_Tracker_Sender
|
||||
*/
|
||||
private $tracker_sender;
|
||||
/**
|
||||
* @param string $plugin_file_name Example: "plugin-name/plugin-name.php".
|
||||
* @param string $plugin_name The full name of the plugin.
|
||||
*/
|
||||
public function __construct(string $plugin_file_name, string $plugin_name)
|
||||
{
|
||||
$this->plugin_file_name = $plugin_file_name;
|
||||
$this->plugin_name = $plugin_name;
|
||||
$this->tracker_sender = new \FcfVendor\WPDesk_Tracker_Sender_Wordpress_To_WPDesk();
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function generate_request_data(\FcfVendor\WPDesk\DeactivationModal\Model\RequestData $request_data) : array
|
||||
{
|
||||
$request_body = ['click_action' => 'plugin_deactivation', 'plugin' => $this->plugin_file_name, 'plugin_name' => $this->plugin_name, 'reason' => $request_data->get_reason_key() ?: self::NO_REASON_CHOSEN_KEY, 'additional_data' => $request_data->get_additional_data()];
|
||||
if ($request_data->get_additional_info() !== null && $request_data->get_additional_info() !== '') {
|
||||
$request_body['additional_info'] = $request_data->get_additional_info();
|
||||
}
|
||||
return \apply_filters(self::HOOK_TRACKER_DEACTIVATION_DATA, $request_body, $this->plugin_file_name);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws SenderRequestFailedException
|
||||
*/
|
||||
public function send_request(\FcfVendor\WPDesk\DeactivationModal\Model\RequestData $request_data) : bool
|
||||
{
|
||||
try {
|
||||
$request_body = $this->generate_request_data($request_data);
|
||||
$response = $this->tracker_sender->send_payload($request_body);
|
||||
return \is_array($response);
|
||||
} catch (\Exception $e) {
|
||||
throw new \FcfVendor\WPDesk\DeactivationModal\Exception\SenderRequestFailedException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Sender;
|
||||
|
||||
use FcfVendor\WPDesk\DeactivationModal\Exception\SenderRequestFailedException;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Model\RequestData;
|
||||
interface Sender
|
||||
{
|
||||
/**
|
||||
* @param RequestData $request_data .
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function generate_request_data(\FcfVendor\WPDesk\DeactivationModal\Model\RequestData $request_data) : array;
|
||||
/**
|
||||
* @param RequestData $request_data .
|
||||
*
|
||||
* @return bool Request success status.
|
||||
*
|
||||
* @throws SenderRequestFailedException
|
||||
*/
|
||||
public function send_request(\FcfVendor\WPDesk\DeactivationModal\Model\RequestData $request_data) : bool;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Service;
|
||||
|
||||
use FcfVendor\WPDesk\DeactivationModal\Hookable;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Modal;
|
||||
/**
|
||||
* Prints the needed contents of CSS and JS files on the plugin list page.
|
||||
*/
|
||||
class AssetsPrinterService implements \FcfVendor\WPDesk\DeactivationModal\Hookable
|
||||
{
|
||||
const PLUGIN_NAME_VARIABLE = '{__PLUGIN_SLUG__}';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_slug;
|
||||
public function __construct(string $plugin_slug)
|
||||
{
|
||||
$this->plugin_slug = $plugin_slug;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hooks()
|
||||
{
|
||||
\add_action('admin_print_styles-plugins.php', [$this, 'load_styles']);
|
||||
\add_action('admin_print_footer_scripts-plugins.php', [$this, 'load_scripts']);
|
||||
}
|
||||
public function load_styles()
|
||||
{
|
||||
?>
|
||||
<style id="<?php
|
||||
echo \esc_attr($this->plugin_slug);
|
||||
?>-deactivation-modal-css">
|
||||
<?php
|
||||
$plugin_slug = $this->plugin_slug;
|
||||
include_once \FcfVendor\WPDesk\DeactivationModal\Modal::MODAL_ASSETS_PATH_CSS;
|
||||
?>
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
public function load_scripts()
|
||||
{
|
||||
?>
|
||||
<script id="<?php
|
||||
echo \esc_attr($this->plugin_slug);
|
||||
?>-deactivation-modal-js">
|
||||
<?php
|
||||
$plugin_slug = $this->plugin_slug;
|
||||
include_once \FcfVendor\WPDesk\DeactivationModal\Modal::MODAL_ASSETS_PATH_JS;
|
||||
?>
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Service;
|
||||
|
||||
use FcfVendor\WPDesk\DeactivationModal\Exception\SenderRequestFailedException;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Hookable;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Model\FormOptions;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Model\FormValues;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Model\RequestData;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Sender\Sender;
|
||||
/**
|
||||
* Sends the report about the plugin deactivation.
|
||||
*/
|
||||
class RequestSenderService implements \FcfVendor\WPDesk\DeactivationModal\Hookable
|
||||
{
|
||||
const FORM_FIELD_REASON = '_deactivation_reason';
|
||||
const FORM_FIELD_MESSAGE = '_deactivation_message_%s';
|
||||
const ADMIN_AJAX_ACTION = 'wpdesk_deactivation_request_';
|
||||
const ADMIN_AJAX_NONCE = 'wpdesk-deactivation-request';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_slug;
|
||||
/**
|
||||
* @var FormOptions
|
||||
*/
|
||||
private $form_options;
|
||||
/**
|
||||
* @var FormValues
|
||||
*/
|
||||
private $form_values;
|
||||
/**
|
||||
* @var Sender
|
||||
*/
|
||||
private $request_sender;
|
||||
public function __construct(string $plugin_slug, \FcfVendor\WPDesk\DeactivationModal\Model\FormOptions $form_options, \FcfVendor\WPDesk\DeactivationModal\Model\FormValues $form_values, \FcfVendor\WPDesk\DeactivationModal\Sender\Sender $request_sender)
|
||||
{
|
||||
$this->plugin_slug = $plugin_slug;
|
||||
$this->form_options = $form_options;
|
||||
$this->form_values = $form_values;
|
||||
$this->request_sender = $request_sender;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hooks()
|
||||
{
|
||||
\add_action('wp_ajax_' . self::ADMIN_AJAX_ACTION . $this->plugin_slug, [$this, 'handle_ajax_request']);
|
||||
\add_action('wp_ajax_nopriv_' . self::ADMIN_AJAX_ACTION . $this->plugin_slug, [$this, 'handle_ajax_request']);
|
||||
}
|
||||
public static function generate_ajax_url(string $plugin_slug) : string
|
||||
{
|
||||
return \sprintf('admin-ajax.php?action=%1$s&nonce=%2$s', self::ADMIN_AJAX_ACTION . $plugin_slug, \wp_create_nonce(self::ADMIN_AJAX_NONCE));
|
||||
}
|
||||
/**
|
||||
* @param mixed|null $request_params .
|
||||
*
|
||||
* @throws SenderRequestFailedException
|
||||
* @internal
|
||||
*/
|
||||
public function handle_ajax_request($request_params = null)
|
||||
{
|
||||
$params = $request_params && \is_array($request_params) ? $request_params : \wp_unslash($_REQUEST);
|
||||
if (\wp_verify_nonce($params['nonce'] ?? '', self::ADMIN_AJAX_NONCE) !== \false) {
|
||||
$this->send_request($params);
|
||||
\wp_send_json_success();
|
||||
} else {
|
||||
\wp_send_json_error();
|
||||
}
|
||||
\wp_die();
|
||||
}
|
||||
/**
|
||||
* @param array $request_params .
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws SenderRequestFailedException
|
||||
*/
|
||||
private function send_request(array $request_params)
|
||||
{
|
||||
$request_data = $this->get_request_data($request_params);
|
||||
$this->request_sender->send_request($request_data);
|
||||
}
|
||||
private function get_request_data(array $request_params) : \FcfVendor\WPDesk\DeactivationModal\Model\RequestData
|
||||
{
|
||||
$request_data = (new \FcfVendor\WPDesk\DeactivationModal\Model\RequestData($this->plugin_slug))->set_reason_key($this->get_deactivation_reason($request_params));
|
||||
if ($request_data->get_reason_key() !== null) {
|
||||
$value_key = \sprintf(self::FORM_FIELD_MESSAGE, $request_data->get_reason_key());
|
||||
$request_data->set_additional_info(isset($request_params[$value_key]) ? \sanitize_textarea_field($request_params[$value_key]) : null);
|
||||
}
|
||||
foreach ($this->form_values->get_values() as $value) {
|
||||
$request_data->set_additional_data_item($value->get_key(), \call_user_func($value->get_value_callback()));
|
||||
}
|
||||
return $request_data;
|
||||
}
|
||||
/**
|
||||
* @param array $request_params .
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function get_deactivation_reason(array $request_params)
|
||||
{
|
||||
$request_reason = $request_params[self::FORM_FIELD_REASON] ?? '';
|
||||
foreach ($this->form_options->get_options() as $option) {
|
||||
if ($option->get_key() === $request_reason) {
|
||||
return $request_reason;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\DeactivationModal\Service;
|
||||
|
||||
use FcfVendor\WPDesk\DeactivationModal\Hookable;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Modal;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Model\FormOptions;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Model\FormTemplate;
|
||||
use FcfVendor\WPDesk\DeactivationModal\Model\FormValues;
|
||||
/**
|
||||
* Prints the deactivation modal template on the plugin list page.
|
||||
*/
|
||||
class TemplateGeneratorService implements \FcfVendor\WPDesk\DeactivationModal\Hookable
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_slug;
|
||||
/**
|
||||
* @var FormTemplate
|
||||
*/
|
||||
private $form_template;
|
||||
/**
|
||||
* @var FormOptions
|
||||
*/
|
||||
private $form_options;
|
||||
/**
|
||||
* @var FormValues
|
||||
*/
|
||||
private $form_values;
|
||||
public function __construct(string $plugin_slug, \FcfVendor\WPDesk\DeactivationModal\Model\FormTemplate $form_template, \FcfVendor\WPDesk\DeactivationModal\Model\FormOptions $form_options, \FcfVendor\WPDesk\DeactivationModal\Model\FormValues $form_values)
|
||||
{
|
||||
$this->plugin_slug = $plugin_slug;
|
||||
$this->form_template = $form_template;
|
||||
$this->form_options = $form_options;
|
||||
$this->form_values = $form_values;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hooks()
|
||||
{
|
||||
\add_action('admin_print_footer_scripts-plugins.php', [$this, 'load_template'], 0);
|
||||
}
|
||||
public function load_template()
|
||||
{
|
||||
$params = ['api_url' => \FcfVendor\WPDesk\DeactivationModal\Service\RequestSenderService::generate_ajax_url($this->plugin_slug), 'plugin_slug' => $this->plugin_slug, 'field_name_reason' => \FcfVendor\WPDesk\DeactivationModal\Service\RequestSenderService::FORM_FIELD_REASON, 'field_name_message' => \FcfVendor\WPDesk\DeactivationModal\Service\RequestSenderService::FORM_FIELD_MESSAGE, 'form_template' => $this->form_template, 'form_options' => $this->form_options, 'form_values' => $this->form_values];
|
||||
\extract($params);
|
||||
// phpcs:ignore WordPress.PHP.DontExtract.extract_extract
|
||||
require_once \FcfVendor\WPDesk\DeactivationModal\Modal::MODAL_TEMPLATE_PATH;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor;
|
||||
|
||||
/**
|
||||
* @var string $api_url .
|
||||
* @var string $plugin_slug .
|
||||
* @var string $field_name_reason .
|
||||
* @var string $field_name_message .
|
||||
* @var WPDesk\DeactivationModal\Model\FormTemplate $form_template .
|
||||
* @var WPDesk\DeactivationModal\Model\FormOptions $form_options .
|
||||
* @var WPDesk\DeactivationModal\Model\FormValues $form_values .
|
||||
*
|
||||
* @package WPDesk\DeactivationModal
|
||||
*/
|
||||
?>
|
||||
|
||||
<div class="wpdeskDeactivationModal"
|
||||
data-wpdesk-deactivation-modal="<?php
|
||||
echo \esc_attr($plugin_slug);
|
||||
?>"
|
||||
hidden>
|
||||
<div class="wpdeskDeactivationModal__wrapper">
|
||||
<form action="<?php
|
||||
echo \esc_url($api_url);
|
||||
?>"
|
||||
method="POST"
|
||||
class="wpdeskDeactivationModal__form"
|
||||
data-wpdesk-deactivation-modal-form>
|
||||
<button type="button"
|
||||
class="wpdeskDeactivationModal__close dashicons dashicons-no"
|
||||
data-wpdesk-deactivation-modal-button-close></button>
|
||||
|
||||
<div class="wpdeskDeactivationModal__headline">
|
||||
<?php
|
||||
echo \wp_kses_post($form_template->get_form_title());
|
||||
?>
|
||||
</div>
|
||||
<div class="wpdeskDeactivationModal__desc">
|
||||
<?php
|
||||
echo \wp_kses_post($form_template->get_form_desc());
|
||||
?>
|
||||
</div>
|
||||
|
||||
<ul class="wpdeskDeactivationModal__options">
|
||||
<?php
|
||||
foreach ($form_options->get_options() as $option) {
|
||||
?>
|
||||
<li class="wpdeskDeactivationModal__option">
|
||||
<input type="radio"
|
||||
name="<?php
|
||||
echo \esc_attr($field_name_reason);
|
||||
?>"
|
||||
value="<?php
|
||||
echo \esc_attr($option->get_key());
|
||||
?>"
|
||||
id="option-<?php
|
||||
echo \esc_attr($plugin_slug);
|
||||
?>-<?php
|
||||
echo \esc_attr($option->get_key());
|
||||
?>"
|
||||
class="wpdeskDeactivationModal__optionInput">
|
||||
<label
|
||||
for="option-<?php
|
||||
echo \esc_attr($plugin_slug);
|
||||
?>-<?php
|
||||
echo \esc_attr($option->get_key());
|
||||
?>"
|
||||
class="wpdeskDeactivationModal__optionLabel">
|
||||
<?php
|
||||
echo \esc_html($option->get_label());
|
||||
?>
|
||||
</label>
|
||||
<div class="wpdeskDeactivationModal__optionExtra">
|
||||
<?php
|
||||
if ($option->get_message() !== null) {
|
||||
?>
|
||||
<div class="wpdeskDeactivationModal__optionMessage">
|
||||
<?php
|
||||
echo \wp_kses_post($option->get_message());
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
if ($option->get_question() !== null) {
|
||||
?>
|
||||
<textarea class="wpdeskDeactivationModal__optionTextarea"
|
||||
name="<?php
|
||||
echo \esc_attr(\sprintf($field_name_message, $option->get_key()));
|
||||
?>"
|
||||
placeholder="<?php
|
||||
echo \esc_attr($option->get_question());
|
||||
?>"
|
||||
rows="2"></textarea>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
|
||||
<ul class="wpdeskDeactivationModal__buttons">
|
||||
<li class="wpdeskDeactivationModal__button">
|
||||
<button type="submit"
|
||||
class="wpdeskDeactivationModal__buttonInner wpdeskDeactivationModal__buttonInner--blue"
|
||||
data-wpdesk-deactivation-modal-button-submit>
|
||||
<?php
|
||||
echo \esc_html(\__('Submit and Deactivate', 'flexible-checkout-fields'));
|
||||
?>
|
||||
</button>
|
||||
</li>
|
||||
<li class="wpdeskDeactivationModal__button">
|
||||
<button type="button"
|
||||
class="wpdeskDeactivationModal__buttonInner wpdeskDeactivationModal__buttonInner--gray"
|
||||
data-wpdesk-deactivation-modal-button-skip>
|
||||
<?php
|
||||
echo \esc_html(\__('Skip and Deactivate', 'flexible-checkout-fields'));
|
||||
?>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @see https://github.com/gbiorczyk/mati-mix/
|
||||
*/
|
||||
const mix = require( 'mati-mix' );
|
||||
const composer = require( './composer.json' );
|
||||
const ReplacePlugin = require( 'replace-in-file-webpack-plugin' );
|
||||
|
||||
mix.mix.setPublicPath( 'assets/build' );
|
||||
mix.version();
|
||||
|
||||
mix.js(
|
||||
[
|
||||
'assets-src/js/Core.js',
|
||||
],
|
||||
'assets/build/js/scripts.js'
|
||||
);
|
||||
|
||||
mix.sass(
|
||||
'assets-src/scss/Core.scss',
|
||||
'assets/build/css/styles.css'
|
||||
);
|
||||
|
||||
mix.webpackConfig( {
|
||||
plugins: [
|
||||
new ReplacePlugin( [
|
||||
{
|
||||
dir: 'assets/build/js',
|
||||
files: [ 'scripts.js' ],
|
||||
rules: [
|
||||
{
|
||||
search: new RegExp( `(${ composer.extra[ 'assets-values' ][ 'plugin-slug' ][ 'search' ] })`, 'g' ),
|
||||
replace: composer.extra[ 'assets-values' ][ 'plugin-slug' ][ 'replace' ],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
dir: 'assets/build/css',
|
||||
files: [ 'styles.css' ],
|
||||
rules: [
|
||||
{
|
||||
search: new RegExp( `(${ composer.extra[ 'assets-values' ][ 'plugin-slug' ][ 'search' ] })`, 'g' ),
|
||||
replace: composer.extra[ 'assets-values' ][ 'plugin-slug' ][ 'replace' ],
|
||||
},
|
||||
],
|
||||
},
|
||||
] ),
|
||||
],
|
||||
} );
|
||||
Reference in New Issue
Block a user