protected static function formTags() {

		check_admin_referer( 'pb-user-catalog' );

		if ( ! empty( $_REQUEST['ID'] ) ) {
			list( $user_id, $blog_id ) = explode( ':', $_REQUEST['ID'] );
		} else {
			$user_id = '';
			$blog_id = '';
		}
		if ( ! empty( $_REQUEST['user_id'] ) ) {
			$user_id = absint( $_REQUEST['user_id'] );
		}
		if ( ! empty( $_REQUEST['blog_id'] ) ) {
			$blog_id = absint( $_REQUEST['blog_id'] );
		}

		if ( ! $user_id || ! current_user_can( 'edit_user', $user_id ) ) {
			wp_die( __( 'You do not have permission to do that.', 'pressbooks' ) );
		}

		// 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' );
		}

		/* Go! */
		$catalog = new static( $user_id );
		$featured = ( isset( $_REQUEST['featured'] ) ) ? absint( $_REQUEST['featured'] ) : 0;
		$catalog->saveBook(
			$blog_id, [
				'featured' => $featured,
			]
		);

		// Tags
		for ( $i = 1; $i <= self::MAX_TAGS_GROUP; ++$i ) {
			$catalog->deleteTags( $blog_id, $i );
			$tags = ( isset( $_REQUEST[ "tags_$i" ] ) ) ? $_REQUEST[ "tags_$i" ] : [];
			foreach ( $tags as $tag ) {
				$catalog->saveTag( $tag, $blog_id, $i );
			}
		}

		$catalog->deleteCache();

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

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

		check_admin_referer( 'pb-user-catalog' );

		if ( ! empty( $_REQUEST['ID'] ) ) {
			list( $user_id, $blog_id ) = explode( ':', $_REQUEST['ID'] );
		} else {
			$user_id = '';
			$blog_id = '';
		}
		if ( ! empty( $_REQUEST['user_id'] ) ) {
			$user_id = absint( $_REQUEST['user_id'] );
		}
		if ( ! empty( $_REQUEST['blog_id'] ) ) {
			$blog_id = absint( $_REQUEST['blog_id'] );
		}

		if ( ! $user_id || ! current_user_can( 'edit_user', $user_id ) ) {
			wp_die( __( 'You do not have permission to do that.', 'pressbooks' ) );
		}

		// 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' );
		}

		/* Go! */
		$catalog = new static( $user_id );
		$featured = ( isset( $_REQUEST['featured'] ) ) ? absint( $_REQUEST['featured'] ) : 0;
		$catalog->saveBook(
			$blog_id, [
				'featured' => $featured,
			]
		);

		// Tags
		for ( $i = 1; $i <= self::MAX_TAGS_GROUP; ++$i ) {
			$catalog->deleteTags( $blog_id, $i );
			$tags = ( isset( $_REQUEST[ "tags_$i" ] ) ) ? $_REQUEST[ "tags_$i" ] : [];
			foreach ( $tags as $tag ) {
				$catalog->saveTag( $tag, $blog_id, $i );
			}
		}

		$catalog->deleteCache();

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

		// Redirect back to form
		\Pressbooks\Redirect\location( $redirect_url );
	}
protected static function formTags ( ) { check_admin_referer ( 'pb-user-catalog' ) ; if ( ! empty ( $ _REQUEST [ 'ID' ] ) ) { list ( $ user_id , $ blog_id ) = explode ( ':' , $ _REQUEST [ 'ID' ] ) ; } else { $ user_id = '' ; $ blog_id = '' ; } if ( ! empty ( $ _REQUEST [ 'user_id' ] ) ) { $ user_id = absint ( $ _REQUEST [ 'user_id' ] ) ; } if ( ! empty ( $ _REQUEST [ 'blog_id' ] ) ) { $ blog_id = absint ( $ _REQUEST [ 'blog_id' ] ) ; } if ( ! $ user_id || ! current_user_can ( 'edit_user' , $ user_id ) ) { wp_die ( __ ( 'You do not have permission to do that.' , 'pressbooks' ) ) ; } // 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' ) ; } /* Go! */ $ catalog = new static ( $ user_id ) ; $ featured = ( isset ( $ _REQUEST [ 'featured' ] ) ) ? absint ( $ _REQUEST [ 'featured' ] ) : 0 ; $ catalog -> saveBook ( $ blog_id , [ 'featured' => $ featured , ] ) ; // Tags for ( $ i = 1 ; $ i <= self :: MAX_TAGS_GROUP ; ++ $ i ) { $ catalog -> deleteTags ( $ blog_id , $ i ) ; $ tags = ( isset ( $ _REQUEST [ "tags_$i" ] ) ) ? $ _REQUEST [ "tags_$i" ] : [ ] ; foreach ( $ tags as $ tag ) { $ catalog -> saveTag ( $ tag , $ blog_id , $ i ) ; } } $ catalog -> deleteCache ( ) ; // Ok! $ _SESSION [ 'pb_notices' ] [ ] = __ ( 'Settings saved.' ) ; // Redirect back to form \ Pressbooks \ Redirect \ location ( $ redirect_url ) ; }
Save tags to database
Save tags to database