Last active
August 29, 2015 14:23
-
-
Save remcotolsma/1c43f555c7f2c5b505b3 to your computer and use it in GitHub Desktop.
WordPress pay Gravity Forms extensions feature/form-settings
This file contains hidden or 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
<?php | |
/** | |
* Title: WordPress pay extension Gravity Forms admin | |
* Description: | |
* Copyright: Copyright (c) 2005 - 2015 | |
* Company: Pronamic | |
* @author Remco Tolsma | |
* @version 1.1.0 | |
*/ | |
class Pronamic_WP_Pay_Extensions_GravityForms_Admin { | |
/** | |
* Bootstrap | |
*/ | |
public static function bootstrap() { | |
// Actions | |
add_action( 'admin_init', array( __CLASS__, 'admin_init' ) ); | |
add_action( 'admin_init', array( __CLASS__, 'maybe_redirect_to_entry' ) ); | |
add_action( 'gform_form_settings_page_pronamic_pay_gf', array( __CLASS__, 'form_settings_page' ) ); | |
// Filters | |
add_filter( 'gform_addon_navigation', array( __CLASS__, 'addon_navigation' ) ); | |
add_filter( 'gform_form_settings_menu', array( __CLASS__, 'form_settings_menu_item' ) ); | |
add_filter( 'gform_entry_info', array( __CLASS__, 'entry_info' ), 10, 2 ); | |
add_filter( 'gform_custom_merge_tags', array( __CLASS__, 'custom_merge_tags' ), 10 ); | |
// Actions - AJAX | |
add_action( 'wp_ajax_gf_get_form_data', array( __CLASS__, 'ajax_get_form_data' ) ); | |
} | |
////////////////////////////////////////////////// | |
/** | |
* Admin initialize | |
*/ | |
public static function admin_init() { | |
new Pronamic_WP_Pay_Extensions_GravityForms_AdminPaymentFormPostType(); | |
} | |
////////////////////////////////////////////////// | |
/** | |
* Gravity Forms addon navigation | |
* | |
* @param $menus array with addon menu items | |
* @return array | |
*/ | |
public static function addon_navigation( $menus ) { | |
if ( version_compare( GFCommon::$version, '1.7', '<' ) ) { | |
$menus[] = array( | |
'name' => 'edit.php?post_type=pronamic_pay_gf', | |
'label' => __( 'iDEAL', 'pronamic_ideal' ), | |
'callback' => null, | |
'permission' => 'manage_options', | |
); | |
} | |
return $menus; | |
} | |
////////////////////////////////////////////////// | |
/** | |
* Add menu item to form settings | |
* | |
* @param $menu_items array with form settings menu items | |
* @return array | |
*/ | |
public static function form_settings_menu_item( $menu_items ) { | |
$menu_items[] = array( | |
'name' => 'pronamic_pay_gf', | |
'label' => __( 'iDEAL', 'pronamic-ideal' ), | |
); | |
return $menu_items; | |
} | |
////////////////////////////////////////////////// | |
/** | |
* Handle payment form settings | |
*/ | |
public static function form_settings_page() { | |
if ( filter_has_var( INPUT_POST, 'pronamic_pay_nonce' ) ) { | |
$nonce = filter_input( INPUT_POST, 'pronamic_pay_nonce', FILTER_SANITIZE_STRING ); | |
// Verify that the nonce is valid. | |
if ( wp_verify_nonce( $nonce, 'pronamic_pay_save_pay_gf' ) ) { | |
global $wpdb; | |
$form_id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT ); | |
$query = new WP_Query( array( | |
'post_type' => 'pronamic_pay_gf', | |
'posts_per_page' => 1, | |
'meta_query' => array( | |
'key' => '_pronamic_pay_gf_form_id', | |
'value' => $form_id, | |
), | |
) ); | |
$post_id = $query->posts[0]->ID; | |
if ( ! $post_id ) { | |
wp_insert_post( array( | |
'post_type' => 'pronamic_pay_gf', | |
'post_name' => 'pronamic-pay-gf-' . $form_id, | |
'post_title' => 'Pronamic iDEAL for Gravity Forms #' . $form_id, | |
'post_status' => 'publish', | |
'comment_status' => 'closed', | |
'ping_status' => 'closed', | |
) ); | |
$post_id = $wpdb->insert_id; | |
} | |
wp_update_post( array( | |
'ID' => $post_id, | |
) ); | |
} | |
} | |
GFFormSettings::page_header(); | |
require( dirname( __FILE__ ) . '/../views/html-admin-meta-box-config.php' ); | |
GFFormSettings::page_footer(); | |
} | |
////////////////////////////////////////////////// | |
/** | |
* Render entry info of the specified form and lead | |
* | |
* @param string $form_id | |
* @param array $lead | |
*/ | |
public static function entry_info( $form_id, $lead ) { | |
$payment_id = gform_get_meta( $lead['id'], 'pronamic_payment_id' ); | |
if ( $payment_id ) { | |
printf( | |
'<a href="%s">%s</a>', | |
get_edit_post_link( $payment_id ), | |
get_the_title( $payment_id ) | |
); | |
} | |
} | |
////////////////////////////////////////////////// | |
/** | |
* Custom merge tags | |
*/ | |
public static function custom_merge_tags( $merge_tags ) { | |
$merge_tags[] = array( | |
'label' => __( 'Payment Status', 'pronamic_ideal' ), | |
'tag' => '{payment_status}', | |
); | |
$merge_tags[] = array( | |
'label' => __( 'Payment Date', 'pronamic_ideal' ), | |
'tag' => '{payment_date}', | |
); | |
$merge_tags[] = array( | |
'label' => __( 'Transaction Id', 'pronamic_ideal' ), | |
'tag' => '{transaction_id}', | |
); | |
$merge_tags[] = array( | |
'label' => __( 'Payment Amount', 'pronamic_ideal' ), | |
'tag' => '{payment_amount}', | |
); | |
return $merge_tags; | |
} | |
////////////////////////////////////////////////// | |
/** | |
* Maybed redirect to Gravity Forms entry | |
*/ | |
public static function maybe_redirect_to_entry() { | |
if ( filter_has_var( INPUT_GET, 'pronamic_gf_lid' ) ) { | |
$lead_id = filter_input( INPUT_GET, 'pronamic_gf_lid', FILTER_SANITIZE_STRING ); | |
$lead = RGFormsModel::get_lead( $lead_id ); | |
if ( ! empty( $lead ) ) { | |
$url = add_query_arg( array( | |
'page' => 'gf_entries', | |
'view' => 'entry', | |
'id' => $lead['form_id'], | |
'lid' => $lead_id, | |
), admin_url( 'admin.php' ) ); | |
wp_redirect( $url, 303 ); | |
exit; | |
} | |
} | |
} | |
////////////////////////////////////////////////// | |
/** | |
* Handle AJAX request get form data | |
*/ | |
public static function ajax_get_form_data() { | |
$form_id = filter_input( INPUT_GET, 'formId', FILTER_SANITIZE_STRING ); | |
$result = new stdClass(); | |
$result->success = true; | |
$result->data = RGFormsModel::get_form_meta( $form_id ); | |
// Output | |
header( 'Content-Type: application/json' ); | |
echo json_encode( $result ); | |
die(); | |
} | |
} |
This file contains hidden or 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
<?php | |
/** | |
* Title: WordPress admin payment form post type | |
* Description: | |
* Copyright: Copyright (c) 2005 - 2015 | |
* Company: Pronamic | |
* @author Remco Tolsma | |
* @version 1.1.0 | |
*/ | |
class Pronamic_WP_Pay_Extensions_GravityForms_AdminPaymentFormPostType { | |
public function __construct() { | |
add_filter( 'manage_edit-pronamic_pay_gf_columns', array( $this, 'edit_columns' ) ); | |
add_action( 'manage_pronamic_pay_gf_posts_custom_column', array( $this, 'custom_columns' ), 10, 2 ); | |
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); | |
add_action( 'gform_after_delete_form', array( $this, 'delete_payment_form' ) ); | |
add_action( 'save_post', array( $this, 'save_post' ) ); | |
} | |
public function edit_columns( $columns ) { | |
$columns = array( | |
'cb' => '<input type="checkbox" />', | |
'title' => __( 'Title', 'pronamic_ideal' ), | |
'pronamic_pay_gf_form' => __( 'Form', 'pronamic_ideal' ), | |
'pronamic_pay_gf_config' => __( 'Configuration', 'pronamic_ideal' ), | |
'pronamic_pay_gf_transaction_description' => __( 'Transaction Description', 'pronamic_ideal' ), | |
'date' => __( 'Date', 'pronamic_ideal' ), | |
); | |
return $columns; | |
} | |
public function custom_columns( $column, $post_id ) { | |
global $post; | |
switch ( $column ) { | |
case 'pronamic_pay_gf_form': | |
$form_id = get_post_meta( $post_id, '_pronamic_pay_gf_form_id', true ); | |
if ( ! empty( $form_id ) ) { | |
printf( | |
'<a href="%s">%s</a>', | |
add_query_arg( array( | |
'page' => 'gf_edit_forms', | |
'id' => $form_id, | |
), admin_url( 'admin.php' ) ), | |
get_pronamic_pay_gf_form_title( $form_id ) | |
); | |
} else { | |
echo '—'; | |
} | |
break; | |
case 'pronamic_pay_gf_config': | |
$config_id = get_post_meta( $post_id, '_pronamic_pay_gf_config_id', true ); | |
if ( ! empty( $config_id ) ) { | |
echo get_the_title( $config_id ); | |
} else { | |
echo '—'; | |
} | |
break; | |
case 'pronamic_pay_gf_transaction_description': | |
echo get_post_meta( $post_id, '_pronamic_pay_gf_transaction_description', true ); | |
break; | |
} | |
} | |
/** | |
* Add meta boxes | |
*/ | |
public function add_meta_boxes() { | |
add_meta_box( | |
'pronamic_pay_gf', | |
__( 'Configuration', 'pronamic_ideal' ), | |
array( $this, 'meta_box_config' ), | |
'pronamic_pay_gf', | |
'normal', | |
'high' | |
); | |
} | |
/** | |
* Pronamic Pay gateway config meta box | |
* | |
* @param WP_Post $post The object for the current post/page. | |
*/ | |
public function meta_box_config( $post ) { | |
include dirname( __FILE__ ) . '/../views/html-admin-meta-box-config.php'; | |
} | |
/** | |
* When the form is deleted from the trash, deletes our custom post. | |
* | |
* @param int $form_id The ID of the form being deleted. | |
*/ | |
public function delete_payment_form( $form_id ) { | |
global $wpdb; | |
$query = new WP_Query( array( | |
'post_type' => 'pronamic_pay_gf', | |
'posts_per_page' => 1, | |
'meta_key' => array( | |
'key' => '_pronamic_pay_gf_form_id', | |
'value' => $form_id, | |
), | |
) ); | |
$post_id = $query->posts[0]->ID; | |
wp_delete_post( $post_id, true ); | |
} | |
/** | |
* When the post is saved, saves our custom data. | |
* | |
* @param int $post_id The ID of the post being saved. | |
*/ | |
public function save_post( $post_id ) { | |
// Check if our nonce is set. | |
if ( ! filter_has_var( INPUT_POST, 'pronamic_pay_nonce' ) ) { | |
return $post_id; | |
} | |
$nonce = filter_input( INPUT_POST, 'pronamic_pay_nonce', FILTER_SANITIZE_STRING ); | |
// Verify that the nonce is valid. | |
if ( ! wp_verify_nonce( $nonce, 'pronamic_pay_save_pay_gf' ) ) { | |
return $post_id; | |
} | |
// If this is an autosave, our form has not been submitted, so we don't want to do anything. | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { | |
return $post_id; | |
} | |
// Check the user's permissions. | |
if ( 'page' == $_POST['post_type'] ) { | |
if ( ! current_user_can( 'edit_page', $post_id ) ) { | |
return $post_id; | |
} | |
} else { | |
if ( ! current_user_can( 'edit_post', $post_id ) ) { | |
return $post_id; | |
} | |
} | |
/* OK, its safe for us to save the data now. */ | |
$definition = array( | |
'_pronamic_pay_gf_form_id' => 'sanitize_text_field', | |
'_pronamic_pay_gf_config_id' => 'sanitize_text_field', | |
'_pronamic_pay_gf_entry_id_prefix' => 'sanitize_text_field', | |
'_pronamic_pay_gf_transaction_description' => 'sanitize_text_field', | |
'_pronamic_pay_gf_condition_enabled' => FILTER_VALIDATE_BOOLEAN, | |
'_pronamic_pay_gf_condition_field_id' => 'sanitize_text_field', | |
'_pronamic_pay_gf_condition_operator' => 'sanitize_text_field', | |
'_pronamic_pay_gf_condition_value' => 'sanitize_text_field', | |
'_pronamic_pay_gf_delay_admin_notification' => FILTER_VALIDATE_BOOLEAN, | |
'_pronamic_pay_gf_delay_user_notification' => FILTER_VALIDATE_BOOLEAN, | |
'_pronamic_pay_gf_delay_notification_ids' => array( | |
'filter' => FILTER_SANITIZE_STRING, | |
'flags' => FILTER_REQUIRE_ARRAY, | |
), | |
'_pronamic_pay_gf_delay_post_creation' => FILTER_VALIDATE_BOOLEAN, | |
'_pronamic_pay_gf_fields' => array( | |
'filter' => FILTER_SANITIZE_STRING, | |
'flags' => FILTER_REQUIRE_ARRAY, | |
), | |
'_pronamic_pay_gf_links' => array( | |
'filter' => FILTER_SANITIZE_STRING, | |
'flags' => FILTER_REQUIRE_ARRAY, | |
), | |
'_pronamic_pay_gf_user_role_field_id' => 'sanitize_text_field', | |
); | |
if ( class_exists( 'GFAWeber' ) ) { | |
$definition['_pronamic_pay_gf_delay_aweber_subscription'] = FILTER_VALIDATE_BOOLEAN; | |
} | |
if ( class_exists( 'GFCampaignMonitor' ) ) { | |
$definition['_pronamic_pay_gf_delay_campaignmonitor_subscription'] = FILTER_VALIDATE_BOOLEAN; | |
} | |
if ( class_exists( 'GFMailChimp' ) ) { | |
$definition['_pronamic_pay_gf_delay_mailchimp_subscription'] = FILTER_VALIDATE_BOOLEAN; | |
} | |
if ( class_exists( 'GFUser' ) ) { | |
$definition['_pronamic_pay_gf_delay_user_registration'] = FILTER_VALIDATE_BOOLEAN; | |
} | |
if ( class_exists( 'GFZapier' ) ) { | |
$definition['_pronamic_pay_gf_delay_zapier'] = FILTER_VALIDATE_BOOLEAN; | |
} | |
foreach ( $definition as $meta_key => $function ) { | |
$meta_value = null; | |
if ( 'sanitize_text_field' == $function ) { | |
if ( isset( $_POST[ $meta_key ] ) ) { | |
$meta_value = sanitize_text_field( $_POST[ $meta_key ] ); | |
} | |
} else { | |
$filter = $function; | |
$options = null; | |
if ( is_array( $function ) && isset( $function['filter'] ) ) { | |
$filter = $function['filter']; | |
$options = $function; | |
} | |
$meta_value = filter_input( INPUT_POST, $meta_key, $filter, $options ); | |
} | |
if ( isset( $meta_value ) && '' != $meta_value ) { | |
update_post_meta( $post_id, $meta_key, $meta_value ); | |
} else { | |
delete_post_meta( $post_id, $meta_key ); | |
} | |
} | |
} | |
} |
This file contains hidden or 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
<?php | |
if ( version_compare( GFCommon::$version, '1.7', '<' ) || ! ( isset( $_GET['page'] ) && $_GET['page'] == 'gf_edit_forms' ) ) : | |
$post_id = get_the_ID(); | |
$form_id = get_post_meta( $post_id, '_pronamic_pay_gf_form_id', true ); | |
else : | |
global $wpdb; | |
$in_form_settings = true; | |
$form_id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT ); | |
$query = new WP_Query( array( | |
'post_type' => 'pronamic_pay_gf', | |
'posts_per_page' => 1, | |
'meta_query' => array( | |
'key' => '_pronamic_pay_gf_form_id', | |
'value' => $form_id, | |
), | |
) ); | |
$post_id = $query->posts[0]->ID; | |
endif; | |
$form_meta = RGFormsModel::get_form_meta( $form_id ); | |
$feed = new stdClass(); | |
$feed->conditionFieldId = get_post_meta( $post_id, '_pronamic_pay_gf_condition_field_id', true ); | |
$feed->conditionOperator = get_post_meta( $post_id, '_pronamic_pay_gf_condition_operator', true ); | |
$feed->conditionValue = get_post_meta( $post_id, '_pronamic_pay_gf_condition_value', true ); | |
$feed->delayNotificationIds = get_post_meta( $post_id, '_pronamic_pay_gf_delay_notification_ids', true ); | |
$feed->fields = get_post_meta( $post_id, '_pronamic_pay_gf_fields', true ); | |
$feed->userRoleFieldId = get_post_meta( $post_id, '_pronamic_pay_gf_user_role_field_id', true ); | |
?> | |
<form method="post"> | |
<div id="gf-ideal-feed-editor"> | |
<?php wp_nonce_field( 'pronamic_pay_save_pay_gf', 'pronamic_pay_nonce' ); ?> | |
<input id="gf_ideal_gravity_form" name="gf_ideal_gravity_form" value="<?php echo esc_attr( json_encode( $form_meta ) ); ?>" type="hidden" /> | |
<input id="gf_ideal_feed" name="gf_ideal_feed" value="<?php echo esc_attr( json_encode( $feed ) ); ?>" type="hidden" /> | |
<?php if( isset( $in_form_settings ) ) : ?> | |
<input id="_pronamic_pay_gf_form_id" name="_pronamic_pay_gf_form_id" value="<?php echo $form_id; ?>" type="hidden" /> | |
<?php endif; ?> | |
<table class="form-table"> | |
<?php if( ! isset( $in_form_settings ) ) : ?> | |
<tr> | |
<th scope="row"> | |
<label for="_pronamic_pay_gf_form_id"> | |
<?php _e( 'Gravity Form', 'pronamic_ideal' ); ?> | |
</label> | |
</th> | |
<td> | |
<select id="_pronamic_pay_gf_form_id" name="_pronamic_pay_gf_form_id"> | |
<option value=""><?php _e( '— Select a form —', 'pronamic_ideal' ); ?></option> | |
<?php foreach ( RGFormsModel::get_forms() as $form ) : ?> | |
<option value="<?php echo $form->id; ?>" <?php selected( $form_id, $form->id ); ?>> | |
<?php echo esc_html( $form->title ); ?> | |
</option> | |
<?php endforeach; ?> | |
</select> | |
</td> | |
</tr> | |
<?php endif; ?> | |
<tr> | |
<th scope="row"> | |
<label for="_pronamic_pay_gf_config_id"> | |
<?php _e( 'Configuration', 'pronamic_ideal' ); ?> | |
</label> | |
</th> | |
<td> | |
<?php | |
$config_id = get_post_meta( $post_id, '_pronamic_pay_gf_config_id', true ); | |
Pronamic_WP_Pay_Admin::dropdown_configs( array( | |
'name' => '_pronamic_pay_gf_config_id', | |
'selected' => $config_id, | |
) ); | |
?> | |
</td> | |
</tr> | |
<tr> | |
<th scope="row"> | |
<label for="_pronamic_pay_gf_order_id"> | |
<?php _e( 'Entry ID Prefix', 'pronamic_ideal' ); ?> | |
</label> | |
</th> | |
<td> | |
<?php | |
$entry_id_prefix = get_post_meta( $post_id, '_pronamic_pay_gf_entry_id_prefix', true ); | |
?> | |
<input id="_pronamic_pay_gf_entry_id_prefix" name="_pronamic_pay_gf_entry_id_prefix" value="<?php echo esc_attr( $entry_id_prefix ); ?>" type="text" class="input-text regular-input" maxlength="8" /> | |
<span class="description"> | |
<br /> | |
<?php _e( 'Please enter a prefix for your entry ID\'s. If you use an gateway for multiple websites ensure this prefix is unique as not all gateways will allow payments with the same ID.', 'pronamic_ideal' ); ?> | |
</span> | |
</td> | |
</tr> | |
<tr> | |
<th scope="row"> | |
<label for="_pronamic_pay_gf_transaction_description"> | |
<?php _e( 'Transaction Description', 'pronamic_ideal' ); ?> | |
</label> | |
</th> | |
<td> | |
<?php | |
$transaction_description = get_post_meta( $post_id, '_pronamic_pay_gf_transaction_description', true ); | |
?> | |
<?php if ( false ) : ?> | |
<div> | |
<?php GFCommon::insert_variables( array(), 'gf_ideal_transaction_description', true, '', ' ' ); ?> | |
</div> | |
<?php endif; ?> | |
<input id="_pronamic_pay_gf_transaction_description" name="_pronamic_pay_gf_transaction_description" value="<?php echo esc_attr( $transaction_description ); ?>" type="text" class="regular-text" /> | |
<span class="description"> | |
<br /> | |
<?php _e( 'Maximum number of charachters is 32, you should also consider the use of variables Gravity Forms. An generated description that is longer than 32 characters will be automatically truncated.', 'pronamic_ideal' ); ?> | |
<br /> | |
<?php _e( 'Merge Tag Examples: Entry Id = <code>{entry_id}</code>, Form Id = <code>{form_id}</code>, Form Title = <code>{form_title}</code>', 'pronamic_ideal' ); ?> | |
</span> | |
</td> | |
</tr> | |
<tr> | |
<th scope="row"> | |
<label for="gf_ideal_condition_enabled"> | |
<?php _e( 'Condition', 'pronamic_ideal' ); ?> | |
</label> | |
</th> | |
<td> | |
<?php | |
$condition_enabled = get_post_meta( $post_id, '_pronamic_pay_gf_condition_enabled', true ); | |
$condition_field_id = get_post_meta( $post_id, '_pronamic_pay_gf_condition_field_id', true ); | |
$condition_operator = get_post_meta( $post_id, '_pronamic_pay_gf_condition_operator', true ); | |
$condition_value = get_post_meta( $post_id, '_pronamic_pay_gf_condition_value', true ); | |
?> | |
<div> | |
<input id="gf_ideal_condition_enabled" name="_pronamic_pay_gf_condition_enabled" value="true" type="checkbox" <?php checked( $condition_enabled ); ?> /> | |
<label for="gf_ideal_condition_enabled"> | |
<?php _e( 'Enable', 'pronamic_ideal' ); ?> | |
</label> | |
</div> | |
<div id="gf_ideal_condition_config"> | |
<?php | |
// Select field | |
$select_field = '<select id="gf_ideal_condition_field_id" name="_pronamic_pay_gf_condition_field_id"></select>'; | |
// Select operator | |
$select_operator = '<select id="gf_ideal_condition_operator" name="_pronamic_pay_gf_condition_operator">'; | |
$operators = array( | |
'' => '', | |
Pronamic_WP_Pay_Extensions_GravityForms_GravityForms::OPERATOR_IS => __( 'is', 'pronamic_ideal' ), | |
Pronamic_WP_Pay_Extensions_GravityForms_GravityForms::OPERATOR_IS_NOT => __( 'is not', 'pronamic_ideal' ), | |
); | |
foreach ( $operators as $value => $label ) { | |
$select_operator .= sprintf( | |
'<option value="%s" %s>%s</option>', | |
esc_attr( $value ), | |
selected( $condition_operator, $value, false ), | |
esc_html( $label ) | |
); | |
} | |
$select_operator .= '</select>'; | |
// Select value | |
$select_value = '<select id="gf_ideal_condition_value" name="_pronamic_pay_gf_condition_value"></select>'; | |
printf( | |
__( 'Send to gateway if %s %s %s', 'pronamic_ideal' ), | |
$select_field, | |
$select_operator, | |
$select_value | |
); | |
?> | |
</div> | |
<div id="gf_ideal_condition_message"> | |
<span class="description"><?php _e( 'To create a condition, your form must have a drop down, checkbox or multiple choice field.', 'pronamic_ideal' ); ?></span> | |
</div> | |
</td> | |
</tr> | |
</table> | |
<h4><?php _e( 'Delay', 'pronamic_ideal' ); ?></h4> | |
<table class="form-table"> | |
<tr> | |
<th scope="row"> | |
<?php _e( 'Send Notifications Delay', 'pronamic_ideal' ); ?> | |
</th> | |
<td> | |
<?php | |
$delay_notification_ids = get_post_meta( $post_id, '_pronamic_pay_gf_delay_notification_ids', true ); | |
if ( ! is_array( $delay_notification_ids ) ) { | |
$delay_notification_ids = array(); | |
} | |
$delay_admin_notification = get_post_meta( $post_id, '_pronamic_pay_gf_delay_admin_notification', true ); | |
$delay_user_notification = get_post_meta( $post_id, '_pronamic_pay_gf_delay_user_notification', true ); | |
?> | |
<?php if ( version_compare( GFCommon::$version, '1.7', '>=' ) ) : ?> | |
<input name="gf_ideal_selected_notifications_parent" type="checkbox" class="gf_ideal_delay_notifications" value="1" id="gf_ideal_delay_notifications" <?php checked( ! empty( $delay_notification_ids ) ); ?>/> | |
<label for="gf_ideal_delay_notifications"> | |
<?php _e( 'Send notifications only when payment is received.', 'pronamic_ideal' ); ?> | |
</label> | |
<div class="pronamic-pay-gf-notifications"> | |
<?php | |
$notifications = array(); | |
if ( isset( $form_meta['notifications'] ) && is_array( $form_meta['notifications'] ) ) { | |
$notifications = $form_meta['notifications']; | |
} | |
if ( ! empty( $notifications ) ) { | |
printf( '<ul>' ); | |
foreach ( $notifications as $notification ) { | |
$id = $notification['id']; | |
printf( '<li>' ); | |
printf( | |
'<input id="%s" type="checkbox" value="%s" name="_pronamic_pay_gf_delay_notification_ids[]" %s />', | |
esc_attr( 'pronamic-pay-gf-notification-' . $id ), | |
esc_attr( $id ), | |
checked( in_array( $id, $delay_notification_ids ), true, false ) | |
); | |
printf( ' ' ); | |
printf( | |
'<label class="inline" for="%s">%s</label>', | |
esc_attr( 'pronamic-pay-gf-notification-' . $id ), | |
$notification['name'] | |
); | |
printf( '</li>' ); | |
} | |
printf( '</ul>' ); | |
} | |
?> | |
</div> | |
<?php else : ?> | |
<ul> | |
<li id="gf_ideal_delay_admin_notification_item"> | |
<input type="checkbox" name="_pronamic_pay_gf_delay_admin_notification" id="gf_ideal_delay_admin_notification" value="true" <?php checked( $delay_admin_notification ); ?> /> | |
<label for="gf_ideal_delay_admin_notification"> | |
<?php _e( 'Send admin notification only when payment is received.', 'pronamic_ideal' ); ?> | |
</label> | |
</li> | |
<li id="gf_ideal_delay_user_notification_item"> | |
<input type="checkbox" name="_pronamic_pay_gf_delay_user_notification" id="gf_ideal_delay_user_notification" value="true" <?php checked( $delay_user_notification ); ?> /> | |
<label for="gf_ideal_delay_user_notification"> | |
<?php _e( 'Send user notification only when payment is received.', 'pronamic_ideal' ); ?> | |
</label> | |
</li> | |
<li id="gf_ideal_delay_post_creation_item"> | |
</li> | |
</ul> | |
<?php endif; ?> | |
</td> | |
</tr> | |
<tr> | |
<?php | |
$delay_post_creation = get_post_meta( $post_id, '_pronamic_pay_gf_delay_post_creation', true ); | |
?> | |
<th scope="row"> | |
<?php _e( 'Create Post Delay', 'pronamic_ideal' ); ?> | |
</th> | |
<td> | |
<input type="checkbox" name="_pronamic_pay_gf_delay_post_creation" id="_pronamic_pay_gf_delay_post_creation" value="true" <?php checked( $delay_post_creation ); ?> /> | |
<label for="_pronamic_pay_gf_delay_post_creation"> | |
<?php _e( 'Create post only when payment is received.', 'pronamic_ideal' ); ?> | |
</label> | |
</td> | |
</tr> | |
<?php if ( class_exists( 'GFAWeber' ) ) : ?> | |
<tr> | |
<?php | |
$delay_aweber_subscription = get_post_meta( $post_id, '_pronamic_pay_gf_delay_aweber_subscription', true ); | |
?> | |
<th scope="row"> | |
<?php _e( 'AWeber Subscription Delay', 'pronamic_ideal' ); ?> | |
</th> | |
<td> | |
<input type="checkbox" name="_pronamic_pay_gf_delay_aweber_subscription" id="_pronamic_pay_gf_delay_aweber_subscription" value="true" <?php checked( $delay_aweber_subscription ); ?> /> | |
<label for="_pronamic_pay_gf_delay_aweber_subscription"> | |
<?php _e( 'Subscribe user to AWeber only when payment is received.', 'pronamic_ideal' ); ?> | |
</label> | |
</td> | |
</tr> | |
<?php endif; ?> | |
<?php if ( class_exists( 'GFCampaignMonitor' ) ) : ?> | |
<tr> | |
<?php | |
$delay_campaignmonitor_subscription = get_post_meta( $post_id, '_pronamic_pay_gf_delay_campaignmonitor_subscription', true ); | |
?> | |
<th scope="row"> | |
<?php _e( 'Campaign Monitor Subscription Delay', 'pronamic_ideal' ); ?> | |
</th> | |
<td> | |
<input type="checkbox" name="_pronamic_pay_gf_delay_campaignmonitor_subscription" id="_pronamic_pay_gf_delay_campaignmonitor_subscription" value="true" <?php checked( $delay_campaignmonitor_subscription ); ?> /> | |
<label for="_pronamic_pay_gf_delay_campaignmonitor_subscription"> | |
<?php _e( 'Subscribe user to Campaign Monitor only when payment is received.', 'pronamic_ideal' ); ?> | |
</label> | |
</td> | |
</tr> | |
<?php endif; ?> | |
<?php if ( class_exists( 'GFMailChimp' ) ) : ?> | |
<tr> | |
<?php | |
$delay_mailchimp_subscription = get_post_meta( $post_id, '_pronamic_pay_gf_delay_mailchimp_subscription', true ); | |
?> | |
<th scope="row"> | |
<?php _e( 'MailChimp Subscription Delay', 'pronamic_ideal' ); ?> | |
</th> | |
<td> | |
<input type="checkbox" name="_pronamic_pay_gf_delay_mailchimp_subscription" id="_pronamic_pay_gf_delay_mailchimp_subscription" value="true" <?php checked( $delay_mailchimp_subscription ); ?> /> | |
<label for="_pronamic_pay_gf_delay_mailchimp_subscription"> | |
<?php _e( 'Subscribe user to MailChimp only when payment is received.', 'pronamic_ideal' ); ?> | |
</label> | |
</td> | |
</tr> | |
<?php endif; ?> | |
<?php if ( class_exists( 'GFZapier' ) ) : ?> | |
<tr> | |
<?php | |
$delay_zapier = get_post_meta( $post_id, '_pronamic_pay_gf_delay_zapier', true ); | |
?> | |
<th scope="row"> | |
<?php _e( 'Zapier Delay', 'pronamic_ideal' ); ?> | |
</th> | |
<td> | |
<input type="checkbox" name="_pronamic_pay_gf_delay_zapier" id="_pronamic_pay_gf_delay_zapier" value="true" <?php checked( $delay_zapier ); ?> /> | |
<label for="_pronamic_pay_gf_delay_zapier"> | |
<?php _e( 'Send data to Zapier only when payment is received.', 'pronamic_ideal' ); ?> | |
</label> | |
</td> | |
</tr> | |
<?php endif; ?> | |
<?php if ( class_exists( 'GFUser' ) ) : ?> | |
<tr> | |
<?php | |
$delay_user_registration = get_post_meta( $post_id, '_pronamic_pay_gf_delay_user_registration', true ); | |
?> | |
<th scope="row"> | |
<?php _e( 'User Registration Delay', 'pronamic_ideal' ); ?> | |
</th> | |
<td> | |
<input type="checkbox" name="_pronamic_pay_gf_delay_user_registration" id="_pronamic_pay_gf_delay_user_registration" value="true" <?php checked( $delay_user_registration ); ?> /> | |
<label for="_pronamic_pay_gf_delay_user_registration"> | |
<?php _e( 'Register user only when a payment is received.', 'pronamic_ideal' ); ?> | |
</label> | |
</td> | |
</tr> | |
<?php endif; ?> | |
</table> | |
<h4> | |
<?php _e( 'Fields', 'pronamic_ideal' ); ?> | |
</h4> | |
<?php | |
$fields = array( | |
'first_name' => __( 'First Name', 'pronamic_ideal' ), | |
'last_name' => __( 'Last Name', 'pronamic_ideal' ), | |
'email' => __( 'Email', 'pronamic_ideal' ), | |
'address1' => __( 'Address', 'pronamic_ideal' ), | |
'address2' => __( 'Address 2', 'pronamic_ideal' ), | |
'city' => __( 'City', 'pronamic_ideal' ), | |
'state' => __( 'State', 'pronamic_ideal' ), | |
'zip' => __( 'Zip', 'pronamic_ideal' ), | |
'country' => __( 'Country', 'pronamic_ideal' ), | |
); | |
?> | |
<table class="form-table"> | |
<?php foreach ( $fields as $name => $label ) : ?> | |
<tr> | |
<th scope="row"> | |
<?php echo $label; ?> | |
</th> | |
<td> | |
<?php | |
printf( | |
'<select id="%s" name="%s" data-gateway-field-name="%s" class="field-select"><select>', | |
esc_attr( 'gf_ideal_fields_' . $name ), | |
esc_attr( '_pronamic_pay_gf_fields[' . $name . ']' ), | |
esc_attr( $name ) | |
); | |
?> | |
</td> | |
</tr> | |
<?php endforeach; ?> | |
</table> | |
<h4> | |
<?php _e( 'Status Links', 'pronamic_ideal' ); ?> | |
</h4> | |
<table class="form-table"> | |
<?php | |
$links = get_post_meta( $post_id, '_pronamic_pay_gf_links', true ); | |
$links = is_array( $links ) ? $links : array(); | |
$fields = array( | |
Pronamic_WP_Pay_Extensions_GravityForms_Links::OPEN => __( 'Open', 'pronamic_ideal' ), | |
Pronamic_WP_Pay_Extensions_GravityForms_Links::SUCCESS => __( 'Success', 'pronamic_ideal' ), | |
Pronamic_WP_Pay_Extensions_GravityForms_Links::CANCEL => __( 'Cancel', 'pronamic_ideal' ), | |
Pronamic_WP_Pay_Extensions_GravityForms_Links::ERROR => __( 'Error', 'pronamic_ideal' ), | |
Pronamic_WP_Pay_Extensions_GravityForms_Links::EXPIRED => __( 'Expired', 'pronamic_ideal' ), | |
); | |
foreach ( $fields as $name => $label ) : ?> | |
<tr> | |
<?php | |
$type = @$links[ $name ]['type']; | |
$page_id = @$links[ $name ]['page_id']; | |
$url = @$links[ $name ]['url']; | |
?> | |
<th scope="row"> | |
<label for="gf_ideal_link_<?php echo $name; ?>_page"> | |
<?php echo $label; ?> | |
</label> | |
</th> | |
<td> | |
<fieldset> | |
<legend class="screen-reader-text"> | |
<span><?php echo $label; ?></span> | |
</legend> | |
<label> | |
<input type="radio" name="_pronamic_pay_gf_links[<?php echo $name; ?>][type]" id="gf_ideal_link_<?php echo $name; ?>_page" value="page" <?php checked( $type, 'page' ); ?> /> | |
<?php _e( 'Page:', 'pronamic_ideal' ); ?> | |
</label> | |
<?php | |
wp_dropdown_pages( array( | |
'selected' => $page_id, | |
'name' => '_pronamic_pay_gf_links[' . $name . '][page_id]', | |
'show_option_none' => __( '— Select —', 'pronamic_ideal' ), | |
) ); | |
?> | |
<br /> | |
<label> | |
<input type="radio" name="_pronamic_pay_gf_links[<?php echo $name; ?>][type]" id="gf_ideal_link_<?php echo $name; ?>_url" value="url" <?php checked( $type, 'url' ); ?> /> | |
<?php _e( 'URL:', 'pronamic_ideal' ); ?> | |
</label> <input type="text" name="_pronamic_pay_gf_links[<?php echo $name; ?>][url]" value="<?php echo esc_attr( $url ); ?>" class="regular-text" /> | |
</fieldset> | |
<td> | |
</tr> | |
<?php endforeach; ?> | |
</table> | |
<h4> | |
<?php _e( 'Advanced', 'pronamic_ideal' ); ?> | |
</h4> | |
<table class="form-table"> | |
<tr> | |
<th scope="row"> | |
<label for="gf_ideal_user_role_field_id"> | |
<?php _e( 'Update user role', 'pronamic_ideal' ); ?> | |
</label> | |
</th> | |
<td> | |
<select id="gf_ideal_user_role_field_id" name="_pronamic_pay_gf_user_role_field_id"> | |
</select> | |
</td> | |
</tr> | |
</table> | |
<?php submit_button(); ?> | |
</div> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment