Support Forum » User Profile

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 24 total)
  • Author
    Posts
  • sherwin_flightsherwin_flight
    Participant

    The last time I just changed the way I was doing things. But I'm trying to do something else, and this error still seems to exist. I'm now using version 5.9.3.

    I can upload multiple files as a clone group, but I get that invalid file error when trying f to delete some files.

    in reply to: Select / Select advanced read-only/disabled #38257
    sherwin_flightsherwin_flight
    Participant

    You can use some JavaScript to remove the disabled attribute when you save, and then the values will be saved as expected.

    But I think a read only/locked option would be great. I'm struggling with a similar issue right now as well, only with clone groups that i want to be read only.

    sherwin_flightsherwin_flight
    Participant

    I have version 5.6.1 now, but I still seem to be having this problem.

    I have a clone group set up, and there's an image file in it. I can clone the field and upload the images, that seems to all work as expected. But if I try to delete the files using the ajax delete option I can only delete one of the files. For the others I get the Invalid File! error.

    The code that calls the error pop-up is:

    		if ( ( 'child' !== $type && ! in_array( $attachment, $field_value ) ) ||
    			 ( 'child' === $type && ! in_array( $attachment,  self::get_sub_values( $field_value, $request->filter_post( 'field_id' ) ) ) ) ) {
    			wp_send_json_error( __( 'Error: Invalid file', 'meta-box' ) );
    		}

    When I debug it a little it seems the array returned by the "self::get_sub_values" function returns a single entry, despite having added two clone groups with images. So I am able to delete the image that matches the one returned by this function, but for the others I get an error.

    So the error is related to how the "self::get_sub_values" is building the array of values. it's not including all of my uploaded files.

    in reply to: Bug with "image" field #36987
    sherwin_flightsherwin_flight
    Participant

    There is a really easy fix for this.

    The only reason this problem exists is because the plugin calls the "wp_get_attachment_image" function on whatever is returned, since it expects an attachment ID.

    So if a simple check is done on the returned value first, we can change the output based on if it's attachment ID or a file URL.

    Inside the image.php file if I add a new variable like this:

    $attachment_image = (is_numeric($file)) ? wp_get_attachment_image( $file, $field['image_size'] ) : '<img width="150" height="150" src="'.$file.'" alt="" />';

    I can then replace the call to wp_get_attachment_image with the $attachment_image variable instead. If an attachment ID is returned, it works as it always did. But if a file URL is returned (because a custom upload folder was used) the preview image still shows up as expected.

    This small change seems to make the plugin work as expected, and removes one of the limitations people may run into.

    So the original code looks like this:

    		return sprintf(
    			'<li class="rwmb-image-item">
    				<div class="rwmb-file-icon">%s</div>
    				<div class="rwmb-image-overlay"></div>
    				<div class="rwmb-image-actions">
    					%s
    					<a href="#" class="rwmb-image-delete rwmb-file-delete" data-attachment_id="%s"><span class="dashicons dashicons-no-alt"></span></a>
    				</div>
    				<input type="hidden" name="%s[%s]" value="%s">
    			</li>',
    			wp_get_attachment_image( $file, $field['image_size'] ),
    			$edit_link,
    			esc_attr( $file ),
    			esc_attr( $attributes['name'] ),
    			esc_attr( $index ),
    			esc_attr( $file )
    		);

    And with my changes, it looks like this:

    $attachment_image = (is_numeric($file)) ? wp_get_attachment_image( $file, $field['image_size'] ) : '<img width="150" height="150" src="'.$file.'" class="attachment-thumbnail size-thumbnail" alt="" />';
    		return sprintf(
    			'<li class="rwmb-image-item">
    				<div class="rwmb-file-icon">%s</div>
    				<div class="rwmb-image-overlay"></div>
    				<div class="rwmb-image-actions">
    					%s
    					<a href="#" class="rwmb-image-delete rwmb-file-delete" data-attachment_id="%s"><span class="dashicons dashicons-no-alt"></span></a>
    				</div>
    				<input type="hidden" name="%s[%s]" value="%s">
    			</li>',
    			$attachment_image,
    			$edit_link,
    			esc_attr( $file ),
    			esc_attr( $attributes['name'] ),
    			esc_attr( $index ),
    			esc_attr( $file )
    		);
    in reply to: Bug with "image" field #36976
    sherwin_flightsherwin_flight
    Participant

    It is kind of a bug, because the image previews are broken and don't work properly.

    It's difficult to manage images if you can't see them.

    I'll look for another solution for what I'm trying to do if image fields don't let you see what's uploaded.

    in reply to: Default values of hidden field in clone group #35543
    sherwin_flightsherwin_flight
    Participant

    I've implemented a solution to this issue that's working for me.

    Cloning the group does clone my hidden fields, but they keep the same value.

    I have some JavaScript that listens for changes to the DOM directly, and if a clone is added to that group the value is reset to 0.

    I haven't tested it extensively yet, but in the testing I have done it seems to be working exactly how I want.

    in reply to: Default values of hidden field in clone group #35346
    sherwin_flightsherwin_flight
    Participant

    I've solved this by watching for DOM changes and clearing the value of the field when a new clone is added.

    in reply to: Ping Slack after Save_post #35313
    sherwin_flightsherwin_flight
    Participant

    You'd use the save_post hook in your functions.PHP file

    Documentation: https://developer.wordpress.org/reference/hooks/save_post/

    in reply to: Bug while deleting files in clone group #35276
    sherwin_flightsherwin_flight
    Participant

    There is a workaround I can use for now, by using a single file field that allows multiple file uploads. That causes the "add new file" link to show up so people can upload additional files.

    However, my original reason for wanting to use a clone group is because my clone groups had a file field and a text field where people could enter a title for the upload. My current workaround doesn't allow adding a title to the files being uploaded.

    in reply to: Bug while deleting files in clone group #35275
    sherwin_flightsherwin_flight
    Participant

    Hi Long,

    That wasn't the setting I was referring to, but you answered my question as part of a comment in a other thread here: https://support.metabox.io/topic/error-invalid-file-when-delete-image-custom-field-user-type-image/

    The important part of that thread was a comment where you said "Please use the field image or file as a top field, not a subfield to delete images/files when clicking "X" button. This issue will be fixed in the next update."

    I updated to the latest version, but the error still occurs, however it's slightly better than with the old version.

    I set up a few fields to test this out.

    Metabox Version: 5.6.1
    Addons: Groups and Tabs

    In a tabbed Metabox I set up:

    - 3 "file" fields
    - A "clone group" with 1 "file" field set to allow a maximum of three fields.

    I have uploaded a file to each of them, so have uploaded 6 files in total. All of the files uploaded successfully and the information was saved in the database.

    As you know, underneath all 6 of the file I've uploaded there is now a red "Delete" link showing.

    Expected behaviour: Clicking those delete links would delete the files.

    Actual behaviour:

    - For the three "file" fields that were added separately, and NOT as part of a group, the files are properly deleted.

    - For the three files that were added as part of the clone group, only the last file added can be deleted. The rest show the "Invalid File!" error. What's weird is that it will always allow me to delete the last file in the list. So say I have File1, File2, and File3 in a clone group. I can delete File3, but not File1 or File2. But if I delete File3 and then save my post, when the page reloads it shows File1 and File2, and I can delete File2 but not File1. So if I had a list of 10 files in a clone group I would have to delete them one at a time starting at the bottom, and saving the post in between deleting each file.

    Prior to updating to the latest version of Metabox it wouldn't allow me to delete files in a group at all, so being able to delete them one at a time is a slight improvement, but it's still not working the way it should.

    sherwin_flightsherwin_flight
    Participant

    Ok, it seems I currently have version 5.4.0 installed.

    I can probably get the newer version from my theme provider since I still have an active license with them and they may have already updated the theme.

    If I want to update the bundled version of Metabox without updating the entire theme, can I just take the Metabox files from the updated version of the theme and just overwrite my current Metabox files with them?

    The theme also came with some of the premium plugins bundled as well. Would those also need to be updated, or just Metabox Core?

    Thanks for your help.

    in reply to: Using metabox in multiple plugins #35220
    sherwin_flightsherwin_flight
    Participant

    Great, thank you. I was having some trouble and wanted to make sure I was doing it correctly, but my problem was related to another issues and it's now working properly.

    Thanks for your help.

    sherwin_flightsherwin_flight
    Participant

    Hi Long,

    You previously mentioned "Please use the field image or file as a top field, not a subfield to delete images/files when clicking "X" button. This issue will be fixed in the next update."

    Was this bug fixed?

    in reply to: Error with ajax file delete on CPT #33662
    sherwin_flightsherwin_flight
    Participant

    I have resolved this issue and you can delete this thread.

    in reply to: Error with ajax file delete on CPT #33661
    sherwin_flightsherwin_flight
    Participant

    A little more info on this.

    In the rwmb_get_registry function, if I output the $data[ $type ] variable, the one CPT where the ajax file deleting doesn't work is missing from the data array. The other CPTs are listed.

    So the actual cause of my problem is that one of my CPTs is missing from the field registry.

Viewing 15 posts - 1 through 15 (of 24 total)