Changeset 8987
- Timestamp:
- 06/22/2019 10:33:28 AM (6 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-discussions
- Files:
-
- 4 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-discussions/inc/class-plugin.php
r8972 r8987 43 43 44 44 add_action( 'wporg_translate_meta', [ $this, 'show_discussion_meta' ] ); 45 add_action( 'gp_pre_tmpl_load', [ $this, 'pre_tmpl_load' ], 10, 2 ); 46 } 47 48 /** 49 * Enqueue custom styles and scripts. 50 */ 51 public function pre_tmpl_load( $template, $args ) { 52 if ( 'translations' !== $template || ! is_user_logged_in() ) { 53 return; 54 } 55 56 $blog_id = $this->get_blog_id( $args['locale_slug'] ); 57 if ( ! $blog_id ) { 58 return; 59 } 60 61 wp_register_style( 62 'gp-translation-discussions', 63 plugins_url( 'css/translation-discussions.css', PLUGIN_FILE ), 64 [], 65 '20190506' 66 ); 67 gp_enqueue_style( 'gp-translation-discussions' ); 68 69 wp_register_script( 70 'gp-translation-discussions', 71 plugins_url( '/js/translation-discussions.js', PLUGIN_FILE ), 72 [ 'gp-editor' ], 73 '20190510' 74 ); 75 76 wp_localize_script( 'gp-translation-discussions', 'WPORG_TRANSLATION_DISCUSSION', [ 77 'nonce' => wp_create_nonce( 'wp_rest' ), 78 'endpoint' => get_rest_url( $blog_id ), 79 ] ); 80 81 gp_enqueue_script( 'gp-translation-discussions' ); 45 82 } 46 83 … … 52 89 public function show_discussion_meta( $entry ) { 53 90 $set = GP::$translation_set->get( $entry->translation_set_id ); 54 $blog_id = $this->get_blog_id( $set->locale );91 $blog_id = $this->get_blog_id( $set->locale ); 55 92 if ( ! $blog_id ) { 56 93 return; 57 94 } 58 95 59 $rest_url = get_rest_url( $blog_id ); 60 61 62 echo '📝'; 96 97 $reject_reasons = [ 98 'style-guide' => 'Style Guide', 99 'glossary' => 'Glossary', 100 'grammar' => 'Grammar', 101 'punctuation' => 'Punctuation', 102 'branding' => 'Branding', 103 'typos' => 'Typos', 104 ]; 105 106 ?> 107 <div class="feedback-modal feedback-modal__reject-with-feedback wporg-translate-modal"> 108 <div class="wporg-translate-modal__overlay"> 109 <div class="wporg-translate-modal__frame" role="dialog" aria-labelledby="wporg-translation-help-modal-headline"> 110 <div class="wporg-translate-modal__header"> 111 <h1 id="wporg-translation-help-modal-headline" class="wporg-translate-modal__headline">Reject with Feedback</h1> 112 <button type="button" aria-label="Close modal" class="wporg-translate-modal__close"><span class="screen-reader-text">Close</span><span aria-hidden="true" class="dashicons dashicons-no-alt"></span></button> 113 </div> 114 115 <div class="wporg-translate-modal__content"> 116 <form action="POST"> 117 <fieldset> 118 <legend>Reason</legend> 119 120 <ul class="feedback__reasons"> 121 <?php foreach ( $reject_reasons as $reason_code => $reason_text ) : ?> 122 <li class="feedback__reason"> 123 <label > 124 <input type="checkbox" name="reject_reason[]" value="<?php echo esc_attr( $reason_code ); ?>" /> 125 <?php echo esc_html( $reason_text ); ?> 126 </label> 127 </li> 128 <?php endforeach; ?> 129 </ul> 130 </fieldset> 131 132 <label class="feedback"> 133 <?php _e( 'Comment:', 'glotpress' ); ?> 134 <textarea placeholder="Let the contributor know what they did wrong…" name="comment" rows="4"></textarea> 135 </label> 136 137 <p class="feedback__actions"> 138 <button class="button feedback__action-submit" type="submit">Submit</button> 139 </p> 140 </form> 141 </div> 142 </div> 143 </div> 144 </div> 145 146 <div class="meta"> 147 <button type="button" class="button__start-discussion">Start Discussion</button> 148 </div> 149 150 <div class="feedback-modal feedback-modal__start-discussion wporg-translate-modal"> 151 <div class="wporg-translate-modal__overlay"> 152 <div class="wporg-translate-modal__frame" role="dialog" aria-labelledby="wporg-translation-help-modal-headline"> 153 <div class="wporg-translate-modal__header"> 154 <h1 id="wporg-translation-help-modal-headline" class="wporg-translate-modal__headline">Start Discussion</h1> 155 <button type="button" aria-label="Close modal" class="wporg-translate-modal__close"><span class="screen-reader-text">Close</span><span aria-hidden="true" class="dashicons dashicons-no-alt"></span></button> 156 </div> 157 158 <div class="wporg-translate-modal__content"> 159 <form action="POST"> 160 <label class="feedback"> 161 <?php _e( 'Comment:', 'glotpress' ); ?> 162 <textarea required placeholder="Type your question or feedback to this string…" name="comment" rows="4"></textarea> 163 </label> 164 165 <p class="feedback__actions"> 166 <button class="button feedback__action-submit" type="submit">Submit</button> 167 </p> 168 </form> 169 </div> 170 </div> 171 </div> 172 </div> 173 <?php 63 174 } 64 175 … … 70 181 */ 71 182 public function get_blog_id( $locale_slug ) { 183 static $mapping = []; 184 185 if ( isset( $mapping[ $locale_slug ] ) ) { 186 return $mapping[ $locale_slug ]; 187 } 188 72 189 $gp_locale = GP_Locales::by_slug( $locale_slug ); 73 190 if ( ! $gp_locale || ! isset( $gp_locale->wp_locale ) ) { … … 85 202 $site = array_shift( $result ); 86 203 87 return $site ? (int) $site->blog_id : 0; 204 205 $mapping[ $locale_slug ] = $site ? (int) $site->blog_id : 0; 206 207 return $mapping[ $locale_slug ]; 88 208 } 89 209 }
Note: See TracChangeset
for help on using the changeset viewer.