Forum Replies Created

Viewing 15 replies - 61 through 75 (of 96 total)
  • Hello omidparkour,

    I had a closer look on this and I created a little snippet to store the user “avatar” into the upload dir, save it as user meta ( you should change the key of the meta ) and also show it on user profile.

    First of all, you had not able to store the file into the upload dir because the profile form is not multipart, so I added an additional hook

    function my_profile_multipart() {
        echo 'enctype="multipart/form-data"';
    }
    add_action('user_edit_form_tag', 'my_profile_multipart' );

    With that we can use the global var $_FILES to move the file into the upload dir.

    For the path for the file I used uploads/users-avatar/{user_login} and for the file name the name of the original file. I think you should consider to use always the same name to prevent user to upload multiple files.

    Here the code https://codepad.co/snippet/xjVvxCJ4 tested in a unix local server and WordPress version 4.5.2

    Let me know if you encounter some issue.

    Alternatively there are a bounce of plugins that add this feature.

    Hello,

    To upload a file programmatically into the upload dir you should use wp_handle_upload

    Forum: Fixing WordPress
    In reply to: Duplicated images

    Hi,

    Yes it is correct, if the image has no class wp-image-{ID} the image will not be removed because there is no way to compare it with the featured image.

    I have not compared the src attribute value of the images ’cause it is possible to use different image sizes within the post editor.

    I think a more accurate regexp should resolve this issue but I have no clue right now.

    Forum: Fixing WordPress
    In reply to: Duplicated images

    Uhm, you’re right.

    I made some changes and I think the only way to remove the duplicated image is to perform a check with the ID of the featured image and the image within the content.

    Have a look at this new one.
    The function get the post thumbnail ID and compare it with the ID get from the wp-image- class value. Generally WordPress add that class with the ID of the image.

    If the post has not a featured image or the ID of the first image found is not the same of the post thumbnail ID nothing will be performed.

    If this code work correctly, we can try to remove the image directly within this function.

    Sorry for the issue, I thought that you had all posts with the duplicated image.

    Let me know.

     
    function xx_remove_first_image( $content ) {
    
    	if ( ! is_singular( 'post' ) || ! is_main_query() ) {
    		return $content;
    	}
    
    	// Get the featured image.
    	$_fthumb = absint( get_post_thumbnail_id() );
    
    	// Do nothing if the post hasn't a featured image.
    	if ( ! $_fthumb ) {
    		return $content;
    	}
    
    	// Try to retrieve the ID of the attachment.
    	if ( preg_match( '/<img class=\".*wp\-image\-([\d]{1,}).*\" [^>]*>/', $content, $matches ) && ! empty( $matches[1] ) ) {
    		$_id = absint( $matches[1] );
    
    		// And compare it with the featured image thumbnail.
    		if ( $_id === $_fthumb ) {
    			preg_match( '/(<img [^>]*>)/', $content, $matches );
    
    			if ( ! empty( $matches[1] ) ) {
    				$content = str_replace( $matches[1], '', $content );
    			}
    		}
    	}
    
    	return $content;
    
    }
    add_filter( 'the_content', 'xx_remove_first_image' );

    Below the entire code. Tested and no parse errore is showing.
    May be you missed a semi-colon at the end of the echo?

    add_action( 'woocommerce_before_single_product_summary', function () {
    
    	global $product;
    	if ( ! $product->is_in_stock() ) {
    		echo '<span class="soldout">' . esc_html__( 'Sold Out', 'textdomain' ) . '</span>';
    	}
    } );
    Forum: Fixing WordPress
    In reply to: Duplicated images

    Of course, try the code below. Consider in this case the image will be removed only in single post post-type.

    function xx_remove_first_image( $content ) {
    
    	if ( is_singular( 'post' ) && preg_match( '/(<img [^>]*>)/', $content, $matches ) ) {
    		$content = str_replace( $matches[1], '', $content );
    	}
    
    	return $content;
    }
    add_filter( 'the_content', 'xx_remove_first_image', 20 );

    Regarding the way to remove them from the post during update or insert you should consider that every first image will be removed even if it is not a duplicated of the featured image.

    Try to set the WP_DEBUG constant to true.

    Then if possible paste the output ( better by pastebin or other service ).

    We can try to detect the issue.

    Forum: Fixing WordPress
    In reply to: Duplicated images

    Hello,

    Try this snippet in functions.php at the end of the file.

    function xx_remove_first_image( $content ) {
    
    	if ( preg_match( '/(<img [^>]*>)/', $content, $matches ) ) {
    		$content = str_replace( $matches[1], '', $content );
    	}
    
    	return $content;
    }
    add_filter( 'the_content', 'xx_remove_first_image', 20 );

    That should remove the first image within the post content. But will not remove it from the content itself, simply the image will not be shown up.

    If you want to remove completely the image from the post content, you need to hook into the wp_insert_post_data filter. In this case make a database backup first.

    Hello,

    You can translate the Sold out text by using one of the functions that WordPress provide for translations. For example the esc_html__() function.

    So, your code should be

    echo '<span class="soldout">' . esc_html__( 'Sold Out', 'textdomain' ) . '</span>';

    Regarding the text domain depend by your theme or plugin. In your case may be ‘woocommerce’.

    Thread Starter Guido Scialfa

    (@wido)

    Sorry my bad, I had not set any relationship on my base site.

    Thread Starter Guido Scialfa

    (@wido)

    Hi Evan,

    Thank you too for your respond. Appreciated it.

    Thread Starter Guido Scialfa

    (@wido)

    Hi @diana,

    Thanks for your respond.

    I can fix by my self as you suggested, but the problem will be fixed in the next release of the plugin? I don’t want to perform the same task every time the plugin get an update.

    Thread Starter Guido Scialfa

    (@wido)

    Tried on a single page the sample form. Dragging the map become gray and nothing appear anymore.

    See these on console.

    `
    2js?v=3.exp&sensor=false&libraries=places&ver=4.5-alpha-35839:29 Uncaught RangeError: Maximum call stack size exceeded
    js?v=3.exp&sensor=false&libraries=places&ver=4.5-alpha-35839:44 Uncaught RangeError: Maximum call stack size exceeded
    js?v=3.exp&sensor=false&libraries=places&ver=4.5-alpha-35839:85 Uncaught RangeError: Maximum call stack size exceeded
    (index):248 #document
    5js?v=3.exp&sensor=false&libraries=places&ver=4.5-alpha-35839:29 Uncaught RangeError: Maximum call stack size exceeded
    js?v=3.exp&sensor=false&libraries=places&ver=4.5-alpha-35839:85 Uncaught RangeError: Maximum call stack size exceeded
    2js?v=3.exp&sensor=false&libraries=places&ver=4.5-alpha-35839:29 Uncaught RangeError: Maximum call stack size exceeded
    util.js:30 Google Maps API warning: SensorNotRequired: https://developers.google.com/maps/documentation/javascript/error-messages
    js?v=3.exp&sensor=false&libraries=places&ver=4.5-alpha-35839:85 Uncaught RangeError: Maximum call stack size exceeded
    js?v=3.exp&sensor=false&libraries=places&ver=4.5-alpha-35839:29 Uncaught RangeError: Maximum call stack size exceeded
    js?v=3.exp&sensor=false&libraries=places&ver=4.5-alpha-35839:85 Uncaught RangeError: Maximum call stack size exceeded
    5js?v=3.exp&sensor=false&libraries=places&ver=4.5-alpha-35839:29 Uncaught RangeError: Maximum call stack size exceeded
    js?v=3.exp&sensor=false&libraries=places&ver=4.5-alpha-35839:85 Uncaught RangeError: Maximum call stack size exceeded
    (index):205 389
    js?v=3.exp&sensor=false&libraries=places&ver=4.5-alpha-35839:29 Uncaught RangeError: Maximum call stack size exceeded
    js?v=3.exp&sensor=false&libraries=places&ver=4.5-alpha-35839:85 Uncaught RangeError: Maximum call stack size exceeded
    `

    Thread Starter Guido Scialfa

    (@wido)

    Hi,

    Thank you for your respond. I tried with wp 3.4.1 and 2015 theme.
    I notice that, after clicking on save button, nothing happen but refreshing the page the option was saved correctly.

    Seems it is only a feedback issue. Sorry, my bad.

    Hello,

    Had the same issue on a network installation. Do you running a net?

Viewing 15 replies - 61 through 75 (of 96 total)