get_base_url() . '/images/sliced-invoices-icon.svg'; } /** * Returns the settings for this step. * * @since 1.6.1-dev-2 Added the Step Completion setting. * * @return array */ public function get_settings() { $settings = parent::get_settings(); if ( ! $this->is_supported() ) { return $settings; } $settings_api = $this->get_common_settings_api(); $fields = array( $settings_api->get_setting_assignee_type(), $settings_api->get_setting_assignees(), $settings_api->get_setting_assignee_routing(), $settings_api->get_setting_notification_tabs( array( array( 'label' => __( 'Assignee Email', 'gravityflow' ), 'id' => 'tab_assignee_notification', 'fields' => $settings_api->get_setting_notification( array( 'type' => 'assignee', ) ), ) ) ), $settings_api->get_setting_instructions(), $settings_api->get_setting_display_fields(), array( 'name' => 'post_feed_completion', 'type' => 'select', 'label' => __( 'Step Completion', 'gravityflow' ), 'choices' => array( array( 'label' => __( 'Immediately following feed processing', 'gravityflow' ), 'value' => '' ), array( 'label' => __( 'Delay until invoices are paid', 'gravityflow' ), 'value' => 'delayed' ), ), ) ); $settings['fields'] = array_merge( $settings['fields'], $fields ); return $settings; } /** * Processes this step. * * @since 1.6.1-dev-2 * * @return bool Is the step complete? */ public function process() { $complete = parent::process(); $this->assign(); return $complete; } /** * Processes the given feed for the add-on. * * @since 1.6.1-dev-2 * * @param array $feed The feed to be processed. * * @return bool Returning false if the feed created an invoice to ensure the next step is not processed until after the invoice is paid. */ public function process_feed( $feed ) { add_action( 'sliced_gravityforms_feed_processed', array( $this, 'sliced_gravityforms_feed_processed' ), 1, 3 ); parent::process_feed( $feed ); remove_action( 'sliced_gravityforms_feed_processed', array( $this, 'sliced_gravityforms_feed_processed' ), 1 ); return rgars( $feed, 'meta/post_type' ) !== 'invoice' || $this->post_feed_completion !== 'delayed' ? true : false; } /** * Perform any actions once the invoice/quote has been created. * * @since 1.6.1-dev-2 * * @param int $id The invoice (post) ID. * @param array $feed The feed which created the invoice. * @param array $entry The entry which created the invoice. */ public function sliced_gravityforms_feed_processed( $id, $feed, $entry ) { if ( rgars( $feed, 'meta/post_type' ) === 'invoice' && $this->post_feed_completion === 'delayed' ) { // Store the IDs so we can complete the step once the invoice is paid. update_post_meta( $id, '_gform-entry-id', rgar( $entry, 'id' ) ); update_post_meta( $id, '_gform-feed-id', rgar( $feed, 'id' ) ); update_post_meta( $id, '_gravityflow-step-id', $this->get_id() ); if ( function_exists( 'sliced_get_accepted_payment_methods' ) ) { update_post_meta( $id, '_sliced_payment_methods', array_keys( sliced_get_accepted_payment_methods() ) ); } } } /** * Display the workflow detail box for this step. * * @since 1.6.1-dev-2 * * @param array $form The current form. * @param array $args The page arguments. */ public function workflow_detail_box( $form, $args ) { $args = array( 'post_type' => 'sliced_invoice', 'meta_query' => array( array( 'key' => '_gform-entry-id', 'value' => $this->get_entry_id(), ), array( 'key' => '_gravityflow-step-id', 'value' => $this->get_id(), ), ), ); $invoices = get_posts( $args ); if ( ! empty( $invoices ) ) { echo sprintf( '