pageName = $args['page_name']; $this->settingsName = $args['field_name']; $this->sectionName = $this->settingsName . '_section'; $this->optionValue = checked(1, get_option($this->settingsName), false); $this->fieldLabel = isset($args['field_label']) ? stripslashes($args['field_label']) : ''; $this->textRight = isset($args['text_right']) ? stripslashes($args['text_right']) : ''; $this->classAttribute = isset($args['class_attribute']) ? $args['class_attribute'] : ''; $this->description = isset($args['description']) ? $args['description'] : ''; add_action('admin_init', [$this, 'optionsSettingsInit']); } public function optionsSettingsInit() { register_setting( $this->pageName, $this->settingsName, [ 'type' => 'number', 'group' => $this->pageName, 'sanitize_callback' => [$this, 'optionCallback'] ] ); add_settings_section( $this->sectionName, '', '', $this->pageName ); add_settings_field( $this->settingsName, $this->fieldLabel, [$this, 'displayCallback'], $this->pageName, $this->sectionName, [ 'label_for' => $this->settingsName, 'class' => $this->classAttribute ] ); } public function optionCallback($value) { if (has_filter(Plugin::PREFIX_ . 'sanitize_option_' . $this->settingsName)) { return apply_filters(Plugin::PREFIX_ . 'sanitize_option_' . $this->settingsName, $value); } return ($value === '1') ? 1 : 0; } public function displayCallback() { print('
'); } }