• Resolved apedog

    (@apedog)


    Calling Red_Item::create() results in fatal error.

    Fatal error: Uncaught Error: Class ‘Red_Group’ not found
    in […]\redirection\models\redirect-sanitizer.php on line 182

    solved by adding require_once WP_PLUGIN_DIR . '/redirection/models/group.php'; before call.

    Also, is there proper documentation on the correct format of $details array that needs to be sent to Red_Item::create()? Or documentation on the usage of the Redirection plugin REST API? I couldn’t find any and have to error_log inside the plugin’s code to find how things work.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author John Godley

    (@johnny5)

    All documentation can be found here:

    https://redirection.me/developer/

    Thread Starter apedog

    (@apedog)

    Thank you for that. Will have a look.

    As for the fatal error when calling Red_Item::create() is this expected behaviour? Or am I doing something wrong? Or will this be fixed in future versions?

    Plugin Author John Godley

    (@johnny5)

    I don’t know how you are doing things, but if you haven’t included that file then you’ll need to include it. The error doesn’t occur normally.

    Thread Starter apedog

    (@apedog)

    This is a simplified version of my code.
    It’s just a function hooked on init
    It runs once after a plugin has upgraded and set an option to true.
    ie. it’s a maybe_upgrade routine running on first page load after a custom plugin has updated.

    function my_redirection_create(){
    
       // some return early tests here.
    
        if ( class_exists( 'Red_Item' ) ){
    
            // require_once WP_PLUGIN_DIR . '/redirection/models/group.php';
    
            $details = [
                'url'         => 'source_url',
                'action_data' => [ 'url' => '/target/?my_param=' . $key ],
                'group_id'    => 2,
                'match_type'  => 'url',
                'action_type'  => 'url',
            ];
            $result = Red_Item::create( $details );
        }
    }
    add_action( 'init', 'my_redirection_create', 11 );
    Plugin Author John Godley

    (@johnny5)

    Ok, well it looks like you’ve solved the error.

    Thread Starter apedog

    (@apedog)

    lol ok
    (props for temperament ?? )

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Call to `Red_Item::create()` results in fatal error’ is closed to new replies.