condition-author.php
1 year ago
condition-device.php
1 year ago
condition-is-or-not.php
1 year ago
condition-number.php
3 years ago
condition-operator.php
1 year ago
condition-string.php
2 years ago
conditions-form.php
5 months ago
display-conditions-list.php
1 year ago
no-option.php
1 year ago
not-selected.php
4 years ago
visitor-conditions-list.php
1 year ago
display-conditions-list.php
101 lines
| 1 | <?php |
| 2 | /** |
| 3 | * HTML code to show all the conditions in metabox |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | */ |
| 7 | |
| 8 | ?> |
| 9 | <table id="<?php echo esc_attr( $list_target ); ?>" class="advads-conditions-table"> |
| 10 | <tbody> |
| 11 | <?php |
| 12 | $last_index = - 1; |
| 13 | $i = 0; |
| 14 | if ( is_array( $set_conditions ) ) : |
| 15 | foreach ( $set_conditions as $_index => $_options ) : |
| 16 | $show_or_force_warning = false; |
| 17 | $show_is_not_or_warning = false; |
| 18 | // get type attribute from previous option format. |
| 19 | $_options['type'] = isset( $_options['type'] ) ? $_options['type'] : $_index; |
| 20 | $connector = ( ! isset( $_options['connector'] ) || 'or' !== $_options['connector'] ) ? 'and' : 'or'; |
| 21 | $operator = ! isset( $_options['operator'] ) || 'is_not' !== $_options['operator'] ? 'is' : 'is_not'; |
| 22 | if ( isset( $_options['type'] ) && isset( $conditions[ $_options['type'] ]['metabox'] ) ) { |
| 23 | $metabox = $conditions[ $_options['type'] ]['metabox']; |
| 24 | } else { |
| 25 | continue; |
| 26 | } |
| 27 | if ( method_exists( $metabox[0], $metabox[1] ) ) { |
| 28 | /** |
| 29 | * Show warning for connector when |
| 30 | * not set to OR already |
| 31 | * this condition and the previous are on page level and not from the identical type |
| 32 | * they are both set to SHOW |
| 33 | */ |
| 34 | $taxonomy = isset( $_options['type'] ) && isset( $conditions[ $_options['type'] ]['taxonomy'] ) ? $conditions[ $_options['type'] ]['taxonomy'] : false; // phpcs:ignore |
| 35 | $last_tax = isset( $set_conditions[ $last_index ]['type'] ) && isset( $conditions[ $set_conditions[ $last_index ]['type'] ]['taxonomy'] ) ? $conditions[ $set_conditions[ $last_index ]['type'] ]['taxonomy'] : false; |
| 36 | if ( |
| 37 | $taxonomy && $last_tax && $last_tax === $taxonomy |
| 38 | && ( ! isset( $_options['connector'] ) || 'or' !== $_options['connector'] ) |
| 39 | && 'is' === $operator && 'is' === $set_conditions[ $last_index ]['operator'] |
| 40 | && $_options['type'] !== $set_conditions[ $last_index ]['type'] |
| 41 | ) { |
| 42 | $show_or_force_warning = true; |
| 43 | } |
| 44 | |
| 45 | if ( |
| 46 | 'is_not' === $operator |
| 47 | && 'or' === $connector |
| 48 | && isset( $set_conditions[ $last_index ]['operator'] ) |
| 49 | && 'is_not' === $set_conditions[ $last_index ]['operator'] |
| 50 | ) { |
| 51 | $show_is_not_or_warning = true; |
| 52 | } |
| 53 | |
| 54 | if ( $i > 0 ) : |
| 55 | ?> |
| 56 | <tr class="advads-conditions-connector advads-conditions-connector-<?php echo esc_attr( $connector ); ?>"> |
| 57 | <td colspan="3"> |
| 58 | <?php |
| 59 | echo Advanced_Ads_Display_Conditions::render_connector_option( $i, $connector, $form_name ); // phpcs:ignore |
| 60 | if ( $show_or_force_warning || $show_is_not_or_warning ) { |
| 61 | ?> |
| 62 | <p class="advads-notice-inline advads-error" style="display: block;"> |
| 63 | <?php |
| 64 | if ( $show_or_force_warning ) { |
| 65 | esc_attr_e( 'Forced to OR.', 'advanced-ads' ); |
| 66 | echo ' <a target="_blank" href="https://wpadvancedads.com/manual/display-conditions#manual-combining-multiple-conditions">' . esc_attr__( 'manual', 'advanced-ads' ) . '</a>'; |
| 67 | } else { |
| 68 | esc_attr_e( 'The ad might always show due to OR and "is not". Better use AND.', 'advanced-ads' ); |
| 69 | echo ' <a target="_blank" href="https://wpadvancedads.com/manual/display-conditions/#Combining_conditions_with_AND_and_OR">' . esc_attr__( 'manual', 'advanced-ads' ) . '</a>'; |
| 70 | } |
| 71 | ?> |
| 72 | </p> |
| 73 | <?php |
| 74 | |
| 75 | } |
| 76 | ?> |
| 77 | </td> |
| 78 | </tr> |
| 79 | <?php endif; ?> |
| 80 | <tr> |
| 81 | <td class="advads-conditions-type" |
| 82 | data-condition-type="<?php echo esc_attr( $_options['type'] ); ?>"><?php echo esc_html( $conditions[ $_options['type'] ]['label'] ); ?> |
| 83 | </td> |
| 84 | <td> |
| 85 | <?php |
| 86 | call_user_func( [ $metabox[0], $metabox[1] ], $_options, $i++, $form_name ); |
| 87 | ?> |
| 88 | </td> |
| 89 | <td> |
| 90 | <button type="button" class="advads-conditions-remove button">x</button> |
| 91 | </td> |
| 92 | </tr> |
| 93 | <?php |
| 94 | } |
| 95 | $last_index = $_index; |
| 96 | endforeach; |
| 97 | endif; |
| 98 | ?> |
| 99 | </tbody> |
| 100 | </table> |
| 101 |