register(); } /** * Register init function */ function register() { add_action( 'admin_init', array( &$this, 'init' ), 30 ); add_action( 'wp_ajax_author-avatars-editor-popup', array( &$this, 'render_tinymce_popup' ) ); } /** * Register button filters and actions */ function init() { global $pagenow; // we need to test that we are in the admin section bewfore we add the button to tinyMCE if ( $pagenow != 'index.php' ) { // Don't bother adding the button if the current user lacks permissions $user_level_for_editor = apply_filters( 'aa_user_level_for_editor', 'edit_posts' ); if ( current_user_can( $user_level_for_editor ) || current_user_can( $user_level_for_editor ) ) { // Add only in Rich Editor mode if ( get_user_option( 'rich_editing' ) == 'true' ) { add_filter( 'mce_external_plugins', array( &$this, 'add_tinymce_plugin' ) ); add_filter( 'mce_buttons', array( &$this, 'add_tinymce_button' ) ); } // In wordpress < 2.7 only the POST parameter "action" is used in admin-ajax.php // but we're using the GET parameter for the tinymce popup iframe, therefore manually // set the POST parameter for the popup calls. if ( defined( 'DOING_AJAX' ) && DOING_AJAX == true ) { $p = 'author-avatars-editor-popup'; $action = isset( $_GET['action'] ) ? $_GET['action'] : null; if ( $action == $p && ! isset( $_POST['action'] ) ) { $_POST['action'] = $action; } } } } } /** * Filter 'mce_external_plugins': add the authoravatars tinymce plugin * * @param $plugin_array * * @return mixed * */ function add_tinymce_plugin( $plugin_array ) { $plugin_array['authoravatars'] = plugins_url( '../tinymce/editor_plugin.js', __FILE__ ); return $plugin_array; } /** * Filter 'mce_buttons': add the authoravatars tinymce button * * @param $buttons * * @return mixed */ function add_tinymce_button( $buttons ) { array_push( $buttons, 'separator', 'authoravatars' ); return $buttons; } /** * Renders the tinymce editor popup */ function render_tinymce_popup() { echo '' . "\n"; $this->render_tinymce_popup_head(); echo "\n"; $this->render_tinymce_popup_body(); echo "\n"; echo ''; exit(); } /** * Builds the html head for the tinymce popup * * @access private */ function render_tinymce_popup_head() { echo '
'; echo "\n\t" . '