• Resolved Li-An

    (@li-an)


    Hello, with last version 5.8.0.1 (and probabably with 5.8, I did not test), I cannot edit my posts. I’ve got an “unexpected error” showing. I must stick to 5.7.3

    • This topic was modified 2 years, 8 months ago by Li-An.
Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Benjamin Denis

    (@rainbowgeek)

    Hi,

    which version of WordPress do you have please?

    Which theme are you using?

    Thx

    Plugin Author Benjamin Denis

    (@rainbowgeek)

    OK we have identified the issue.

    Can you test on your site by replacing the code of this file (wp-seopress/assets/js/build/primary-category-select.js) by the one below please?

    import { __ } from '@wordpress/i18n'
    import { Component } from '@wordpress/element'
    import { withSelect } from '@wordpress/data';
    import { PanelRow, SelectControl } from '@wordpress/components'
    
    class TermSelect extends Component {
        constructor() {
            super(...arguments);
            this.onChange = this.onChange.bind(this);
            this.updateMetabox = this.updateMetabox.bind(this);
            this.state = {
                primaryTermId: 'none',
                selectableTerms: [],
            }
        }
    
        componentDidMount() {
            const primaryTermId = this.props.primaryTermId || 'none';
            this.setState({ primaryTermId });
            this.metaboxField = document.querySelector('#seopress_robots_primary_cat');
            if (this.metaboxField) {
                this.metaboxField.addEventListener('change', e => {
                    this.setState({ primaryTermId: e.target.value });
                });
            }
        }
    
        componentDidUpdate(prevProps, prevState) {
            // If available terms or selected terms have changed, check state.
            if (prevProps.allTerms !== this.props.allTerms || prevProps.selectedTermIds !== this.props.selectedTermIds) {
                const selectableTerms = this.props.allTerms.filter(term => this.props.selectedTermIds.includes(term.id));
                const primaryTermId = !this.props.selectedTermIds.length || !this.props.selectedTermIds.includes(parseInt(this.state.primaryTermId)) ? 'none' : this.state.primaryTermId;
                this.setState({ selectableTerms, primaryTermId });
            }
            if (prevState.primaryTermId !== this.state.primaryTermId || prevState.selectableTerms !== this.state.selectableTerms) {
                this.updateMetabox(this.state.primaryTermId);
            }
        }
    
        updateMetabox(selectedTermId) {
            if (this.metaboxField) {
                const options = this.getOptions().map(option => {
                    const selected = option.value == selectedTermId ? 'selected="selected"' : '';
                    return <code><option value=&quot;${option.value}&quot; ${selected}>${option.label}</option></code>;
                });
                this.metaboxField.value = selectedTermId;
                this.metaboxField.innerHTML = options.join('');
            }
        }
    
        getOptions() {
            return [
                { value: 'none', label: __('None (will disable this feature)', 'wp-seopress') },
                ...this.state.selectableTerms.map((term) => ({ value: term.id, label: term.name, }))
            ];
        }
    
        onChange(termId) {
            this.setState({ primaryTermId: termId });
        }
    
        render() {
            return !!this.state.selectableTerms.length && (
                <SelectControl
                    label={__('Select a primary category', 'wp-seopress')}
                    value={this.state.primaryTermId}
                    options={this.getOptions()}
                    onChange={this.onChange}
                />
            );
        }
    }
    
    const PrimaryTermSelect = withSelect((select, { slug }) => {
        const taxonomy = select('core').getTaxonomy(slug);
        const selectedTermIds = taxonomy ? select('core/editor').getEditedPostAttribute(taxonomy.rest_base) : [];
        const allTerms = select('core').getEntityRecords('taxonomy', slug, { per_page: -1 })
        const primaryTermId = select('core/editor').getEditedPostAttribute('meta')['_seopress_robots_primary_cat'] || 'none';
        return { taxonomy, allTerms, primaryTermId, selectedTermIds }
    })(TermSelect);
    
    wp.hooks.addFilter(
        'editor.PostTaxonomyType',
        'wpseopress',
        (PostTaxonomies) => (props) => {
            return (
                <>
                    <PostTaxonomies {...props} />
                    {props.slug && 'category' === props.slug &&
                        <PanelRow className="seopress-primary-term-picker">
                            <PrimaryTermSelect {...props} />
                        </PanelRow>
                    }
                </>
            );
        }
    )

    Thank you for your help!

    Thread Starter Li-An

    (@li-an)

    I’m on WP 5.9.1. I tried the code but it seems it does not change anything for me. Theme is Blocksy.

    Plugin Author Benjamin Denis

    (@rainbowgeek)

    Make sure to clear your browser cache.

    Thread Starter Li-An

    (@li-an)

    OK, cleaning the cache seems to make the deal.

    Plugin Author Benjamin Denis

    (@rainbowgeek)

    Perfect! Patch incoming soon.

    Plugin Author Benjamin Denis

    (@rainbowgeek)

    Version 5.8.0.2 is now available, please update.

    Thank you!

    Thread Starter Li-An

    (@li-an)

    Still broken in 5.8.0.2 for me ??

    Plugin Author Benjamin Denis

    (@rainbowgeek)

    @li-an have you clear again you cache? Can you confirm you’re using SEOPress version 5.8.0.2?

    Do you use Classic Editor or Gutenberg?
    Do you have enabled Universal SEO metabox from SEO, Advanced, Appearance tab?

    Plugin Author Benjamin Denis

    (@rainbowgeek)

    It seems the problem is only present with WP versions < 6.0.

    Still investigating.

    Thread Starter Li-An

    (@li-an)

    SEOPress 5.8.0.2
    Gutenberg
    Universal Box not activated

    • This reply was modified 2 years, 8 months ago by Li-An.
    Plugin Author Benjamin Denis

    (@rainbowgeek)

    @li-an do you still have the issue with version 5.8.0.3 (not 5.8.0.2)?

    Thx

    Thread Starter Li-An

    (@li-an)

    It seems solved with 5.8.0.3. Thanks.

    Plugin Author Benjamin Denis

    (@rainbowgeek)

    Perfect!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Error on edit page’ is closed to new replies.