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 ) {
			return;
		}

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

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

		$post = get_post( $post_id );

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

		// Bail if the action isn't supported on post type.
		if ( ! post_type_supports( $post->post_type, $action ) ) {
			wp_die( __( '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( __( '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-clone-post':
				$r = $post->clone_post();
				if ( is_wp_error( $r ) ) {
					LLMS_Admin_Notices::flash_notice( $r->get_error_message(), 'error' );
				}
				wp_redirect( admin_url( 'edit.php?post_type=' . $post->get( 'type' ) ) );
				exit;

		}

	}


Top ↑

Changelog Changelog

Changelog
Version Description
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.