module_url = $this->get_module_url( __FILE__ ); // Register the module with Edit Flow $args = array( 'title' => __( 'Editorial Comments', 'edit-flow' ), 'short_description' => __( 'Share internal notes with your team.', 'edit-flow' ), 'extended_description' => __( 'Use editorial comments to hold a private discussion about a post. Communicate directly with your writers or editors about what works and what needs to be improved for each piece.', 'edit-flow' ), 'module_url' => $this->module_url, 'img_url' => $this->module_url . 'lib/editorial_comments_s128.png', 'slug' => 'editorial-comments', 'default_options' => array( 'enabled' => 'on', 'post_types' => array( 'post' => 'on', 'page' => 'on', ), ), 'configure_page_cb' => 'print_configure_view', 'configure_link_text' => __( 'Choose Post Types', 'edit-flow' ), 'autoload' => false, 'settings_help_tab' => array( 'id' => 'ef-editorial-comments-overview', 'title' => __('Overview', 'edit-flow'), 'content' => __('

Editorial comments help you cut down on email overload and keep the conversation close to where it matters: your content. Threaded commenting in the admin, similar to what you find at the end of a blog post, allows writers and editors to privately leave feedback and discuss what needs to be changed before publication.

Anyone with access to view the story in progress will also have the ability to comment on it. If you have notifications enabled, those following the post will receive an email every time a comment is left.

', 'edit-flow'), ), 'settings_help_sidebar' => __( '

For more information:

Editorial Comments Documentation

Edit Flow Forum

Edit Flow on Github

', 'edit-flow' ), ); $this->module = EditFlow()->register_module( 'editorial_comments', $args ); } /** * Initialize the rest of the stuff in the class if the module is active */ function init() { add_action( 'add_meta_boxes', array ( $this, 'add_post_meta_box' ) ); add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_scripts' ) ); add_action( 'wp_ajax_editflow_ajax_insert_comment', array( $this, 'ajax_insert_comment' ) ); } /** * Upgrade our data in case we need to * * @since 0.7 */ function upgrade( $previous_version ) { global $edit_flow; // Upgrade path to v0.7 if ( version_compare( $previous_version, '0.7' , '<' ) ) { // Technically we've run this code before so we don't want to auto-install new data $edit_flow->update_module_option( $this->module->name, 'loaded_once', true ); } } /** * Load any of the admin scripts we need but only on the pages we need them */ function add_admin_scripts( ) { global $pagenow; $post_type = $this->get_current_post_type(); $supported_post_types = $this->get_post_types_for_module( $this->module ); if ( !in_array( $post_type, $supported_post_types ) ) return; if ( !in_array( $pagenow, array( 'post.php', 'page.php', 'post-new.php', 'page-new.php' ) ) ) return; wp_enqueue_script( 'edit_flow-post_comment', $this->module_url . 'lib/editorial-comments.js', array( 'jquery', 'wp-ajax-response' ), EDIT_FLOW_VERSION, true ); wp_localize_script( 'edit_flow-post_comment', '__ef_localize_post_comment', array( 'and' => esc_html__( 'and', 'edit-flow' ), 'none_notified' => esc_html__( 'No one will be notified.', 'edit-flow' ), ) ); wp_enqueue_style( 'edit-flow-editorial-comments-css', $this->module_url . 'lib/editorial-comments.css', false, EDIT_FLOW_VERSION, 'all' ); $thread_comments = (int) get_option('thread_comments'); ?> get_post_types_for_module( $this->module ); foreach ( $supported_post_types as $post_type ) add_meta_box('edit-flow-editorial-comments', __('Editorial Comments', 'edit-flow'), array($this, 'editorial_comments_meta_box'), $post_type, 'normal' ); } function editorial_comments_meta_box( ) { global $post, $post_ID; ?>
post_status, array( 'new', 'auto-draft' ) ) ) : // Unused since switched to wp_list_comments $editorial_comments = get_comments( array( 'post_id' => $post->ID, 'comment_type' => self::comment_type, 'orderby' => 'comment_date', 'order' => 'ASC', 'status' => self::comment_type ) ); ?> the_comment_form(); ?>

module_enabled( 'notifications' ) || ! apply_filters( 'ef_editorial_comments_show_notified_users', true ) ) { return; } $notification = get_comment_meta( $comment_id, 'notification_list', true ); if ( empty( $notification ) ) { $message = esc_html__( 'No users or groups were notified.', 'edit-flow' ); } else { $message = ''. esc_html__( 'Notified', 'edit-flow' ) . ': ' . esc_html( $notification ); } echo '

' . $message . '

'; } /** * Displays a single comment */ function the_comment($comment, $args, $depth) { global $current_user, $userdata; // Get current user wp_get_current_user() ; $GLOBALS['comment'] = $comment; $actions = array(); $actions_string = ''; // Comments can only be added by users that can edit the post if ( current_user_can('edit_post', $comment->comment_post_ID) ) { $actions['reply'] = '' . __( 'Reply', 'edit-flow' ) . ''; $sep = ' '; $i = 0; foreach ( $actions as $action => $link ) { ++$i; // Reply and quickedit need a hide-if-no-js span if ( 'reply' == $action || 'quickedit' == $action ) $action .= ' hide-if-no-js'; $actions_string .= "$sep$link"; } } ?>
  • comment_ID) ) ); ?>> comment_author_email, 50 ); ?>
    %1$s said on %2$s at %3$s', 'edit-flow'), comment_author_email_link( $comment->comment_author ), get_comment_date( get_option( 'date_format' ) ), get_comment_time() ); ?>
    maybe_output_comment_meta( $comment->comment_ID ); ?>

  • (int) $post_id, 'comment_author' => esc_sql($current_user->display_name), 'comment_author_email' => esc_sql($current_user->user_email), 'comment_author_url' => esc_sql($current_user->user_url), 'comment_content' => wp_kses($comment_content, array('a' => array('href' => array(),'title' => array()),'b' => array(),'i' => array(),'strong' => array(),'em' => array(),'u' => array(),'del' => array(), 'blockquote' => array(), 'sub' => array(), 'sup' => array() )), 'comment_type' => self::comment_type, 'comment_parent' => (int) $parent, 'user_id' => (int) $user_ID, 'comment_author_IP' => esc_sql($_SERVER['REMOTE_ADDR']), 'comment_agent' => esc_sql($_SERVER['HTTP_USER_AGENT']), 'comment_date' => $time, 'comment_date_gmt' => $time, // Set to -1? 'comment_approved' => self::comment_type, ); $data = apply_filters( 'ef_pre_insert_editorial_comment', $data ); // Insert Comment $comment_id = wp_insert_comment($data); $comment = get_comment($comment_id); // Save the list of notified users/usergroups. if ( $this->module_enabled( 'notifications' ) && apply_filters( 'ef_editorial_comments_show_notified_users', true ) ) { $notification = isset( $_POST['notification'] ) ? sanitize_text_field( $_POST['notification'] ) : ''; if ( ! empty( $notification ) && __( 'No one will be notified.', 'edit-flow' ) !== $notification ) { add_comment_meta( $comment_id, 'notification_list', $notification ); } } // Register actions -- will be used to set up notifications and other modules can hook into this if ( $comment_id ) do_action( 'ef_post_insert_editorial_comment', $comment ); // Prepare response $response = new WP_Ajax_Response(); ob_start(); $this->the_comment( $comment, '', '' ); $comment_list_item = ob_get_contents(); ob_end_clean(); $response->add( array( 'what' => 'comment', 'id' => $comment_id, 'data' => $comment_list_item, 'action' => ($parent) ? 'reply' : 'new' )); $response->send(); } else { die( __('There was a problem of some sort. Try again or contact your administrator.', 'edit-flow') ); } } /** * Register settings for editorial comments so we can partially use the Settings API * (We use the Settings API for form generation, but not saving) * * @since 0.7 */ function register_settings() { add_settings_section( $this->module->options_group_name . '_general', false, '__return_false', $this->module->options_group_name ); add_settings_field( 'post_types', __( 'Enable for these post types:', 'edit-flow' ), array( $this, 'settings_post_types_option' ), $this->module->options_group_name, $this->module->options_group_name . '_general' ); } /** * Chose the post types for editorial comments * * @since 0.7 */ function settings_post_types_option() { global $edit_flow; $edit_flow->settings->helper_option_custom_post_type( $this->module ); } /** * Validate our user input as the settings are being saved * * @since 0.7 */ function settings_validate( $new_options ) { // Whitelist validation for the post type options if ( !isset( $new_options['post_types'] ) ) $new_options['post_types'] = array(); $new_options['post_types'] = $this->clean_post_type_options( $new_options['post_types'], $this->module->post_type_support ); return $new_options; } /** * Settings page for editorial comments * * @since 0.7 */ function print_configure_view() { ?>
    module->options_group_name ); ?> module->options_group_name ); ?> module->name ) . '" />'; ?>