first commit

This commit is contained in:
2024-11-10 21:08:49 +01:00
commit 0d932ce5ee
14455 changed files with 2567501 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
<?php
namespace WPDesk\FCF\Free\Exception;
/** * .
*/
class TemplateLoadingFailed extends \Exception {
}

View File

@@ -0,0 +1,60 @@
<?php
namespace WPDesk\FCF\Free\Field;
use WPDesk\FCF\Free\Field\Type\DefaultType;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
/**
* Generates field data based on options for field type.
*/
class FieldData {
/**
* Returns parsed data for field.
*
* @param array $field_settings Settings of field.
* @param bool $is_decode Is it decoding (used saved settings) data instead of encoding (for settings save).
*
* @return array Data of field.
*/
public static function get_field_data( array $field_settings, bool $is_decode = true ): array {
$field_data = [];
$option_objects = self::get_field_options( $field_settings );
if ( ! $option_objects ) {
return $field_data;
}
$field_data['name'] = $field_settings['name'];
foreach ( $option_objects as $field_option ) {
$field_data = $field_option[ ( $is_decode ) ? 'update_field_callback' : 'save_field_callback' ](
$field_data,
$field_settings
);
}
return $field_data;
}
/**
* Returns list of option objects.
*
* @param array $field_settings Settings of field.
*
* @return OptionInterface[] List of options.
*/
public static function get_field_options( array $field_settings ): array {
$field_types = apply_filters( 'flexible_checkout_fields/field_types', [] );
foreach ( $field_types as $field_type ) {
if ( in_array( $field_settings['name'], $field_type['reserved_field_names'], true ) ) {
return $field_type['options'];
}
}
foreach ( $field_types as $field_type ) {
if ( isset( $field_settings['type'] ) && ( $field_settings['type'] === $field_type['type'] ) ) {
return $field_type['options'];
}
}
return $field_types[ DefaultType::FIELD_TYPE ]['options'] ?? [];
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace WPDesk\FCF\Free\Field;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use WPDesk\FCF\Free\Exception\TemplateLoadingFailed;
use WPDesk\FCF\Free\Service\TemplateLoader;
use WPDesk\FCF\Free\Settings\Form\EditFieldsForm;
use WPDesk\FCF\Free\Settings\Option\CustomFieldOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
/**
* .
*/
class FieldTemplateLoader implements Hookable {
/**
* @var TemplateLoader
*/
private $template_loader;
/**
* Class constructor.
*/
public function __construct( TemplateLoader $template_loader ) {
$this->template_loader = $template_loader;
}
/**
* {@inheritdoc}
*/
public function hooks() {
add_filter( 'woocommerce_form_field', [ $this, 'load_field_template' ], 999, 4 );
add_filter( 'flexible_checkout_fields_form_field', [ $this, 'load_field_template' ], 10, 4 );
add_filter( 'woocommerce_form_field_args', [ $this, 'load_default_field_args' ], 10, 1 );
}
/**
* @param string $output HTML output.
* @param string $key Field name.
* @param array $args Fields args.
* @param mixed $value .
*
* @return string
*
* @throws TemplateLoadingFailed
* @internal
*/
public function load_field_template( $output, $key, $args, $value ) {
if ( ! isset( $args[ CustomFieldOption::FIELD_NAME ] ) || ! $args[ CustomFieldOption::FIELD_NAME ] ) {
return $output;
}
$field_data = $this->get_field_data( $key );
if ( $field_data === null ) {
return $output;
}
$field_type = $args[ FieldTypeOption::FIELD_NAME ];
$field_types = apply_filters( 'flexible_checkout_fields/field_types', [] );
if ( ! isset( $field_types[ $field_type ] ) || ! $field_types[ $field_type ]['is_available'] ) {
return $output;
}
remove_filter( 'woocommerce_form_field', [ $this, 'load_field_template' ], 999 );
$output = $this->template_loader->load_template(
'fields/' . $field_type,
[
'args' => apply_filters( 'flexible_checkout_fields_field_args', $field_data, $key ),
'key' => $key,
'value' => $value,
'custom_attributes' => apply_filters( 'flexible_checkout_fields_custom_attributes', [], $field_data ),
]
);
add_filter( 'woocommerce_form_field', [ $this, 'load_field_template' ], 999, 4 );
return $output;
}
/**
* @param string $field_name .
*
* @return mixed|null
*/
private function get_field_data( string $field_name ) {
$fields_settings = get_option( EditFieldsForm::SETTINGS_OPTION_NAME, [] );
foreach ( $fields_settings as $group_name => $fields ) {
foreach ( $fields as $field_id => $field_data ) {
if ( $field_id === $field_name ) {
return $field_data;
}
}
}
return null;
}
/**
* @param array $args .
*
* @return array
* @internal
*/
public function load_default_field_args( $args ) {
if ( ! isset( $args[ CustomFieldOption::FIELD_NAME ] ) || ! $args[ CustomFieldOption::FIELD_NAME ] ) {
return $args;
}
$args['options'] = [];
return $args;
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace WPDesk\FCF\Free\Field;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Supports translating field settings via external plugins.
*/
class FieldTranslator implements Hookable {
/**
* {@inheritdoc}
*/
public function hooks() {
add_filter( 'flexible_checkout_fields_field_args', [ $this, 'translate_field' ], 10, 2 );
}
/**
* @param mixed[] $field_data .
* @param string $field_name .
*
* @return mixed[]
*/
public function translate_field( $field_data, $field_name ) {
if ( isset( $field_data['label'] ) ) {
$field_data['label'] = wpdesk__( $field_data['label'], 'flexible-checkout-fields' );
}
if ( isset( $field_data['placeholder'] ) ) {
$field_data['placeholder'] = wpdesk__( $field_data['placeholder'], 'flexible-checkout-fields' );
}
if ( isset( $field_data['default'] ) ) {
$field_data['default'] = wpdesk__( $field_data['default'], 'flexible-checkout-fields' );
}
if ( isset( $field_data['options'] ) ) {
foreach ( $field_data['options'] as $option_index => $option ) {
$field_data['options'][ $option_index ]['value'] = wpdesk__( $option['value'], 'flexible-checkout-fields' );
}
}
return $field_data;
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class CheckboxDefaultType extends DefaultType implements TypeInterface {
const FIELD_TYPE = 'checkbox';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
$options = parent::get_options_objects();
$options[ GeneralTab::TAB_NAME ][ FieldTypeOption::FIELD_NAME ] = new FieldTypeOption();
return $options;
}
}

View File

@@ -0,0 +1,99 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\CustomFieldOption;
use WPDesk\FCF\Free\Settings\Option\DefaultOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\FormattingOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\PlaceholderCheckboxOption;
use WPDesk\FCF\Free\Settings\Option\PricingAdvOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredOption;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
use WPDesk\FCF\Free\Settings\Tab\PricingTab;
/**
* {@inheritdoc}
*/
class CheckboxType extends TypeAbstract {
const FIELD_TYPE = 'inspirecheckbox';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Checkbox', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_OPTION;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-check-square';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* {@inheritdoc}
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
PriorityOption::FIELD_NAME => new PriorityOption(),
FieldTypeOption::FIELD_NAME => new FieldTypeOption(),
CustomFieldOption::FIELD_NAME => new CustomFieldOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
RequiredOption::FIELD_NAME => new RequiredOption(),
LabelOption::FIELD_NAME => new LabelOption(),
PlaceholderCheckboxOption::FIELD_NAME => new PlaceholderCheckboxOption(),
DefaultOption::FIELD_NAME => new DefaultOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AppearanceTab::TAB_NAME => [
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingOption::FIELD_NAME => new FormattingOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
PricingTab::TAB_NAME => [
PricingAdvOption::FIELD_NAME => new PricingAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\CustomFieldOption;
use WPDesk\FCF\Free\Settings\Option\DefaultOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\FormattingOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\PlaceholderOption;
use WPDesk\FCF\Free\Settings\Option\PricingAdvOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
use WPDesk\FCF\Free\Settings\Tab\PricingTab;
/**
* {@inheritdoc}
*/
class ColorType extends TypeAbstract {
const FIELD_TYPE = 'colorpicker';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Color', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_PICKER;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-paint-brush';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* {@inheritdoc}
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
PriorityOption::FIELD_NAME => new PriorityOption(),
FieldTypeOption::FIELD_NAME => new FieldTypeOption(),
CustomFieldOption::FIELD_NAME => new CustomFieldOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
RequiredOption::FIELD_NAME => new RequiredOption(),
LabelOption::FIELD_NAME => new LabelOption(),
DefaultOption::FIELD_NAME => new DefaultOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValidationOption::FIELD_NAME => new ValidationOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
PlaceholderOption::FIELD_NAME => new PlaceholderOption(),
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingOption::FIELD_NAME => new FormattingOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
PricingTab::TAB_NAME => [
PricingAdvOption::FIELD_NAME => new PricingAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
/**
* {@inheritdoc}
*/
class DateType extends TypeAbstract {
const FIELD_TYPE = 'datepicker';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Date', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_PICKER;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-calendar-alt';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return false;
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\CustomFieldDisabledOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldInfoOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeDefaultOption;
use WPDesk\FCF\Free\Settings\Option\FormattingWcOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PlaceholderOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationWcOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
/**
* {@inheritdoc}
*/
class DefaultType extends TypeAbstract {
const FIELD_TYPE = 'fcf_default';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Default Field', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function is_hidden(): bool {
return true;
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return false;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
ExternalFieldInfoOption::FIELD_NAME => new ExternalFieldInfoOption(),
PriorityOption::FIELD_NAME => new PriorityOption(),
FieldTypeDefaultOption::FIELD_NAME => new FieldTypeDefaultOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
CustomFieldDisabledOption::FIELD_NAME => new CustomFieldDisabledOption(),
ExternalFieldOption::FIELD_NAME => new ExternalFieldOption(),
RequiredOption::FIELD_NAME => new RequiredOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValidationWcOption::FIELD_NAME => new ValidationWcOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
PlaceholderOption::FIELD_NAME => new PlaceholderOption(),
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingWcOption::FIELD_NAME => new FormattingWcOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,111 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\CustomFieldOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldInfoOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\FormattingOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PlaceholderOption;
use WPDesk\FCF\Free\Settings\Option\PricingAdvOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
use WPDesk\FCF\Free\Settings\Tab\PricingTab;
/**
* {@inheritdoc}
*/
class EmailType extends TypeAbstract {
const FIELD_TYPE = 'email';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'E-mail', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_TEXT;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-at-email';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
ExternalFieldInfoOption::FIELD_NAME => new ExternalFieldInfoOption(),
PriorityOption::FIELD_NAME => new PriorityOption(),
FieldTypeOption::FIELD_NAME => new FieldTypeOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
CustomFieldOption::FIELD_NAME => new CustomFieldOption(),
ExternalFieldOption::FIELD_NAME => new ExternalFieldOption(),
RequiredOption::FIELD_NAME => new RequiredOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValidationOption::FIELD_NAME => new ValidationOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
PlaceholderOption::FIELD_NAME => new PlaceholderOption(),
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingOption::FIELD_NAME => new FormattingOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
PricingTab::TAB_NAME => [
PricingAdvOption::FIELD_NAME => new PricingAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
/**
* {@inheritdoc}
*/
class FileType extends TypeAbstract {
const FIELD_TYPE = 'file';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'File Upload', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_PICKER;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-upload';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return false;
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\CustomFieldOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredHiddenOption;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
/**
* {@inheritdoc}
*/
class HeadingType extends TypeAbstract {
const FIELD_TYPE = 'heading';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Heading', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_OTHER;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-heading';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
PriorityOption::FIELD_NAME => new PriorityOption(),
FieldTypeOption::FIELD_NAME => new FieldTypeOption(),
CustomFieldOption::FIELD_NAME => new CustomFieldOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
RequiredHiddenOption::FIELD_NAME => new RequiredHiddenOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AppearanceTab::TAB_NAME => [
CssOption::FIELD_NAME => new CssOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
/**
* {@inheritdoc}
*/
class HiddenType extends TypeAbstract {
const FIELD_TYPE = 'hidden';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Hidden', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_OTHER;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-eye-slash';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return false;
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\CustomFieldOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredHiddenOption;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
/**
* {@inheritdoc}
*/
class HtmlType extends TypeAbstract {
const FIELD_TYPE = 'info';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'HTML', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_OTHER;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-code';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
PriorityOption::FIELD_NAME => new PriorityOption(),
FieldTypeOption::FIELD_NAME => new FieldTypeOption(),
CustomFieldOption::FIELD_NAME => new CustomFieldOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
RequiredHiddenOption::FIELD_NAME => new RequiredHiddenOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AppearanceTab::TAB_NAME => [
CssOption::FIELD_NAME => new CssOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\CustomFieldOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\ImageOption;
use WPDesk\FCF\Free\Settings\Option\ImageWidthOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredHiddenOption;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
/**
* {@inheritdoc}
*/
class ImageType extends TypeAbstract {
const FIELD_TYPE = 'image';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Image', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_OTHER;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-image';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
PriorityOption::FIELD_NAME => new PriorityOption(),
FieldTypeOption::FIELD_NAME => new FieldTypeOption(),
CustomFieldOption::FIELD_NAME => new CustomFieldOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
RequiredHiddenOption::FIELD_NAME => new RequiredHiddenOption(),
LabelOption::FIELD_NAME => new LabelOption(),
ImageOption::FIELD_NAME => new ImageOption(),
ImageWidthOption::FIELD_NAME => new ImageWidthOption(),
],
AppearanceTab::TAB_NAME => [
CssOption::FIELD_NAME => new CssOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
/**
* {@inheritdoc}
*/
class MultiCheckboxType extends TypeAbstract {
const FIELD_TYPE = 'multicheckbox';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Multi-checkbox', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_OPTION;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-check-square-multi';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return false;
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
/**
* {@inheritdoc}
*/
class MultiSelectType extends TypeAbstract {
const FIELD_TYPE = 'wpdeskmultiselect';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Multi-select', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_OPTION;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-tasks';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return false;
}
}

View File

@@ -0,0 +1,117 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\CustomFieldOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldInfoOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\FormattingOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PlaceholderOption;
use WPDesk\FCF\Free\Settings\Option\PricingAdvOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationOption;
use WPDesk\FCF\Free\Settings\Option\ValueMaxOption;
use WPDesk\FCF\Free\Settings\Option\ValueMinOption;
use WPDesk\FCF\Free\Settings\Option\ValueStepOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
use WPDesk\FCF\Free\Settings\Tab\PricingTab;
/**
* {@inheritdoc}
*/
class NumberType extends TypeAbstract {
const FIELD_TYPE = 'number';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Number', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_TEXT;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-digits';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
ExternalFieldInfoOption::FIELD_NAME => new ExternalFieldInfoOption(),
PriorityOption::FIELD_NAME => new PriorityOption(),
FieldTypeOption::FIELD_NAME => new FieldTypeOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
CustomFieldOption::FIELD_NAME => new CustomFieldOption(),
ExternalFieldOption::FIELD_NAME => new ExternalFieldOption(),
RequiredOption::FIELD_NAME => new RequiredOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValueMinOption::FIELD_NAME => new ValueMinOption(),
ValueMaxOption::FIELD_NAME => new ValueMaxOption(),
ValueStepOption::FIELD_NAME => new ValueStepOption(),
ValidationOption::FIELD_NAME => new ValidationOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
PlaceholderOption::FIELD_NAME => new PlaceholderOption(),
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingOption::FIELD_NAME => new FormattingOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
PricingTab::TAB_NAME => [
PricingAdvOption::FIELD_NAME => new PricingAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\CustomFieldOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredHiddenOption;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
/**
* {@inheritdoc}
*/
class ParagraphType extends TypeAbstract {
const FIELD_TYPE = 'paragraph';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Paragraph', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_OTHER;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-paragraph';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
PriorityOption::FIELD_NAME => new PriorityOption(),
FieldTypeOption::FIELD_NAME => new FieldTypeOption(),
CustomFieldOption::FIELD_NAME => new CustomFieldOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
RequiredHiddenOption::FIELD_NAME => new RequiredHiddenOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AppearanceTab::TAB_NAME => [
CssOption::FIELD_NAME => new CssOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,115 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\CustomFieldOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldInfoOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\FormattingOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PlaceholderOption;
use WPDesk\FCF\Free\Settings\Option\PricingAdvOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RegexMessageOption;
use WPDesk\FCF\Free\Settings\Option\RegexPhoneOption;
use WPDesk\FCF\Free\Settings\Option\RequiredOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
use WPDesk\FCF\Free\Settings\Tab\PricingTab;
/**
* {@inheritdoc}
*/
class PhoneType extends TypeAbstract {
const FIELD_TYPE = 'phone';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Phone', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_TEXT;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-phone';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
ExternalFieldInfoOption::FIELD_NAME => new ExternalFieldInfoOption(),
PriorityOption::FIELD_NAME => new PriorityOption(),
FieldTypeOption::FIELD_NAME => new FieldTypeOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
CustomFieldOption::FIELD_NAME => new CustomFieldOption(),
ExternalFieldOption::FIELD_NAME => new ExternalFieldOption(),
RequiredOption::FIELD_NAME => new RequiredOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
RegexPhoneOption::FIELD_NAME => new RegexPhoneOption(),
RegexMessageOption::FIELD_NAME => new RegexMessageOption(),
ValidationOption::FIELD_NAME => new ValidationOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
PlaceholderOption::FIELD_NAME => new PlaceholderOption(),
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingOption::FIELD_NAME => new FormattingOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
PricingTab::TAB_NAME => [
PricingAdvOption::FIELD_NAME => new PricingAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
/**
* {@inheritdoc}
*/
class RadioColorsType extends TypeAbstract {
const FIELD_TYPE = 'radiocolors';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Radio with colors', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_OPTION;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-palette';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return false;
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class RadioDefaultType extends DefaultType implements TypeInterface {
const FIELD_TYPE = 'radio';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
$options = parent::get_options_objects();
$options[ GeneralTab::TAB_NAME ][ FieldTypeOption::FIELD_NAME ] = new FieldTypeOption();
return $options;
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
/**
* {@inheritdoc}
*/
class RadioImagesType extends TypeAbstract {
const FIELD_TYPE = 'radioimages';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Radio with images', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_OPTION;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-images';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return false;
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
/**
* {@inheritdoc}
*/
class RadioType extends TypeAbstract {
const FIELD_TYPE = 'inspireradio';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Radio', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_OPTION;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-list-ul';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return false;
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class SelectType extends DefaultType implements TypeInterface {
const FIELD_TYPE = 'select';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Select', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_OPTION;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-tasks-alt';
}
/**
* {@inheritdoc}
*/
public function is_hidden(): bool {
return false;
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return false;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
$options = parent::get_options_objects();
$options[ GeneralTab::TAB_NAME ][ FieldTypeOption::FIELD_NAME ] = new FieldTypeOption();
return $options;
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\CustomFieldOption;
use WPDesk\FCF\Free\Settings\Option\DefaultOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldInfoOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\FormattingOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PlaceholderOption;
use WPDesk\FCF\Free\Settings\Option\PricingAdvOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationWcOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
use WPDesk\FCF\Free\Settings\Tab\PricingTab;
/**
* {@inheritdoc}
*/
class TextType extends TypeAbstract {
const FIELD_TYPE = 'text';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Text', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_TEXT;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-font';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
ExternalFieldInfoOption::FIELD_NAME => new ExternalFieldInfoOption(),
PriorityOption::FIELD_NAME => new PriorityOption(),
FieldTypeOption::FIELD_NAME => new FieldTypeOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
CustomFieldOption::FIELD_NAME => new CustomFieldOption(),
ExternalFieldOption::FIELD_NAME => new ExternalFieldOption(),
RequiredOption::FIELD_NAME => new RequiredOption(),
LabelOption::FIELD_NAME => new LabelOption(),
DefaultOption::FIELD_NAME => new DefaultOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValidationWcOption::FIELD_NAME => new ValidationWcOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
PlaceholderOption::FIELD_NAME => new PlaceholderOption(),
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingOption::FIELD_NAME => new FormattingOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
PricingTab::TAB_NAME => [
PricingAdvOption::FIELD_NAME => new PricingAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\CustomFieldOption;
use WPDesk\FCF\Free\Settings\Option\DefaultOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldInfoOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\FormattingOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PlaceholderOption;
use WPDesk\FCF\Free\Settings\Option\PricingAdvOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
use WPDesk\FCF\Free\Settings\Tab\PricingTab;
/**
* {@inheritdoc}
*/
class TextareaType extends TypeAbstract {
const FIELD_TYPE = 'textarea';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Textarea', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_TEXT;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-align-left';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
ExternalFieldInfoOption::FIELD_NAME => new ExternalFieldInfoOption(),
PriorityOption::FIELD_NAME => new PriorityOption(),
FieldTypeOption::FIELD_NAME => new FieldTypeOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
CustomFieldOption::FIELD_NAME => new CustomFieldOption(),
ExternalFieldOption::FIELD_NAME => new ExternalFieldOption(),
RequiredOption::FIELD_NAME => new RequiredOption(),
LabelOption::FIELD_NAME => new LabelOption(),
DefaultOption::FIELD_NAME => new DefaultOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValidationOption::FIELD_NAME => new ValidationOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
PlaceholderOption::FIELD_NAME => new PlaceholderOption(),
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingOption::FIELD_NAME => new FormattingOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
PricingTab::TAB_NAME => [
PricingAdvOption::FIELD_NAME => new PricingAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
/**
* {@inheritdoc}
*/
class TimeType extends TypeAbstract {
const FIELD_TYPE = 'timepicker';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'Time', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_PICKER;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-clock';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return false;
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Settings\Option\OptionIntegration;
/**
* {@inheritdoc}
*/
abstract class TypeAbstract implements TypeInterface {
/**
* {@inheritdoc}
*/
public function get_raw_field_type(): string {
return $this->get_field_type();
}
/**
* {@inheritdoc}
*/
public function get_field_group() {
return null;
}
/**
* {@inheritdoc}
*/
public function get_reserved_field_names(): array {
return [];
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return '';
}
/**
* {@inheritdoc}
*/
public function is_hidden(): bool {
return false;
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return false;
}
/**
* {@inheritdoc}
*/
public function get_options_objects(): array {
return [];
}
/**
* {@inheritdoc}
*/
public function get_options(): array {
$options = [];
foreach ( $this->get_options_objects() as $option_objects ) {
foreach ( $option_objects as $option_object ) {
$options[] = ( new OptionIntegration( $option_object ) )->get_field_settings();
}
}
return $options;
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
/**
* Initializes integration for REST API route.
*/
class TypeIntegration {
/**
* Class object for field type.
*
* @var TypeInterface
*/
private $type_object;
/**
* Class constructor.
*
* @param TypeInterface $type_object Class object of field type.
*/
public function __construct( TypeInterface $type_object ) {
$this->type_object = $type_object;
}
/**
* {@inheritdoc}
*/
public function hooks() {
add_filter( 'flexible_checkout_fields/field_types', [ $this, 'add_field_type' ], 0 );
}
/**
* Adds new field type with settings of field type.
*
* @param array $types List of field types.
*
* @return array Updated list of field types.
* @internal
*/
public function add_field_type( array $types ): array {
$field_type = $this->type_object->get_field_type();
$types[ $field_type ] = $this->get_field_type_settings();
return $types;
}
/**
* Returns list of settings for field type.
*
* @return array Settings of field type.
*/
private function get_field_type_settings(): array {
return [
'type' => $this->type_object->get_field_type(),
'field_group' => $this->type_object->get_field_group(),
'reserved_field_names' => $this->type_object->get_reserved_field_names(),
'label' => $this->type_object->get_field_type_label(),
'icon' => $this->type_object->get_field_type_icon(),
'is_hidden' => $this->type_object->is_hidden(),
'is_available' => $this->type_object->is_available(),
'options' => $this->type_object->get_options(),
];
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
/**
* Interface of field type.
*/
interface TypeInterface {
/**
* Returns value of field type.
*
* @return string Field type.
*/
public function get_field_type(): string;
/**
* Returns value of field type used in HTML.
*
* @return string Field type.
*/
public function get_raw_field_type(): string;
/**
* Returns reserved field names, overriding this field type for selected field names.
*
* @return array Field names.
*/
public function get_reserved_field_names(): array;
/**
* Returns label of field type.
*
* @return string Field label.
*/
public function get_field_type_label(): string;
/**
* Returns key of field group.
*
* @return string|null
*/
public function get_field_group();
/**
* Returns field icon as CSS Class supported by Icomoon.
*
* @return string Field icon.
*/
public function get_field_type_icon(): string;
/**
* Returns whether field type is hidden.
*
* @return bool Status if field type is hidden.
*/
public function is_hidden(): bool;
/**
* Returns whether field type is available for plugin version.
*
* @return bool Status if field type is available.
*/
public function is_available(): bool;
/**
* Returns list of options objects for field settings.
*
* @return OptionInterface[] List of field options objects.
*/
public function get_options_objects(): array;
/**
* Returns list of options for field settings.
*
* @return array List of field options.
*/
public function get_options(): array;
}

View File

@@ -0,0 +1,111 @@
<?php
namespace WPDesk\FCF\Free\Field\Type;
use WPDesk\FCF\Free\Field\Types;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\CustomFieldOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldInfoOption;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldOption;
use WPDesk\FCF\Free\Settings\Option\FieldTypeOption;
use WPDesk\FCF\Free\Settings\Option\FormattingOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PlaceholderOption;
use WPDesk\FCF\Free\Settings\Option\PricingAdvOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
use WPDesk\FCF\Free\Settings\Tab\PricingTab;
/**
* {@inheritdoc}
*/
class UrlType extends TypeAbstract {
const FIELD_TYPE = 'url';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'URL', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_field_group(): string {
return Types::FIELD_GROUP_TEXT;
}
/**
* {@inheritdoc}
*/
public function get_field_type_icon(): string {
return 'icon-link';
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
ExternalFieldInfoOption::FIELD_NAME => new ExternalFieldInfoOption(),
PriorityOption::FIELD_NAME => new PriorityOption(),
FieldTypeOption::FIELD_NAME => new FieldTypeOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
CustomFieldOption::FIELD_NAME => new CustomFieldOption(),
ExternalFieldOption::FIELD_NAME => new ExternalFieldOption(),
RequiredOption::FIELD_NAME => new RequiredOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValidationOption::FIELD_NAME => new ValidationOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
PlaceholderOption::FIELD_NAME => new PlaceholderOption(),
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingOption::FIELD_NAME => new FormattingOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
PricingTab::TAB_NAME => [
PricingAdvOption::FIELD_NAME => new PricingAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,101 @@
<?php
namespace WPDesk\FCF\Free\Field\Type\Wc;
use WPDesk\FCF\Free\Field\Type\TypeAbstract;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\FormattingWcOption;
use WPDesk\FCF\Free\Settings\Option\LabelOptionallyOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PlaceholderOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationWcOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
/**
* {@inheritdoc}
*/
class WcAddress2Type extends TypeAbstract {
const FIELD_TYPE = 'wc_address2';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'WooCommerce Default Field', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_reserved_field_names(): array {
return [
'billing_address_2',
'shipping_address_2',
];
}
/**
* {@inheritdoc}
*/
public function is_hidden(): bool {
return true;
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
PriorityOption::FIELD_NAME => new PriorityOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
RequiredOption::FIELD_NAME => new RequiredOption(),
LabelOptionallyOption::FIELD_NAME => new LabelOptionallyOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValidationWcOption::FIELD_NAME => new ValidationWcOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
PlaceholderOption::FIELD_NAME => new PlaceholderOption(),
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingWcOption::FIELD_NAME => new FormattingWcOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,99 @@
<?php
namespace WPDesk\FCF\Free\Field\Type\Wc;
use WPDesk\FCF\Free\Field\Type\TypeAbstract;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOnlyAddressOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PlaceholderOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationWcOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
/**
* {@inheritdoc}
*/
class WcContactType extends TypeAbstract {
const FIELD_TYPE = 'wc_contact';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'WooCommerce Default Field', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_reserved_field_names(): array {
return [
'billing_phone',
'billing_email',
];
}
/**
* {@inheritdoc}
*/
public function is_hidden(): bool {
return true;
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
PriorityOption::FIELD_NAME => new PriorityOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
RequiredOption::FIELD_NAME => new RequiredOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValidationWcOption::FIELD_NAME => new ValidationWcOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
PlaceholderOption::FIELD_NAME => new PlaceholderOption(),
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOnlyAddressOption::FIELD_NAME => new DisplayOnOnlyAddressOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace WPDesk\FCF\Free\Field\Type\Wc;
use WPDesk\FCF\Free\Field\Type\TypeAbstract;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\FormattingWcOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredWcHiddenOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationWcOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class WcCountryType extends TypeAbstract {
const FIELD_TYPE = 'wc_country';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'WooCommerce Default Field', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_reserved_field_names(): array {
return [
'billing_country',
'shipping_country',
];
}
/**
* {@inheritdoc}
*/
public function is_hidden(): bool {
return true;
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
PriorityOption::FIELD_NAME => new PriorityOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
RequiredWcHiddenOption::FIELD_NAME => new RequiredWcHiddenOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValidationWcOption::FIELD_NAME => new ValidationWcOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingWcOption::FIELD_NAME => new FormattingWcOption(),
],
];
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace WPDesk\FCF\Free\Field\Type\Wc;
use WPDesk\FCF\Free\Field\Type\TypeAbstract;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\FormattingWcOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PlaceholderOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationWcOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
/**
* {@inheritdoc}
*/
class WcDefaultType extends TypeAbstract {
const FIELD_TYPE = 'wc_text';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'WooCommerce Default Field', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_reserved_field_names(): array {
return [
'billing_first_name',
'billing_last_name',
'billing_company',
'billing_address_1',
'billing_city',
'shipping_first_name',
'shipping_last_name',
'shipping_company',
'shipping_address_1',
'shipping_city',
];
}
/**
* {@inheritdoc}
*/
public function is_hidden(): bool {
return true;
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
PriorityOption::FIELD_NAME => new PriorityOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
RequiredOption::FIELD_NAME => new RequiredOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValidationWcOption::FIELD_NAME => new ValidationWcOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
PlaceholderOption::FIELD_NAME => new PlaceholderOption(),
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingWcOption::FIELD_NAME => new FormattingWcOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace WPDesk\FCF\Free\Field\Type\Wc;
use WPDesk\FCF\Free\Field\Type\TypeAbstract;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnWithoutAddressOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\LogicAdvOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PlaceholderOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationWcOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
/**
* {@inheritdoc}
*/
class WcNotesType extends TypeAbstract {
const FIELD_TYPE = 'wc_notes';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'WooCommerce Default Field', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_reserved_field_names(): array {
return [
'order_comments',
];
}
/**
* {@inheritdoc}
*/
public function is_hidden(): bool {
return true;
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
PriorityOption::FIELD_NAME => new PriorityOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
RequiredOption::FIELD_NAME => new RequiredOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValidationWcOption::FIELD_NAME => new ValidationWcOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
PlaceholderOption::FIELD_NAME => new PlaceholderOption(),
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnWithoutAddressOption::FIELD_NAME => new DisplayOnWithoutAddressOption(),
],
LogicTab::TAB_NAME => [
LogicAdvOption::FIELD_NAME => new LogicAdvOption(),
],
];
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace WPDesk\FCF\Free\Field\Type\Wc;
use WPDesk\FCF\Free\Field\Type\TypeAbstract;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\FormattingWcOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PlaceholderOption;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredWcHiddenOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationPostcodeOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class WcPostcodeType extends TypeAbstract {
const FIELD_TYPE = 'wc_postcode';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'WooCommerce Default Field', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_reserved_field_names(): array {
return [
'billing_postcode',
'shipping_postcode',
];
}
/**
* {@inheritdoc}
*/
public function is_hidden(): bool {
return true;
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
PriorityOption::FIELD_NAME => new PriorityOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
RequiredWcHiddenOption::FIELD_NAME => new RequiredWcHiddenOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValidationPostcodeOption::FIELD_NAME => new ValidationPostcodeOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
PlaceholderOption::FIELD_NAME => new PlaceholderOption(),
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingWcOption::FIELD_NAME => new FormattingWcOption(),
],
];
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace WPDesk\FCF\Free\Field\Type\Wc;
use WPDesk\FCF\Free\Field\Type\TypeAbstract;
use WPDesk\FCF\Free\Settings\Option\CssOption;
use WPDesk\FCF\Free\Settings\Option\DisplayOnOption;
use WPDesk\FCF\Free\Settings\Option\EnabledOption;
use WPDesk\FCF\Free\Settings\Option\FormattingStateOption;
use WPDesk\FCF\Free\Settings\Option\FormattingWcOption;
use WPDesk\FCF\Free\Settings\Option\LabelOption;
use WPDesk\FCF\Free\Settings\Option\NameOption;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\PriorityOption;
use WPDesk\FCF\Free\Settings\Option\RequiredWcHiddenOption;
use WPDesk\FCF\Free\Settings\Option\ValidationInfoOption;
use WPDesk\FCF\Free\Settings\Option\ValidationWcOption;
use WPDesk\FCF\Free\Settings\Tab\AdvancedTab;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class WcStateType extends TypeAbstract {
const FIELD_TYPE = 'wc_state';
/**
* {@inheritdoc}
*/
public function get_field_type(): string {
return self::FIELD_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_field_type_label(): string {
return __( 'WooCommerce Default Field', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_reserved_field_names(): array {
return [
'billing_state',
'shipping_state',
];
}
/**
* {@inheritdoc}
*/
public function is_hidden(): bool {
return true;
}
/**
* {@inheritdoc}
*/
public function is_available(): bool {
return true;
}
/**
* Returns list of options for field settings.
*
* @return OptionInterface[] List of option fields.
*/
public function get_options_objects(): array {
return [
GeneralTab::TAB_NAME => [
PriorityOption::FIELD_NAME => new PriorityOption(),
EnabledOption::FIELD_NAME => new EnabledOption(),
RequiredWcHiddenOption::FIELD_NAME => new RequiredWcHiddenOption(),
LabelOption::FIELD_NAME => new LabelOption(),
NameOption::FIELD_NAME => new NameOption(),
],
AdvancedTab::TAB_NAME => [
ValidationWcOption::FIELD_NAME => new ValidationWcOption(),
ValidationInfoOption::FIELD_NAME => new ValidationInfoOption(),
],
AppearanceTab::TAB_NAME => [
CssOption::FIELD_NAME => new CssOption(),
],
DisplayTab::TAB_NAME => [
DisplayOnOption::FIELD_NAME => new DisplayOnOption(),
FormattingWcOption::FIELD_NAME => new FormattingWcOption(),
FormattingStateOption::FIELD_NAME => new FormattingStateOption(),
],
];
}
}

View File

@@ -0,0 +1,92 @@
<?php
namespace WPDesk\FCF\Free\Field;
use WPDesk\FCF\Free\Field\Type\CheckboxDefaultType;
use WPDesk\FCF\Free\Field\Type\CheckboxType;
use WPDesk\FCF\Free\Field\Type\ColorType;
use WPDesk\FCF\Free\Field\Type\DateType;
use WPDesk\FCF\Free\Field\Type\DefaultType;
use WPDesk\FCF\Free\Field\Type\EmailType;
use WPDesk\FCF\Free\Field\Type\FileType;
use WPDesk\FCF\Free\Field\Type\HeadingType;
use WPDesk\FCF\Free\Field\Type\HiddenType;
use WPDesk\FCF\Free\Field\Type\HtmlType;
use WPDesk\FCF\Free\Field\Type\ImageType;
use WPDesk\FCF\Free\Field\Type\MultiCheckboxType;
use WPDesk\FCF\Free\Field\Type\MultiSelectType;
use WPDesk\FCF\Free\Field\Type\NumberType;
use WPDesk\FCF\Free\Field\Type\ParagraphType;
use WPDesk\FCF\Free\Field\Type\PhoneType;
use WPDesk\FCF\Free\Field\Type\RadioColorsType;
use WPDesk\FCF\Free\Field\Type\RadioDefaultType;
use WPDesk\FCF\Free\Field\Type\RadioImagesType;
use WPDesk\FCF\Free\Field\Type\RadioType;
use WPDesk\FCF\Free\Field\Type\SelectType;
use WPDesk\FCF\Free\Field\Type\TextareaType;
use WPDesk\FCF\Free\Field\Type\TextType;
use WPDesk\FCF\Free\Field\Type\TimeType;
use WPDesk\FCF\Free\Field\Type\TypeIntegration;
use WPDesk\FCF\Free\Field\Type\UrlType;
use WPDesk\FCF\Free\Field\Type\Wc\WcAddress2Type;
use WPDesk\FCF\Free\Field\Type\Wc\WcContactType;
use WPDesk\FCF\Free\Field\Type\Wc\WcCountryType;
use WPDesk\FCF\Free\Field\Type\Wc\WcDefaultType;
use WPDesk\FCF\Free\Field\Type\Wc\WcNotesType;
use WPDesk\FCF\Free\Field\Type\Wc\WcPostcodeType;
use WPDesk\FCF\Free\Field\Type\Wc\WcStateType;
/**
* Supports management for field types.
*/
class Types {
const FIELD_GROUP_TEXT = 'text';
const FIELD_GROUP_OPTION = 'option';
const FIELD_GROUP_PICKER = 'picker';
const FIELD_GROUP_OTHER = 'other';
/**
* Initializes actions for class.
*
* @return void
*/
public function init() {
( new TypeIntegration( new TextType() ) )->hooks();
( new TypeIntegration( new TextareaType() ) )->hooks();
( new TypeIntegration( new NumberType() ) )->hooks();
( new TypeIntegration( new EmailType() ) )->hooks();
( new TypeIntegration( new PhoneType() ) )->hooks();
( new TypeIntegration( new UrlType() ) )->hooks();
( new TypeIntegration( new CheckboxType() ) )->hooks();
( new TypeIntegration( new MultiCheckboxType() ) )->hooks();
( new TypeIntegration( new SelectType() ) )->hooks();
( new TypeIntegration( new MultiSelectType() ) )->hooks();
( new TypeIntegration( new RadioType() ) )->hooks();
( new TypeIntegration( new RadioImagesType() ) )->hooks();
( new TypeIntegration( new RadioColorsType() ) )->hooks();
( new TypeIntegration( new ColorType() ) )->hooks();
( new TypeIntegration( new DateType() ) )->hooks();
( new TypeIntegration( new TimeType() ) )->hooks();
( new TypeIntegration( new FileType() ) )->hooks();
( new TypeIntegration( new HeadingType() ) )->hooks();
( new TypeIntegration( new ParagraphType() ) )->hooks();
( new TypeIntegration( new ImageType() ) )->hooks();
( new TypeIntegration( new HtmlType() ) )->hooks();
( new TypeIntegration( new HiddenType() ) )->hooks();
( new TypeIntegration( new DefaultType() ) )->hooks();
( new TypeIntegration( new CheckboxDefaultType() ) )->hooks();
( new TypeIntegration( new RadioDefaultType() ) )->hooks();
( new TypeIntegration( new WcDefaultType() ) )->hooks();
( new TypeIntegration( new WcContactType() ) )->hooks();
( new TypeIntegration( new WcAddress2Type() ) )->hooks();
( new TypeIntegration( new WcCountryType() ) )->hooks();
( new TypeIntegration( new WcPostcodeType() ) )->hooks();
( new TypeIntegration( new WcStateType() ) )->hooks();
( new TypeIntegration( new WcNotesType() ) )->hooks();
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace WPDesk\FCF\Free\Form;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use FcfVendor\WPDesk_Plugin_Info;
/**
* Initiates loading of assets required to handle the form.
*/
class Assets implements Hookable {
const ASSETS_HANDLE_PATTERN = 'fcf-assets-%s';
/**
* @var WPDesk_Plugin_Info
*/
private $plugin_info;
public function __construct( WPDesk_Plugin_Info $plugin_info ) {
$this->plugin_info = $plugin_info;
}
/**
* {@inheritdoc}
*/
public function hooks() {
add_action( 'wp_enqueue_scripts', [ $this, 'load_front_assets' ] );
add_action( 'admin_print_scripts-post.php', [ $this, 'load_admin_order_assets' ] );
add_action( 'admin_print_scripts-post-new.php', [ $this, 'load_admin_order_assets' ] );
add_action( 'admin_print_scripts-profile.php', [ $this, 'load_checkout_assets' ] );
}
/**
* @return void
*
* @internal
*/
public function load_front_assets() {
if ( ! is_checkout() && ! is_account_page() ) {
return;
}
$this->load_checkout_assets();
}
/**
* @return void
*
* @internal
*/
public function load_admin_order_assets() {
global $post_type;
if ( $post_type !== 'shop_order' ) {
return;
}
$this->load_checkout_assets();
}
/**
* @return void
*
* @internal
*/
public function load_checkout_assets() {
wp_enqueue_style(
sprintf( self::ASSETS_HANDLE_PATTERN, 'new-admin-css' ),
sprintf( '%1$s/assets/css/new-front.css', untrailingslashit( $this->plugin_info->get_plugin_url() ) ),
[],
$this->plugin_info->get_version()
);
wp_enqueue_script(
sprintf( self::ASSETS_HANDLE_PATTERN, 'new-admin-js' ),
sprintf( '%1$s/assets/js/new-front.js', untrailingslashit( $this->plugin_info->get_plugin_url() ) ),
[ 'jquery' ],
$this->plugin_info->get_version(),
true
);
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace WPDesk\FCF\Free\Integration;
/**
* .
*/
class Field implements FieldInterface {
/**
* Settings of field.
*
* @var array
*/
private $field_data;
/**
* Key of field group.
*
* @var string
*/
private $field_group;
/**
* Class constructor.
*
* @param array $field_data Settings of field.
* @param string $field_group Key of field group.
*/
public function __construct( array $field_data, string $field_group ) {
$this->field_data = $field_data;
$this->field_group = $field_group;
}
/**
* Returns key of field.
*
* @return string Field key.
*/
public function get_field_key(): string {
return $this->field_data['name'];
}
/**
* Returns type of field.
*
* @return string Field type, if known.
*/
public function get_field_type(): string {
return $this->field_data['type'] ?? '';
}
/**
* Returns label of field.
*
* @return string Field label.
*/
public function get_field_label(): string {
return $this->field_data['label'];
}
/**
* Returns status if field is custom.
*
* @return bool If field is custom?
*/
public function is_custom_field(): bool {
return ( isset( $this->field_data['custom_field'] ) && $this->field_data['custom_field'] );
}
/**
* Returns key of field group.
*
* @return string Group key.
*/
public function get_group_key(): string {
return $this->field_group;
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace WPDesk\FCF\Free\Integration;
/**
* .
*/
interface FieldInterface {
/**
* Returns key of field.
*
* @return string Field key.
*/
public function get_field_key(): string;
/**
* Returns label of field.
*
* @return string Field label.
*/
public function get_field_label(): string;
/**
* Returns type of field.
*
* @return string Field type.
*/
public function get_field_type(): string;
/**
* Returns status if field is custom.
*
* @return bool If field is custom?
*/
public function is_custom_field(): bool;
/**
* Returns key of field group.
*
* @return string Group key.
*/
public function get_group_key(): string;
}

View File

@@ -0,0 +1,47 @@
<?php
namespace WPDesk\FCF\Free\Integration;
/**
* .
*/
class Fields implements FieldsInterface {
/**
* List of field groups.
*
* @var array
*/
private $field_groups;
/**
* Class constructor.
*
* @param array $field_groups List of field groups.
*/
public function __construct( array $field_groups ) {
$this->field_groups = $field_groups;
}
/**
* Returns list of available fields.
*
* @param string $group_key Optionally key of field group.
*
* @return FieldInterface[] List of objects with field data.
*/
public function get_available_fields( string $group_key = '' ): array {
$items = [];
foreach ( $this->field_groups as $field_group => $fields ) {
if ( ( $group_key !== '' ) && ( $field_group !== $group_key ) ) {
continue;
}
foreach ( $fields as $field ) {
$items[] = new Field( $field, $field_group );
}
}
return $items;
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace WPDesk\FCF\Free\Integration;
/**
* .
*/
interface FieldsInterface {
/**
* Returns list of available fields.
*
* @param string $group_key Optionally key of field group.
*
* @return FieldInterface[] List of objects with field data.
*/
public function get_available_fields( string $group_key = '' ): array;
}

View File

@@ -0,0 +1,126 @@
<?php
namespace WPDesk\FCF\Free\Integration;
/**
* .
*/
class Integrator implements IntegratorInterface {
/**
* Major version of integration script.
*
* @var int
*/
const INTEGRATOR_VERSION = 1000;
/**
* Version of plugin.
*
* @var string
*/
private $version_plugin = FLEXIBLE_CHECKOUT_FIELDS_VERSION;
/**
* Version of plugin core (for compatibility with dependent plugins).
*
* @var string
*/
private $version_dev = FLEXIBLE_CHECKOUT_FIELDS_VERSION_DEV;
/**
* List of field sections.
*
* @var array
*/
private $field_sections;
/**
* List of field groups.
*
* @var array
*/
private $field_groups;
/**
* Class constructor.
*
* @param array $field_sections List of field sections.
* @param array $field_groups List of field groups.
*/
public function __construct( array $field_sections, array $field_groups ) {
$this->field_sections = $field_sections;
$this->field_groups = $field_groups;
}
/**
* Returns version of integration script.
*
* @return string Integration script version.
* @example Use method to integration with plugin.
*/
public function get_version(): string {
$version_major = explode( '.', $this->version_plugin )[0];
$version_minor = explode( '.', $this->version_plugin )[1];
$version_patch = explode( '.', $this->version_plugin )[2];
return sprintf(
'%d.%d.%d',
self::INTEGRATOR_VERSION,
( ( $version_major * 1000 ) + $version_minor ),
$version_patch
);
}
/**
* Returns version of plugin core (do not use this method for plugin integration).
*
* @return string Plugin core version.
* @example Use method to create plugin dependent on this plugin.
*/
public function get_version_dev(): string {
$version_dev_major = explode( '.', $this->version_dev )[0];
$version_dev_minor = explode( '.', $this->version_dev )[1];
$version_major = explode( '.', $this->version_plugin )[0];
$version_minor = explode( '.', $this->version_plugin )[1];
return sprintf(
'%d.%d.%d',
$version_dev_major,
$version_dev_minor,
( ( $version_major * 1000 ) + $version_minor )
);
}
/**
* Returns list of available field sections.
*
* @return SectionInterface[] List of objects with section data.
*/
public function get_available_field_sections(): array {
return ( new Sections( $this->field_sections ) )->get_available_field_sections();
}
/**
* Returns list of available fields.
*
* @param string $group_key Optionally key of field group.
*
* @return FieldInterface[] List of objects with field data.
*/
public function get_available_fields( string $group_key = '' ): array {
return ( new Fields( $this->field_groups ) )->get_available_fields( $group_key );
}
/**
* Returns value of order field.
*
* @param string $field_key Field key.
* @param int $order_id ID of WC_Order.
*
* @return mixed Value of field, or null if not exists.
*/
public function get_field_value( string $field_key, int $order_id ) {
return ( new Value() )->get_field_value( $field_key, $order_id );
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace WPDesk\FCF\Free\Integration;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use FcfVendor\WPDesk\PluginBuilder\Plugin\HookablePluginDependant;
use FcfVendor\WPDesk\PluginBuilder\Plugin\PluginAccess;
/**
* .
*/
class IntegratorIntegration implements Hookable, HookablePluginDependant {
use PluginAccess;
/**
* Instance of old version main class of plugin.
*
* @var \Flexible_Checkout_Fields_Plugin
*/
private $plugin_old;
/**
* Class constructor.
*
* @param \Flexible_Checkout_Fields_Plugin $plugin_old Main plugin.
*/
public function __construct( \Flexible_Checkout_Fields_Plugin $plugin_old ) {
$this->plugin_old = $plugin_old;
}
/**
* {@inheritdoc}
*/
public function hooks() {
add_action( 'init', [ $this, 'set_hook_for_integration' ], 0 );
}
/**
* Initializes integration for 3rd party plugins.
*
* @internal
*/
public function set_hook_for_integration() {
$sections = $this->plugin_old->sections ?? [];
$settings = $this->plugin_old->get_settings();
do_action(
'flexible_checkout_fields/init',
( new Integrator( $sections, $settings ) )
);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace WPDesk\FCF\Free\Integration;
/**
* .
*/
interface IntegratorInterface extends SectionsInterface, FieldsInterface, ValueInterface {
/**
* Returns version of integration script.
*
* @return string Integration script version.
* @example Use method to integration with plugin.
*/
public function get_version(): string;
/**
* Returns version of plugin core (do not use this method for plugin integration).
*
* @return string Plugin core version.
* @example Use method to create plugin dependent on this plugin.
*/
public function get_version_dev(): string;
}

View File

@@ -0,0 +1,43 @@
<?php
namespace WPDesk\FCF\Free\Integration;
/**
* .
*/
class Section implements SectionInterface {
/**
* Settings of field section.
*
* @var array
*/
private $section_data;
/**
* Class constructor.
*
* @param array $section_data Settings of field section.
*/
public function __construct( array $section_data ) {
$this->section_data = $section_data;
}
/**
* Returns key of field section.
*
* @return string Section key.
*/
public function get_section_key(): string {
return $this->section_data['section'];
}
/**
* Returns label of field section.
*
* @return string Section label.
*/
public function get_section_label(): string {
return $this->section_data['tab_title'];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace WPDesk\FCF\Free\Integration;
/**
* .
*/
interface SectionInterface {
/**
* Returns key of field section.
*
* @return string Section key.
*/
public function get_section_key(): string;
/**
* Returns label of field section.
*
* @return string Section label.
*/
public function get_section_label(): string;
}

View File

@@ -0,0 +1,39 @@
<?php
namespace WPDesk\FCF\Free\Integration;
/**
* .
*/
class Sections implements SectionsInterface {
/**
* List of field sections.
*
* @var array
*/
private $field_sections;
/**
* Class constructor.
*
* @param array $field_sections List of field sections.
*/
public function __construct( array $field_sections ) {
$this->field_sections = $field_sections;
}
/**
* Returns list of available field sections.
*
* @return SectionInterface[] List of objects with section data.
*/
public function get_available_field_sections(): array {
$items = [];
foreach ( $this->field_sections as $section ) {
$items[] = new Section( $section );
}
return $items;
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace WPDesk\FCF\Free\Integration;
/**
* .
*/
interface SectionsInterface {
/**
* Returns list of field sections.
*
* @return array Field sections.
*/
public function get_available_field_sections(): array;
}

View File

@@ -0,0 +1,32 @@
<?php
namespace WPDesk\FCF\Free\Integration;
/**
* .
*/
class Value implements ValueInterface {
/**
* Returns value of order field.
*
* @param string $field_key Field key.
* @param int $order_id ID of WC_Order.
*
* @return mixed Value of field, or null if not exists.
*/
public function get_field_value( string $field_key, int $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order ) {
return null;
}
$value = wpdesk_get_order_meta( $order, '_' . $field_key, true );
$json = json_decode( $value, true );
if ( $json ) {
return $json;
} else {
return $value;
}
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace WPDesk\FCF\Free\Integration;
/**
* .
*/
interface ValueInterface {
/**
* Returns value of order field.
*
* @param string $field_key Field key.
* @param int $order_id ID of WC_Order.
*
* @return mixed Value of field, or null if not exists.
*/
public function get_field_value( string $field_key, int $order_id );
}

View File

@@ -0,0 +1,102 @@
<?php
namespace WPDesk\FCF\Free\Notice;
use FcfVendor\WPDesk\PluginBuilder\Plugin\AbstractPlugin;
/**
* Notice about new plugin - Flexible Wishlist.
*/
class FlexibleWishlistReview implements Notice {
const ACTIVATION_OPTION_NAME = 'plugin_activation_%s';
const NOTICE_OPTION_NAME = 'notice_flexible_wishlist_%s';
const NOTICE_NAME = 'notice_flexible_wishlist';
/**
* @var AbstractPlugin
*/
private $plugin;
public function __construct( AbstractPlugin $plugin ) {
$this->plugin = $plugin;
}
/**
* {@inheritdoc}
*/
public function get_notice_name(): string {
return self::NOTICE_NAME;
}
/**
* {@inheritdoc}
*/
public function is_active(): bool {
if ( basename( $_SERVER['PHP_SELF'] ) !== 'index.php' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
return false;
}
$plugins = [
$this->plugin->get_plugin_file_path(),
'flexible-product-fields/flexible-product-fields.php',
];
foreach ( $plugins as $plugin_filename ) {
$option_notice = sprintf( self::NOTICE_OPTION_NAME, $plugin_filename );
$notice_date = strtotime( get_option( $option_notice, false ) );
$min_date = strtotime( current_time( 'mysql' ) );
if ( ( $notice_date !== false ) && ( $notice_date > $min_date ) ) {
return false;
}
}
$option_activation = sprintf( self::ACTIVATION_OPTION_NAME, $this->plugin->get_plugin_file_path() );
$activation_date = strtotime( get_option( $option_activation, current_time( 'mysql' ) ) );
$min_date = strtotime( current_time( 'mysql' ) . ' -1 day' );
if ( $activation_date > $min_date ) {
return false;
}
$installed_plugins = get_plugins();
return ! isset( $installed_plugins['flexible-wishlist/flexible-wishlist.php'] );
}
/**
* {@inheritdoc}
*/
public function get_template_path(): string {
return 'notices/flexible-wishlist';
}
/**
* {@inheritdoc}
*/
public function get_vars_for_view(): array {
return [
'image_url' => untrailingslashit( $this->plugin->get_plugin_assets_url() ) . '/img/flexible-wishlist.png',
'install_url' => wp_nonce_url(
add_query_arg(
[
'action' => 'install-plugin',
'plugin' => 'flexible-wishlist',
],
admin_url( 'update.php' )
),
'install-plugin_flexible-wishlist'
),
];
}
/**
* {@inheritdoc}
*/
public function set_notice_as_hidden( bool $is_permanently ) {
$option_name = sprintf( self::NOTICE_OPTION_NAME, $this->plugin->get_plugin_file_path() );
$notice_time = strtotime( current_time( 'mysql' ) . ( ( $is_permanently ) ? ' +10 years' : ' +1 month' ) );
$notice_date = gmdate( 'Y-m-d H:i:s', $notice_time );
update_option( $option_name, $notice_date, true );
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace WPDesk\FCF\Free\Notice;
/**
* Interface for class that supports notice displayed in admin panel.
*/
interface Notice {
/**
* Returns unique key of notice.
*
* @return string
*/
public function get_notice_name(): string;
/**
* Returns status if notice is active.
*
* @return bool Do show notice?
*/
public function is_active(): bool;
/**
* Returns server path for view template.
*
* @return string Server path relative to plugin /templates directory.
*/
public function get_template_path(): string;
/**
* Returns variables with values using in view template.
*
* @return string[] Args extract in view template.
*/
public function get_vars_for_view(): array;
/**
* Disables visible notice.
*
* @param bool $is_permanently .
*
* @return void
* @internal
*/
public function set_notice_as_hidden( bool $is_permanently );
}

View File

@@ -0,0 +1,116 @@
<?php
namespace WPDesk\FCF\Free\Notice;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use FcfVendor\WPDesk\PluginBuilder\Plugin\HookablePluginDependant;
use FcfVendor\WPDesk\PluginBuilder\Plugin\PluginAccess;
use FcfVendor\WPDesk\View\Renderer\SimplePhpRenderer;
use FcfVendor\WPDesk\View\Resolver\DirResolver;
/**
* Supports ability to display notice and its management.
*/
class NoticeIntegration implements Hookable, HookablePluginDependant {
use PluginAccess;
/**
* @var Notice
*/
private $notice;
/**
* @var SimplePhpRenderer
*/
private $renderer;
/**
* Class constructor.
*/
public function __construct( Notice $notice ) {
$this->notice = $notice;
$this->renderer = new SimplePhpRenderer( new DirResolver( dirname( dirname( __DIR__ ) ) . '/templates' ) );
}
/**
* {@inheritdoc}
*/
public function hooks() {
add_filter( 'admin_init', [ $this, 'init_admin_notice' ] );
add_action( 'wp_ajax_fcf_close_' . $this->notice->get_notice_name(), [ $this, 'hide_admin_notice' ] );
}
/**
* @return void
* @internal
*/
public function init_admin_notice() {
if ( ! $this->notice->is_active() ) {
return;
}
add_filter( 'admin_notices', [ $this, 'load_admin_notice_template' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'load_styles_for_notice' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'load_scripts_for_notice' ] );
}
/**
* @return void
* @internal
*/
public function load_admin_notice_template() {
echo $this->renderer->render( // phpcs:ignore
$this->notice->get_template_path(),
array_merge( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[
'ajax_url' => esc_attr( admin_url( 'admin-ajax.php' ) ),
'ajax_action' => esc_attr( 'fcf_close_' . $this->notice->get_notice_name() ),
],
$this->notice->get_vars_for_view()
)
);
}
/**
* @return void
* @internal
*/
public function load_styles_for_notice() {
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.css' : '.min.css';
wp_register_style(
'fcf-notice',
trailingslashit( $this->plugin->get_plugin_assets_url() ) . 'css/admin-notice' . $suffix,
[],
( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? time() : $this->plugin->get_script_version()
);
wp_enqueue_style( 'fcf-notice' );
}
/**
* @return void
* @internal
*/
public function load_scripts_for_notice() {
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.js' : '.min.js';
wp_register_script(
'fcf-notice',
trailingslashit( $this->plugin->get_plugin_assets_url() ) . 'js/admin-notice' . $suffix,
[],
( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? time() : $this->plugin->get_script_version(),
true
);
wp_enqueue_script( 'fcf-notice' );
}
/**
* @return void
* @internal
*/
public function hide_admin_notice() {
$is_permanently = ( isset( $_POST['is_permanently'] ) && $_POST['is_permanently'] ); // phpcs:ignore
$this->notice->set_notice_as_hidden( $is_permanently );
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace WPDesk\FCF\Free\Notice;
use FcfVendor\WPDesk\PluginBuilder\Plugin\AbstractPlugin;
/**
* Notice about review.
*/
class ReviewNotice implements Notice {
const ACTIVATION_OPTION_NAME = 'plugin_activation_%s';
const NOTICE_OPTION_NAME = 'notice_review_%s';
const NOTICE_NAME = 'notice_review';
/**
* @var AbstractPlugin
*/
private $plugin;
public function __construct( AbstractPlugin $plugin ) {
$this->plugin = $plugin;
}
/**
* {@inheritdoc}
*/
public function get_notice_name(): string {
return self::NOTICE_NAME;
}
/**
* {@inheritdoc}
*/
public function is_active(): bool {
$option_notice = sprintf( self::NOTICE_OPTION_NAME, $this->plugin->get_plugin_file_path() );
$notice_date = strtotime( get_option( $option_notice, false ) );
$min_date = strtotime( current_time( 'mysql' ) );
if ( ( basename( $_SERVER['PHP_SELF'] ) !== 'index.php' ) // phpcs:ignore
|| ( ( $notice_date !== false ) && ( $notice_date > $min_date ) ) ) {
return false;
}
$option_activation = sprintf( self::ACTIVATION_OPTION_NAME, $this->plugin->get_plugin_file_path() );
$activation_date = strtotime( get_option( $option_activation, current_time( 'mysql' ) ) );
$min_date = strtotime( current_time( 'mysql' ) . ' -7 days' );
return ( $activation_date <= $min_date );
}
/**
* {@inheritdoc}
*/
public function get_template_path(): string {
return 'notices/review';
}
/**
* {@inheritdoc}
*/
public function get_vars_for_view(): array {
return [];
}
/**
* {@inheritdoc}
*/
public function set_notice_as_hidden( bool $is_permanently ) {
$option_name = sprintf( self::NOTICE_OPTION_NAME, $this->plugin->get_plugin_file_path() );
$notice_time = strtotime( current_time( 'mysql' ) . ( ( $is_permanently ) ? ' +10 years' : ' +1 month' ) );
$notice_date = gmdate( 'Y-m-d H:i:s', $notice_time );
update_option( $option_name, $notice_date, true );
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace WPDesk\FCF\Free;
use FcfVendor\WPDesk\PluginBuilder\Plugin\AbstractPlugin;
use FcfVendor\WPDesk\PluginBuilder\Plugin\HookableCollection;
use FcfVendor\WPDesk\PluginBuilder\Plugin\HookableParent;
use FcfVendor\WPDesk_Plugin_Info;
use WPDesk\FCF\Free\Field;
use WPDesk\FCF\Free\Integration;
use WPDesk\FCF\Free\Notice;
use WPDesk\FCF\Free\Service;
use WPDesk\FCF\Free\Settings;
use WPDesk\FCF\Free\Tracker;
/**
* Main plugin class. The most important flow decisions are made here.
*/
class Plugin extends AbstractPlugin implements HookableCollection {
use HookableParent;
/**
* Scripts version.
*
* @var string
*/
private $script_version = '1';
/**
* Instance of old version main class of plugin.
*
* @var \Flexible_Checkout_Fields_Plugin
*/
private $plugin_old;
/**
* @var Service\TemplateLoader
*/
private $template_loader;
/**
* Plugin constructor.
*
* @param WPDesk_Plugin_Info $plugin_info Plugin info.
* @param \Flexible_Checkout_Fields_Plugin $plugin_old Main plugin.
*/
public function __construct( WPDesk_Plugin_Info $plugin_info, \Flexible_Checkout_Fields_Plugin $plugin_old ) {
parent::__construct( $plugin_info );
$this->plugin_url = $this->plugin_info->get_plugin_url();
$this->plugin_namespace = $this->plugin_info->get_text_domain();
$this->script_version = $plugin_info->get_version();
$this->plugin_old = $plugin_old;
$this->template_loader = new Service\TemplateLoader( $plugin_info->get_plugin_dir(), 'flexible-checkout-fields' );
}
/**
* Initializes plugin external state.
* The plugin internal state is initialized in the constructor and the plugin should be internally consistent after
* creation. The external state includes hooks execution, communication with other plugins, integration with WC
* etc.
*
* @return void
*/
public function init() {
( new \FcfVendor\WPDesk\Dashboard\DashboardWidget() )->hooks();
$this->add_hookable( new Service\ShortLinksGenerator() );
$this->add_hookable( new Notice\NoticeIntegration( new Notice\ReviewNotice( $this ) ) );
$this->add_hookable( new Notice\NoticeIntegration( new Notice\FlexibleWishlistReview( $this ) ) );
$this->add_hookable( new Settings\Page() );
$this->add_hookable( new Form\Assets( $this->plugin_info ) );
$this->add_hookable( new Field\FieldTranslator() );
$this->add_hookable( new Field\FieldTemplateLoader( $this->template_loader ) );
$this->add_hookable( new Integration\IntegratorIntegration( $this->plugin_old ) );
$this->add_hookable( new Tracker\DeactivationTracker( $this->plugin_info ) );
$this->add_hookable( new Validator\FieldValidator() );
$this->add_hookable( new Validator\ValidationClassGenerator() );
( new Field\Types() )->init();
( new Settings\Forms() )->init();
( new Settings\Routes() )->init();
( new Settings\Tabs() )->init();
$this->add_hookable( new Settings\MigrationsManager( $this->plugin_info->get_version() ) );
}
/**
* {@inheritdoc}
*/
public function hooks() {
$this->hooks_on_hookable_objects();
}
/**
* Get script version.
*
* @return string;
*/
public function get_script_version() {
return $this->script_version;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace WPDesk\FCF\Free\Service;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use FcfVendor\WPDesk\PluginBuilder\Plugin\HookablePluginDependant;
use FcfVendor\WPDesk\PluginBuilder\Plugin\PluginAccess;
/**
* Creates helpers for short URLs.
*/
class ShortLinksGenerator implements Hookable, HookablePluginDependant {
use PluginAccess;
const SHORTENER_DOMAIN = 'https://wpde.sk/';
/**
* {@inheritdoc}
*/
public function hooks() {
add_filter( 'flexible_checkout_fields/short_url', [ $this, 'generate_short_url' ], 10, 2 );
}
/**
* Generates short URL for link.
*
* @param string $default_value Default value for filter.
* @param string $short_path Path for short URL.
*
* @return string Short URL.
* @internal
*/
public function generate_short_url( string $default_value, string $short_path ): string {
if ( ! preg_match( '/^[a-z-]+$/i', $short_path ) ) {
return '#';
}
$locale = get_user_locale();
$short_url = self::SHORTENER_DOMAIN . $short_path;
switch ( $locale ) {
case 'pl_PL':
$short_url .= '-pl';
break;
}
return $short_url;
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace WPDesk\FCF\Free\Service;
use FcfVendor\WPDesk\View\Renderer\Renderer;
use FcfVendor\WPDesk\View\Renderer\SimplePhpRenderer;
use FcfVendor\WPDesk\View\Resolver\ChainResolver;
use FcfVendor\WPDesk\View\Resolver\DirResolver;
use FcfVendor\WPDesk\View\Resolver\Exception\CanNotResolve;
use FcfVendor\WPDesk\View\Resolver\WPThemeResolver;
use WPDesk\FCF\Free\Exception\TemplateLoadingFailed;
/**
* .
*/
class TemplateLoader {
/**
* @var string
*/
private $plugin_path;
/**
* @var string
*/
private $theme_templates_path;
/**
* @var SimplePhpRenderer|null
*/
private $renderer = null;
public function __construct( string $plugin_path, string $theme_templates_path ) {
$this->plugin_path = $plugin_path;
$this->theme_templates_path = $theme_templates_path;
}
private function get_renderer(): Renderer {
$resolver = new ChainResolver();
$resolver->appendResolver( new WPThemeResolver( $this->theme_templates_path ) );
foreach ( $this->get_template_directories() as $directory_path ) {
$resolver->appendResolver( new DirResolver( $directory_path ) );
}
return new SimplePhpRenderer( $resolver );
}
private function get_template_directories(): array {
$paths = [
untrailingslashit( $this->plugin_path ) . '/templates',
];
return apply_filters( 'flexible_checkout_fields/templates_paths', $paths );
}
/**
* @throws TemplateLoadingFailed
*/
public function load_template( string $template_path, array $params ): string {
$this->renderer = $this->renderer ?: $this->get_renderer();
try {
return $this->renderer->render( $template_path, $params );
} catch ( CanNotResolve $e ) {
throw new TemplateLoadingFailed( $e->getMessage() );
}
}
}

View File

@@ -0,0 +1,159 @@
<?php
namespace WPDesk\FCF\Free\Settings\Form;
use WPDesk\FCF\Free\Field\FieldData;
use WPDesk\FCF\Free\Settings\Option\ExternalFieldOption;
/**
* {@inheritdoc}
*/
class EditFieldsForm extends FormAbstract implements FormInterface {
const FORM_TYPE = 'fields';
const SETTINGS_OPTION_NAME = 'inspire_checkout_fields_settings';
/**
* {@inheritdoc}
*/
public function get_form_type(): string {
return self::FORM_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_form_data( array $form_data, string $form_key = '' ): array {
$settings = get_option( self::SETTINGS_OPTION_NAME, [] );
$section_fields = $this->combine_fields_settings(
$this->get_section_form_data( $form_key ),
( $settings[ $form_key ] ?? [] ) ?: []
);
if ( ! $section_fields ) {
return $form_data;
}
foreach ( $section_fields as $field_name => $field_data ) {
$field_data['name'] = $field_name;
$new_field_data = FieldData::get_field_data( $field_data );
if ( ! $new_field_data ) {
continue;
}
$form_data[ $field_name ] = $new_field_data;
}
uasort(
$form_data,
function ( $a, $b ) {
if ( ( $a['priority'] ?? 0 ) === 0 ) {
return 1;
} elseif ( ( $b['priority'] ?? 0 ) === 0 ) {
return -1;
}
return ( $a['priority'] < $b['priority'] ) ? -1 : 1;
}
);
return $form_data;
}
/**
* Returns default settings for form of checkout section.
*
* @param string $section_key Key of section.
*
* @return array Settings of form.
*/
private function get_section_form_data( string $section_key ): array {
$countries = new \WC_Countries();
$sections = [
'billing' => $countries->get_address_fields( $countries->get_base_country(), 'billing_' ),
'shipping' => $countries->get_address_fields( $countries->get_base_country(), 'shipping_' ),
'order' => [
'order_comments' => [
'type' => 'textarea',
'class' => [ 'notes' ],
'label' => __( 'Order Notes', 'flexible-checkout-fields' ),
'placeholder' => __( 'Notes about your order, e.g. special notes for delivery.', 'flexible-checkout-fields' ),
],
],
];
$sections += $this->get_custom_sections();
return $sections[ $section_key ] ?? [];
}
/**
* Returns list of custom checkout sections.
*
* @return array List of sections.
*/
private function get_custom_sections(): array {
$custom_sections = apply_filters( 'flexible_checkout_fields_all_sections', [] );
$sections = [];
foreach ( $custom_sections as $custom_section ) {
$sections[ $custom_section['section'] ] = [];
}
return $sections;
}
/**
* Combines default field settings with settings saved by plugin.
*
* @param array $checkout_fields Default field settings.
* @param array $settings_fields Field settings saved by plugin.
*
* @return array Final field settings.
*/
private function combine_fields_settings( array $checkout_fields, array $settings_fields ): array {
$fields = $checkout_fields;
foreach ( $fields as $field_name => $field ) {
if ( ! isset( $settings_fields[ $field_name ] ) ) {
$fields[ $field_name ][ ExternalFieldOption::FIELD_NAME ] = 1;
}
}
foreach ( $settings_fields as $field_name => $settings_field ) {
$fields[ $field_name ] = array_merge( $fields[ $field_name ] ?? [], $settings_field );
}
return $fields;
}
/**
* Saves settings for form.
*
* @param array $params Params for endpoint.
*
* @return bool Status of process.
* @throws \Exception .
*/
public function save_form_data( array $params ): bool {
$posted_fields = [];
foreach ( $params['form_fields'] as $field ) {
$posted_fields[ $field['name'] ] = $field;
}
$section_fields = [];
foreach ( $params['form_fields'] as $field_data ) {
$new_field_data = FieldData::get_field_data( $posted_fields[ $field_data['name'] ], false );
if ( ! $new_field_data ) {
continue;
}
$section_fields[ $field_data['name'] ] = $new_field_data;
}
$settings = get_option( self::SETTINGS_OPTION_NAME, [] ) ?: [];
if ( ! $section_fields ) {
if ( isset( $settings[ $params['form_section'] ] ) ) {
unset( $settings[ $params['form_section'] ] );
}
} else {
$settings[ $params['form_section'] ] = $section_fields;
}
update_option( self::SETTINGS_OPTION_NAME, $settings );
return true;
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace WPDesk\FCF\Free\Settings\Form;
/**
* {@inheritdoc}
*/
abstract class FormAbstract implements FormInterface {
}

View File

@@ -0,0 +1,69 @@
<?php
namespace WPDesk\FCF\Free\Settings\Form;
/**
* Initializes integration for form.
*/
class FormIntegration {
/**
* Class object for field type.
*
* @var FormInterface
*/
private $form_object;
/**
* Class constructor.
*
* @param FormInterface $form_object Class object of field type.
*/
public function __construct( FormInterface $form_object ) {
$this->form_object = $form_object;
}
/**
* {@inheritdoc}
*/
public function hooks() {
add_filter(
'flexible_checkout_fields/form_data_' . $this->form_object->get_form_type(),
[ $this, 'get_form_data' ],
10,
2
);
add_filter(
'flexible_checkout_fields/form_fields_' . $this->form_object->get_form_type(),
[ $this, 'get_form_fields' ],
10,
2
);
}
/**
* Returns updated settings for form.
*
* @param array $form_data Default settings of form.
* @param string $form_key Key of form.
*
* @return array Settings of form.
* @internal
*/
public function get_form_data( array $form_data, string $form_key = '' ): array {
return $this->form_object->get_form_data( $form_data, $form_key );
}
/**
* Returns fields of settings for form.
*
* @param array $form_fields Default fields of form.
* @param string $form_key Key of form.
*
* @return array Fields of form.
* @internal
*/
public function get_form_fields( array $form_fields, string $form_key = '' ): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
return $this->form_object->get_options_list();
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace WPDesk\FCF\Free\Settings\Form;
/**
* Interface for form settings.
*/
interface FormInterface {
/**
* Returns type of form.
*
* @return string Type of form.
*/
public function get_form_type(): string;
/**
* Returns basic settings for form.
*
* @param array $form_data Default settings of form.
* @param string $form_key Key of form.
*
* @return array Settings of form.
*/
public function get_form_data( array $form_data, string $form_key = '' ): array;
/**
* Saves settings for form.
*
* @param array $params Params for endpoint.
*
* @return bool Status of process.
*/
public function save_form_data( array $params ): bool;
}

View File

@@ -0,0 +1,84 @@
<?php
namespace WPDesk\FCF\Free\Settings\Form;
use WPDesk\FCF\Free\Settings\Option\OptionIntegration;
use WPDesk\FCF\Free\Settings\Option\OptionInterface;
use WPDesk\FCF\Free\Settings\Option\SettingJqueryOption;
use WPDesk\FCF\Free\Settings\Option\SettingSectionsAdvOption;
/**
* {@inheritdoc}
*/
class SettingsPageForm extends FormAbstract implements FormInterface {
const FORM_TYPE = 'settings';
/**
* {@inheritdoc}
*/
public function get_form_type(): string {
return self::FORM_TYPE;
}
/**
* {@inheritdoc}
*/
public function get_form_data( array $form_data, string $form_key = '' ): array {
$section_fields = [];
$options = ( new SettingJqueryOption() )->get_children();
foreach ( $options as $option ) {
$option_status = get_option( $option->get_option_name(), 0 );
$section_fields[ $option->get_option_name() ] = ( $option_status ) ? '1' : '0';
}
$option_objects = $this->get_options_list();
foreach ( $option_objects as $field_option ) {
$form_data = $field_option['update_field_callback'](
$form_data,
$section_fields
);
}
return $form_data;
}
/**
* Returns list of option objects.
*
* @return OptionInterface[] List of options.
*/
public function get_options_list(): array {
return [
( new OptionIntegration( new SettingJqueryOption() ) )->get_field_settings(),
( new OptionIntegration( new SettingSectionsAdvOption() ) )->get_field_settings(),
];
}
/**
* Saves settings for form.
*
* @param array $params Params for endpoint.
*
* @return bool Status of process.
* @throws \Exception .
*/
public function save_form_data( array $params ): bool {
$settings_options = [];
$option_objects = $this->get_options_list();
foreach ( $option_objects as $field_option ) {
$settings_options = $field_option['save_field_callback'](
$settings_options,
$params['form_fields']
);
}
foreach ( $settings_options as $option => $option_status ) {
update_option( $option, ( $option_status ) ? '1' : '0', true );
}
return true;
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace WPDesk\FCF\Free\Settings;
use WPDesk\FCF\Free\Settings\Form\EditFieldsForm;
use WPDesk\FCF\Free\Settings\Form\FormIntegration;
use WPDesk\FCF\Free\Settings\Form\SettingsPageForm;
/**
* Supports management for forms.
*/
class Forms {
/**
* Initializes actions for class.
*
* @return void
*/
public function init() {
( new FormIntegration( new EditFieldsForm() ) )->hooks();
( new FormIntegration( new SettingsPageForm() ) )->hooks();
}
}

View File

@@ -0,0 +1,101 @@
<?php
namespace WPDesk\FCF\Free\Settings;
/**
* Supports items for menu plugin settings page.
*/
class Menu {
const OPTION_NAME_ENABLED = 'inspire_checkout_fields_%s';
const MENU_TAB_SETTINGS = 'settings';
const MENU_TAB_SECTIONS = 'sections';
/**
* List of default checkout sections.
*
* @var array
*/
private static $default_field_sections = [
'billing',
'shipping',
'order',
];
/**
* Returns list of items for menu with tabs.
*
* @return array Menu items.
*/
public function get_menu_tabs(): array {
$current_tab = $_GET['tab'] ?? self::MENU_TAB_SECTIONS; // phpcs:ignore
$page_tabs = [
self::MENU_TAB_SETTINGS => __( 'Settings', 'flexible-checkout-fields' ),
self::MENU_TAB_SECTIONS => __( 'Checkout Sections', 'flexible-checkout-fields' ),
];
$values = [];
foreach ( $page_tabs as $tab_id => $tab_name ) {
$values[] = [
'id' => $tab_id,
'label' => $tab_name,
'url' => admin_url(
sprintf(
'admin.php?page=%s&tab=%s',
Page::SETTINGS_PAGE,
$tab_id
)
),
'is_active' => ( $tab_id === $current_tab ),
];
}
return $values;
}
/**
* Returns list of items for menu with sections.
*
* @return array Menu items.
*/
public function get_menu_sections(): array {
$current_tab = $_GET['tab'] ?? self::MENU_TAB_SECTIONS; // phpcs:ignore
if ( $current_tab !== self::MENU_TAB_SECTIONS ) {
return [];
}
$current_section = $_GET['section'] ?? 'billing'; // phpcs:ignore
$page_sections = [
'billing' => __( 'Billing', 'flexible-checkout-fields' ),
'shipping' => __( 'Shipping', 'flexible-checkout-fields' ),
'order' => __( 'Order', 'flexible-checkout-fields' ),
];
$sections = apply_filters( 'flexible_checkout_fields_all_sections', [] );
foreach ( $sections as $section ) {
$page_sections[ $section['section'] ] = $section['tab_title'];
}
$values = [];
foreach ( $page_sections as $section_id => $section_name ) {
if ( ! in_array( $section_id, self::$default_field_sections, true )
&& ( get_option( sprintf( self::OPTION_NAME_ENABLED, $section_id ) ) !== '1' ) ) {
continue;
}
$values[] = [
'id' => $section_id,
'label' => $section_name,
'url' => admin_url(
sprintf(
'admin.php?page=%s&tab=sections&section=%s',
Page::SETTINGS_PAGE,
$section_id
)
),
'is_active' => ( $section_id === $current_section ),
'has_section_form' => ( ! in_array( $section_id, self::$default_field_sections, true ) ),
];
}
return $values;
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace WPDesk\FCF\Free\Settings\Migrations;
interface Migration {
/**
* @return string
*/
public function get_version(): string;
/**
* Performs migration operations.
*
* @return void
*/
public function up();
/**
* Rolls back migration operations.
*
* @return void
*/
public function down();
}

View File

@@ -0,0 +1,176 @@
<?php
namespace WPDesk\FCF\Free\Settings\Migrations;
use WPDesk\FCF\Free\Field\Type\FileType;
use WPDesk\FCF\Free\Field\Type\MultiSelectType;
use WPDesk\FCF\Free\Field\Type\RadioType;
use WPDesk\FCF\Free\Field\Type\SelectType;
use WPDesk\FCF\Free\Settings\Form\EditFieldsForm;
/**
* {@inheritdoc}
*/
class Migration320 implements Migration {
/**
* {@inheritdoc}
*/
public function get_version(): string {
return '3.2.0';
}
/**
* {@inheritdoc}
*/
public function up() {
$plugin_settings = get_option( EditFieldsForm::SETTINGS_OPTION_NAME, [] );
foreach ( $plugin_settings as $section_id => $section_fields ) {
foreach ( $section_fields as $field_id => $field_data ) {
switch ( $field_data['type'] ?? '' ) {
case RadioType::FIELD_TYPE:
case SelectType::FIELD_TYPE:
case MultiSelectType::FIELD_TYPE:
$field_data = $this->convert_option_string_to_options_array( $field_data );
break;
case FileType::FIELD_TYPE:
$field_data = $this->convert_extensions_to_mime_types( $field_data );
break;
}
$plugin_settings[ $section_id ][ $field_id ] = $field_data;
}
}
update_option( EditFieldsForm::SETTINGS_OPTION_NAME, $plugin_settings );
}
/**
* {@inheritdoc}
*/
public function down() {
$plugin_settings = get_option( EditFieldsForm::SETTINGS_OPTION_NAME, [] );
foreach ( $plugin_settings as $section_id => $section_fields ) {
foreach ( $section_fields as $field_id => $field_data ) {
switch ( $field_data['type'] ?? '' ) {
case RadioType::FIELD_TYPE:
case SelectType::FIELD_TYPE:
case MultiSelectType::FIELD_TYPE:
$field_data = $this->convert_options_array_to_option_string( $field_data );
break;
case FileType::FIELD_TYPE:
$field_data = $this->convert_mime_types_to_extensions( $field_data );
break;
}
$plugin_settings[ $section_id ][ $field_id ] = $field_data;
}
}
update_option( EditFieldsForm::SETTINGS_OPTION_NAME, $plugin_settings );
}
/**
* Converts "value1 : Value 1\nvalue2 : Value 2" to array structure.
*/
private function convert_option_string_to_options_array( array $field_data ): array {
if ( isset( $field_data['options'] ) ) {
return $field_data;
}
$options = explode( "\n", $field_data['option'] ?? '' );
$rows = [];
foreach ( $options as $option ) {
$values = explode( ':', $option );
if ( ! $values ) {
continue;
}
$rows[] = [
'key' => trim( $values[0] ),
'value' => trim( implode( ':', array_slice( $values, 1 ) ) ),
];
}
$field_data['options'] = $rows;
if ( isset( $field_data['option'] ) ) {
unset( $field_data['option'] );
}
return $field_data;
}
/**
* Converts array structure to "value1 : Value 1\nvalue2 : Value 2".
*/
private function convert_options_array_to_option_string( array $field_data ): array {
if ( isset( $field_data['option'] ) ) {
return $field_data;
}
$options = $field_data['options'] ?? [];
$rows = [];
foreach ( $options as $option ) {
$rows[] = sprintf( '%1$s : %2$s', $option['key'], $option['value'] );
}
$field_data['option'] = implode( "\n", $rows );
if ( isset( $field_data['options'] ) ) {
unset( $field_data['options'] );
}
return $field_data;
}
/**
* Converts "jpg,pdf" to "image/jpeg,application/pdf".
*/
private function convert_extensions_to_mime_types( array $field_data ): array {
$values = array_map( 'trim', explode( ',', $field_data['file_types'] ?? '' ) );
$mime_types = get_allowed_mime_types();
$mime_values = [];
foreach ( $mime_types as $mime_extensions => $mime_type ) {
foreach ( explode( '|', $mime_extensions ) as $mime_extension ) {
$mime_values[ $mime_extension ] = $mime_type;
}
}
$new_values = [];
foreach ( $values as $value ) {
if ( in_array( $value, $mime_values, true ) ) {
$new_values[] = $value;
} elseif ( isset( $mime_values[ $value ] ) ) {
$new_values[] = $mime_values[ $value ];
}
}
$field_data['file_types'] = implode( ',', array_unique( $new_values ) );
return $field_data;
}
/**
* Converts "image/jpeg,application/pdf" to "jpg,jpeg,jpe,pdf".
*/
private function convert_mime_types_to_extensions( array $field_data ): array {
$values = array_map( 'trim', explode( ',', $field_data['file_types'] ?? '' ) );
$mime_types = get_allowed_mime_types();
$mime_values = [];
foreach ( $mime_types as $mime_extensions => $mime_type ) {
$mime_values[ $mime_type ] = explode( '|', $mime_extensions );
}
$new_values = [];
foreach ( $values as $value ) {
if ( isset( $mime_values[ $value ] ) ) {
$new_values[] = implode( ',', $mime_values[ $value ] );
} else {
$new_values[] = $value;
}
}
$field_data['file_types'] = implode( ',', array_unique( $new_values ) );
return $field_data;
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace WPDesk\FCF\Free\Settings;
use FcfVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use WPDesk\FCF\Free\Settings\Migrations\Migration;
use WPDesk\FCF\Free\Settings\Migrations\Migration320;
/**
* Manage migration of plugin settings after plugin update.
*/
class MigrationsManager implements Hookable {
const PLUGIN_MIGRATION_OPTION_KEY = 'fcf_migration_version';
/**
* @var string
*/
private $plugin_version;
/**
* @var Migration[]
*/
private $migrations = [];
public function __construct( string $plugin_version ) {
$this->plugin_version = $plugin_version;
$this->migrations[] = new Migration320();
}
/**
* {@inheritdoc}
*/
public function hooks() {
add_action( 'init', [ $this, 'make_migrations' ] );
}
/**
* @return void
*
* @internal
*/
public function make_migrations() {
$current_migration = get_option( self::PLUGIN_MIGRATION_OPTION_KEY, '1.0.0' );
if ( $current_migration === $this->plugin_version ) {
return;
}
foreach ( $this->migrations as $migration ) {
if ( $migration->get_version() > $this->plugin_version ) {
$migration->down();
} elseif ( $migration->get_version() > $current_migration ) {
$migration->up();
}
}
update_option( self::PLUGIN_MIGRATION_OPTION_KEY, $this->plugin_version );
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\AppearanceTab;
/**
* {@inheritdoc}
*/
class CssOption extends OptionAbstract {
const FIELD_NAME = 'class';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return AppearanceTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_TEXT;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'CSS class', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_label_tooltip(): string {
return __( 'Enter CSS classes separated by a space.', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_default_value() {
return 'form-row-wide';
}
/**
* {@inheritdoc}
*/
public function update_field_data( array $field_data, array $field_settings ): array {
$option_name = $this->get_option_name();
$field_data[ $option_name ] = $this->sanitize_option_value(
implode( ' ', (array) $field_settings[ $option_name ] )
);
return $field_data;
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class CustomFieldDisabledOption extends CustomFieldOption {
/**
* {@inheritdoc}
*/
public function get_default_value() {
return '';
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class CustomFieldOption extends OptionAbstract {
const FIELD_NAME = 'custom_field';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return GeneralTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_HIDDEN;
}
/**
* {@inheritdoc}
*/
public function get_default_value() {
return '1';
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class DefaultOption extends OptionAbstract {
const FIELD_NAME = 'default';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return GeneralTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_HIDDEN;
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class DisplayOnAccountAddressOption extends OptionAbstract {
const FIELD_NAME = 'display_on_address';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_CHECKBOX;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'My Account - address', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_default_value() {
return '1';
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class DisplayOnAccountOrderOption extends OptionAbstract {
const FIELD_NAME = 'display_on_order';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_CHECKBOX;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'My Account - order', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_default_value() {
return '1';
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class DisplayOnEmailsOption extends OptionAbstract {
const FIELD_NAME = 'display_on_emails';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_CHECKBOX;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'E-mails', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_default_value() {
return '1';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class DisplayOnOnlyAddressOption extends DisplayOnOption {
/**
* {@inheritdoc}
*/
public function get_children(): array {
return [
DisplayOnAccountAddressOption::FIELD_NAME => new DisplayOnAccountAddressOption(),
];
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
/**
* {@inheritdoc}
*/
class DisplayOnOption extends OptionAbstract {
const FIELD_NAME = 'display_on';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return DisplayTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_CHECKBOX_LIST;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'Pages/e-mails', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_children(): array {
return [
DisplayOnThankYouOption::FIELD_NAME => new DisplayOnThankYouOption(),
DisplayOnAccountAddressOption::FIELD_NAME => new DisplayOnAccountAddressOption(),
DisplayOnAccountOrderOption::FIELD_NAME => new DisplayOnAccountOrderOption(),
DisplayOnEmailsOption::FIELD_NAME => new DisplayOnEmailsOption(),
];
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class DisplayOnThankYouOption extends OptionAbstract {
const FIELD_NAME = 'display_on_thank_you';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_CHECKBOX;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'Thank You Page', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_default_value() {
return '1';
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class DisplayOnWithoutAddressOption extends DisplayOnOption {
/**
* {@inheritdoc}
*/
public function get_children(): array {
return [
DisplayOnThankYouOption::FIELD_NAME => new DisplayOnThankYouOption(),
DisplayOnAccountOrderOption::FIELD_NAME => new DisplayOnAccountOrderOption(),
DisplayOnEmailsOption::FIELD_NAME => new DisplayOnEmailsOption(),
];
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class EnabledOption extends OptionAbstract {
const FIELD_NAME = 'visible';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return GeneralTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_CHECKBOX;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'Enable field', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_default_value() {
return '1';
}
/**
* {@inheritdoc}
*/
public function update_field_data( array $field_data, array $field_settings ): array {
$option_name = $this->get_option_name();
$option_value = $field_settings[ $option_name ] ?? 0;
$field_data[ $option_name ] = $this->sanitize_option_value( ( $option_value ) ? '0' : '1' );
return $field_data;
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class ExternalFieldInfoOption extends OptionAbstract {
const FIELD_NAME = 'external_field_info';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return GeneralTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_INFO_NOTICE;
}
/**
* {@inheritdoc}
*/
public function get_options_regexes_to_display(): array {
return [
ExternalFieldOption::FIELD_NAME => '^1$',
];
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'Another plugin has added this field but FCF is taking control of it. Editing is OK but keep in mind the functioning of the plugin that uses it.', 'flexible-checkout-fields' );
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class ExternalFieldOption extends OptionAbstract {
const FIELD_NAME = 'external_field';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return GeneralTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_HIDDEN;
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class FieldTypeDefaultOption extends FieldTypeOption {
/**
* {@inheritdoc}
*/
public function get_default_value() {
return 'text';
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class FieldTypeOption extends OptionAbstract {
const FIELD_NAME = 'type';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return GeneralTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_HIDDEN;
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class FormattingFieldLabelOption extends OptionAbstract {
const FIELD_NAME = 'display_on_option_show_label';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_CHECKBOX;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'Display field label', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_default_value() {
return '1';
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class FormattingNewLineOption extends OptionAbstract {
const FIELD_NAME = 'display_on_option_new_line_before';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_CHECKBOX;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'Display the field on a new line', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_default_value() {
return '1';
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
/**
* {@inheritdoc}
*/
class FormattingOption extends OptionAbstract {
const FIELD_NAME = 'formatting_options';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return DisplayTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_CHECKBOX_LIST;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'Formatting on pages/e-mails', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_children(): array {
return [
FormattingNewLineOption::FIELD_NAME => new FormattingNewLineOption(),
FormattingFieldLabelOption::FIELD_NAME => new FormattingFieldLabelOption(),
];
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class FormattingStateAbbrOption extends OptionAbstract {
const FIELD_NAME = 'display_on_option_state_code';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_CHECKBOX;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'Display state abbreviations', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_default_value() {
return '0';
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class FormattingStateCommaOption extends OptionAbstract {
const FIELD_NAME = 'display_on_option_state_code_comma_before';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_CHECKBOX;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'Display a comma before if the field is not on a new line', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_default_value() {
return '0';
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\DisplayTab;
/**
* {@inheritdoc}
*/
class FormattingStateOption extends OptionAbstract {
const FIELD_NAME = 'formatting_state_options';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return DisplayTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_CHECKBOX_LIST;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'State/County formatting', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_children(): array {
return [
FormattingStateAbbrOption::FIELD_NAME => new FormattingStateAbbrOption(),
FormattingStateCommaOption::FIELD_NAME => new FormattingStateCommaOption(),
];
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class FormattingWcOption extends FormattingOption {
/**
* {@inheritdoc}
*/
public function get_children(): array {
return [
FormattingNewLineOption::FIELD_NAME => new FormattingNewLineOption(),
];
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class ImageOption extends OptionAbstract {
const FIELD_NAME = 'image';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return GeneralTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_IMAGE;
}
/**
* {@inheritdoc}
*/
public function get_validation_rules(): array {
return [
'^.{1,}$' => __( 'This field is required.', 'flexible-checkout-fields' ),
];
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'Image', 'flexible-checkout-fields' );
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class ImageWidthOption extends OptionAbstract {
const FIELD_NAME = 'image_width';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return GeneralTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_NUMBER;
}
/**
* {@inheritdoc}
*/
public function get_validation_rules(): array {
return [
'^.{1,}$' => __( 'This field is required.', 'flexible-checkout-fields' ),
];
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'Image width (in pixels)', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_input_atts(): array {
return [
'min' => '1',
'step' => '1',
];
}
/**
* {@inheritdoc}
*/
public function get_default_value() {
return '150';
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class LabelOption extends OptionAbstract {
const FIELD_NAME = 'label';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return GeneralTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_TEXTAREA;
}
/**
* {@inheritdoc}
*/
public function get_validation_rules(): array {
return [
'^.{1,}$' => __( 'This field is required.', 'flexible-checkout-fields' ),
];
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'Label', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function sanitize_option_value( $field_value ) {
return wp_kses_post( wp_unslash( $field_value ) );
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
/**
* {@inheritdoc}
*/
class LabelOptionallyOption extends LabelOption {
/**
* {@inheritdoc}
*/
public function get_validation_rules(): array {
return [];
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\LogicTab;
/**
* {@inheritdoc}
*/
class LogicAdvOption extends OptionAbstract {
const FIELD_NAME = 'conditional_logic_adv';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return LogicTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_INFO_ADV;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
$url_products = esc_url( apply_filters( 'flexible_checkout_fields/short_url', '#', 'fcf-settings-field-tab-logic-docs-products-upgrade' ) );
$url_fields = esc_url( apply_filters( 'flexible_checkout_fields/short_url', '#', 'fcf-settings-field-tab-logic-docs-fields-upgrade' ) );
$url_shipping = esc_url( apply_filters( 'flexible_checkout_fields/short_url', '#', 'fcf-settings-field-tab-logic-docs-shipping-upgrade' ) );
$url_upgrade = esc_url( apply_filters( 'flexible_checkout_fields/short_url', '#', 'fcf-settings-field-tab-logic-upgrade' ) );
return sprintf(
/* translators: %1$s: anchor opening tag, %2$s: anchor closing tag, %3$s: anchor opening tag, %4$s: anchor closing tag, %5$s: anchor opening tag, %6$s: anchor closing tag, %7$s: break line, %8$s: anchor opening tag, %9$s: anchor closing tag */
__( 'Add conditional logic based on %1$sproducts and categories%2$s as well as %3$sFCF fields%4$s and %5$sshipping methods%6$s set. %7$s%8$sUpgrade to PRO%9$s', 'flexible-checkout-fields' ),
'<a href="' . $url_products . '" target="_blank">',
'</a>',
'<a href="' . $url_fields . '" target="_blank">',
'</a>',
'<a href="' . $url_shipping . '" target="_blank">',
'</a>',
'<br>',
'<a href="' . $url_upgrade . '" target="_blank" class="fcfArrowLink">',
'</a>'
);
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace WPDesk\FCF\Free\Settings\Option;
use WPDesk\FCF\Free\Settings\Tab\GeneralTab;
/**
* {@inheritdoc}
*/
class NameOption extends OptionAbstract {
const FIELD_NAME = 'name';
/**
* {@inheritdoc}
*/
public function get_option_name(): string {
return self::FIELD_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_tab(): string {
return GeneralTab::TAB_NAME;
}
/**
* {@inheritdoc}
*/
public function get_option_type(): string {
return self::FIELD_TYPE_TEXT;
}
/**
* {@inheritdoc}
*/
public function is_readonly(): bool {
return true;
}
/**
* {@inheritdoc}
*/
public function get_option_label(): string {
return __( 'Meta name', 'flexible-checkout-fields' );
}
/**
* {@inheritdoc}
*/
public function get_print_pattern(): string {
return '_%s';
}
}

Some files were not shown because too many files have changed in this diff Show More