*/ function plugmemo_get_all() { $notes = get_site_option( PLUGMEMO_OPTION, array() ); return is_array( $notes ) ? $notes : array(); } /** * Whether the current user may read notes. * * @return bool */ function plugmemo_user_can_view() { return current_user_can( 'activate_plugins' ); } /** * Whether the current user may add, edit and clear notes. * * On Multisite, notes are shared across the network, so only super admins may change them. * * @return bool */ function plugmemo_user_can_edit() { return current_user_can( is_multisite() ? 'manage_network_plugins' : 'activate_plugins' ); } /** * Add a "Note" link to each plugin's action links. * * @param string[] $actions Plugin action links. * @param string $plugin_file Plugin file relative to the plugins directory. * @return string[] */ function plugmemo_action_link( $actions, $plugin_file ) { if ( ! plugmemo_user_can_edit() ) { return $actions; } $notes = plugmemo_get_all(); $label = isset( $notes[ $plugin_file ] ) ? __( 'Edit note', 'plugmemo' ) : __( 'Add note', 'plugmemo' ); $actions['plugmemo'] = sprintf( '%s', esc_attr( $plugin_file ), esc_html( $label ) ); return $actions; } add_filter( 'plugin_action_links', 'plugmemo_action_link', 20, 2 ); add_filter( 'network_admin_plugin_action_links', 'plugmemo_action_link', 20, 2 ); /** * Print the note row (and its hidden editor) below each plugin. * * @param string $plugin_file Plugin file relative to the plugins directory. */ function plugmemo_row( $plugin_file ) { if ( ! plugmemo_user_can_view() ) { return; } $notes = plugmemo_get_all(); $note = isset( $notes[ $plugin_file ] ) ? $notes[ $plugin_file ] : ''; $can_edit = plugmemo_user_can_edit(); if ( '' === $note && ! $can_edit ) { return; } $wp_list_table = _get_list_table( 'WP_Plugins_List_Table', array( 'screen' => get_current_screen() ) ); $is_active = is_network_admin() ? is_plugin_active_for_network( $plugin_file ) : is_plugin_active( $plugin_file ); $editor_id = 'plugmemo-' . md5( $plugin_file ); ?>