LLMS_Admin_Post_Tables::handle_link_actions()

Handle events for our custom postrow actions


Return Return

(void)


Top ↑

Source Source

File: includes/admin/post-types/class.llms.post.tables.php

	public function handle_link_actions() {

		$action = llms_filter_input( INPUT_GET, 'action' );

		// Bail early if request doesn't concern us.
		if ( empty( $action ) ) {
			return;
		}

		// Bail early if it isn't a clone/ export request.
		if ( 'llms-clone-post' !== $action && 'llms-export-post' !== $action && 'llms-detach-post' !== $action ) {
			return;
		}

		$post_id = llms_filter_input( INPUT_GET, 'post' );

		// Bail if there's no post ID.
		if ( empty( $post_id ) ) {
			wp_die( esc_html__( 'Missing post ID.', 'lifterlms' ) );
		}

		$post = get_post( $post_id );

		// Bail if post ID is invalid.
		if ( ! $post ) {
			wp_die( esc_html__( 'Invalid post ID.', 'lifterlms' ) );
		}

		// Bail if the action isn't supported on post type.
		if ( ! post_type_supports( $post->post_type, $action ) ) {
			wp_die( esc_html__( 'Action cannot be executed on the current post.', 'lifterlms' ) );
		}

		// Bail if user doesn't have permissions.
		if ( ! current_user_can( 'edit_course', $post->ID ) ) {
			wp_die( esc_html__( 'You are not authorized to perform this action on the current post.', 'lifterlms' ) );
		}

		$post = llms_get_post( $post );

		// Run export or clone action as needed.
		switch ( $action ) {

			case 'llms-export-post':
				$post->export();
				break;

			case 'llms-detach-post':
				if ( ! isset( $_GET['llms_detach_post_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['llms_detach_post_nonce'] ), 'llms_detach_post' ) ) {
					wp_die( esc_html__( 'You are not authorized to perform this action on the current post.', 'lifterlms' ) );
				}
				$r = delete_post_meta( $post->id, '_llms_parent_section' ) && delete_post_meta( $post->id, '_llms_parent_course' );
				if ( ! $r ) {
					LLMS_Admin_Notices::flash_notice( esc_html__( 'There was an error detaching the post.', 'lifterlms' ), 'error' );
				}
				wp_safe_redirect( admin_url( 'edit.php?post_type=' . $post->get( 'type' ) ) );
				exit;

			case 'llms-clone-post':
				if ( ! isset( $_GET['llms_clone_post_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['llms_clone_post_nonce'] ), 'llms_clone_post' ) ) {
					wp_die( esc_html__( 'You are not authorized to perform this action on the current post.', 'lifterlms' ) );
				}
				$r = $post->clone_post();
				if ( is_wp_error( $r ) ) {
					LLMS_Admin_Notices::flash_notice( $r->get_error_message(), 'error' );
				}
				wp_safe_redirect( admin_url( 'edit.php?post_type=' . $post->get( 'type' ) ) );
				exit;

		}
	}


Top ↑

Changelog Changelog

Changelog
Version Description
7.5.1 Adding nonce to course clone links
3.33.1 Use edit_course cap instead of edit_post cap.
3.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.