ThemeAvenue /
BetterOptin
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * BetterOptin Provider MailPoet |
||
| 4 | * |
||
| 5 | * @package BetterOptin/Provider/MailChimp |
||
| 6 | * @author ThemeAvenue <[email protected]> |
||
| 7 | * @license GPL-2.0+ |
||
| 8 | * @link http://themeavenue.net |
||
| 9 | * @copyright 2015 ThemeAvenue |
||
| 10 | */ |
||
| 11 | |||
| 12 | // If this file is called directly, abort. |
||
| 13 | if ( ! defined( 'WPINC' ) ) { |
||
| 14 | die; |
||
| 15 | } |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Check if MailChimp settings are correct. |
||
| 19 | * |
||
| 20 | * @since 1.0.0 |
||
| 21 | * @return boolean True if MailPoet integration is ready to work |
||
| 22 | */ |
||
| 23 | function wpbo_is_mailpoet_ready() { |
||
| 24 | |||
| 25 | $list_id = wpbo_get_option( 'mp_list_id', '' ); |
||
| 26 | |||
| 27 | if ( empty( $list_id ) ) { |
||
| 28 | return false; |
||
| 29 | } |
||
| 30 | |||
| 31 | return true; |
||
| 32 | |||
| 33 | } |
||
| 34 | |||
| 35 | add_action( 'admin_notices', 'wpbo_mp_settings_warning' ); |
||
| 36 | /** |
||
| 37 | * User warning. |
||
| 38 | * |
||
| 39 | * Warn user if settings are not correct. |
||
| 40 | * |
||
| 41 | * @since 1.0.0 |
||
| 42 | */ |
||
| 43 | View Code Duplication | function wpbo_mp_settings_warning() { |
|
|
0 ignored issues
–
show
|
|||
| 44 | |||
| 45 | if ( ! wpbo_is_mailpoet_ready() ): ?> |
||
| 46 | |||
| 47 | <div class="error"> |
||
| 48 | <p><?php printf( __( 'Please select a list for your new subscribers, otherwise your popups won\'t send subscribers anywhere! <a href="%s">Click here to see the settings</a>.', 'betteroptin' ), esc_url( add_query_arg( array( |
||
| 49 | 'post_type' => 'wpbo-popup', |
||
| 50 | 'page' => 'edit.php?post_type=wpbo-popup-settings&tab=mailpoet' |
||
| 51 | ), admin_url( 'edit.php' ) ) ) ); ?></p> |
||
| 52 | </div> |
||
| 53 | |||
| 54 | <?php endif; |
||
| 55 | |||
| 56 | } |
||
| 57 | |||
| 58 | add_filter( 'wpbo_checklist', 'wpbo_mp_add_step' ); |
||
| 59 | /** |
||
| 60 | * Add new step. |
||
| 61 | * |
||
| 62 | * Add a step in the checklist during popup creation process |
||
| 63 | * in order to was the user if the settings are not correct. |
||
| 64 | * |
||
| 65 | * @since 1.0.0 |
||
| 66 | * |
||
| 67 | * @param array $checklist Current checklist |
||
| 68 | * |
||
| 69 | * @return array Updated checklist |
||
| 70 | */ |
||
| 71 | function wpbo_mp_add_step( $checklist ) { |
||
| 72 | |||
| 73 | $ready = wpbo_is_mailpoet_ready() ? true : false; |
||
| 74 | $new = array(); |
||
| 75 | $step = array( |
||
| 76 | 'label' => __( 'Setup MailPoet', 'betteroptin' ), |
||
| 77 | 'check' => $ready, |
||
| 78 | 'against' => true, |
||
| 79 | 'compare' => 'EQUAL' |
||
| 80 | ); |
||
| 81 | |||
| 82 | foreach ( $checklist as $id => $check ) { |
||
| 83 | |||
| 84 | if ( 'published' == $id ) { |
||
| 85 | $new['mailpoet'] = $step; |
||
| 86 | } |
||
| 87 | |||
| 88 | $new[ $id ] = $check; |
||
| 89 | |||
| 90 | } |
||
| 91 | |||
| 92 | return $new; |
||
| 93 | |||
| 94 | } |
||
| 95 | |||
| 96 | add_filter( 'wpbo_publish_button_action', 'wpbo_mp_prevent_publishing', 10, 2 ); |
||
| 97 | /** |
||
| 98 | * Prevent from publishing popup if MailPoet is not ready. |
||
| 99 | * |
||
| 100 | * @since 1.0.0 |
||
| 101 | * |
||
| 102 | * @param array $data Sanitized data |
||
| 103 | * @param array $postarr Raw data |
||
| 104 | * |
||
| 105 | * @return array Sanitized data with updated status |
||
| 106 | */ |
||
| 107 | View Code Duplication | function wpbo_mp_prevent_publishing( $data, $postarr ) { |
|
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 108 | |||
| 109 | if ( 'wpbo-popup' == $postarr['post_type'] && 'publish' == $data['post_status'] ) { |
||
| 110 | |||
| 111 | if ( ! wpbo_is_mailpoet_ready() ) { |
||
| 112 | $data['post_status'] = 'draft'; |
||
| 113 | } |
||
| 114 | |||
| 115 | } |
||
| 116 | |||
| 117 | return $data; |
||
| 118 | |||
| 119 | } |
||
| 120 | |||
| 121 | add_filter( 'wpbo_publish_button_label', 'wpbo_mp_publish_button_label', 10, 2 ); |
||
| 122 | /** |
||
| 123 | * Change the "Publish" button label |
||
| 124 | * |
||
| 125 | * @param $translation |
||
| 126 | * @param $text |
||
| 127 | * |
||
| 128 | * @return string |
||
| 129 | */ |
||
| 130 | View Code Duplication | function wpbo_mp_publish_button_label( $translation, $text ) { |
|
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 131 | |||
| 132 | global $typenow; |
||
| 133 | |||
| 134 | if ( 'wpbo-popup' == $typenow ) { |
||
| 135 | |||
| 136 | if ( isset( $_GET['post'] ) && 'Publish' == $text && ! wpbo_is_mailpoet_ready() ) { |
||
| 137 | $translation = __( 'Save', 'betteroptin' ); |
||
| 138 | } |
||
| 139 | |||
| 140 | } |
||
| 141 | |||
| 142 | return $translation; |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Get user lists. |
||
| 147 | * |
||
| 148 | * @since 1.0.0 |
||
| 149 | * @return array Array of available lists for this account |
||
| 150 | */ |
||
| 151 | function wpbo_mp_get_mailpoet_lists() { |
||
| 152 | |||
| 153 | if ( ! class_exists( 'WYSIJA' ) ) { |
||
| 154 | return array(); |
||
| 155 | } |
||
| 156 | |||
| 157 | $model_list = WYSIJA::get( 'list', 'model' ); |
||
| 158 | $mailpoet_lists = $model_list->get( array( 'name', 'list_id' ), array( 'is_enabled' => 1 ) ); |
||
| 159 | |||
| 160 | return $mailpoet_lists; |
||
| 161 | |||
| 162 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.