static function formAddByUrl() {

		check_admin_referer( 'bulk-books' ); // Nonce auto-generated by WP_List_Table

		$catalog = new static();
		$user_id = $catalog->getUserId();

		// Set Redirect URL
		if ( get_current_user_id() !== $user_id ) {
			$redirect_url = get_admin_url( get_current_blog_id(), '/index.php?page=pb_catalog&user_id=' . $user_id );
		} else {
			$redirect_url = get_admin_url( get_current_blog_id(), '/index.php?page=pb_catalog' );
		}

		$url = wp_parse_url( \Pressbooks\Sanitize\canonicalize_url( $_REQUEST['add_book_by_url'] ) );
		$main = wp_parse_url( network_home_url() );

		if ( strpos( $url['host'], $main['host'] ) === false ) {
			$_SESSION['pb_errors'][] = __( 'Invalid URL.', 'pressbooks' );
			\Pressbooks\Redirect\location( $redirect_url );
		}

		if ( $url['host'] === $main['host'] ) {
			// Get slug using the path
			$slug = str_replace( $main['path'], '', $url['path'] );
			$slug = trim( $slug, '/' );
			$slug = explode( '/', $slug );
			$slug = $slug[0];
		} else {
			// Get slug using host
			$slug = str_replace( $main['host'], '', $url['host'] );
			$slug = trim( $slug, '.' );
			$slug = explode( '.', $slug );
			$slug = $slug[0];
		}

		$book_id = get_id_from_blogname( $slug );
		if ( ! $book_id ) {
			$_SESSION['pb_errors'][] = __( 'No book found.', 'pressbooks' );
			\Pressbooks\Redirect\location( $redirect_url );
		}

		$catalog->saveBook( $book_id, [] );
		$catalog->deleteCache();

		// Ok!
		$_SESSION['pb_notices'][] = __( 'Settings saved.' );

		// Redirect back to form
		\Pressbooks\Redirect\location( $redirect_url );
	}
static function formAddByUrl() {

		check_admin_referer( 'bulk-books' ); // Nonce auto-generated by WP_List_Table

		$catalog = new static();
		$user_id = $catalog->getUserId();

		// Set Redirect URL
		if ( get_current_user_id() !== $user_id ) {
			$redirect_url = get_admin_url( get_current_blog_id(), '/index.php?page=pb_catalog&user_id=' . $user_id );
		} else {
			$redirect_url = get_admin_url( get_current_blog_id(), '/index.php?page=pb_catalog' );
		}

		$url = wp_parse_url( \Pressbooks\Sanitize\canonicalize_url( $_REQUEST['add_book_by_url'] ) );
		$main = wp_parse_url( network_home_url() );

		if ( strpos( $url['host'], $main['host'] ) === false ) {
			$_SESSION['pb_errors'][] = __( 'Invalid URL.', 'pressbooks' );
			\Pressbooks\Redirect\location( $redirect_url );
		}

		if ( $url['host'] === $main['host'] ) {
			// Get slug using the path
			$slug = str_replace( $main['path'], '', $url['path'] );
			$slug = trim( $slug, '/' );
			$slug = explode( '/', $slug );
			$slug = $slug[0];
		} else {
			// Get slug using host
			$slug = str_replace( $main['host'], '', $url['host'] );
			$slug = trim( $slug, '.' );
			$slug = explode( '.', $slug );
			$slug = $slug[0];
		}

		$book_id = get_id_from_blogname( $slug );
		if ( ! $book_id ) {
			$_SESSION['pb_errors'][] = __( 'No book found.', 'pressbooks' );
			\Pressbooks\Redirect\location( $redirect_url );
		}

		$catalog->saveBook( $book_id, [] );
		$catalog->deleteCache();

		// Ok!
		$_SESSION['pb_notices'][] = __( 'Settings saved.' );

		// Redirect back to form
		\Pressbooks\Redirect\location( $redirect_url );
	}
static function formAddByUrl ( ) { check_admin_referer ( 'bulk-books' ) ; // Nonce auto-generated by WP_List_Table $ catalog = new static ( ) ; $ user_id = $ catalog -> getUserId ( ) ; // Set Redirect URL if ( get_current_user_id ( ) !== $ user_id ) { $ redirect_url = get_admin_url ( get_current_blog_id ( ) , '/index.php?page=pb_catalog&user_id=' . $ user_id ) ; } else { $ redirect_url = get_admin_url ( get_current_blog_id ( ) , '/index.php?page=pb_catalog' ) ; } $ url = wp_parse_url ( \ Pressbooks \ Sanitize \ canonicalize_url ( $ _REQUEST [ 'add_book_by_url' ] ) ) ; $ main = wp_parse_url ( network_home_url ( ) ) ; if ( strpos ( $ url [ 'host' ] , $ main [ 'host' ] ) === false ) { $ _SESSION [ 'pb_errors' ] [ ] = __ ( 'Invalid URL.' , 'pressbooks' ) ; \ Pressbooks \ Redirect \ location ( $ redirect_url ) ; } if ( $ url [ 'host' ] === $ main [ 'host' ] ) { // Get slug using the path $ slug = str_replace ( $ main [ 'path' ] , '' , $ url [ 'path' ] ) ; $ slug = trim ( $ slug , '/' ) ; $ slug = explode ( '/' , $ slug ) ; $ slug = $ slug [ 0 ] ; } else { // Get slug using host $ slug = str_replace ( $ main [ 'host' ] , '' , $ url [ 'host' ] ) ; $ slug = trim ( $ slug , '.' ) ; $ slug = explode ( '.' , $ slug ) ; $ slug = $ slug [ 0 ] ; } $ book_id = get_id_from_blogname ( $ slug ) ; if ( ! $ book_id ) { $ _SESSION [ 'pb_errors' ] [ ] = __ ( 'No book found.' , 'pressbooks' ) ; \ Pressbooks \ Redirect \ location ( $ redirect_url ) ; } $ catalog -> saveBook ( $ book_id , [ ] ) ; $ catalog -> deleteCache ( ) ; // Ok! $ _SESSION [ 'pb_notices' ] [ ] = __ ( 'Settings saved.' ) ; // Redirect back to form \ Pressbooks \ Redirect \ location ( $ redirect_url ) ; }
Add Book by URL
Add Book by URL