Last active
May 11, 2018 09:24
-
-
Save woogists/f009b638ba349d38698e18db94262f9c to your computer and use it in GitHub Desktop.
[Extending][Implementing the WC Integration Class] Creating your own WooCommerce settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Initialize integration settings form fields. | |
* | |
* @return void | |
*/ | |
public function init_form_fields() { | |
$this->form_fields = array( | |
// don't forget to put your other settings here | |
'customize_button' => array( | |
'title' => __( 'Customize!', 'woocommerce-integration-demo' ), | |
'type' => 'button', | |
'custom_attributes' => array( | |
'onclick' => "location.href='http://www.woothemes.com'", | |
), | |
'description' => __( 'Customize your settings by going to the integration site directly.', 'woocommerce-integration-demo' ), | |
'desc_tip' => true, | |
) | |
); | |
} | |
/** | |
* Generate Button HTML. | |
* | |
* @access public | |
* @param mixed $key | |
* @param mixed $data | |
* @since 1.0.0 | |
* @return string | |
*/ | |
public function generate_button_html( $key, $data ) { | |
$field = $this->plugin_id . $this->id . '_' . $key; | |
$defaults = array( | |
'class' => 'button-secondary', | |
'css' => '', | |
'custom_attributes' => array(), | |
'desc_tip' => false, | |
'description' => '', | |
'title' => '', | |
); | |
$data = wp_parse_args( $data, $defaults ); | |
ob_start(); | |
?> | |
<tr valign="top"> | |
<th scope="row" class="titledesc"> | |
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label> | |
<?php echo $this->get_tooltip_html( $data ); ?> | |
</th> | |
<td class="forminp"> | |
<fieldset> | |
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> | |
<button class="<?php echo esc_attr( $data['class'] ); ?>" type="button" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php echo $this->get_custom_attribute_html( $data ); ?>><?php echo wp_kses_post( $data['title'] ); ?></button> | |
<?php echo $this->get_description_html( $data ); ?> | |
</fieldset> | |
</td> | |
</tr> | |
<?php | |
return ob_get_clean(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment