Skip to content

Commit

Permalink
Merge pull request #23 from atarime/add-function-to-determine-plugin-…
Browse files Browse the repository at this point in the history
…loading

Add function to determine plugin loading
  • Loading branch information
kznakata authored Dec 19, 2024
2 parents d81d7aa + b0e1631 commit 2c4e1f7
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions includes/class-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,18 @@ final class Forms {
* @access public
*/
public function __construct() {
if ( ! is_admin() ) {
if ( did_action( 'fmpress_forms_pro_loaded' ) ) {
$this->update_form = new Update_Form( $this );
}
if ( is_admin() ) {
return;
}

add_action( 'the_post', array( $this, 'prepare_form' ), 9 );
add_action( 'wpcf7_before_send_mail', array( $this, 'post' ), 10, 3 );
add_action( 'wpcf7_skip_mail', array( $this, 'set_skip_mail' ), 10, 2 );
add_filter( 'wpcf7_submission_result', array( $this, 'set_error' ), 10, 2 );
if ( $this->is_enabled_fmpress_forms_pro() ) {
$this->update_form = new Update_Form( $this );

Check failure on line 122 in includes/class-forms.php

View workflow job for this annotation

GitHub Actions / Run PHPStan (0)

Instantiated class Emic\FMPress\Forms\Update_Form not found.
}

add_action( 'the_post', array( $this, 'prepare_form' ), 9 );
add_action( 'wpcf7_before_send_mail', array( $this, 'post' ), 10, 3 );
add_action( 'wpcf7_skip_mail', array( $this, 'set_skip_mail' ), 10, 2 );
add_filter( 'wpcf7_submission_result', array( $this, 'set_error' ), 10, 2 );
}

/**
Expand Down Expand Up @@ -261,7 +263,7 @@ public function prepare_form() {
$fm_value_list = new Fm_Value_List();
add_filter( 'wpcf7_form_tag', array( $fm_value_list, 'generate_custom_select' ), 10, 1 );

if ( did_action( 'fmpress_forms_pro_loaded' ) ) {
if ( $this->is_enabled_fmpress_forms_pro() ) {
// Set up the form for updating.
add_filter( 'wpcf7_form_tag', array( $this->update_form, 'set_up_form_for_update' ), 11, 1 );
}
Expand Down Expand Up @@ -564,7 +566,7 @@ private function format_posted_data( $cf7_settings, $posted_data ) {
}
}

if ( did_action( 'fmpress_forms_pro_loaded' ) ) {
if ( $this->is_enabled_fmpress_forms_pro() ) {
if ( '1' === $cf7_settings['form_mode'] && ! empty( $cf7_settings['external_table_key_field'] ) ) {
// Create mode.
// Add primary field and value.
Expand Down Expand Up @@ -631,4 +633,15 @@ private function get_group_of_field_type( $tag ) {
}
return $group;
}

/**
* Determine if FMPress Form Pro plugin is enabled.
*
* @since 1.3.2
* @access private
* @return bool
*/
private function is_enabled_fmpress_forms_pro() {
return 1 === did_action( 'fmpress_forms_pro_loaded' ) ? true : false;
}
}

0 comments on commit 2c4e1f7

Please sign in to comment.