| 1 |
<?php |
| 2 |
namespace EverCompare\Admin; |
| 3 |
/** |
| 4 |
* Admin Page Fields handlers class |
| 5 |
*/ |
| 6 |
class Admin_Fields { |
| 7 |
|
| 8 |
private $settings_api; |
| 9 |
|
| 10 |
/** |
| 11 |
* [$_instance] |
| 12 |
* @var null |
| 13 |
*/ |
| 14 |
private static $_instance = null; |
| 15 |
|
| 16 |
/** |
| 17 |
* [instance] Initializes a singleton instance |
| 18 |
* @return [Admin] |
| 19 |
*/ |
| 20 |
public static function instance() { |
| 21 |
if ( is_null( self::$_instance ) ) { |
| 22 |
self::$_instance = new self(); |
| 23 |
} |
| 24 |
return self::$_instance; |
| 25 |
} |
| 26 |
|
| 27 |
function __construct() { |
| 28 |
$this->settings_api = new Settings_APi(); |
| 29 |
add_action( 'admin_init', [ $this, 'admin_init' ] ); |
| 30 |
} |
| 31 |
|
| 32 |
public function admin_init() { |
| 33 |
|
| 34 |
//set the settings |
| 35 |
$this->settings_api->set_sections( $this->get_settings_sections() ); |
| 36 |
$this->settings_api->set_fields( $this->fields_settings() ); |
| 37 |
|
| 38 |
//initialize settings |
| 39 |
$this->settings_api->admin_init(); |
| 40 |
} |
| 41 |
|
| 42 |
// Options page Section register |
| 43 |
public function get_settings_sections() { |
| 44 |
$sections = array( |
| 45 |
|
| 46 |
array( |
| 47 |
'id' => 'ever_compare_settings_tabs', |
| 48 |
'title' => esc_html__( 'Button Settings', 'ever-compare' ) |
| 49 |
), |
| 50 |
|
| 51 |
array( |
| 52 |
'id' => 'ever_compare_table_settings_tabs', |
| 53 |
'title' => esc_html__( 'Table Settings', 'ever-compare' ) |
| 54 |
), |
| 55 |
|
| 56 |
); |
| 57 |
return $sections; |
| 58 |
} |
| 59 |
|
| 60 |
// Options page field register |
| 61 |
protected function fields_settings() { |
| 62 |
|
| 63 |
$settings_fields = array( |
| 64 |
|
| 65 |
'ever_compare_settings_tabs' => array( |
| 66 |
|
| 67 |
array( |
| 68 |
'name' => 'button_text', |
| 69 |
'label' => __( 'Button', 'ever-compare' ), |
| 70 |
'desc' => __( 'Enter your compare button text.', 'ever-compare' ), |
| 71 |
'type' => 'text', |
| 72 |
'default' => __( 'Compare', 'ever-compare' ), |
| 73 |
'placeholder' => __( 'Compare', 'ever-compare' ), |
| 74 |
), |
| 75 |
|
| 76 |
array( |
| 77 |
'name' => 'added_button_text', |
| 78 |
'label' => __( 'Added Button Text', 'ever-compare' ), |
| 79 |
'desc' => __( 'Enter your compare added button text.', 'ever-compare' ), |
| 80 |
'type' => 'text', |
| 81 |
'default' => __( 'Added', 'ever-compare' ), |
| 82 |
'placeholder' => __( 'Added', 'ever-compare' ), |
| 83 |
), |
| 84 |
|
| 85 |
array( |
| 86 |
'name' => 'btn_show_shoppage', |
| 87 |
'label' => __( 'Show compare button in product list', 'ever-compare' ), |
| 88 |
'type' => 'checkbox', |
| 89 |
'default' => 'on', |
| 90 |
), |
| 91 |
|
| 92 |
array( |
| 93 |
'name' => 'btn_show_productpage', |
| 94 |
'label' => __( 'Show compare button on single product page', 'ever-compare' ), |
| 95 |
'type' => 'checkbox', |
| 96 |
'default' => 'on', |
| 97 |
), |
| 98 |
|
| 99 |
array( |
| 100 |
'name' => 'open_popup', |
| 101 |
'label' => __( 'Open popup', 'ever-compare' ), |
| 102 |
'type' => 'checkbox', |
| 103 |
'default' => 'on', |
| 104 |
), |
| 105 |
|
| 106 |
), |
| 107 |
|
| 108 |
'ever_compare_table_settings_tabs' => array( |
| 109 |
|
| 110 |
array( |
| 111 |
'name' => 'compare_page', |
| 112 |
'label' => __( 'Compare page', 'ever-compare' ), |
| 113 |
'desc' => __( 'Select a compare page for compare table. It should contain the shortcode [evercompare_table]', 'ever-compare' ), |
| 114 |
'type' => 'select', |
| 115 |
'default' => '0', |
| 116 |
'options' => ever_compare_get_post_list() |
| 117 |
), |
| 118 |
|
| 119 |
array( |
| 120 |
'name' => 'show_fields', |
| 121 |
'label' => __('Show fields in table', 'ever-compare'), |
| 122 |
'desc' => __('Choose which fields should be presented on the product compare page with table.', 'ever-compare'), |
| 123 |
'type' => 'multicheckshort', |
| 124 |
'options' => ever_compare_get_available_attributes(), |
| 125 |
'default' => [ |
| 126 |
'title' => esc_html__( 'title', 'ever-compare' ), |
| 127 |
'ratting' => esc_html__( 'ratting', 'ever-compare' ), |
| 128 |
'price' => esc_html__( 'price', 'ever-compare' ), |
| 129 |
'add_to_cart' => esc_html__( 'add_to_cart', 'ever-compare' ), |
| 130 |
'description' => esc_html__( 'description', 'ever-compare' ), |
| 131 |
'availability' => esc_html__( 'availability', 'ever-compare' ), |
| 132 |
'sku' => esc_html__( 'sku', 'ever-compare' ), |
| 133 |
'weight' => esc_html__( 'weight', 'ever-compare' ), |
| 134 |
'dimensions' => esc_html__( 'dimensions', 'ever-compare' ), |
| 135 |
], |
| 136 |
), |
| 137 |
|
| 138 |
array( |
| 139 |
'name' => 'empty_table_text', |
| 140 |
'label' => __('Empty compare page text', 'ever-compare'), |
| 141 |
'desc' => __('Text will be displayed if user don\'t add any products to compare', 'ever-compare'), |
| 142 |
'type' => 'textarea' |
| 143 |
), |
| 144 |
|
| 145 |
array( |
| 146 |
'name' => 'shop_button_text', |
| 147 |
'label' => __( 'Return to shop button text', 'ever-compare' ), |
| 148 |
'desc' => __( 'Enter your return to shop button text.', 'ever-compare' ), |
| 149 |
'type' => 'text', |
| 150 |
'default' => __( 'Return to shop', 'ever-compare' ), |
| 151 |
'placeholder' => __( 'Return to shop', 'ever-compare' ), |
| 152 |
), |
| 153 |
|
| 154 |
array( |
| 155 |
'name' => 'image_size', |
| 156 |
'label' => __( 'Image size', 'ever-compare' ), |
| 157 |
'desc' => __( 'Enter your required image size.', 'ever-compare' ), |
| 158 |
'type' => 'multitext', |
| 159 |
'options' =>[ |
| 160 |
'width' => esc_html__( 'Width', 'ever-compare' ), |
| 161 |
'height' => esc_html__( 'Height', 'ever-compare' ), |
| 162 |
] |
| 163 |
), |
| 164 |
|
| 165 |
array( |
| 166 |
'name' => 'hard_crop', |
| 167 |
'label' => __( 'Image Hard Crop', 'ever-compare' ), |
| 168 |
'type' => 'checkbox', |
| 169 |
'default' => 'on', |
| 170 |
), |
| 171 |
|
| 172 |
), |
| 173 |
|
| 174 |
); |
| 175 |
|
| 176 |
return $settings_fields; |
| 177 |
} |
| 178 |
|
| 179 |
public function plugin_page() { |
| 180 |
echo '<div class="wrap">'; |
| 181 |
echo '<h2>'.esc_html__( 'Compare Settings','ever-compare' ).'</h2>'; |
| 182 |
$this->save_message(); |
| 183 |
$this->settings_api->show_navigation(); |
| 184 |
$this->settings_api->show_forms(); |
| 185 |
echo '</div>'; |
| 186 |
} |
| 187 |
|
| 188 |
public function save_message() { |
| 189 |
if( isset( $_GET['settings-updated'] ) ) { |
| 190 |
?> |
| 191 |
<div class="updated notice is-dismissible"> |
| 192 |
<p><strong><?php esc_html_e('Successfully Settings Saved.', 'ever-compare') ?></strong></p> |
| 193 |
</div> |
| 194 |
<?php |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
} |