| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly. |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* WordPress settings API class |
| 8 |
* |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'WeDevs_Settings_API_Test' ) ) { |
| 11 |
class WSC_Settings { |
| 12 |
const OPTION_NAME = 'wsc_proofreader'; |
| 13 |
|
| 14 |
/** |
| 15 |
* @var WeDevs_Settings_API |
| 16 |
*/ |
| 17 |
private $settings_api; |
| 18 |
private $page_title; |
| 19 |
private $menu_title; |
| 20 |
private $menu_slug; |
| 21 |
|
| 22 |
function __construct( $page_title, $menu_title, $menu_slug ) { |
| 23 |
$this->settings_api = new WeDevs_Settings_API; |
| 24 |
$this->menu_title = $menu_title; |
| 25 |
$this->menu_slug = $menu_slug; |
| 26 |
$this->page_title = $page_title; |
| 27 |
add_action( 'admin_init', array( $this, 'admin_init' ) ); |
| 28 |
add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
| 29 |
} |
| 30 |
|
| 31 |
function admin_init() { |
| 32 |
//enable if woocommerce active |
| 33 |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 34 |
if ( class_exists( 'WooCommerce' ) && is_plugin_active( 'woocommerce/woocommerce.php' ) || class_exists( 'WP_eCommerce' ) ) { |
| 35 |
add_filter( 'wsc_admin_fields', array( $this, 'enable_woocommerce' ), 1 ); |
| 36 |
} |
| 37 |
|
| 38 |
//set the settings |
| 39 |
$this->settings_api->set_sections( $this->get_settings_sections() ); |
| 40 |
$this->settings_api->set_fields( $this->get_settings_fields() ); |
| 41 |
|
| 42 |
//initialize settings |
| 43 |
$this->settings_api->admin_init(); |
| 44 |
// $this->set_default_settings(); |
| 45 |
} |
| 46 |
|
| 47 |
function enable_woocommerce( $settings_fields ) { |
| 48 |
$enable_on_products = array( |
| 49 |
'name' => 'enable_on_products', |
| 50 |
'label' => __( 'Check Products', 'webspellchecker' ), |
| 51 |
'type' => 'checkbox', |
| 52 |
'default' => 'on' |
| 53 |
); |
| 54 |
array_push( $settings_fields['wsc_proofreader'], $enable_on_products ); |
| 55 |
|
| 56 |
return $settings_fields; |
| 57 |
} |
| 58 |
|
| 59 |
public function set_default_settings( $settings ) { |
| 60 |
$this->settings_api->set_fields( $settings ); |
| 61 |
} |
| 62 |
|
| 63 |
function admin_menu() { |
| 64 |
add_options_page( $this->page_title, $this->menu_title, 'delete_posts', $this->menu_slug, array( |
| 65 |
$this, |
| 66 |
'plugin_page' |
| 67 |
) ); |
| 68 |
} |
| 69 |
|
| 70 |
function get_settings_sections() { |
| 71 |
$sections = array( |
| 72 |
array( |
| 73 |
'id' => self::OPTION_NAME, |
| 74 |
'title' => '' |
| 75 |
) |
| 76 |
); |
| 77 |
|
| 78 |
return $sections; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Returns all the settings fields |
| 83 |
* |
| 84 |
* @return array settings fields |
| 85 |
*/ |
| 86 |
function get_settings_fields() { |
| 87 |
$settings_fields = array( |
| 88 |
'wsc_proofreader' => array( |
| 89 |
array( |
| 90 |
'name' => 'customer_id', |
| 91 |
'label' => __( 'License Key', 'webspellchecker' ), |
| 92 |
'desc' => __( 'Upgrade to WProofreader Pro for <strong>$49 per year</strong> to check spelling and grammar across a list of your websites. <br>Contact us at <a href="mailto:info@webspellchecker.net">info@webspellchecker.net</a> to find out how to proceed with the upgrade.', 'webspellchecker' ), |
| 93 |
'type' => 'text', |
| 94 |
'default' => '', |
| 95 |
'sanitize_callback' => 'sanitize_text_field' |
| 96 |
), |
| 97 |
array( |
| 98 |
'name' => 'slang', |
| 99 |
'label' => __( 'Default Language', 'webspellchecker' ), |
| 100 |
'type' => 'select', |
| 101 |
'options' => ! empty( $this->get_lang_list() ) ? $this->get_lang_list() : array( |
| 102 |
'en_US' => 'English', |
| 103 |
'en_GB' => 'British English', |
| 104 |
'en_CA' => 'Canadian English', |
| 105 |
'fr_FR' => 'French', |
| 106 |
'fr_CA' => 'Canadian French', |
| 107 |
'de_DE' => 'German', |
| 108 |
'it_IT' => 'Italian', |
| 109 |
'pt_PT' => 'Portuguese', |
| 110 |
'pt_BR' => 'Brazilian Portuguese', |
| 111 |
'da_DK' => 'Danish', |
| 112 |
), |
| 113 |
'default' => 'en_US' |
| 114 |
), |
| 115 |
array( |
| 116 |
'name' => 'disable_badge_button', |
| 117 |
'label' => __( 'Disable WProofreader Badge', 'webspellchecker' ), |
| 118 |
'type' => 'checkbox', |
| 119 |
'default' => 'off' |
| 120 |
), |
| 121 |
array( |
| 122 |
'name' => 'enable_on_posts', |
| 123 |
'label' => __( 'Check Posts', 'webspellchecker' ), |
| 124 |
'type' => 'checkbox', |
| 125 |
'default' => 'on' |
| 126 |
), |
| 127 |
array( |
| 128 |
'name' => 'enable_on_pages', |
| 129 |
'label' => __( 'Check Pages', 'webspellchecker' ), |
| 130 |
'type' => 'checkbox', |
| 131 |
'default' => 'on' |
| 132 |
), |
| 133 |
array( |
| 134 |
'name' => 'enable_on_categories', |
| 135 |
'label' => __( 'Check Categories', 'webspellchecker' ), |
| 136 |
'type' => 'checkbox', |
| 137 |
'default' => 'on' |
| 138 |
), |
| 139 |
array( |
| 140 |
'name' => 'enable_on_tags', |
| 141 |
'label' => __( 'Check Tags', 'webspellchecker' ), |
| 142 |
'type' => 'checkbox', |
| 143 |
'default' => 'on' |
| 144 |
) |
| 145 |
|
| 146 |
) |
| 147 |
); |
| 148 |
|
| 149 |
return apply_filters( 'wsc_admin_fields', $settings_fields ); |
| 150 |
} |
| 151 |
|
| 152 |
function plugin_page() { |
| 153 |
echo '<div class="wrap">'; |
| 154 |
echo "<h1>$this->page_title</h1>"; |
| 155 |
$this->settings_api->show_navigation(); |
| 156 |
$this->settings_api->show_forms(); |
| 157 |
echo '</div>'; |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Get all the pages |
| 162 |
* |
| 163 |
* @return array page names with key value pairs |
| 164 |
*/ |
| 165 |
function get_pages() { |
| 166 |
$pages = get_pages(); |
| 167 |
$pages_options = array(); |
| 168 |
if ( $pages ) { |
| 169 |
foreach ( $pages as $page ) { |
| 170 |
$pages_options[ $page->ID ] = $page->post_title; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
return $pages_options; |
| 175 |
} |
| 176 |
|
| 177 |
function get_lang_list() { |
| 178 |
$get_info = get_option( 'wsc_proofreader_info' ); |
| 179 |
|
| 180 |
return $get_info['langList']['ltr']; |
| 181 |
} |
| 182 |
|
| 183 |
} |
| 184 |
|
| 185 |
} |