Site icon Hip-Hop Website Design and Development

How can I set off a javascript perform after a put up replace on edit put up display in wordpress admin panel?

I exploit WordPress 5.2.2 and I develop a customized theme.

EDIT : On my theme I added a metabox who present an enter kind=”textual content”.

Code in features.php of my theme

if ( ! function_exists( 'vn_add_metabox' ) ) {
    perform vn_add_metabox () {
        add_meta_box('vn_youtube_single_metabox', __('Youtube hyperlink', WP_THEME_TEXTDOMAIN), 'show_vn_youtube_link_metabox', array('put up', 'web page'), 'aspect', 'low');

    }
    add_action( 'add_meta_boxes', 'vn_add_metabox' );
}

This metabox name show_vn_youtube_link_metabox who show an enter textual content and youtube video iframe

if (!function_exists('show_vn_youtube_link_metabox')) {
    perform show_vn_youtube_link_metabox()
    {
        international $put up;
        show_vn_input_text('vn_youtube_link'); // <enter kind="textual content" identify ="vn_youtube_link" worth="VALUE_POST_META" />
        echo '<br/>'.vn_get_youtube_iframe(get_post_meta( $post->ID, 'vn_youtube_link', true )); /*<iframe class="youtube-video-iframe" src="'.VIDEO_LINK.'?rel=0" width="790" peak="496" allowtransparency="true" fashion="width:100%;" frameborder="0" allowFullScreen enable="encrypted-media" ></iframe> */
    }
}

I save worth of postmeta on motion save_post

if ( ! function_exists( 'vn_save_metabox_value' ) ) {
    perform vn_save_metabox_value ( $post_id, $put up ) { // Enregistrement des données dans la base WordPress.
        //évite de perdre des données à trigger de l'enregistrement automatique
        if ( ( outlined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( outlined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_REQUEST[ 'bulk_edit' ] ) ) {
            return $post->ID;
        }
        // Vérification des droits de l'utilisateur.
        if ( ! current_user_can( 'edit_post', $post->ID ) ) {
            return $post->ID;
        }

        vn_save_meta_box_content($put up, 'vn_youtube_link');

        return $post->ID;
    }

    add_action( 'save_post', 'vn_save_metabox_value', 1, 2 );
}

I exploit a perform to regulate worth of postmeta and put it aside

if ( ! function_exists( 'vn_save_meta_box_content' ) ) {
    perform vn_save_meta_box_content ( $put up, $meta_box_id, $input_name = '' ) {
        if ( ! isset( $input_name ) || empty( $input_name ) ) {
            $input_name = $meta_box_id;
        }

        if ( ! isset( $_POST[ $input_name ] ) || empty( $_POST[ $input_name ] ) ) {
            delete_post_meta( $post->ID, $meta_box_id );
        } else {
            if ( get_post_meta( $post->ID, $meta_box_id, true ) ) {
                update_post_meta( $post->ID, $meta_box_id, $_POST[ $input_name ] );
            } else {
                add_post_meta( $post->ID, $meta_box_id, $_POST[ $input_name ] );
            }
        }
    }
}

I wish to execute a JS perform (AJAX or different) after the AJAX accomplished by WordPress to replace put up (XHR POST http://localhost/wp_uimm/wp-json/wp/v2/pages/5?_locale=person) on admin put up edit display. This javascript perform shall be used to show the iframe or hyperlink of the youtube video with out refreshing the put up edit display.

Is there a callback to execute a perform when wp POST has accomplished ?