@@ -1,62 +1,62 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | $too_complicate_reason_label = sprintf( |
| 3 | - '<a target="_blank" href="%s">%s</a>', |
|
| 4 | - /* translators: the link https://wordlift.io/contact-us/ should be changed to language version of the page */ |
|
| 5 | - esc_attr__( 'https://wordlift.io/contact-us/', 'wordlift' ), |
|
| 6 | - esc_html__( 'Contact Us', 'wordlift' ) |
|
| 3 | + '<a target="_blank" href="%s">%s</a>', |
|
| 4 | + /* translators: the link https://wordlift.io/contact-us/ should be changed to language version of the page */ |
|
| 5 | + esc_attr__( 'https://wordlift.io/contact-us/', 'wordlift' ), |
|
| 6 | + esc_html__( 'Contact Us', 'wordlift' ) |
|
| 7 | 7 | ); |
| 8 | 8 | |
| 9 | 9 | $reasons = array( |
| 10 | - array( |
|
| 11 | - 'id' => 'TOO_COMPLICATED', |
|
| 12 | - 'text' => esc_html__( 'It was too complicated and unclear to me', 'wordlift' ), |
|
| 13 | - 'message' => array( |
|
| 14 | - 'text' => sprintf( |
|
| 15 | - esc_html__( 'Need help? We are ready to answer your questions. %s', 'wordlift' ), |
|
| 16 | - $too_complicate_reason_label |
|
| 17 | - ), |
|
| 18 | - ), |
|
| 19 | - ), |
|
| 20 | - array( |
|
| 21 | - 'id' => 'NOT_ENOUGH_FEATURES', |
|
| 22 | - 'text' => esc_html__( 'It misses some important feature to me', 'wordlift' ), |
|
| 23 | - 'message' => array( |
|
| 24 | - 'field' => 'text', |
|
| 25 | - 'text' => esc_html__( 'Tell us what this feature is.', 'wordlift' ), |
|
| 26 | - ), |
|
| 27 | - ), |
|
| 28 | - array( |
|
| 29 | - 'id' => 'COSTS_TOO_MUCH', |
|
| 30 | - 'text' => esc_html__( 'It costs too much', 'wordlift' ), |
|
| 31 | - 'message' => array( |
|
| 32 | - 'field' => 'text', |
|
| 33 | - 'text' => esc_html__( 'How much you would like to pay?', 'wordlift' ), |
|
| 34 | - ), |
|
| 35 | - ), |
|
| 36 | - array( |
|
| 37 | - 'id' => 'FOUND_ANOTHER_TOOL', |
|
| 38 | - 'text' => esc_html__( 'I found another tool that I like better', 'wordlift' ), |
|
| 39 | - 'message' => array( |
|
| 40 | - 'field' => 'text', |
|
| 41 | - 'text' => esc_html__( 'Please tell us some more details.', 'wordlift' ), |
|
| 42 | - ), |
|
| 43 | - ), |
|
| 44 | - array( |
|
| 45 | - 'id' => 'I_DONT_USE_IT', |
|
| 46 | - 'text' => esc_html__( 'I\'m not using it right now', 'wordlift' ), |
|
| 47 | - ), |
|
| 48 | - array( |
|
| 49 | - 'id' => 'SOMETHING_DIDNT_WORK', |
|
| 50 | - 'text' => esc_html__( 'Something didn\'t work right', 'wordlift' ), |
|
| 51 | - ), |
|
| 52 | - array( |
|
| 53 | - 'id' => 'ANOTHER_REASON', |
|
| 54 | - 'text' => esc_html__( 'Another reason', 'wordlift' ), |
|
| 55 | - 'message' => array( |
|
| 56 | - 'field' => 'textarea', |
|
| 57 | - 'text' => esc_html__( 'Please tell us the reason so we can improve it.', 'wordlift' ), |
|
| 58 | - ), |
|
| 59 | - ), |
|
| 10 | + array( |
|
| 11 | + 'id' => 'TOO_COMPLICATED', |
|
| 12 | + 'text' => esc_html__( 'It was too complicated and unclear to me', 'wordlift' ), |
|
| 13 | + 'message' => array( |
|
| 14 | + 'text' => sprintf( |
|
| 15 | + esc_html__( 'Need help? We are ready to answer your questions. %s', 'wordlift' ), |
|
| 16 | + $too_complicate_reason_label |
|
| 17 | + ), |
|
| 18 | + ), |
|
| 19 | + ), |
|
| 20 | + array( |
|
| 21 | + 'id' => 'NOT_ENOUGH_FEATURES', |
|
| 22 | + 'text' => esc_html__( 'It misses some important feature to me', 'wordlift' ), |
|
| 23 | + 'message' => array( |
|
| 24 | + 'field' => 'text', |
|
| 25 | + 'text' => esc_html__( 'Tell us what this feature is.', 'wordlift' ), |
|
| 26 | + ), |
|
| 27 | + ), |
|
| 28 | + array( |
|
| 29 | + 'id' => 'COSTS_TOO_MUCH', |
|
| 30 | + 'text' => esc_html__( 'It costs too much', 'wordlift' ), |
|
| 31 | + 'message' => array( |
|
| 32 | + 'field' => 'text', |
|
| 33 | + 'text' => esc_html__( 'How much you would like to pay?', 'wordlift' ), |
|
| 34 | + ), |
|
| 35 | + ), |
|
| 36 | + array( |
|
| 37 | + 'id' => 'FOUND_ANOTHER_TOOL', |
|
| 38 | + 'text' => esc_html__( 'I found another tool that I like better', 'wordlift' ), |
|
| 39 | + 'message' => array( |
|
| 40 | + 'field' => 'text', |
|
| 41 | + 'text' => esc_html__( 'Please tell us some more details.', 'wordlift' ), |
|
| 42 | + ), |
|
| 43 | + ), |
|
| 44 | + array( |
|
| 45 | + 'id' => 'I_DONT_USE_IT', |
|
| 46 | + 'text' => esc_html__( 'I\'m not using it right now', 'wordlift' ), |
|
| 47 | + ), |
|
| 48 | + array( |
|
| 49 | + 'id' => 'SOMETHING_DIDNT_WORK', |
|
| 50 | + 'text' => esc_html__( 'Something didn\'t work right', 'wordlift' ), |
|
| 51 | + ), |
|
| 52 | + array( |
|
| 53 | + 'id' => 'ANOTHER_REASON', |
|
| 54 | + 'text' => esc_html__( 'Another reason', 'wordlift' ), |
|
| 55 | + 'message' => array( |
|
| 56 | + 'field' => 'textarea', |
|
| 57 | + 'text' => esc_html__( 'Please tell us the reason so we can improve it.', 'wordlift' ), |
|
| 58 | + ), |
|
| 59 | + ), |
|
| 60 | 60 | ); |
| 61 | 61 | ?> |
| 62 | 62 | <div class="wl-modal-deactivation-feedback" style="display: none"> |
@@ -92,15 +92,15 @@ discard block |
||
| 92 | 92 | <?php if ( ! empty( $reason['message'] ) ) : ?> |
| 93 | 93 | <div class="additional-info <?php echo ( ! empty( $reason['message']['field'] ) ) ? 'has-field' : ''; ?>"> |
| 94 | 94 | <?php |
| 95 | - if ( ! empty( $reason['message']['field'] ) ) { |
|
| 96 | - if ( $reason['message']['field'] === 'text' ) { |
|
| 97 | - echo '<input type="text" name="wl-details" class="wl-details"/>'; |
|
| 98 | - } else { |
|
| 99 | - echo '<textarea name="wl-details" class="wl-details"></textarea>'; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - echo wp_kses( wpautop( $reason['message']['text'] ), array( 'p' => array() ) ) |
|
| 103 | - ?> |
|
| 95 | + if ( ! empty( $reason['message']['field'] ) ) { |
|
| 96 | + if ( $reason['message']['field'] === 'text' ) { |
|
| 97 | + echo '<input type="text" name="wl-details" class="wl-details"/>'; |
|
| 98 | + } else { |
|
| 99 | + echo '<textarea name="wl-details" class="wl-details"></textarea>'; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + echo wp_kses( wpautop( $reason['message']['text'] ), array( 'p' => array() ) ) |
|
| 103 | + ?> |
|
| 104 | 104 | </div> |
| 105 | 105 | <?php endif ?> |
| 106 | 106 | </li> |
@@ -111,11 +111,11 @@ discard block |
||
| 111 | 111 | <div class="notes"> |
| 112 | 112 | <p> |
| 113 | 113 | <?php |
| 114 | - echo wp_kses( sprintf( |
|
| 115 | - __( 'Important notice: Uninstalling the plugin will delete your vocabulary.<br>Maybe you would like to <a href="%s" target="_blank">download your data</a> first.', 'wordlift' ), |
|
| 116 | - add_query_arg( array( 'page' => 'wl_download_your_data' ), admin_url( 'admin.php' ) ) |
|
| 117 | - ), array( 'br' => array(), 'a' => array( 'href' => array(), 'target' => array() ) ) ); |
|
| 118 | - ?> |
|
| 114 | + echo wp_kses( sprintf( |
|
| 115 | + __( 'Important notice: Uninstalling the plugin will delete your vocabulary.<br>Maybe you would like to <a href="%s" target="_blank">download your data</a> first.', 'wordlift' ), |
|
| 116 | + add_query_arg( array( 'page' => 'wl_download_your_data' ), admin_url( 'admin.php' ) ) |
|
| 117 | + ), array( 'br' => array(), 'a' => array( 'href' => array(), 'target' => array() ) ) ); |
|
| 118 | + ?> |
|
| 119 | 119 | </p> |
| 120 | 120 | </div> |
| 121 | 121 | |
@@ -2,59 +2,59 @@ discard block |
||
| 2 | 2 | $too_complicate_reason_label = sprintf( |
| 3 | 3 | '<a target="_blank" href="%s">%s</a>', |
| 4 | 4 | /* translators: the link https://wordlift.io/contact-us/ should be changed to language version of the page */ |
| 5 | - esc_attr__( 'https://wordlift.io/contact-us/', 'wordlift' ), |
|
| 6 | - esc_html__( 'Contact Us', 'wordlift' ) |
|
| 5 | + esc_attr__('https://wordlift.io/contact-us/', 'wordlift'), |
|
| 6 | + esc_html__('Contact Us', 'wordlift') |
|
| 7 | 7 | ); |
| 8 | 8 | |
| 9 | 9 | $reasons = array( |
| 10 | 10 | array( |
| 11 | 11 | 'id' => 'TOO_COMPLICATED', |
| 12 | - 'text' => esc_html__( 'It was too complicated and unclear to me', 'wordlift' ), |
|
| 12 | + 'text' => esc_html__('It was too complicated and unclear to me', 'wordlift'), |
|
| 13 | 13 | 'message' => array( |
| 14 | 14 | 'text' => sprintf( |
| 15 | - esc_html__( 'Need help? We are ready to answer your questions. %s', 'wordlift' ), |
|
| 15 | + esc_html__('Need help? We are ready to answer your questions. %s', 'wordlift'), |
|
| 16 | 16 | $too_complicate_reason_label |
| 17 | 17 | ), |
| 18 | 18 | ), |
| 19 | 19 | ), |
| 20 | 20 | array( |
| 21 | 21 | 'id' => 'NOT_ENOUGH_FEATURES', |
| 22 | - 'text' => esc_html__( 'It misses some important feature to me', 'wordlift' ), |
|
| 22 | + 'text' => esc_html__('It misses some important feature to me', 'wordlift'), |
|
| 23 | 23 | 'message' => array( |
| 24 | 24 | 'field' => 'text', |
| 25 | - 'text' => esc_html__( 'Tell us what this feature is.', 'wordlift' ), |
|
| 25 | + 'text' => esc_html__('Tell us what this feature is.', 'wordlift'), |
|
| 26 | 26 | ), |
| 27 | 27 | ), |
| 28 | 28 | array( |
| 29 | 29 | 'id' => 'COSTS_TOO_MUCH', |
| 30 | - 'text' => esc_html__( 'It costs too much', 'wordlift' ), |
|
| 30 | + 'text' => esc_html__('It costs too much', 'wordlift'), |
|
| 31 | 31 | 'message' => array( |
| 32 | 32 | 'field' => 'text', |
| 33 | - 'text' => esc_html__( 'How much you would like to pay?', 'wordlift' ), |
|
| 33 | + 'text' => esc_html__('How much you would like to pay?', 'wordlift'), |
|
| 34 | 34 | ), |
| 35 | 35 | ), |
| 36 | 36 | array( |
| 37 | 37 | 'id' => 'FOUND_ANOTHER_TOOL', |
| 38 | - 'text' => esc_html__( 'I found another tool that I like better', 'wordlift' ), |
|
| 38 | + 'text' => esc_html__('I found another tool that I like better', 'wordlift'), |
|
| 39 | 39 | 'message' => array( |
| 40 | 40 | 'field' => 'text', |
| 41 | - 'text' => esc_html__( 'Please tell us some more details.', 'wordlift' ), |
|
| 41 | + 'text' => esc_html__('Please tell us some more details.', 'wordlift'), |
|
| 42 | 42 | ), |
| 43 | 43 | ), |
| 44 | 44 | array( |
| 45 | 45 | 'id' => 'I_DONT_USE_IT', |
| 46 | - 'text' => esc_html__( 'I\'m not using it right now', 'wordlift' ), |
|
| 46 | + 'text' => esc_html__('I\'m not using it right now', 'wordlift'), |
|
| 47 | 47 | ), |
| 48 | 48 | array( |
| 49 | 49 | 'id' => 'SOMETHING_DIDNT_WORK', |
| 50 | - 'text' => esc_html__( 'Something didn\'t work right', 'wordlift' ), |
|
| 50 | + 'text' => esc_html__('Something didn\'t work right', 'wordlift'), |
|
| 51 | 51 | ), |
| 52 | 52 | array( |
| 53 | 53 | 'id' => 'ANOTHER_REASON', |
| 54 | - 'text' => esc_html__( 'Another reason', 'wordlift' ), |
|
| 54 | + 'text' => esc_html__('Another reason', 'wordlift'), |
|
| 55 | 55 | 'message' => array( |
| 56 | 56 | 'field' => 'textarea', |
| 57 | - 'text' => esc_html__( 'Please tell us the reason so we can improve it.', 'wordlift' ), |
|
| 57 | + 'text' => esc_html__('Please tell us the reason so we can improve it.', 'wordlift'), |
|
| 58 | 58 | ), |
| 59 | 59 | ), |
| 60 | 60 | ); |
@@ -63,43 +63,43 @@ discard block |
||
| 63 | 63 | <div class="wl-modal"> |
| 64 | 64 | <div class="wl-modal-body"> |
| 65 | 65 | <h2> |
| 66 | - <?php esc_html_e( 'We\'re sorry to see you go!', 'wordlift' ); ?> |
|
| 66 | + <?php esc_html_e('We\'re sorry to see you go!', 'wordlift'); ?> |
|
| 67 | 67 | </h2> |
| 68 | 68 | |
| 69 | 69 | <div class="wl-modal-panel active"> |
| 70 | 70 | <h4> |
| 71 | - <?php esc_html_e( 'If you have a moment, please let us know why you are deactivating', 'wordlift' ); ?> |
|
| 71 | + <?php esc_html_e('If you have a moment, please let us know why you are deactivating', 'wordlift'); ?> |
|
| 72 | 72 | : |
| 73 | 73 | </h4> |
| 74 | 74 | |
| 75 | 75 | <ul> |
| 76 | - <?php foreach ( $reasons as $reason ) : ?> |
|
| 77 | - <li class="wl-reason-item <?php echo ( $reason['id'] == 'I_DONT_USE_IT' ) ? 'selected' : ''; ?>"> |
|
| 76 | + <?php foreach ($reasons as $reason) : ?> |
|
| 77 | + <li class="wl-reason-item <?php echo ($reason['id'] == 'I_DONT_USE_IT') ? 'selected' : ''; ?>"> |
|
| 78 | 78 | <label> |
| 79 | 79 | <input |
| 80 | 80 | type="radio" |
| 81 | 81 | name="wl-code" |
| 82 | 82 | class="wl-code" |
| 83 | - <?php checked( 'I_DONT_USE_IT', $reason['id'], true ); ?> |
|
| 84 | - value="<?php echo esc_attr( $reason['id'] ); ?>" |
|
| 83 | + <?php checked('I_DONT_USE_IT', $reason['id'], true); ?> |
|
| 84 | + value="<?php echo esc_attr($reason['id']); ?>" |
|
| 85 | 85 | /> |
| 86 | 86 | |
| 87 | 87 | <span class="description"> |
| 88 | - <?php echo esc_html( $reason['text'] ); ?> |
|
| 88 | + <?php echo esc_html($reason['text']); ?> |
|
| 89 | 89 | </span> |
| 90 | 90 | </label> |
| 91 | 91 | |
| 92 | - <?php if ( ! empty( $reason['message'] ) ) : ?> |
|
| 93 | - <div class="additional-info <?php echo ( ! empty( $reason['message']['field'] ) ) ? 'has-field' : ''; ?>"> |
|
| 92 | + <?php if ( ! empty($reason['message'])) : ?> |
|
| 93 | + <div class="additional-info <?php echo ( ! empty($reason['message']['field'])) ? 'has-field' : ''; ?>"> |
|
| 94 | 94 | <?php |
| 95 | - if ( ! empty( $reason['message']['field'] ) ) { |
|
| 96 | - if ( $reason['message']['field'] === 'text' ) { |
|
| 95 | + if ( ! empty($reason['message']['field'])) { |
|
| 96 | + if ($reason['message']['field'] === 'text') { |
|
| 97 | 97 | echo '<input type="text" name="wl-details" class="wl-details"/>'; |
| 98 | 98 | } else { |
| 99 | 99 | echo '<textarea name="wl-details" class="wl-details"></textarea>'; |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | - echo wp_kses( wpautop( $reason['message']['text'] ), array( 'p' => array() ) ) |
|
| 102 | + echo wp_kses(wpautop($reason['message']['text']), array('p' => array())) |
|
| 103 | 103 | ?> |
| 104 | 104 | </div> |
| 105 | 105 | <?php endif ?> |
@@ -111,10 +111,10 @@ discard block |
||
| 111 | 111 | <div class="notes"> |
| 112 | 112 | <p> |
| 113 | 113 | <?php |
| 114 | - echo wp_kses( sprintf( |
|
| 115 | - __( 'Important notice: Uninstalling the plugin will delete your vocabulary.<br>Maybe you would like to <a href="%s" target="_blank">download your data</a> first.', 'wordlift' ), |
|
| 116 | - add_query_arg( array( 'page' => 'wl_download_your_data' ), admin_url( 'admin.php' ) ) |
|
| 117 | - ), array( 'br' => array(), 'a' => array( 'href' => array(), 'target' => array() ) ) ); |
|
| 114 | + echo wp_kses(sprintf( |
|
| 115 | + __('Important notice: Uninstalling the plugin will delete your vocabulary.<br>Maybe you would like to <a href="%s" target="_blank">download your data</a> first.', 'wordlift'), |
|
| 116 | + add_query_arg(array('page' => 'wl_download_your_data'), admin_url('admin.php')) |
|
| 117 | + ), array('br' => array(), 'a' => array('href' => array(), 'target' => array()))); |
|
| 118 | 118 | ?> |
| 119 | 119 | </p> |
| 120 | 120 | </div> |
@@ -124,11 +124,11 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | <div class="wl-modal-footer"> |
| 126 | 126 | <a href="#" class="button button-secondary wl-modal-button-close"> |
| 127 | - <?php esc_html_e( 'Cancel', 'wordlift' ); ?> |
|
| 127 | + <?php esc_html_e('Cancel', 'wordlift'); ?> |
|
| 128 | 128 | </a> |
| 129 | 129 | |
| 130 | 130 | <a href="#" class="button button-primary wl-modal-button-deactivate"> |
| 131 | - <?php esc_html_e( 'Deactivate', 'wordlift' ); ?> |
|
| 131 | + <?php esc_html_e('Deactivate', 'wordlift'); ?> |
|
| 132 | 132 | </a> |
| 133 | 133 | <div class="clear"></div> |
| 134 | 134 | </div> |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | type="hidden" |
| 138 | 138 | name="wl_deactivation_feedback_nonce" |
| 139 | 139 | class="wl_deactivation_feedback_nonce" |
| 140 | - value="<?php echo esc_attr( wp_create_nonce( 'wl_deactivation_feedback_nonce' ) ); ?>" |
|
| 140 | + value="<?php echo esc_attr(wp_create_nonce('wl_deactivation_feedback_nonce')); ?>" |
|
| 141 | 141 | > |
| 142 | 142 | </div> |
| 143 | 143 | </div> |
@@ -18,77 +18,77 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_User_Profile_Page { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * The {@link Wordlift_Admin_Person_Element} instance. |
|
| 23 | - * |
|
| 24 | - * @since 3.14.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var \Wordlift_Admin_Author_Element $plugin The person entity |
|
| 27 | - * selection element rendering the possible persons. |
|
| 28 | - */ |
|
| 29 | - private $author_element; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * The {@link Wordlift_User_Service} instance. |
|
| 33 | - * |
|
| 34 | - * @since 3.14.0 |
|
| 35 | - * @access private |
|
| 36 | - * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 37 | - */ |
|
| 38 | - private $user_service; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Create the {@link Wordlift_Admin_User_Profile_Page} instance. |
|
| 42 | - * |
|
| 43 | - * @param \Wordlift_Admin_Author_Element $author_element The person entity selection |
|
| 44 | - * element rendering the possible persons. |
|
| 45 | - * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 46 | - * |
|
| 47 | - * @since 3.14.0 |
|
| 48 | - * |
|
| 49 | - */ |
|
| 50 | - function __construct( $author_element, $user_service ) { |
|
| 51 | - |
|
| 52 | - $this->author_element = $author_element; |
|
| 53 | - $this->user_service = $user_service; |
|
| 54 | - |
|
| 55 | - /* |
|
| 21 | + /** |
|
| 22 | + * The {@link Wordlift_Admin_Person_Element} instance. |
|
| 23 | + * |
|
| 24 | + * @since 3.14.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var \Wordlift_Admin_Author_Element $plugin The person entity |
|
| 27 | + * selection element rendering the possible persons. |
|
| 28 | + */ |
|
| 29 | + private $author_element; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * The {@link Wordlift_User_Service} instance. |
|
| 33 | + * |
|
| 34 | + * @since 3.14.0 |
|
| 35 | + * @access private |
|
| 36 | + * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 37 | + */ |
|
| 38 | + private $user_service; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Create the {@link Wordlift_Admin_User_Profile_Page} instance. |
|
| 42 | + * |
|
| 43 | + * @param \Wordlift_Admin_Author_Element $author_element The person entity selection |
|
| 44 | + * element rendering the possible persons. |
|
| 45 | + * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 46 | + * |
|
| 47 | + * @since 3.14.0 |
|
| 48 | + * |
|
| 49 | + */ |
|
| 50 | + function __construct( $author_element, $user_service ) { |
|
| 51 | + |
|
| 52 | + $this->author_element = $author_element; |
|
| 53 | + $this->user_service = $user_service; |
|
| 54 | + |
|
| 55 | + /* |
|
| 56 | 56 | * When an admin (or similar permissions) edits his own profile a |
| 57 | 57 | * different action than the usual is being triggered. |
| 58 | 58 | * It is too early in the wordpress boot to do user capabilities filtering |
| 59 | 59 | * here and it is deferred to the handler. |
| 60 | 60 | */ |
| 61 | - add_action( 'show_user_profile', array( $this, 'edit_user_profile' ) ); |
|
| 62 | - add_action( 'edit_user_profile', array( $this, 'edit_user_profile' ) ); |
|
| 63 | - add_action( 'edit_user_profile_update', array( |
|
| 64 | - $this, |
|
| 65 | - 'edit_user_profile_update', |
|
| 66 | - ) ); |
|
| 67 | - add_action( 'personal_options_update', array( |
|
| 68 | - $this, |
|
| 69 | - 'edit_user_profile_update', |
|
| 70 | - ) ); |
|
| 71 | - |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Add a WordLift section in the user profile which lets |
|
| 76 | - * the admin to associate a wordpress user with a person entity. |
|
| 77 | - * |
|
| 78 | - * @param WP_User $user The current WP_User object of the user being edited. |
|
| 79 | - * |
|
| 80 | - * @since 3.14.0 |
|
| 81 | - * |
|
| 82 | - */ |
|
| 83 | - public function edit_user_profile( $user ) { |
|
| 84 | - |
|
| 85 | - // In case it is a user editing his own profile, make sure he has admin |
|
| 86 | - // like capabilities. |
|
| 87 | - if ( ! current_user_can( 'edit_users' ) ) { |
|
| 88 | - return; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - ?> |
|
| 61 | + add_action( 'show_user_profile', array( $this, 'edit_user_profile' ) ); |
|
| 62 | + add_action( 'edit_user_profile', array( $this, 'edit_user_profile' ) ); |
|
| 63 | + add_action( 'edit_user_profile_update', array( |
|
| 64 | + $this, |
|
| 65 | + 'edit_user_profile_update', |
|
| 66 | + ) ); |
|
| 67 | + add_action( 'personal_options_update', array( |
|
| 68 | + $this, |
|
| 69 | + 'edit_user_profile_update', |
|
| 70 | + ) ); |
|
| 71 | + |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Add a WordLift section in the user profile which lets |
|
| 76 | + * the admin to associate a wordpress user with a person entity. |
|
| 77 | + * |
|
| 78 | + * @param WP_User $user The current WP_User object of the user being edited. |
|
| 79 | + * |
|
| 80 | + * @since 3.14.0 |
|
| 81 | + * |
|
| 82 | + */ |
|
| 83 | + public function edit_user_profile( $user ) { |
|
| 84 | + |
|
| 85 | + // In case it is a user editing his own profile, make sure he has admin |
|
| 86 | + // like capabilities. |
|
| 87 | + if ( ! current_user_can( 'edit_users' ) ) { |
|
| 88 | + return; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + ?> |
|
| 92 | 92 | <h2><?php esc_html_e( 'WordLift', 'wordlift' ); ?></h2> |
| 93 | 93 | |
| 94 | 94 | <table class="form-table"> |
@@ -99,12 +99,12 @@ discard block |
||
| 99 | 99 | </th> |
| 100 | 100 | <td> |
| 101 | 101 | <?php |
| 102 | - $this->author_element->render( array( |
|
| 103 | - 'id' => 'wl_person', |
|
| 104 | - 'name' => 'wl_person', |
|
| 105 | - 'current_entity' => $this->user_service->get_entity( $user->ID ), |
|
| 106 | - ) ); |
|
| 107 | - ?> |
|
| 102 | + $this->author_element->render( array( |
|
| 103 | + 'id' => 'wl_person', |
|
| 104 | + 'name' => 'wl_person', |
|
| 105 | + 'current_entity' => $this->user_service->get_entity( $user->ID ), |
|
| 106 | + ) ); |
|
| 107 | + ?> |
|
| 108 | 108 | <p class="description"><?php esc_html_e( 'The entity, person or organization, from the vocabulary to associate with this author.', 'wordlift' ); ?></p> |
| 109 | 109 | </td> |
| 110 | 110 | </tr> |
@@ -122,66 +122,66 @@ discard block |
||
| 122 | 122 | </td> |
| 123 | 123 | <?php } ?> |
| 124 | 124 | <?php |
| 125 | - /** |
|
| 126 | - * Action name: wordlift_user_settings_page |
|
| 127 | - * An action to render the wordlift user settings. |
|
| 128 | - * @since 3.30.0 |
|
| 129 | - * |
|
| 130 | - */ |
|
| 131 | - do_action( 'wordlift_user_settings_page' ); |
|
| 132 | - ?> |
|
| 125 | + /** |
|
| 126 | + * Action name: wordlift_user_settings_page |
|
| 127 | + * An action to render the wordlift user settings. |
|
| 128 | + * @since 3.30.0 |
|
| 129 | + * |
|
| 130 | + */ |
|
| 131 | + do_action( 'wordlift_user_settings_page' ); |
|
| 132 | + ?> |
|
| 133 | 133 | </table> |
| 134 | 134 | <?php |
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Handle storing the person entity associated with the user. |
|
| 139 | - * |
|
| 140 | - * @param int $user_id The user id of the user being saved. |
|
| 141 | - * |
|
| 142 | - * @since 3.14.0 |
|
| 143 | - * |
|
| 144 | - */ |
|
| 145 | - public function edit_user_profile_update( $user_id ) { |
|
| 146 | - |
|
| 147 | - // In case it is a user editing his own profile, make sure he has admin |
|
| 148 | - // like capabilities. |
|
| 149 | - if ( ! current_user_can( 'edit_users' ) ) { |
|
| 150 | - return; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // Link an entity to the user. |
|
| 154 | - $this->link_entity( $user_id, $_POST ); |
|
| 155 | - |
|
| 156 | - // Deny and enable the edit entity capability |
|
| 157 | - if ( isset( $_POST['wl_can_create_entities'] ) ) { |
|
| 158 | - // User has capability so remove the deny indication if present. |
|
| 159 | - $this->user_service->allow_editor_entity_create( $user_id ); |
|
| 160 | - } else { |
|
| 161 | - $this->user_service->deny_editor_entity_create( $user_id ); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Link an entity (specified in the `$_POST` array) to the {@link WP_User} |
|
| 168 | - * with the specified `id`. |
|
| 169 | - * |
|
| 170 | - * @param int $user_id The {@link WP_User} `id`. |
|
| 171 | - * @param array $post The `$_POST` array. |
|
| 172 | - * |
|
| 173 | - * @since 3.14.0 |
|
| 174 | - * |
|
| 175 | - */ |
|
| 176 | - private function link_entity( $user_id, $post ) { |
|
| 177 | - |
|
| 178 | - // Bail out if the `wl_person` parameter isn't set. |
|
| 179 | - if ( ! isset( $post['wl_person'] ) || ! is_numeric( $post['wl_person'] ) ) { |
|
| 180 | - return; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $this->user_service->set_entity( $user_id, intval( $post['wl_person'] ) ); |
|
| 184 | - |
|
| 185 | - } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Handle storing the person entity associated with the user. |
|
| 139 | + * |
|
| 140 | + * @param int $user_id The user id of the user being saved. |
|
| 141 | + * |
|
| 142 | + * @since 3.14.0 |
|
| 143 | + * |
|
| 144 | + */ |
|
| 145 | + public function edit_user_profile_update( $user_id ) { |
|
| 146 | + |
|
| 147 | + // In case it is a user editing his own profile, make sure he has admin |
|
| 148 | + // like capabilities. |
|
| 149 | + if ( ! current_user_can( 'edit_users' ) ) { |
|
| 150 | + return; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // Link an entity to the user. |
|
| 154 | + $this->link_entity( $user_id, $_POST ); |
|
| 155 | + |
|
| 156 | + // Deny and enable the edit entity capability |
|
| 157 | + if ( isset( $_POST['wl_can_create_entities'] ) ) { |
|
| 158 | + // User has capability so remove the deny indication if present. |
|
| 159 | + $this->user_service->allow_editor_entity_create( $user_id ); |
|
| 160 | + } else { |
|
| 161 | + $this->user_service->deny_editor_entity_create( $user_id ); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Link an entity (specified in the `$_POST` array) to the {@link WP_User} |
|
| 168 | + * with the specified `id`. |
|
| 169 | + * |
|
| 170 | + * @param int $user_id The {@link WP_User} `id`. |
|
| 171 | + * @param array $post The `$_POST` array. |
|
| 172 | + * |
|
| 173 | + * @since 3.14.0 |
|
| 174 | + * |
|
| 175 | + */ |
|
| 176 | + private function link_entity( $user_id, $post ) { |
|
| 177 | + |
|
| 178 | + // Bail out if the `wl_person` parameter isn't set. |
|
| 179 | + if ( ! isset( $post['wl_person'] ) || ! is_numeric( $post['wl_person'] ) ) { |
|
| 180 | + return; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $this->user_service->set_entity( $user_id, intval( $post['wl_person'] ) ); |
|
| 184 | + |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | 187 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @since 3.14.0 |
| 48 | 48 | * |
| 49 | 49 | */ |
| 50 | - function __construct( $author_element, $user_service ) { |
|
| 50 | + function __construct($author_element, $user_service) { |
|
| 51 | 51 | |
| 52 | 52 | $this->author_element = $author_element; |
| 53 | 53 | $this->user_service = $user_service; |
@@ -58,16 +58,16 @@ discard block |
||
| 58 | 58 | * It is too early in the wordpress boot to do user capabilities filtering |
| 59 | 59 | * here and it is deferred to the handler. |
| 60 | 60 | */ |
| 61 | - add_action( 'show_user_profile', array( $this, 'edit_user_profile' ) ); |
|
| 62 | - add_action( 'edit_user_profile', array( $this, 'edit_user_profile' ) ); |
|
| 63 | - add_action( 'edit_user_profile_update', array( |
|
| 61 | + add_action('show_user_profile', array($this, 'edit_user_profile')); |
|
| 62 | + add_action('edit_user_profile', array($this, 'edit_user_profile')); |
|
| 63 | + add_action('edit_user_profile_update', array( |
|
| 64 | 64 | $this, |
| 65 | 65 | 'edit_user_profile_update', |
| 66 | - ) ); |
|
| 67 | - add_action( 'personal_options_update', array( |
|
| 66 | + )); |
|
| 67 | + add_action('personal_options_update', array( |
|
| 68 | 68 | $this, |
| 69 | 69 | 'edit_user_profile_update', |
| 70 | - ) ); |
|
| 70 | + )); |
|
| 71 | 71 | |
| 72 | 72 | } |
| 73 | 73 | |
@@ -80,45 +80,45 @@ discard block |
||
| 80 | 80 | * @since 3.14.0 |
| 81 | 81 | * |
| 82 | 82 | */ |
| 83 | - public function edit_user_profile( $user ) { |
|
| 83 | + public function edit_user_profile($user) { |
|
| 84 | 84 | |
| 85 | 85 | // In case it is a user editing his own profile, make sure he has admin |
| 86 | 86 | // like capabilities. |
| 87 | - if ( ! current_user_can( 'edit_users' ) ) { |
|
| 87 | + if ( ! current_user_can('edit_users')) { |
|
| 88 | 88 | return; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | ?> |
| 92 | - <h2><?php esc_html_e( 'WordLift', 'wordlift' ); ?></h2> |
|
| 92 | + <h2><?php esc_html_e('WordLift', 'wordlift'); ?></h2> |
|
| 93 | 93 | |
| 94 | 94 | <table class="form-table"> |
| 95 | - <?php if ( apply_filters( 'wl_feature__enable__user-author', true ) ) { ?> |
|
| 95 | + <?php if (apply_filters('wl_feature__enable__user-author', true)) { ?> |
|
| 96 | 96 | <tr class="user-description-wrap"> |
| 97 | 97 | <th><label |
| 98 | - for="wl_person"><?php esc_html_e( 'Author from the vocabulary', 'wordlift' ); ?></label> |
|
| 98 | + for="wl_person"><?php esc_html_e('Author from the vocabulary', 'wordlift'); ?></label> |
|
| 99 | 99 | </th> |
| 100 | 100 | <td> |
| 101 | 101 | <?php |
| 102 | - $this->author_element->render( array( |
|
| 102 | + $this->author_element->render(array( |
|
| 103 | 103 | 'id' => 'wl_person', |
| 104 | 104 | 'name' => 'wl_person', |
| 105 | - 'current_entity' => $this->user_service->get_entity( $user->ID ), |
|
| 106 | - ) ); |
|
| 105 | + 'current_entity' => $this->user_service->get_entity($user->ID), |
|
| 106 | + )); |
|
| 107 | 107 | ?> |
| 108 | - <p class="description"><?php esc_html_e( 'The entity, person or organization, from the vocabulary to associate with this author.', 'wordlift' ); ?></p> |
|
| 108 | + <p class="description"><?php esc_html_e('The entity, person or organization, from the vocabulary to associate with this author.', 'wordlift'); ?></p> |
|
| 109 | 109 | </td> |
| 110 | 110 | </tr> |
| 111 | 111 | <?php } ?> |
| 112 | - <?php if ( $this->user_service->is_editor( $user->ID ) ) { ?> |
|
| 112 | + <?php if ($this->user_service->is_editor($user->ID)) { ?> |
|
| 113 | 113 | <tr> |
| 114 | 114 | <th> |
| 115 | 115 | <label |
| 116 | - for="wl_can_create_entities"><?php esc_html_e( 'Can create new entities', 'wordlift' ) ?></label> |
|
| 116 | + for="wl_can_create_entities"><?php esc_html_e('Can create new entities', 'wordlift') ?></label> |
|
| 117 | 117 | </th> |
| 118 | 118 | <td> |
| 119 | 119 | <input id="wl_can_create_entities" |
| 120 | 120 | name="wl_can_create_entities" |
| 121 | - type="checkbox" <?php checked( $this->user_service->editor_can_create_entities( $user->ID ) ) ?> |
|
| 121 | + type="checkbox" <?php checked($this->user_service->editor_can_create_entities($user->ID)) ?> |
|
| 122 | 122 | </td> |
| 123 | 123 | <?php } ?> |
| 124 | 124 | <?php |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @since 3.30.0 |
| 129 | 129 | * |
| 130 | 130 | */ |
| 131 | - do_action( 'wordlift_user_settings_page' ); |
|
| 131 | + do_action('wordlift_user_settings_page'); |
|
| 132 | 132 | ?> |
| 133 | 133 | </table> |
| 134 | 134 | <?php |
@@ -142,23 +142,23 @@ discard block |
||
| 142 | 142 | * @since 3.14.0 |
| 143 | 143 | * |
| 144 | 144 | */ |
| 145 | - public function edit_user_profile_update( $user_id ) { |
|
| 145 | + public function edit_user_profile_update($user_id) { |
|
| 146 | 146 | |
| 147 | 147 | // In case it is a user editing his own profile, make sure he has admin |
| 148 | 148 | // like capabilities. |
| 149 | - if ( ! current_user_can( 'edit_users' ) ) { |
|
| 149 | + if ( ! current_user_can('edit_users')) { |
|
| 150 | 150 | return; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // Link an entity to the user. |
| 154 | - $this->link_entity( $user_id, $_POST ); |
|
| 154 | + $this->link_entity($user_id, $_POST); |
|
| 155 | 155 | |
| 156 | 156 | // Deny and enable the edit entity capability |
| 157 | - if ( isset( $_POST['wl_can_create_entities'] ) ) { |
|
| 157 | + if (isset($_POST['wl_can_create_entities'])) { |
|
| 158 | 158 | // User has capability so remove the deny indication if present. |
| 159 | - $this->user_service->allow_editor_entity_create( $user_id ); |
|
| 159 | + $this->user_service->allow_editor_entity_create($user_id); |
|
| 160 | 160 | } else { |
| 161 | - $this->user_service->deny_editor_entity_create( $user_id ); |
|
| 161 | + $this->user_service->deny_editor_entity_create($user_id); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | } |
@@ -173,14 +173,14 @@ discard block |
||
| 173 | 173 | * @since 3.14.0 |
| 174 | 174 | * |
| 175 | 175 | */ |
| 176 | - private function link_entity( $user_id, $post ) { |
|
| 176 | + private function link_entity($user_id, $post) { |
|
| 177 | 177 | |
| 178 | 178 | // Bail out if the `wl_person` parameter isn't set. |
| 179 | - if ( ! isset( $post['wl_person'] ) || ! is_numeric( $post['wl_person'] ) ) { |
|
| 179 | + if ( ! isset($post['wl_person']) || ! is_numeric($post['wl_person'])) { |
|
| 180 | 180 | return; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - $this->user_service->set_entity( $user_id, intval( $post['wl_person'] ) ); |
|
| 183 | + $this->user_service->set_entity($user_id, intval($post['wl_person'])); |
|
| 184 | 184 | |
| 185 | 185 | } |
| 186 | 186 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | - exit; |
|
| 16 | + exit; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -30,219 +30,219 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | class Wordlift_Admin_Entity_Type_Settings { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * A {@link Wordlift_Log_Service} instance. |
|
| 35 | - * |
|
| 36 | - * @since 3.14.0 |
|
| 37 | - * @access private |
|
| 38 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 39 | - */ |
|
| 40 | - private $log; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Create a {@link Wordlift_Admin_Entity_Type_Settings} instance. |
|
| 44 | - * |
|
| 45 | - * @since 3.14.0 |
|
| 46 | - */ |
|
| 47 | - public function __construct() { |
|
| 48 | - |
|
| 49 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Admin_Entity_Type_Settings' ); |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Handle menu registration. |
|
| 55 | - * |
|
| 56 | - * The registration is required, although we do not want to actually to add |
|
| 57 | - * an item to the menu, in order to "whitelist" the access to the settings page in |
|
| 58 | - * the admin. |
|
| 59 | - * |
|
| 60 | - * @since 3.11.0 |
|
| 61 | - */ |
|
| 62 | - public function admin_menu() { |
|
| 63 | - |
|
| 64 | - /* |
|
| 33 | + /** |
|
| 34 | + * A {@link Wordlift_Log_Service} instance. |
|
| 35 | + * |
|
| 36 | + * @since 3.14.0 |
|
| 37 | + * @access private |
|
| 38 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 39 | + */ |
|
| 40 | + private $log; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Create a {@link Wordlift_Admin_Entity_Type_Settings} instance. |
|
| 44 | + * |
|
| 45 | + * @since 3.14.0 |
|
| 46 | + */ |
|
| 47 | + public function __construct() { |
|
| 48 | + |
|
| 49 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Admin_Entity_Type_Settings' ); |
|
| 50 | + |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Handle menu registration. |
|
| 55 | + * |
|
| 56 | + * The registration is required, although we do not want to actually to add |
|
| 57 | + * an item to the menu, in order to "whitelist" the access to the settings page in |
|
| 58 | + * the admin. |
|
| 59 | + * |
|
| 60 | + * @since 3.11.0 |
|
| 61 | + */ |
|
| 62 | + public function admin_menu() { |
|
| 63 | + |
|
| 64 | + /* |
|
| 65 | 65 | * Before anything else check if an settings form was submitted. |
| 66 | 66 | * This has to be done before any output happens in order to be able to |
| 67 | 67 | * display proper "die" error messages and redirect. |
| 68 | 68 | */ |
| 69 | - if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) { |
|
| 70 | - |
|
| 71 | - // Validate inputs. Do not return on invalid parameters or capabilities. |
|
| 72 | - $this->validate_proper_term(); |
|
| 73 | - |
|
| 74 | - // If proper form submission, handle it and redirect back to the settings page. |
|
| 75 | - if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) { |
|
| 76 | - $this->handle_form_submission(); |
|
| 77 | - } |
|
| 78 | - /** |
|
| 79 | - * Filter: wl_feature__enable__notices. |
|
| 80 | - * |
|
| 81 | - * @param bool whether the notices needs to be enabled or not. |
|
| 82 | - * |
|
| 83 | - * @return bool |
|
| 84 | - * @since 3.27.6 |
|
| 85 | - */ |
|
| 86 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
| 87 | - // Register admin notices handler. |
|
| 88 | - add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /* |
|
| 69 | + if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) { |
|
| 70 | + |
|
| 71 | + // Validate inputs. Do not return on invalid parameters or capabilities. |
|
| 72 | + $this->validate_proper_term(); |
|
| 73 | + |
|
| 74 | + // If proper form submission, handle it and redirect back to the settings page. |
|
| 75 | + if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) { |
|
| 76 | + $this->handle_form_submission(); |
|
| 77 | + } |
|
| 78 | + /** |
|
| 79 | + * Filter: wl_feature__enable__notices. |
|
| 80 | + * |
|
| 81 | + * @param bool whether the notices needs to be enabled or not. |
|
| 82 | + * |
|
| 83 | + * @return bool |
|
| 84 | + * @since 3.27.6 |
|
| 85 | + */ |
|
| 86 | + if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
| 87 | + // Register admin notices handler. |
|
| 88 | + add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /* |
|
| 94 | 94 | * Use a null parent slug to prevent the menu from actually appearing |
| 95 | 95 | * in the admin menu. |
| 96 | 96 | */ |
| 97 | - // @todo: use the new {@link Wordlift_Admin_Page}. |
|
| 98 | - add_submenu_page( |
|
| 99 | - null, |
|
| 100 | - __( 'Edit Entity term', 'wordlift' ), |
|
| 101 | - __( 'Edit Entity term', 'wordlift' ), |
|
| 102 | - 'manage_options', |
|
| 103 | - 'wl_entity_type_settings', |
|
| 104 | - array( $this, 'render' ) |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Output admin notices if needed, based on the message url parameter. |
|
| 110 | - * A value of 1 indicates that a successful save was done. |
|
| 111 | - * |
|
| 112 | - * @since 3.11.0 |
|
| 113 | - */ |
|
| 114 | - function admin_notice() { |
|
| 115 | - if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) { |
|
| 116 | - ?> |
|
| 97 | + // @todo: use the new {@link Wordlift_Admin_Page}. |
|
| 98 | + add_submenu_page( |
|
| 99 | + null, |
|
| 100 | + __( 'Edit Entity term', 'wordlift' ), |
|
| 101 | + __( 'Edit Entity term', 'wordlift' ), |
|
| 102 | + 'manage_options', |
|
| 103 | + 'wl_entity_type_settings', |
|
| 104 | + array( $this, 'render' ) |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Output admin notices if needed, based on the message url parameter. |
|
| 110 | + * A value of 1 indicates that a successful save was done. |
|
| 111 | + * |
|
| 112 | + * @since 3.11.0 |
|
| 113 | + */ |
|
| 114 | + function admin_notice() { |
|
| 115 | + if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) { |
|
| 116 | + ?> |
|
| 117 | 117 | <div class="notice notice-success is-dismissible"> |
| 118 | 118 | <p><?php esc_html_e( 'Settings saved', 'wordlift' ) ?></p> |
| 119 | 119 | </div> |
| 120 | 120 | <?php |
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Validate the existence of the entity type indicated by the tag_ID url |
|
| 126 | - * parameter before doing any processing. Done before any output to mimic |
|
| 127 | - * the way WordPress handles same situation with "normal" term editing screens. |
|
| 128 | - * |
|
| 129 | - * @since 3.11.0 |
|
| 130 | - */ |
|
| 131 | - function validate_proper_term() { |
|
| 132 | - |
|
| 133 | - // Validate capabilities. |
|
| 134 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 135 | - wp_die( |
|
| 136 | - '<h1>' . esc_html__( 'Cheatin’ uh?' ) . '</h1>' . |
|
| 137 | - '<p>' . esc_html__( 'Sorry, you are not allowed to edit this item.' ) . '</p>', |
|
| 138 | - 403 |
|
| 139 | - ); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // Get the term id and the actual term. |
|
| 143 | - $term_id = isset( $_REQUEST['tag_ID'] ) ? (int) $_REQUEST['tag_ID'] : 0; |
|
| 144 | - |
|
| 145 | - if ( ! term_exists( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ) { |
|
| 146 | - wp_die( esc_html__( 'You attempted to edit an entity type term that doesn’t exist.', 'wordlift' ) ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Handle the form submission of the settings form. On successful |
|
| 153 | - * handling redirect tp the setting edit page. |
|
| 154 | - * |
|
| 155 | - * @since 3.11.0 |
|
| 156 | - */ |
|
| 157 | - function handle_form_submission() { |
|
| 158 | - |
|
| 159 | - $term_id = isset( $_POST['tag_ID'] ) ? (int) $_POST['tag_ID'] : 0; |
|
| 160 | - |
|
| 161 | - // Check the nonce. |
|
| 162 | - check_admin_referer( 'update-entity_type_term_' . $term_id ); |
|
| 163 | - |
|
| 164 | - $term = get_term( $term_id, 'wl_entity_type' ); |
|
| 165 | - |
|
| 166 | - $title = isset( $_POST['title'] ) ? (string) $_POST['title'] : ''; |
|
| 167 | - $description = isset( $_POST['description'] ) ? (string) $_POST['description'] : ''; |
|
| 168 | - $this->set_setting( |
|
| 169 | - $term_id, |
|
| 170 | - trim( wp_unslash( $title ) ), |
|
| 171 | - wp_unslash( $description ) |
|
| 172 | - ); |
|
| 173 | - |
|
| 174 | - // Redirect back to the term settings page and indicate a save was done. |
|
| 175 | - $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" ); |
|
| 176 | - |
|
| 177 | - wp_redirect( $url ); |
|
| 178 | - exit; |
|
| 179 | - |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Render the settings page for the term. |
|
| 184 | - * |
|
| 185 | - * Access and parameter validity is assumed to be done earlier. |
|
| 186 | - * |
|
| 187 | - * @since 3.11.0 |
|
| 188 | - */ |
|
| 189 | - function render() { |
|
| 190 | - |
|
| 191 | - // Set variables used by the partial |
|
| 192 | - $term_id = isset( $_REQUEST['tag_ID'] ) ? absint( $_REQUEST['tag_ID'] ) : 0; |
|
| 193 | - $settings = $this->get_setting( $term_id ); |
|
| 194 | - |
|
| 195 | - include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-entity-type-settings.php'; |
|
| 196 | - |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Store the entity type term settings in the DB |
|
| 201 | - * |
|
| 202 | - * @param integer $term_id The ID of the entity type term |
|
| 203 | - * @param string $title The override for the terms title. |
|
| 204 | - * @param string $description The override for the terms description. |
|
| 205 | - * |
|
| 206 | - * @since 3.11.0 |
|
| 207 | - * |
|
| 208 | - */ |
|
| 209 | - function set_setting( $term_id, $title, $description ) { |
|
| 210 | - |
|
| 211 | - $settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 212 | - $settings[ $term_id ] = array( |
|
| 213 | - 'title' => $title, |
|
| 214 | - 'description' => $description, |
|
| 215 | - ); |
|
| 216 | - update_option( 'wl_entity_type_settings', $settings ); |
|
| 217 | - |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Retrieve the entity type term settings from the DB |
|
| 222 | - * |
|
| 223 | - * @param integer $term_id The ID of the entity type term |
|
| 224 | - * |
|
| 225 | - * @return null|array { |
|
| 226 | - * null is returned when there are no settings otherwise |
|
| 227 | - * an array is returned with following fields |
|
| 228 | - * |
|
| 229 | - * @type string title The overriding title for the term |
|
| 230 | - * @type string description The overriding description for the term |
|
| 231 | - * } |
|
| 232 | - * @since 3.11.0 |
|
| 233 | - * |
|
| 234 | - */ |
|
| 235 | - function get_setting( $term_id ) { |
|
| 236 | - |
|
| 237 | - $settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 238 | - |
|
| 239 | - if ( isset( $settings[ $term_id ] ) ) { |
|
| 240 | - return $settings[ $term_id ]; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - $this->log->warn( "No settings found for term id $term_id." ); |
|
| 244 | - |
|
| 245 | - return null; |
|
| 246 | - } |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Validate the existence of the entity type indicated by the tag_ID url |
|
| 126 | + * parameter before doing any processing. Done before any output to mimic |
|
| 127 | + * the way WordPress handles same situation with "normal" term editing screens. |
|
| 128 | + * |
|
| 129 | + * @since 3.11.0 |
|
| 130 | + */ |
|
| 131 | + function validate_proper_term() { |
|
| 132 | + |
|
| 133 | + // Validate capabilities. |
|
| 134 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 135 | + wp_die( |
|
| 136 | + '<h1>' . esc_html__( 'Cheatin’ uh?' ) . '</h1>' . |
|
| 137 | + '<p>' . esc_html__( 'Sorry, you are not allowed to edit this item.' ) . '</p>', |
|
| 138 | + 403 |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // Get the term id and the actual term. |
|
| 143 | + $term_id = isset( $_REQUEST['tag_ID'] ) ? (int) $_REQUEST['tag_ID'] : 0; |
|
| 144 | + |
|
| 145 | + if ( ! term_exists( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ) { |
|
| 146 | + wp_die( esc_html__( 'You attempted to edit an entity type term that doesn’t exist.', 'wordlift' ) ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Handle the form submission of the settings form. On successful |
|
| 153 | + * handling redirect tp the setting edit page. |
|
| 154 | + * |
|
| 155 | + * @since 3.11.0 |
|
| 156 | + */ |
|
| 157 | + function handle_form_submission() { |
|
| 158 | + |
|
| 159 | + $term_id = isset( $_POST['tag_ID'] ) ? (int) $_POST['tag_ID'] : 0; |
|
| 160 | + |
|
| 161 | + // Check the nonce. |
|
| 162 | + check_admin_referer( 'update-entity_type_term_' . $term_id ); |
|
| 163 | + |
|
| 164 | + $term = get_term( $term_id, 'wl_entity_type' ); |
|
| 165 | + |
|
| 166 | + $title = isset( $_POST['title'] ) ? (string) $_POST['title'] : ''; |
|
| 167 | + $description = isset( $_POST['description'] ) ? (string) $_POST['description'] : ''; |
|
| 168 | + $this->set_setting( |
|
| 169 | + $term_id, |
|
| 170 | + trim( wp_unslash( $title ) ), |
|
| 171 | + wp_unslash( $description ) |
|
| 172 | + ); |
|
| 173 | + |
|
| 174 | + // Redirect back to the term settings page and indicate a save was done. |
|
| 175 | + $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" ); |
|
| 176 | + |
|
| 177 | + wp_redirect( $url ); |
|
| 178 | + exit; |
|
| 179 | + |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Render the settings page for the term. |
|
| 184 | + * |
|
| 185 | + * Access and parameter validity is assumed to be done earlier. |
|
| 186 | + * |
|
| 187 | + * @since 3.11.0 |
|
| 188 | + */ |
|
| 189 | + function render() { |
|
| 190 | + |
|
| 191 | + // Set variables used by the partial |
|
| 192 | + $term_id = isset( $_REQUEST['tag_ID'] ) ? absint( $_REQUEST['tag_ID'] ) : 0; |
|
| 193 | + $settings = $this->get_setting( $term_id ); |
|
| 194 | + |
|
| 195 | + include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-entity-type-settings.php'; |
|
| 196 | + |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Store the entity type term settings in the DB |
|
| 201 | + * |
|
| 202 | + * @param integer $term_id The ID of the entity type term |
|
| 203 | + * @param string $title The override for the terms title. |
|
| 204 | + * @param string $description The override for the terms description. |
|
| 205 | + * |
|
| 206 | + * @since 3.11.0 |
|
| 207 | + * |
|
| 208 | + */ |
|
| 209 | + function set_setting( $term_id, $title, $description ) { |
|
| 210 | + |
|
| 211 | + $settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 212 | + $settings[ $term_id ] = array( |
|
| 213 | + 'title' => $title, |
|
| 214 | + 'description' => $description, |
|
| 215 | + ); |
|
| 216 | + update_option( 'wl_entity_type_settings', $settings ); |
|
| 217 | + |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Retrieve the entity type term settings from the DB |
|
| 222 | + * |
|
| 223 | + * @param integer $term_id The ID of the entity type term |
|
| 224 | + * |
|
| 225 | + * @return null|array { |
|
| 226 | + * null is returned when there are no settings otherwise |
|
| 227 | + * an array is returned with following fields |
|
| 228 | + * |
|
| 229 | + * @type string title The overriding title for the term |
|
| 230 | + * @type string description The overriding description for the term |
|
| 231 | + * } |
|
| 232 | + * @since 3.11.0 |
|
| 233 | + * |
|
| 234 | + */ |
|
| 235 | + function get_setting( $term_id ) { |
|
| 236 | + |
|
| 237 | + $settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 238 | + |
|
| 239 | + if ( isset( $settings[ $term_id ] ) ) { |
|
| 240 | + return $settings[ $term_id ]; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + $this->log->warn( "No settings found for term id $term_id." ); |
|
| 244 | + |
|
| 245 | + return null; |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | 248 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * @since 3.11.0 |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if ( ! defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function __construct() { |
| 48 | 48 | |
| 49 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Admin_Entity_Type_Settings' ); |
|
| 49 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Admin_Entity_Type_Settings'); |
|
| 50 | 50 | |
| 51 | 51 | } |
| 52 | 52 | |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | * This has to be done before any output happens in order to be able to |
| 67 | 67 | * display proper "die" error messages and redirect. |
| 68 | 68 | */ |
| 69 | - if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) { |
|
| 69 | + if (isset($_GET['page']) && ('wl_entity_type_settings' === $_GET['page'])) { |
|
| 70 | 70 | |
| 71 | 71 | // Validate inputs. Do not return on invalid parameters or capabilities. |
| 72 | 72 | $this->validate_proper_term(); |
| 73 | 73 | |
| 74 | 74 | // If proper form submission, handle it and redirect back to the settings page. |
| 75 | - if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) { |
|
| 75 | + if (isset($_POST['action']) && ('wl_edit_entity_type_term' === $_POST['action'])) { |
|
| 76 | 76 | $this->handle_form_submission(); |
| 77 | 77 | } |
| 78 | 78 | /** |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | * @return bool |
| 84 | 84 | * @since 3.27.6 |
| 85 | 85 | */ |
| 86 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
| 86 | + if (apply_filters('wl_feature__enable__notices', true)) { |
|
| 87 | 87 | // Register admin notices handler. |
| 88 | - add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
|
| 88 | + add_action('admin_notices', array($this, 'admin_notice')); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | } |
@@ -97,11 +97,11 @@ discard block |
||
| 97 | 97 | // @todo: use the new {@link Wordlift_Admin_Page}. |
| 98 | 98 | add_submenu_page( |
| 99 | 99 | null, |
| 100 | - __( 'Edit Entity term', 'wordlift' ), |
|
| 101 | - __( 'Edit Entity term', 'wordlift' ), |
|
| 100 | + __('Edit Entity term', 'wordlift'), |
|
| 101 | + __('Edit Entity term', 'wordlift'), |
|
| 102 | 102 | 'manage_options', |
| 103 | 103 | 'wl_entity_type_settings', |
| 104 | - array( $this, 'render' ) |
|
| 104 | + array($this, 'render') |
|
| 105 | 105 | ); |
| 106 | 106 | } |
| 107 | 107 | |
@@ -112,10 +112,10 @@ discard block |
||
| 112 | 112 | * @since 3.11.0 |
| 113 | 113 | */ |
| 114 | 114 | function admin_notice() { |
| 115 | - if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) { |
|
| 115 | + if (isset($_GET['message']) && ('1' === $_GET['message'])) { |
|
| 116 | 116 | ?> |
| 117 | 117 | <div class="notice notice-success is-dismissible"> |
| 118 | - <p><?php esc_html_e( 'Settings saved', 'wordlift' ) ?></p> |
|
| 118 | + <p><?php esc_html_e('Settings saved', 'wordlift') ?></p> |
|
| 119 | 119 | </div> |
| 120 | 120 | <?php |
| 121 | 121 | } |
@@ -131,19 +131,19 @@ discard block |
||
| 131 | 131 | function validate_proper_term() { |
| 132 | 132 | |
| 133 | 133 | // Validate capabilities. |
| 134 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 134 | + if ( ! current_user_can('manage_options')) { |
|
| 135 | 135 | wp_die( |
| 136 | - '<h1>' . esc_html__( 'Cheatin’ uh?' ) . '</h1>' . |
|
| 137 | - '<p>' . esc_html__( 'Sorry, you are not allowed to edit this item.' ) . '</p>', |
|
| 136 | + '<h1>'.esc_html__('Cheatin’ uh?').'</h1>'. |
|
| 137 | + '<p>'.esc_html__('Sorry, you are not allowed to edit this item.').'</p>', |
|
| 138 | 138 | 403 |
| 139 | 139 | ); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // Get the term id and the actual term. |
| 143 | - $term_id = isset( $_REQUEST['tag_ID'] ) ? (int) $_REQUEST['tag_ID'] : 0; |
|
| 143 | + $term_id = isset($_REQUEST['tag_ID']) ? (int) $_REQUEST['tag_ID'] : 0; |
|
| 144 | 144 | |
| 145 | - if ( ! term_exists( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ) { |
|
| 146 | - wp_die( esc_html__( 'You attempted to edit an entity type term that doesn’t exist.', 'wordlift' ) ); |
|
| 145 | + if ( ! term_exists($term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME)) { |
|
| 146 | + wp_die(esc_html__('You attempted to edit an entity type term that doesn’t exist.', 'wordlift')); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | } |
@@ -156,25 +156,25 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | function handle_form_submission() { |
| 158 | 158 | |
| 159 | - $term_id = isset( $_POST['tag_ID'] ) ? (int) $_POST['tag_ID'] : 0; |
|
| 159 | + $term_id = isset($_POST['tag_ID']) ? (int) $_POST['tag_ID'] : 0; |
|
| 160 | 160 | |
| 161 | 161 | // Check the nonce. |
| 162 | - check_admin_referer( 'update-entity_type_term_' . $term_id ); |
|
| 162 | + check_admin_referer('update-entity_type_term_'.$term_id); |
|
| 163 | 163 | |
| 164 | - $term = get_term( $term_id, 'wl_entity_type' ); |
|
| 164 | + $term = get_term($term_id, 'wl_entity_type'); |
|
| 165 | 165 | |
| 166 | - $title = isset( $_POST['title'] ) ? (string) $_POST['title'] : ''; |
|
| 167 | - $description = isset( $_POST['description'] ) ? (string) $_POST['description'] : ''; |
|
| 166 | + $title = isset($_POST['title']) ? (string) $_POST['title'] : ''; |
|
| 167 | + $description = isset($_POST['description']) ? (string) $_POST['description'] : ''; |
|
| 168 | 168 | $this->set_setting( |
| 169 | 169 | $term_id, |
| 170 | - trim( wp_unslash( $title ) ), |
|
| 171 | - wp_unslash( $description ) |
|
| 170 | + trim(wp_unslash($title)), |
|
| 171 | + wp_unslash($description) |
|
| 172 | 172 | ); |
| 173 | 173 | |
| 174 | 174 | // Redirect back to the term settings page and indicate a save was done. |
| 175 | - $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" ); |
|
| 175 | + $url = admin_url("admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1"); |
|
| 176 | 176 | |
| 177 | - wp_redirect( $url ); |
|
| 177 | + wp_redirect($url); |
|
| 178 | 178 | exit; |
| 179 | 179 | |
| 180 | 180 | } |
@@ -189,10 +189,10 @@ discard block |
||
| 189 | 189 | function render() { |
| 190 | 190 | |
| 191 | 191 | // Set variables used by the partial |
| 192 | - $term_id = isset( $_REQUEST['tag_ID'] ) ? absint( $_REQUEST['tag_ID'] ) : 0; |
|
| 193 | - $settings = $this->get_setting( $term_id ); |
|
| 192 | + $term_id = isset($_REQUEST['tag_ID']) ? absint($_REQUEST['tag_ID']) : 0; |
|
| 193 | + $settings = $this->get_setting($term_id); |
|
| 194 | 194 | |
| 195 | - include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-entity-type-settings.php'; |
|
| 195 | + include plugin_dir_path(dirname(__FILE__)).'admin/partials/wordlift-admin-entity-type-settings.php'; |
|
| 196 | 196 | |
| 197 | 197 | } |
| 198 | 198 | |
@@ -206,14 +206,14 @@ discard block |
||
| 206 | 206 | * @since 3.11.0 |
| 207 | 207 | * |
| 208 | 208 | */ |
| 209 | - function set_setting( $term_id, $title, $description ) { |
|
| 209 | + function set_setting($term_id, $title, $description) { |
|
| 210 | 210 | |
| 211 | - $settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 212 | - $settings[ $term_id ] = array( |
|
| 211 | + $settings = get_option('wl_entity_type_settings', array()); |
|
| 212 | + $settings[$term_id] = array( |
|
| 213 | 213 | 'title' => $title, |
| 214 | 214 | 'description' => $description, |
| 215 | 215 | ); |
| 216 | - update_option( 'wl_entity_type_settings', $settings ); |
|
| 216 | + update_option('wl_entity_type_settings', $settings); |
|
| 217 | 217 | |
| 218 | 218 | } |
| 219 | 219 | |
@@ -232,15 +232,15 @@ discard block |
||
| 232 | 232 | * @since 3.11.0 |
| 233 | 233 | * |
| 234 | 234 | */ |
| 235 | - function get_setting( $term_id ) { |
|
| 235 | + function get_setting($term_id) { |
|
| 236 | 236 | |
| 237 | - $settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 237 | + $settings = get_option('wl_entity_type_settings', array()); |
|
| 238 | 238 | |
| 239 | - if ( isset( $settings[ $term_id ] ) ) { |
|
| 240 | - return $settings[ $term_id ]; |
|
| 239 | + if (isset($settings[$term_id])) { |
|
| 240 | + return $settings[$term_id]; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - $this->log->warn( "No settings found for term id $term_id." ); |
|
| 243 | + $this->log->warn("No settings found for term id $term_id."); |
|
| 244 | 244 | |
| 245 | 245 | return null; |
| 246 | 246 | } |
@@ -18,28 +18,28 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class Wordlift_Admin_Select_Element implements Wordlift_Admin_Element { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @inheritdoc |
|
| 23 | - */ |
|
| 24 | - public function render( $args ) { |
|
| 25 | - // Some select fields may need custom script/styles to work. |
|
| 26 | - $this->enqueue_resources(); |
|
| 27 | - |
|
| 28 | - // Parse the arguments and merge with default values. |
|
| 29 | - $params = wp_parse_args( |
|
| 30 | - $args, |
|
| 31 | - array( |
|
| 32 | - 'id' => uniqid( 'wl-input-' ), |
|
| 33 | - 'name' => uniqid( 'wl-input-' ), |
|
| 34 | - 'value' => '', |
|
| 35 | - 'class' => '', |
|
| 36 | - 'notice' => '', |
|
| 37 | - 'description' => false, |
|
| 38 | - 'data' => array(), |
|
| 39 | - 'options' => array(), |
|
| 40 | - ) |
|
| 41 | - ); |
|
| 42 | - ?> |
|
| 21 | + /** |
|
| 22 | + * @inheritdoc |
|
| 23 | + */ |
|
| 24 | + public function render( $args ) { |
|
| 25 | + // Some select fields may need custom script/styles to work. |
|
| 26 | + $this->enqueue_resources(); |
|
| 27 | + |
|
| 28 | + // Parse the arguments and merge with default values. |
|
| 29 | + $params = wp_parse_args( |
|
| 30 | + $args, |
|
| 31 | + array( |
|
| 32 | + 'id' => uniqid( 'wl-input-' ), |
|
| 33 | + 'name' => uniqid( 'wl-input-' ), |
|
| 34 | + 'value' => '', |
|
| 35 | + 'class' => '', |
|
| 36 | + 'notice' => '', |
|
| 37 | + 'description' => false, |
|
| 38 | + 'data' => array(), |
|
| 39 | + 'options' => array(), |
|
| 40 | + ) |
|
| 41 | + ); |
|
| 42 | + ?> |
|
| 43 | 43 | <select |
| 44 | 44 | id="<?php echo esc_attr( $params['id'] ); ?>" |
| 45 | 45 | name="<?php echo esc_attr( $params['name'] ); ?>" |
@@ -50,130 +50,130 @@ discard block |
||
| 50 | 50 | </select> |
| 51 | 51 | |
| 52 | 52 | <?php |
| 53 | - // Print the notice message if there is such. |
|
| 54 | - $this->print_notice( $params['notice'] ); |
|
| 55 | - |
|
| 56 | - // Print the field description. |
|
| 57 | - echo wp_kses( $this->get_description( $params['description'] ), array( 'p' => array() ) ); |
|
| 58 | - |
|
| 59 | - return $this; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Returns html escaped description string. |
|
| 64 | - * Note: Only `a` tags are allowed with only `href` attributes. |
|
| 65 | - * |
|
| 66 | - * @param string|bool $description The field description or false if not set. |
|
| 67 | - * |
|
| 68 | - * @since 3.18.0 |
|
| 69 | - * |
|
| 70 | - * @return string|void The description or null if not set. |
|
| 71 | - */ |
|
| 72 | - public function get_description( $description ) { |
|
| 73 | - // Bail if the description is not set. |
|
| 74 | - if ( empty( $description ) ) { |
|
| 75 | - return; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // Remove all characters except links. |
|
| 79 | - $filtered_descrption = wp_kses( |
|
| 80 | - $description, |
|
| 81 | - array( |
|
| 82 | - 'a' => array( |
|
| 83 | - 'href' => array(), |
|
| 84 | - ), |
|
| 85 | - ) |
|
| 86 | - ); |
|
| 87 | - |
|
| 88 | - return wpautop( $filtered_descrption ); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Prints the field notice that will be shown on error. |
|
| 93 | - * |
|
| 94 | - * @param string $notice The notice to add. |
|
| 95 | - * |
|
| 96 | - * @since 3.18.0 |
|
| 97 | - * |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public function print_notice( $notice ) { |
|
| 101 | - // Bail if the notice is empty. |
|
| 102 | - if ( empty( $notice ) ) { |
|
| 103 | - return; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Print the notice message. |
|
| 107 | - printf( |
|
| 108 | - '<small class="wl-select-notices">%s</small>', |
|
| 109 | - esc_html( $notice ) |
|
| 110 | - ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Adds data attributes to select element. |
|
| 115 | - * |
|
| 116 | - * We need to use method here, because different select elements |
|
| 117 | - * may have different data attributes. |
|
| 118 | - * |
|
| 119 | - * @param array $pre_attributes Array of all data attributes. |
|
| 120 | - * |
|
| 121 | - * @since 3.18.0 |
|
| 122 | - * |
|
| 123 | - * @return string $output The data attributes or empty string |
|
| 124 | - */ |
|
| 125 | - private function get_data_attributes( $pre_attributes ) { |
|
| 126 | - // The output. |
|
| 127 | - $output = ''; |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Filter: 'wl_admin_select_element_data_attributes' - Allow third |
|
| 131 | - * parties to modify the field data attrbutes. |
|
| 132 | - * |
|
| 133 | - * @since 3.18.0 |
|
| 134 | - * |
|
| 135 | - * @param array $pre_attributes Array of the field data attributes. |
|
| 136 | - */ |
|
| 137 | - $attributes = apply_filters( 'wl_admin_select_element_data_attributes', $pre_attributes ); |
|
| 138 | - |
|
| 139 | - // Bail is there are no data attributes. |
|
| 140 | - if ( empty( $attributes ) ) { |
|
| 141 | - return $output; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // Loop throught all data attributes and build the output string. |
|
| 145 | - foreach ( $attributes as $name => $value ) { |
|
| 146 | - $output .= sprintf( |
|
| 147 | - 'data-%s="%s" ', |
|
| 148 | - $name, |
|
| 149 | - esc_attr( $value ) |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // Finally return the output escaped. |
|
| 154 | - return $output; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Prints specific resources(scripts/styles) if the select requires them. |
|
| 159 | - * |
|
| 160 | - * @since 3.18.0 |
|
| 161 | - * |
|
| 162 | - * @return void |
|
| 163 | - */ |
|
| 164 | - protected function enqueue_resources() { |
|
| 165 | - |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Abstract method that renders the select options. |
|
| 170 | - * |
|
| 171 | - * @since 3.18.0 |
|
| 172 | - * |
|
| 173 | - * @param array $params Select params. |
|
| 174 | - * |
|
| 175 | - * @return Prints the select options. |
|
| 176 | - */ |
|
| 177 | - abstract function render_options( $params ); |
|
| 53 | + // Print the notice message if there is such. |
|
| 54 | + $this->print_notice( $params['notice'] ); |
|
| 55 | + |
|
| 56 | + // Print the field description. |
|
| 57 | + echo wp_kses( $this->get_description( $params['description'] ), array( 'p' => array() ) ); |
|
| 58 | + |
|
| 59 | + return $this; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Returns html escaped description string. |
|
| 64 | + * Note: Only `a` tags are allowed with only `href` attributes. |
|
| 65 | + * |
|
| 66 | + * @param string|bool $description The field description or false if not set. |
|
| 67 | + * |
|
| 68 | + * @since 3.18.0 |
|
| 69 | + * |
|
| 70 | + * @return string|void The description or null if not set. |
|
| 71 | + */ |
|
| 72 | + public function get_description( $description ) { |
|
| 73 | + // Bail if the description is not set. |
|
| 74 | + if ( empty( $description ) ) { |
|
| 75 | + return; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // Remove all characters except links. |
|
| 79 | + $filtered_descrption = wp_kses( |
|
| 80 | + $description, |
|
| 81 | + array( |
|
| 82 | + 'a' => array( |
|
| 83 | + 'href' => array(), |
|
| 84 | + ), |
|
| 85 | + ) |
|
| 86 | + ); |
|
| 87 | + |
|
| 88 | + return wpautop( $filtered_descrption ); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Prints the field notice that will be shown on error. |
|
| 93 | + * |
|
| 94 | + * @param string $notice The notice to add. |
|
| 95 | + * |
|
| 96 | + * @since 3.18.0 |
|
| 97 | + * |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public function print_notice( $notice ) { |
|
| 101 | + // Bail if the notice is empty. |
|
| 102 | + if ( empty( $notice ) ) { |
|
| 103 | + return; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Print the notice message. |
|
| 107 | + printf( |
|
| 108 | + '<small class="wl-select-notices">%s</small>', |
|
| 109 | + esc_html( $notice ) |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Adds data attributes to select element. |
|
| 115 | + * |
|
| 116 | + * We need to use method here, because different select elements |
|
| 117 | + * may have different data attributes. |
|
| 118 | + * |
|
| 119 | + * @param array $pre_attributes Array of all data attributes. |
|
| 120 | + * |
|
| 121 | + * @since 3.18.0 |
|
| 122 | + * |
|
| 123 | + * @return string $output The data attributes or empty string |
|
| 124 | + */ |
|
| 125 | + private function get_data_attributes( $pre_attributes ) { |
|
| 126 | + // The output. |
|
| 127 | + $output = ''; |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Filter: 'wl_admin_select_element_data_attributes' - Allow third |
|
| 131 | + * parties to modify the field data attrbutes. |
|
| 132 | + * |
|
| 133 | + * @since 3.18.0 |
|
| 134 | + * |
|
| 135 | + * @param array $pre_attributes Array of the field data attributes. |
|
| 136 | + */ |
|
| 137 | + $attributes = apply_filters( 'wl_admin_select_element_data_attributes', $pre_attributes ); |
|
| 138 | + |
|
| 139 | + // Bail is there are no data attributes. |
|
| 140 | + if ( empty( $attributes ) ) { |
|
| 141 | + return $output; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // Loop throught all data attributes and build the output string. |
|
| 145 | + foreach ( $attributes as $name => $value ) { |
|
| 146 | + $output .= sprintf( |
|
| 147 | + 'data-%s="%s" ', |
|
| 148 | + $name, |
|
| 149 | + esc_attr( $value ) |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // Finally return the output escaped. |
|
| 154 | + return $output; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Prints specific resources(scripts/styles) if the select requires them. |
|
| 159 | + * |
|
| 160 | + * @since 3.18.0 |
|
| 161 | + * |
|
| 162 | + * @return void |
|
| 163 | + */ |
|
| 164 | + protected function enqueue_resources() { |
|
| 165 | + |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Abstract method that renders the select options. |
|
| 170 | + * |
|
| 171 | + * @since 3.18.0 |
|
| 172 | + * |
|
| 173 | + * @param array $params Select params. |
|
| 174 | + * |
|
| 175 | + * @return Prints the select options. |
|
| 176 | + */ |
|
| 177 | + abstract function render_options( $params ); |
|
| 178 | 178 | |
| 179 | 179 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * @inheritdoc |
| 23 | 23 | */ |
| 24 | - public function render( $args ) { |
|
| 24 | + public function render($args) { |
|
| 25 | 25 | // Some select fields may need custom script/styles to work. |
| 26 | 26 | $this->enqueue_resources(); |
| 27 | 27 | |
@@ -29,8 +29,8 @@ discard block |
||
| 29 | 29 | $params = wp_parse_args( |
| 30 | 30 | $args, |
| 31 | 31 | array( |
| 32 | - 'id' => uniqid( 'wl-input-' ), |
|
| 33 | - 'name' => uniqid( 'wl-input-' ), |
|
| 32 | + 'id' => uniqid('wl-input-'), |
|
| 33 | + 'name' => uniqid('wl-input-'), |
|
| 34 | 34 | 'value' => '', |
| 35 | 35 | 'class' => '', |
| 36 | 36 | 'notice' => '', |
@@ -41,20 +41,20 @@ discard block |
||
| 41 | 41 | ); |
| 42 | 42 | ?> |
| 43 | 43 | <select |
| 44 | - id="<?php echo esc_attr( $params['id'] ); ?>" |
|
| 45 | - name="<?php echo esc_attr( $params['name'] ); ?>" |
|
| 46 | - class="<?php echo esc_attr( $params['class'] ); ?>" |
|
| 47 | - <?php echo $this->get_data_attributes( $params['data'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
|
| 44 | + id="<?php echo esc_attr($params['id']); ?>" |
|
| 45 | + name="<?php echo esc_attr($params['name']); ?>" |
|
| 46 | + class="<?php echo esc_attr($params['class']); ?>" |
|
| 47 | + <?php echo $this->get_data_attributes($params['data']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
|
| 48 | 48 | > |
| 49 | - <?php $this->render_options( $params ); ?> |
|
| 49 | + <?php $this->render_options($params); ?> |
|
| 50 | 50 | </select> |
| 51 | 51 | |
| 52 | 52 | <?php |
| 53 | 53 | // Print the notice message if there is such. |
| 54 | - $this->print_notice( $params['notice'] ); |
|
| 54 | + $this->print_notice($params['notice']); |
|
| 55 | 55 | |
| 56 | 56 | // Print the field description. |
| 57 | - echo wp_kses( $this->get_description( $params['description'] ), array( 'p' => array() ) ); |
|
| 57 | + echo wp_kses($this->get_description($params['description']), array('p' => array())); |
|
| 58 | 58 | |
| 59 | 59 | return $this; |
| 60 | 60 | } |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @return string|void The description or null if not set. |
| 71 | 71 | */ |
| 72 | - public function get_description( $description ) { |
|
| 72 | + public function get_description($description) { |
|
| 73 | 73 | // Bail if the description is not set. |
| 74 | - if ( empty( $description ) ) { |
|
| 74 | + if (empty($description)) { |
|
| 75 | 75 | return; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | ) |
| 86 | 86 | ); |
| 87 | 87 | |
| 88 | - return wpautop( $filtered_descrption ); |
|
| 88 | + return wpautop($filtered_descrption); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -97,16 +97,16 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @return void |
| 99 | 99 | */ |
| 100 | - public function print_notice( $notice ) { |
|
| 100 | + public function print_notice($notice) { |
|
| 101 | 101 | // Bail if the notice is empty. |
| 102 | - if ( empty( $notice ) ) { |
|
| 102 | + if (empty($notice)) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Print the notice message. |
| 107 | 107 | printf( |
| 108 | 108 | '<small class="wl-select-notices">%s</small>', |
| 109 | - esc_html( $notice ) |
|
| 109 | + esc_html($notice) |
|
| 110 | 110 | ); |
| 111 | 111 | } |
| 112 | 112 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @return string $output The data attributes or empty string |
| 124 | 124 | */ |
| 125 | - private function get_data_attributes( $pre_attributes ) { |
|
| 125 | + private function get_data_attributes($pre_attributes) { |
|
| 126 | 126 | // The output. |
| 127 | 127 | $output = ''; |
| 128 | 128 | |
@@ -134,19 +134,19 @@ discard block |
||
| 134 | 134 | * |
| 135 | 135 | * @param array $pre_attributes Array of the field data attributes. |
| 136 | 136 | */ |
| 137 | - $attributes = apply_filters( 'wl_admin_select_element_data_attributes', $pre_attributes ); |
|
| 137 | + $attributes = apply_filters('wl_admin_select_element_data_attributes', $pre_attributes); |
|
| 138 | 138 | |
| 139 | 139 | // Bail is there are no data attributes. |
| 140 | - if ( empty( $attributes ) ) { |
|
| 140 | + if (empty($attributes)) { |
|
| 141 | 141 | return $output; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // Loop throught all data attributes and build the output string. |
| 145 | - foreach ( $attributes as $name => $value ) { |
|
| 145 | + foreach ($attributes as $name => $value) { |
|
| 146 | 146 | $output .= sprintf( |
| 147 | 147 | 'data-%s="%s" ', |
| 148 | 148 | $name, |
| 149 | - esc_attr( $value ) |
|
| 149 | + esc_attr($value) |
|
| 150 | 150 | ); |
| 151 | 151 | } |
| 152 | 152 | |
@@ -174,6 +174,6 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return Prints the select options. |
| 176 | 176 | */ |
| 177 | - abstract function render_options( $params ); |
|
| 177 | + abstract function render_options($params); |
|
| 178 | 178 | |
| 179 | 179 | } |
@@ -18,48 +18,48 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Radio_Input_Element implements Wordlift_Admin_Element { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Output the HTML for an input box type settings_page. |
|
| 23 | - * |
|
| 24 | - * @param array $args { |
|
| 25 | - * An array of arguments. |
|
| 26 | - * |
|
| 27 | - * @type string $name The name attribute of the input element. Mandatory. |
|
| 28 | - * @type string $id The id attribute of the input element. Optional, |
|
| 29 | - * randomly generated one is used if not supplied. |
|
| 30 | - * @type string $value The value of the input element. Optional, defaults |
|
| 31 | - * to empty string. |
|
| 32 | - * @type string $css_class The class attribute for the input element. If empty |
|
| 33 | - * string no class attribute will be added. Optional, |
|
| 34 | - * defaults to empty string. |
|
| 35 | - * @type string $description The description text to be displayed below the element. |
|
| 36 | - * Can include some HTML element. If empty string no |
|
| 37 | - * description will be displayed. Optional, defaults to |
|
| 38 | - * empty string. |
|
| 39 | - * } |
|
| 40 | - * @return $this|Wordlift_Admin_Element |
|
| 41 | - * @since 3.13.0 |
|
| 42 | - * |
|
| 43 | - */ |
|
| 44 | - public function render( $args ) { |
|
| 45 | - /* |
|
| 21 | + /** |
|
| 22 | + * Output the HTML for an input box type settings_page. |
|
| 23 | + * |
|
| 24 | + * @param array $args { |
|
| 25 | + * An array of arguments. |
|
| 26 | + * |
|
| 27 | + * @type string $name The name attribute of the input element. Mandatory. |
|
| 28 | + * @type string $id The id attribute of the input element. Optional, |
|
| 29 | + * randomly generated one is used if not supplied. |
|
| 30 | + * @type string $value The value of the input element. Optional, defaults |
|
| 31 | + * to empty string. |
|
| 32 | + * @type string $css_class The class attribute for the input element. If empty |
|
| 33 | + * string no class attribute will be added. Optional, |
|
| 34 | + * defaults to empty string. |
|
| 35 | + * @type string $description The description text to be displayed below the element. |
|
| 36 | + * Can include some HTML element. If empty string no |
|
| 37 | + * description will be displayed. Optional, defaults to |
|
| 38 | + * empty string. |
|
| 39 | + * } |
|
| 40 | + * @return $this|Wordlift_Admin_Element |
|
| 41 | + * @since 3.13.0 |
|
| 42 | + * |
|
| 43 | + */ |
|
| 44 | + public function render( $args ) { |
|
| 45 | + /* |
|
| 46 | 46 | * Parse the arguments and merge with default values. |
| 47 | 47 | * Name intentionally do not have a default as it has to be in SyncEvent |
| 48 | 48 | * with form handling code |
| 49 | 49 | */ |
| 50 | - $params = wp_parse_args( $args, array( |
|
| 51 | - 'id' => uniqid( 'wl-input-' ), |
|
| 52 | - 'value' => '', |
|
| 53 | - 'css_class' => '', |
|
| 54 | - 'description' => '', |
|
| 55 | - ) ); |
|
| 50 | + $params = wp_parse_args( $args, array( |
|
| 51 | + 'id' => uniqid( 'wl-input-' ), |
|
| 52 | + 'value' => '', |
|
| 53 | + 'css_class' => '', |
|
| 54 | + 'description' => '', |
|
| 55 | + ) ); |
|
| 56 | 56 | |
| 57 | - // Set the readonly and class attributes and the description. |
|
| 58 | - $value = $params['value']; |
|
| 59 | - $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 60 | - $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 57 | + // Set the readonly and class attributes and the description. |
|
| 58 | + $value = $params['value']; |
|
| 59 | + $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 60 | + $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 61 | 61 | |
| 62 | - ?> |
|
| 62 | + ?> |
|
| 63 | 63 | |
| 64 | 64 | <input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>" |
| 65 | 65 | name="<?php echo esc_attr( $params['name'] ); ?>" |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | /> No |
| 74 | 74 | |
| 75 | 75 | <?php |
| 76 | - echo wp_kses( $description, array( 'a' => array( 'href' => array() ) ) ); |
|
| 76 | + echo wp_kses( $description, array( 'a' => array( 'href' => array() ) ) ); |
|
| 77 | 77 | |
| 78 | - return $this; |
|
| 79 | - } |
|
| 78 | + return $this; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | } |
@@ -41,39 +41,39 @@ |
||
| 41 | 41 | * @since 3.13.0 |
| 42 | 42 | * |
| 43 | 43 | */ |
| 44 | - public function render( $args ) { |
|
| 44 | + public function render($args) { |
|
| 45 | 45 | /* |
| 46 | 46 | * Parse the arguments and merge with default values. |
| 47 | 47 | * Name intentionally do not have a default as it has to be in SyncEvent |
| 48 | 48 | * with form handling code |
| 49 | 49 | */ |
| 50 | - $params = wp_parse_args( $args, array( |
|
| 51 | - 'id' => uniqid( 'wl-input-' ), |
|
| 50 | + $params = wp_parse_args($args, array( |
|
| 51 | + 'id' => uniqid('wl-input-'), |
|
| 52 | 52 | 'value' => '', |
| 53 | 53 | 'css_class' => '', |
| 54 | 54 | 'description' => '', |
| 55 | - ) ); |
|
| 55 | + )); |
|
| 56 | 56 | |
| 57 | 57 | // Set the readonly and class attributes and the description. |
| 58 | 58 | $value = $params['value']; |
| 59 | - $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 60 | - $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 59 | + $css_class = ! empty($params['css_class']) ? ' class="'.esc_attr($params['css_class']).'"' : ''; |
|
| 60 | + $description = ! empty($params['description']) ? '<p>'.wp_kses($params['description'], array('a' => array('href' => array()))).'</p>' : ''; |
|
| 61 | 61 | |
| 62 | 62 | ?> |
| 63 | 63 | |
| 64 | - <input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>" |
|
| 65 | - name="<?php echo esc_attr( $params['name'] ); ?>" |
|
| 64 | + <input type="radio" id="<?php echo esc_attr($params['id']); ?>" |
|
| 65 | + name="<?php echo esc_attr($params['name']); ?>" |
|
| 66 | 66 | value="yes" <?php echo $css_class; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 67 | - <?php checked( $value, 'yes' ); ?> |
|
| 67 | + <?php checked($value, 'yes'); ?> |
|
| 68 | 68 | /> Yes |
| 69 | - <input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>" |
|
| 70 | - name="<?php echo esc_attr( $params['name'] ); ?>" |
|
| 69 | + <input type="radio" id="<?php echo esc_attr($params['id']); ?>" |
|
| 70 | + name="<?php echo esc_attr($params['name']); ?>" |
|
| 71 | 71 | value="no" <?php echo $css_class; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped?> |
| 72 | - <?php checked( $value, 'no' ); ?> |
|
| 72 | + <?php checked($value, 'no'); ?> |
|
| 73 | 73 | /> No |
| 74 | 74 | |
| 75 | 75 | <?php |
| 76 | - echo wp_kses( $description, array( 'a' => array( 'href' => array() ) ) ); |
|
| 76 | + echo wp_kses($description, array('a' => array('href' => array()))); |
|
| 77 | 77 | |
| 78 | 78 | return $this; |
| 79 | 79 | } |
@@ -15,24 +15,24 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | function wl_admin_menu() { |
| 17 | 17 | |
| 18 | - $menu_slug = 'wl_admin_menu'; |
|
| 19 | - $capability = 'manage_options'; |
|
| 18 | + $menu_slug = 'wl_admin_menu'; |
|
| 19 | + $capability = 'manage_options'; |
|
| 20 | 20 | |
| 21 | - // see http://codex.wordpress.org/Function_Reference/add_menu_page |
|
| 22 | - add_menu_page( |
|
| 23 | - __( 'WordLift', 'wordlift' ), // page title |
|
| 24 | - __( 'WordLift', 'wordlift' ), // menu title |
|
| 25 | - $capability, // capabilities |
|
| 26 | - $menu_slug, // menu slug |
|
| 27 | - //'wl_admin_menu_callback', // TODO: function callback to draw the coming dashboard |
|
| 28 | - 'wl_configuration_admin_menu_callback', |
|
| 29 | - WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-logo-icon.svg' ); // icon URL 20x20 px |
|
| 21 | + // see http://codex.wordpress.org/Function_Reference/add_menu_page |
|
| 22 | + add_menu_page( |
|
| 23 | + __( 'WordLift', 'wordlift' ), // page title |
|
| 24 | + __( 'WordLift', 'wordlift' ), // menu title |
|
| 25 | + $capability, // capabilities |
|
| 26 | + $menu_slug, // menu slug |
|
| 27 | + //'wl_admin_menu_callback', // TODO: function callback to draw the coming dashboard |
|
| 28 | + 'wl_configuration_admin_menu_callback', |
|
| 29 | + WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-logo-icon.svg' ); // icon URL 20x20 px |
|
| 30 | 30 | |
| 31 | - // Call hooked functions. |
|
| 32 | - do_action( 'wl_admin_menu', $menu_slug, $capability ); |
|
| 31 | + // Call hooked functions. |
|
| 32 | + do_action( 'wl_admin_menu', $menu_slug, $capability ); |
|
| 33 | 33 | |
| 34 | - // Remove duplicate 'WordLift' subpage created by WordPress. |
|
| 35 | - remove_submenu_page( $menu_slug, $menu_slug ); |
|
| 34 | + // Remove duplicate 'WordLift' subpage created by WordPress. |
|
| 35 | + remove_submenu_page( $menu_slug, $menu_slug ); |
|
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | |
@@ -46,20 +46,20 @@ discard block |
||
| 46 | 46 | * @since 3.15.0 |
| 47 | 47 | */ |
| 48 | 48 | function wl_remove_entity_type_menu() { |
| 49 | - /* |
|
| 49 | + /* |
|
| 50 | 50 | * Remove from the menu links to the entity type admin page when |
| 51 | 51 | * under non entity hierarchy. |
| 52 | 52 | */ |
| 53 | - foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $post_type ) { |
|
| 54 | - // In the context of admin menues post has no explicit indication of post type in the urls. |
|
| 55 | - if ( 'post' !== $post_type ) { |
|
| 56 | - remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=' . Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 57 | - } |
|
| 53 | + foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $post_type ) { |
|
| 54 | + // In the context of admin menues post has no explicit indication of post type in the urls. |
|
| 55 | + if ( 'post' !== $post_type ) { |
|
| 56 | + remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=' . Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - if ( Wordlift_Entity_Service::TYPE_NAME !== $post_type ) { |
|
| 60 | - remove_submenu_page( 'edit.php?post_type=' . $post_type, 'edit-tags.php?taxonomy=' . Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME . '&post_type=' . $post_type ); |
|
| 61 | - } |
|
| 62 | - } |
|
| 59 | + if ( Wordlift_Entity_Service::TYPE_NAME !== $post_type ) { |
|
| 60 | + remove_submenu_page( 'edit.php?post_type=' . $post_type, 'edit-tags.php?taxonomy=' . Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME . '&post_type=' . $post_type ); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | add_action( 'admin_menu', 'wl_remove_entity_type_menu', 100 ); |
@@ -71,12 +71,12 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | function wl_admin_menu_callback() { |
| 73 | 73 | |
| 74 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 75 | - wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) ); |
|
| 76 | - } |
|
| 74 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 75 | + wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) ); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - echo '<div class="wrap">'; |
|
| 79 | - echo '<p>Here is where the form would go if I actually had options.</p>'; |
|
| 80 | - echo '</div>'; |
|
| 78 | + echo '<div class="wrap">'; |
|
| 79 | + echo '<p>Here is where the form would go if I actually had options.</p>'; |
|
| 80 | + echo '</div>'; |
|
| 81 | 81 | |
| 82 | 82 | } |
@@ -20,23 +20,23 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | // see http://codex.wordpress.org/Function_Reference/add_menu_page |
| 22 | 22 | add_menu_page( |
| 23 | - __( 'WordLift', 'wordlift' ), // page title |
|
| 24 | - __( 'WordLift', 'wordlift' ), // menu title |
|
| 25 | - $capability, // capabilities |
|
| 26 | - $menu_slug, // menu slug |
|
| 23 | + __('WordLift', 'wordlift'), // page title |
|
| 24 | + __('WordLift', 'wordlift'), // menu title |
|
| 25 | + $capability, // capabilities |
|
| 26 | + $menu_slug, // menu slug |
|
| 27 | 27 | //'wl_admin_menu_callback', // TODO: function callback to draw the coming dashboard |
| 28 | 28 | 'wl_configuration_admin_menu_callback', |
| 29 | - WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-logo-icon.svg' ); // icon URL 20x20 px |
|
| 29 | + WP_CONTENT_URL.'/plugins/wordlift/images/svg/wl-logo-icon.svg' ); // icon URL 20x20 px |
|
| 30 | 30 | |
| 31 | 31 | // Call hooked functions. |
| 32 | - do_action( 'wl_admin_menu', $menu_slug, $capability ); |
|
| 32 | + do_action('wl_admin_menu', $menu_slug, $capability); |
|
| 33 | 33 | |
| 34 | 34 | // Remove duplicate 'WordLift' subpage created by WordPress. |
| 35 | - remove_submenu_page( $menu_slug, $menu_slug ); |
|
| 35 | + remove_submenu_page($menu_slug, $menu_slug); |
|
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | -add_action( 'admin_menu', 'wl_admin_menu' ); |
|
| 39 | +add_action('admin_menu', 'wl_admin_menu'); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * This function is called by the *admin_menu* hook to remove for the admin menu |
@@ -50,19 +50,19 @@ discard block |
||
| 50 | 50 | * Remove from the menu links to the entity type admin page when |
| 51 | 51 | * under non entity hierarchy. |
| 52 | 52 | */ |
| 53 | - foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $post_type ) { |
|
| 53 | + foreach (Wordlift_Entity_Service::valid_entity_post_types() as $post_type) { |
|
| 54 | 54 | // In the context of admin menues post has no explicit indication of post type in the urls. |
| 55 | - if ( 'post' !== $post_type ) { |
|
| 56 | - remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=' . Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 55 | + if ('post' !== $post_type) { |
|
| 56 | + remove_submenu_page('edit.php', 'edit-tags.php?taxonomy='.Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if ( Wordlift_Entity_Service::TYPE_NAME !== $post_type ) { |
|
| 60 | - remove_submenu_page( 'edit.php?post_type=' . $post_type, 'edit-tags.php?taxonomy=' . Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME . '&post_type=' . $post_type ); |
|
| 59 | + if (Wordlift_Entity_Service::TYPE_NAME !== $post_type) { |
|
| 60 | + remove_submenu_page('edit.php?post_type='.$post_type, 'edit-tags.php?taxonomy='.Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME.'&post_type='.$post_type); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | -add_action( 'admin_menu', 'wl_remove_entity_type_menu', 100 ); |
|
| 65 | +add_action('admin_menu', 'wl_remove_entity_type_menu', 100); |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * This function is called as a callback by the *wl_admin_menu* to display the actual page. |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | function wl_admin_menu_callback() { |
| 73 | 73 | |
| 74 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 75 | - wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) ); |
|
| 74 | + if ( ! current_user_can('manage_options')) { |
|
| 75 | + wp_die(esc_html__('You do not have sufficient permissions to access this page.')); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | echo '<div class="wrap">'; |
@@ -21,14 +21,14 @@ discard block |
||
| 21 | 21 | * @since 3.20.0 |
| 22 | 22 | * |
| 23 | 23 | */ |
| 24 | - public function __construct( $entity_service ) { |
|
| 24 | + public function __construct($entity_service) { |
|
| 25 | 25 | |
| 26 | - add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) ); |
|
| 26 | + add_action('wp_dashboard_setup', array($this, 'dashboard_setup')); |
|
| 27 | 27 | |
| 28 | 28 | // Define where to access the tip. |
| 29 | - defined( 'WL_TODAYS_TIP_JSON_URL' ) || define( 'WL_TODAYS_TIP_JSON_URL', 'https://wordlift.io/blog' ); |
|
| 30 | - defined( 'WL_TODAYS_TIP_JSON_URL_IT' ) || define( 'WL_TODAYS_TIP_JSON_URL_IT', '/it/wp-json/wp/v2/posts?context=embed&per_page=1&categories=27' ); |
|
| 31 | - defined( 'WL_TODAYS_TIP_JSON_URL_EN' ) || define( 'WL_TODAYS_TIP_JSON_URL_EN', '/en/wp-json/wp/v2/posts?context=embed&per_page=1&categories=38' ); |
|
| 29 | + defined('WL_TODAYS_TIP_JSON_URL') || define('WL_TODAYS_TIP_JSON_URL', 'https://wordlift.io/blog'); |
|
| 30 | + defined('WL_TODAYS_TIP_JSON_URL_IT') || define('WL_TODAYS_TIP_JSON_URL_IT', '/it/wp-json/wp/v2/posts?context=embed&per_page=1&categories=27'); |
|
| 31 | + defined('WL_TODAYS_TIP_JSON_URL_EN') || define('WL_TODAYS_TIP_JSON_URL_EN', '/en/wp-json/wp/v2/posts?context=embed&per_page=1&categories=38'); |
|
| 32 | 32 | $this->entity_service = $entity_service; |
| 33 | 33 | |
| 34 | 34 | } |
@@ -44,11 +44,11 @@ discard block |
||
| 44 | 44 | * Feature flag to enable / disable dashboard |
| 45 | 45 | * @since 3.30.0 |
| 46 | 46 | */ |
| 47 | - if ( apply_filters( 'wl_feature__enable__wordlift-dashboard', true ) ) { |
|
| 47 | + if (apply_filters('wl_feature__enable__wordlift-dashboard', true)) { |
|
| 48 | 48 | wp_add_dashboard_widget( |
| 49 | 49 | 'wl-dashboard-v2', |
| 50 | - __( 'WordLift Dashboard', 'wordlift' ), |
|
| 51 | - array( $this, 'dashboard_setup_callback' ) |
|
| 50 | + __('WordLift Dashboard', 'wordlift'), |
|
| 51 | + array($this, 'dashboard_setup_callback') |
|
| 52 | 52 | ); |
| 53 | 53 | } |
| 54 | 54 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function dashboard_setup_callback() { |
| 63 | 63 | |
| 64 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-dashboard-v2.php'; |
|
| 64 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/partials/wordlift-admin-dashboard-v2.php'; |
|
| 65 | 65 | |
| 66 | 66 | } |
| 67 | 67 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
| 80 | 80 | * Top entities are generated by cron now. |
| 81 | 81 | */ |
| 82 | - return get_option( Top_Entities::OPTION_KEY, array() ); |
|
| 82 | + return get_option(Top_Entities::OPTION_KEY, array()); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -92,20 +92,20 @@ discard block |
||
| 92 | 92 | $data = @self::get_todays_tip_data(); |
| 93 | 93 | |
| 94 | 94 | // Unable to get data from the local cache, nor from the remote URL. |
| 95 | - if ( false === $data ) { |
|
| 95 | + if (false === $data) { |
|
| 96 | 96 | return; |
| 97 | 97 | } |
| 98 | 98 | ?> |
| 99 | 99 | |
| 100 | 100 | <div id="wl-todays-tip" class="wl-dashboard__block wl-dashboard__block--todays-tip"> |
| 101 | 101 | <header> |
| 102 | - <h3><?php esc_html_e( "Today's Tip", 'wordlift' ); ?></h3> |
|
| 102 | + <h3><?php esc_html_e("Today's Tip", 'wordlift'); ?></h3> |
|
| 103 | 103 | </header> |
| 104 | 104 | <article> |
| 105 | - <p><strong><?php echo esc_html( wp_strip_all_tags( $data['title'] ) ); ?></strong> |
|
| 106 | - <?php echo esc_html( wp_strip_all_tags( $data['excerpt'] ) ); ?> |
|
| 105 | + <p><strong><?php echo esc_html(wp_strip_all_tags($data['title'])); ?></strong> |
|
| 106 | + <?php echo esc_html(wp_strip_all_tags($data['excerpt'])); ?> |
|
| 107 | 107 | <a target="_blank" |
| 108 | - href="<?php echo esc_attr( $data['link'] ); ?>"><?php echo esc_html( __( 'Read more', 'wordlift' ) ); ?></a> |
|
| 108 | + href="<?php echo esc_attr($data['link']); ?>"><?php echo esc_html(__('Read more', 'wordlift')); ?></a> |
|
| 109 | 109 | </p> |
| 110 | 110 | </div> |
| 111 | 111 | <?php |
@@ -122,39 +122,39 @@ discard block |
||
| 122 | 122 | private static function get_todays_tip_data() { |
| 123 | 123 | |
| 124 | 124 | // Return the transient. |
| 125 | - if ( false !== get_transient( self::TODAYS_TIP ) ) { |
|
| 126 | - return get_transient( self::TODAYS_TIP ); |
|
| 125 | + if (false !== get_transient(self::TODAYS_TIP)) { |
|
| 126 | + return get_transient(self::TODAYS_TIP); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // If the transient isn't available, query the remote web site. |
| 130 | 130 | $url = WL_TODAYS_TIP_JSON_URL |
| 131 | - . ( 'it' === get_bloginfo( 'language' ) ? WL_TODAYS_TIP_JSON_URL_IT : WL_TODAYS_TIP_JSON_URL_EN ); |
|
| 131 | + . ('it' === get_bloginfo('language') ? WL_TODAYS_TIP_JSON_URL_IT : WL_TODAYS_TIP_JSON_URL_EN); |
|
| 132 | 132 | |
| 133 | - $response = wp_remote_get( $url ); |
|
| 133 | + $response = wp_remote_get($url); |
|
| 134 | 134 | |
| 135 | - if ( is_wp_error( $response ) |
|
| 136 | - || ! isset( $response['response']['code'] ) |
|
| 137 | - || 2 !== (int) $response['response']['code'] / 100 ) { |
|
| 135 | + if (is_wp_error($response) |
|
| 136 | + || ! isset($response['response']['code']) |
|
| 137 | + || 2 !== (int) $response['response']['code'] / 100) { |
|
| 138 | 138 | return false; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $json = json_decode( $response['body'], true ); |
|
| 141 | + $json = json_decode($response['body'], true); |
|
| 142 | 142 | |
| 143 | - if ( empty( $json ) |
|
| 144 | - || ! isset( $json[0]['title']['rendered'] ) |
|
| 145 | - || ! isset( $json[0]['excerpt']['rendered'] ) |
|
| 146 | - || ! isset( $json[0]['link'] ) ) { |
|
| 143 | + if (empty($json) |
|
| 144 | + || ! isset($json[0]['title']['rendered']) |
|
| 145 | + || ! isset($json[0]['excerpt']['rendered']) |
|
| 146 | + || ! isset($json[0]['link'])) { |
|
| 147 | 147 | return false; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | $value = array( |
| 151 | 151 | 'title' => $json[0]['title']['rendered'], |
| 152 | - 'excerpt' => '<!-- cached -->' . $json[0]['excerpt']['rendered'], |
|
| 152 | + 'excerpt' => '<!-- cached -->'.$json[0]['excerpt']['rendered'], |
|
| 153 | 153 | 'link' => $json[0]['link'], |
| 154 | 154 | ); |
| 155 | 155 | |
| 156 | 156 | // Store the results for one day. |
| 157 | - set_transient( self::TODAYS_TIP, $value, 86400 ); |
|
| 157 | + set_transient(self::TODAYS_TIP, $value, 86400); |
|
| 158 | 158 | |
| 159 | 159 | return $value; |
| 160 | 160 | } |
@@ -18,133 +18,133 @@ |
||
| 18 | 18 | * @since 3.6.0 |
| 19 | 19 | */ |
| 20 | 20 | class Wordlift_Admin_Download_Your_Data_Page { |
| 21 | - /** |
|
| 22 | - * Used to check if the requested file is supported. |
|
| 23 | - * |
|
| 24 | - * @since 3.16.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var $allowed_formats array Allowed formats. |
|
| 27 | - */ |
|
| 28 | - private $allowed_formats = array( |
|
| 29 | - 'json', |
|
| 30 | - 'rdf', |
|
| 31 | - 'ttl', |
|
| 32 | - 'n3', |
|
| 33 | - ); |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * The list of headers allowed by the endpoint. |
|
| 38 | - * @since 3.28.2 |
|
| 39 | - * @var string[] |
|
| 40 | - */ |
|
| 41 | - private $allowed_headers = array( |
|
| 42 | - 'json' => 'application/ld+json', |
|
| 43 | - 'rdf' => 'application/rdf+xml', |
|
| 44 | - 'n3' => 'text/n3', |
|
| 45 | - 'ttl' => 'text/turtle' |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Hook to 'admin_menu' to add the 'Download Your Data' page. |
|
| 50 | - * |
|
| 51 | - * @since 3.6.0 |
|
| 52 | - */ |
|
| 53 | - public function admin_menu() { |
|
| 54 | - |
|
| 55 | - // Add a callback to our 'page' function. |
|
| 56 | - add_submenu_page( |
|
| 57 | - 'wl_admin_menu', |
|
| 58 | - _x( 'Download Your Data', 'Page title', 'wordlift' ), |
|
| 59 | - _x( 'Download Your Data', 'Menu title', 'wordlift' ), |
|
| 60 | - 'manage_options', |
|
| 61 | - 'wl_download_your_data', |
|
| 62 | - array( $this, 'page' ) |
|
| 63 | - ); |
|
| 64 | - |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * The admin menu callback to render the page. |
|
| 69 | - * |
|
| 70 | - * @since 3.6.0 |
|
| 71 | - */ |
|
| 72 | - public function page() { |
|
| 73 | - |
|
| 74 | - // Include the partial. |
|
| 75 | - include( plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-download-your-data.php' ); |
|
| 76 | - |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Ajax call to redirect to a download URL. |
|
| 81 | - * |
|
| 82 | - * @since 3.6.0 |
|
| 83 | - */ |
|
| 84 | - public function download_your_data() { |
|
| 85 | - |
|
| 86 | - $default_api_service = Default_Api_Service::get_instance(); |
|
| 87 | - |
|
| 88 | - // Avoid PHP notices when buffer is empty. |
|
| 89 | - if ( ob_get_contents() ) { |
|
| 90 | - ob_end_clean(); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Get WL's key. |
|
| 94 | - $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 95 | - |
|
| 96 | - // Use json suffix by default. |
|
| 97 | - $suffix = 'json'; |
|
| 98 | - |
|
| 99 | - // Check if there is suffix. |
|
| 100 | - if ( isset( $_GET['out'] ) ) { |
|
| 101 | - $suffix = sanitize_text_field( wp_unslash( $_GET['out'] ) ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // Create filename. |
|
| 105 | - $filename = 'dataset.' . $suffix; |
|
| 106 | - |
|
| 107 | - if ( ! in_array( $suffix, $this->allowed_formats, true ) ) { |
|
| 108 | - // The file type is not from allowed types. |
|
| 109 | - wp_die( esc_html__( 'The format is not supported.', 'wordlift' ) ); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - $accept_header_format = $this->allowed_headers[ $suffix ]; |
|
| 114 | - |
|
| 115 | - $headers = array( |
|
| 116 | - 'Accept' => $accept_header_format |
|
| 117 | - ); |
|
| 118 | - |
|
| 119 | - $response = $default_api_service->get( '/dataset/export', $headers ); |
|
| 120 | - |
|
| 121 | - $response = $response->get_response(); |
|
| 122 | - |
|
| 123 | - if ( |
|
| 124 | - is_wp_error( $response ) || |
|
| 125 | - 200 !== (int) $response['response']['code'] |
|
| 126 | - ) { |
|
| 127 | - // Something is not working properly, so display error message. |
|
| 128 | - wp_die( esc_html__( 'There was an error trying to connect to the server. Please try again later.', 'wordlift' ) ); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - // Get response body. |
|
| 133 | - $body = wp_remote_retrieve_body( $response ); |
|
| 134 | - $type = wp_remote_retrieve_header( $response, 'content-type' ); |
|
| 135 | - $filename = 'dataset-' . date( 'Y-m-d-H-i-s' ) . '.' . $suffix; |
|
| 136 | - |
|
| 137 | - // Add proper file headers. |
|
| 138 | - header( "Content-Disposition: attachment; filename=$filename" ); |
|
| 139 | - header( "Content-Type: $type" ); |
|
| 140 | - |
|
| 141 | - /* |
|
| 21 | + /** |
|
| 22 | + * Used to check if the requested file is supported. |
|
| 23 | + * |
|
| 24 | + * @since 3.16.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var $allowed_formats array Allowed formats. |
|
| 27 | + */ |
|
| 28 | + private $allowed_formats = array( |
|
| 29 | + 'json', |
|
| 30 | + 'rdf', |
|
| 31 | + 'ttl', |
|
| 32 | + 'n3', |
|
| 33 | + ); |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * The list of headers allowed by the endpoint. |
|
| 38 | + * @since 3.28.2 |
|
| 39 | + * @var string[] |
|
| 40 | + */ |
|
| 41 | + private $allowed_headers = array( |
|
| 42 | + 'json' => 'application/ld+json', |
|
| 43 | + 'rdf' => 'application/rdf+xml', |
|
| 44 | + 'n3' => 'text/n3', |
|
| 45 | + 'ttl' => 'text/turtle' |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Hook to 'admin_menu' to add the 'Download Your Data' page. |
|
| 50 | + * |
|
| 51 | + * @since 3.6.0 |
|
| 52 | + */ |
|
| 53 | + public function admin_menu() { |
|
| 54 | + |
|
| 55 | + // Add a callback to our 'page' function. |
|
| 56 | + add_submenu_page( |
|
| 57 | + 'wl_admin_menu', |
|
| 58 | + _x( 'Download Your Data', 'Page title', 'wordlift' ), |
|
| 59 | + _x( 'Download Your Data', 'Menu title', 'wordlift' ), |
|
| 60 | + 'manage_options', |
|
| 61 | + 'wl_download_your_data', |
|
| 62 | + array( $this, 'page' ) |
|
| 63 | + ); |
|
| 64 | + |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * The admin menu callback to render the page. |
|
| 69 | + * |
|
| 70 | + * @since 3.6.0 |
|
| 71 | + */ |
|
| 72 | + public function page() { |
|
| 73 | + |
|
| 74 | + // Include the partial. |
|
| 75 | + include( plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-download-your-data.php' ); |
|
| 76 | + |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Ajax call to redirect to a download URL. |
|
| 81 | + * |
|
| 82 | + * @since 3.6.0 |
|
| 83 | + */ |
|
| 84 | + public function download_your_data() { |
|
| 85 | + |
|
| 86 | + $default_api_service = Default_Api_Service::get_instance(); |
|
| 87 | + |
|
| 88 | + // Avoid PHP notices when buffer is empty. |
|
| 89 | + if ( ob_get_contents() ) { |
|
| 90 | + ob_end_clean(); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Get WL's key. |
|
| 94 | + $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 95 | + |
|
| 96 | + // Use json suffix by default. |
|
| 97 | + $suffix = 'json'; |
|
| 98 | + |
|
| 99 | + // Check if there is suffix. |
|
| 100 | + if ( isset( $_GET['out'] ) ) { |
|
| 101 | + $suffix = sanitize_text_field( wp_unslash( $_GET['out'] ) ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // Create filename. |
|
| 105 | + $filename = 'dataset.' . $suffix; |
|
| 106 | + |
|
| 107 | + if ( ! in_array( $suffix, $this->allowed_formats, true ) ) { |
|
| 108 | + // The file type is not from allowed types. |
|
| 109 | + wp_die( esc_html__( 'The format is not supported.', 'wordlift' ) ); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + $accept_header_format = $this->allowed_headers[ $suffix ]; |
|
| 114 | + |
|
| 115 | + $headers = array( |
|
| 116 | + 'Accept' => $accept_header_format |
|
| 117 | + ); |
|
| 118 | + |
|
| 119 | + $response = $default_api_service->get( '/dataset/export', $headers ); |
|
| 120 | + |
|
| 121 | + $response = $response->get_response(); |
|
| 122 | + |
|
| 123 | + if ( |
|
| 124 | + is_wp_error( $response ) || |
|
| 125 | + 200 !== (int) $response['response']['code'] |
|
| 126 | + ) { |
|
| 127 | + // Something is not working properly, so display error message. |
|
| 128 | + wp_die( esc_html__( 'There was an error trying to connect to the server. Please try again later.', 'wordlift' ) ); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + // Get response body. |
|
| 133 | + $body = wp_remote_retrieve_body( $response ); |
|
| 134 | + $type = wp_remote_retrieve_header( $response, 'content-type' ); |
|
| 135 | + $filename = 'dataset-' . date( 'Y-m-d-H-i-s' ) . '.' . $suffix; |
|
| 136 | + |
|
| 137 | + // Add proper file headers. |
|
| 138 | + header( "Content-Disposition: attachment; filename=$filename" ); |
|
| 139 | + header( "Content-Type: $type" ); |
|
| 140 | + |
|
| 141 | + /* |
|
| 142 | 142 | * Echo the response body. As this is not HTML we can not escape it |
| 143 | 143 | * and neither sanitize it, therefor turning off the linter notice. |
| 144 | 144 | */ |
| 145 | - echo $body; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 145 | + echo $body; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 146 | 146 | |
| 147 | - // Exit in both cases. |
|
| 148 | - exit; |
|
| 149 | - } |
|
| 147 | + // Exit in both cases. |
|
| 148 | + exit; |
|
| 149 | + } |
|
| 150 | 150 | } |
@@ -7,194 +7,194 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Wordlift_Notice_Service { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * The template used to display notices. The <em>notice dismissible</em> style classes make this notice dismissible |
|
| 12 | - * on the WordPress UI (via a small X button on the right side of the notice). |
|
| 13 | - * |
|
| 14 | - * @since 3.2.0 |
|
| 15 | - */ |
|
| 16 | - const TEMPLATE = '<div class="wl-notice notice is-dismissible %s"><p>%s</p></div>'; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * The standard WordPress <em>update</em> style class. |
|
| 20 | - * |
|
| 21 | - * @since 3.2.0 |
|
| 22 | - */ |
|
| 23 | - const UPDATE = 'update'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * The standard WordPress <em>update-nag</em> style class. |
|
| 27 | - * |
|
| 28 | - * @since 3.2.0 |
|
| 29 | - */ |
|
| 30 | - const UPDATE_NAG = 'update-nag'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * The standard WordPress <em>error</em> style class. |
|
| 34 | - * |
|
| 35 | - * @since 3.2.0 |
|
| 36 | - */ |
|
| 37 | - const ERROR = 'error'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * A custom WordLift css style class used for WordLift suggestions. |
|
| 41 | - * |
|
| 42 | - * @since 3.3.0 |
|
| 43 | - */ |
|
| 44 | - const SUGGESTION = 'wl-suggestion'; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * The array of notices. |
|
| 48 | - * |
|
| 49 | - * @since 3.2.0 |
|
| 50 | - * @access private |
|
| 51 | - * @var array $notices The array of notices. |
|
| 52 | - */ |
|
| 53 | - private $notices = array(); |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * A singleton instance of the Notice service. |
|
| 57 | - * |
|
| 58 | - * @since 3.2.0 |
|
| 59 | - * @access private |
|
| 60 | - * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service. |
|
| 61 | - */ |
|
| 62 | - private static $instance; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Create an instance of the Notice service. |
|
| 66 | - * |
|
| 67 | - * @since 3.2.0 |
|
| 68 | - */ |
|
| 69 | - public function __construct() { |
|
| 70 | - /** |
|
| 71 | - * Filter: wl_feature__enable__notices. |
|
| 72 | - * |
|
| 73 | - * @param bool whether the notices needs to be enabled or not. |
|
| 74 | - * |
|
| 75 | - * @return bool |
|
| 76 | - * @since 3.27.6 |
|
| 77 | - */ |
|
| 78 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
| 79 | - // Hook to be called when to display notices. |
|
| 80 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 81 | - } |
|
| 82 | - self::$instance = $this; |
|
| 83 | - |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Get the singleton instance of the Notice service. |
|
| 88 | - * |
|
| 89 | - * @return \Wordlift_Notice_Service The singleton instance of the Notice service. |
|
| 90 | - * @since 3.2.0 |
|
| 91 | - */ |
|
| 92 | - public static function get_instance() { |
|
| 93 | - |
|
| 94 | - return self::$instance; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Add a notice. |
|
| 99 | - * |
|
| 100 | - * @param string $class The css class. |
|
| 101 | - * @param string $message The message. |
|
| 102 | - * |
|
| 103 | - * @since 3.2.0 |
|
| 104 | - * |
|
| 105 | - */ |
|
| 106 | - public function add( $class, $message ) { |
|
| 107 | - |
|
| 108 | - $this->notices[] = sprintf( self::TEMPLATE, $class, $this->transform( $message ) ); |
|
| 109 | - |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Add an update notice (message with a white background and a green left border). |
|
| 114 | - * |
|
| 115 | - * @param string $message The message to display. |
|
| 116 | - * |
|
| 117 | - * @since 3.2.0 |
|
| 118 | - * |
|
| 119 | - */ |
|
| 120 | - public function add_update( $message ) { |
|
| 121 | - |
|
| 122 | - $this->add( self::UPDATE, $message ); |
|
| 123 | - |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Add an update nag notice (message with a white background and a yellow left border). |
|
| 128 | - * |
|
| 129 | - * @param string $message The message to display. |
|
| 130 | - * |
|
| 131 | - * @since 3.2.0 |
|
| 132 | - * |
|
| 133 | - */ |
|
| 134 | - public function add_update_nag( $message ) { |
|
| 135 | - |
|
| 136 | - $this->add( self::UPDATE_NAG, $message ); |
|
| 137 | - |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Add an error notice (message with a white background and a red left border). |
|
| 142 | - * |
|
| 143 | - * @param string $message The message to display. |
|
| 144 | - * |
|
| 145 | - * @since 3.2.0 |
|
| 146 | - * |
|
| 147 | - */ |
|
| 148 | - public function add_error( $message ) { |
|
| 149 | - |
|
| 150 | - $this->add( self::ERROR, $message ); |
|
| 151 | - |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Add a suggestion notice (message with a white background and a WordLift brand colored left border). |
|
| 156 | - * |
|
| 157 | - * @param string $message The message to display. |
|
| 158 | - * |
|
| 159 | - * @since 3.3.0 |
|
| 160 | - * |
|
| 161 | - */ |
|
| 162 | - public function add_suggestion( $message ) { |
|
| 163 | - |
|
| 164 | - $this->add( self::SUGGESTION, $message ); |
|
| 165 | - |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Print out the notices when the admin_notices action is called. |
|
| 170 | - * |
|
| 171 | - * @since 3.2.0 |
|
| 172 | - */ |
|
| 173 | - public function admin_notices() { |
|
| 174 | - |
|
| 175 | - foreach ( $this->notices as $notice ) { |
|
| 176 | - echo( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Transform message depending on message type. Return a string |
|
| 183 | - * |
|
| 184 | - * @param string $message The message. |
|
| 185 | - * |
|
| 186 | - * @since 3.3.0 |
|
| 187 | - * |
|
| 188 | - */ |
|
| 189 | - private function transform( $message ) { |
|
| 190 | - |
|
| 191 | - switch ( gettype( $message ) ) { |
|
| 192 | - case 'array': |
|
| 193 | - return implode('<br />', $message ); |
|
| 194 | - default: |
|
| 195 | - return $message; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - } |
|
| 10 | + /** |
|
| 11 | + * The template used to display notices. The <em>notice dismissible</em> style classes make this notice dismissible |
|
| 12 | + * on the WordPress UI (via a small X button on the right side of the notice). |
|
| 13 | + * |
|
| 14 | + * @since 3.2.0 |
|
| 15 | + */ |
|
| 16 | + const TEMPLATE = '<div class="wl-notice notice is-dismissible %s"><p>%s</p></div>'; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * The standard WordPress <em>update</em> style class. |
|
| 20 | + * |
|
| 21 | + * @since 3.2.0 |
|
| 22 | + */ |
|
| 23 | + const UPDATE = 'update'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * The standard WordPress <em>update-nag</em> style class. |
|
| 27 | + * |
|
| 28 | + * @since 3.2.0 |
|
| 29 | + */ |
|
| 30 | + const UPDATE_NAG = 'update-nag'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * The standard WordPress <em>error</em> style class. |
|
| 34 | + * |
|
| 35 | + * @since 3.2.0 |
|
| 36 | + */ |
|
| 37 | + const ERROR = 'error'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * A custom WordLift css style class used for WordLift suggestions. |
|
| 41 | + * |
|
| 42 | + * @since 3.3.0 |
|
| 43 | + */ |
|
| 44 | + const SUGGESTION = 'wl-suggestion'; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * The array of notices. |
|
| 48 | + * |
|
| 49 | + * @since 3.2.0 |
|
| 50 | + * @access private |
|
| 51 | + * @var array $notices The array of notices. |
|
| 52 | + */ |
|
| 53 | + private $notices = array(); |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * A singleton instance of the Notice service. |
|
| 57 | + * |
|
| 58 | + * @since 3.2.0 |
|
| 59 | + * @access private |
|
| 60 | + * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service. |
|
| 61 | + */ |
|
| 62 | + private static $instance; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Create an instance of the Notice service. |
|
| 66 | + * |
|
| 67 | + * @since 3.2.0 |
|
| 68 | + */ |
|
| 69 | + public function __construct() { |
|
| 70 | + /** |
|
| 71 | + * Filter: wl_feature__enable__notices. |
|
| 72 | + * |
|
| 73 | + * @param bool whether the notices needs to be enabled or not. |
|
| 74 | + * |
|
| 75 | + * @return bool |
|
| 76 | + * @since 3.27.6 |
|
| 77 | + */ |
|
| 78 | + if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
| 79 | + // Hook to be called when to display notices. |
|
| 80 | + add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 81 | + } |
|
| 82 | + self::$instance = $this; |
|
| 83 | + |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Get the singleton instance of the Notice service. |
|
| 88 | + * |
|
| 89 | + * @return \Wordlift_Notice_Service The singleton instance of the Notice service. |
|
| 90 | + * @since 3.2.0 |
|
| 91 | + */ |
|
| 92 | + public static function get_instance() { |
|
| 93 | + |
|
| 94 | + return self::$instance; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Add a notice. |
|
| 99 | + * |
|
| 100 | + * @param string $class The css class. |
|
| 101 | + * @param string $message The message. |
|
| 102 | + * |
|
| 103 | + * @since 3.2.0 |
|
| 104 | + * |
|
| 105 | + */ |
|
| 106 | + public function add( $class, $message ) { |
|
| 107 | + |
|
| 108 | + $this->notices[] = sprintf( self::TEMPLATE, $class, $this->transform( $message ) ); |
|
| 109 | + |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Add an update notice (message with a white background and a green left border). |
|
| 114 | + * |
|
| 115 | + * @param string $message The message to display. |
|
| 116 | + * |
|
| 117 | + * @since 3.2.0 |
|
| 118 | + * |
|
| 119 | + */ |
|
| 120 | + public function add_update( $message ) { |
|
| 121 | + |
|
| 122 | + $this->add( self::UPDATE, $message ); |
|
| 123 | + |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Add an update nag notice (message with a white background and a yellow left border). |
|
| 128 | + * |
|
| 129 | + * @param string $message The message to display. |
|
| 130 | + * |
|
| 131 | + * @since 3.2.0 |
|
| 132 | + * |
|
| 133 | + */ |
|
| 134 | + public function add_update_nag( $message ) { |
|
| 135 | + |
|
| 136 | + $this->add( self::UPDATE_NAG, $message ); |
|
| 137 | + |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Add an error notice (message with a white background and a red left border). |
|
| 142 | + * |
|
| 143 | + * @param string $message The message to display. |
|
| 144 | + * |
|
| 145 | + * @since 3.2.0 |
|
| 146 | + * |
|
| 147 | + */ |
|
| 148 | + public function add_error( $message ) { |
|
| 149 | + |
|
| 150 | + $this->add( self::ERROR, $message ); |
|
| 151 | + |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Add a suggestion notice (message with a white background and a WordLift brand colored left border). |
|
| 156 | + * |
|
| 157 | + * @param string $message The message to display. |
|
| 158 | + * |
|
| 159 | + * @since 3.3.0 |
|
| 160 | + * |
|
| 161 | + */ |
|
| 162 | + public function add_suggestion( $message ) { |
|
| 163 | + |
|
| 164 | + $this->add( self::SUGGESTION, $message ); |
|
| 165 | + |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Print out the notices when the admin_notices action is called. |
|
| 170 | + * |
|
| 171 | + * @since 3.2.0 |
|
| 172 | + */ |
|
| 173 | + public function admin_notices() { |
|
| 174 | + |
|
| 175 | + foreach ( $this->notices as $notice ) { |
|
| 176 | + echo( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Transform message depending on message type. Return a string |
|
| 183 | + * |
|
| 184 | + * @param string $message The message. |
|
| 185 | + * |
|
| 186 | + * @since 3.3.0 |
|
| 187 | + * |
|
| 188 | + */ |
|
| 189 | + private function transform( $message ) { |
|
| 190 | + |
|
| 191 | + switch ( gettype( $message ) ) { |
|
| 192 | + case 'array': |
|
| 193 | + return implode('<br />', $message ); |
|
| 194 | + default: |
|
| 195 | + return $message; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | 200 | } |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | * @return bool |
| 76 | 76 | * @since 3.27.6 |
| 77 | 77 | */ |
| 78 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
| 78 | + if (apply_filters('wl_feature__enable__notices', true)) { |
|
| 79 | 79 | // Hook to be called when to display notices. |
| 80 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 80 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 81 | 81 | } |
| 82 | 82 | self::$instance = $this; |
| 83 | 83 | |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | * @since 3.2.0 |
| 104 | 104 | * |
| 105 | 105 | */ |
| 106 | - public function add( $class, $message ) { |
|
| 106 | + public function add($class, $message) { |
|
| 107 | 107 | |
| 108 | - $this->notices[] = sprintf( self::TEMPLATE, $class, $this->transform( $message ) ); |
|
| 108 | + $this->notices[] = sprintf(self::TEMPLATE, $class, $this->transform($message)); |
|
| 109 | 109 | |
| 110 | 110 | } |
| 111 | 111 | |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | * @since 3.2.0 |
| 118 | 118 | * |
| 119 | 119 | */ |
| 120 | - public function add_update( $message ) { |
|
| 120 | + public function add_update($message) { |
|
| 121 | 121 | |
| 122 | - $this->add( self::UPDATE, $message ); |
|
| 122 | + $this->add(self::UPDATE, $message); |
|
| 123 | 123 | |
| 124 | 124 | } |
| 125 | 125 | |
@@ -131,9 +131,9 @@ discard block |
||
| 131 | 131 | * @since 3.2.0 |
| 132 | 132 | * |
| 133 | 133 | */ |
| 134 | - public function add_update_nag( $message ) { |
|
| 134 | + public function add_update_nag($message) { |
|
| 135 | 135 | |
| 136 | - $this->add( self::UPDATE_NAG, $message ); |
|
| 136 | + $this->add(self::UPDATE_NAG, $message); |
|
| 137 | 137 | |
| 138 | 138 | } |
| 139 | 139 | |
@@ -145,9 +145,9 @@ discard block |
||
| 145 | 145 | * @since 3.2.0 |
| 146 | 146 | * |
| 147 | 147 | */ |
| 148 | - public function add_error( $message ) { |
|
| 148 | + public function add_error($message) { |
|
| 149 | 149 | |
| 150 | - $this->add( self::ERROR, $message ); |
|
| 150 | + $this->add(self::ERROR, $message); |
|
| 151 | 151 | |
| 152 | 152 | } |
| 153 | 153 | |
@@ -159,9 +159,9 @@ discard block |
||
| 159 | 159 | * @since 3.3.0 |
| 160 | 160 | * |
| 161 | 161 | */ |
| 162 | - public function add_suggestion( $message ) { |
|
| 162 | + public function add_suggestion($message) { |
|
| 163 | 163 | |
| 164 | - $this->add( self::SUGGESTION, $message ); |
|
| 164 | + $this->add(self::SUGGESTION, $message); |
|
| 165 | 165 | |
| 166 | 166 | } |
| 167 | 167 | |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | public function admin_notices() { |
| 174 | 174 | |
| 175 | - foreach ( $this->notices as $notice ) { |
|
| 176 | - echo( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 175 | + foreach ($this->notices as $notice) { |
|
| 176 | + echo($notice); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | } |
@@ -186,11 +186,11 @@ discard block |
||
| 186 | 186 | * @since 3.3.0 |
| 187 | 187 | * |
| 188 | 188 | */ |
| 189 | - private function transform( $message ) { |
|
| 189 | + private function transform($message) { |
|
| 190 | 190 | |
| 191 | - switch ( gettype( $message ) ) { |
|
| 191 | + switch (gettype($message)) { |
|
| 192 | 192 | case 'array': |
| 193 | - return implode('<br />', $message ); |
|
| 193 | + return implode('<br />', $message); |
|
| 194 | 194 | default: |
| 195 | 195 | return $message; |
| 196 | 196 | } |