Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 12 replies - 1 through 12 (of 12 total)

  • phucitol
    Participant

    @phucitol

    I should have mentioned

    wordpress 4.9.4
    buddypress 2.9.4


    phucitol
    Participant

    @phucitol

    Final analysis. It turns out that the previous developer’s method for loading certain plugin related pages/posts was done very much NOT “the wordpress way”. This caused bad oembed URLs to be created, so when the oembed data was returned it was corrupted. I was able to resolve all the issues.

    This thread can be closed.


    phucitol
    Participant

    @phucitol

    Update: The meta_value saved in wp_bp_messages_meta for meta_key _oembed-***** has the wrong URL saved in there so the problem is occurring before the data is saved. The fact that this same problem happened on my site as well as in this forum is interesting and leads me to believe the problem is somewhere in wordpress or buddypress core files.


    phucitol
    Participant

    @phucitol

    Well that is interesting. It made the same change to URL when I posted it in the code block of my previous comment. The path was supposed to be
    /fossils/28220/

    I think this bug may be related to autolinking and possibly to the link preview feature.


    phucitol
    Participant

    @phucitol

    @meebovn Just saw your post. Here is the code I was using. I just load it from it’s own JS file in my functions.php. IIRC most of it is copy-pasta from a buddypress file with w/e tweaking I needed to get it working. It’s not pretty though.

    
    jQuery(document).ready(function($) {
    	
    	/* necessary to get the custom post-form working */
      	//Deregister buddypress built in actions
      	$('#whats-new').off("focus");
      	$('#whats-new-form').off("focusout");
      	$('#whats-new-options').show();
      	$('#aw-whats-new-submit').off('click');
    
      	/* New posts */
    	$('#aw-whats-new-submit').on( 'click', function() {
    		var editor = tinymce.get('whats-new');
    		editor.save();
    
    		var last_date_recorded = 0,
    			button = $(this),
    			form   = button.closest('form#whats-new-form'),
    			inputs = {}, post_data;
    
    		// Get all inputs and organize them into an object {name: value}
    		$.each( form.serializeArray(), function( key, input ) {
    			// Only include public extra data
    			if ( '_' !== input.name.substr( 0, 1 ) && 'whats-new' !== input.name.substr( 0, 9 ) ) {
    				if ( ! inputs[ input.name ] ) {
    					inputs[ input.name ] = input.value;
    				} else {
    					// Checkboxes/dropdown list can have multiple selected value
    					if ( ! $.isArray( inputs[ input.name ] ) ) {
    						inputs[ input.name ] = new Array( inputs[ input.name ], input.value );
    					} else {
    						inputs[ input.name ].push( input.value );
    					}
    				}
    			}
    		} );
    
    		form.find( '*' ).each( function() {
    			if ( $.nodeName( this, 'textarea' ) || $.nodeName( this, 'input' ) ) {
    				$(this).prop( 'disabled', true );
    			}
    		} );
    
    		/* Remove any errors */
    		$('div.error').remove();
    		button.addClass('loading');
    		button.prop('disabled', true);
    		form.addClass('submitted');
    
    		/* Default POST values */
    		object = '';
    		item_id = $('#whats-new-post-in').val();
    		content = $('#whats-new').val();
    		firstrow = $( '#buddypress ul.activity-list li' ).first();
    		activity_row = firstrow;
    		timestamp = null;
    
    		// Checks if at least one activity exists
    		if ( firstrow.length ) {
    
    			if ( activity_row.hasClass( 'load-newest' ) ) {
    				activity_row = firstrow.next();
    			}
    
    			timestamp = activity_row.prop( 'class' ).match( /date-recorded-([0-9]+)/ );
    		}
    
    		if ( timestamp ) {
    			last_date_recorded = timestamp[1];
    		}
    
    		/* Set object for non-profile posts */
    		if ( item_id > 0 ) {
    			object = $('#whats-new-post-object').val();
    		}
    
    		post_data = $.extend( {
    			action: 'post_update',
    			'cookie': bp_get_cookies(),
    			'_wpnonce_post_update': $('#_wpnonce_post_update').val(),
    			'content': content,
    			'object': object,
    			'item_id': item_id,
    			'since': last_date_recorded,
    			'_bp_as_nonce': $('#_bp_as_nonce').val() || ''
    		}, inputs );
    
    		$.post( ajaxurl, post_data, function( response ) {
    			form.find( '*' ).each( function() {
    				if ( $.nodeName( this, 'textarea' ) || $.nodeName( this, 'input' ) ) {
    					$(this).prop( 'disabled', false );
    				}
    			});
    
    			/* Check for errors and append if found. */
    			if ( response[0] + response[1] === '-1' ) {
    				form.prepend( response.substr( 2, response.length ) );
    				$( '#' + form.attr('id') + ' div.error').hide().fadeIn( 200 );
    			} else {
    				if ( 0 === $('ul.activity-list').length ) {
    					$('div.error').slideUp(100).remove();
    					$('#message').slideUp(100).remove();
    					$('div.activity').append( '<ul id="activity-stream" class="activity-list item-list">' );
    				}
    
    				if ( firstrow.hasClass( 'load-newest' ) ) {
    					firstrow.remove();
    				}
    
    				$('#activity-stream').prepend(response);
    
    				if ( ! last_date_recorded ) {
    					$('#activity-stream li:first').addClass('new-update just-posted');
    				}
    
    				if ( 0 !== $('#latest-update').length ) {
    					var l   = $('#activity-stream li.new-update .activity-content .activity-inner p').html(),
    						v     = $('#activity-stream li.new-update .activity-content .activity-header p a.view').attr('href'),
    						ltext = $('#activity-stream li.new-update .activity-content .activity-inner p').text(),
    						u     = '';
    
    					if ( ltext !== '' ) {
    						u = l + ' ';
    					}
    
    					u += '<a href="' + v + '" rel="nofollow">' + BP_DTheme.view + '</a>';
    
    					$('#latest-update').slideUp(300,function(){
    						$('#latest-update').html( u );
    						$('#latest-update').slideDown(300);
    					});
    				}
    
    				$('li.new-update').hide().slideDown( 300 );
    				$('li.new-update').removeClass( 'new-update' );
    				$('#whats-new').val('');
    				form.get(0).reset();
    
    				// reset vars to get newest activities
    				newest_activities = '';
    				activity_last_recorded  = 0;
    			}
    
    			//$('#whats-new-options').slideUp();
    			$('#whats-new-form textarea').animate({
    				height:'2.2em'
    			});
    			$('#aw-whats-new-submit').removeClass('loading');
    			$( '#whats-new-content' ).removeClass( 'active' );
    		});
    
    		return false;
    	});
    })

    phucitol
    Participant

    @phucitol

    @tizianopitisci

    did you find a solution to this, or do you have a link to the buddypress trac where it was reported?


    phucitol
    Participant

    @phucitol

    @r-a-y

    Thanks for the code. I had gotten this working by adding this really gross javascript:

    	window.onload = function() { 
    	      my_timing = setInterval(function(){myTimer();},1000);
    	      function myTimer() {
    	        if (typeof window.tinyMCE !== 'undefined' && window.tinyMCE.activeEditor !== null && typeof window.tinyMCE.activeEditor !== 'undefined') {  
    		        $( window.tinyMCE.activeEditor.contentDocument.activeElement )
    					.atwho( 'setIframe', $( '.wp-editor-wrap iframe' )[0] )
    					.bp_mentions( bp.mentions.users );
    				 window.clearInterval(my_timing);
    		    }
    	      }
    	      myTimer();
    	};

    ONE question. Shouldn’t this line of code:
    add_filter( 'tiny_mce_before_init', 'cac_enable_mentions_in_group_forum_tinymce', 10, 2 );

    be

    add_filter( 'tiny_mce_before_init', 'my_enable_mentions_in_group_forum_tinymce', 10, 2 );
    ?


    phucitol
    Participant

    @phucitol

    Thanks for the response, I had already used bp-custom.php to build a custom post-form before. I’ll read that thread on child theme js. Thank you for confirming for me that there was no reason for the last dev to alter those core js files.


    phucitol
    Participant

    @phucitol

    I’m trying to get @ mentions to work as well and I’ve very nearly done it.
    I created a custom post-form.php that calls do_action on this function in my bp-custom.php file:

    function bpfr_whats_new_tiny_editor() {
    	// building the what's new textarea
    	if ( isset( $_GET['r'] ) ) :
    	$content = esc_textarea( $_GET['r'] ); 
    	endif;
    
    	// adding tinymce tools
    	$editor_id = 'whats-new';
    		$settings = array(
                     'textarea_name' => 'whats-new',
                    );	
    	
    	// get the editor	
    	wp_editor( $content, $editor_id, $settings );
    }
    add_action( 'whats_new_textarea', 'bpfr_whats_new_tiny_editor' );

    But it wasn’t working, so I looked in mentions.js and found

    bp.mentions.tinyMCEinit = function() {
    		if ( typeof window.tinyMCE === 'undefined' || window.tinyMCE.activeEditor === null || typeof window.tinyMCE.activeEditor === 'undefined' ) {
    			return;
    		} else {
    			$( window.tinyMCE.activeEditor.contentDocument.activeElement )
    				.atwho( 'setIframe', $( '.wp-editor-wrap iframe' )[0] )
    				.bp_mentions( bp.mentions.users );
    		}
    	};

    I added some jQuery alerts to my document ready code to check typeof window.tinyMCE === 'undefined' || window.tinyMCE.activeEditor === null || typeof window.tinyMCE.activeEditor === 'undefined' and it seems like this code is running before tinyMCE is fully loaded because window.tinyMCE.activeEditor === null comes back as true. To double check I made a button on my page that, when clicked, calls:

    $( window.tinyMCE.activeEditor.contentDocument.activeElement )
    .atwho( 'setIframe', $( '.wp-editor-wrap iframe' )[0] )
    .bp_mentions( bp.mentions.users );

    and after that the mentions work in tinyMCE. Can anyone point me in the right direction on this? Is there a way that I can make my own javascript file and enqueue it after tinyMCE is loaded so I can get this working?


    phucitol
    Participant

    @phucitol

    Thanks again for your prompt and detailed answer.

    In the end I had to remove some event handlers

    $('#whats-new').off("focus");
     $('#whats-new-form').off("focusout");
     $('#whats-new-options').show();
     $('#aw-whats-new-submit').off('click');

    then I modified my own version of the $('#aw-whats-new-submit').on('click'); handler and no changes to the css were required (other than removing what the event handlers were changing).

    I’m still having some issues with some styling tags added by the visual editor being stripped on submission, but that seems off topic for this thread.


    phucitol
    Participant

    @phucitol

    Thanks so much for your quick responses. I’m not explaining myself well I guess.

    I want my users to only see and use the visual editor. I know that the button to submit is on the page. I know it is being hidden by javascript on page load. I know that it normally becomes visible when clicking in the textarea. The text area in the visual editor, located in an iframe, doesn’t register the events that make the submit button visible.

    Do you know if it is possible to get the buddypress javascript that handles the buttons visibility to work with the text area in the iframe?

    Alternatively, would it be possible for me to write custom buttons and add them to the default BP textarea?


    phucitol
    Participant

    @phucitol

    Thanks so much for your response. I reread that post (which is what I based my code on) and I do realize I made some changes. For example removing:

    // deactivation of the visual tab, so user can't play with template styles
    add_filter ( 'user_can_richedit' , create_function ( '$a' , 'return false;' ) , 50 );

    and using:

    'tinymce'=> array(
                     'toolbar1'=> 'bold,italic,underline,strikethrough,forecolor',
                     'toolbar2' => 'bullist,numlist,link,unlink,undo,redo'
                           )

    instead of

    'quicktags' => array(
    		'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close')

    Without those changes I can’t get the rich text editor that I require. Did you mean by “It’s explained here” that making the visual editor work in this context is not possible?

Viewing 12 replies - 1 through 12 (of 12 total)
Skip to toolbar