Changeset 323
- Timestamp:
- 01/29/2014 05:37:09 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/trac-notifications/trac-components.php
r322 r323 6 6 add_action( 'admin_menu', array( $this, 'admin_menu' ) ); 7 7 add_action( 'the_content', array( $this, 'the_content' ), 5 ); 8 add_action( 'save_post ', array( $this, 'save_post' ), 10, 2 );8 add_action( 'save_post_component', array( $this, 'save_post' ), 10, 2 ); 9 9 $this->trac = $GLOBALS['wpdb']; 10 10 } … … 52 52 } 53 53 54 function page_is_component( $post ) { 55 $post = get_post( $post ); 56 if ( $post->post_type != 'component' ) { 57 return false; 58 } 59 if ( $post->post_parent == 0 ) { 60 return true; 61 } 62 if ( get_post_meta( $post->ID, '_page_is_subcomponent', true ) ) { 63 return true; 64 } 65 return false; 66 } 67 54 68 function register_meta_box_cb( $post ) { 55 if ( $post->post_ parent == 0 && $post->post_status !== 'auto-draft' ) {69 if ( $post->post_status !== 'auto-draft' ) { 56 70 add_meta_box( 'component-settings', 'Settings', array( $this, 'meta_box_cb' ) ); 57 71 } … … 59 73 60 74 function meta_box_cb( $post ) { 75 wp_nonce_field( 'component-settings_' . $post->ID, 'component-settings-nonce', false ); 76 if ( $post->post_parent != 0 ) { 77 $checked = checked( (bool) get_post_meta( $post->ID, '_page_is_subcomponent', true ), true, false ); 78 echo '<p><label for="page-is-subcomponent"><input type="checkbox"' . $checked . ' name="page-is-subcomponent" id="page-is-subcomponent" /> This page is a subcomponent</label></p>'; 79 } 80 if ( ! $this->page_is_component( $post ) ) { 81 return; 82 } 61 83 $value = get_post_meta( $post->ID, '_active_maintainers', true ); 62 84 echo '<p><label for="active-maintainers">Active maintainers (WP.org usernames, comma-separated)</label> <input type="text" class="large-text" id="active-maintainers" name="active-maintainers" value="' . esc_attr( $value ) . '" />'; … … 64 86 65 87 function save_post( $post_id, $post ) { 66 if ( $post->post_type !== 'component' || $post->post_parent != 0) {88 if ( ! isset( $_POST['component-settings-nonce'] ) ) { 67 89 return; 68 90 } 69 if ( ! isset( $_POST['active-maintainers'] ) ) { 91 92 if ( ! wp_verify_nonce( $_POST['component-settings-nonce'], 'component-settings_' . $post->ID ) ) { 70 93 return; 71 94 } 72 update_post_meta( $post->ID, '_active_maintainers', sanitize_text_field( wp_unslash( $_POST['active-maintainers'] ) ) ); 95 96 if ( $post->post_parent != 0 ) { 97 update_post_meta( $post->ID, '_page_is_subcomponent', isset( $_POST['page-is-subcomponent'] ) ); 98 } 99 100 if ( isset( $_POST['active-maintainers'] ) ) { 101 update_post_meta( $post->ID, '_active_maintainers', sanitize_text_field( wp_unslash( $_POST['active-maintainers'] ) ) ); 102 } 73 103 } 74 104 … … 79 109 function the_content( $content ) { 80 110 $post = get_post(); 81 if ( $post->post_type !== 'component' || $post->post_parent != 0) {111 if ( ! $this->page_is_component( $post ) ) { 82 112 return $content; 83 } 84 113 } 114 115 if ( $post->post_parent ) { 116 $top_level = '<h4>This is a subcomponent of the <a href="' . get_permalink( $post->post_parent ) . '">' . get_post( $post->post_parent )->post_title . '</a> component.</h4>'; 117 $content = $top_level . "\n\n" . $content; 118 } 85 119 ob_start(); 86 120 ?> … … 123 157 } 124 158 125 $sub_pages = wp_list_pages( array( 'child_of' => $post->ID, 'post_type' => 'component', 'echo' => false, 'title_li' => false ) ); 159 $subcomponents_query = new WP_Query( array( 160 'post_type' => 'component', 161 'post_status' => 'publish', 162 'post_parent' => $post->ID, 163 'update_post_term_cache' => false, 164 'update_post_meta_cache' => false, 165 'meta_key' => '_page_is_subcomponent', 166 'meta_value' => '1', 167 ) ); 168 169 if ( $subcomponents_query->have_posts() ) { 170 echo '<h4>Subcomponents: '; 171 $subcomponents = array(); 172 foreach ( $subcomponents_query->posts as $subcomponent ) { 173 $subcomponents[ $subcomponent->ID ] = '<a href="' . get_permalink( $subcomponent ) . '">' . $subcomponent->post_title . '</a>'; 174 } 175 echo implode( ', ', $subcomponents ) . '</h4>'; 176 } 177 178 179 $sub_pages = wp_list_pages( array( 'child_of' => $post->ID, 'post_type' => 'component', 'echo' => false, 'title_li' => false, 'exclude' => implode( ',', array_keys( $subcomponents ) ) ) ); 126 180 if ( $sub_pages ) { 127 181 echo "<h3>Pages under " . get_the_title() . "</h3>\n";
Note: See TracChangeset
for help on using the changeset viewer.