/** * Outputs the content of the widget. * * @since 0.1.0 * @param array args The array of form elements * @param array instance The current instance of the widget */ public function widget( $args, $instance ) { /** * * @since 0.1.0 * @var int $hide_if_empty Flag to determine if widget should still be displayed when there are no published posts. */ $hide_if_empty; /** * * @since 0.1.0 * @var array $wp_notes_data A multidimensional associative array containing all the data for the notes (title, text, date). */ $wp_notes_data = array(); include( plugin_dir_path( dirname( __FILE__ ) ) . 'includes/wp-notes-post-data.php' ); include( plugin_dir_path( dirname( __FILE__ ) ) . 'includes/wp-notes-widget-data.php' ); $widget_data = getNotesWidgetData($instance); extract( $widget_data, EXTR_SKIP ); $note_query_args = array ( 'post_type' => 'nw-item', 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'menu_order date' ); /** * Since we need to run WP_Query to determine the number of active notes, we iterate through the results and store the * values in $wp_notes_data to be used later. This prevents the need to run WP_Query again later. */ $note_query = new WP_Query( $note_query_args ); global $post; $count = 0; if ( $note_query->have_posts() ) { while ( $note_query->have_posts() ) : $note_query->the_post(); $wp_notes_data[$count]['data'] = getNotePostData( $post->ID); $wp_notes_data[$count]['title'] = get_the_title(); $wp_notes_data[$count]['date'] = get_the_date(); $count++; endwhile; } else if ($hide_if_empty) { return; } // Check if there is a cached output $cache = wp_cache_get( $this->get_widget_slug(), 'widget' ); if ( !is_array( $cache ) ) $cache = array(); if ( ! isset ( $args['widget_id'] ) ) $args['widget_id'] = $this->id; if ( isset ( $cache[ $args['widget_id'] ] ) ) return print $cache[ $args['widget_id'] ]; extract( $args, EXTR_SKIP ); $widget_string = ''; if ((bool)$multiple_notes) { ob_start(); if ( $note_query->have_posts() ) { $note_count = 0; foreach($wp_notes_data as $wp_note_data ) { echo ((bool)$wrap_widget) ? $before_widget : ''; include( plugin_dir_path( dirname( __FILE__ ) ) . 'public/public-widget-single-view.php' ); echo ((bool)$wrap_widget) ? $after_widget : ''; $note_count++; } } else { echo ((bool)$wrap_widget) ? $before_widget : ''; include( plugin_dir_path( dirname( __FILE__ ) ) . 'public/public-widget-empty-view.php' ); echo ((bool)$wrap_widget) ? $after_widget : ''; } $widget_string .= ob_get_clean(); $cache[ $args['widget_id'] ] = $widget_string; wp_cache_set( $this->get_widget_slug(), $cache, 'widget' ); } else { $widget_string = ((bool)$wrap_widget) ? $before_widget : ''; ob_start(); include( plugin_dir_path( dirname( __FILE__ ) ) . 'public/public-widget-view.php' ); $widget_string .= ob_get_clean(); $widget_string .= ((bool)$wrap_widget) ? $after_widget : ''; $cache[ $args['widget_id'] ] = $widget_string; wp_cache_set( $this->get_widget_slug(), $cache, 'widget' ); } print $widget_string; } // end widget
/** * Renders the nonce, textarea, and text inputs for the note. * * @since 0.1.0 * @param $post current post object */ function WP_Notes_meta_display( $post ) { include( plugin_dir_path( dirname( __FILE__ ) ) . 'includes/wp-notes-post-data.php' ); $wp_notes_data = getNotePostData( $post->ID); function WP_Notes_get_hidden_class_output($action_link_type, $link_type ) { switch ($link_type) { case 'plain': if ( $action_link_type == 'download') { echo 'wp-notes-hidden'; } break; case 'download': if ( (!(bool)$action_link_type) || $action_link_type == 'plain') { echo 'wp-notes-hidden'; } break; } } function WP_Notes_get_selected_output($action_link_type, $link_type ) { switch ($link_type) { case 'plain': if ( (!(bool)$action_link_type) || $action_link_type == 'plain') { echo 'checked'; } break; case 'download': if ( $action_link_type == 'download') { echo 'checked'; } break; } } wp_nonce_field( plugin_basename( __FILE__ ), 'WP_Notes_nonce' ); ob_start(); include( plugin_dir_path( dirname( __FILE__ ) ) . 'admin/admin-post-view.php' ); $html = ob_get_clean(); echo $html; } // end WP_Notes_meta_display